/* ==========================================================================
   FINANCE PLANNER WEB — stylesheet
   --------------------------------------------------------------------------
   The palette is LOOM's own, lifted from the constants at the top of
   finance_planner.py so the web app and the desktop app read as one product.

   MOBILE FIRST, and not as a slogan: the base rules are the phone layout and
   every media query adds to it. The planner is the thing you check standing in
   a shop, so the phone case is the one that has to be right.

   Two structural decisions worth knowing:
     - the day grid is CSS grid with `auto-fit`, so cards reflow from one column
       to four without a breakpoint per step;
     - the bottom tab bar is `position: fixed` with safe-area padding, and the
       main column reserves its height, so nothing hides behind it on an iPhone.
   ========================================================================== */

:root {
  --base:      #080C0A;
  --surface:   #0E1512;
  --raised:    #141D19;
  --hairline:  #22302A;
  --text:      #ECF3EF;
  --muted:     #8CA096;
  --faint:     #5C6E66;
  --accent:    #3FD9A0;
  --accent-soft:#16352A;
  --in:        #4FE0A6;
  --out:       #FF8080;
  --bill:      #F5B95C;
  --assumed:   #B98CFF;
  --danger:    #FF6B7A;
  --overdue:   #FF5C5C;
  --grouped:   #7FA6FF;

  --radius:    12px;
  --radius-sm: 8px;
  --gap:       12px;
  --tabbar:    58px;

  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
}

/* A light theme for anyone whose phone is set to it. The app defaults to dark
   (LOOM is dark) and only follows the system when the user has not chosen. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --base: #F5F8F6; --surface: #FFFFFF; --raised: #FFFFFF;
    --hairline: #DCE6E1; --text: #10201A; --muted: #5A6E66; --faint: #8A9A93;
    --accent: #10855E; --accent-soft: #E3F5EC;
    --in: #0F8A5F; --out: #C63B3B; --bill: #A9741A; --assumed: #6A45B5;
    --danger: #C22F3E; --overdue: #C22F3E; --grouped: #2F5FBF;
    --shadow: 0 1px 2px rgba(16,32,26,.06), 0 6px 18px rgba(16,32,26,.08);
  }
}
:root[data-theme="light"] {
  --base: #F5F8F6; --surface: #FFFFFF; --raised: #FFFFFF;
  --hairline: #DCE6E1; --text: #10201A; --muted: #5A6E66; --faint: #8A9A93;
  --accent: #10855E; --accent-soft: #E3F5EC;
  --in: #0F8A5F; --out: #C63B3B; --bill: #A9741A; --assumed: #6A45B5;
  --danger: #C22F3E; --overdue: #C22F3E; --grouped: #2F5FBF;
  --shadow: 0 1px 2px rgba(16,32,26,.06), 0 6px 18px rgba(16,32,26,.08);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--base);
  color: var(--text);
  font: 15px/1.5 var(--font);
  /* Stops the whole page rubber-banding sideways on iOS when a table inside it
     is wider than the screen. */
  overflow-x: hidden;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); text-decoration: none; }
a:hover, a:focus-visible { text-decoration: underline; }

/* One visible focus style for everything, and never removed — a keyboard user
   who cannot see where they are cannot use the app at all. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--accent-soft); color: var(--text); }

/* ==========================================================================
   THE SIGNED-OUT PAGES
   ========================================================================== */

body.gate {
  display: grid;
  place-items: center;
  min-height: 100svh;
  padding: 1.25rem;
  padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
}

.gate-card {
  width: 100%;
  max-width: 25rem;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 1.75rem 1.5rem;
  box-shadow: var(--shadow);
}
.gate-card.profile-card { max-width: 30rem; }

.gate-head { text-align: center; margin-bottom: 1.25rem; }
.gate-mark { display: flex; justify-content: center; margin-bottom: .6rem; }
.gate-head h1 { font-size: 1.15rem; }
.gate-sub { color: var(--muted); font-size: .9rem; margin: .3rem 0 0; }

.gate-form { display: grid; gap: .35rem; }
.gate-form label {
  font-size: .78rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; margin-top: .6rem;
}
.gate-form .hint {
  text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--faint);
}
.gate-form .check {
  display: flex; align-items: center; gap: .5rem; margin-top: .9rem;
  text-transform: none; letter-spacing: 0; font-size: .85rem; color: var(--muted);
}
.gate-form button { margin-top: 1.1rem; }

