/* Layout: phone = slim top bar, scrolling page, bottom tabs with a raised "New order" button.
   Desktop = left rail (brand, tabs, New order) beside one content column. */
:root {
  --bg: #FBF6F8;
  --surface: #FFFFFF;
  --surface-2: #F5ECF0;
  --ink: #2A1A22;
  --muted: #76626C;
  --line: #EADDE3;
  --berry: #B5336A;
  --berry-ink: #FFFFFF;
  --berry-soft: #F9E5EE;
  --teal: #3F7380;
  --teal-soft: #E1EEF1;
  --cookie-soft: #F5E6D3;
  --cookie-ink: #8A5520;
  --ok: #136C32;
  --ok-soft: #DDF3E4;
  --warn: #8F5400;
  --warn-soft: #FBEBCB;
  --owe: #AD350C;
  --owe-soft: #FCE3D8;
  --shadow: 0 1px 2px rgba(60, 20, 40, .06), 0 6px 18px rgba(60, 20, 40, .07);
  --toast-bg: #2A1A22;
  --toast-fg: #FBF6F8;
  --toast-accent: #F7A8C9;
  --font-display: 'Bebas Neue', 'Oswald', 'Arial Narrow', Impact, sans-serif;
  --font-body: 'Figtree', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-script: 'Sue Ellen Francisco', 'Segoe Script', 'Bradley Hand', cursive;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #170F14;
    --surface: #22171D;
    --surface-2: #2D1F26;
    --ink: #F7ECF1;
    --muted: #B7A0AB;
    --line: #3B2A33;
    --berry: #E57AA6;
    --berry-ink: #2A0E1B;
    --berry-soft: #3A1D2B;
    --teal: #8CC3CF;
    --teal-soft: #1E3238;
    --cookie-soft: #3A2A18;
    --cookie-ink: #E0B07A;
    --ok: #6FD596;
    --ok-soft: #173A25;
    --warn: #F2BE62;
    --warn-soft: #3F2E0E;
    --owe: #F59A6B;
    --owe-soft: #41200F;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
    --toast-bg: #F7ECF1;
    --toast-fg: #2A1A22;
    --toast-accent: #A02A5C;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.45 var(--font-body);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
body.locked { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: left; -webkit-tap-highlight-color: transparent; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--teal); text-decoration: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--berry) 55%, transparent); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- shell ---------- */
.app { max-width: 1120px; margin: 0 auto; }
.col { min-width: 0; }
.rail { display: none; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 14px 6px; }
main { padding-bottom: 128px; outline: none; }

.brand { display: flex; flex-direction: column; line-height: 1; }
.wm { font: 400 34px/1 var(--font-display); letter-spacing: .05em; color: var(--berry); display: inline-flex; align-items: center; }
.wm .cookie { width: .84em; height: .84em; margin: 0 .03em 0 .01em; }
.tag { font: 400 20px/1 var(--font-script); color: var(--teal); margin: 1px 0 0 3px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px; font-size: 12px; font-weight: 600; color: var(--muted); text-align: center; }
.tab[aria-current="page"] { color: var(--berry); }
.tab.new { color: var(--ink); }
.fab { width: 56px; height: 56px; border-radius: 50%; background: var(--berry); color: var(--berry-ink); display: grid; place-items: center; margin-top: -26px; box-shadow: 0 6px 16px color-mix(in srgb, var(--berry) 40%, transparent); }
.fab svg.i { width: 26px; height: 26px; stroke-width: 2.2; }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 44px; align-items: start; }
  .app.login-mode { display: block; }
  .app.login-mode .rail { display: none; }
  .rail { display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; padding-block: 28px; }
  .rail .brand { margin-bottom: 20px; }
  .topbar, .tabbar { display: none; }
  main { padding-top: 26px; padding-bottom: 72px; }
}
.rail-link { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border-radius: 14px; font-weight: 600; color: var(--muted); }
.rail-link:hover { background: var(--surface-2); }
.rail-link[aria-current="page"] { background: var(--berry-soft); color: var(--berry); }
.rail .newbtn { margin: 12px 0 6px; }
.rail .spacer { flex: 1; }

.banner { border-radius: 12px; padding: 10px 14px; font-size: 14px; margin: 6px 0 0; background: var(--warn-soft); color: var(--warn); }

