/* BillBell — warm ledger paper, deep teal ink, amber bell. */
:root {
  --bg: #f4f1e8;
  --bg-2: #ebe6d8;
  --card: #fffdf8;
  --ink: #18302d;
  --ink-2: #4e625f;
  --ink-3: #7d8c89;
  --line: #e2dccb;
  --brand: #0f4c47;
  --brand-2: #16685f;
  --brand-ink: #ffffff;
  --amber: #e29a2d;
  --amber-soft: #fbecd2;
  --red: #c8433f;
  --red-soft: #fbe3e0;
  --green: #2c8155;
  --green-soft: #def1e5;
  --blue: #3567b5;
  --blue-soft: #e1eaf8;
  --shadow: 0 1px 2px rgba(24, 48, 45, .06), 0 6px 20px rgba(24, 48, 45, .06);
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101614; --bg-2: #18201e; --card: #1a2321; --ink: #e8efec; --ink-2: #aab9b5; --ink-3: #7a8a86;
    --line: #2a3533; --brand: #5cc2b4; --brand-2: #7ad3c6; --brand-ink: #0b1f1c;
    --amber: #f0b356; --amber-soft: #3a2f1c; --red: #ff7b72; --red-soft: #3b201f;
    --green: #5fc48b; --green-soft: #183126; --blue: #82a9ea; --blue-soft: #1c2a40;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101614; --bg-2: #18201e; --card: #1a2321; --ink: #e8efec; --ink-2: #aab9b5; --ink-3: #7a8a86;
  --line: #2a3533; --brand: #5cc2b4; --brand-2: #7ad3c6; --brand-ink: #0b1f1c;
  --amber: #f0b356; --amber-soft: #3a2f1c; --red: #ff7b72; --red-soft: #3b201f;
  --green: #5fc48b; --green-soft: #183126; --blue: #82a9ea; --blue-soft: #1c2a40;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  min-height: 100vh;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-2); }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); font-size: .85rem; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; border-radius: 8px; }

/* ---------- layout */
#app { max-width: 640px; margin: 0 auto; padding: calc(var(--safe-t) + 8px) 16px calc(96px + var(--safe-b)); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0 14px; }
.topbar h1 { font-size: 1.55rem; margin: 0; letter-spacing: -.02em; }
.topbar .sub { font-size: .9rem; color: var(--ink-2); }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--card); box-shadow: var(--shadow); display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + var(--safe-b));
  display: flex; justify-content: center;
}
.tabbar-inner { display: flex; width: 100%; max-width: 560px; justify-content: space-around; }
.tab { flex: 1; border: 0; background: none; padding: 6px 0 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .7rem; color: var(--ink-3); cursor: pointer; }
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--brand); font-weight: 600; }

.fab {
  position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(80px + var(--safe-b)); z-index: 21;
  width: 58px; height: 58px; border-radius: 20px; border: 0; cursor: pointer;
  background: var(--brand); color: var(--brand-ink); box-shadow: 0 8px 24px rgba(15, 76, 71, .35);
  display: grid; place-items: center;
}
.fab svg { width: 28px; height: 28px; }

/* ---------- cards */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h2, .section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 0 0 10px; font-weight: 700; }
.section-title { margin: 22px 4px 8px; display: flex; justify-content: space-between; align-items: center; }
.section-title a, .section-title button { text-transform: none; letter-spacing: 0; font-weight: 600; font-size: .85rem; background: none; border: 0; color: var(--brand-2); cursor: pointer; padding: 0; }

.hero { background: var(--brand); color: var(--brand-ink); position: relative; overflow: hidden; }
.hero h2 { color: color-mix(in srgb, var(--brand-ink) 70%, transparent); }
.hero .big { font-size: 2.4rem; font-weight: 750; letter-spacing: -.03em; line-height: 1.1; }
.hero .row { display: flex; gap: 10px; margin-top: 14px; }
.hero .pill { flex: 1; background: color-mix(in srgb, var(--brand-ink) 12%, transparent); border-radius: 12px; padding: 8px 10px; }
.hero .pill small { display: block; font-size: .72rem; opacity: .8; }
.hero .pill strong { font-size: 1.02rem; }
.hero .bell-bg { position: absolute; right: -18px; top: -14px; width: 120px; height: 120px; opacity: .1; }
.progress { height: 8px; border-radius: 99px; background: color-mix(in srgb, var(--brand-ink) 18%, transparent); overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; background: var(--amber); border-radius: 99px; transition: width .4s; }
.meter { height: 8px; border-radius: 99px; background: var(--bg-2); overflow: hidden; margin-top: 6px; }
.meter > i { display: block; height: 100%; border-radius: 99px; background: var(--brand-2); }
.meter.over > i { background: var(--red); }

