/* ===== Paleta validada (dataviz) + tema claro/oscuro ===== */
:root {
  --surface-1: #fcfcfb;      /* superficie de tarjetas/gráfico */
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --good: #006300;
  --bad: #c0392b;
  --accent: #2a78d6;
  --accent-soft: #cde2fb;
  /* categorical slots (light) */
  --s1: #2a78d6; --s2: #1baf7a; --s3: #eda100; --s4: #008300;
  --s5: #4a3aa7; --s6: #e34948; --s7: #e87ba4; --s8: #eb6834;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(11,11,11,.04), 0 4px 16px rgba(11,11,11,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --good: #0ca30c;
    --bad: #e66767;
    --accent: #3987e5;
    --accent-soft: #184f95;
    --s1: #3987e5; --s2: #199e70; --s3: #c98500; --s4: #008300;
    --s5: #9085e9; --s6: #e66767; --s7: #d55181; --s8: #d95926;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h3 { margin: 0; font-weight: 650; }
.muted { color: var(--muted); font-size: .85rem; }

/* ===== Topbar ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  max-width: 1180px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: .75rem; }
.brand__mark {
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 10px;
  background: linear-gradient(135deg, var(--s1), var(--s5));
  color: #fff; font-size: 1.5rem; font-weight: 700;
}
.brand h1 { font-size: 1.15rem; letter-spacing: -.01em; }
.brand__sub { margin: 0; font-size: .8rem; color: var(--text-secondary); }
.pill {
  font-size: .78rem; color: var(--text-secondary);
  background: var(--surface-1); border: 1px solid var(--border);
  padding: .3rem .6rem; border-radius: 999px; white-space: nowrap;
}

/* ===== Tabs ===== */
.tabs {
  display: flex; gap: .25rem; max-width: 1180px; margin: 0 auto;
  padding: 0 1.25rem; border-bottom: 1px solid var(--border);
}
.tab {
  appearance: none; background: none; border: none; cursor: pointer;
  font: inherit; color: var(--text-secondary);
  padding: .7rem .9rem; border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text-primary); }
.tab.is-active { color: var(--text-primary); border-bottom-color: var(--accent); font-weight: 600; }

/* ===== Views ===== */
.view { display: none; max-width: 1180px; margin: 0 auto; padding: 1.25rem; }
.view.is-active { display: block; }

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}

/* ===== Toolbar / inputs ===== */
.toolbar { display: flex; align-items: center; gap: .75rem; margin-bottom: .85rem; }
.input {
  font: inherit; color: var(--text-primary);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: .45rem .65rem; outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#valores-search { min-width: 240px; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .6rem .8rem; text-align: left; white-space: nowrap; }
.table thead th {
  color: var(--muted); font-weight: 600; font-size: .78rem;
  text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: var(--surface-1);
}
.table tbody tr { border-bottom: 1px solid var(--grid); }
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.th-sortable { cursor: pointer; user-select: none; }
.th-sortable.sorted::after { content: " ▾"; color: var(--accent); }
.th-sortable.sorted.asc::after { content: " ▴"; }
.chip-money {
  display: inline-block; font-size: .72rem; padding: .1rem .45rem;
  border-radius: 999px; border: 1px solid var(--border); color: var(--text-secondary);
}
.delta-up { color: var(--good); }
.delta-down { color: var(--bad); }

/* ===== Comparador layout ===== */
.comparador { display: grid; grid-template-columns: 260px 1fr; gap: 1.25rem; }
.panel {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem; align-self: start; position: sticky; top: 1rem;
}
.panel__block + .panel__block { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--grid); }
.panel__title { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin-bottom: .6rem; }

.picker { display: flex; flex-direction: column; gap: .1rem; max-height: 240px; overflow-y: auto; }
.picker label {
  display: flex; align-items: center; gap: .55rem; cursor: pointer;
  padding: .3rem .35rem; border-radius: 7px; font-size: .88rem;
}
.picker label:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.picker input { accent-color: var(--accent); width: 15px; height: 15px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.swatch--dash { width: 14px; height: 0; border-top: 2px dashed var(--muted); border-radius: 0; }
.dolar-toggle { display: flex; align-items: center; gap: .55rem; cursor: pointer; font-size: .88rem; padding: .3rem .35rem; border-radius: 7px; }
.dolar-toggle:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.dolar-toggle input { accent-color: var(--accent); width: 15px; height: 15px; }

.presets { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem; }
.preset, .seg {
  appearance: none; font: inherit; cursor: pointer;
  background: var(--surface-1); color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: 8px; padding: .4rem .5rem; font-size: .82rem;
}
.preset:hover, .seg:hover { color: var(--text-primary); border-color: var(--accent); }
.preset.is-active, .seg.is-active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--text-primary); border-color: var(--accent); font-weight: 600;
}
.range-custom { display: flex; flex-direction: column; gap: .5rem; margin-top: .6rem; }
.range-custom label { display: flex; flex-direction: column; gap: .2rem; font-size: .78rem; color: var(--muted); }
.segmented { display: inline-flex; gap: .25rem; }
.hint { font-size: .76rem; color: var(--muted); margin: .55rem 0 0; }

/* ===== Stat tiles ===== */
.stat-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: .7rem .8rem; border-left: 3px solid var(--slot, var(--accent));
}
.stat__name { font-size: .78rem; color: var(--text-secondary); display: flex; align-items: center; gap: .4rem; }
.stat__val { font-size: 1.3rem; font-weight: 650; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.stat__sub { font-size: .74rem; color: var(--muted); margin-top: .1rem; }

/* ===== Chart card ===== */
.chart-card { padding: 1rem 1.1rem 1.2rem; }
.chart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.chart-title { font-size: 1rem; }
.link-btn { appearance: none; background: none; border: none; font: inherit; color: var(--accent); cursor: pointer; font-size: .85rem; }
.link-btn:hover { text-decoration: underline; }
.chart-box { position: relative; height: 420px; }
.chart-table { margin-top: 1rem; }
.empty-hint, .empty-hint[hidden] { }
.empty-hint { color: var(--muted); text-align: center; padding: 3rem 1rem; }

.foot { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem; }

@media (max-width: 760px) {
  .comparador { grid-template-columns: 1fr; }
  .panel { position: static; }
  .chart-box { height: 340px; }
}
[hidden] { display: none !important; }