.gate-links {
  display: flex; flex-wrap: wrap; gap: .25rem 1rem; justify-content: center;
  margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--hairline);
  font-size: .85rem;
}

.fineprint { color: var(--faint); font-size: .78rem; margin: .8rem 0 0; }

/* --- inputs ---------------------------------------------------------------- */

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], input[type="url"], select, textarea {
  width: 100%;
  background: var(--base);
  color: var(--text);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: .6rem .7rem;
  /* 16px minimum, because anything smaller makes iOS Safari zoom the page in
     the moment the field is focused. */
  font: inherit;
  font-size: 16px;
  appearance: none;
}
textarea { min-height: 5rem; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--faint); }
input[type="checkbox"], input[type="radio"] {
  width: 1.05rem; height: 1.05rem; accent-color: var(--accent); flex: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2rem;
}

/* --- buttons -------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  /* 44px tall: the smallest target a thumb hits reliably. */
  min-height: 44px;
  padding: .55rem 1rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--raised);
  color: var(--text);
  font: inherit; font-weight: 600; font-size: .9rem;
  cursor: pointer;
  text-align: center;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:hover { border-color: var(--faint); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #04140D; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-ghost { background: transparent; }
.btn-sm { min-height: 34px; padding: .3rem .6rem; font-size: .8rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; }

/* --- banners -------------------------------------------------------------- */

.banner {
  border: 1px solid var(--hairline);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  padding: .65rem .8rem;
  font-size: .88rem;
  margin: 0 0 1rem;
  background: var(--raised);
}
.banner-error { border-left-color: var(--danger); color: var(--out); }
.banner-ok    { border-left-color: var(--accent); }
.banner-note  { border-left-color: var(--bill); }

/* ==========================================================================
   THE APP SHELL
   ========================================================================== */

.booting {
  display: grid; place-items: center; gap: .9rem;
  min-height: 70svh; color: var(--muted);
}
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--hairline); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
  * { scroll-behavior: auto !important; }
}

.shell {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  /* Room for the fixed tab bar, plus the phone's own bottom inset. */
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom));
}

/* --- top bar -------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem .85rem;
  padding-top: max(.6rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--base) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hairline);
}
.topbar .brand {
  display: flex; align-items: center; gap: .5rem;
  font-weight: 700; font-size: .95rem; letter-spacing: -.01em;
}
.topbar .brand svg { flex: none; }
.topbar .spacer { flex: 1; }

.plan-chip {
  font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: .22rem .45rem; border-radius: 999px;
  border: 1px solid var(--hairline); color: var(--muted); white-space: nowrap;
}
.plan-chip.pro { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.save-chip {
  font-size: .72rem; color: var(--faint); white-space: nowrap;
  display: inline-flex; align-items: center; gap: .3rem;
}
.save-chip.dirty { color: var(--bill); }
.save-chip.error { color: var(--out); }
.save-chip .pip {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none;
}

/* --- main column ---------------------------------------------------------- */

main.view {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 1rem .85rem 2rem;
}

.view-head {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: .5rem 1rem;
  margin-bottom: 1rem;
}
.view-head h2 { font-size: 1.1rem; }
.view-head .sub { color: var(--muted); font-size: .85rem; }
.view-head .grow { flex: 1; }

/* --- panels --------------------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  margin-bottom: var(--gap);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: .7rem .85rem;
  border-bottom: 1px solid var(--hairline);
}
.panel-head h3 {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 700;
}
.panel-head .grow { flex: 1; }
.panel-body { padding: .85rem; }
.panel-body.tight { padding: 0; }

/* --- HUD / stat tiles ----------------------------------------------------- */

.tiles {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: var(--gap);
}
.tile {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: .8rem .85rem;
}
.tile .label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 700; margin-bottom: .3rem;
}
.tile .figure {
  font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.tile .note { font-size: .76rem; color: var(--faint); margin-top: .2rem; }
.tile.good .figure { color: var(--in); }
.tile.bad .figure  { color: var(--out); }
.tile.warn .figure { color: var(--bill); }

/* --- the resources HUD ---------------------------------------------------- */
/* Rows are sorted largest first and every row is shown — the desktop app had a
   bug where a [:5] slice hid the second-largest account, and the fix was to
   stop truncating. Same rule here. */
.hud-rows { display: grid; }
.hud-row {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .85rem;
  border-top: 1px solid var(--hairline);
  font-variant-numeric: tabular-nums;
}
.hud-row:first-child { border-top: none; }
.hud-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
                 white-space: nowrap; }