.banner { border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; display: flex; gap: 10px; align-items: flex-start; font-size: .93rem; }
.banner.warn { background: var(--red-soft); color: var(--red); }
.banner.info { background: var(--blue-soft); color: var(--blue); }
.banner.amber { background: var(--amber-soft); color: color-mix(in srgb, var(--amber) 60%, var(--ink)); }
.banner.good { background: var(--green-soft); color: var(--green); }
.banner .b-body { flex: 1; }
.banner button { margin-top: 8px; }
.banner .x { background: none; border: 0; color: inherit; cursor: pointer; font-size: 1.1rem; padding: 0 2px; }

/* ---------- bill rows */
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; background: none; width: 100%; text-align: left; border-left: 0; border-right: 0; border-top: 0; }
.row-item:last-child { border-bottom: 0; }
.row-item:active { background: var(--bg-2); }
.cat { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 1.2rem; flex: none; background: var(--bg-2); }
.row-main { flex: 1; min-width: 0; }
.row-main .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main .s { font-size: .82rem; color: var(--ink-2); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row-amt { text-align: right; font-weight: 650; }
.row-amt .s { font-size: .78rem; font-weight: 500; }
.due-over { color: var(--red); font-weight: 600; }
.due-soon { color: color-mix(in srgb, var(--amber) 70%, var(--ink)); font-weight: 600; }
.paid-txt { color: var(--green); font-weight: 600; }
.tag { font-size: .7rem; padding: 1px 7px; border-radius: 99px; background: var(--bg-2); color: var(--ink-2); font-weight: 600; }
.tag.auto { background: var(--blue-soft); color: var(--blue); }
.tag.paid { background: var(--green-soft); color: var(--green); }
.tag.over { background: var(--red-soft); color: var(--red); }
.check-btn { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--line); background: none; cursor: pointer; display: grid; place-items: center; flex: none; color: var(--ink-3); }
.check-btn svg { width: 20px; height: 20px; }
.check-btn:hover, .check-btn:focus-visible { border-color: var(--green); color: var(--green); }
.check-btn.done { background: var(--green); border-color: var(--green); color: #fff; }
.empty { text-align: center; padding: 28px 16px; color: var(--ink-2); }
.empty .e-icon { font-size: 2.2rem; margin-bottom: 6px; }

/* ---------- controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 650; cursor: pointer; background: var(--brand); color: var(--brand-ink); text-decoration: none; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--bg-2); color: var(--ink); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.green { background: var(--green); color: #fff; }
.btn.small { padding: 8px 12px; font-size: .88rem; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; gap: 10px; margin-top: 14px; }
.btn-row .btn { flex: 1; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 5px; color: var(--ink-2); }
.input, select.input, textarea.input {
  width: 100%; padding: 12px 13px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); font-size: 16px; appearance: none; -webkit-appearance: none;
}
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.input:focus { border-color: var(--brand-2); outline: none; }
textarea.input { min-height: 80px; resize: vertical; }
.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; min-width: 0; }
.money-wrap { position: relative; }
.money-wrap .sym { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.money-wrap .input { padding-left: 30px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.toggle:last-child { border-bottom: 0; }
.toggle .tl { flex: 1; }
.toggle .tl small { display: block; color: var(--ink-3); font-size: .8rem; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .2s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: .2s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid var(--amber); outline-offset: 2px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1.5px solid var(--line); background: var(--card); padding: 7px 13px; border-radius: 99px; font-size: .88rem; font-weight: 600; cursor: pointer; color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.search { position: relative; margin-bottom: 10px; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--ink-3); }
.search .input { padding-left: 40px; }
.seg { display: flex; background: var(--bg-2); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 9px; font-weight: 600; font-size: .88rem; color: var(--ink-2); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- sheet (modal) */
.sheet-back { position: fixed; inset: 0; background: rgba(10, 20, 18, .45); z-index: 40; opacity: 0; transition: opacity .2s; }
.sheet-back.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; margin: 0 auto; max-width: 640px;
  background: var(--card); border-radius: 22px 22px 0 0; max-height: 92vh; overflow-y: auto;
  padding: 8px 18px calc(20px + var(--safe-b)); transform: translateY(100%); transition: transform .25s ease-out;
}
.sheet.open { transform: none; }
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.sheet-head h3 { margin: 0; font-size: 1.2rem; }
.sheet-close { background: var(--bg-2); border: 0; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 1rem; flex: none; }

.detail-amt { font-size: 2.2rem; font-weight: 750; letter-spacing: -.02em; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 14px 0; font-size: .93rem; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; text-align: right; font-weight: 550; overflow-wrap: anywhere; }
.notes { background: var(--bg); border-radius: 12px; padding: 10px 12px; white-space: pre-wrap; font-size: .92rem; margin-bottom: 12px; overflow-wrap: anywhere; }
.receipt-thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); }
.receipt-full { width: 100%; border-radius: 12px; }

