/* ============================================================
   EARTH WATCH LIVE — Design System
   Premium command-center dark theme
   ============================================================ */

/* ---------- Custom Properties ---------- */
:root {
    --accent: #38bdf8;
    --accent-dim: rgba(56, 189, 248, 0.12);
    --accent-glow: rgba(56, 189, 248, 0.2);
    --accent-solid: #0284c7;
    --bg-dark: #070a11;
    --bg-panel: rgba(12, 17, 26, 0.65);
    --bg-panel-hover: rgba(18, 25, 38, 0.85);
    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(56, 189, 248, 0.3);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-dim: #64748b;
    --red: #ef4444;
    --orange: #f97316;
    --brown: #d97706;
    --green: #22c55e;
    --blue: #3b82f6;
    --panel-w: 290px;
    --topbar-h: 52px;
    --radius: 10px;
    --radius-sm: 6px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.6);
}

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Globe Viewport ---------- */
#globeViz {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
}

/* ============================================================
   TOP BAR — Sleek Command Strip
   ============================================================ */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    z-index: 200;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    background: var(--bg-panel);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

/* Logo area */
.topbar__brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    cursor: default;
    user-select: none;
}

.topbar__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 8px #22c55e;
    animation: live-pulse 2s infinite;
}

@keyframes live-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.85); }
}

.topbar__title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-primary);
    white-space: nowrap;
}

/* Disaster badges strip */
.topbar__badges {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    justify-content: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 2px 0;
}
.topbar__badges::-webkit-scrollbar {
    display: none;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: default;
    transition: var(--transition);
    flex-shrink: 0;
}

.badge:hover {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.06);
}

.badge .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.badge__count {
    min-width: 14px;
    text-align: center;
    font-weight: 700;
    color: var(--text-primary);
}

.badge--earthquake { color: var(--text-secondary); }
.badge--wildfire { color: var(--text-secondary); }
.badge--volcano { color: var(--text-secondary); }
.badge--storm { color: var(--text-secondary); }
.badge--flood { color: var(--text-secondary); }

/* Pulse animation for live counts */
@keyframes badge-pulse {
    0% { border-color: var(--accent); }
    50% { border-color: rgba(255, 255, 255, 0.4); }
    100% { border-color: var(--border); }
}
.badge--pulse {
    animation: badge-pulse 1s ease-out;
}

/* Total events indicator */
.topbar__total {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    color: var(--text-dim);
    white-space: nowrap;
    flex-shrink: 0;
    padding-left: 8px;
    border-left: 1px solid var(--border);
}

.topbar__total strong {
    color: var(--text-primary);
    font-size: 0.8rem;
}

/* Topbar actions (panel toggles) */
.topbar__actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.topbar__btn {
    height: 32px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.topbar__btn svg {
    flex-shrink: 0;
}

.topbar__btn:hover,
.topbar__btn.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

/* ============================================================
   SIDE PANELS — Glassmorphism collapsible drawers
   ============================================================ */
.panel {
    position: fixed;
    top: calc(var(--topbar-h) + 12px);
    width: var(--panel-w);
    max-height: calc(100vh - var(--topbar-h) - 24px);
    z-index: 150;
    background: var(--bg-panel);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform var(--transition), opacity var(--transition);
    scrollbar-width: thin;
    scrollbar-color: var(--accent-dim) transparent;
}

.panel::-webkit-scrollbar {
    width: 4px;
}
.panel::-webkit-scrollbar-track {
    background: transparent;
}
.panel::-webkit-scrollbar-thumb {
    background: var(--accent-dim);
    border-radius: 4px;
}

/* Left panel — Globe Controls */
.panel--left {
    left: 12px;
}
.panel--left.collapsed {
    transform: translateX(calc(-100% - 20px));
    opacity: 0;
    pointer-events: none;
}

/* Right panel — Event Filters */
.panel--right {
    right: 12px;
}
.panel--right.collapsed {
    transform: translateX(calc(100% + 20px));
    opacity: 0;
    pointer-events: none;
}

/* Panel header */
.panel__header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 18px 12px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-panel);
    backdrop-filter: blur(24px);
    z-index: 2;
}

.panel__header-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--accent);
    flex: 1;
}

.panel__close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
}
.panel__close:hover {
    background: rgba(255, 71, 87, 0.15);
    color: var(--red);
}

/* Panel body */
.panel__body {
    padding: 12px 18px 18px;
}

/* Control groups */
.control-group {
    margin-bottom: 18px;
}

.control-group__title {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

/* Select inputs */
.control-select {
    width: 100%;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    cursor: pointer;
    transition: var(--transition);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a95a8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

.control-select:hover,
.control-select:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-dim);
}

.control-select option {
    background: var(--bg-dark);
    color: var(--text-primary);
}

/* Checkbox labels */
.control-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    margin: 4px 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.82rem;
    transition: var(--transition);
}

.control-checkbox:hover {
    background: rgba(255, 255, 255, 0.04);
}

.control-checkbox input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--text-dim);
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: var(--transition);
}

.control-checkbox input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.control-checkbox input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 10px;
    color: var(--bg-dark);
    font-weight: 700;
}

.control-checkbox .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 6px currentColor;
}

/* Range sliders */
.control-slider {
    margin: 8px 0 14px;
}

.control-slider__label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.control-slider__value {
    font-family: 'JetBrains Mono', monospace;
    color: var(--accent);
    font-weight: 600;
    font-size: 0.75rem;
}

