:root {
    --ink: #0d1a1c;
    --ink-soft: #294046;
    --paper: #edf1ea;
    --panel: rgba(10, 19, 22, 0.88);
    --panel-border: rgba(144, 255, 214, 0.2);
    --toxic-green: #95ff5f;
    --toxic-cyan: #18f0d4;
    --toxic-blue: #2d7cff;
    --toxic-lime: #d4ff61;
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 10px 25px rgba(0, 0, 0, 0.2);
    --radius-lg: 24px;
    --radius-md: 16px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--paper);
    background:
        radial-gradient(circle at top left, rgba(28, 124, 255, 0.15), transparent 26%),
        radial-gradient(circle at bottom right, rgba(149, 255, 95, 0.18), transparent 24%),
        linear-gradient(135deg, #071013 0%, #102329 45%, #17363f 100%);
}

body {
    min-height: 100vh;
}

.app-shell {
    display: grid;
    grid-template-columns: 360px 1fr;
    min-height: 100vh;
}

.control-panel {
    padding: 28px 22px 24px;
    background: var(--panel);
    backdrop-filter: blur(18px);
    border-right: 1px solid var(--panel-border);
    overflow-y: auto;
}

.panel-kicker,
.heading-kicker {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--toxic-cyan);
}

.control-panel h1,
.map-heading h2 {
    margin: 10px 0 12px;
    font-family: "Poppins", sans-serif;
    font-size: 31px;
    line-height: 1.05;
    letter-spacing: -0.03em;
}

.panel-intro,
.map-heading p,
.note-card p,
.legend-item p {
    margin: 0;
    color: rgba(237, 241, 234, 0.78);
    line-height: 1.55;
}

.control-block {
    margin-top: 20px;
}

.control-block label {
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(237, 241, 234, 0.82);
}

.control-block select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid rgba(237, 241, 234, 0.18);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.08);
    color: #f6f7f0;
    font-size: 14px;
    outline: none;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2318f0d4' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.control-block select:hover {
    border-color: rgba(237, 241, 234, 0.32);
    background-color: rgba(255, 255, 255, 0.11);
}

.control-block select:focus-visible {
    outline: 2px solid var(--toxic-cyan);
    outline-offset: 2px;
    border-color: var(--toxic-cyan);
}

.slider-readout {
    display: grid;
    gap: 10px;
}

.slider-year {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    min-width: 76px;
    padding: 7px 12px;
    border-radius: 999px;
    background: rgba(57, 255, 20, 0.14);
    color: #efffea;
    font-size: 14px;
    font-weight: 800;
    box-shadow: inset 0 0 0 1px rgba(57, 255, 20, 0.18);
}

input[type="range"] {
    width: 100%;
    appearance: none;
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(0, 119, 255, 0.28), rgba(57, 255, 20, 0.35));
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 999px;
    background: #39ff14;
    box-shadow: 0 0 18px rgba(57, 255, 20, 0.42);
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 999px;
    background: #39ff14;
    box-shadow: 0 0 18px rgba(57, 255, 20, 0.42);
    cursor: pointer;
}

.checkbox-row {
    display: flex !important;
    align-items: center;
    gap: 10px;
    margin-bottom: 0 !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
}

.checkbox-row input {
    width: 18px;
    height: 18px;
    accent-color: var(--toxic-cyan);
}

.legend-card,
.note-card {
    margin-top: 24px;
    padding: 18px 18px 16px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(237, 241, 234, 0.1);
    box-shadow: var(--shadow-md);
}

.legend-card h2,
.note-card h2 {
    margin: 0 0 12px;
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.metric-summary {
    margin-bottom: 14px;
    color: rgba(237, 241, 234, 0.8);
    font-size: 13px;
    line-height: 1.45;
}

.legend-scale {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-end;
}

.scale-step {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.scale-bubble {
    border-radius: 999px;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.08),
        0 0 24px rgba(24, 240, 212, 0.14);
}

.scale-label {
    text-align: center;
    font-size: 11px;
    color: rgba(237, 241, 234, 0.76);
}

.legend-divider {
    height: 1px;
    margin: 14px 0;
    background: rgba(237, 241, 234, 0.12);
}

.legend-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.legend-item strong {
    display: block;
    margin-bottom: 3px;
    font-size: 13px;
}

.legend-chip {
    width: 16px;
    height: 16px;
    margin-top: 2px;
    border-radius: 999px;
    flex-shrink: 0;
}

.legend-factory-icon {
    width: 28px;
    height: 28px;
    object-fit: contain;
    flex-shrink: 0;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.3));
}

.map-stage {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 18px;
}

.map-heading {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: flex-end;
    padding: 0 10px 16px;
}

.map-heading h2 {
    margin-bottom: 6px;
    font-size: 40px;
}

.map-heading p {
    max-width: 480px;
    font-size: 14px;
    text-align: right;
}

#map {
    flex: 1;
    min-height: 680px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(237, 241, 234, 0.08);
}

.leaflet-container {
    background: linear-gradient(180deg, #dbe9db 0%, #d0ddd8 100%);
}

.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow-md) !important;
}

.leaflet-control-zoom a {
    color: var(--ink) !important;
}

.leaflet-popup-content-wrapper {
    background: rgba(8, 18, 20, 0.94);
    color: #f3f6ef;
    border: 1px solid rgba(149, 255, 95, 0.2);
    border-radius: 16px;
}

.leaflet-popup-tip {
    background: rgba(8, 18, 20, 0.94);
}

.popup-card h3 {
    margin: 0 0 10px;
    font-family: "Poppins", sans-serif;
    font-size: 20px;
    line-height: 1.1;
}

