/* ==========================================================================
   Reservoir Monitoring System — Dark Theme
   Government of Andhra Pradesh | APSDMA
   Indian Tricolor-Accented Institutional Design
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Plus+Jakarta+Sans:wght@600;700;800&display=swap');

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    /* Indian Tricolor */
    --saffron:     #FF9933;
    --india-green: #138808;
    --navy-blue:   #000080;

    /* Institutional header */
    --primary:     #0c2340;
    --primary-l:   #1a3a5c;
    --primary-xl:  #234e78;

    /* Dark theme body */
    --bg-dark: #091520;
    --bg-mid: #0d1f35;
    --bg-card: rgba(255,255,255,0.05);
    --bg-card-hover: rgba(255,255,255,0.08);
    --border-subtle: rgba(255,255,255,0.08);
    --border-light: rgba(255,255,255,0.15);
    --text-primary: #e0e0e0;
    --text-secondary: rgba(255,255,255,0.7);
    --text-muted: rgba(255,255,255,0.5);

    --water: #1565c0;
    --water-light: #42a5f5;
    --water-glow: rgba(33, 150, 243, 0.3);
    --dam: #78909c;
    --accent: #00bcd4;

    --critical: #ff5252;
    --low: #ff9800;
    --moderate: #ffeb3b;
    --good: #69f0ae;
    --high: #40c4ff;
    --overflow: #e040fb;

    --tricolor-h: 4px;
    --header-h:   72px;
    --navbar-h:   40px;
}

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-mid) 100%);
    min-height: 100vh;
    color: var(--text-primary);
    overflow: hidden;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* ==========================================================================
   Tricolor Stripe (top of page)
   ========================================================================== */
.tricolor-bar {
    height: var(--tricolor-h);
    background: linear-gradient(to right,
        var(--saffron) 0%, var(--saffron) 33.33%,
        #ffffff 33.33%, #ffffff 66.66%,
        var(--india-green) 66.66%, var(--india-green) 100%);
    flex-shrink: 0;
}

/* ==========================================================================
   Institutional Header — Centered "Government of AP" Design
   AP Logo (left) | Title Block (center) | APSDMA Logo (right)
   ========================================================================== */
.inst-header {
    background: linear-gradient(135deg, var(--primary) 0%, #0f2d50 50%, var(--primary) 100%);
    color: white;
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 28px;
    gap: 20px;
    position: relative;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(0,0,0,.3);
}

.inst-header .logo-left {
    height: 56px;
    width: auto;
    flex-shrink: 0;
    object-fit: contain;
}

.inst-header .logo-left.emblem-fallback {
    filter: brightness(0) invert(1);
    opacity: 0.95;
}

.inst-header .title-block {
    flex: 1;
    min-width: 0;
    text-align: center;
}

.inst-header .gov-name {
    font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 2px;
    text-transform: uppercase;
    opacity: 1;
    margin-bottom: 1px;
}

.inst-header .authority-name {
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 600;
    opacity: 0.8;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.inst-header .app-title {
    font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
    font-size: 17px;
    font-weight: 800;
    letter-spacing: 0.3px;
    line-height: 1.15;
    color: var(--saffron);
}

.inst-header .logo-right {
    height: 48px;
    width: auto;
    flex-shrink: 0;
    border-radius: 4px;
    object-fit: contain;
}

.status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--good);
    animation: pulse 2s infinite;
    display: inline-block;
}
.status-dot.offline { background: var(--critical); animation: none; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.last-update { opacity: 0.8; font-size: 12px; }
.clock-ist { font-weight: 600; color: var(--water-light); font-size: 12px; }

/* ==========================================================================
   Navigation Bar
   ========================================================================== */
.nav-bar {
    background: var(--primary-l);
    height: var(--navbar-h);
    display: flex;
    align-items: stretch;
    padding: 0 20px;
    border-bottom: 2px solid var(--saffron);
    position: relative;
    z-index: 99;
}

.nav-link {
    padding: 0 16px;
    display: flex;
    align-items: center;
    cursor: pointer;
    border: none;
    background: transparent;
    color: rgba(255,255,255,.6);
    font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: 0.3px;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}
.nav-link:hover { color: rgba(255,255,255,.9); background: rgba(255,255,255,.06); }
.nav-link.active { color: #fff; background: var(--primary); border-bottom-color: var(--saffron); }

.nav-stats {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 4px;
    flex-shrink: 0;
    color: rgba(255,255,255,.75);
}

@media (min-width:1101px){ .nav-bar{ overflow-x:auto; overflow-y:hidden; scrollbar-width:thin; } .nav-stats{ position:sticky; right:0; background:var(--primary-l); } }
@media (min-width:1101px) and (max-width:1439px){ .nav-bar{ padding:0 12px; } .nav-link{ padding:0 10px; } }
@media (min-width:1101px){ .nav-stats{ flex-shrink:1; min-width:0; } .nav-stats > *{ flex-shrink:0; } .nav-stats .last-update{ flex-shrink:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; } }

/* --- Main Layout --- */
.main-layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    grid-template-rows: 1fr;
    height: calc(100vh - 116px);
}

.sidebar {
    background: rgba(0, 0, 0, 0.3);
    overflow-y: auto;
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
}

.map-area { position: relative; }
#mapView { width: 100%; height: 100%; }

/* --- Stats Cards --- */
.stats-grid {
    display: grid;
    gap: 8px;
    padding: 10px;
    grid-template-columns: 1fr 1fr;
}

.stat-card {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border-subtle);
    text-align: center;
    transition: all 0.3s;
}
.stat-card:hover {
    border-color: rgba(33,150,243,0.3);
    background: var(--bg-card-hover);
}
.stat-card .value {
    font-size: 1.6em;
    font-weight: 700;
    color: var(--water-light);
    line-height: 1.2;
}
.stat-card .label {
    font-size: 0.68em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
    margin-top: 3px;
}
.stat-card.wide { grid-column: 1 / -1; }
.stat-card.danger .value { color: var(--critical); }
.stat-card.warning .value { color: var(--low); }
.stat-card.success .value { color: var(--good); }
.stat-card.info .value { color: var(--high); }

