/* Colores por función, no por valor: se cambian en un solo lugar para claro y oscuro. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hairline: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.04);
  --series: #2a78d6;
  --series-soft: #cde2fb;
  --on-series: #ffffff;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --serious-ink: #a8431c;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --hairline: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.06);
    --series: #3987e5;
    --series-soft: #104281;
    --good-ink: #0ca30c;
    --serious-ink: #ec835a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

/* ---------- estructura ---------- */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--page); border-bottom: 1px solid var(--hairline);
}
.top .spacer { flex: 1; }
.month { display: flex; align-items: center; gap: 2px; }
.month b { min-width: 9.5em; text-align: center; font-weight: 600; text-transform: capitalize; }
.month .narrow { display: none; }
@media (max-width: 520px) {
  .month b { min-width: 5.2em; }
  .month .wide { display: none; }
  .month .narrow { display: inline; }
  .top { gap: 4px; }
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid transparent; background: none;
  display: inline-grid; place-items: center; font-size: 18px; line-height: 1;
}
.icon-btn:hover { background: var(--wash); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 7px 11px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--page); }
main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 16px 16px 96px; }
main.loading > * { opacity: 0.55; transition: opacity 0.15s; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; background: var(--surface); border-top: 1px solid var(--hairline);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; border: 0; background: none; padding: 9px 2px 8px; font-size: 11.5px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative;
}
.tabs button .ico { font-size: 19px; line-height: 1; filter: grayscale(1); opacity: 0.7; }
.tabs button[aria-current="page"] { color: var(--ink); font-weight: 600; }
.tabs button[aria-current="page"] .ico { filter: none; opacity: 1; }
.badge {
  position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--critical); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px;
}
@media (min-width: 900px) {
  .shell { flex-direction: row; flex-wrap: wrap; }
  .top { flex: 0 0 100%; padding-left: 232px; }
  .tabs {
    top: 0; right: auto; width: 208px; flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--hairline); padding: 68px 10px 10px; gap: 2px; z-index: 4;
  }
  .tabs button { flex: 0 0 auto; flex-direction: row; gap: 10px; font-size: 14px; padding: 10px 12px; border-radius: 8px; }
  .tabs button[aria-current="page"] { background: var(--wash); }
  .badge { position: static; margin-left: auto; }
  main { margin-left: 208px; max-width: none; padding: 20px 28px 40px; }
  main > .wrap { max-width: 1040px; }
}

