:root {
  --bg: #fbf7f4;
  --surface: #ffffff;
  --surface-2: #f4eee9;
  --text: #2a2321;
  --muted: #8a7f7a;
  --border: #ebe3dd;
  --accent: #e8505b;
  --accent-ink: #ffffff;
  --accent-soft: #fde8e9;
  --accent-2: #8b6fd6;
  --danger: #c93a3a;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(60 30 20 / 0.06), 0 4px 14px rgb(60 30 20 / 0.05);
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171413;
    --surface: #221e1c;
    --surface-2: #2c2725;
    --text: #f2ebe7;
    --muted: #a39893;
    --border: #3a3330;
    --accent: #f0646e;
    --accent-soft: #3d2326;
    --accent-2: #a58df0;
    --danger: #f07070;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row.end { justify-content: flex-end; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { padding: 6px 12px; font-size: 0.9rem; }
.btn.small svg { width: 18px; height: 18px; }
.btn.icon-only { padding: 10px; }
.btn:disabled { opacity: 0.6; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px;
  border: 0; background: transparent; border-radius: 10px;
  color: var(--text); text-decoration: none; flex: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.subtle { color: var(--muted); width: 34px; height: 34px; }
.icon-btn.subtle svg { width: 19px; height: 19px; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 4px; }

/* Pantallas de acceso */
.splash { min-height: 100dvh; display: grid; place-items: center; }
.splash img, .brand img { border-radius: 22%; box-shadow: var(--shadow); }
.splash img { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(0.9); opacity: 0.7; } }
.center-card { max-width: 400px; margin: 0 auto; padding: 48px 16px; display: flex; flex-direction: column; gap: 24px; }
.brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.brand h1 { font-size: 1.8rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }

/* Estructura */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  max-width: 640px; margin: 0 auto;
}
.topbar h1 { font-size: 1.4rem; }
.demo-banner {
  max-width: 608px; margin: 0 auto 8px; text-align: center;
  font-size: 0.8rem; color: var(--accent); background: var(--accent-soft);
  border-radius: 8px; padding: 6px 10px;
}
@media (max-width: 640px) { .demo-banner { margin: 0 16px 8px; } }
.view { max-width: 640px; margin: 0 auto; padding: 4px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px); }
.module { display: flex; flex-direction: column; gap: 12px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 8px;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 0 1 120px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.75rem; font-weight: 600;
}
.tabbar a.active { color: var(--accent); }

/* Listas */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 6px 10px 12px; box-shadow: var(--shadow);
}
.item .title { font-weight: 550; overflow-wrap: anywhere; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.section-title { margin-top: 16px; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; margin: 0; }

/* Compra */
.add-row { display: flex; gap: 8px; }
.add-row .qty { flex: 0 0 76px; }
.sticky { position: sticky; top: calc(env(safe-area-inset-top) + 60px); z-index: 4; background: var(--bg); padding: 4px 0 8px; }
.check {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--border); background: var(--surface);
  display: grid; place-items: center; padding: 0; color: transparent;
}
.check svg { width: 16px; height: 16px; stroke-width: 3; }
.item.checked .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.item.checked .title { text-decoration: line-through; color: var(--muted); }
.list.done .item { box-shadow: none; background: transparent; }
.qty-tag { margin-left: 6px; font-size: 0.8rem; color: var(--muted); background: var(--surface-2); padding: 1px 7px; border-radius: 99px; white-space: nowrap; }
.avatar {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; font-size: 0.72rem; font-weight: 700;
  color: #fff; background: var(--c);
}