/* ---------- type ---------- */
h1 { font: 400 44px/1 var(--font-display); letter-spacing: .03em; text-wrap: balance; }
.h2 { font: 400 24px/1.05 var(--font-display); letter-spacing: .04em; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.sub { font-size: 14px; color: var(--muted); }
.link { color: var(--teal); font-weight: 600; font-size: 14px; padding: 6px 0; }
.err { color: var(--owe); font-size: 14px; font-weight: 600; flex-basis: 100%; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; padding: 10px 0 14px; }
.block { margin-top: 22px; }
.block-h { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- buttons & fields ---------- */
.btn { white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border-radius: 14px; font-weight: 700; text-align: center; background: var(--surface-2); color: var(--ink); transition: transform .08s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--berry); color: var(--berry-ink); }
.btn.soft { background: var(--teal-soft); color: var(--teal); }
.btn.danger { background: var(--owe-soft); color: var(--owe); }
.btn.mini { min-height: 38px; padding: 0 12px; font-size: 14px; border-radius: 11px; }
.btn.wide { width: 100%; }
.btn.ico { width: 44px; min-height: 44px; padding: 0; border-radius: 50%; }
@media (max-width: 640px) {
  .row-side { padding-right: 8px; gap: 4px; }
  .row-side .btxt { display: none; }
  .row-side .btn.mini { width: 44px; min-height: 44px; padding: 0; border-radius: 50%; }
  .row-main { padding-inline: 12px; }
  .row.stack { flex-wrap: wrap; }
  .row.stack .row-main { flex-basis: 100%; padding-bottom: 4px; }
  .row.stack .row-side { flex-basis: 100%; padding: 0 12px 12px 64px; justify-content: flex-start; gap: 8px; }
  .row.stack .row-side .btxt { display: inline; }
  .row.stack .row-side .btn.mini { width: auto; padding: 0 14px; border-radius: 11px; }
}
.btn[disabled] { opacity: .5; cursor: default; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--surface-2); }

