:root {
    --bg-color: #0f172a;
    --text-light: #f8fafc;
    --accent: #38bdf8;
    --panel-bg: rgba(15, 23, 42, 0.85);
    --panel-light-bg: rgba(255, 255, 255, 0.95);
    --text-dark: #1f2937;
    --transition-speed: 0.8s;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background-color: var(--bg-color); color: var(--text-light); overflow: hidden; width: 100vw; height: 100vh; }
*:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

#loader { position: fixed; inset: 0; background: var(--bg-color); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 9999; transition: opacity 0.5s ease; }
.spinner { width: 40px; height: 40px; border: 4px solid rgba(255,255,255,0.1); border-left-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 1rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Vistas Principales */
#main-view { position: absolute; inset: 0; width: 100vw; height: 100vh; display: flex; align-items: center; justify-content: center; overflow: hidden; transition: opacity var(--transition-speed) ease, visibility var(--transition-speed); }
#image-wrapper { position: relative; display: inline-block; max-width: 100%; max-height: 100vh; transition: transform 1s cubic-bezier(0.65, 0, 0.35, 1); transform-origin: center center; will-change: transform; }
#base-image { display: block; max-width: 100%; max-height: 100vh; width: auto; height: auto; }
#markers-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* Aviso inicial: deja claro que los estudios son exploratorios y deben ser
   validados por especialistas, no reemplaza su juicio profesional. */
#main-disclaimer {
    position: absolute; top: 0; left: 0; right: 0; z-index: 20;
    display: flex; align-items: flex-start; justify-content: center;
    padding: 1rem 3.25rem 2rem;
    background: linear-gradient(to bottom, rgba(15,23,42,0.95), rgba(15,23,42,0.55) 75%, transparent);
    pointer-events: none;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}
#main-disclaimer.dismissed { opacity: 0; visibility: hidden; }
.disclaimer-text { max-width: 720px; text-align: center; }
.disclaimer-text strong { display: block; font-size: 1rem; margin-bottom: 0.3rem; color: var(--accent); }
.disclaimer-text span { display: block; font-size: 0.8rem; line-height: 1.45; color: rgba(248,250,252,0.85); }
#disclaimer-close {
    position: absolute; top: 0.6rem; right: 0.75rem; pointer-events: auto;
    background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.25); color: var(--text-light);
    width: 28px; height: 28px; border-radius: 50%; font-size: 1rem; line-height: 1; cursor: pointer;
}
#disclaimer-close:hover { background: rgba(255,255,255,0.2); }

.marker { position: absolute; transform: translate(-50%, -50%); pointer-events: auto; cursor: pointer; display: flex; flex-direction: column; align-items: center; transition: transform 0.2s ease; background: transparent; border: none; color: var(--text-light); font-family: inherit; }
.marker:hover, .marker:focus-visible { transform: translate(-50%, -50%) scale(1.1); }
.marker-dot { width: 24px; height: 24px; background: var(--accent); border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 15px var(--accent); animation: pulse 2s infinite; }
.marker-label { margin-top: 8px; background: rgba(0,0,0,0.7); padding: 4px 10px; border-radius: 4px; font-size: 0.85rem; font-weight: 600; white-space: nowrap; border: 1px solid rgba(255,255,255,0.2); }
.marker-label.position-up { position: absolute; bottom: 100%; margin-top: 0; margin-bottom: 8px; }

@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.7); } 70% { box-shadow: 0 0 0 15px rgba(56, 189, 248, 0); } 100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); } }

/* Vista Detalle */
#detail-view { position: absolute; inset: 0; opacity: 0; visibility: hidden; pointer-events: none; transition: opacity var(--transition-speed) ease 0.2s, visibility var(--transition-speed) ease 0.2s; display: flex; align-items: center; justify-content: flex-start; padding: 4rem; }
#detail-view.active { opacity: 1; visibility: visible; pointer-events: auto; }
/* Frame de proporción fija: SIEMPRE tiene el mismo aspect ratio que la imagen base
   vigente (lo calcula app.js con el ancho/alto real de esa imagen), sin importar
   si la pantalla es ancha (PC) o angosta y alta (teléfono). app.js le asigna
   width/height en px para que haga "contain" real dentro de #detail-view. Gracias
   a esto, los bgSize/bgPosX/bgPosY de cada capa en reports/*.js apuntan siempre
   al mismo lugar relativo a la imagen, sin importar el dispositivo. */
#detail-bg-frame { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: -2; background-color: var(--bg-color); }
#detail-bg-base, #detail-bg-overlay { position: absolute; inset: 0; background-repeat: no-repeat; }
#detail-bg-base { background-size: 100% 100%; background-position: center; will-change: background-image; }
#detail-bg-overlay { background-size: contain; background-position: center; transition: background-image 0.5s ease; will-change: background-image; }

