/* =============================================
 * NDAMAPS Traffic — Dark Theme UI
 * Color palette + layout + animations
 * ============================================= */

/* ========================
 * CSS Variables (Dark Theme)
 * ======================== */
:root {
    --bg-primary:     #0f1117;
    --bg-secondary:   #1a1d2e;
    --bg-tertiary:    #252840;
    --border:         #2d3148;
    --text-primary:   #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted:     #475569;
    --accent-blue:    #3b82f6;
    --accent-green:   #22c55e;
    --traffic-green:  #16a34a;
    --traffic-yellow: #ca8a04;
    --traffic-red:    #dc2626;
    --font-main:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --glass-bg:       rgba(15, 17, 23, 0.85);
    --glass-border:   rgba(45, 49, 72, 0.6);
    --transition:     all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================
 * Reset & Base
 * ======================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ========================
 * Map Container
 * ======================== */
#map {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

/* ========================
 * Glassmorphism Panel Base
 * ======================== */
.panel {
    position: absolute;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    transition: var(--transition);
    z-index: 10;
}

.panel:hover {
    border-color: rgba(59, 130, 246, 0.3);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(59, 130, 246, 0.1);
}

/* ========================
 * Stats Panel (Góc trên phải)
 * ======================== */
#stats-panel {
    top: 12px;
    right: 12px;
    min-width: 220px;
}

#stats-panel h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid rgba(45, 49, 72, 0.3);
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.stat-value {
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.stat-value.green  { color: var(--traffic-green); }
.stat-value.yellow { color: var(--traffic-yellow); }
.stat-value.red    { color: var(--traffic-red); }

/* ========================
 * Legend Panel (Góc dưới trái)
 * ======================== */
#legend-panel {
    bottom: 32px;
    left: 12px;
    min-width: 200px;
}

#legend-panel h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.gradient-bar {
    width: 100%;
    height: 10px;
    border-radius: 5px;
    background: linear-gradient(to right,
        #dc2626 0%,
        #ea580c 12%,
        #d97706 22%,
        #ca8a04 38%,
        #65a30d 55%,
        #16a34a 78%,
        #15803d 100%
    );
    margin-bottom: 4px;
}

.gradient-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.level-counts {
    display: flex;
    gap: 12px;
    font-size: 13px;
    font-weight: 600;
}

.level-count {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ========================
 * Zoom Indicator
 * ======================== */
#zoom-indicator {
    bottom: 32px;
    right: 12px;
    font-size: 12px;
    padding: 8px 14px;
    color: var(--text-secondary);
    min-width: auto;
}

#zoom-indicator .zoom-value {
    font-weight: 700;
    color: var(--accent-blue);
    font-size: 14px;
}

/* ========================
 * Update Timer
 * ======================== */
#update-timer {
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    padding: 6px 16px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

#update-timer .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-green);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ========================
 * Popup Styles
 * ======================== */
.maplibregl-popup-content {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--glass-border) !important;
    border-radius: 10px !important;
    padding: 14px !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5) !important;
    font-family: var(--font-main) !important;
    min-width: 200px;
}

.maplibregl-popup-tip {
    border-top-color: var(--bg-secondary) !important;
}

.maplibregl-popup-close-button {
    color: var(--text-secondary) !important;
    font-size: 18px !important;
    right: 6px !important;
    top: 4px !important;
}

.popup-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.popup-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 0;
    font-size: 12px;
}

.popup-row .label {
    color: var(--text-secondary);
}

.popup-row .value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.popup-level {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.popup-level.green  { background: rgba(22, 163, 74, 0.2); color: #4ade80; }
.popup-level.yellow { background: rgba(202, 138, 4, 0.2);  color: #facc15; }
.popup-level.red    { background: rgba(220, 38, 38, 0.2);  color: #f87171; }

/* ========================
 * Mini Chart (SVG)
 * ======================== */
.mini-chart {
    margin-top: 10px;
    width: 100%;
}

.mini-chart svg {
    width: 100%;
    height: 60px;
}

.chart-line {
    fill: none;
    stroke: var(--accent-blue);
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chart-area {
    fill: url(#chart-gradient);
    opacity: 0.3;
}

/* ========================
 * Loading overlay
 * ======================== */
#loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s ease;
}

#loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    margin-top: 12px;
    font-size: 14px;
    color: var(--text-secondary);
}

/* ========================
 * Responsive
 * ======================== */
@media (max-width: 480px) {
    .panel { padding: 10px; border-radius: 8px; }
    #stats-panel { top: 8px; right: 8px; min-width: 180px; }
    #legend-panel { bottom: 24px; left: 8px; min-width: 170px; }
    .level-counts { gap: 8px; font-size: 12px; }
}
