/* Core Variables & Reset */
:root {
    --hud-bg: rgba(10, 15, 25, 0.7);
    --hud-border: rgba(45, 136, 255, 0.3);
    --hud-cyan: #00d2ff;
    --hud-pink: #ff4757;
    --hud-text: #e0e6ed;
    --hud-glow: 0 0 10px rgba(0, 210, 255, 0.5);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body,
html {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-color: #000;
    font-family: 'Inter', sans-serif;
    color: var(--hud-text);
}

/* Typography Helpers */
.mono {
    font-family: 'Share Tech Mono', monospace;
}

/* 3D Globe Container */
#globe-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    /* Below UI */
}

/* Hide Cesium Default Credit UI */
.cesium-viewer-bottom {
    display: none !important;
}

/* ---- Top Header Bar ---- */
.hud-header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0) 100%);
    border-bottom: 1px solid var(--hud-border);
    backdrop-filter: blur(2px);
}

.hud-logo {
    font-size: 1.5rem;
    font-weight: 800;
    font-family: 'Share Tech Mono', monospace;
    letter-spacing: 2px;
    color: #fff;
    text-shadow: var(--hud-glow);
    display: flex;
    align-items: center;
    gap: 10px;
}

.hud-search {
    position: relative;
    width: 300px;
}

.hud-search input {
    width: 100%;
    background: rgba(0, 50, 100, 0.2);
    border: 1px solid var(--hud-border);
    border-radius: 20px;
    padding: 8px 50px 8px 35px; /* Added extra right padding for the GO button */
    color: #fff;
    font-family: 'Inter', sans-serif;
    outline: none;
    transition: all 0.3s;
}

.hud-search input:focus {
    border-color: var(--hud-cyan);
    box-shadow: 0 0 8px rgba(0, 210, 255, 0.3);
}

.hud-search i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--hud-cyan);
    opacity: 0.7;
}

.search-btn {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 210, 255, 0.1);
    color: var(--hud-cyan);
    border: 1px solid rgba(0, 210, 255, 0.3);
    border-radius: 15px;
    padding: 4px 12px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.75rem;
    font-weight: bold;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s;
}

.search-btn:hover {
    background: var(--hud-cyan);
    color: #000;
    box-shadow: 0 0 10px rgba(0, 210, 255, 0.6);
}

.settings-btn {
    background: transparent;
    color: var(--hud-cyan);
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    opacity: 0.8;
}

.settings-btn:hover {
    opacity: 1;
    text-shadow: 0 0 10px rgba(0, 210, 255, 0.6);
}

/* Demo Toggle Button */
.demo-btn {
    margin-left: 10px;
    padding: 6px 14px;
    background: rgba(255, 71, 87, 0.15);
    border: 1px solid var(--hud-pink);
    color: var(--hud-pink);
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.85rem;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    text-shadow: 0 0 5px rgba(255, 71, 87, 0.5);
    box-shadow: 0 0 10px rgba(255, 71, 87, 0.2);
}

.demo-btn:hover:not(.active) {
    background: rgba(255, 71, 87, 0.3);
    box-shadow: 0 0 15px rgba(255, 71, 87, 0.4);
}

.demo-btn.active {
    background: rgba(46, 213, 115, 0.15);
    border-color: #2ed573;
    color: #2ed573;
    text-shadow: 0 0 5px rgba(46, 213, 115, 0.5);
    box-shadow: 0 0 15px rgba(46, 213, 115, 0.3);
    animation: demoPulse 2s infinite;
}

@keyframes demoPulse {
    0% {
        box-shadow: 0 0 5px rgba(46, 213, 115, 0.2);
    }
    50% {
        box-shadow: 0 0 20px rgba(46, 213, 115, 0.6);
    }
    100% {
        box-shadow: 0 0 5px rgba(46, 213, 115, 0.2);
    }
}

.demo-volume-slider {
    width: 80px;
    margin-left: 10px;
    accent-color: var(--hud-cyan);
    cursor: pointer;
    display: none; /* Hidden until Demo is ON */
}

.hud-status {
    display: flex;
    align-items: center;
    gap: 20px;
}

.status-indicator {
    --status-color: #2ed573;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 1px;
    color: var(--hud-cyan);
}

.status-indicator.offline {
    --status-color: #ff4757;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background-color: var(--status-color);
    border-radius: 50%;
    box-shadow: 0 0 5px var(--status-color);
    animation: flash 2s infinite;
}