/* Paneles Globales */
.content-panel { background: var(--panel-bg); backdrop-filter: blur(10px); padding: 2.5rem; border-radius: 12px; max-width: 500px; border: 1px solid rgba(255,255,255,0.1); transform: translateY(20px); transition: transform 0.6s ease; display: none; }
#detail-view.active .content-panel.active-panel { transform: translateY(0); display: block; }
.glass-panel-container { display: none; position: absolute; top: 1.5rem; left: 1.5rem; width: 24rem; max-height: calc(100vh - 3rem); background: var(--panel-light-bg); backdrop-filter: blur(8px); box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); border-radius: 0.5rem; z-index: 10; flex-direction: column; overflow-y: auto; color: var(--text-dark); border: 1px solid rgba(255,255,255,0.2); }
#detail-view.active .glass-panel-container.active-panel { display: flex; }
.glass-panel-header { padding: 1.25rem; border-bottom: 1px solid #e5e7eb; }
.glass-panel-header h1 { font-size: 1.25rem; font-weight: 700; color: #1e293b; margin-bottom: 0.25rem; }
.alert-badge { display: inline-block; margin-top: 0.5rem; padding: 0.25rem 0.5rem; background-color: #fee2e2; color: #b91c1c; font-size: 0.75rem; font-weight: 600; border-radius: 0.25rem; }
.glass-panel-body { padding: 1.25rem; font-size: 0.875rem; color: #475569; line-height: 1.5; }
.systems-list h3 { font-weight: 700; color: #1e293b; margin-bottom: 0.75rem; font-size: 0.9rem; }
.systems-list ul { list-style: none; display: flex; flex-direction: column; gap: 0.75rem; }
.systems-list li { display: flex; align-items: flex-start; }
.dot { width: 0.75rem; height: 0.75rem; border-radius: 50%; margin-top: 0.25rem; margin-right: 0.5rem; flex-shrink: 0; }

.btn-back-dark, .btn-back { padding: 8px 16px; border-radius: 6px; cursor: pointer; font-size: 0.85rem; font-weight: 600; margin-bottom: 1rem; transition: all 0.2s ease; display: inline-flex; align-items: center; }
.btn-back-dark { background: #f1f5f9; color: #334155; border: 1px solid #cbd5e1; }
.btn-back-dark:hover { background: #e2e8f0; }
.btn-back { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-back:hover { background: var(--accent); color: #fff; }
/* Selector Derecho */
.layer-control { display: none; position: absolute; top: 1.5rem; right: 1.5rem; width: 340px; max-height: calc(100vh - 3rem); overflow-y: auto; background: var(--panel-light-bg); padding: 1rem; border-radius: 0.5rem; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); z-index: 10; color: var(--text-dark); border: 1px solid #e5e7eb; }
.layer-control.active-control { display: block; }
.layer-control fieldset { border: none; }
.layer-control legend { font-weight: 700; margin-bottom: 0.75rem; font-size: 0.9rem; color: #1e293b; border-bottom: 1px solid #e5e7eb; padding-bottom: 0.25rem; width: 100%; }
.layer-control label { display: flex; align-items: center; font-size: 0.9rem; font-weight: 600; cursor: pointer; margin-bottom: 0.75rem; padding: 0.25rem; border-radius: 0.25rem; transition: background-color 0.2s; }
.layer-control label:hover { background-color: #f1f5f9; }
.layer-control label:last-child { margin-bottom: 0; }
.layer-control input[type="radio"] { margin-right: 0.75rem; width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent-hover); }

/* Fichas Técnicas (Panel Derecho) */
.ficha-box { margin-top: 1.25rem; background: #fff; border: 1px solid #e2e8f0; border-radius: 0.375rem; box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05); font-size: 0.75rem; color: #334155; overflow: hidden; }
.f-header { padding: 0.5rem 0.75rem; display: flex; align-items: center; justify-content: space-between; font-weight: 600; border-bottom: 1px solid; }
.f-badge { padding: 0.125rem 0.5rem; border-radius: 0.25rem; font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; text-align: center;}
.f-body { padding: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; }
.f-row { display: flex; justify-content: space-between; border-bottom: 1px solid #f1f5f9; padding-bottom: 0.25rem; }
.f-label { color: #64748b; }
.f-val { font-weight: 700; color: #1e293b; text-align: right; }
.f-section { padding-top: 0.25rem; }
.f-block { display: block; margin-bottom: 0.25rem; }
.f-alert { display: block; padding: 0.5rem; border-radius: 0.25rem; border: 1px solid; font-weight: 500; }
.f-footer { padding-top: 0.25rem; margin-top: 0.25rem; border-top: 1px solid #f1f5f9; }
.f-label-dark { font-weight: 600; color: #334155; }
.f-text { color: #475569; }

.theme-green { border-color: #bbf7d0; } .theme-green .f-header { background: #f0fdf4; border-color: #bbf7d0; color: #166534; } .theme-green .f-badge { background: #bbf7d0; color: #166534; }
.theme-red { border-color: #fecaca; } .theme-red .f-header { background: #fef2f2; border-color: #fecaca; color: #991b1b; } .theme-red .f-badge { background: #fecaca; color: #991b1b; }
.theme-indigo { border-color: #c7d2fe; } .theme-indigo .f-header { background: #eef2ff; border-color: #c7d2fe; color: #3730a3; } .theme-indigo .f-badge { background: #c7d2fe; color: #3730a3; }
.alert-red { background: #fef2f2; border-color: #fee2e2; color: #dc2626; }
.alert-indigo { background: #eef2ff; border-color: #e0e7ff; color: #4338ca; }

/* Interpretación Visual (Panel Izquierdo) */
.dynamic-info-box { margin-top: 1.5rem; padding: 1rem; background-color: #f8fafc; border-left: 4px solid var(--accent); border-radius: 0 0.375rem 0.375rem 0; font-size: 0.85rem; color: #475569; display: none; }
.dynamic-info-box.active { display: block; }
.dynamic-info-box h4 { color: #0f172a; font-weight: 700; margin-bottom: 0.5rem; font-size: 0.9rem; }

.salto-texto {white-space: pre-line;}

.etiqueta-marcador { position: absolute; top: 100%; margin-top: 12px; left: 50%; transform: translateX(-50%); z-index: 10;}
.etiqueta-marcador.position-up { top: auto; bottom: 100%; margin-top: 0; margin-bottom: 12}

/* ============================================================
   RESPONSIVE â€” TABLETS Y MóVILES
   En vez de mostrar los dos paneles fijos y grandes (que tapaban
   casi toda la imagen), aquí arrancan PLEGADOS: solo se ve una
   barra angosta arriba (informe) y una fila de pastillas abajo
   (capas). La imagen de fondo queda visible en todo momento.
   El usuario toca la barra/leyenda para desplegar el contenido
   completo cuando lo necesita. app.js agrega/quita la clase
   .panel-expanded al tocar; en escritorio esto no tiene efecto.
   ============================================================ */
@media (max-width: 768px) {
    #detail-view { padding: 0; align-items: stretch; }

    .content-panel { max-width: calc(100% - 1.5rem); width: calc(100% - 1.5rem); margin: 4.5rem auto 0; padding: 1.5rem; }

    /* --- Panel ejecutivo: barra colapsada arriba --- */
    .glass-panel-container {
        top: 0.75rem;
        left: 0.75rem;
        right: 0.75rem;
        width: auto;
        max-width: none;
        max-height: 4.4rem;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }
    .glass-panel-container.panel-expanded { max-height: 62vh; overflow-y: auto; }
    .glass-panel-header { cursor: pointer; position: relative; padding-right: 2.5rem; }
    .glass-panel-header::after {
        content: 'â–¾'; position: absolute; right: 1.25rem; top: 1.15rem;
        font-size: 1.1rem; color: var(--accent); transition: transform 0.3s ease;
    }
    .glass-panel-container.panel-expanded .glass-panel-header::after { transform: rotate(180deg); }
    .glass-panel-body { display: none; }
    .glass-panel-container.panel-expanded .glass-panel-body { display: block; }

    /* --- Selector de capas: cuadrícula de pastillas compactas abajo --- */
    .layer-control {
        top: auto;
        bottom: 0.75rem;
        left: 0.75rem;
        right: 0.75rem;
        width: auto;
        max-width: none;
        max-height: none;
        padding: 0.6rem 0.75rem;
    }
    .layer-control legend {
        cursor: pointer;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: none;
        padding-bottom: 0;
        margin-bottom: 0.4rem;
        font-size: 0.8rem;
    }
    .legend-hint { font-size: 0.6rem; font-weight: 500; color: #94a3b8; text-transform: none; }
    .layer-options {
        display: flex;
        flex-wrap: wrap;
        gap: 0.4rem;
        overflow-x: visible;
        max-height: 6rem;
        overflow-y: auto;
        padding-bottom: 0.1rem;
    }
    .layer-control label {
        flex: 0 0 auto;
        white-space: nowrap;
        margin-bottom: 0;
        padding: 0.35rem 0.7rem;
        border-radius: 999px;
        background: #f1f5f9;
        font-size: 0.78rem;
    }
    .layer-control label span { font-size: 0.78rem; }
    .layer-control label.layer-pill-active { background: #dbeafe; box-shadow: inset 0 0 0 1.5px var(--accent); }
    .layer-control input[type="radio"] { display: none; }
    .layer-info { display: none; margin-top: 0.6rem; max-height: 32vh; overflow-y: auto; }
    .layer-control.panel-expanded .layer-info { display: block; }

    .marker-label { font-size: 0.75rem; padding: 3px 8px; }
    .marker-dot { width: 20px; height: 20px; }
}

@media (max-width: 480px) {
    .glass-panel-header h1 { font-size: 1rem; }
    .glass-panel-body { font-size: 0.8rem; }
    .btn-back-dark, .btn-back { font-size: 0.8rem; padding: 6px 12px; }
    .content-panel { padding: 1.25rem; }
    .marker-label { font-size: 0.68rem; padding: 3px 6px; }
    .marker-dot { width: 16px; height: 16px; }
    #main-disclaimer { padding: 0.75rem 2.5rem 1.5rem; }
    .disclaimer-text strong { font-size: 0.85rem; }
    .disclaimer-text span { font-size: 0.7rem; }
}

/* ============================================================
   TELéFONO EN HORIZONTAL (landscape)
   Aquí NO usamos el ancho como criterio, porque un teléfono
   acostado puede medir más de 768px de ancho (por eso el bloque
   de arriba no alcanzaba y se veía como en escritorio, tapando
   la imagen). El criterio es el ALTO disponible: si es bajo,
   asumimos teléfono acostado. Los paneles pasan a ser franjas
   angostas anaclas a cada esquina superior (no barras de ancho
   completo), dejando la imagen visible entre ambas.
   ============================================================ */
@media (orientation: landscape) and (max-height: 500px) {
    #detail-view { padding: 0.5rem; align-items: flex-start; }

    .content-panel { max-width: 60vw; width: 60vw; margin: 0; padding: 1rem; }

    /* --- Panel de informe: franja angosta arriba a la izquierda --- */
    .glass-panel-container {
        top: 0.5rem;
        left: 0.5rem;
        right: auto;
        bottom: auto;
        width: min(62vw, 320px);
        max-width: none;
        max-height: 3rem;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }
    .glass-panel-container.panel-expanded { max-height: 90vh; overflow-y: auto; }
    .glass-panel-header { cursor: pointer; position: relative; padding: 0.6rem 2.2rem 0.6rem 0.9rem; }
    .glass-panel-header h1 { font-size: 0.9rem; }
    .glass-panel-header p { font-size: 0.7rem; }
    .glass-panel-header::after {
        content: '▾'; position: absolute; right: 0.9rem; top: 0.65rem;
        font-size: 1rem; color: var(--accent); transition: transform 0.3s ease;
    }
    .glass-panel-container.panel-expanded .glass-panel-header::after { transform: rotate(180deg); }
    .glass-panel-body { display: none; font-size: 0.75rem; padding: 0.9rem; }
    .glass-panel-container.panel-expanded .glass-panel-body { display: block; }

    /* --- Selector de capas: franja angosta arriba a la derecha --- */
    .layer-control {
        top: 0.5rem;
        bottom: auto;
        left: auto;
        right: 0.5rem;
        width: min(48vw, 260px);
        max-width: none;
        max-height: 5.2rem;
        overflow: hidden;
        padding: 0.5rem 0.65rem;
        transition: max-height 0.3s ease;
    }
    .layer-control.panel-expanded { max-height: 90vh; overflow-y: auto; }
    .layer-control legend {
        cursor: pointer;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: none;
        padding-bottom: 0;
        margin-bottom: 0.3rem;
        font-size: 0.72rem;
    }
    .legend-hint { font-size: 0.6rem; font-weight: 500; color: #94a3b8; text-transform: none; }
    .layer-options { display: flex; flex-wrap: wrap; gap: 0.3rem; overflow-x: visible; }
    .layer-control label {
        flex: 0 0 auto;
        white-space: nowrap;
        margin-bottom: 0;
        padding: 0.3rem 0.55rem;
        border-radius: 999px;
        background: #f1f5f9;
        font-size: 0.68rem;
    }
    .layer-control label span { font-size: 0.68rem; }
    .layer-control label.layer-pill-active { background: #dbeafe; box-shadow: inset 0 0 0 1.5px var(--accent); }
    .layer-control input[type="radio"] { display: none; }
    .layer-info { display: none; margin-top: 0.5rem; max-height: 26vh; overflow-y: auto; }
    .layer-control.panel-expanded .layer-info { display: block; }

    .marker-label { font-size: 0.68rem; padding: 2px 6px; }
    .marker-dot { width: 16px; height: 16px; }
}

/* ============================================================
   REDISEÑO GEOINT (ESTÉTICA HUD TÁCTICO)
   ============================================================ */

/* 1. Loader estilo Terminal */
.terminal-box {
    width: 400px; max-width: 90%;
    background: rgba(10, 15, 25, 0.9);
    border: 1px solid rgba(56, 189, 248, 0.4);
    border-top: 3px solid var(--accent);
    padding: 15px; font-family: monospace; color: var(--accent);
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.1);
}
.term-header { border-bottom: 1px solid rgba(56, 189, 248, 0.3); padding-bottom: 8px; margin-bottom: 12px; font-weight: bold; font-size: 0.9rem; letter-spacing: 1px; }
.term-body { font-size: 0.85rem; line-height: 1.6; }
.cursor { display: inline-block; width: 8px; height: 14px; background: var(--accent); vertical-align: middle; margin-left: 5px; animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* 2. Retícula de Radar sobre el Mapa Global */
#main-view::before {
    content: ''; position: absolute; inset: 0; z-index: 5; pointer-events: none;
    background-image: 
        linear-gradient(rgba(56, 189, 248, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(56, 189, 248, 0.05) 1px, transparent 1px);
    background-size: 80px 80px; /* Tamaño de los cuadros */
}

/* 3. Transformación de los Paneles (Cyber-Glassmorphism) */
.glass-panel-container, .content-panel, .layer-control, details {
    border-radius: 0 !important; /* Se eliminan las curvas para un look duro/tecnológico */
    border: 1px solid rgba(56, 189, 248, 0.25) !important;
    border-top: 2px solid var(--accent) !important;
    border-bottom: 2px solid var(--accent) !important;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.95) 0%, rgba(10, 15, 25, 0.9) 100%) !important;
    box-shadow: inset 0 0 15px rgba(56, 189, 248, 0.05), 0 8px 30px rgba(0, 0, 0, 0.8) !important;
    overflow: hidden; /* Necesario para que las líneas de escaneo no salgan */
}

.glass-panel-header h1, .layer-control legend, .dynamic-info-box h4 {
    color: var(--accent) !important;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.glass-panel-body, .glass-panel-header p, .layer-control label, .layer-control legend {
    color: #cbd5e1 !important; /* Gris claro para lectura cómoda */
}
.btn-back-dark {
    background: rgba(56, 189, 248, 0.1) !important;
    color: var(--accent) !important;
    border: 1px solid var(--accent) !important;
    border-radius: 0 !important;
}
.btn-back-dark:hover { background: rgba(56, 189, 248, 0.3) !important; color: #fff !important; }

/* 3.2 Transformación de Cajas Blancas Internas (Fichas e Interpretación) */
.dynamic-info-box, .ficha-box {
    background: rgba(0, 0, 0, 0.6) !important; /* Fondo negro translúcido */
    border: 1px solid rgba(56, 189, 248, 0.2) !important;
    border-left: 3px solid var(--accent) !important;
    border-radius: 0 !important;
    color: #94a3b8 !important;
}
.f-header {
    background: rgba(56, 189, 248, 0.1) !important;
    color: #e2e8f0 !important;
    border-bottom: 1px solid rgba(56, 189, 248, 0.3) !important;
}
.f-body { color: #cbd5e1 !important; }
.f-val { color: var(--accent) !important; }
.f-label, .f-text { color: #94a3b8 !important; }
.f-row { border-bottom: 1px dashed rgba(255,255,255,0.1) !important; }

/* 3.3 Colores de Alerta Internos (Adaptados al modo oscuro) */
.theme-red { border-left-color: #ef4444 !important; }
.theme-red .f-header { background: rgba(239, 68, 68, 0.15) !important; color: #fca5a5 !important; border-bottom-color: rgba(239,68,68,0.3) !important; }
.theme-green { border-left-color: #10b981 !important; }
.theme-green .f-header { background: rgba(16, 185, 129, 0.15) !important; color: #6ee7b7 !important; border-bottom-color: rgba(16,185,129,0.3) !important; }

/* Efecto hover en el panel de control de capas */
.layer-control label:hover { background-color: rgba(56, 189, 248, 0.1) !important; }
.layer-control label.layer-pill-active { 
    background: rgba(56, 189, 248, 0.2) !important; 
    box-shadow: inset 0 0 0 1px var(--accent) !important; 
}


/* Título Principal Táctico */
#titulo-principal { border-radius: 0 !important; border: 1px solid rgba(56, 189, 248, 0.3) !important; border-left: 4px solid var(--accent) !important; }

/* 4. Efecto de "Scanlines" (Líneas de transmisión) sobre los paneles */
.glass-panel-container::after, .content-panel::after, .layer-control::after, details::after {
    content: ''; position: absolute; inset: 0; z-index: 1; pointer-events: none;
    background: repeating-linear-gradient( 0deg, transparent, transparent 2px, rgba(56, 189, 248, 0.04) 2px, rgba(56, 189, 248, 0.04) 4px );
}
/* Asegurar que el texto esté por encima de las scanlines */
.glass-panel-header, .glass-panel-body, .layer-options, .layer-info, summary { position: relative; z-index: 2; }

/* 5. Telemetría Periférica (HUD) */
#hud-overlay { position: fixed; inset: 0; pointer-events: none; z-index: 900; font-family: monospace; color: rgba(56, 189, 248, 0.8); font-size: 0.75rem; letter-spacing: 1px; }
.hud-top-right { position: absolute; top: 20px; right: 25px; text-align: right; }
.hud-bottom-left { position: absolute; bottom: 20px; left: 25px; line-height: 1.5; border-left: 2px solid rgba(56, 189, 248, 0.8); padding-left: 8px; }
.hud-bottom-right { position: absolute; bottom: 20px; right: 25px; text-align: right; line-height: 1.5; border-right: 2px solid rgba(56, 189, 248, 0.8); padding-right: 8px; }

/* Barras de Señal Simuladas */
.hud-bars { display: flex; gap: 3px; justify-content: flex-end; margin-top: 6px; }
.hud-bars span { display: block; width: 4px; background: rgba(56, 189, 248, 0.6); animation: hudPulse 2s infinite; }
.hud-bars span:nth-child(1) { height: 4px; }
.hud-bars span:nth-child(2) { height: 7px; animation-delay: 0.2s; }
.hud-bars span:nth-child(3) { height: 10px; animation-delay: 0.4s; }
.hud-bars span:nth-child(4) { height: 14px; animation-delay: 0.6s; }
.hud-bars span:nth-child(5) { height: 18px; animation-delay: 0.8s; }
@keyframes hudPulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

@media (max-width: 768px) { #hud-overlay { display: none; } } /* Ocultar HUD perimetral en móviles para no saturar */

/* ============================================================
   CORRECCIONES: SCROLL TÁCTICO Y REUBICACIÓN DEL HUD
   ============================================================ */

/* 1. Restaurar la capacidad de desplazamiento (Scroll) */
.glass-panel-container, .layer-control {
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

/* 2. Personalizar la barra de desplazamiento para que coincida con el HUD */
.glass-panel-container::-webkit-scrollbar, 
.layer-control::-webkit-scrollbar {
    width: 6px; /* Barra delgada y sutil */
}
.glass-panel-container::-webkit-scrollbar-track, 
.layer-control::-webkit-scrollbar-track {
    background: rgba(10, 15, 25, 0.8);
    border-left: 1px solid rgba(56, 189, 248, 0.1);
}
.glass-panel-container::-webkit-scrollbar-thumb, 
.layer-control::-webkit-scrollbar-thumb {
    background: rgba(56, 189, 248, 0.5); /* Color cian translúcido */
    border-radius: 0; /* Bordes rectos tácticos */
}
.glass-panel-container::-webkit-scrollbar-thumb:hover, 
.layer-control::-webkit-scrollbar-thumb:hover {
    background: var(--accent); /* Brilla al pasar el cursor */
}

/* 3. Reubicación de la Telemetría (Overlays) al Centro Inferior */
.hud-bottom-left {
    position: absolute;
    bottom: 25px;
    left: calc(50% - 15px); /* Se posiciona justo a la izquierda del centro */
    transform: translateX(-100%); /* Lo empuja hacia la izquierda */
    text-align: right;
    line-height: 1.5;
    border-left: none !important; /* Anula el borde izquierdo anterior */
    border-right: 2px solid rgba(56, 189, 248, 0.5); /* Borde central */
    padding-left: 0 !important;
    padding-right: 12px;
}

.hud-bottom-right {
    position: absolute;
    bottom: 25px;
    right: auto !important; /* Anula el ancla a la derecha de la pantalla */
    left: calc(50% + 15px); /* Se posiciona justo a la derecha del centro */
    text-align: left;
    line-height: 1.5;
    border-right: none !important; /* Anula el borde derecho anterior */
    border-left: 2px solid rgba(56, 189, 248, 0.5); /* Borde central */
    padding-right: 0 !important;
    padding-left: 12px;
}


.systems-list h3 {
    background: transparent !important;
    color: var(--accent) !important;
    font-size: 0.95rem !important;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 15px !important;
    margin-bottom: 12px !important;
    border-bottom: 1px dashed rgba(56, 189, 248, 0.3);
    padding-bottom: 5px;
}

.systems-list ul li {
    color: #cbd5e1 !important; /* Gris claro */
    font-size: 0.85rem;
    line-height: 1.5;
    margin-bottom: 10px;
}

.systems-list ul li strong, 
.glass-panel-body p strong {
    color: #f8fafc !important; /* Blanco puro para destacar el texto fuerte */
}

/* ============================================================
   UPGRADE GEOINT: CINEMÁTICA Y TEXTURAS (FASE 2)
   ============================================================ */

/* 1. Transformación del Mapa Base (Filtro Óptico Táctico) */
#base-image {
    /* Desatura los verdes/marrones, tiñe de azul/cian oscuro y sube el contraste */
    filter: grayscale(70%) sepia(50%) hue-rotate(180deg) brightness(45%) contrast(160%) !important;
    transition: filter 1s ease;
}

/* 2. Barrido Orbital Continuo (Scanline Sweeper) */
#main-view::after {
    content: '';
    position: absolute;
    top: -20vh; left: 0; right: 0; height: 15vh;
    background: linear-gradient(to bottom, transparent, rgba(56, 189, 248, 0.02) 80%, rgba(56, 189, 248, 0.4) 100%);
    z-index: 4; /* Queda entre el mapa y los paneles */
    pointer-events: none;
    animation: radarSweep 8s linear infinite;
    border-bottom: 1px solid rgba(56, 189, 248, 0.6);
}
@keyframes radarSweep {
    0% { transform: translateY(-100%); opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { transform: translateY(110vh); opacity: 0; }
}

/* 3. Dinámica de Marcadores (Nodos de Sonar Activo) */
.marker-dot {
    width: 14px !important; height: 14px !important;
    background: var(--accent) !important;
    border: 2px solid #fff !important;
    box-shadow: 0 0 10px var(--accent) !important;
    position: relative;
    border-radius: 50%;
    animation: none !important; /* Apagamos el pulso viejo */
}
/* Ondas de Sonar Concéntricas */
.marker-dot::before, .marker-dot::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    border: 1px solid var(--accent);
    animation: sonarPulse 2.5s cubic-bezier(0.1, 0.8, 0.3, 1) infinite;
}
.marker-dot::after { animation-delay: 1.25s; }
@keyframes sonarPulse {
    0% { width: 14px; height: 14px; opacity: 1; border-width: 2px; }
    100% { width: 70px; height: 70px; opacity: 0; border-width: 1px; }
}

/* 4. Animación Cinemática de Despliegue de Paneles (Persiana Digital) */
#detail-view.active .glass-panel-container.active-panel, 
#detail-view.active .layer-control.active-control {
    animation: bootUpSequence 0.5s cubic-bezier(0.1, 0.8, 0.1, 1) forwards !important;
    transform-origin: center;
}
@keyframes bootUpSequence {
    0% { 
        clip-path: polygon(50% 0, 50% 0, 50% 100%, 50% 100%); 
        opacity: 0; 
        filter: brightness(2) contrast(1.5);
    }
    100% { 
        clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); 
        opacity: 1; 
        filter: brightness(1) contrast(1);
    }
}

/* 5. Inyección de Micro-Datos "Vivos" (Sparklines del HUD) */
.hud-sparkline {
    display: inline-flex; align-items: flex-end; gap: 2px;
    height: 12px; margin-right: 15px; vertical-align: bottom;
}
.hud-sparkline span {
    width: 3px; background: rgba(56, 189, 248, 0.8);
    animation: sparklineAnim 1s ease-in-out infinite alternate;
}
/* Ritmos irregulares para simular flujo de red */
.hud-sparkline span:nth-child(1) { animation-duration: 0.4s; }
.hud-sparkline span:nth-child(2) { animation-duration: 0.6s; }
.hud-sparkline span:nth-child(3) { animation-duration: 0.3s; }
.hud-sparkline span:nth-child(4) { animation-duration: 0.7s; }
.hud-sparkline span:nth-child(5) { animation-duration: 0.5s; }
.hud-sparkline span:nth-child(6) { animation-duration: 0.8s; }
@keyframes sparklineAnim {
    0% { height: 2px; }
    100% { height: 12px; }
}

/* 6. Ruido Térmico Sutil / Interferencia Atmosférica */
body::after {
    content: '';
    position: fixed; inset: 0; z-index: 9999; pointer-events: none;
    /* Genera un ruido fractal SVG directamente en el código para evitar cargar imágenes externas */
    background-image: url('data:image/svg+xml;utf8,%3Csvg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"%3E%3Cfilter id="noiseFilter"%3E%3CfeTurbulence type="fractalNoise" baseFrequency="0.85" numOctaves="3" stitchTiles="stitch"/%3E%3C/filter%3E%3Crect width="100%25" height="100%25" filter="url(%23noiseFilter)"/%3E%3C/svg%3E');
    opacity: 0.03; /* Casi imperceptible, pero le da textura a los negros */
    mix-blend-mode: screen;
}

/* ============================================================
   BORDES TÁCTICOS Y CALIBRACIÓN ÓPTICA
   ============================================================ */

/* 1. Viñeteado Atmosférico (Enfoca la vista al centro oscureciendo los bordes) */
.hud-vignette {
    position: fixed; inset: 0; pointer-events: none; z-index: 10;
    background: radial-gradient(circle at center, transparent 45%, rgba(0, 0, 0, 0.7) 100%);
}

/* 2. Marcos de Enfoque Óptico (Las esquineras cian) */
.hud-corners {
    position: fixed; top: 15px; left: 15px; right: 15px; bottom: 15px;
    pointer-events: none; z-index: 899;
    /* Dibujamos las 8 líneas exactas de las esquinas usando gradientes de fondo */
    background:
        linear-gradient(var(--accent), var(--accent)) top left / 40px 2px no-repeat,
        linear-gradient(var(--accent), var(--accent)) top left / 2px 40px no-repeat,
        linear-gradient(var(--accent), var(--accent)) top right / 40px 2px no-repeat,
        linear-gradient(var(--accent), var(--accent)) top right / 2px 40px no-repeat,
        linear-gradient(var(--accent), var(--accent)) bottom left / 40px 2px no-repeat,
        linear-gradient(var(--accent), var(--accent)) bottom left / 2px 40px no-repeat,
        linear-gradient(var(--accent), var(--accent)) bottom right / 40px 2px no-repeat,
        linear-gradient(var(--accent), var(--accent)) bottom right / 2px 40px no-repeat;
    opacity: 0.6;
}

/* 3. Reglas de Calibración Periférica (Las marcas laterales) */
.hud-ruler {
    position: fixed; top: 30%; bottom: 30%; width: 10px;
    pointer-events: none; z-index: 898;
    /* Genera líneas horizontales repetitivas como una cinta métrica */
    background: repeating-linear-gradient(to bottom, transparent, transparent 15px, rgba(56, 189, 248, 0.4) 15px, rgba(56, 189, 248, 0.4) 16px);
}
.hud-ruler.left { left: 15px; border-right: 1px solid rgba(56, 189, 248, 0.3); }
.hud-ruler.right { right: 15px; border-left: 1px solid rgba(56, 189, 248, 0.3); }

/* 4. Textos Verticales de Coordenadas Simbólicas */
.vertical-text {
    position: absolute; top: 50%;
    color: rgba(56, 189, 248, 0.5);
    font-family: monospace; font-size: 0.65rem;
    letter-spacing: 2px; white-space: nowrap;
    writing-mode: vertical-rl; /* Gira el texto verticalmente */
}
.hud-ruler.left .vertical-text { 
    left: 12px; 
    transform: translateY(-50%) rotate(180deg); /* Se lee de abajo hacia arriba */
} 
.hud-ruler.right .vertical-text { 
    right: 12px; 
    transform: translateY(-50%); /* Se lee de arriba hacia abajo */
}

/* Ocultar en móviles para evitar amontonamiento */
@media (max-width: 768px) {
    .hud-corners, .hud-ruler { display: none; }
}

/* ============================================================
   BOTÓN DESPLEGABLE DE CONCEPTO TÁCTICO
   ============================================================ */
.tactical-concept {
    margin-top: 15px;
    border: 1px solid rgba(56, 189, 248, 0.3);
    background: rgba(10, 15, 25, 0.6);
    border-left: 3px solid var(--accent);
    /* Hereda las propiedades del HUD táctico */
    box-shadow: inset 0 0 10px rgba(56, 189, 248, 0.05);
}

.tactical-concept summary {
    padding: 10px 15px;
    cursor: pointer;
    font-weight: 600;
    color: var(--accent);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.3s ease;
}

.tactical-concept summary:hover {
    background: rgba(56, 189, 248, 0.15);
}

/* Ocultar la flecha por defecto del navegador */
.tactical-concept summary::-webkit-details-marker { 
    display: none; 
}

/* Crear un icono de cruz '+' futurista */
.tactical-concept summary::after {
    content: '+';
    font-size: 1.2rem;
    color: var(--accent);
    transition: transform 0.3s ease;
}

/* Convertir la cruz en 'x' al abrir el panel */
.tactical-concept[open] summary::after {
    transform: rotate(45deg);
}

.tactical-concept-body {
    padding: 0 15px 15px 15px;
    color: #cbd5e1;
    font-size: 0.8rem;
    line-height: 1.6;
    border-top: 1px dashed rgba(56, 189, 248, 0.2);
    margin-top: 5px;
    padding-top: 10px;
}

.tactical-concept-body strong { 
    color: #f8fafc; 
    display: block;
    margin-bottom: 5px;
}

/* ============================================================
   CONCEPTO TÁCTICO FLOTANTE (FUERA DE LOS PANELES)
   ============================================================ */
.floating-tactical-box {
    position: absolute;
    bottom: 80px; /* Queda arriba de la telemetría central */
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    width: 90%;
    max-width: 500px;
    filter: drop-shadow(0 10px 20px rgba(0,0,0,0.8));
}

.tactical-concept {
    border: 1px solid rgba(56, 189, 248, 0.4);
    background: rgba(10, 15, 25, 0.85);
    backdrop-filter: blur(10px);
    border-left: 3px solid var(--accent);
    box-shadow: inset 0 0 15px rgba(56, 189, 248, 0.1);
    transition: all 0.3s ease;
}

.tactical-concept summary {
    padding: 12px 20px;
    cursor: pointer;
    font-weight: 600;
    color: var(--accent);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tactical-concept summary:hover { background: rgba(56, 189, 248, 0.15); }
.tactical-concept summary::-webkit-details-marker { display: none; }

.tactical-concept summary::after {
    content: '+';
    font-size: 1.4rem;
    color: var(--accent);
    transition: transform 0.3s ease;
}

.tactical-concept[open] summary::after { transform: rotate(45deg); }

.tactical-concept-body {
    padding: 0 20px 20px 20px;
    color: #cbd5e1;
    font-size: 0.85rem;
    line-height: 1.6;
    border-top: 1px dashed rgba(56, 189, 248, 0.3);
    margin-top: 5px;
    padding-top: 15px;
}

.tactical-concept-body strong { 
    color: #f8fafc; 
    display: block;
    margin-bottom: 5px;
    font-size: 0.9rem;
}

@media (max-width: 768px) { .floating-tactical-box { bottom: 90px; } }