.hud-row .amount { font-weight: 650; }
.hud-row.zero { color: var(--faint); }
.hud-row.negative .amount { color: var(--out); }
.hud-total {
  display: flex; gap: .6rem; padding: .7rem .85rem;
  border-top: 1px solid var(--hairline); font-weight: 700;
  font-variant-numeric: tabular-nums; background: var(--raised);
}
.hud-total .name { flex: 1; }

/* ==========================================================================
   THE PLANNER GRID
   ========================================================================== */

.day-block { margin-bottom: var(--gap); }

.day-head {
  display: flex; align-items: center; gap: .5rem;
  padding: .45rem .1rem .5rem;
  position: sticky; top: calc(env(safe-area-inset-top) + 44px);
  background: linear-gradient(var(--base) 70%, transparent);
  z-index: 10;
}
.day-head .date { font-weight: 700; font-size: .92rem; }
.day-head .rel { font-size: .74rem; color: var(--faint); }
.day-head .net {
  margin-left: auto; font-size: .8rem; font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.day-head .net.pos { color: var(--in); }
.day-head .net.neg { color: var(--out); }
.day-head.today .date { color: var(--accent); }
.day-head button.fold {
  background: none; border: none; color: var(--faint); cursor: pointer;
  font-size: .9rem; padding: .2rem .35rem; min-height: 32px;
}

/* One column on a phone, as many as fit after that. No per-size breakpoints:
   auto-fit does the work and the cards keep a sane minimum width. */
.cards {
  display: grid;
  gap: .5rem;
  grid-template-columns: 1fr;
}
@media (min-width: 560px)  { .cards { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); } }

