@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;600;800;900&family=Outfit:wght@300;400;600;700&display=swap');

:root {
    --bg-base: #080b11;
    --bg-panel: rgba(13, 20, 32, 0.7);
    --border-color: rgba(0, 242, 254, 0.15);
    --primary: #00f2fe; /* Cyan */
    --primary-glow: rgba(0, 242, 254, 0.4);
    --secondary: #4facfe; /* Blue */
    --accent: #39ff14; /* Neon Green */
    --accent-glow: rgba(57, 255, 20, 0.4);
    --warning: #ffb100; /* Amber */
    --danger: #ff0055; /* Hot Pink */
    --text-main: #f1f5f9;
    --text-muted: #64748b;
    --font-cyber: 'Orbitron', sans-serif;
    --font-body: 'Outfit', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    font-family: var(--font-body);
    overflow-x: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Background Glowing Accents */
.bg-glow {
    position: fixed;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(0, 242, 254, 0.05) 0%, rgba(0, 0, 0, 0) 70%);
    top: -200px;
    left: -200px;
    pointer-events: none;
    z-index: -1;
}

.bg-glow-alt {
    position: fixed;
    width: 800px;
    height: 800px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(79, 172, 254, 0.03) 0%, rgba(0, 0, 0, 0) 70%);
    bottom: -300px;
    right: -300px;
    pointer-events: none;
    z-index: -1;
}

/* App Header */
header {
    height: 70px;
    padding: 0 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(8, 11, 17, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
    z-index: 100;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 15px var(--primary-glow);
    animation: pulse-glow 2s infinite alternate;
}

.logo-icon svg {
    width: 22px;
    height: 22px;
    fill: #080b11;
}

.logo-text h1 {
    font-family: var(--font-cyber);
    font-size: 1.3rem;
    font-weight: 900;
    letter-spacing: 1px;
    background: linear-gradient(to right, #ffffff, var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-text span {
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 2px;
    text-transform: uppercase;
    display: block;
    margin-top: -2px;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 20px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    background: rgba(255, 255, 255, 0.03);
    padding: 6px 14px;
    border-radius: 30px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
    display: inline-block;
}

.dot.pulse {
    animation: flash 1.5s infinite;
}

.dot.offline {
    background-color: var(--danger);
    box-shadow: 0 0 8px rgba(255, 0, 85, 0.5);
}

/* Dashboard Grid Layout */
.dashboard-container {
    flex: 1;
    display: grid;
    grid-template-columns: 320px 1fr 400px;
    padding: 20px;
    gap: 20px;
    height: calc(100vh - 70px);
    overflow: hidden;
}

/* Sidebar: CCTV Directory */
.sidebar {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    padding: 15px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-title {
    font-family: var(--font-cyber);
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 1px;
    color: var(--primary);
    text-transform: uppercase;
}

.search-box {
    margin: 10px 12px;
    position: relative;
}

.search-box input {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 0.82rem;
    transition: all 0.25s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 8px rgba(0, 242, 254, 0.2);
}

.cctv-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 10px 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* --- CCTV List Card --- */
.cctv-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-left: 3px solid transparent;
    border-radius: 8px;
    padding: 9px 12px 9px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 3px;
    /* NO overflow:hidden — prevents badge clip */
}

.cctv-card:hover {
    background: rgba(0, 242, 254, 0.04);
    border-left-color: rgba(0, 242, 254, 0.6);
    box-shadow: 2px 0 0 0 rgba(0, 242, 254, 0.15);
}

.cctv-card.active {
    background: rgba(0, 242, 254, 0.06);
    border-left-color: var(--primary);
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.07);
}

.cctv-card.active::before {
    display: none;
}

/* Row 1: name (left, truncated) + badge (right, never cut) */
.cctv-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    width: 100%;
    min-width: 0;
}