@keyframes flash {
    0% {
        opacity: 1;
        box-shadow: 0 0 8px var(--status-color);
    }

    50% {
        opacity: 0.2;
        box-shadow: 0 0 2px var(--status-color);
    }

    100% {
        opacity: 1;
        box-shadow: 0 0 8px var(--status-color);
    }
}

/* ---- Side Panels ---- */
.hud-panel {
    position: absolute;
    top: 80px;
    width: 320px;
    background: var(--hud-bg);
    border: 1px solid var(--hud-border);
    border-radius: 8px;
    backdrop-filter: blur(8px);
    z-index: 10;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.panel-left {
    left: 20px;
    height: calc(100vh - 100px);
    max-height: calc(100vh - 100px);
    transition: max-height 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-left.collapsed {
    max-height: 48px; /* Height of the title bar to hide content */
}

/* Ensure the title bar doesn't shrink during collapse */
.panel-left .panel-title {
    flex-shrink: 0;
}

.panel-right {
    right: 20px;
    width: 280px;
}

.panel-title {
    font-family: 'Share Tech Mono', monospace;
    font-size: 1rem;
    padding: 12px 15px;
    background: rgba(0, 0, 0, 0.4);
    border-bottom: 1px solid var(--hud-border);
    color: var(--hud-cyan);
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.panel-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px;
    flex: 1;
    min-height: 0;
}

/* Layer Toggle Items */
.layer-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin-bottom: 8px;
}

.layer-item {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 0;
    background: rgba(10, 25, 30, 0.6);
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid rgba(0, 210, 255, 0.15);
    transition: all 0.2s;
    flex-grow: 1;
}

.layer-item:hover {
    background: rgba(0, 210, 255, 0.1);
}

.layer-item.active {
    border-color: rgba(0, 210, 255, 0.6);
    background: rgba(10, 35, 45, 0.9);
}

.layer-header {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 10px;
    gap: 10px;
}

.layer-options-container {
    padding: 0 10px 10px 56px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    display: none;
}

.layer-item.expanded .layer-options-container {
    display: flex;
}

.layer-chevron {
    color: var(--hud-cyan);
    font-size: 1rem;
    transition: transform 0.3s;
    opacity: 0.7;
    margin-left: auto;
    padding-left: 5px;
}

.layer-item.expanded .layer-chevron {
    transform: rotate(180deg);
}

.layer-toggle-btn {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    background: rgba(10, 25, 30, 0.6);
    border: 1px solid rgba(0, 210, 255, 0.15);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.layer-toggle-btn:hover {
    background: rgba(0, 210, 255, 0.1);
}

.layer-toggle-btn.active {
    background: rgba(10, 35, 45, 0.9);
    border-color: rgba(0, 210, 255, 0.6);
}

.layer-toggle-btn i {
    font-size: 1.4rem;
    color: rgba(255, 255, 255, 0.2);
    transition: color 0.2s, filter 0.2s;
}

.layer-toggle-btn.active i {
    color: var(--hud-cyan);
    filter: drop-shadow(0 0 5px rgba(0, 210, 255, 0.5));
}

/* Modals */
#settings-modal {
    width: 380px !important;
}

#settings-modal .layer-item {
    margin-bottom: 5px;
    padding: 10px;
    flex-direction: row;
    align-items: center;
}

#settings-modal .hud-select {
    background: rgba(0, 30, 60, 0.6);
    color: white;
    border: 1px solid var(--hud-border);
    border-radius: 4px;
    padding: 6px;
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    outline: none;
    cursor: pointer;
}

#settings-modal .hud-select:hover {
    border-color: var(--hud-cyan);
}

#settings-modal .hud-select option {
    background: #001220;
    color: white;
}

.layer-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0b1116;
    border-radius: 8px;
    font-size: 1.2rem;
    color: var(--hud-cyan);
}

.layer-info {
    flex-grow: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 0;
}

.layer-info h3 {
    font-size: 0.95rem;
    margin-bottom: 1px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.5px;
}

.layer-info p {
    font-size: 0.7rem;
    font-weight: 600;
    opacity: 0.6;
}

.badge.live {
    background: rgba(255, 71, 87, 0.15);
    color: var(--hud-pink);
    border: 1px solid rgba(255, 71, 87, 0.5);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.6rem;
    margin-left: 5px;
}

.layer-count {
    font-family: 'Share Tech Mono', monospace;
    font-size: 1rem;
    color: #fff;
    opacity: 0.95;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.3);
}