.card {
  --stripe: var(--hairline);
  display: grid;
  grid-template-columns: 3px 1fr auto;
  align-items: center;
  gap: 0 .7rem;
  background: var(--raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
  min-height: 56px;
  transition: border-color .12s ease, transform .06s ease;
}
.card::before { content: ""; background: var(--stripe); align-self: stretch; }
.card:hover { border-color: var(--faint); }
.card:active { transform: scale(.995); }
.card .body { padding: .5rem 0; min-width: 0; }
.card .name {
  font-weight: 620; font-size: .92rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card .detail {
  font-size: .74rem; color: var(--faint); margin-top: .1rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card .amount {
  padding: .5rem .7rem .5rem 0; font-weight: 700; font-size: .95rem;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

.card.bill    { --stripe: var(--bill); }
.card.expense { --stripe: var(--out); }
.card.income  { --stripe: var(--in); }
.card.assumed_income  { --stripe: var(--assumed); }
.card.assumed_expense { --stripe: var(--assumed); }
.card.overdue { --stripe: var(--overdue); border-color: color-mix(in srgb, var(--overdue) 35%, var(--hairline)); }
.card.income .amount, .card.assumed_income .amount { color: var(--in); }
.card.bill .amount, .card.expense .amount, .card.assumed_expense .amount { color: var(--out); }
.card.overdue .amount { color: var(--overdue); }

.card .flags { display: flex; gap: .25rem; margin-top: .25rem; flex-wrap: wrap; }
.flag {
  font-size: .62rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  padding: .1rem .3rem; border-radius: 3px;
  border: 1px solid currentColor; color: var(--faint);
}
.flag.due { color: var(--overdue); }
.flag.moved { color: var(--grouped); }
.flag.pulled { color: var(--bill); }
.flag.spread { color: var(--assumed); }
.flag.pinned { color: var(--accent); }
.flag.plan { color: var(--muted); }

/* A folded run of identical days. */
.band {
  display: flex; align-items: center; gap: .6rem;
  width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px dashed var(--hairline);
  border-radius: var(--radius-sm); padding: .6rem .8rem; min-height: 48px;
  margin-bottom: var(--gap);
}
.band:hover { border-color: var(--faint); }
.band .range { font-weight: 650; font-size: .88rem; }
.band .what { font-size: .76rem; color: var(--faint); }
.band .net { margin-left: auto; font-variant-numeric: tabular-nums; font-size: .84rem; }

.empty {
  text-align: center; color: var(--faint); padding: 2.5rem 1rem; font-size: .9rem;
}
.empty strong { display: block; color: var(--muted); margin-bottom: .3rem; font-size: 1rem; }

/* ==========================================================================
   TABLES  (history, transfers, admin)
   ========================================================================== */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.grid {
  width: 100%; border-collapse: collapse; font-size: .86rem;
  font-variant-numeric: tabular-nums;
}
table.grid th, table.grid td {
  padding: .55rem .7rem; text-align: left; border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}
table.grid th {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 700; position: sticky; top: 0;
  background: var(--surface); z-index: 1;
}
table.grid td.wrap { white-space: normal; min-width: 11rem; }
table.grid td.num, table.grid th.num { text-align: right; }
table.grid tbody tr:hover { background: var(--raised); }
table.grid .in  { color: var(--in); }
table.grid .out { color: var(--out); }
table.grid tr.pending td { color: var(--muted); font-style: italic; }

/* On a phone, tables that are really lists of records read better as cards.
   The header is hidden and each cell labels itself from data-label. */
@media (max-width: 620px) {
  table.stacked thead { display: none; }
  table.stacked tr {
    display: grid; grid-template-columns: auto 1fr;
    gap: 0 .6rem; padding: .6rem 0; border-bottom: 1px solid var(--hairline);
  }
  table.stacked td {
    display: contents; white-space: normal; border: none; padding: 0;
  }
  table.stacked td::before {
    content: attr(data-label);
    font-size: .68rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--faint); padding: .12rem 0;
  }
}

/* ==========================================================================
   CHARTS  (inline SVG, drawn by the views)
   ========================================================================== */

/* preserveAspectRatio="none" on the SVGs means the browser stretches them to
   whatever box they are given, so the height is set here rather than derived
   from the viewBox -- otherwise a 640x180 chart becomes 320px tall in a 1150px
   panel and a year with two busy months reads as mostly empty sky. */
.chart {
  width: 100%;
  height: auto;
  max-height: 200px;
  display: block;
  overflow: visible;
}
.chart-tall { max-height: 260px; }
.chart-spark { max-height: 44px; }
.chart .axis { stroke: var(--hairline); stroke-width: 1; }
.chart .grid-line { stroke: var(--hairline); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .label { fill: var(--faint); font-size: 10px; font-family: var(--font); }
.chart .bar-in  { fill: var(--in); }
.chart .bar-out { fill: var(--out); }
.chart .line-known { stroke: var(--accent); stroke-width: 2; fill: none; }
.chart .line-assumed {
  stroke: var(--assumed); stroke-width: 2; fill: none; stroke-dasharray: 4 3;
}
.chart .zero { stroke: var(--faint); stroke-width: 1; }

.legend { display: flex; flex-wrap: wrap; gap: .4rem .9rem; font-size: .76rem;
          color: var(--muted); margin-top: .5rem; }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* A bar with its own label, used for categories and progress. */
.meter { display: grid; gap: .3rem; margin-bottom: .6rem; }
.meter .top {
  display: flex; gap: .6rem; font-size: .84rem; font-variant-numeric: tabular-nums;
}
.meter .top .name { flex: 1; min-width: 0; overflow: hidden;
                    text-overflow: ellipsis; white-space: nowrap; }
.meter .track { height: 6px; border-radius: 3px; background: var(--hairline); overflow: hidden; }
.meter .fill { height: 100%; background: var(--accent); border-radius: 3px; }
.meter.debt .fill { background: var(--bill); }
.meter.over .fill { background: var(--out); }

/* ==========================================================================
   BOTTOM TAB BAR
   ========================================================================== */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--hairline);
  padding-bottom: env(safe-area-inset-bottom);
  /* Eight tabs will not fit across a phone, so it scrolls sideways and the
     active one is scrolled into view. */
  overflow-x: auto;
  scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }
.tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-width: 62px; min-height: var(--tabbar);
  background: none; border: none; cursor: pointer;
  color: var(--faint); font: inherit; font-size: .62rem; font-weight: 600;
  letter-spacing: .03em; padding: .35rem .2rem;
}
.tabbar button .ico { font-size: 1.05rem; line-height: 1; }
.tabbar button[aria-current="page"] { color: var(--accent); }
.tabbar button[aria-current="page"] .ico { transform: translateY(-1px); }

@media (min-width: 900px) {
  /* On a wide screen the tabs move to the top bar and the fixed bar goes away,
     which gives the planner its full height back. */
  .tabbar {
    position: static; border-top: none; border-bottom: 1px solid var(--hairline);
    grid-auto-columns: auto; justify-content: start; padding: 0 .5rem;
    background: transparent; backdrop-filter: none; overflow: visible;
  }
  .tabbar button {
    flex-direction: row; gap: .4rem; min-height: 42px; font-size: .8rem;
    padding: .3rem .7rem; border-radius: var(--radius-sm);
  }
  .tabbar button[aria-current="page"] { background: var(--accent-soft); }
  .shell { padding-bottom: 0; }
  .day-head { top: 46px; }
}

/* ==========================================================================
   SHEETS AND DIALOGS
   ========================================================================== */
/* A sheet slides up from the bottom on a phone and becomes a centred dialog on
   a wide screen — same markup, same code path, one media query. */

.scrim {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  animation: fade .14s ease;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  width: 100%; max-height: 92svh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  animation: rise .18s cubic-bezier(.2,.8,.2,1);
  box-shadow: 0 -8px 40px rgba(0,0,0,.5);
}
@keyframes rise { from { transform: translateY(14px); } }
@media (prefers-reduced-motion: reduce) {
  .scrim, .sheet { animation: none; }
}
@media (min-width: 640px) {
  .scrim { align-items: center; padding: 1.5rem; }
  .sheet {
    max-width: 30rem; border-radius: var(--radius);
    padding-bottom: 1rem; max-height: 86svh;
  }
}
.sheet-head {
  display: flex; align-items: flex-start; gap: .6rem; margin-bottom: .8rem;
}
.sheet-head h3 { font-size: 1.02rem; flex: 1; }
.sheet-head .kind {
  font-size: .66rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--faint);
}
.sheet-head button.close {
  background: none; border: none; color: var(--faint); font-size: 1.2rem;
  cursor: pointer; min-width: 36px; min-height: 36px; line-height: 1;
}
.sheet .figure-big {
  font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; margin: .2rem 0 .1rem;
}
.sheet .rows { display: grid; gap: .35rem; margin: .8rem 0; font-size: .86rem; }
.sheet .rows div { display: flex; gap: .7rem; }
.sheet .rows div span:first-child { color: var(--muted); flex: 1; }
.sheet .rows div span:last-child { font-variant-numeric: tabular-nums; }
.sheet .actions {
  display: grid; gap: .5rem; margin-top: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
}

