:root {
  --paper: #EEF1F6;
  --surface: #FFFFFF;
  --ink: #1C2A4A;
  --ink-2: #4D5A75;
  --ink-3: #7C879D;
  --line: #D6DCE7;
  --note: #FFD54A;
  --note-ink: #3A2E05;
  --plus: #13795B;
  --minus: #C13B2E;
  --focus: #2F6FEB;
  --accent: #1C2A4A;
  --accent-ink: #FFFFFF;
  --radius-s: 8px;
  --radius-l: 18px;
  --display: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111726;
    --surface: #1A2235;
    --ink: #E7ECF6;
    --ink-2: #B3BDD1;
    --ink-3: #8691A8;
    --line: #2C3650;
    --note: #F5CB3A;
    --note-ink: #2B2203;
    --plus: #4CC89A;
    --minus: #FF7B6E;
    --focus: #7AA5FF;
    --accent: #E7ECF6;
    --accent-ink: #111726;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 var(--body);
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; font-family: var(--display); }
.plus { color: var(--plus); }
.minus { color: var(--minus); }
.muted { color: var(--ink-3); }
.small { font-size: 14px; }
.boot { padding: 40px 16px; text-align: center; color: var(--ink-3); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- estructura ---------- */
.shell { max-width: 560px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(12px + env(safe-area-inset-top)) 0 8px;
}
.hh-switch {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px;
  background: none; border: 0; padding: 6px 0; text-align: left;
  font: 700 22px/1.2 var(--display); letter-spacing: -0.01em;
}
.hh-switch span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hh-switch svg { flex: none; opacity: .6; }
h2 { font: 700 18px/1.3 var(--display); margin: 28px 0 8px; }
h3 { font: 600 16px/1.3 var(--display); margin: 20px 0 6px; }

/* ---------- la nota de la nevera ---------- */
.note {
  position: relative;
  margin: 14px 4px 6px;
  padding: 22px 20px 20px;
  background: var(--note);
  color: var(--note-ink);
  border-radius: 3px 3px 14px 3px;
  transform: rotate(-1.2deg);
  box-shadow: 0 1px 0 rgba(0,0,0,.08), 0 14px 22px -14px rgba(60,45,0,.55);
}
.note::before { /* celo */
  content: ""; position: absolute; top: -10px; left: 50%; width: 84px; height: 22px;
  transform: translateX(-50%) rotate(2deg);
  background: rgba(255,255,255,.55); border-radius: 2px;
}
.note-label { font-size: 15px; font-weight: 600; margin: 0; }
.note-amount { font: 800 44px/1.05 var(--display); letter-spacing: -0.02em; margin: 2px 0 6px; font-variant-numeric: tabular-nums; }
.note-lines { margin: 8px 0 0; padding: 0; list-style: none; font-size: 15px; }
.note-lines li { padding: 3px 0; }
@media (prefers-reduced-motion: no-preference) {
  .note.pop { animation: pop .45s cubic-bezier(.2,.9,.3,1.3); }
  @keyframes pop { from { transform: rotate(-4deg) scale(.96); opacity: .4; } }
}

/* ---------- listas ---------- */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius-l); }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 14px; background: none; border: 0; text-align: left;
  border-top: 1px solid var(--line);
}
.list > li:first-child > .row, .list > .row:first-child { border-top: 0; }
button.row:hover { background: color-mix(in srgb, var(--paper) 55%, transparent); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-amt { text-align: right; font-weight: 700; white-space: nowrap; }
.row-amt small { display: block; font-weight: 500; font-size: 12.5px; }
.cat { width: 38px; height: 38px; flex: none; display: grid; place-items: center; font-size: 19px;
  background: var(--paper); border-radius: 12px; }
.day { font-size: 13.5px; color: var(--ink-3); font-weight: 600; margin: 18px 4px 6px; }
.empty { padding: 26px 18px; text-align: center; color: var(--ink-2); background: var(--surface); border-radius: var(--radius-l); }
.empty p { margin: 0 0 12px; }

.avatar {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font: 700 13px/1 var(--display); color: #fff;
}
.debt { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); }
.list > .debt:first-child { border-top: 0; }
.debt-text { flex: 1; min-width: 0; }

/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1.5px solid var(--ink);
  background: var(--accent); color: var(--accent-ink); font-weight: 650;
}
.btn.ghost { background: transparent; color: var(--ink); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn.danger { background: transparent; border-color: var(--minus); color: var(--minus); }
.btn[disabled] { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 4px 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.iconbtn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: none; display: grid; place-items: center; }

/* ---------- navegación inferior ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar-in { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr 76px 1fr 1fr; align-items: center; }
.tab {
  background: none; border: 0; padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; color: var(--ink-3);
}
.tab[aria-current="page"] { color: var(--ink); font-weight: 650; }
.tab svg { width: 24px; height: 24px; }
.add-btn {
  justify-self: center; width: 58px; height: 58px; margin-top: -22px; border-radius: 50%;
  border: 0; background: var(--note); color: var(--note-ink); display: grid; place-items: center;
  box-shadow: 0 8px 18px -8px rgba(60,45,0,.6);
}
.add-btn svg { width: 28px; height: 28px; }

/* ---------- formularios ---------- */
.field { display: block; margin: 14px 0; }
.field > span { display: block; font-size: 14px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: var(--radius-s);
  border: 1.5px solid var(--line); background: var(--surface);
}
.input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.amount-input {
  width: 100%; border: 0; border-bottom: 2px solid var(--line); background: none; padding: 4px 0;
  font: 800 42px/1.1 var(--display); text-align: left; font-variant-numeric: tabular-nums; border-radius: 0;
}
.amount-input:focus { outline: none; border-bottom-color: var(--focus); }
.amount-wrap { display: flex; align-items: baseline; gap: 6px; }
.amount-wrap .cur { font: 700 30px var(--display); color: var(--ink-3); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 12px;
  border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); font-size: 14.5px;
}
.chip[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.chip .avatar { width: 22px; height: 22px; font-size: 11px; margin-left: -6px; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; border-radius: 9px; padding: 8px 2px; font-size: 13.5px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); font-weight: 650; }