.popup-card p {
    margin: 0 0 8px;
    color: rgba(243, 246, 239, 0.82);
    line-height: 1.45;
    font-size: 13px;
}

.popup-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 14px;
    margin-top: 12px;
}

.popup-grid div {
    font-size: 12px;
    color: rgba(243, 246, 239, 0.72);
}

.popup-grid strong {
    display: block;
    margin-bottom: 2px;
    color: #ffffff;
    font-size: 12px;
}

.monitor-label {
    background: rgba(8, 18, 20, 0.92);
    color: #f5f7f2;
    border: 1px solid rgba(149, 255, 95, 0.24);
    border-radius: 999px;
    box-shadow: var(--shadow-md);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.03em;
    padding: 6px 10px;
}

.monitor-label::before {
    display: none;
}

.repda-cluster-icon {
    position: relative;
}

.repda-cluster-icon img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
}

.repda-cluster-icon span {
    position: absolute;
    top: -5px;
    right: -7px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: rgba(255, 45, 149, 0.96);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 10px rgba(255, 45, 149, 0.5);
    font-family: "Manrope", sans-serif;
}

/* ── Multiparámetro: checkboxes ─────────────────────────────── */

.param-toggle-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.param-toggle-btn {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid rgba(237, 241, 234, 0.2);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    color: rgba(237, 241, 234, 0.88);
    font-family: "Manrope", sans-serif;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
}

.param-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.14);
}

#parameter-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.param-checkbox-row {
    display: flex !important;
    align-items: center;
    gap: 10px;
    margin-bottom: 0 !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
    cursor: pointer;
}

.param-checkbox-row input {
    width: 16px;
    height: 16px;
    accent-color: var(--toxic-cyan);
    flex-shrink: 0;
}

.param-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    flex-shrink: 0;
}

/* ── Multiparámetro: leyenda ────────────────────────────────── */

.legend-param-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0;
}

.legend-param-dot {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    flex-shrink: 0;
}

.legend-param-info {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    line-height: 1.3;
}

.legend-param-info strong {
    color: #fff;
    font-size: 12px;
}

.legend-param-info span {
    color: rgba(237, 241, 234, 0.6);
    font-size: 11px;
}

/* ── Íconos ─────────────────────────────────────────────────── */

.factory-icon {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.28));
    pointer-events: none;
}

@media (max-width: 1100px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .control-panel {
        border-right: none;
        border-bottom: 1px solid var(--panel-border);
    }

    .map-heading {
        flex-direction: column;
        align-items: flex-start;
    }

    .map-heading p {
        text-align: left;
    }
}

@media (max-width: 720px) {
    .control-panel,
    .map-stage {
        padding: 16px;
    }

    .control-panel h1,
    .map-heading h2 {
        font-size: 28px;
    }

    #map {
        min-height: 72vh;
    }
}

/* ── Navegación entre páginas ───────────────────────────────── */

.page-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.page-nav-btn {
    flex: 1;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid rgba(24, 240, 212, 0.28);
    background: transparent;
    color: rgba(237, 241, 234, 0.65);
    font-family: "Manrope", sans-serif;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    text-decoration: none;
    text-align: center;
    letter-spacing: 0.02em;
}

.page-nav-btn:hover {
    background: rgba(24, 240, 212, 0.08);
    color: var(--toxic-cyan);
    border-color: rgba(24, 240, 212, 0.5);
}

.page-nav-btn[aria-current="page"] {
    background: rgba(24, 240, 212, 0.12);
    color: var(--toxic-cyan);
    border-color: rgba(24, 240, 212, 0.6);
}

.page-nav-btn:focus-visible {
    outline: 2px solid var(--toxic-cyan);
    outline-offset: 2px;
}

/* ── Overlay de carga ───────────────────────────────────────── */

.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(7, 16, 19, 0.94);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    backdrop-filter: blur(6px);
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(24, 240, 212, 0.18);
    border-top-color: var(--toxic-cyan);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-text {
    font-family: "Manrope", sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: rgba(237, 241, 234, 0.65);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin: 0;
}

/* ── Hover / focus en checkboxes y botones de parámetro ─────── */

.checkbox-row:focus-within {
    outline: 2px solid var(--toxic-cyan);
    outline-offset: 3px;
    border-radius: 6px;
}

.param-toggle-btn:focus-visible {
    outline: 2px solid var(--toxic-cyan);
    outline-offset: 2px;
}

.param-toggle-btn:active {
    transform: scale(0.97);
    background: rgba(24, 240, 212, 0.1);
}

.param-checkbox-row:hover {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 6px;
    padding-left: 4px;
    padding-right: 4px;
}

/* ── Responsive mobile: panel con scroll interno ────────────── */

@media (max-width: 768px) {
    .control-panel {
        max-height: 52vh;
        overflow-y: auto;
        scrollbar-width: thin;
        scrollbar-color: rgba(24, 240, 212, 0.28) transparent;
    }

    .control-panel::-webkit-scrollbar {
        width: 4px;
    }

    .control-panel::-webkit-scrollbar-thumb {
        background: rgba(24, 240, 212, 0.28);
        border-radius: 999px;
    }

    #map {
        min-height: 55vh;
    }
}

/* ── Contraste de texto secundario en leyenda ───────────────── */

.legend-param-info span {
    color: rgba(237, 241, 234, 0.72);
}

/* ── Reduced motion ─────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .loading-spinner {
        animation: none;
        border-color: var(--toxic-cyan);
    }

    .page-nav-btn,
    .param-toggle-btn,
    .control-block select {
        transition: none;
    }
}
