:root {
  --bg: #F4F5F8; --card: #FFFFFF; --ink: #14171F; --ink-2: #4A5263; --ink-3: #8A92A3; --line: #E3E6EC; --fill: #EEF0F4;
  --accent: #2F6FEB; --danger: #D93025; --ok: #1E8E5A; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --r: 16px; --tab-h: 58px;
  --st: env(safe-area-inset-top); --sb: env(safe-area-inset-bottom);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0E1116; --card: #181C23; --ink: #F1F3F7; --ink-2: #B7BECB; --ink-3: #7D8595; --line: #2A303B; --fill: #222833; --shadow: none; --accent: #5B8CFF; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input, select, textarea { -webkit-appearance: none; appearance: none; }
.boot { height: 100vh; display: grid; place-items: center; } .boot img { border-radius: 18px; opacity: .9; }

/* Estructura */
.screen { min-height: 100vh; padding: calc(var(--st) + 8px) 16px calc(var(--tab-h) + var(--sb) + 96px); max-width: 640px; margin: 0 auto; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0 12px; }
.top h1 { font-size: 30px; line-height: 1.1; margin: 0; letter-spacing: -.02em; }
.top .sub { color: var(--ink-3); font-size: 14px; margin-top: 2px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--card); box-shadow: var(--shadow); font-size: 18px; color: var(--ink-2); }
.icon-btn:active { transform: scale(.94); }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 14px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); margin: 22px 4px 8px; font-weight: 600; }
.muted { color: var(--ink-3); } .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; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.empty { text-align: center; color: var(--ink-3); padding: 18px 8px; }

/* Barra de pestañas */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center; background: color-mix(in srgb, var(--card) 86%, transparent);
  backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px); border-top: .5px solid var(--line); padding-bottom: var(--sb); }
.tabbar .in { display: flex; width: 100%; max-width: 640px; }
.tabbar button { flex: 1; height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--ink-3); font-weight: 500; }
.tabbar button svg { width: 25px; height: 25px; }
.tabbar button.on { color: var(--accent); }
.fab { position: fixed; right: max(18px, calc(50% - 302px)); bottom: calc(var(--tab-h) + var(--sb) + 16px); z-index: 19; width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 30px; font-weight: 300; box-shadow: 0 6px 20px rgba(47,111,235,.35); display: grid; place-items: center; }
.fab:active { transform: scale(.94); }