/* --- Section Titles --- */
.section-title {
    font-size: 0.78em;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 10px 12px 6px;
    opacity: 0.6;
    border-top: 1px solid rgba(255,255,255,0.06);
}

/* --- Source badges --- */
.source-badges {
    padding: 6px 12px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.source-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    font-size: 0.75em;
    color: #ccc;
}
.source-badge .dot {
    width: 8px; height: 8px; border-radius: 50%;
}
.source-badge.active { border-color: var(--accent); background: rgba(0,188,212,0.1); color: #fff; }

/* --- Filter --- */
.filter-bar {
    padding: 6px 12px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}
.filter-bar select, .filter-bar input {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 6px;
    color: #fff;
    padding: 5px 8px;
    font-size: 0.8em;
    outline: none;
}
.filter-bar select:hover, .filter-bar input:focus {
    border-color: rgba(255,255,255,0.25);
}
/* Open dropdown lists: with a translucent <select> background the browser draws the list on white, which made the
   white option text invisible. Give every list the portal's dark colours. */
select { color-scheme: dark; }
select option, select optgroup { background-color: #0d1b2a; color: #fff; }
.filter-label {
    font-size: 0.7em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.5;
}

/* --- Data Table --- */
.data-table-wrap {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 8px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.76em;
}
.data-table th {
    position: sticky;
    top: 0;
    background: rgba(13, 31, 53, 0.98);
    padding: 7px 5px;
    text-align: left;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.8em;
    opacity: 0.7;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    cursor: pointer;
}
.data-table th:hover { opacity: 1; }
.data-table th .sort-icon { font-size: 0.7em; opacity: 0.5; }
.data-table td {
    padding: 5px 5px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    white-space: nowrap;
}
.data-table tr { cursor: pointer; }
.data-table tr:hover td { background: rgba(33,150,243,0.06); }
.data-table tr.selected td { background: rgba(33,150,243,0.12); }

/* --- Storage Bar (inline in table) --- */
.storage-bar {
    width: 60px;
    height: 14px;
    background: rgba(255,255,255,0.06);
    border-radius: 3px;
    overflow: hidden;
    display: inline-block;
    vertical-align: middle;
}
.storage-bar .fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s;
}

/* --- Storage badges --- */
.storage-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.82em;
    font-weight: 600;
}
.storage-critical { background: rgba(255,82,82,0.2); color: var(--critical); }
.storage-low { background: rgba(255,152,0,0.2); color: var(--low); }
.storage-moderate { background: rgba(255,235,59,0.15); color: var(--moderate); }
.storage-good { background: rgba(105,240,174,0.12); color: var(--good); }
.storage-high { background: rgba(64,196,255,0.15); color: var(--high); }
.storage-overflow { background: rgba(224,64,251,0.2); color: var(--overflow); }
.storage-na { background: rgba(100,100,100,0.2); color: #888; }

/* Inflow badges */
.inflow-nil { color: #666; }
.inflow-min { color: var(--high); }
.inflow-low { color: var(--good); }
.inflow-mod { color: var(--moderate); }
.inflow-high { color: var(--low); }
.inflow-vhigh { color: var(--critical); font-weight: 700; }

/* --- Map Controls --- */
.map-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 10;
}
.map-toggle {
    padding: 6px 12px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    background: rgba(13, 31, 53, 0.85);
    color: #ccc;
    font-size: 0.78em;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
}
.map-toggle:hover { background: rgba(13, 31, 53, 0.95); color: #fff; }
.map-toggle.active { border-color: var(--water-light); color: var(--water-light); }

/* --- Map Legend --- */
.map-legend {
    position: absolute;
    bottom: 28px;
    left: 10px;
    background: rgba(13, 31, 53, 0.92);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 10px 14px;
    z-index: 10;
    backdrop-filter: blur(10px);
}
.map-legend h4 {
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    opacity: 0.7;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 3px;
    font-size: 0.75em;
}
.legend-dot {
    width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}

/* --- Info Panel (right of map, overlay) --- */
.info-panel {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 320px;
    max-height: calc(100% - 20px);
    overflow-y: auto;
    background: rgba(13, 31, 53, 0.95);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    z-index: 20;
    backdrop-filter: blur(10px);
    display: none;
}
.info-panel.visible { display: block; }
.info-panel-header {
    padding: 12px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-subtle);
}
.info-panel-header h3 {
    font-size: 0.95em;
    color: var(--water-light);
}
.info-panel-close {
    background: none; border: none; color: #888;
    font-size: 1.2em; cursor: pointer;
}
.info-panel-close:hover { color: #fff; }
.info-panel-body { padding: 12px 14px; }
.info-panel-body .info-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 0.82em;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.info-row .info-label { opacity: 0.6; }
.info-row .info-value { font-weight: 600; }

/* --- Water level gauge (detail panel) --- */
.gauge-container {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    gap: 16px;
}
.gauge {
    width: 60px;
    height: 120px;
    background: rgba(255,255,255,0.06);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border-light);
}
.gauge .water-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(180deg, var(--water-light) 0%, var(--water) 100%);
    transition: height 1s ease;
    border-radius: 0 0 7px 7px;
}
.gauge .frl-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--critical);
    z-index: 2;
}
.gauge .frl-label {
    position: absolute;
    right: -35px;
    font-size: 0.6em;
    color: var(--critical);
    white-space: nowrap;
}
.gauge-stats {
    font-size: 0.82em;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.gauge-stats .gauge-val {
    font-size: 1.3em;
    font-weight: 700;
    color: var(--water-light);
}
.gauge-stats .gauge-label { opacity: 0.6; font-size: 0.78em; }

/* --- Bottom Panel (basin summary / charts) --- */
.bottom-panel {
    background: rgba(0,0,0,0.35);
    border-top: 1px solid var(--border-subtle);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    height: 170px;
    overflow: hidden;
}
.bottom-panel .chart-cell {
    background: rgba(0,0,0,0.15);
    padding: 10px 14px;
    position: relative;
}
.bottom-panel .chart-title {
    font-size: 0.72em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.6;
    margin-bottom: 6px;
}

/* --- Basin Bar Chart --- */
.basin-chart {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: calc(100% - 20px);
}
.basin-bar-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
}
.basin-bar {
    width: 100%;
    min-width: 20px;
    background: rgba(33,150,243,0.15);
    border-radius: 4px 4px 0 0;
    transition: height 0.5s;
    position: relative;
}
.basin-bar .bar-inner {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: 4px 4px 0 0;
    transition: height 0.5s;
}
.basin-bar-label {
    font-size: 0.55em;
    margin-top: 3px;
    opacity: 0.5;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 55px;
}

