:root {
  --bg: #f4f3fa;
  --card: #ffffff;
  --ink: #1e1b2e;
  --muted: #6e6a80;
  --line: #e6e3f0;
  --brand: #6c5ce7;
  --brand-ink: #ffffff;
  --brand-soft: #ece9ff;
  --pos: #0a9a6c;
  --pos-soft: #e1f6ee;
  --neg: #d6453d;
  --neg-soft: #fde8e6;
  --warn: #b7791f;
  --warn-soft: #fff4dc;
  --shadow: 0 1px 2px rgba(30, 27, 46, .06), 0 4px 16px rgba(30, 27, 46, .06);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121019; --card: #1d1a28; --ink: #f1eff8; --muted: #a29db6; --line: #2e2a3d;
    --brand: #8b7cf6; --brand-soft: #2b2547; --pos: #34d399; --pos-soft: #12322a;
    --neg: #f87171; --neg-soft: #3a1c1f; --warn: #fbbf24; --warn-soft: #3a2f14;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121019; --card: #1d1a28; --ink: #f1eff8; --muted: #a29db6; --line: #2e2a3d;
  --brand: #8b7cf6; --brand-soft: #2b2547; --pos: #34d399; --pos-soft: #12322a;
  --neg: #f87171; --neg-soft: #3a1c1f; --warn: #fbbf24; --warn-soft: #3a2f14;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
[hidden] { display: none !important; }

.app { max-width: 560px; margin: 0 auto; min-height: 100vh; padding: 0 16px 120px; }
.splash { display: grid; place-items: center; height: 80vh; font-size: 72px; color: var(--brand); font-weight: 800; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5; margin: 0 -16px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px);
  display: flex; align-items: center; gap: 8px;
}
.top h1 { font-size: 20px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 12px; cursor: pointer;
  display: grid; place-items: center; font-size: 20px; flex: none;
}
.icon-btn:active { background: var(--line); }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; border: 1px solid var(--line); background: var(--card); padding: 7px 14px; border-radius: 999px;
  text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 600; position: relative;
}
.tab.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.tab .dot { position: absolute; top: 2px; right: 4px; width: 8px; height: 8px; background: var(--neg); border-radius: 50%; }

/* ---------- cards & lists ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.hero { text-align: center; padding: 20px 16px; }
.hero .label { color: var(--muted); font-size: 14px; }
.hero .big { font-size: 32px; font-weight: 800; letter-spacing: -.02em; margin: 4px 0; }
.hero .sub { color: var(--muted); font-size: 13px; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.item:last-child { border-bottom: 0; }
.item:active { background: var(--bg); }
.item .t { font-weight: 600; }
.item .s { color: var(--muted); font-size: 13px; }
.item .amt { text-align: right; font-weight: 700; white-space: nowrap; }
.item .amt .s { font-weight: 500; }
.emoji { width: 40px; height: 40px; border-radius: 12px; background: var(--brand-soft); display: grid; place-items: center; font-size: 20px; flex: none; }
.day { font-size: 13px; font-weight: 700; color: var(--muted); margin: 16px 4px 6px; text-transform: capitalize; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); vertical-align: middle; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.neg { background: var(--neg-soft); color: var(--neg); }
.badge.pos { background: var(--pos-soft); color: var(--pos); }
.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; color: #fff; display: inline-grid; place-items: center; font-size: 13px; font-weight: 700; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.empty .e { font-size: 44px; }
h2 { font-size: 15px; margin: 20px 4px 8px; color: var(--muted); font-weight: 700; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 700; cursor: pointer;
  background: var(--brand); color: var(--brand-ink); display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none;
}
.btn.block { width: 100%; }
.btn.ghost { background: var(--brand-soft); color: var(--brand); }
.btn.plain { background: transparent; color: var(--brand); padding: 8px 10px; }
.btn.danger { background: var(--neg-soft); color: var(--neg); }
.btn.sm { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.fab {
  position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 6;
  width: 60px; height: 60px; border-radius: 20px; border: 0; background: var(--brand); color: #fff; font-size: 30px;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--brand) 45%, transparent); cursor: pointer;
}

/* ---------- forms ---------- */
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin: 0 2px 6px; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px 14px; outline: none;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input.amount { font-size: 28px; font-weight: 800; padding: 10px 14px; }
.inline { display: flex; gap: 8px; }
.inline > * { flex: 1; min-width: 0; }
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 4px; border-radius: 10px; font-weight: 700; color: var(--muted); cursor: pointer; font-size: 14px; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 12px; cursor: pointer;
  font-size: 14px; display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.split-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.split-row:last-child { border-bottom: 0; }
.split-row input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--brand); }
.split-row .w { width: 110px; text-align: right; padding: 8px 10px; }
.split-row .calc { width: 96px; text-align: right; font-weight: 700; font-size: 14px; }
.hint { font-size: 13px; color: var(--muted); margin: -6px 2px 14px; }
.err { color: var(--neg); font-size: 14px; font-weight: 600; margin: 8px 2px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0 14px; }
.switch input { width: 46px; height: 26px; accent-color: var(--brand); }

/* ---------- balances / bars ---------- */
.bal-row { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 10px; padding: 8px 0; }
.bal-bar { position: relative; height: 30px; }
.bal-bar .mid { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--line); }
.bal-bar .b { position: absolute; top: 4px; height: 22px; border-radius: 6px; }
.bal-bar .v { position: absolute; top: 5px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; margin-bottom: 10px; }
.hbar .track { grid-column: 1 / -1; height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--brand); border-radius: 99px; }
.vbars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 10px; }
.vbars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.vbars .bar { width: 100%; background: var(--brand); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.vbars .bar.on { background: var(--pos); }
.vbars .lbl { font-size: 10px; color: var(--muted); }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.progress > div { height: 100%; background: var(--brand); }

/* ---------- sheet / toast ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(10, 8, 20, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 10px; }
.sheet h3 { margin: 4px 0 14px; font-size: 19px; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 30; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.offline { position: sticky; top: 0; z-index: 10; background: var(--warn-soft); color: var(--warn); text-align: center; font-size: 13px; font-weight: 700; padding: 6px; }
.search { margin-bottom: 8px; }
.updbar {
  position: sticky; top: 0; z-index: 15; display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--brand); color: var(--brand-ink); padding: calc(8px + env(safe-area-inset-top)) 12px 8px; font-size: 14px; font-weight: 600;
}
.updbar .btn { background: var(--brand-ink); color: var(--brand); }
.code { font: 700 22px/1 ui-monospace, monospace; letter-spacing: .12em; text-align: center; padding: 14px; background: var(--brand-soft); color: var(--brand); border-radius: 12px; }
.receipt-img { max-width: 100%; border-radius: 12px; margin-top: 8px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv > span:first-child { color: var(--muted); }

/* ---------- print (resumen PDF) ---------- */
.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; }
  .top, .tabs, .fab, .no-print, #toast, #offline { display: none !important; }
  .print-only { display: block; }
  .card, .list { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .app { max-width: none; padding: 0; }
}
