:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1c1f1d;
  --muted: #646b67;
  --line: #e3e1da;
  --primary: #14532d;
  --primary-text: #ffffff;
  --primary-soft: #e3efe6;
  --danger: #a12a1e;
  --warn-bg: #fdf3dc;
  --warn-text: #6b4a00;
  --info-bg: #e8eef8;
  --info-text: #1f3b66;
  --ok-text: #1d6b39;
  --block-bg: #fbe5e2;
  --demo: #6d28d9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1311;
    --surface: #181d1a;
    --text: #e8ebe9;
    --muted: #9aa39e;
    --line: #2a312d;
    --primary: #4ade80;
    --primary-text: #0b1410;
    --primary-soft: #183424;
    --danger: #f87171;
    --warn-bg: #3a2d0c;
    --warn-text: #f5d58a;
    --info-bg: #17243a;
    --info-text: #b9cdf0;
    --ok-text: #6ee79b;
    --block-bg: #3d1a17;
    --demo: #a78bfa;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

body.is-demo .top { border-bottom: 3px solid var(--demo); }

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; font-size: 20px; letter-spacing: -.01em; }

.status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; margin-top: 2px; }
.status:empty { display: none; }

.chip { font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; }
.chip-edit { background: var(--primary-soft); color: var(--ok-text); }
.chip-ro { background: var(--info-bg); color: var(--info-text); }

main, .banners { max-width: 720px; margin: 0 auto; padding: 0 16px; }
main { padding-top: 12px; }

.banners:empty { display: none; }
.banner { margin-top: 10px; padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.banner-demo { background: color-mix(in srgb, var(--demo) 15%, var(--surface)); }
.banner-info, .banner-ro { background: var(--info-bg); color: var(--info-text); }
.banner-warn { background: var(--warn-bg); color: var(--warn-text); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 10px; font-size: 17px; }
details.card summary { cursor: pointer; font-weight: 600; }
details.card[open] summary { margin-bottom: 10px; }

p { margin: 0 0 10px; }
.hint { font-size: 13px; color: var(--muted); }
.muted { color: var(--muted); }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.wrap { overflow-wrap: anywhere; }

button {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 14px;
  min-height: 44px;
  cursor: pointer;
}
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
button.danger { color: var(--danger); }
button.primary.danger, form[data-form="wipe"] button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.block { display: block; width: 100%; margin-bottom: 6px; }
button.small { min-height: 36px; padding: 6px 10px; font-size: 14px; }
button.link { background: none; border: 0; padding: 0; min-height: 0; color: inherit; text-decoration: underline; font-weight: 600; }
button.add { margin-bottom: 12px; }

.stack { display: flex; flex-direction: column; gap: 6px; }
.stack .hint { margin-top: -2px; }
.choice { margin-top: 14px; }

label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 12px; }
label input:not([type=checkbox]) {
  display: block;
  width: 100%;
  margin-top: 4px;
  font: inherit;
  font-size: 17px;
  font-weight: 400;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  min-height: 44px;
}
label.check { display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: 16px; }
label.check input { width: 22px; height: 22px; accent-color: var(--primary); }
input:focus-visible, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

form.no-enc .enc { display: none; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: var(--bg); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; }
.kpi-wide { grid-column: 1 / -1; }
.kpi-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-unit { font-size: 13px; color: var(--muted); }
.kpi-label { font-size: 13px; color: var(--muted); margin-top: 4px; }
.kpi-empty { font-size: 17px; font-weight: 700; margin: 2px 0; }