/* --- District heatmap grid --- */
.district-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 2px;
    height: calc(100% - 20px);
}
.district-cell {
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.5em;
    text-align: center;
    padding: 2px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
}
.district-cell:hover { transform: scale(1.05); z-index: 1; }

/* --- Loading overlay --- */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(9, 21, 32, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loading-icon { font-size: 4em; animation: waterPulse 2s infinite; }

@keyframes waterPulse {
    0%, 100% { opacity: 0.3; transform: translateY(0); }
    50% { opacity: 1; transform: translateY(-5px); }
}

.loading-text { margin-top: 14px; font-size: 1.05em; opacity: 0.8; }
.no-data-msg { text-align: center; padding: 30px; opacity: 0.5; font-size: 0.9em; }

/* ==========================================================================
   Site Footer — Dark Theme (adapted from APSDMA & DM Personnel)
   ========================================================================== */
.site-footer {
    flex-shrink: 0;
}

.footer-tricolor {
    height: 3px;
    background: linear-gradient(to right,
        var(--saffron) 0%, var(--saffron) 33.33%,
        #ffffff 33.33%, #ffffff 66.66%,
        var(--india-green) 66.66%, var(--india-green) 100%);
}

.footer-main {
    background: var(--primary);
    color: rgba(255,255,255,.85);
    padding: 28px 40px;
}

.footer-grid {
    max-width: 1100px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1.3fr 1fr 1fr;
    gap: 36px;
}

.footer-col h4 {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--saffron);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255,255,255,.1);
}

