:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --ink: #12201d;
  --muted: #4d5f5a;
  --line: #e2e8e6;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --good: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --warn-bg: #fef3c7;
  --bad-bg: #fee2e2;
  --info-bg: #e0f2fe;
  --shadow: 0 1px 2px rgba(18, 32, 29, .06), 0 4px 14px rgba(18, 32, 29, .05);
  --tabs-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1412;
    --card: #14211e;
    --ink: #e6f0ed;
    --muted: #93a8a2;
    --line: #243632;
    --accent: #2dd4bf;
    --accent-ink: #04201c;
    --good: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
    --warn-bg: #3a2c0b;
    --bad-bg: #3b1515;
    --info-bg: #0f2a3a;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 15px; color: var(--muted); font-weight: 600; letter-spacing: .02em; text-transform: uppercase; }

.topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 8px; padding: 14px 16px 6px; }
.topbar h1 { font-size: 21px; }
.monthnav { display: flex; align-items: center; gap: 4px; }
.monthnav button { border: 0; background: var(--card); width: 38px; height: 38px; border-radius: 12px; font-size: 20px; box-shadow: var(--shadow); }
.monthnav strong { min-width: 104px; text-align: center; white-space: nowrap; font-size: 14px; }

main { padding: 6px 16px 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; max-width: 720px; margin: 0 auto; }
main > *, .grid2 > *, .stack > * { min-width: 0; }
.card { background: var(--card); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.card > h2 { margin-bottom: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--muted); font-size: 14px; }
.num { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.neg { color: var(--bad); } .pos { color: var(--good); }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 560px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--card); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); }
.kpi small { color: var(--muted); display: block; font-size: 12px; }
.kpi b { font-size: 17px; font-variant-numeric: tabular-nums; }

.alert { display: grid; gap: 2px; padding: 10px 12px; border-radius: 12px; margin-top: 8px; background: var(--info-bg); }
.alert.warn { background: var(--warn-bg); } .alert.bad { background: var(--bad-bg); }
.alert b { font-size: 15px; } .alert span { font-size: 14px; color: var(--muted); }
.alert button { justify-self: start; margin-top: 6px; }

.chart-box { position: relative; height: 220px; }
.chart-box.short { height: 180px; }

.cat { display: grid; gap: 4px; padding: 9px 0; border-top: 1px solid var(--line); cursor: pointer; }
.cat:first-of-type { border-top: 0; }
.cat .row b { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.bar { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.over > i { background: var(--bad); } .bar.near > i { background: var(--warn); }

.btn { border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; background: var(--accent); color: var(--accent-ink); min-height: 44px; }
.btn.ghost { background: transparent; color: var(--accent); border: 1.5px solid var(--accent); }
.btn.danger { background: transparent; color: var(--bad); border: 1.5px solid var(--bad); }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns > .btn { flex: 1; }

input, select, textarea { width: 100%; background: var(--bg); border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 12px; min-height: 44px; }
textarea { min-height: 96px; resize: vertical; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack { display: grid; gap: 10px; }

.day { font-size: 13px; color: var(--muted); font-weight: 600; padding: 12px 2px 4px; text-transform: capitalize; display: flex; justify-content: space-between; }
.tx { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 12px; background: var(--card); border-radius: 12px; margin-bottom: 6px; box-shadow: var(--shadow); width: 100%; text-align: left; border: 0; }
.tx .l { flex: 1 1 auto; min-width: 0; }
.tx .l b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .l small { color: var(--muted); }
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--line); color: var(--muted); margin-left: 4px; vertical-align: 1px; }

.q { border: 1.5px solid var(--warn); border-radius: 14px; padding: 12px; margin-top: 10px; display: grid; gap: 8px; }
.q .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.q .side { background: var(--bg); border-radius: 10px; padding: 8px 10px; font-size: 14px; min-width: 0; }
.q .side small { color: var(--muted); display: block; }
.q .side b { display: block; overflow-wrap: anywhere; }

.pend { display: grid; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
.pend:first-of-type { border-top: 0; }
.acc { display: grid; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.acc:first-of-type { border-top: 0; }
.drop { border: 2px dashed var(--line); border-radius: 14px; padding: 22px; text-align: center; color: var(--muted); }
.draft { border: 1.5px solid var(--accent); border-radius: 14px; padding: 12px; display: grid; gap: 10px; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(4, 1fr); z-index: 20; }
.tab { position: relative; border: 0; background: transparent; display: grid; place-items: center; align-content: center; gap: 2px; color: var(--muted); font-size: 11px; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--accent); }
.tab.add svg { background: var(--accent); stroke: var(--accent-ink); border-radius: 50%; padding: 4px; width: 32px; height: 32px; }
.tab.add.active { color: var(--accent); }
.badge { position: absolute; top: 8px; right: calc(50% - 22px); width: 10px; height: 10px; border-radius: 50%; background: var(--bad); }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 30; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow: auto; z-index: 31; background: var(--card);
  border-radius: 20px 20px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); display: grid; gap: 12px; max-width: 720px; margin: 0 auto; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px); z-index: 40; background: var(--ink); color: var(--bg);
  padding: 12px 14px; border-radius: 12px; max-width: 520px; margin: 0 auto; }
.toast.err { background: var(--bad); color: #fff; }
[hidden] { display: none !important; }

.login { min-height: 70vh; display: grid; place-content: center; gap: 12px; text-align: center; padding: 24px; }
.rec { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .rec { animation: none; } }

/* accesibilidad: foco visible, hoja con botón de cierre */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
#view:focus { outline: none; }
.sheet h2 { padding-right: 48px; }
.sheet-close { position: absolute; top: 8px; right: 8px; width: 40px; height: 40px; border-radius: 20px; border: 0; background: var(--line); color: var(--ink); font-size: 24px; line-height: 1; cursor: pointer; }
.cat[role=button] { cursor: pointer; }