/* Compra con catálogo */
.search-bar { display: flex; align-items: center; gap: 4px; }
.search-bar input { flex: 1; padding: 12px 14px; font-size: 1rem; border-radius: 12px; }
.search-bar input::-webkit-search-cancel-button { display: none; }
.search-bar .icon-btn { font-size: 1.5rem; }
.center { text-align: center; }
.thumb { flex: none; width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: #fff; }
.thumb.placeholder { display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.item.result { cursor: pointer; padding-right: 10px; }
.item.result:active { background: var(--surface-2); }
.item.result .title { font-weight: 500; font-size: 0.95rem; }
.item.result .price { flex: none; font-weight: 700; font-size: 0.95rem; }
.add-badge {
  flex: none; min-width: 32px; height: 32px; border-radius: 99px; padding: 0 6px;
  display: grid; place-items: center; font-weight: 700; font-size: 0.85rem;
  background: var(--accent-soft); color: var(--accent);
}
.add-badge svg { width: 18px; height: 18px; }
.item.result.added .add-badge { background: var(--accent); color: var(--accent-ink); }
.item.result.free .title { color: var(--accent); }
.group-title { margin: 14px 2px 6px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.item.product { padding: 8px 8px 8px 10px; gap: 8px; }
.item.product .title { font-size: 0.95rem; line-height: 1.25; }
.item.checked .thumb { opacity: 0.5; }
.stepper { flex: none; display: flex; align-items: center; background: var(--surface-2); border-radius: 99px; }
.stepper button { width: 30px; height: 30px; border: 0; background: none; font-size: 1.1rem; font-weight: 700; color: var(--accent); padding: 0; }
.stepper span { min-width: 16px; text-align: center; font-weight: 700; font-size: 0.9rem; }
.total {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  margin-top: 12px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--accent-soft); font-size: 0.95rem;
}
.total strong { color: var(--accent); font-size: 1.05rem; }

/* Inicio */
.hello h2 { font-size: 1.5rem; }
.hello p { margin: 2px 0 4px; }
.dash-card {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); color: var(--text); text-decoration: none;
}
.dash-card:active { background: var(--surface-2); }
.dash-card p { margin: 0; }
.dash-head { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.dash-head svg { width: 20px; height: 20px; color: var(--accent); }
.dash-head span { flex: 1; }
.dash-head svg:last-child { color: var(--muted); width: 18px; height: 18px; }
.dash-sub { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-top: 4px; }
.mini-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.mini-event { display: flex; align-items: center; gap: 10px; padding-left: 10px; border-left: 3px solid var(--c); font-size: 0.95rem; }
.mini-when { flex: none; min-width: 70px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.kpis { display: flex; gap: 10px; }
.kpi { flex: 1; display: flex; flex-direction: column; background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }
.kpi strong { font-size: 1.25rem; line-height: 1.2; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 0.82rem; background: var(--surface-2); border-radius: 99px; padding: 3px 10px; }
.dash-balance { font-size: 1.4rem; font-weight: 800; }
.dash-balance.pos { color: #2f9e6e; }
.dash-balance.neg { color: var(--danger); }
.hbars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.hbar { display: grid; grid-template-columns: minmax(0, 7.5em) 1fr auto; align-items: center; gap: 10px; font-size: 0.88rem; }
.hbar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 10px; }
.hbar-fill { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.hbar-value { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.cols { display: flex; align-items: stretch; gap: 8px; height: 120px; padding-top: 4px; }
.col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; min-width: 0; }
.col-bar { width: 100%; max-width: 28px; background: color-mix(in srgb, var(--accent) 40%, var(--surface-2)); border-radius: 4px 4px 0 0; }
.col.current .col-bar { background: var(--accent); }
.col-value { font-size: 0.72rem; font-weight: 600; color: var(--text); white-space: nowrap; min-height: 1em; }
.col-label { font-size: 0.75rem; color: var(--muted); }
.col-plot { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; min-height: 0; }

/* Gastos */
.balance-card {
  border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 4px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.balance-card .big { font-size: 1.6rem; font-weight: 800; line-height: 1.2; }
.balance-card.pos .big { color: #2f9e6e; }
.balance-card.neg .big { color: var(--danger); }
.balance-card .stats { display: flex; gap: 12px; margin-top: 10px; }
.balance-card .stats > div {
  flex: 1; display: flex; flex-direction: column; gap: 2px;
  background: var(--surface-2); border-radius: 10px; padding: 8px 12px;
}
.settle-row { display: flex; align-items: center; gap: 8px; }
.month-title { display: flex; justify-content: space-between; }
.item.expense { cursor: pointer; padding-right: 12px; }
.item.expense:active { background: var(--surface-2); }
.cat-icon { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 1.2rem; background: var(--surface-2); }
.item.expense .amount { flex: none; display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.item.transfer .title { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 99px;
  padding: 7px 12px; font-size: 0.9rem; font-weight: 500;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.on .dot { outline: 2px solid var(--accent-ink); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 0.85rem; color: var(--muted); }
.amount-input { position: relative; display: flex; align-items: center; }
.amount-input input { padding-right: 30px; font-size: 1.3rem; font-weight: 700; }
.amount-input span { position: absolute; right: 12px; color: var(--muted); font-weight: 600; }
.amount-input.small { width: 120px; flex: none; }
.amount-input.small input { font-size: 1rem; padding: 8px 28px 8px 10px; }
.split-list { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.split-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 4px 10px;
}
.split-row.off { opacity: 0.55; }
.split-who { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 0.95rem; }
.split-who input { width: 18px; height: 18px; accent-color: var(--accent); }
.split-amt { font-weight: 700; }
.danger-btn { color: var(--danger); }

/* Calendario */
.cal-head { display: flex; align-items: center; gap: 4px; }
.cal-head h2 { flex: 1; text-align: center; }
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px; box-shadow: var(--shadow);
}
.cal-wd { text-align: center; font-size: 0.75rem; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal-day {
  aspect-ratio: 1 / 1; min-height: 40px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; border-radius: 10px; background: transparent; padding: 0; font-weight: 500;
}
.cal-day:hover { background: var(--surface-2); }
.cal-day.today span:first-child { color: var(--accent); font-weight: 800; }
.cal-day.selected { background: var(--accent); }
.cal-day.selected span:first-child { color: var(--accent-ink); }
.cal-day.selected .dots i { outline: 1.5px solid var(--accent-ink); }
.dots { display: flex; gap: 3px; height: 6px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; }
.event { border-left: 4px solid var(--c); }
.ev-when { flex: none; width: 74px; display: flex; flex-direction: column; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.ev-date { color: var(--text); }
.badge { flex: none; font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
@media (max-width: 400px) { .badge { display: none; } .ev-when { width: 62px; } }

/* Ajustes */
.code-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.code { font: 700 1.6rem/1 ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: 0.15em; color: var(--accent); }
.members { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.members li { display: flex; align-items: center; gap: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; }

.error { color: var(--danger); }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 0.9rem; transition: 0.2s; z-index: 20; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
[hidden] { display: none !important; }