.footer-col p {
    font-size: 12px;
    line-height: 1.65;
    margin-bottom: 6px;
    color: rgba(255,255,255,.7);
}

.footer-col .footer-address {
    opacity: 0.55;
    font-size: 11px;
}

.footer-col .emergency-list {
    list-style: none;
    font-size: 12px;
}

.footer-col .emergency-list li {
    padding: 3px 0;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,.06);
}

.footer-col .emergency-list li .em-label { opacity: .7; }

.footer-col .emergency-list li .em-num {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 700;
    color: var(--saffron);
    letter-spacing: .5px;
}

.footer-col .quick-links {
    list-style: none;
    font-size: 12px;
}

.footer-col .quick-links li { padding: 3px 0; }

.footer-col .quick-links a {
    color: rgba(255,255,255,.65);
    text-decoration: none;
    transition: color .15s;
}

.footer-col .quick-links a:hover { color: var(--saffron); }

.footer-bottom {
    background: #081a30;
    padding: 10px 40px;
    text-align: center;
    font-size: 11px;
    color: rgba(255,255,255,.45);
}

.footer-bottom .footer-credit {
    margin-left: 16px;
    padding-left: 16px;
    border-left: 1px solid rgba(255,255,255,.15);
}

/* --- Responsive --- */
@media (max-width: 1100px) {
    .main-layout {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto 1fr;
    }
    .sidebar { max-height: 45vh; }
    .bottom-panel { grid-template-columns: 1fr 1fr; height: auto; }
    .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }
    .nav-bar { overflow-x: auto; }
    .nav-stats { gap: 6px; font-size: 11px; }
    .info-panel { width: 280px; }
    .footer-grid { grid-template-columns: 1fr 1fr; gap: 20px; }
    .inst-header { padding: 0 16px; gap: 14px; }
    .inst-header .gov-name { font-size: 13px; letter-spacing: 1.5px; }
    .inst-header .app-title { font-size: 15px; }
}

@media (max-width: 768px) {
    .inst-header { height: auto; min-height: var(--header-h); padding: 8px 12px; flex-wrap: wrap; }
    .inst-header .logo-left { height: 40px; }
    .inst-header .logo-right { height: 36px; }
    .inst-header .gov-name { font-size: 11px; letter-spacing: 1px; }
    .inst-header .authority-name { font-size: 9px; }
    .inst-header .app-title { font-size: 13px; }
    .nav-bar { padding: 0 10px; overflow-x: auto; }
    .nav-link { padding: 0 10px; font-size: 11px; }
    .nav-stats { font-size: 10px; gap: 5px; }
    .footer-grid { grid-template-columns: 1fr; gap: 16px; }
    .footer-main { padding: 20px 16px; }
    .footer-bottom { padding: 8px 16px; }
}

@media (max-width: 600px) {
    .bottom-panel { grid-template-columns: 1fr; }
    .info-panel { width: 100%; right: 0; top: 0; border-radius: 0; }
}