.field { display: grid; gap: .25rem; margin-bottom: .7rem; }
.field label {
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted);
}
.field .help { font-size: .74rem; color: var(--faint); }
.field.row { grid-template-columns: 1fr 1fr; gap: .6rem; }
.field-error { color: var(--out); font-size: .78rem; }

.toggle {
  display: flex; align-items: flex-start; gap: .6rem; padding: .55rem 0;
  font-size: .88rem; cursor: pointer;
}
.toggle .copy { flex: 1; }
.toggle .copy b { display: block; font-weight: 620; }
.toggle .copy span { color: var(--faint); font-size: .78rem; }

/* --- toasts -------------------------------------------------------------- */

.toasts {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 12px);
  display: grid; gap: .4rem; width: calc(100% - 1.6rem); max-width: 26rem;
  pointer-events: none;
}
@media (min-width: 900px) { .toasts { bottom: 16px; } }
.toast {
  background: var(--raised); border: 1px solid var(--hairline);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: .6rem .75rem;
  font-size: .86rem; box-shadow: var(--shadow);
  animation: rise .16s ease;
}
.toast.error { border-left-color: var(--danger); }
.toast.warn  { border-left-color: var(--bill); }

/* ==========================================================================
   PROFILE PAGE
   ========================================================================== */

