:root {
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e2dd;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --bar: #2a78d6;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-ink: #b42323;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #262624; --border: #33332f;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #3987e5; --bar: #3987e5; --good-ink: #4cc24c; --critical-ink: #ef7b7b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #262624; --border: #33332f;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #3987e5; --bar: #3987e5; --good-ink: #4cc24c; --critical-ink: #ef7b7b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; }
main { max-width: 720px; margin: 0 auto; padding: 12px 16px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); margin: 20px 0 8px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--good-ink); }
.neg { color: var(--text); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.hero { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hero .card { margin: 0; }
.hero .label { font-size: 12px; color: var(--text-2); }
.hero .value { font-size: 22px; font-weight: 650; margin-top: 2px; }
.hero .wide { grid-column: 1 / -1; }
.hero .wide .value { font-size: 30px; }

.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--border); cursor: pointer; }
.row:first-child { border-top: 0; }
.row:active { background: var(--surface-2); }
.row .ico { width: 34px; height: 34px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; flex: none; font-size: 17px; }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amt { text-align: right; font-weight: 600; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); }
.badge.pend { background: #fff2cc; color: #6b4e00; }
.badge.over { background: #fbe1e1; color: #8a1f1f; }
:root[data-theme="dark"] .badge.pend { background: #4a3b10; color: #ffd978; }
:root[data-theme="dark"] .badge.over { background: #4d1d1d; color: #ffb3b3; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge.pend { background: #4a3b10; color: #ffd978; }
  :root:not([data-theme="light"]) .badge.over { background: #4d1d1d; color: #ffb3b3; }
}

.banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #fff2cc; color: #4d3800; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
:root[data-theme="dark"] .banner { background: #3b300f; color: #ffe199; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .banner { background: #3b300f; color: #ffe199; } }

/* Barras horizontales (gastos por categoría): una sola serie, un solo tono */
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; }
.bar-row .lbl { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .val { font-size: 13px; color: var(--text-2); }
.bar-track { grid-column: 1 / -1; height: 10px; border-radius: 4px; background: transparent; position: relative; }
.bar-fill { height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 3px; }
.bar-row:hover .bar-fill { filter: brightness(1.1); }

/* Presupuestos: progreso con estado (siempre con ícono + texto) */
.progress { height: 10px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin: 8px 0 4px; display: flex; }
.progress > i { display: block; height: 100%; }
.progress .p-ok { background: var(--good); }
.progress .p-warn { background: var(--warning); }
.progress .p-over { background: var(--critical); }
.progress .p-pend { background: repeating-linear-gradient(45deg, var(--muted) 0 3px, transparent 3px 6px); opacity: .6; }
.status { font-size: 12.5px; font-weight: 600; }
.status.ok { color: var(--good-ink); }
.status.warn { color: #8a6100; }
.status.over { color: var(--critical-ink); }
:root[data-theme="dark"] .status.warn { color: #ffcc55; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .status.warn { color: #ffcc55; } }

.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; }
.filters select, .filters input { flex: none; }
select, input, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 10px; width: 100%; min-width: 0;
}
.filters select, .filters input { width: auto; max-width: 180px; }
label { display: block; font-size: 13px; color: var(--text-2); margin: 10px 0 4px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.grid2 label { margin-top: 10px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14.5px; }
.check input { width: auto; }

button, .btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer;
  background: var(--surface-2); color: var(--text);
}
button.primary { background: var(--accent); color: var(--accent-ink); }
button.danger { background: transparent; color: var(--critical-ink); }
button.small { padding: 6px 10px; font-size: 13px; }
.icon-btn { background: transparent; font-size: 20px; padding: 4px 8px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.actions .spacer { flex: 1; }
.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { flex: 1; background: transparent; padding: 7px 6px; font-size: 13px; font-weight: 550; }
.seg button.on { background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.fab {
  position: fixed; right: 18px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 6;
  width: 56px; height: 56px; border-radius: 18px; font-size: 28px; line-height: 1;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex;
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { flex: 1; text-align: center; color: var(--muted); text-decoration: none; font-size: 10.5px; padding: 7px 0 8px; }
.tabbar a span { display: block; font-size: 19px; line-height: 1.3; }
.tabbar a.on { color: var(--accent); font-weight: 600; }

dialog {
  width: min(560px, 100vw); max-height: 92vh; border: 0; padding: 0; margin: auto auto 0;
  border-radius: 18px 18px 0 0; background: var(--surface); color: var(--text);
}
@media (min-width: 600px) { dialog { margin: auto; border-radius: 18px; } }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 92vh; }
dialog h3 { margin: 0 0 6px; }

#toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; }

.login { max-width: 360px; margin: 10vh auto 0; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data td, table.data th { padding: 6px 4px; border-top: 1px solid var(--border); text-align: left; }
table.data td.num, table.data th.num { text-align: right; }
details summary { cursor: pointer; color: var(--text-2); font-size: 13px; margin-top: 10px; }