input[type="range"] {
    width: 100%;
    height: 4px;
    appearance: none;
    -webkit-appearance: none;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg-dark);
    box-shadow: 0 0 8px var(--accent-glow);
    cursor: pointer;
    transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg-dark);
    box-shadow: 0 0 8px var(--accent-glow);
    cursor: pointer;
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 9px 16px;
    background: var(--accent-dim);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.btn-primary:hover {
    background: var(--accent);
    color: var(--bg-dark);
    box-shadow: 0 0 16px var(--accent-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    width: 100%;
    padding: 8px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-dim);
}

/* ============================================================
   FOOTER
   ============================================================ */
.app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 8px 20px;
    text-align: center;
    font-size: 0.65rem;
    color: var(--text-dim);
    background: linear-gradient(to top, rgba(10, 14, 23, 0.7), transparent);
    pointer-events: none;
}

.app-footer a {
    color: var(--text-dim);
    text-decoration: none;
    pointer-events: auto;
    transition: color var(--transition);
}

.app-footer a:hover {
    color: var(--accent);
}

/* ============================================================
   LOADING OVERLAY
   ============================================================ */
.overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.6s ease-out;
}

.overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loader-content {
    text-align: center;
}

.loader-content h1 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 2px;
    margin-bottom: 20px;
}

.spinner {
    width: 42px;
    height: 42px;
    border: 3px solid rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader-status {
    font-size: 0.72rem;
    color: var(--text-dim);
    letter-spacing: 1px;
}

/* ============================================================
   TOOLTIPS (for globe hover)
   ============================================================ */
.earthquake-tooltip,
.event-tooltip {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    color: var(--text-primary);
    pointer-events: none;
    max-width: 260px;
    box-shadow: var(--shadow);
}

.earthquake-tooltip {
    border-left: 3px solid var(--red);
}

.event-tooltip strong,
.earthquake-tooltip strong {
    color: var(--accent);
    display: block;
    margin-bottom: 4px;
}

/* ============================================================
   MOBILE OVERLAY BACKDROP
   ============================================================ */
.panel-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 140;
    opacity: 0;
    transition: opacity var(--transition);
}

.panel-backdrop.visible {
    opacity: 1;
}

/* ============================================================
   RESPONSIVE — Tablet
   ============================================================ */
@media (max-width: 1024px) {
    .panel {
        width: 280px;
    }

    .topbar__subtitle {
        display: none;
    }
}

/* ============================================================
   RESPONSIVE — Mobile
   ============================================================ */
@media (max-width: 768px) {
    :root {
        --topbar-h: 48px;
    }

    .topbar {
        padding: 0 10px;
        gap: 6px;
    }

    .topbar__brand {
        gap: 6px;
    }

    .topbar__dot {
        display: none; /* Hide green dot on mobile */
    }

    .topbar__title {
        font-size: 0.75rem;
        letter-spacing: 0.8px;
    }

    .topbar__subtitle,
    .topbar__total {
        display: none;
    }

    .topbar__badges {
        gap: 4px;
        justify-content: flex-start;
        padding-right: 4px;
    }

    .badge {
        padding: 3px 7px;
        font-size: 0.68rem;
        gap: 4px;
    }

    .topbar__btn {
        padding: 0;
        width: 32px;
        height: 32px;
        justify-content: center;
    }

    .topbar__btn .btn-text {
        display: none;
    }

    /* Panels become bottom sheets on mobile */
    .panel {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 75vh;
        border-radius: var(--radius) var(--radius) 0 0;
        transform: translateY(100%);
        opacity: 1;
        transition: transform var(--transition);
    }

    .panel--left.collapsed,
    .panel--right.collapsed {
        transform: translateY(100%);
        opacity: 1;
        pointer-events: none;
    }

    .panel--left:not(.collapsed),
    .panel--right:not(.collapsed) {
        transform: translateY(0);
        pointer-events: auto;
    }

    /* Show backdrop when panel is open */
    .panel-backdrop.visible {
        display: block;
        opacity: 1;
    }

    /* Bottom sheet handle */
    .panel__header::before {
        content: '';
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: rgba(255, 255, 255, 0.15);
        border-radius: 2px;
    }

    .panel__header {
        padding-top: 20px;
        position: relative;
    }

    .app-footer {
        display: none;
    }
}

/* ============================================================
   RESPONSIVE — Small mobile
   ============================================================ */
@media (max-width: 480px) {
    .topbar__title {
        display: none; /* Hide text on narrow phones so badges get full space */
    }

    .badge__label {
        display: none; /* Show dot + count only on very narrow screens */
    }
}

/* ============================================================
   UTILITY — Desktop-only panel toggle buttons in topbar
   ============================================================ */
@media (min-width: 769px) {
    .panel-backdrop {
        display: none !important;
    }
}

/* ============================================================
   ANIMATIONS — Entrance
   ============================================================ */
@keyframes slide-in-left {
    from { transform: translateX(-30px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slide-in-right {
    from { transform: translateX(30px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.panel--left:not(.collapsed) {
    animation: slide-in-left 0.4s ease-out;
}

.panel--right:not(.collapsed) {
    animation: slide-in-right 0.4s ease-out;
}

/* ============================================================
   SEPARATOR LINE
   ============================================================ */
.separator {
    height: 1px;
    background: var(--border);
    margin: 14px 0;
}