/* Legacy toggle fallback for any untouched items */
.layer-toggle {
    position: absolute;
    right: 10px;
    bottom: 8px;
    font-size: 1.3rem;
    color: rgba(255, 255, 255, 0.2);
    transition: color 0.2s;
}

.layer-item.active .layer-toggle {
    color: var(--hud-cyan);
    filter: drop-shadow(0 0 5px rgba(0, 210, 255, 0.5));
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    transition: opacity 0.5s ease-out;
}

/* Tooltip standardizer */
.scene-tooltip {
    background: var(--hud-bg) !important;
    border: 1px solid var(--hud-cyan) !important;
    border-radius: 4px !important;
    backdrop-filter: blur(4px) !important;
    box-shadow: var(--hud-glow) !important;
    pointer-events: none;
    font-family: 'Inter', sans-serif !important;
    color: #fff !important;
}

/* Layer Options & Selects */
.layer-options {
    margin-top: 8px;
    display: flex;
    gap: 6px;
    flex-direction: column;
}

.hud-select {
    width: 100%;
    background: rgba(4, 15, 20, 0.8);
    border: 1px solid var(--hud-border);
    color: var(--hud-cyan);
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.75rem;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2300d2ff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 14px;
}

.hud-select:hover {
    background-color: rgba(0, 210, 255, 0.1);
}

.hud-select:focus {
    border-color: var(--hud-cyan);
    box-shadow: var(--hud-glow);
}