.cctv-name {
    flex: 1 1 0;
    min-width: 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Row 2: sub-label region */
.cctv-sub {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-left: 2px;
}

/* Status badge — pill, readable, never shrinks */
.badge {
    flex: 0 0 auto;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 20px;
    line-height: 1.5;
    white-space: nowrap;
}

.badge.online {
    background: rgba(74, 222, 128, 0.12);
    color: #4ade80;
    border: 1px solid rgba(74, 222, 128, 0.3);
}

.badge.offline {
    background: rgba(251, 113, 133, 0.12);
    color: #fb7185;
    border: 1px solid rgba(251, 113, 133, 0.3);
}

/* Center Column: Radar Screen & Feed */
.main-screen {
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto; /* Enable scroll if height exceeds dashboard grid */
}

/* Live Stream Video and AI Overlay */
.video-radar-container {
    flex: none; /* Prevent browser from squeezing the monitor */
    width: 100%;
    aspect-ratio: 4 / 3; /* Standard 4:3 CCTV Aspect Ratio */
    background: #000;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}

.video-element {
    width: 100%;
    height: 100%;
    object-fit: fill; /* Fit exactly without cropping or letterbox black bars */
    display: block;
}

.canvas-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
}

/* Cybernetic Radar Interface elements */
.radar-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 2px solid rgba(0, 242, 254, 0.05);
    pointer-events: none;
    z-index: 5;
    background: 
        linear-gradient(rgba(0, 242, 254, 0.02) 1px, transparent 1px) 0 0 / 40px 40px,
        linear-gradient(90deg, rgba(0, 242, 254, 0.02) 1px, transparent 1px) 0 0 / 40px 40px;
}

/* Sweep Line Animation */
.radar-sweep {
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(0, 242, 254, 0.08) 80%, rgba(0, 242, 254, 0.25) 98%, #ffffff 100%);
    pointer-events: none;
    z-index: 6;
    animation: sweep 4s infinite linear;
}

.radar-vignette {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.85);
    pointer-events: none;
    z-index: 8;
}

/* Target Reticles */
.radar-target {
    position: absolute;
    width: 40px;
    height: 40px;
    border: 1px solid var(--primary);
    pointer-events: none;
    z-index: 7;
}

.radar-target::before, .radar-target::after {
    content: '';
    position: absolute;
    background-color: var(--primary);
}

