@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface2: #21262d;
    --border: #30363d;
    --accent: #58a6ff;
    --green: #3fb950;
    --red: #f85149;
    --yellow: #e3b341;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --radius: 10px;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ── HEADER ────────────────────────────────────────────────── */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
    z-index: 1000;
}

header .logo {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--accent);
    text-transform: uppercase;
    opacity: 0.8;
}

header h1 {
    font-size: 1rem;
    font-weight: 600;
    flex: 1;
}

header .badge {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2px 10px;
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* ── LAYOUT ────────────────────────────────────────────────── */
.layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── SIDEBAR ───────────────────────────────────────────────── */
.sidebar {
    width: 320px;
    min-width: 300px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-scroll {
    overflow-y: auto;
    flex: 1;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.sidebar-scroll::-webkit-scrollbar {
    width: 4px;
}

.sidebar-scroll::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

.card-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

/* ── SELECTORS ─────────────────────────────────────────────── */
select,
input[type=range] {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 7px 10px;
    font-size: 0.82rem;
    font-family: inherit;
    outline: none;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color .2s;
}

select:hover,
select:focus {
    border-color: var(--accent);
}

select:last-child,
input[type=range]:last-child {
    margin-bottom: 0;
}

label {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 4px;
}

/* ── MODE TOGGLE ───────────────────────────────────────────── */
.mode-toggle {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.mode-btn {
    flex: 1;
    padding: 7px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    transition: all .2s;
}

.mode-btn.active {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(88, 166, 255, 0.08);
}

/* ── YEAR SLIDER ───────────────────────────────────────────── */
.slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.slider-row input {
    flex: 1;
    margin: 0;
}

.year-badge {
    background: var(--accent);
    color: #000;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.8rem;
    font-weight: 700;
    min-width: 42px;
    text-align: center;
}

/* ── STATS BAR ─────────────────────────────────────────────── */
.stats-bar {
    display: flex;
    gap: 6px;
}

.stat-pill {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 6px;
    text-align: center;
}

.stat-pill .sv {
    font-size: 1rem;
    font-weight: 700;
}

.stat-pill .sl {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.sv.green {
    color: var(--green);
}

.sv.red {
    color: var(--red);
}

.sv.blue {
    color: var(--accent);
}

/* ── LEGEND ────────────────────────────────────────────────── */
.legend-bar {
    height: 10px;
    border-radius: 5px;
    background: linear-gradient(to right, rgb(200, 40, 30), rgb(170, 210, 40), rgb(30, 190, 70));
    margin: 6px 0 4px;
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--text-muted);
}

/* ── RANKING LIST ──────────────────────────────────────────── */
.rank-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rank-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    background: var(--bg);
    cursor: pointer;
    transition: background .15s;
    font-size: 0.78rem;
}

.rank-item:hover {
    background: var(--surface);
}

.rank-n {
    font-size: 0.65rem;
    color: var(--text-muted);
    min-width: 18px;
}

.rank-cusec {
    color: var(--text-muted);
    font-size: 0.7rem;
    flex: 1;
}

.rank-val {
    font-weight: 600;
}

.rank-val.hi {
    color: var(--green);
}

.rank-val.lo {
    color: var(--red);
}

.rank-separator {
    text-align: center;
    font-size: 0.65rem;
    color: var(--text-muted);
    padding: 2px 0;
}

/* ── NATIONAL RANKING ─────────────────────────────────────── */
.rank-nacional {
    background: linear-gradient(135deg, rgba(88, 166, 255, 0.08), rgba(63, 185, 80, 0.06));
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 4px;
}

.rn-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent);
    margin-bottom: 4px;
}

.rn-pos {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
}

.rn-pos .rn-total {
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--text-muted);
}

.rn-bar-wrap {
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    margin: 6px 0;
    overflow: hidden;
}

.rn-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--green), var(--accent));
    border-radius: 3px;
    transition: width .5s ease;
}

.rn-info {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.rn-info b {
    color: var(--text);
}

/* ── CHART ─────────────────────────────────────────────────── */
#chart-container {
    position: relative;
    height: 140px;
}

/* ── DETAIL PANEL ──────────────────────────────────────────── */
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.detail-cusec {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 4px;
}

/* ── BUTTONS ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: all .2s;
    width: 100%;
    justify-content: center;
}

.btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
    font-weight: 600;
}

.btn.primary:hover {
    background: #79b8ff;
}

/* ── MAP ───────────────────────────────────────────────────── */
#map {
    width: 100%;
    height: 100%;
    background: #0d1117;
}

/* ── LOADING ───────────────────────────────────────────────── */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(13, 17, 23, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── TOOLTIP ───────────────────────────────────────────────── */
.map-tooltip {
    background: var(--surface) !important;
    border: 1px solid var(--border) !important;
    color: var(--text) !important;
    border-radius: 8px !important;
    padding: 10px 12px !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 0.82rem !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5) !important;
}

/* ── EVOLUTION CONTROLS ────────────────────────────────────── */
.evo-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.evo-row>div {
    flex: 1;
}

.info-bar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 0.75rem;
    color: var(--text-muted);
    z-index: 500;
    pointer-events: none;
    white-space: nowrap;
}

/* ── OPACITY CONTROL ───────────────────────────────────────── */
.opacity-control {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 12px;
    backdrop-filter: blur(6px);
}

.oc-icon {
    font-size: 1rem;
    cursor: default;
}

.oc-val {
    font-size: 0.7rem;
    color: var(--text-muted);
    min-width: 30px;
}

.opacity-control input[type="range"] {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.opacity-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
    cursor: pointer;
}

/* ── HELP BUTTON ───────────────────────────────────────────── */
.btn-help {
    margin-left: auto;
    background: rgba(88, 166, 255, 0.12);
    border: 1px solid var(--accent);
    color: var(--accent);
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
}

.btn-help:hover {
    background: rgba(88, 166, 255, 0.25);
    transform: scale(1.05);
}

/* ── MODAL ─────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn .2s ease;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: min(860px, 92vw);
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp .3s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all .15s;
}

.btn-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    line-height: 1.6;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.modal-body h3 {
    color: var(--text);
    font-size: 0.92rem;
    font-weight: 700;
    margin: 18px 0 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body p {
    margin-bottom: 8px;
}

.modal-body ul {
    padding-left: 18px;
    margin-bottom: 8px;
}

.modal-body li {
    margin-bottom: 4px;
}

.modal-body b {
    color: var(--text);
}

.modal-body code {
    background: var(--bg);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.78rem;
    color: var(--accent);
}

/* ── HELP TABLE ────────────────────────────────────────────── */
.help-table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0 12px;
    font-size: 0.78rem;
}

.help-table th {
    background: var(--bg);
    color: var(--accent);
    padding: 6px 8px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--border);
}

.help-table td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
}

.help-table tr:hover td {
    background: rgba(88, 166, 255, 0.04);
}

.help-footer {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}