/* ==========================================================================
   LAMS — Lightning Alert Monitoring System — Shared Dark Theme
   APSDMA (Andhra Pradesh State Disaster Management Authority)
   ========================================================================== */

/* --- Reset & Base --- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* === Dark-themed form controls (portal-wide) ============================
   Native <select> dropdowns render in the browser's default colour scheme.
   On a dark UI the open dropdown shows as a white panel covering content
   beneath. `color-scheme: dark` tells modern browsers to use the OS dark-
   mode native widget. Explicit option styling is the fallback for older
   browsers that don't respect color-scheme. */
html, body { color-scheme: dark; }
select, input, textarea, button {
    color-scheme: dark;
    font-family: inherit;
}
select option {
    background: #0d1b2a;
    color: #e0e0e0;
}
select option:checked, select option:hover {
    background: #1a2a44;
    color: #ffd700;
}

:root {
    --bg-dark: #0a0a1a;
    --bg-mid: #0d1b2a;
    --bg-card: rgba(255,255,255,0.06);
    --bg-card-hover: rgba(255,255,255,0.09);
    --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);
    --gold: #ffd700;
    --cyan: #40c4ff;
    --gray-strike: #b4b4b4;
    --green: #69f0ae;
    --yellow: #ffeb3b;
    --orange: #ff9800;
    --red: #ff5252;
    --accent: #00bcd4;
    --header-start: rgba(0, 100, 140, 0.95);
    --header-end: rgba(0, 60, 100, 0.95);
    --cg-neg: #ffd700;
    --cg-pos: #ff9800;
    --ic-color: #f44336;
    /* v2 — operational polish tokens (added 2026-05-30) */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-card: 0 2px 8px rgba(0,0,0,0.35), 0 0 0 1px rgba(255,255,255,0.03);
    --shadow-card-hover: 0 6px 22px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.06);
    --focus-ring: 0 0 0 2px rgba(64,196,255,0.55), 0 0 12px rgba(64,196,255,0.30);
    --transition-snap: 120ms cubic-bezier(0.4,0,0.2,1);
}

/* ─── v2 polish — small, restrained cohesion ───────────────────────────────
   No glows. No gradients on UI chrome. No hover lifts. Just slim scrollbars,
   accessible focus rings, and reduced-motion support.
   ────────────────────────────────────────────────────────────────────────── */

/* Slim, neutral scrollbars (no gold gradient) */
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.20) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.18);
    border-radius: 4px;
}
*::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.30); }

/* Selection — soft, not bright */
::selection { background: rgba(255,215,0,0.30); color: #fff; }

/* Focus rings — single, restrained cyan outline (accessibility) */
button:focus-visible, input:focus-visible, textarea:focus-visible,
select:focus-visible, a:focus-visible, [tabindex]:focus-visible {
    outline: 1px solid rgba(64,196,255,0.55);
    outline-offset: 1px;
    box-shadow: none;
}

/* Snap transitions — only on interactive elements, very fast */
button, a, input, select, textarea {
    transition: border-color var(--transition-snap), background var(--transition-snap), color var(--transition-snap);
}

/* Reduced-motion support — respect OS setting */
@media (prefers-reduced-motion: reduce) {
    *,*::before,*::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-mid) 100%);
    min-height: 100vh;
    color: var(--text-primary);
    overflow: hidden;
}

/* --- Scrollbar --- */
::-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); }

