*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Arial, sans-serif; height: 100vh; overflow: hidden; background: #f0f2f5; }

/* ── Header ── */
.header {
    background: #00274D;
    color: white;
    padding: 0 20px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.header-title { font-size: 18px; font-weight: bold; }
.header-right { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.badge {
    background: #1a4a7a;
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 12px;
    color: #aad4ff;
}
.badge.ok { background: #1a5c2a; color: #7effa0; }
.countdown { font-size: 12px; color: #aad4ff; }
.btn-refresh {
    background: #1a4a7a; border: none; border-radius: 50%;
    color: white; width: 28px; height: 28px; font-size: 16px;
    cursor: pointer; line-height: 1; transition: background 0.15s;
}
.btn-refresh:hover { background: #2a6aaa; }

/* ── Layout principal ── */
.main-content {
    display: flex;
    height: calc(100vh - 52px);
}

/* ── Mapa ── */
#map {
    flex: 1;
    min-width: 0;
    height: 100%;
}

/* ── Painel lateral ── */
.side-panel {
    width: 46%;
    min-width: 460px;
    max-width: 700px;
    display: flex;
    flex-direction: column;
    background: white;
    border-left: 2px solid #dde3ec;
    overflow: hidden;
}

/* ── Abas de região ── */
.tab-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px 10px;
    background: #f7f9fb;
    border-bottom: 1px solid #dde3ec;
    flex-shrink: 0;
}
.tab-btn {
    background: #e4eaf2;
    border: none;
    border-radius: 14px;
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    color: #333;
    white-space: nowrap;
    transition: background 0.15s;
}
.tab-btn:hover { background: #c8d8ed; }
.tab-btn.active { background: #00274D; color: white; font-weight: bold; }

/* ── Tabela ── */
.table-wrapper {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
}
#rain-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    min-width: 480px;
}
#rain-table thead th {
    background: #00274D;
    color: white;
    font-weight: bold;
    padding: 7px 5px;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 2;
    white-space: nowrap;
}
#rain-table thead th.col-name { text-align: left; padding-left: 10px; min-width: 160px; }
#rain-table tbody td {
    padding: 5px 4px;
    text-align: center;
    border-bottom: 1px solid #eee;
    font-size: 12px;
}
#rain-table tbody tr:hover td { filter: brightness(0.9); }
#rain-table tbody tr.group-header td {
    background: #00274D;
    color: white;
    font-weight: bold;
    font-size: 12px;
    padding: 5px 10px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    position: sticky;
    top: 31px;
    z-index: 1;
}
.col-name {
    text-align: left !important;
    padding-left: 10px !important;
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Legenda ── */
.legend-corrego { border-top: 1px solid #dde3ec; }
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px 10px;
    background: #f7f9fb;
    border-top: 1px solid #dde3ec;
    flex-shrink: 0;
}
.leg {
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: bold;
}

/* ── Loading ── */
#loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.spinner {
    width: 48px; height: 48px;
    border: 5px solid #00274D;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Alerta flutuante ── */
#alert-toast {
    display: none;
    position: fixed;
    top: 62px; right: 20px;
    width: 360px;
    background: white;
    border: 2px solid #FF0000;
    border-radius: 10px;
    padding: 12px 16px 12px 16px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    z-index: 1050;
}
.alert-header { font-weight: bold; font-size: 14px; margin-bottom: 8px; text-align: center; }
#alert-toast button {
    position: absolute; top: 8px; right: 10px;
    background: none; border: none; font-size: 16px; cursor: pointer; color: #888;
}
#alert-body { padding-left: 16px; font-size: 13px; line-height: 1.6; }
