:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --text: #15201c;
  --muted: #64716c;
  --border: #dde4e1;
  --brand: #0f9d7a;
  --brand-ink: #ffffff;
  --brand-soft: #dff4ee;
  --pos: #0f8a5f;
  --neg: #d14343;
  --gold: #c98a00;
  --gold-soft: #fff3d6;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412;
    --surface: #17201d;
    --surface-2: #1f2a26;
    --text: #e8efec;
    --muted: #93a29c;
    --border: #2a3632;
    --brand: #23c49b;
    --brand-ink: #062a20;
    --brand-soft: #143a30;
    --pos: #3ccf95;
    --neg: #ff7a7a;
    --gold: #f2b632;
    --gold-soft: #3a2f12;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
#app { max-width: 520px; margin: 0 auto; padding: 0 16px 110px; min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* Header */
.topbar { display: flex; align-items: center; gap: 10px; padding: 18px 0 14px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.topbar h1 { font-size: 22px; margin: 0; flex: 1; letter-spacing: -.02em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo { font-weight: 800; color: var(--brand); }
.icon-btn { border: 0; background: var(--surface); width: 38px; height: 38px; border-radius: 50%; box-shadow: var(--shadow); font-size: 18px; flex: none; }
.badge-premium { border: 0; background: var(--gold-soft); color: var(--gold); font-weight: 700; font-size: 13px; padding: 7px 12px; border-radius: 999px; flex: none; }
.btn-premium { border: 0; background: linear-gradient(135deg, #f2b632, #e08a00); color: #2b1c00; font-weight: 700; font-size: 13px; padding: 8px 13px; border-radius: 999px; flex: none; }

/* Cards */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 10px; }
.group-card { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0; }
.group-emoji { width: 46px; height: 46px; border-radius: 12px; background: var(--brand-soft); display: grid; place-items: center; font-size: 24px; flex: none; }
.grow { flex: 1; min-width: 0; }
.title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { color: var(--muted); font-size: 13px; }
.right { text-align: right; flex: none; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.summary { display: flex; gap: 10px; margin-bottom: 14px; }
.summary .card { flex: 1; margin: 0; }
.summary .big { font-size: 20px; font-weight: 750; letter-spacing: -.02em; }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 4px 8px; font-weight: 650; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .big-emoji { font-size: 52px; }
.empty h2 { color: var(--text); margin: 10px 0 6px; }

.upsell { display: flex; gap: 12px; align-items: center; background: var(--gold-soft); border-radius: var(--radius); padding: 12px 14px; margin: 14px 0; border: 0; width: 100%; text-align: left; }
.upsell b { color: var(--gold); }

/* Buttons */
.btn { border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 650; background: var(--surface-2); }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-danger { background: transparent; color: var(--neg); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.fab { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); border: 0; background: var(--brand); color: var(--brand-ink); font-weight: 700; font-size: 16px; padding: 15px 26px; border-radius: 999px; box-shadow: 0 6px 24px rgba(15,157,122,.4); z-index: 10; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* Tabs */
.tabs { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 9px 4px; border-radius: 9px; font-weight: 600; color: var(--muted); font-size: 14px; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Lists */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--border); background: transparent; width: 100%; text-align: left; }
.item:last-child { border-bottom: 0; }
.cat-icon { width: 38px; height: 38px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-size: 19px; flex: none; }
.date-sep { font-size: 12px; color: var(--muted); padding: 12px 4px 6px; font-weight: 600; }

.balance-row { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border); }
.balance-row:last-child { border-bottom: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 750; font-size: 14px; flex: none; }

/* Stats */
.bar-row { margin: 10px 0; }
.bar-label { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; }
.bar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.locked { position: relative; text-align: center; padding: 30px 18px; }
.locked .big-emoji { font-size: 40px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
#paywall { z-index: 60; }
.sheet { background: var(--bg); width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 18px 16px 24px; animation: up .22s ease-out; }
@media (min-width: 560px) { .modal { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; margin-bottom: 14px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 19px; }

/* Forms */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
input[type=text], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
textarea { resize: vertical; min-height: 80px; }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; min-width: 0; }
.amount-input { font-size: 24px !important; font-weight: 700; }
.form-error { color: var(--neg); font-size: 14px; margin: 8px 0; min-height: 0; }

.segmented { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.segmented label { flex: 1; min-width: 70px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; text-align: center; padding: 8px 6px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); font-size: 13px; font-weight: 600; cursor: pointer; }
.segmented input:checked + span { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.emoji-pick { display: flex; gap: 6px; flex-wrap: wrap; }
.emoji-pick label input { position: absolute; opacity: 0; pointer-events: none; }
.emoji-pick span { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 11px; background: var(--surface); border: 1px solid var(--border); font-size: 21px; cursor: pointer; }
.emoji-pick input:checked + span { border: 2px solid var(--brand); background: var(--brand-soft); }

.member-split { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.member-split:last-child { border-bottom: 0; }
.member-split input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--brand); flex: none; }
.member-split .name { flex: 1; min-width: 0; }
.member-split input[type=number] { width: 110px; flex: none; padding: 8px 10px; }
form[data-split=equal] .split-value { display: none; }
.split-hint { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* Paywall */
.pw-hero { text-align: center; padding: 6px 0 10px; }
.pw-hero .big-emoji { font-size: 46px; }
.pw-hero h2 { margin: 6px 0 4px; }
.perks { list-style: none; padding: 0; margin: 14px 0; }
.perks li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.perks li:last-child { border-bottom: 0; }
.plans { display: flex; gap: 10px; margin: 14px 0; }
.plans label { flex: 1; }
.plans input { position: absolute; opacity: 0; pointer-events: none; }
.plans .plan { display: block; text-align: center; padding: 14px 8px; border-radius: 14px; border: 2px solid var(--border); background: var(--surface); cursor: pointer; position: relative; }
.plans input:checked + .plan { border-color: var(--gold); background: var(--gold-soft); }
.plan .price { font-size: 22px; font-weight: 800; display: block; }
.plan .tag { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); background: var(--gold); color: #2b1c00; font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.btn-gold { background: linear-gradient(135deg, #f2b632, #e08a00); color: #2b1c00; }
.lock { font-size: 11px; }
.btn-mp { background: #009ee3; color: #fff; }

/* Auth */
.auth { max-width: 380px; margin: 0 auto; padding: 40px 0 24px; }
.auth-hero { text-align: center; margin-bottom: 22px; }
.auth-hero h1 { margin: 10px 0 4px; font-size: 28px; letter-spacing: -.02em; }
.auth-hero .big-emoji { font-size: 48px; }
.btn-oauth { display: flex; align-items: center; justify-content: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); margin-bottom: 10px; }
.gsi-btn { display: flex; justify-content: center; min-height: 44px; margin-bottom: 10px; }
.btn-apple { background: var(--text); color: var(--bg); border-color: var(--text); }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-switch { text-align: center; color: var(--muted); margin-top: 16px; }
.link { border: 0; background: none; color: var(--brand); font-weight: 650; padding: 0; }
.demo-banner { background: var(--brand-soft); border-radius: 12px; padding: 12px 14px; font-size: 13px; margin-bottom: 16px; }
.demo-banner code { font-size: 12px; background: var(--surface); padding: 1px 5px; border-radius: 5px; }
input[type=email], input[type=password], input[type=search] {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); outline: none;
}
.prefix-input { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); padding-left: 12px; }
.prefix-input:focus-within { border-color: var(--brand); }
.prefix-input > span { color: var(--muted); font-weight: 650; }
.prefix-input input { border: 0 !important; padding-left: 4px; background: transparent; }
.username-hint { display: block; margin-top: 5px; font-size: 12px; }
button:disabled { opacity: .55; cursor: default; }

/* Topbar extras */
.bell { position: relative; font-size: 16px; }
.bell .dot { position: absolute; top: -3px; right: -3px; background: var(--neg); color: #fff; font-size: 11px; font-weight: 800; min-width: 18px; height: 18px; border-radius: 99px; display: grid; place-items: center; padding: 0 4px; }
.avatar-btn { border: 0; width: 38px; height: 38px; }
.avatar-lg { width: 56px; height: 56px; font-size: 22px; }
.muted-avatar { background: var(--surface-2); color: var(--muted); }
.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.invite-card { display: flex; gap: 12px; align-items: flex-start; border-left: 4px solid var(--brand); }
.invite-card .row-actions { margin-top: 10px; }
.search-results { min-height: 40px; margin-bottom: 4px; }

/* Historial, compartir y redes */
.group-card.archived { opacity: .75; }
.archived-banner { display: flex; align-items: center; gap: 10px; justify-content: space-between; background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; font-size: 14px; }
.close-card { display: flex; align-items: center; gap: 12px; margin-top: 14px; border-left: 4px solid var(--brand); }
.share-card { display: flex; align-items: center; gap: 12px; margin-top: 22px; }
.btn-whatsapp { display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: #25d366; color: #073b1c; }
.social-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.social-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none; font-size: 13px; font-weight: 600; }
.social-btn:hover { border-color: var(--brand); }
.social-btn.disabled { opacity: .45; cursor: default; }

.legal-links { text-align: center; margin-top: 14px; }
.legal-links a { color: var(--muted); }

.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 100; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