.list { list-style: none; margin: 0 0 12px; padding: 0; }
.list li { margin-bottom: 8px; }
.list li.empty { color: var(--muted); font-size: 14px; padding: 12px; text-align: center; }
.row { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 2px; font-weight: 400; padding: 12px 14px; }
.row-main { display: flex; justify-content: space-between; align-items: baseline; font-variant-numeric: tabular-nums; }
.row-sub { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tag { display: inline-block; margin-left: 6px; font-size: 12px; font-weight: 600; padding: 0 7px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.tag-full { background: var(--primary-soft); border-color: transparent; color: var(--ok-text); }

.tbl { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 10px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { text-align: right; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }

.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 0 0 12px; font-size: 14px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }

.plain { list-style: none; margin: 0; padding: 0; }
.plain li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.plain li:last-child { border-bottom: 0; }
.row-actions { display: flex; flex-direction: column; gap: 6px; }

.issues { list-style: none; padding: 0; margin: 0 0 12px; font-size: 14px; }
.issues li { padding: 8px 10px; border-radius: 8px; margin-bottom: 6px; }
.lvl-ok { color: var(--ok-text); background: var(--primary-soft); }
.lvl-info { color: var(--info-text); background: var(--info-bg); }
.lvl-warn { color: var(--warn-text); background: var(--warn-bg); }
.lvl-block { color: var(--danger); background: var(--block-bg); }
.box { padding: 10px 12px; border-radius: 10px; font-size: 14px; }

.steps { padding-left: 20px; margin: 0 0 12px; }
.steps li { margin-bottom: 8px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.spacer { flex: 1; }

dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin: 0 0 12px; font-size: 19px; }

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs[hidden] { display: none; }
.tabs button {
  flex: 1;
  max-width: 200px;
  border: 0;
  border-radius: 0;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 4px;
  min-height: 56px;
}
.tabs button.active { color: var(--primary); }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 20;
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast[hidden] { display: none; }

/* ---------- Planificación (v0.2) ---------- */
h3 { font-size: 15px; margin: 14px 0 8px; }
.small { font-size: 12px; }
.qn { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--primary-soft); color: var(--ok-text); font-size: 13px; margin-right: 8px; vertical-align: 1px; }
.big { font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; margin: 2px 0 4px; }
.neg { color: var(--danger); }
.pos { color: var(--ok-text); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.kv { list-style: none; margin: 8px 0 10px; padding: 0; font-size: 14px; }
.kv li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.kv li:last-child { border-bottom: 0; }
.kv li.total { font-weight: 700; border-top: 1px solid var(--text); border-bottom: 0; }
.kv li.neg .num { color: var(--danger); }

.seg { display: flex; gap: 4px; overflow-x: auto; padding: 3px; margin: 0 0 12px; background: var(--line); border-radius: 12px; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: 1 0 auto; border: 0; background: transparent; min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 9px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.scenario-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.scenario-bar .seg { flex: 1 1 auto; margin-bottom: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.chip-btn { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 999px; }
.chip-btn.on { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.chip-btn.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }

.chart { width: 100%; height: auto; display: block; margin: 6px 0 2px; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; }
.chart .s-free { stroke: var(--primary); }
.chart .s-liq { stroke: var(--muted); stroke-dasharray: 4 3; stroke-width: 1.5; }
.chart .zero { stroke: var(--danger); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .mk { fill: var(--primary); }
.chart .tk { font-size: 9px; fill: var(--muted); text-anchor: middle; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.sw { display: inline-block; width: 14px; height: 0; border-top: 2px solid; margin-right: 5px; vertical-align: middle; }
.sw.s-free { border-color: var(--primary); }
.sw.s-liq { border-color: var(--muted); border-top-style: dashed; }

.tbl-wrap { overflow-x: auto; margin: 0 -4px; }
.tbl-click tbody tr { cursor: pointer; }
.tbl-click tbody tr:active { background: var(--bg); }
.warn-row td { background: var(--warn-bg); }
.tbl td.neg { color: var(--danger); }

.list.compact li { margin-bottom: 6px; }
.list.compact .row { padding: 10px 12px; min-height: 0; }
.row .row-main { gap: 10px; }
.row.slim { border: 0; border-radius: 0; padding: 6px 0; min-height: 0; border-top: 1px solid var(--line); }
.days { list-style: none; padding: 0; margin: 0; }
.days li.day { padding: 8px 0 4px; border-bottom: 1px solid var(--line); }
.day-h { display: flex; justify-content: space-between; font-size: 14px; }
.plain-cards { list-style: none; margin: 0; padding: 0; }
.card.res progress { width: 100%; height: 8px; accent-color: var(--primary); margin: 6px 0 2px; }
.grp { margin: 18px 4px 8px; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.adj li { align-items: center; }
.tag-var { background: var(--info-bg); color: var(--info-text); border-color: transparent; }
.tag-est { background: var(--bg); }
.tag-warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.actions-top { margin: 0 0 6px; }
.actions-top button { flex: 1; }
.tbl td:first-child { white-space: nowrap; }

select, textarea {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 16px; font-weight: 400;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); min-height: 44px;
}
label select, label textarea { margin-top: 4px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 2px; margin: 0 0 12px; }
legend { font-size: 14px; font-weight: 600; padding: 0 4px; }
details.sub { margin: -4px 0 12px; font-size: 14px; }
details.sub summary { color: var(--muted); cursor: pointer; margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 0 10px; }
.months { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 8px 0 10px; }
label.check.mini { font-size: 14px; margin: 0; gap: 6px; }
label.check.mini input { width: 18px; height: 18px; }
label.check input[type=radio] { width: 20px; height: 20px; accent-color: var(--primary); }

.sk { display: none; margin-top: 10px; }
form[data-skind="once"] .sk-once, form[data-skind="monthly"] .sk-monthly, form[data-skind="months"] .sk-months, form[data-skind="dates"] .sk-dates { display: block; }
form[data-form="commitment"] .only-transfer { display: none; }
form[data-type="transferencia"] .only-transfer { display: block; }
form[data-type="transferencia"] .not-transfer { display: none; }
form[data-type="ingreso"] .only-gasto { display: none; }
form[data-form="occurrence"] .real-fields { display: none; }
form[data-form="occurrence"].is-real .real-fields { display: grid; }
