:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e5e7eb;
  --text: #191919;
  --text-2: #5f6368;
  --text-3: #8a8f98;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f4f2;
  --income: #0a7d3b;
  --expense: #c62828;
  --warn: #b45309;
  --danger: #c62828;
  --series-1: #00b894;  /* ingresos */
  --series-2: #f47230;  /* gastos */
  --bar: #257de0;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111213;
    --surface: #1b1c1e;
    --surface-2: #232427;
    --border: #2e3034;
    --text: #efefef;
    --text-2: #a9adb3;
    --text-3: #7d828a;
    --accent: #2bb3a3;
    --accent-ink: #062723;
    --accent-soft: #15302d;
    --income: #4ade80;
    --expense: #f87171;
    --warn: #f59e0b;
    --danger: #f87171;
    --series-1: #00a888;
    --series-2: #e76624;
    --bar: #338ced;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111213; --surface: #1b1c1e; --surface-2: #232427; --border: #2e3034;
  --text: #efefef; --text-2: #a9adb3; --text-3: #7d828a;
  --accent: #2bb3a3; --accent-ink: #062723; --accent-soft: #15302d;
  --income: #4ade80; --expense: #f87171; --warn: #f59e0b; --danger: #f87171;
  --series-1: #00a888; --series-2: #e76624; --bar: #338ced; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; }
.inc { color: var(--income); } .exp { color: var(--expense); }
.muted { color: var(--text-2); } .small { font-size: 13px; } .tiny { font-size: 12px; color: var(--text-3); }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
}
.brand { font-weight: 700; font-size: 20px; padding: 4px 12px 18px; display: flex; gap: 8px; align-items: center; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--text-2); font-weight: 500;
}
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav a:hover:not(.active) { background: var(--surface-2); }
.sidebar .me { margin-top: auto; padding: 12px; font-size: 13px; color: var(--text-2); }
main { flex: 1; min-width: 0; padding: 24px 28px 100px; max-width: 1100px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; margin: 0; letter-spacing: -.01em; }
.tabbar { display: none; }
.fab {
  position: fixed; right: 24px; bottom: 24px; width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink); font-size: 30px; line-height: 1; box-shadow: 0 6px 20px rgba(15,118,110,.35); cursor: pointer; z-index: 20;
}

@media (max-width: 820px) {
  .sidebar { display: none; }
  main { padding: 16px 16px calc(96px + var(--safe-b)); }
  .page-head h1 { font-size: 22px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + var(--safe-b));
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--text-3); padding: 4px 0; }
  .tabbar a .ico { font-size: 20px; line-height: 1.1; }
  .tabbar a.active { color: var(--accent); }
  .tabbar .tab-add { display: grid; place-items: center; }
  .tabbar .tab-add button {
    width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 28px; margin-top: -18px;
    box-shadow: 0 6px 18px rgba(15,118,110,.35);
  }
  .fab { display: none; }
}

/* ---------- componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 14px; }
.card h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.card h2 .tiny { font-weight: 400; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 820px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 560px) { .grid-3 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .grid-3 > :first-child { grid-column: 1 / -1; } }
.section { margin-top: 18px; }

.hero { padding: 20px; }
.hero .label { color: var(--text-2); font-size: 13px; }
.hero .big { font-size: 34px; font-weight: 700; letter-spacing: -.02em; }
.stat .label { color: var(--text-2); font-size: 13px; }
.stat .val { font-size: 22px; font-weight: 650; }

.btn {
  border: 1px solid var(--border); background: var(--surface); padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 550;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--text-2); font-weight: 550; font-size: 14px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg.full { display: flex; } .seg.full button { flex: 1; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.input, select.input, textarea.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); outline: none; min-height: 42px;
}
.input:focus { border-color: var(--accent); background: var(--surface); }
.amount-input { font-size: 30px; font-weight: 700; text-align: center; padding: 10px; }
.check { display: flex; align-items: flex-start; gap: 10px; margin: 10px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); flex: none; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters .input { width: auto; min-width: 0; flex: 1 1 150px; }

/* listas */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--surface-2); border-radius: 10px; }
.ico-circle { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; flex: none; background: var(--surface-2); }
.item .title { font-weight: 550; }
.item .sub { font-size: 12.5px; color: var(--text-3); }
.item .amt { font-weight: 600; text-align: right; white-space: nowrap; }
.day-head { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-3); padding: 14px 4px 4px; text-transform: capitalize; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); vertical-align: 1px; }
.badge.shared { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.warn { color: var(--warn); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.empty { text-align: center; color: var(--text-3); padding: 28px 10px; }

/* cuentas */
.wallets { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.wallet { border-radius: var(--radius); padding: 14px; background: var(--surface); border: 1px solid var(--border); cursor: pointer; position: relative; overflow: hidden; }
.wallet::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--wc, var(--accent)); }
.wallet .name { font-weight: 600; }
.wallet .bal { font-size: 20px; font-weight: 700; margin-top: 6px; }

/* barras de progreso / categorías */
.bar-track { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; border-radius: 99px; background: var(--accent); }
.bar-fill.over { background: var(--danger); } .bar-fill.near { background: var(--warn); }
.catbars .cb { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; padding: 6px 4px; border-radius: 8px; cursor: default; }
.catbars .cb:hover { background: var(--surface-2); }
.catbars .cb .track { grid-column: 2 / 4; height: 8px; }
.catbars .cb .fill { height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.chart-box { position: relative; height: 260px; }

/* tablas */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { padding: 8px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.t th { color: var(--text-2); font-weight: 550; font-size: 12.5px; }
table.t td.r, table.t th.r { text-align: right; }
table.t tr.skip td { opacity: .45; }
table.t select.input, table.t input.input { min-height: 34px; padding: 5px 8px; font-size: 13.5px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s; }
.modal {
  background: var(--surface); border-radius: 18px; width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto;
  padding: 18px 18px 20px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal .mh { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal .mh h3 { margin: 0; font-size: 18px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
@media (max-width: 560px) {
  .modal-bg { align-items: flex-end; padding: 0; }
  .modal { border-radius: 18px 18px 0 0; max-height: 92vh; padding-bottom: calc(20px + var(--safe-b)); }
}
@keyframes fade { from { opacity: 0; } }

.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; max-height: 210px; overflow: auto; padding: 2px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 12px; padding: 8px 4px; cursor: pointer; text-align: center; font-size: 12px; line-height: 1.2;
}
.chip .e { font-size: 20px; display: block; margin-bottom: 2px; }
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; transition: .2s; z-index: 80; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: #b91c1c; }

/* login */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 24px; }
.auth h1 { margin: 0 0 4px; font-size: 26px; }

.drop {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px 16px; text-align: center; cursor: pointer; background: var(--surface-2); display: block;
}
.drop:hover, .drop.over { border-color: var(--accent); }
.drop input { display: none; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.thumbs img { height: 90px; border-radius: 8px; border: 1px solid var(--border); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