/* ---------- toast */
.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(92px + var(--safe-b)); z-index: 60; display: flex; justify-content: center; pointer-events: none; padding: 0 16px; }
.toast { background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 14px; display: flex; align-items: center; gap: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.25); pointer-events: auto; max-width: 520px; animation: toastIn .2s ease-out; font-size: .95rem; }
.toast.error { background: var(--red); color: #fff; }
.toast button { background: none; border: 0; color: var(--amber); font-weight: 700; cursor: pointer; padding: 0; }
@keyframes toastIn { from { transform: translateY(14px); opacity: 0; } }

/* ---------- calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head h2 { margin: 0; font-size: 1.15rem; text-transform: none; letter-spacing: 0; color: var(--ink); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: .72rem; font-weight: 700; color: var(--ink-3); padding-bottom: 4px; }
.cal-day { aspect-ratio: 1 / 1.05; border-radius: 12px; border: 0; background: none; cursor: pointer; display: flex; flex-direction: column; align-items: center; padding-top: 6px; gap: 3px; font-size: .9rem; color: var(--ink); }
.cal-day.other { color: var(--ink-3); opacity: .45; }
.cal-day.today { background: var(--bg-2); font-weight: 800; }
.cal-day[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.dots { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; max-width: 30px; }
.dot { width: 6px; height: 6px; border-radius: 50%; }
.dot.over { background: var(--red); } .dot.due { background: var(--amber); } .dot.paid { background: var(--green); } .dot.pay { background: var(--blue); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .78rem; color: var(--ink-2); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

/* ---------- plan */
.period { border-left: 4px solid var(--blue); padding: 2px 0 2px 12px; margin: 6px 0 16px; }
.period.pre { border-color: var(--amber); }
.period.short { border-color: var(--red); }
.period-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.period-head strong { font-size: 1.02rem; }
.period ul { list-style: none; margin: 8px 0; padding: 0; font-size: .9rem; }
.period li { display: flex; justify-content: space-between; padding: 3px 0; color: var(--ink-2); gap: 10px; }
.period .left { display: flex; justify-content: space-between; font-weight: 700; padding-top: 6px; border-top: 1px dashed var(--line); }
.pos { color: var(--green); } .neg { color: var(--red); }

/* ---------- charts */
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--ink-3); font-size: 11px; }
.chart .bar-in { fill: var(--green); } .chart .bar-out { fill: var(--amber); } .chart .bar-paid { fill: var(--brand-2); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.hbar { margin: 10px 0; }
.hbar-top { display: flex; justify-content: space-between; font-size: .9rem; gap: 8px; }

/* ---------- auth */
.auth { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; max-width: 420px; margin: 0 auto; padding: 24px 20px calc(24px + var(--safe-b)); }
.brand { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 26px; text-align: center; }
.brand img { width: 76px; height: 76px; border-radius: 22px; box-shadow: var(--shadow); }
.brand h1 { margin: 6px 0 0; font-size: 1.9rem; letter-spacing: -.03em; }
.brand p { margin: 0; color: var(--ink-2); }
.auth .switch-link { text-align: center; margin-top: 18px; font-size: .95rem; }
.auth .switch-link button { background: none; border: 0; color: var(--brand-2); font-weight: 700; cursor: pointer; padding: 4px; }
.auth .legal { text-align: center; font-size: .8rem; color: var(--ink-3); margin-top: 20px; }
.err-msg { background: var(--red-soft); color: var(--red); padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: .92rem; }
.ok-msg { background: var(--green-soft); color: var(--green); padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: .92rem; }

.member { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--amber-soft); color: color-mix(in srgb, var(--amber) 60%, var(--ink)); display: grid; place-items: center; font-weight: 800; flex: none; }
.code-box { font-family: ui-monospace, Menlo, monospace; font-size: 1.4rem; letter-spacing: .18em; font-weight: 700; background: var(--bg); border-radius: 12px; padding: 12px; text-align: center; margin: 8px 0; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 1.4rem; }
.stat small { color: var(--ink-3); }
.offline-pill { position: fixed; top: calc(var(--safe-t) + 8px); left: 50%; transform: translateX(-50%); z-index: 70; background: var(--ink); color: var(--bg); font-size: .8rem; padding: 5px 12px; border-radius: 99px; font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 700px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
/* Keep toasts out of the way while a sheet is open */
body:has(.sheet.open) .toast-wrap { bottom: auto; top: calc(var(--safe-t) + 12px); }