.fld { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fld > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.fld input, .fld textarea, .in {
  width: 100%; min-height: 46px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface); padding: 10px 14px; color: var(--ink);
}
.fld textarea { resize: vertical; min-height: 88px; }
.fld input:focus, .fld textarea:focus, .in:focus { outline: none; border-color: var(--berry); box-shadow: 0 0 0 3px color-mix(in srgb, var(--berry) 22%, transparent); }
::placeholder { color: var(--muted); opacity: .75; }
.search { position: relative; margin-bottom: 12px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .in { height: 48px; padding-left: 44px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 600; font-size: 15px; text-align: center; display: inline-flex; align-items: center; gap: 6px; }
.chip[aria-pressed="true"] { background: var(--berry); border-color: var(--berry); color: var(--berry-ink); }
.chip .n { font-size: 12px; opacity: .75; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 14px; margin-bottom: 14px; }
.seg button { min-height: 40px; border-radius: 10px; text-align: center; font-weight: 700; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.chk { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; min-height: 44px; }
.chk input { width: 20px; height: 20px; accent-color: var(--berry); }

/* ---------- stats & cards ---------- */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 720px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; } }
.stat { background: var(--surface); border-radius: 16px; padding: 14px 14px 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat .k { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.stat .v { font: 400 38px/1.05 var(--font-display); letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 13px; color: var(--muted); }
.v.ok { color: var(--ok); }
.v.owe { color: var(--owe); }

.cols { display: flex; flex-direction: column; }
.colA, .colB { display: contents; }
.fund { order: 1; } .hand { order: 2; } .owing { order: 3; } .bake { order: 4; }
@media (min-width: 1180px) {
  .cols { flex-direction: row; gap: 24px; align-items: flex-start; }
  .colA, .colB { display: flex; flex-direction: column; flex: 1; min-width: 0; }
  .colA { flex: 1.25; }
}
.fundcard { background: var(--berry-soft); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.fund-h { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.fund-pct { font: 400 34px/1 var(--font-display); color: var(--berry); }
.bar { height: 12px; border-radius: 999px; background: color-mix(in srgb, var(--berry) 20%, transparent); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 999px; background: var(--berry); }
.fundcard.empty { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }

.panel { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: stretch; }
.row + .row { border-top: 1px solid var(--line); }
.row-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 64px; }
.row-main:hover { background: var(--surface-2); }
.row-side { display: flex; align-items: center; gap: 8px; padding-right: 12px; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-sub { font-size: 14px; color: var(--muted); }
.amt { font: 400 24px/1 var(--font-display); letter-spacing: .02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt.owe { color: var(--owe); }
.amt.ok { color: var(--ok); }
.av { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; }
.av0 { background: var(--berry-soft); color: var(--berry); }
.av1 { background: var(--teal-soft); color: var(--teal); }
.av2 { background: var(--cookie-soft); color: var(--cookie-ink); }
.av3 { background: var(--surface-2); color: var(--muted); }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pill { display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; line-height: 1; padding: 5px 9px; border-radius: 999px; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.owe { background: var(--owe-soft); color: var(--owe); }
.pill.info { background: var(--teal-soft); color: var(--teal); }
.pill.muted { background: var(--surface-2); color: var(--muted); }
.empty { padding: 30px 20px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty .cookie { width: 44px; height: 44px; opacity: .7; }
.bk { display: flex; align-items: center; gap: 14px; padding: 10px 16px; }
.bk + .bk { border-top: 1px solid var(--line); }
.bk-n { font: 400 32px/1 var(--font-display); color: var(--berry); min-width: 36px; text-align: right; }
.day-h { display: flex; justify-content: space-between; padding: 10px 16px 6px; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); }
.loading { padding: 60px 0; text-align: center; color: var(--muted); }

/* ---------- sign in ---------- */
.login { min-height: 80vh; display: grid; place-items: center; padding-block: 32px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 16px; }
.login-card .wm { font-size: 46px; }
.login-card .tag { font-size: 24px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }

/* ---------- sheets ---------- */
.scrim { position: fixed; inset: 0; background: rgba(24, 8, 16, .5); z-index: 40; animation: fade .18s ease; }
.sheet {
  position: fixed; z-index: 41; left: 0; right: 0; bottom: 0;
  max-height: 94vh; max-height: 94dvh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 22px 22px 0 0; outline: none;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .25); animation: rise .24s cubic-bezier(.2, .8, .2, 1);
}
@media (min-width: 720px) {
  .sheet { left: 50%; right: auto; top: 50%; bottom: auto; transform: translate(-50%, -50%); width: min(580px, calc(100vw - 48px)); max-height: 88vh; max-height: 88dvh; border-radius: 22px; animation: pop .2s ease; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -48%); } }
.sh-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px max(20px, env(safe-area-inset-right, 0px)) 6px max(20px, env(safe-area-inset-left, 0px)); }
.sh-head h2 { font: 400 30px/1.05 var(--font-display); letter-spacing: .03em; overflow-wrap: anywhere; }
.sh-body { overflow: auto; padding: 4px max(20px, env(safe-area-inset-right, 0px)) 20px max(20px, env(safe-area-inset-left, 0px)); flex: 1; overscroll-behavior: contain; }
.sh-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px max(20px, env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px)); border-top: 1px solid var(--line); }
.sh-foot .btn { flex: 1; }
.sheet .panel { box-shadow: none; border: 1px solid var(--line); }
.fsec { padding: 14px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.fsec:first-child { border-top: 0; }
.fsec > h3 { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.lbl { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.picked { display: flex; align-items: center; gap: 12px; }
.sugg { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.sugg .row-main { border-radius: 12px; min-height: 56px; padding: 8px 10px; }
.pick { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.pick + .pick { border-top: 1px solid var(--line); }
.pick .nm { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.step { display: flex; align-items: center; gap: 6px; }
.step button { width: 44px; height: 44px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; }
.step button[disabled] { opacity: .35; }
.step .plus { background: var(--berry); color: var(--berry-ink); }
.step .q { min-width: 30px; text-align: center; font: 400 28px/1 var(--font-display); }
.pick:not(.on) .q { color: var(--muted); }
.sum { display: flex; flex-direction: column; line-height: 1; min-width: 96px; }
.sum small { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.sum strong { font: 400 34px/1 var(--font-display); }
.lines { display: flex; flex-direction: column; }
.line { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; }
.line + .line { border-top: 1px dashed var(--line); }
.line.total { border-top: 1.5px solid var(--line); font-weight: 700; }
.line.bal b { font: 400 28px/1 var(--font-display); color: var(--owe); }
.line.bal.zero b { color: var(--ok); }
.acts { display: flex; flex-wrap: wrap; gap: 8px; }
.mini-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mini-stats div { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.mini-stats small { display: block; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.mini-stats b { font: 400 26px/1.1 var(--font-display); }
.mrow { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 10px; padding: 12px 0; align-items: end; }
.mrow + .mrow { border-top: 1px solid var(--line); }
.mrow .wide-f { grid-column: 1 / -1; }
.mrow .mfoot { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; }
.paylist { display: flex; flex-direction: column; }
.pay { display: flex; align-items: center; gap: 8px; padding: 4px 0; min-height: 44px; }
.pay + .pay { border-top: 1px dashed var(--line); }
.confirm { background: var(--owe-soft); color: var(--owe); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; font-weight: 600; }

/* ---------- toasts ---------- */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(92px + env(safe-area-inset-bottom, 0px)); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(440px, calc(100vw - 32px)); pointer-events: none; }
@media (min-width: 900px) { #toasts { bottom: 28px; } }
.toast { pointer-events: auto; background: var(--toast-bg); color: var(--toast-fg); border-radius: 14px; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px; box-shadow: var(--shadow); font-weight: 600; animation: rise .2s ease; }
.toast button { color: var(--toast-accent); font-weight: 700; padding: 4px 6px; }
.toast.bad { background: #B3360C; color: #fff; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
