/* ---------- Tokens (claro / oscuro) ---------- */
:root {
    color-scheme: light;
    --page: #f9f9f7;
    --surface: #fcfcfb;
    --surface-2: #f0efec;
    --ink: #0b0b0b;
    --ink-2: #52514e;
    --muted: #898781;
    --grid: #e1e0d9;
    --axis: #c3c2b7;
    --border: rgba(11, 11, 11, .10);
    --accent: #2a78d6;
    --up: #006300;
    --down: #d03b3b;
    --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
    --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
    --neg: #e34948;
    --radius: 12px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --page: #0d0d0d; --surface: #1a1a19; --surface-2: #262624;
        --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
        --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, .10);
        --accent: #3987e5; --up: #0ca30c; --down: #e66767;
        --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
        --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
        --neg: #e66767;
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #262624;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, .10);
    --accent: #3987e5; --up: #0ca30c; --down: #e66767;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --neg: #e66767;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--page);
    color: var(--ink);
    font: 15px/1.5 var(--font);
}
a { color: var(--accent); }
h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 2.25rem 0 .75rem; }
.lead { color: var(--ink-2); margin: 0 0 1.5rem; max-width: 70ch; }
.muted { color: var(--muted); }
.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
main.container { padding-top: 1.75rem; padding-bottom: 3rem; }

/* ---------- Barra superior ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 1rem; min-height: 56px; }
.brand { font-weight: 700; font-size: 1.2rem; color: var(--ink); text-decoration: none; letter-spacing: -.02em; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.nav a { color: var(--ink-2); text-decoration: none; padding: .4rem .7rem; border-radius: 8px; font-size: .93rem; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--surface-2); font-weight: 600; }
.nav-toggle, .theme-toggle {
    background: none; border: 1px solid var(--border); color: var(--ink); border-radius: 8px;
    width: 36px; height: 36px; cursor: pointer; font-size: 1rem;
}
.nav-toggle { display: none; }
@media (max-width: 860px) {
    .nav-toggle { display: block; margin-left: auto; }
    .nav { display: none; position: absolute; left: 0; right: 0; top: 56px; background: var(--surface);
           flex-direction: column; padding: .5rem 16px 1rem; border-bottom: 1px solid var(--border); }
    .nav.open { display: flex; }
}

/* ---------- Tarjetas de indicadores ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.tile {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px 16px 10px; display: flex; flex-direction: column; min-height: 132px;
}
.tile-label { font-size: .85rem; color: var(--ink-2); }
.tile-value { font-size: 1.6rem; font-weight: 600; letter-spacing: -.01em; margin-top: 2px; }
.tile-value small { font-size: .85rem; font-weight: 400; color: var(--muted); margin-left: 2px; }
.tile-meta { font-size: .8rem; color: var(--muted); display: flex; gap: .5rem; flex-wrap: wrap; }
.delta-up { color: var(--up); }
.delta-down { color: var(--down); }
.spark { position: relative; height: 36px; margin-top: auto; padding-top: 6px; }

/* ---------- Gráficos ---------- */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr)); gap: 16px; }
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; flex-wrap: wrap; margin-bottom: .5rem; }
.card-title { font-weight: 600; margin: 0; font-size: 1rem; }
.card-sub { font-size: .85rem; color: var(--ink-2); margin: 2px 0 0; }
.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 380px; }
.card-foot { display: flex; gap: .5rem; justify-content: space-between; align-items: center; margin-top: .5rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.chart-status { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: .9rem; text-align: center; padding: 1rem; }

.legend { display: flex; flex-wrap: wrap; gap: .25rem 1rem; font-size: .83rem; color: var(--ink-2); margin: .25rem 0 .5rem; }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.bar { height: 10px; width: 10px; border-radius: 2px; }
.legend i.dash { background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px) !important; }

/* Segmentado de rangos */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 2px; flex-wrap: wrap; }
.seg button {
    border: 0; background: none; color: var(--ink-2); font: inherit; font-size: .8rem;
    padding: .25rem .55rem; border-radius: 6px; cursor: pointer;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }

.btn-link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: .8rem; padding: 0; }
.btn-link:hover { text-decoration: underline; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; max-height: 420px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { padding: .45rem .75rem; text-align: left; border-bottom: 1px solid var(--grid); }
th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; color: var(--ink-2); z-index: 1; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }

/* ---------- Formularios ---------- */
input, select {
    font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--axis);
    border-radius: 8px; padding: .45rem .6rem; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; }
.form-row label { display: flex; flex-direction: column; gap: .25rem; font-size: .83rem; color: var(--ink-2); }

/* ---------- Conversor ---------- */
.converter { display: grid; grid-template-columns: 1fr auto 1fr; gap: .75rem; align-items: end; }
.converter .eq { padding-bottom: .5rem; color: var(--muted); }
.converter output { font-size: 1.5rem; font-weight: 600; }
@media (max-width: 560px) { .converter { grid-template-columns: 1fr; } .converter .eq { display: none; } }

/* ---------- Explorador ---------- */
.explorer { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .explorer { grid-template-columns: 1fr; } }
.var-list { max-height: 640px; overflow-y: auto; margin-top: .5rem; }
.var-list details { border-bottom: 1px solid var(--grid); }
.var-list summary { cursor: pointer; padding: .5rem .25rem; font-weight: 600; font-size: .88rem; }
.var-list summary .muted { font-weight: 400; }
.var-item {
    display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--ink);
    font: inherit; font-size: .84rem; padding: .35rem .5rem; border-radius: 6px; cursor: pointer;
}
.var-item:hover { background: var(--surface-2); }
.var-item .muted { font-size: .76rem; display: block; }
.var-item[aria-pressed="true"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; }
.chip { display: inline-flex; align-items: center; gap: .4rem; background: var(--surface-2); border-radius: 999px; padding: .25rem .4rem .25rem .7rem; font-size: .83rem; max-width: 100%; }
.chip i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; }

.alert { background: var(--surface-2); border-left: 3px solid var(--down); padding: .75rem 1rem; border-radius: 6px; }
.note { font-size: .85rem; color: var(--ink-2); background: var(--surface-2); padding: .75rem 1rem; border-radius: 8px; }

.footer { border-top: 1px solid var(--border); padding: 1.5rem 0; font-size: .83rem; color: var(--muted); }