/* Calendario */
.cal { padding: 10px 8px 12px; }
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-head div { text-align: center; font-size: 12px; color: var(--ink-3); font-weight: 600; padding: 2px 0 8px; }
.cal-grid button { aspect-ratio: 1 / 1.08; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 6px; gap: 4px; border-radius: 12px; font-size: 16px; position: relative; }
.cal-grid button.out { color: var(--ink-3); opacity: .45; }
.cal-grid button .n { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-variant-numeric: tabular-nums; }
.cal-grid button.today .n { color: var(--accent); font-weight: 700; }
.cal-grid button.sel .n { background: var(--ink); color: var(--card); font-weight: 600; }
.cal-grid button.today.sel .n { background: var(--accent); color: #fff; }
.cal-grid .marks { display: flex; gap: 3px; height: 6px; }
.cal-grid .marks i { width: 6px; height: 6px; border-radius: 50%; display: block; }
.day-head { display: flex; align-items: baseline; justify-content: space-between; margin: 18px 4px 8px; }
.day-head h2 { font-size: 19px; margin: 0; }
.ev { display: flex; gap: 12px; align-items: stretch; padding: 12px 14px; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); margin-bottom: 8px; width: 100%; text-align: left; }
.ev .bar { width: 4px; border-radius: 4px; flex: none; }
.ev .t { font-weight: 600; } .ev .when { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.ev .who { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 6px 0; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* Gastos */
.total { font-size: 38px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.bars .b { margin: 10px 0; }
.bars .b .l { display: flex; justify-content: space-between; font-size: 15px; margin-bottom: 5px; gap: 8px; }
.bars .b .track { height: 8px; background: var(--fill); border-radius: 8px; overflow: hidden; }
.bars .b .track i { display: block; height: 100%; border-radius: 8px; background: var(--accent); }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.split { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.chip-s { display: inline-flex; align-items: center; gap: 6px; background: var(--fill); padding: 5px 10px; border-radius: 99px; font-size: 13px; }
.months { display: flex; align-items: flex-end; gap: 6px; height: 64px; margin-top: 12px; }
.months div { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--ink-3); height: 100%; justify-content: flex-end; }
.months div i { width: 100%; max-width: 30px; background: var(--fill); border-radius: 5px 5px 2px 2px; min-height: 3px; display: block; }
.months div.on i { background: var(--accent); } .months div.on { color: var(--ink); font-weight: 600; }
.list { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.list > .it { display: flex; align-items: center; gap: 12px; padding: 12px 16px; width: 100%; text-align: left; border-bottom: .5px solid var(--line); background: var(--card); }
.list > .it:last-child { border-bottom: 0; }
.list > .it:active { background: var(--fill); }
.list .ic { width: 38px; height: 38px; border-radius: 11px; background: var(--fill); display: grid; place-items: center; font-size: 19px; flex: none; }
.list .date-sep { padding: 10px 16px 6px; font-size: 12px; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: var(--bg); }

/* Formularios y hojas */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; opacity: 0; transition: opacity .2s; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--bg); border-radius: 18px 18px 0 0; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 8px 16px calc(var(--sb) + 18px); transform: translateY(100%); transition: transform .28s cubic-bezier(.2,.8,.2,1); max-width: 640px; margin: 0 auto; }
.sheet.open { transform: none; } .sheet-bg.open { opacity: 1; }
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h3 { margin: 0; font-size: 18px; }
.link { color: var(--accent); font-weight: 500; padding: 6px 2px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--ink-3); margin: 0 4px 6px; font-weight: 500; }
.input { min-width: 0; max-width: 100%; width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 17px; outline: none; min-height: 48px; }
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 84px; resize: vertical; }
.input.big { font-size: 34px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.two > * { min-width: 0; }
input[type=date].input, input[type=time].input { display: block; text-align: left; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 9px 13px; border-radius: 99px; background: var(--card); border: 1.5px solid var(--line); font-size: 15px; }
.chip.on { border-color: var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 14%, var(--card)); font-weight: 600; }
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.cats button { background: var(--card); border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12.5px; line-height: 1.15; text-align: center; }
.cats button b { font-size: 22px; font-weight: 400; }
.cats button.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--card)); font-weight: 600; }
.switch { display: flex; align-items: center; justify-content: space-between; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; min-height: 48px; margin-bottom: 12px; }
.switch input { width: 51px; height: 31px; border-radius: 99px; background: var(--fill); position: relative; transition: background .2s; flex: none; border: 1px solid var(--line); }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 25px; height: 25px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked { background: var(--ok); border-color: var(--ok); } .switch input:checked::after { transform: translateX(20px); }
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 50px; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 600; font-size: 17px; margin-top: 6px; }
.btn:disabled { opacity: .55; } .btn:active { filter: brightness(.94); }
.btn.ghost { background: var(--card); color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--line)); }
.btn.sm { min-height: 40px; font-size: 15px; width: auto; padding: 0 14px; margin: 0; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 32px; height: 32px; border-radius: 50%; background: var(--c); border: 3px solid var(--card); box-shadow: 0 0 0 1px var(--line); }
.swatches button.on { box-shadow: 0 0 0 2.5px var(--c); }
.err { color: var(--danger); font-size: 14px; margin: 8px 4px 0; min-height: 1em; }

/* Ajustes */
.set { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.set > * { border-bottom: .5px solid var(--line); }
.set > *:last-child { border-bottom: 0; }
.set .it { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 52px; width: 100%; text-align: left; }
.set .it .val { color: var(--ink-3); font-size: 15px; }
.set .it.danger { color: var(--danger); }
.set .switch { border: 0; border-radius: 0; margin: 0; padding: 10px 16px; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: var(--fill); color: var(--ink-2); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; flex: none; }
.note { background: color-mix(in srgb, var(--accent) 10%, var(--card)); border-radius: 14px; padding: 12px 14px; font-size: 14px; color: var(--ink-2); margin-bottom: 14px; }
.note b { color: var(--ink); }
.linkbox { background: var(--fill); border-radius: 12px; padding: 12px; font-size: 13px; word-break: break-all; font-family: ui-monospace, Menlo, monospace; margin: 8px 0; user-select: all; -webkit-user-select: all; }

/* Bloqueo y alta */
.lock { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(var(--st) + 24px) 28px calc(var(--sb) + 24px); text-align: center; max-width: 440px; margin: 0 auto; }
.lock img { width: 92px; height: 92px; border-radius: 22px; box-shadow: var(--shadow); }
.lock h1 { font-size: 32px; margin: 18px 0 4px; letter-spacing: -.02em; }
.lock p { color: var(--ink-2); margin: 4px 0 26px; }
.lock .btn { max-width: 320px; }
.faceid { width: 22px; height: 22px; }
.ios-tip { margin-top: 28px; font-size: 14px; color: var(--ink-2); background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); text-align: left; }

#toast { position: fixed; left: 50%; top: calc(var(--st) + 10px); transform: translate(-50%, -140%); z-index: 60; background: var(--ink); color: var(--card); padding: 11px 18px; border-radius: 99px; font-size: 15px;
  font-weight: 500; transition: transform .3s cubic-bezier(.2,.8,.2,1); max-width: 92vw; box-shadow: 0 6px 24px rgba(0,0,0,.2); pointer-events: none; }
#toast.show { transform: translate(-50%, 0); }
#toast.bad { background: var(--danger); color: #fff; }