/* --- Header --- */
.header {
    background: linear-gradient(90deg, var(--header-start) 0%, var(--header-end) 100%);
    padding: 8px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 15px rgba(0,0,0,0.5);
    z-index: 100;
    position: relative;
    height: 52px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-left img {
    height: 34px;
    background: rgba(255,255,255,0.9);
    padding: 2px;
    border-radius: 6px;
}

.header h1 {
    font-size: 1.15em;
    font-weight: 600;
    color: #fff;
    letter-spacing: 0.5px;
}

.header h1 span {
    font-weight: 400;
    font-size: 0.72em;
    opacity: 0.8;
    display: block;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
    font-size: 0.82em;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    animation: pulse 2s infinite;
}

.status-dot.offline { background: var(--red); animation: none; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.last-update { opacity: 0.8; }
.clock-ist { font-weight: 600; color: var(--cyan); }

/* --- Navigation --- */
.nav-bar {
    display: flex;
    background: rgba(0, 0, 0, 0.4);
    padding: 0 20px;
    border-bottom: 1px solid var(--border-subtle);
    height: 38px;
    align-items: stretch;
}

.nav-link {
    padding: 0 22px;
    display: flex;
    align-items: center;
    cursor: pointer;
    border: none;
    background: transparent;
    color: #888;
    font-size: 0.85em;
    font-weight: 500;
    transition: all 0.3s;
    border-bottom: 3px solid transparent;
    text-decoration: none;
    white-space: nowrap;
}

.nav-link:hover { color: #fff; background: rgba(255,255,255,0.05); }
.nav-link.active { color: var(--gold); border-bottom-color: var(--gold); background: rgba(255,215,0,0.08); }

/* --- Stat Cards --- */
.stats-grid {
    display: grid;
    gap: 10px;
    padding: 10px;
}

.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(255,215,0,0.3);
    background: var(--bg-card-hover);
}

.stat-card .value {
    font-size: 1.7em;
    font-weight: 700;
    color: var(--gold);
    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.iitm .value { color: var(--gold); }
.stat-card.danger .value { color: var(--red); }
.stat-card.info .value { color: var(--cyan); }
.stat-card.success .value { color: var(--green); }

/* --- 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 Toggle --- */
.source-toggle {
    padding: 8px 12px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.source-toggle label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    padding: 4px 10px;
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    font-size: 0.78em;
    transition: all 0.2s;
}

.source-toggle label:hover {
    border-color: var(--accent);
    background: rgba(0,188,212,0.08);
}

.source-toggle input[type="radio"] { display: none; }
.source-toggle input[type="radio"]:checked + label {
    border-color: var(--accent);
    background: rgba(0,188,212,0.15);
    color: #fff;
}

.source-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.source-dot.iitm { background: var(--gold); }

/* --- Time Filter Buttons --- */
.time-filter {
    padding: 6px 12px;
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.time-btn {
    padding: 4px 10px;
    border: 1px solid rgba(255,215,0,0.3);
    border-radius: 14px;
    background: transparent;
    color: #ccc;
    font-size: 0.75em;
    cursor: pointer;
    transition: all 0.2s;
}

.time-btn:hover { background: rgba(255,215,0,0.15); color: #fff; }
.time-btn.active { background: rgba(255,215,0,0.25); color: var(--gold); border-color: var(--gold); }

/* --- Live rolling buttons (1m, 5m) — distinct green styling with pulse --- */
.time-btn.live-mode { border-color: rgba(105,240,174,0.5); position: relative; padding-left: 18px; }
.time-btn.live-mode::before {
    content: ""; position: absolute; left: 7px; top: 50%;
    width: 6px; height: 6px; border-radius: 50%;
    background: #69f0ae; transform: translateY(-50%);
    box-shadow: 0 0 6px #69f0ae; animation: timebtn-pulse 1s infinite;
}
.time-btn.live-mode.active { background: rgba(105,240,174,0.25); color: #69f0ae; border-color: #69f0ae; }
.time-btn.live-mode:hover { background: rgba(105,240,174,0.15); color: #fff; }
@keyframes timebtn-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* --- Tables --- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78em;
}

.data-table th {
    position: sticky;
    top: 0;
    background: rgba(13, 27, 42, 0.95);
    padding: 7px 6px;
    text-align: left;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.82em;
    opacity: 0.7;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.data-table td {
    padding: 5px 6px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    white-space: nowrap;
}

.data-table tr:hover td {
    background: rgba(255,215,0,0.05);
}

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.82em;
    font-weight: 600;
}

.badge-cg { background: rgba(255,215,0,0.2); color: var(--gold); }
.badge-ic { background: rgba(255,152,0,0.2); color: var(--orange); }
.badge-cc { background: rgba(244,67,54,0.2); color: var(--ic-color); }

.badge-iitm { background: rgba(255,215,0,0.18); color: var(--gold); }
.badge-unknown { background: rgba(180,180,180,0.18); color: var(--gray-strike); }

/* Alert level badges */
.alert-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.85em;
}

.alert-badge.safe { background: rgba(105,240,174,0.1); color: var(--green); }
.alert-badge.yellow { background: rgba(255,235,59,0.15); color: var(--yellow); }
.alert-badge.orange { background: rgba(255,152,0,0.15); color: var(--orange); }
.alert-badge.red { background: rgba(255,82,82,0.2); color: var(--red); animation: alertPulse 2s infinite; }

@keyframes alertPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.alert-badge .dot {
    width: 7px; height: 7px; border-radius: 50%;
}

.alert-badge.safe .dot { background: var(--green); }
.alert-badge.yellow .dot { background: var(--yellow); }
.alert-badge.orange .dot { background: var(--orange); }
.alert-badge.red .dot { background: var(--red); }

/* --- 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, 27, 42, 0.85);
    color: #ccc;
    font-size: 0.78em;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
}

.map-toggle:hover { background: rgba(13, 27, 42, 0.95); color: #fff; }
.map-toggle.active { border-color: var(--gold); color: var(--gold); }

/* --- Map Legend --- */
.map-legend {
    position: absolute;
    bottom: 28px;
    left: 10px;
    background: rgba(13, 27, 42, 0.9);
    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;
}

/* --- Panel --- */
.panel {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    overflow: hidden;
}

.panel-header {
    padding: 10px 14px;
    background: rgba(0,0,0,0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.panel-title {
    font-size: 0.85em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.panel-body { padding: 12px; }

/* --- Bottom Panel (collapsible charts) --- */
.bottom-panel {
    background: rgba(0, 0, 0, 0.35);
    border-top: 1px solid var(--border-subtle);
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1px;
    height: 180px;
    transition: height 0.3s;
    overflow: hidden;
}

.bottom-panel.collapsed { height: 0; }

.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: 8px;
}

.bottom-toggle {
    position: absolute;
    top: -16px;
    right: 20px;
    padding: 2px 14px;
    background: rgba(13, 27, 42, 0.9);
    border: 1px solid var(--border-subtle);
    border-radius: 8px 8px 0 0;
    color: #888;
    font-size: 0.7em;
    cursor: pointer;
    z-index: 5;
}

.bottom-toggle:hover { color: #fff; }

/* --- Bar Chart (CSS) --- */
.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 1px;
    height: 100%;
    padding: 0 2px;
}

.bar-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
    min-width: 6px;
}

.bar-stack {
    width: 100%;
    display: flex;
    flex-direction: column-reverse;
}

.bar-seg {
    width: 100%;
    transition: height 0.5s ease;
}

.bar-seg.iitm { background: var(--gold); }

.bar-label {
    font-size: 0.55em;
    margin-top: 2px;
    opacity: 0.5;
    white-space: nowrap;
}

/* --- Donut Chart --- */
.donut-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    height: 100%;
}

.donut-legend {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.75em;
}

.donut-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.donut-legend-item .swatch {
    width: 10px; height: 10px; border-radius: 2px;
}

/* --- Loading overlay --- */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(10, 10, 26, 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-bolt {
    font-size: 4em;
    animation: flash 1.5s infinite;
}

@keyframes flash {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.1); }
}

.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;
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .main-layout {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto 1fr;
    }
    .sidebar { max-height: 45vh; }
    .bottom-panel {
        grid-template-columns: 1fr;
        height: auto;
    }
    .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }
    .nav-bar { overflow-x: auto; }
}