.split-rows { margin-top: 10px; }
.split-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.split-row:first-child { border-top: 0; }
.split-row .name { flex: 1; }
.split-row input.input { width: 110px; min-height: 40px; text-align: right; }
.split-row .share { min-width: 86px; text-align: right; color: var(--ink-2); }
.check { width: 22px; height: 22px; accent-color: var(--ink); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; }
.form-error { color: var(--minus); font-weight: 600; margin: 10px 0 0; }
.hint { font-size: 13.5px; color: var(--ink-3); margin: 6px 0 0; }

/* ---------- hoja inferior (dialog) ---------- */
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 22px 22px 0 0; background: var(--paper); color: var(--ink);
  overflow: hidden;
}
.sheet::backdrop { background: rgba(10, 16, 30, .45); }
@media (min-width: 640px) { .sheet { margin: auto; border-radius: 22px; } }
@media (prefers-reduced-motion: no-preference) {
  .sheet[open] { animation: up .25s ease-out; }
  @keyframes up { from { transform: translateY(40px); opacity: 0; } }
}
.sheet-in { max-height: 92dvh; overflow-y: auto; padding: 0 18px calc(18px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--paper); padding: 18px 0 6px; z-index: 1; }
.sheet-head h2 { margin: 0; }
.sheet-actions { display: flex; gap: 10px; margin-top: 22px; }
.sheet-actions .btn { flex: 1; }

/* ---------- pantalla de acceso ---------- */
.auth { max-width: 420px; margin: 0 auto; padding: calc(40px + env(safe-area-inset-top)) 20px 40px; }
.auth h1 { font: 800 34px/1.1 var(--display); letter-spacing: -0.02em; margin: 26px 0 6px; }
.auth .lead { color: var(--ink-2); margin: 0 0 18px; }
.auth .note { margin: 0 6px 6px; }

/* ---------- resumen ---------- */
.monthnav { display: flex; align-items: center; justify-content: space-between; margin: 10px 0 4px; }
.monthnav strong { font: 700 17px var(--display); }
.bigtotal { font: 800 38px/1.1 var(--display); margin: 8px 0 2px; font-variant-numeric: tabular-nums; }
.bars { list-style: none; margin: 0; padding: 14px; background: var(--surface); border-radius: var(--radius-l); }
.bars li { margin: 0 0 12px; }
.bars li:last-child { margin-bottom: 0; }
.bar-label { display: flex; justify-content: space-between; gap: 8px; font-size: 14.5px; margin-bottom: 4px; }
.bar { height: 10px; border-radius: 5px; background: var(--paper); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ink); border-radius: 5px; }
.months { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; align-items: end; height: 120px; padding: 14px; background: var(--surface); border-radius: var(--radius-l); }
.months div { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; font-size: 12px; color: var(--ink-3); }
.months i { width: 100%; max-width: 30px; background: var(--line); border-radius: 5px 5px 2px 2px; min-height: 3px; }
.months .cur i { background: var(--note); }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius-l); overflow: hidden; font-size: 14.5px; }
.table th, .table td { padding: 10px 12px; text-align: right; border-top: 1px solid var(--line); }
.table th:first-child, .table td:first-child { text-align: left; }
.table thead th { border-top: 0; color: var(--ink-3); font-weight: 600; font-size: 13px; }

/* ---------- aviso flotante ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; z-index: 50;
  max-width: calc(100% - 32px); font-weight: 600; box-shadow: 0 10px 24px -10px rgba(0,0,0,.5);
}
.invite-box { display: flex; gap: 8px; align-items: center; background: var(--surface); border-radius: var(--radius-l); padding: 10px 10px 10px 14px; }
.invite-box code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.stack > * + * { margin-top: 10px; }

/* ---------- ajustes tras revisión ---------- */
.row.solo { border-radius: var(--radius-l); border-top: 0; background: var(--surface); }
.chips.scroller {
  flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 4px;
  margin: 0 -18px; padding-left: 18px; padding-right: 18px; scrollbar-width: none;
}
.chips.scroller::-webkit-scrollbar { display: none; }
.chips.scroller .chip { flex: none; scroll-snap-align: start; }
.sheet-actions.sticky {
  position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom)); margin: 22px -18px 0;
  padding: 12px 18px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--paper) 18px);
}
.scan-box { margin: 6px 0 4px; }
.scan-box .btn { border-style: dashed; min-height: 52px; }
.steps { padding-left: 22px; } .steps li { margin: 6px 0; }
/* página de privacidad */
.doc { max-width: 680px; margin: 0 auto; padding: calc(28px + env(safe-area-inset-top)) 20px 60px; }
.doc h1 { font: 800 30px/1.15 var(--display); letter-spacing: -0.01em; margin: 18px 0 6px; }
.doc h2 { margin-top: 30px; }
.doc p, .doc li { color: var(--ink-2); max-width: 68ch; }
.doc a { color: var(--ink); }
.auth h1.brand { font-size: 44px; font-weight: 900; letter-spacing: -0.035em; margin-top: 30px; }