/* Sensor Feed Title Badge (Always High Contrast & Readable over Video) */
.sensor-feed-title {
    position: absolute;
    top: 12px;
    left: 14px;
    z-index: 25;
    background: rgba(8, 15, 28, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(0, 242, 254, 0.3);
    padding: 5px 12px;
    border-radius: 8px;
    font-family: var(--font-cyber);
    font-size: 0.78rem;
    color: #f8fafc;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    max-width: 80%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

body.light-theme .sensor-feed-title {
    background: rgba(255, 255, 255, 0.92);
    border-color: rgba(2, 132, 199, 0.3);
    color: #0f172a;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

/* AI Stream Toolbar Controls (Desktop Compact & Sleek) */
.video-toolbar {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(8, 15, 28, 0.92);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 6px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 20;
    box-shadow: 0 4px 20px rgba(0,0,0,0.6);
}

body.light-theme .video-toolbar {
    background: rgba(255, 255, 255, 0.94);
    border-color: rgba(15, 23, 42, 0.15);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.btn-control {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-family: var(--font-cyber);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 6px 12px;
    border-radius: 8px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.video-toolbar .btn-control {
    padding: 5px 12px !important;
    font-size: 0.7rem !important;
    gap: 5px !important;
    border-radius: 8px !important;
}

.btn-control svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.btn-control:hover {
    color: var(--primary);
    background: rgba(0, 242, 254, 0.06);
    border-color: rgba(0, 242, 254, 0.4);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 242, 254, 0.15);
}

.btn-control:active {
    transform: scale(0.97);
}

.btn-control.active {
    color: #080b11;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-color: transparent;
    box-shadow: 0 0 14px var(--primary-glow);
}

.btn-control.active-green {
    color: #080b11;
    background: linear-gradient(135deg, var(--accent), #22c55e);
    border-color: transparent;
    box-shadow: 0 0 14px var(--accent-glow);
}

.sensor-feed-title {
    position: absolute;
    top: 20px;
    left: 20px;
    font-family: var(--font-cyber);
    font-size: 0.85rem;
    background: rgba(8, 15, 28, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    padding: 6px 15px;
    border-radius: 8px;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: 1px;
}

/* Map Section */
.map-container {
    height: 250px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
    background: #0d131f;
}

/* Leaflet Dark Theme Overrides */
.leaflet-container {
    background-color: #0d131f !important;
}

.leaflet-tile {
    filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
}

/* Right Column: AI Traffic Analytics */
.analytics-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 20px;
    overflow-y: auto;
}

.analytics-panel > * {
    flex-shrink: 0; /* Prevent flex children from shrinking, forcing vertical scroll */
}

/* Big Stats Density Widget */
.density-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.density-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
}

.density-value-container {
    margin: 10px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.density-number {
    font-family: var(--font-cyber);
    font-size: 2.8rem;
    font-weight: 900;
    line-height: 1;
    color: var(--primary);
    text-shadow: 0 0 15px var(--primary-glow);
}

.density-status {
    font-family: var(--font-cyber);
    font-size: 0.95rem;
    font-weight: 800;
    text-transform: uppercase;
    margin-top: 5px;
    letter-spacing: 1px;
}

.status-smooth { color: var(--accent); text-shadow: 0 0 10px var(--accent-glow); }
.status-moderate { color: var(--warning); text-shadow: 0 0 10px rgba(255, 177, 0, 0.4); }
.status-heavy { color: var(--danger); text-shadow: 0 0 10px rgba(255, 0, 85, 0.4); }

.density-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

/* Counters Grid */
.counters-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.counter-item {
    background: rgba(255, 255, 255, 0.015);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 10px;
    padding: 15px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.3s;
}

.counter-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    border: 1px solid rgba(255,255,255,0.05);
}

.counter-item:hover .counter-icon {
    background: rgba(0, 242, 254, 0.05);
    color: var(--primary);
    border-color: rgba(0, 242, 254, 0.2);
}

.counter-value {
    font-family: var(--font-cyber);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-main);
}

.counter-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Charts Card */
.chart-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.chart-wrapper {
    position: relative;
    height: 180px;
    width: 100%;
}

/* Loading Overlay for model */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(8, 11, 17, 0.9);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    border-radius: 16px;
    transition: opacity 0.5s;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(0, 242, 254, 0.1);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s infinite linear;
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.1);
}

.loading-text {
    font-family: var(--font-cyber);
    font-size: 0.9rem;
    color: var(--primary);
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* Animations */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes sweep {
    0% { left: -100%; }
    50% { left: 100%; }
    100% { left: 100%; }
}

@keyframes flash {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

@keyframes pulse-glow {
    0% {
        box-shadow: 0 0 10px rgba(0, 242, 254, 0.2);
    }
    100% {
        box-shadow: 0 0 20px rgba(0, 242, 254, 0.6);
    }
}

/* Responsive Overrides */
@media (max-width: 1200px) {
    .dashboard-container {
        grid-template-columns: 280px 1fr;
        grid-template-rows: auto auto;
        height: auto;
        overflow: visible;
    }
    .analytics-panel {
        grid-column: span 2;
        overflow: visible;
        height: auto;
    }
}

/* Responsive Mobile Layout (Pure 1-Column Mobile Experience) */
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        position: relative;
    }

    /* Clean Mobile Header */
    header {
        height: auto !important;
        min-height: 56px !important;
        padding: 8px 12px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        background: rgba(8, 11, 17, 0.95);
        position: relative !important;
        z-index: 120 !important;
        border-bottom: 1px solid var(--border-color) !important;
    }

    .logo-container {
        gap: 8px !important;
    }

    .logo-icon {
        width: 32px !important;
        height: 32px !important;
    }

    .logo-text h1 {
        font-size: 1.0rem !important;
        letter-spacing: 0.5px !important;
    }

    .logo-text span {
        font-size: 0.6rem !important;
        letter-spacing: 1px !important;
    }

    .header-status {
        display: flex !important;
        align-items: center !important;
        gap: 5px !important;
        margin-left: auto !important;
    }

    /* Compact Header Icon-Only Buttons on Mobile */
    .header-status .btn-control {
        padding: 6px 8px !important;
        border-radius: 8px !important;
        justify-content: center !important;
        gap: 0 !important;
    }

    .header-status .btn-control span,
    .header-status #theme-text {
        display: none !important;
    }

    .header-status .btn-control svg {
        margin-right: 0 !important;
        width: 15px !important;
        height: 15px !important;
    }

    .status-indicator {
        padding: 4px 8px !important;
        font-size: 0.7rem !important;
    }

    /* Weather Marquee Positioned Cleanly Under Header */
    .weather-marquee-container {
        position: relative !important;
        z-index: 110 !important;
        width: 100% !important;
        box-sizing: border-box !important;
        border-bottom: 1px solid var(--border-color) !important;
    }

    /* Single Column Mobile Dashboard Container */
    .dashboard-container {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        height: auto !important;
        padding: 8px !important;
        gap: 14px !important;
        box-sizing: border-box !important;
    }

    /* Order 1: Main Stream Screen */
    .main-screen {
        order: 1 !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Order 2: Right Analytics Panel */
    .analytics-panel {
        order: 2 !important;
        width: 100% !important;
        grid-column: span 1 !important;
        box-sizing: border-box !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }

    /* Order 3: Camera Sidebar at Bottom */
    .sidebar {
        order: 3 !important;
        width: 100% !important;
        height: 360px !important;
        grid-column: span 1 !important;
        box-sizing: border-box !important;
    }

    /* Sensor Feed Title Badge Mobile Scale */
    .sensor-feed-title {
        top: 8px !important;
        left: 8px !important;
        padding: 3px 8px !important;
        font-size: 0.68rem !important;
        max-width: 85% !important;
    }

    /* Video Overlay Control Bar Fix (Compact & High Contrast) */
    .video-toolbar {
        position: absolute !important;
        bottom: 8px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: 96% !important;
        max-width: 350px !important;
        padding: 3px 5px !important;
        gap: 3px !important;
        border-radius: 16px !important;
        justify-content: space-around !important;
        background: rgba(15, 23, 42, 0.94) !important;
        border: 1px solid rgba(0, 242, 254, 0.3) !important;
        box-sizing: border-box !important;
    }

    body.light-theme .video-toolbar {
        background: rgba(255, 255, 255, 0.96) !important;
        border: 1px solid rgba(15, 23, 42, 0.18) !important;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15) !important;
    }

    .video-toolbar .btn-control {
        padding: 4px 5px !important;
        font-size: 0.6rem !important;
        font-weight: 800 !important;
        border-radius: 6px !important;
        gap: 2px !important;
        letter-spacing: 0 !important;
    }

    body.light-theme .video-toolbar .btn-control {
        background: rgba(15, 23, 42, 0.06) !important;
        color: #0f172a !important;
        border-color: rgba(15, 23, 42, 0.12) !important;
    }

    body.light-theme .video-toolbar .btn-control.active {
        background: #0284c7 !important;
        color: #ffffff !important;
        border-color: #0284c7 !important;
    }

    .video-toolbar .btn-control svg {
        width: 11px !important;
        height: 11px !important;
    }

    /* Multi-column Inline Layout Conversion to Pure 1-Column Stack */
    .apace-dashboard-container div[style*="grid-template-columns"],
    div[style*="grid-template-columns: 1fr 1fr"],
    div[style*="grid-template-columns: 1.2fr 1fr"] {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* Instant Speed Metrics Wrapping */
    div[style*="justify-content: space-around"] {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    /* Time Range Creator Form Mobile Vertical Stack */
    .rekap-creator-form {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }

    .rekap-creator-form > div {
        width: 100% !important;
        min-width: 100% !important;
    }

    .rekap-creator-form button {
        width: 100% !important;
        justify-content: center !important;
    }

    /* Table Container Responsive Wrapper */
    .chart-card > div[style*="overflow-x: auto"] {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        margin-top: 10px;
        border-radius: 8px;
        border: 1px solid var(--border-color);
    }

    .chart-card table {
        width: 100% !important;
        min-width: 520px !important;
        font-size: 0.72rem !important;
    }

    .chart-card th, .chart-card td {
        padding: 6px 8px !important;
        white-space: nowrap !important;
    }
}

/* Light Theme Styling System Override */
body.light-theme {
    --bg-base: #f8fafc;
    --bg-panel: rgba(255, 255, 255, 0.85);
    --border-color: rgba(15, 23, 42, 0.08);
    --primary: #0284c7; /* Dark Cyan/Blue */
    --primary-glow: rgba(2, 132, 199, 0.2);
    --secondary: #0369a1;
    --accent: #16a34a; /* Green */
    --accent-glow: rgba(22, 163, 74, 0.2);
    --text-main: #0f172a;
    --text-muted: #64748b;
}

body.light-theme header {
    background: rgba(255, 255, 255, 0.95) !important;
    border-bottom: 1px solid rgba(15, 23, 42, 0.1) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

body.light-theme .header-status .btn-control {
    background: rgba(15, 23, 42, 0.05) !important;
    border-color: rgba(15, 23, 42, 0.12) !important;
    color: #334155 !important;
}

body.light-theme .header-status .btn-control:hover {
    background: rgba(2, 132, 199, 0.1) !important;
    color: #0284c7 !important;
    border-color: #0284c7 !important;
}

body.light-theme .status-indicator {
    background: rgba(15, 23, 42, 0.04) !important;
    border-color: rgba(15, 23, 42, 0.1) !important;
}

body.light-theme #cctv-status-text {
    color: #0284c7 !important;
}

body.light-theme .logo-text h1 {
    background: linear-gradient(to right, #0f172a, #0284c7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

body.light-theme .cctv-card {
    background: rgba(248, 250, 252, 0.8);
    border: 1px solid rgba(15, 23, 42, 0.06);
    border-left: 2px solid transparent;
}

body.light-theme .cctv-card:hover {
    background: rgba(2, 132, 199, 0.04);
    border-color: rgba(2, 132, 199, 0.2);
    border-left-color: rgba(2, 132, 199, 0.5);
}

body.light-theme .cctv-card.active {
    background: rgba(2, 132, 199, 0.07);
    border-color: rgba(2, 132, 199, 0.2);
    border-left: 2px solid #0284c7;
    box-shadow: 0 0 12px rgba(2, 132, 199, 0.08);
}

body.light-theme .counter-item {
    background: rgba(0, 0, 0, 0.015);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

body.light-theme .counter-icon {
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

body.light-theme .loading-overlay {
    background: rgba(248, 250, 252, 0.95);
}

body.light-theme .video-toolbar {
    background: rgba(248, 250, 252, 0.9);
}

/* Fullscreen Monitor Viewport Styling */
#video-box:fullscreen,
#video-box:-webkit-full-screen,
#video-box.fullscreen-active {
    width: 100vw !important;
    height: 100vh !important;
    border-radius: 0 !important;
    border: none !important;
    background: #000000 !important;
    box-shadow: none !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
}

#video-box:fullscreen .video-element,
#video-box:-webkit-full-screen .video-element,
#video-box.fullscreen-active .video-element {
    object-fit: contain !important;
    width: 100vw !important;
    height: 100vh !important;
    background: #000000 !important;
}

#video-box:fullscreen .canvas-overlay,
#video-box:-webkit-full-screen .canvas-overlay,
#video-box.fullscreen-active .canvas-overlay {
    width: 100vw !important;
    height: 100vh !important;
}

body.light-theme .sensor-feed-title {
    background: rgba(248, 250, 252, 0.9);
}

body.light-theme .btn-control {
    color: var(--text-main);
}

body.light-theme .btn-control.active {
    color: #ffffff;
    background: var(--primary);
}

body.light-theme .btn-control.active-green {
    color: #ffffff;
    background: var(--accent);
}

body.light-theme .search-box input {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(15, 23, 42, 0.1);
}

body.light-theme select, body.light-theme #wa-phone {
    background: rgba(255, 255, 255, 0.9) !important;
    border-color: rgba(15, 23, 42, 0.1) !important;
}

/* High-Contrast App Footer Bar */
.app-footer-bar {
    padding: 14px 30px;
    background: #0f172a !important;
    border-top: 2px solid #00f2fe !important;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.92rem;
    z-index: 100;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
}

.footer-label {
    color: #94a3b8 !important;
    font-weight: 500;
}

.footer-author-link {
    color: #00f2fe !important;
    font-weight: 800;
    font-family: var(--font-cyber);
    font-size: 0.95rem;
    text-decoration: none;
    border-bottom: 2px dashed #00f2fe;
    padding-bottom: 1px;
    margin-left: 6px;
    transition: all 0.3s;
}

.footer-author-link:hover {
    color: #ffffff !important;
    border-color: #ffffff;
    text-shadow: 0 0 10px rgba(0, 242, 254, 0.8);
}

.footer-source-text {
    color: #ffffff !important;
    font-weight: 800;
    margin-left: 6px;
    letter-spacing: 0.5px;
}

body.light-theme .app-footer-bar {
    background: #ffffff !important;
    border-top-color: #0284c7 !important;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
}

body.light-theme .footer-label {
    color: #475569 !important;
}

body.light-theme .footer-author-link {
    color: #0284c7 !important;
    border-bottom-color: #0284c7;
}

body.light-theme .footer-source-text {
    color: #0f172a !important;
}

body.light-theme .bg-glow {
    background: radial-gradient(circle, rgba(2, 132, 199, 0.04) 0%, rgba(0, 0, 0, 0) 70%);
}

/* Weather Marquee */
.weather-marquee-container {
    display: flex;
    align-items: center;
    background: #eef2f6;
    border-bottom: 1px solid var(--border-color);
    height: 35px;
    font-size: 0.85rem;
    font-family: var(--font-body);
}

body:not(.light-theme) .weather-marquee-container {
    background: rgba(8, 11, 17, 0.95);
    color: var(--text-main);
    border-bottom: 1px solid rgba(0, 242, 254, 0.2);
}

body.light-theme .weather-marquee-container {
    background: #f1f5f9;
    color: #334155;
    border-bottom: 1px solid #cbd5e1;
}

.weather-label {
    background: #0f172a;
    color: #fff;
    padding: 0 20px;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    letter-spacing: 1px;
    z-index: 10;
}

body:not(.light-theme) .weather-label {
    background: #020617;
    color: var(--primary);
    border-right: 1px solid rgba(0, 242, 254, 0.3);
}

.weather-label svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.weather-marquee {
    flex: 1;
    overflow: hidden;
    display: flex;
    align-items: center;
}

.weather-marquee marquee {
    width: 100%;
    padding-top: 4px;
}

.weather-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 40px;
}

.weather-item .kecamatan {
    font-weight: 700;
    color: #334155;
}

body:not(.light-theme) .weather-item .kecamatan {
    color: #e2e8f0;
}

.weather-item .temp {
    font-weight: 700;
}

.weather-item .desc {
    color: #64748b;
}

.weather-item .dot {
    color: #94a3b8;
    margin-left: 40px;
    font-size: 0.5rem;
}

.weather-marquee {
    position: relative;
    white-space: nowrap;
}

.ticker-content {
    display: inline-block;
    padding-left: 100%;
    animation: marquee-scroll 35s linear infinite;
    will-change: transform;
}

.ticker-content:hover {
    animation-play-state: paused;
}

@keyframes marquee-scroll {
    0% {
        transform: translate3d(0, 0, 0);
    }
    100% {
        transform: translate3d(-100%, 0, 0);
    }
}

#region-filter option { 
    background-color: var(--bg-panel, #1e293b); 
    color: var(--text-main, #ffffff); 
}

/* APACE Analytics Dashboard Light Theme Overrides */
body.light-theme .apace-dashboard-container {
    background: #ffffff !important;
    border-color: rgba(2, 132, 199, 0.2) !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05) !important;
    color: #0f172a !important;
}

body.light-theme .apace-dashboard-container div[style*="background: rgba(8, 11, 17, 0.8)"],
body.light-theme .apace-dashboard-container div[style*="background: rgba(15, 23, 42, 0.9)"] {
    background: #f8fafc !important;
    border-color: rgba(2, 132, 199, 0.15) !important;
}

body.light-theme .apace-ring-card {
    background: #f1f5f9 !important;
    border-color: rgba(2, 132, 199, 0.15) !important;
    color: #0f172a !important;
}

body.light-theme .apace-total-card {
    background: #f1f5f9 !important;
    border-color: rgba(2, 132, 199, 0.2) !important;
    color: #0f172a !important;
}

body.light-theme .ring-circle {
    background: #ffffff !important;
    color: #0f172a !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

body.light-theme .apace-dashboard-container h3,
body.light-theme .apace-dashboard-container h4 {
    color: #0284c7 !important;
}

body.light-theme .apace-dashboard-container span[style*="color: #94a3b8"],
body.light-theme .apace-dashboard-container div[style*="color: #94a3b8"] {
    color: #475569 !important;
}

/* =========================================================================
   PREMIUM SYSTEMS STYLING: TOASTS, LIGHTBOX & PRINTING
   ========================================================================= */

.alert-toast-container {
    position: fixed;
    bottom: 90px;
    right: 30px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 9999;
    pointer-events: none;
}
.alert-toast {
    pointer-events: auto;
    background: rgba(255, 0, 85, 0.15);
    border: 1px solid rgba(255, 0, 85, 0.5);
    border-radius: 12px;
    padding: 15px;
    width: 320px;
    color: #fff;
    font-family: var(--font-body);
    box-shadow: 0 8px 32px rgba(255, 0, 85, 0.25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: all 0.4s ease;
    animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
    from { transform: translateX(50px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
.toast-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.toast-title {
    font-weight: 800;
    font-family: var(--font-cyber);
    font-size: 0.8rem;
    color: var(--danger);
    letter-spacing: 0.5px;
}
.toast-close-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    font-size: 0.75rem;
}
.toast-close-btn:hover {
    color: #fff;
}
.toast-body {
    font-size: 0.8rem;
    line-height: 1.4;
}

/* Light theme overrides for toast alerts */
body.light-theme .alert-toast {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.4);
    color: #0f172a;
    box-shadow: 0 8px 32px rgba(239, 68, 68, 0.15);
}
body.light-theme .toast-close-btn {
    color: rgba(15, 23, 42, 0.6);
}

.lightbox-modal {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(8, 11, 17, 0.95);
    z-index: 999999;
    display: none;
    align-items: center;
    justify-content: center;
}
.lightbox-content {
    width: 90%;
    max-width: 640px;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(0, 242, 254, 0.25);
    border-radius: 16px;
    padding: 20px;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
    animation: zoomIn 0.25s ease-out;
}
@keyframes zoomIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
.lightbox-close {
    position: absolute;
    top: -15px; right: -15px;
    background: #ff0055;
    border: none;
    color: #fff;
    width: 30px; height: 30px;
    border-radius: 50%;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 10px rgba(255, 0, 85, 0.5);
}

body.light-theme .lightbox-modal {
    background: rgba(248, 250, 252, 0.95);
}
body.light-theme .lightbox-content {
    background: #ffffff;
    border-color: rgba(2, 132, 199, 0.2);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}
body.light-theme #lightbox-caption {
    color: #0f172a !important;
}

/* Executive A4 Landscape printing style updates */
@media print {
    .dashboard-container, header, .weather-marquee-container, .app-footer-bar, .print-bar, .no-print {
        display: none !important;
    }
    body {
        background-color: #ffffff !important;
        color: #000000 !important;
    }
    .document-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }
}
/* Modern Fields (Selects and Inputs) Design System */
.modern-select, .modern-input {
    background-color: rgba(15, 23, 42, 0.6) !important;
    border: 1px solid rgba(0, 242, 254, 0.2) !important;
    color: var(--text-main) !important;
    font-family: var(--font-body) !important;
    font-size: 0.8rem !important;
    padding: 8px 12px !important;
    border-radius: 10px !important;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
}

.modern-select {
    cursor: pointer;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2300f2fe'%3e%3cpath d='M7 10l5 5 5-5z'/%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-position: right 10px center !important;
    background-size: 16px !important;
    padding-right: 32px !important;
}

.modern-select option {
    background: #0f172a;
    color: #fff;
}

.modern-select:hover, .modern-input:hover {
    border-color: rgba(0, 242, 254, 0.45) !important;
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.15);
}

.modern-select:focus, .modern-input:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 12px var(--primary-glow);
    background-color: rgba(15, 23, 42, 0.85) !important;
}

body.light-theme .modern-select, body.light-theme .modern-input {
    background-color: #ffffff !important;
    border: 1px solid rgba(15, 23, 42, 0.12) !important;
    color: #0f172a !important;
    box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

body.light-theme .modern-select {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%230284c7'%3e%3cpath d='M7 10l5 5 5-5z'/%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-position: right 10px center !important;
    background-size: 16px !important;
}

body.light-theme .modern-select option {
    background: #ffffff;
    color: #0f172a;
}

body.light-theme .modern-select:hover, body.light-theme .modern-input:hover {
    border-color: rgba(2, 132, 199, 0.4) !important;
    box-shadow: 0 0 8px rgba(2, 132, 199, 0.1);
}

body.light-theme .modern-select:focus, body.light-theme .modern-input:focus {
    border-color: #0284c7 !important;
    box-shadow: 0 0 10px rgba(2, 132, 199, 0.2);
}