.profile-head { display: flex; align-items: center; gap: .9rem; margin-bottom: 1rem; }
.profile-avatar {
  width: 54px; height: 54px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-size: 1.4rem; font-weight: 700;
  border: 1px solid var(--hairline);
}
.profile-head h1 { font-size: 1.15rem; }
.profile-handle { color: var(--muted); font-size: .84rem; margin: .2rem 0 0; }
.profile-handle .dot { color: var(--faint); margin: 0 .2rem; }
.profile-bio { color: var(--text); font-size: .92rem; line-height: 1.6; }
.profile-link { font-size: .88rem; }
.profile-refs { color: var(--muted); font-size: .86rem; }
.profile-stats {
  list-style: none; margin: 1rem 0 .4rem; padding: 0;
  display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
}
.profile-stats li {
  background: var(--raised); border: 1px solid var(--hairline);
  border-radius: var(--radius-sm); padding: .6rem .7rem;
}
.profile-stats b { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.profile-stats span { font-size: .72rem; color: var(--faint); }

/* ==========================================================================
   REFERRALS / SUBSCRIPTION / SETUP
   ========================================================================== */

.funnel {
  display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
}
.funnel-step {
  background: var(--raised); border: 1px solid var(--hairline);
  border-radius: var(--radius-sm); padding: .7rem .75rem;
}
.funnel-step b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.funnel-step span { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
                    color: var(--muted); font-weight: 700; }
.funnel-step em { display: block; font-style: normal; font-size: .74rem;
                  color: var(--faint); margin-top: .2rem; }

.copybox { display: flex; gap: .4rem; align-items: stretch; }
.copybox input {
  font-family: var(--mono); font-size: .82rem; flex: 1; min-width: 0;
}

.price-grid {
  display: grid; gap: var(--gap); grid-template-columns: 1fr;
}
@media (min-width: 620px) { .price-grid { grid-template-columns: 1fr 1fr; } }
.price-card {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 1.1rem;
  display: flex; flex-direction: column;
}
.price-card.featured { border-color: var(--accent); }
.price-card .tier {
  font-size: .7rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted);
}
.price-card .price {
  font-size: 2rem; font-weight: 700; letter-spacing: -.02em; margin: .3rem 0 0;
}
.price-card .per { font-size: .84rem; color: var(--faint); font-weight: 400; }
.price-card ul {
  list-style: none; margin: .9rem 0; padding: 0; display: grid; gap: .35rem;
  font-size: .86rem; flex: 1;
}
.price-card li { display: flex; gap: .45rem; }
.price-card li::before { content: "✓"; color: var(--accent); flex: none; }
.price-card li.no { color: var(--faint); }
.price-card li.no::before { content: "—"; color: var(--faint); }
.save-badge {
  display: inline-block; font-size: .68rem; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--accent); background: var(--accent-soft);
  border-radius: 999px; padding: .15rem .45rem; margin-left: .35rem;
}

.setup-grid { display: grid; gap: var(--gap); }
@media (min-width: 860px) { .setup-grid { grid-template-columns: 1fr 1fr; } }

.kv { display: grid; gap: .3rem; font-size: .86rem; }
.kv > div { display: flex; gap: .7rem; padding: .25rem 0;
            border-bottom: 1px solid var(--hairline); }
.kv > div:last-child { border-bottom: none; }
.kv .k { color: var(--muted); flex: 1; }
.kv .v { font-variant-numeric: tabular-nums; text-align: right; }

.list-rows { display: grid; }
.list-row {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem .85rem; border-top: 1px solid var(--hairline);
}
.list-row:first-child { border-top: none; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .grow b { display: block; font-weight: 620; font-size: .9rem;
                    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .grow span { font-size: .75rem; color: var(--faint); }
.list-row .amount { font-variant-numeric: tabular-nums; font-weight: 650; }

.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
  font-size: .76rem; padding: .25rem .55rem; border-radius: 999px;
  border: 1px solid var(--hairline); background: var(--raised); color: var(--muted);
  cursor: pointer; min-height: 32px; display: inline-flex; align-items: center;
}
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent);
                             background: var(--accent-soft); }

.locked {
  display: grid; place-items: center; gap: .6rem; text-align: center;
  padding: 2.5rem 1rem; color: var(--muted);
}
.locked .lock { font-size: 1.6rem; color: var(--bill); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media print {
  .tabbar, .topbar, .toasts, .btn { display: none !important; }
  body { background: #fff; color: #000; }
  .panel { border-color: #ccc; break-inside: avoid; }
}