/* ---------- tarjetas y figuras ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.card h2 { font-size: 15px; font-weight: 600; }
.card .sub { color: var(--muted); font-size: 13px; margin-top: 1px; }
.card-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.card-head .spacer { flex: 1; }
.link { border: 0; background: none; padding: 0; color: var(--series); font-weight: 600; font-size: 13px; }
.link:hover { text-decoration: underline; }
.grid2 { display: grid; gap: 12px; }
@media (min-width: 720px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid2 > .card { margin-bottom: 0; } }
.hero-label { color: var(--ink-2); font-size: 14px; }
.hero { font-size: 48px; font-weight: 650; line-height: 1.1; letter-spacing: -0.02em; margin: 2px 0 6px; overflow-wrap: anywhere; }
@media (max-width: 380px) { .hero { font-size: 40px; } }
.delta { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; }
.delta.up { color: var(--serious-ink); }
.delta.down { color: var(--good-ink); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 12px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
  text-align: left; box-shadow: var(--shadow); display: block; width: 100%;
}
button.tile:hover { background: var(--wash); }
.tile .label { color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 22px; font-weight: 650; line-height: 1.2; margin-top: 2px; overflow-wrap: anywhere; }
.tile .note { color: var(--muted); font-size: 12px; margin-top: 2px; }
@media (max-width: 440px) { .tile .value { font-size: 19px; } .tile { padding: 12px; } }
.alert {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: 10px; margin-bottom: 12px;
  background: var(--surface); border: 1px solid var(--border); font-size: 14px;
}
.alert .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex: none; }
.alert.serious .dot { background: var(--serious); }
.alert.info .dot { background: var(--series); }
.alert.good .dot { background: var(--good); }

/* ---------- barras ordenadas (un solo color; el valor va en texto) ---------- */
.bars { display: grid; gap: 10px; }
.bar-row { display: block; width: 100%; border: 0; background: none; padding: 4px 6px; margin: -4px -6px; border-radius: 8px; text-align: left; }
button.bar-row:hover, button.bar-row:focus-visible { background: var(--wash); }
.bar-row[aria-pressed="true"] { background: var(--wash); }
.bar-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.bar-top .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-top .val { font-weight: 600; white-space: nowrap; }
.bar-track { height: 10px; margin-top: 5px; }
.bar-fill { height: 100%; min-width: 4px; background: var(--series); border-radius: 0 4px 4px 0; }
.pending-note { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- columnas (últimos meses) ---------- */
.chart svg { display: block; max-width: 100%; overflow: visible; }
.chart-slot { min-height: 210px; }
.chart .grid { stroke: var(--hairline); stroke-width: 1; }
.chart .base { stroke: var(--axis); stroke-width: 1; }
.chart .col { fill: var(--series); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .col, .chart .hit:focus-visible + .col { opacity: 0.8; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart text.cap { fill: var(--ink); font-weight: 600; font-size: 12px; }
.chart text.now { fill: var(--ink); font-weight: 600; }
table.plain { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 10px; }
table.plain th, table.plain td { padding: 6px 4px; border-bottom: 1px solid var(--hairline); text-align: left; }
table.plain td:last-child, table.plain th:last-child { text-align: right; }

/* ---------- listas de movimientos ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters select, .filters input, .field input, .field select, .field textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 38px;
}
.filters input[type="search"] { flex: 1 1 160px; min-width: 0; }
.filters select { flex: 1 1 140px; min-width: 0; max-width: 100%; }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; width: 100%; text-align: left;
  padding: 11px 14px; border: 0; border-bottom: 1px solid var(--hairline); background: none;
}
.row:last-child { border-bottom: 0; }
button.row:hover { background: var(--wash); }
.row .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amt { font-weight: 600; white-space: nowrap; text-align: right; }
.row .meta, .row .orig { color: var(--muted); font-size: 12.5px; }
.row .orig { text-align: right; white-space: nowrap; }
.row .meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .extra { grid-column: 1 / -1; margin-top: 2px; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.tag::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.tag.revisar::before { background: var(--warning); }
.tag.ok::before { background: var(--good); }
.tag.falta::before { background: var(--serious); }
.list-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 2px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }

/* ---------- por revisar ---------- */
.review { border-left: 3px solid var(--warning); }
.review .line1 { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.review .line1 b { font-size: 17px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 7px 12px; font-size: 13.5px;
  min-height: 36px;
}
.chip:hover { background: var(--wash); }
.chip.primary { background: var(--ink); color: var(--page); border-color: var(--ink); font-weight: 600; }
.chip.danger { color: var(--critical); }
.ask { margin-top: 12px; font-size: 13px; color: var(--ink-2); font-weight: 600; }
.inline-form { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.inline-form input, .inline-form select {
  flex: 1 1 120px; min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}

/* ---------- hoja de detalle ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--page); width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto;
  border-radius: 16px 16px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .backdrop { align-items: center; } .sheet { border-radius: 16px; } }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.sheet-head h2 { flex: 1; font-size: 17px; }
.field { display: grid; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.field input, .field select, .field textarea { width: 100%; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 9px 14px; font-weight: 600; min-height: 40px;
}
a.btn { display: inline-flex; align-items: center; color: var(--ink); text-decoration: none; }
a.link { text-decoration: none; }
.btn:hover { background: var(--wash); }
.btn.primary { background: var(--ink); color: var(--page); border-color: var(--ink); }
.btn.danger { color: var(--critical); }
.btn:disabled { opacity: 0.5; cursor: default; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13.5px; margin: 10px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.files a { border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; color: var(--ink); text-decoration: none; font-size: 13px; background: var(--surface); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--hairline); }
.switch:last-child { border-bottom: 0; }
.switch select { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 8px; max-width: 55%; }
.switch input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--series); }

/* ---------- avisos ---------- */
#tip {
  position: fixed; z-index: 40; pointer-events: none; background: var(--ink); color: var(--page);
  padding: 6px 9px; border-radius: 7px; font-size: 12.5px; line-height: 1.3; max-width: 240px;
}
#tip b { display: block; font-size: 13.5px; }
#toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 50; background: var(--ink); color: var(--page);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100vw - 32px); text-align: center;
}
.gate { max-width: 420px; margin: 18vh auto 0; padding: 0 24px; text-align: center; }
.gate h1 { font-size: 22px; margin-bottom: 8px; }
.gate code { background: var(--wash); padding: 2px 6px; border-radius: 5px; }
:focus-visible { outline: 2px solid var(--series); outline-offset: 2px; }