.hud-select option {
    background: #0d1117;
    color: var(--hud-cyan);
    font-family: 'Inter', sans-serif;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

::-webkit-scrollbar-thumb {
    background: var(--hud-border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--hud-cyan);
}

/* ============================================================
   RESPONSIVE LAYOUT — TABLET & MOBILE
   ============================================================ */

/* ---- Tablet (769px – 1024px) ---- */
@media (max-width: 1024px) and (min-width: 769px) {
    .hud-panel {
        width: 270px;
    }

    .hud-search {
        width: 220px;
    }
}

/* ---- Mobile (≤768px) ---- */
@media (max-width: 768px) {

    /* Header: tighten up, hide clock */
    .hud-header {
        padding: 0 1rem;
        padding-top: env(safe-area-inset-top, 0); /* Notch support */
        height: auto;
        min-height: 50px;
    }

    .hud-logo {
        font-size: 1rem;
        letter-spacing: 1px;
    }

    /* Hide the subtitle text "by Sherpa Solutions" */
    .hud-logo span {
        display: none;
    }

    /* Search bar: compact GO button fits inside on mobile */
    .hud-search {
        width: 200px;
    }

    .hud-search input {
        font-size: 0.75rem;
        padding: 6px 38px 6px 28px;
    }

    .hud-search .search-btn {
        padding: 2px 6px;
        font-size: 0.6rem;
        right: 3px;
    }

    /* Hide the status text on very narrow screens */
    .status-indicator span {
        display: none;
    }

    /* Clock: hidden on mobile to save header space */
    #clock-display {
        display: none;
    }

    /* Left data-layer panel: anchor to BOTTOM instead of left side */
    .panel-left {
        left: 2%;
        right: 2%;
        top: auto;
        bottom: 0;
        width: 96%; /* Widen for 19.5:9 / 20:9 screens */
        max-height: 38vh;
        padding-bottom: env(safe-area-inset-bottom, 15px); /* Home indicator support */
        border-radius: 12px 12px 0 0;
        border-bottom: none;
        transition: max-height 0.4s cubic-bezier(0.25, 1, 0.5, 1);
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .panel-left .panel-title {
        flex-shrink: 0;             /* title bar never shrinks */
    }

    .panel-left.collapsed {
        max-height: 48px;           /* Height of just the title bar */
    }

    /* Scroll layer items vertically */
    .panel-content {
        display: flex;
        flex-direction: column;
        gap: 5px;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 6px;
        -webkit-overflow-scrolling: touch;
        flex: 1;
        min-height: 0;
    }

    /* Show scrollbar to indicate more items below */
    .panel-content::-webkit-scrollbar {
        display: block;
        width: 6px;
    }

    .layer-item {
        width: 100%;
        flex: none;
        margin-bottom: 0;
        padding: 8px;
        padding-right: 50px;
        overflow: visible;
    }

    /* Hide chevron on mobile — toggle button serves the same purpose */
    .layer-chevron {
        display: none;
    }

    /* Prevent layer name from overlapping count */
    .layer-row .layer-name,
    .layer-row .layer-info h3 {
        min-width: 0;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        flex-shrink: 1;
    }

    .layer-row .layer-count {
        flex-shrink: 0;
        margin-left: 4px;
    }

    /* Layer row: relative so toggle button can position inside */
    .layer-row {
        position: relative !important;
        overflow: visible !important;
    }

    /* Toggle button: absolute position inside the layer card */
    .panel-left .layer-toggle-btn {
        position: absolute !important;
        right: 8px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        width: 36px !important;
        height: 36px !important;
        z-index: 5;
        background: rgba(0, 20, 30, 0.8) !important;
        border-radius: 6px;
    }

    .panel-left .layer-toggle-btn i {
        font-size: 1.2rem;
    }


    /* Layer options (dropdowns): show on mobile so user can toggle specific sub-items */
    .layer-options {
        display: flex;
    }

    /* Move filter dropdowns to the far left */
    .layer-options-container {
        padding-left: 8px !important;
    }

    /* Counts: smaller font */
    .layer-count {
        font-size: 0.7rem;
    }

    /* Target lock panel: scaled down heavily for mobile to not consume screen space */
    .panel-right {
        right: 2%;
        left: auto;
        top: calc(70px + env(safe-area-inset-top, 0)); /* Clear header + Notch */
        width: 45%; /* Slightly wider for legible text */
        max-height: 45vh; /* Allow a bit more room for target details */
        border-radius: 8px;
        overflow-y: visible;
        box-shadow: 0 10px 25px rgba(0,0,0,0.8);
        padding-bottom: 5px;
    }

    /* Reduce the header section (icon + callsign + country) by 20% */
    .panel-right #target-details > div:first-child {
        margin-bottom: 10px !important;
    }
    .panel-right #target-details > div:first-child > div:first-child {
        font-size: 1.6rem !important; /* down from 2rem */
    }
    .panel-right #target-details > div:first-child h3 {
        font-size: 1.2rem !important; /* down from 1.5rem */
    }
    .panel-right #target-details > div:first-child > div:last-of-type {
        font-size: 0.64rem !important; /* down from 0.8rem */
        margin-top: 3px !important;
    }

    /* Override the JS inline table styles dynamically injected from live_earth.js */
    .panel-right .panel-title {
        font-size: 0.75rem !important; /* Smaller header */
        padding: 4px 8px !important;
        margin-bottom: 0px !important; /* Pack tighter */
    }

    .panel-right td {
        padding: 2px 0 !important; /* Ultra tight rows */
        font-size: 0.65rem !important;
        line-height: 1.1 !important;
    }

    .panel-right td span {
        font-size: 0.55rem !important;
    }
    
    .panel-right #close-target {
        padding: 4px !important;
        margin-top: 5px !important;
        font-size: 0.65rem !important;
    }

    /* Video iframes & CCTV feeds in panel: much shorter on mobile */
    .panel-right iframe, .panel-right img, .panel-right video {
        height: 110px !important;
        min-height: 110px !important;
    }

    /* Settings Modal: full width, constrained height, scrollable */
    #settings-modal {
        width: 100% !important;
        right: 0;
        left: 0;
        top: 55px;
        max-height: calc(100vh - 55px);
        border-radius: 0 0 8px 8px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        z-index: 20;
    }

    #settings-modal .panel-title {
        flex-shrink: 0;
    }

    #settings-modal .panel-content {
        overflow-y: auto;
        flex: 1;
        min-height: 0;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 20px;
    }
}

/* ---- Very small phones (≤375px) ---- */
@media (max-width: 375px) {
    .hud-search {
        display: none;
    }

    .panel-left {
        max-height: 38vh;
    }
}

/* ============================================================
   VIRTUAL CURSOR (DEMO MODE)
   ============================================================ */
#virtual-cursor {
    position: fixed;
    top: 0;
    left: 0;
    width: 24px;
    height: 24px;
    z-index: 10000; /* Above all HUD elements */
    pointer-events: none; /* Don't block actual clicks */
    transition: transform 0.15s ease-out;
    display: none;
    filter: drop-shadow(0 0 5px rgba(0, 210, 255, 0.8));
}

#virtual-cursor::after {
    content: '\f245'; /* fa-mouse-pointer */
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    font-size: 24px;
    color: #fff;
    -webkit-text-stroke: 1px #000;
    display: block;
}

#virtual-cursor.clicking {
    transform: scale(0.7);
}

#virtual-cursor.clicking::after {
    color: var(--hud-cyan);
}