/* Scara · mobile-first design system.
   Colors are tokens; the account's accent and theme are applied as data
   attributes on <html> (CSP forbids inline styles). Sizes are tokens too:
   touch screens get comfortable targets, mouse users a denser layout. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f3f4f3;
  --surface: #ffffff;
  --surface-2: #f6f7f6;
  --line: #e3e7e5;
  --line-2: #d0d6d3;
  --ink: #141a18;
  --ink-2: #48524e;
  --ink-3: #66706b;
  --green: #12703f; --green-bg: #e2f3e9;
  --amber: #875800; --amber-bg: #fcefd2;
  --red: #b42318;   --red-bg: #fde6e3;
  --blue: #1f5fcf;  --blue-bg: #e4ecfc;
  --neutral: #48524e; --neutral-bg: #edf0ee;
  --accent: var(--accent-l);
  --on-accent: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 11%, var(--surface));
  --accent-line: color-mix(in srgb, var(--accent) 38%, var(--surface));
  --ring: color-mix(in srgb, var(--accent) 28%, transparent);
  --scrim: rgba(10, 14, 13, .42);
  --shadow: 0 1px 2px rgba(16, 24, 20, .04);
  --shadow-pop: 0 12px 40px rgba(10, 14, 13, .18);
  --r-sm: 7px; --r: 10px; --r-lg: 13px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2366706b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");

  /* Density: touch defaults. Inputs stay at 16px so iOS does not zoom on focus. */
  --text: 15px;
  --ctl-h: 40px; --ctl-fs: 16px; --ctl-px: 11px;
  --btn-h: 40px; --btn-sm-h: 30px; --btn-fs: 14px;
  --icon-btn: 36px;
  --row-h: 48px; --row-py: 7px; --row-px: 12px;
  --gap: 14px;
  --tabbar: 58px;
  --sidebar: 224px;
}

/* Accent palettes: -l on light surfaces (white text ≥ 4.5:1), -d on dark surfaces. */
:root,
[data-accent="forest"]   { --accent-l: #2b6a52; --accent-d: #72cfa7; }
[data-accent="ocean"]    { --accent-l: #1f5fcf; --accent-d: #8ab6ff; }
[data-accent="indigo"]   { --accent-l: #4b45d4; --accent-d: #aba7ff; }
[data-accent="plum"]     { --accent-l: #7b3fc6; --accent-d: #d0abff; }
[data-accent="rose"]     { --accent-l: #be2551; --accent-d: #ff98b3; }
[data-accent="clay"]     { --accent-l: #a8440e; --accent-d: #ffae7a; }
[data-accent="teal"]     { --accent-l: #0d6f6d; --accent-d: #66d5cd; }
[data-accent="graphite"] { --accent-l: #3d4752; --accent-d: #c5cfda; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1110; --surface: #151a19; --surface-2: #1b2120; --line: #252c2a; --line-2: #343c39;
  --ink: #e8edeb; --ink-2: #b3bcb8; --ink-3: #8c9692;
  --green: #63d39b; --green-bg: rgba(99, 211, 155, .13);
  --amber: #f0c060; --amber-bg: rgba(240, 192, 96, .13);
  --red: #ff8b7b;   --red-bg: rgba(255, 139, 123, .13);
  --blue: #8ab6ff;  --blue-bg: rgba(138, 182, 255, .13);
  --neutral: #b3bcb8; --neutral-bg: #232a28;
  --accent: var(--accent-d); --on-accent: #0b0f0e;
  --scrim: rgba(0, 0, 0, .6);
  --shadow: none; --shadow-pop: 0 16px 48px rgba(0, 0, 0, .5);
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238c9692' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    color-scheme: dark;
    --bg: #0d1110; --surface: #151a19; --surface-2: #1b2120; --line: #252c2a; --line-2: #343c39;
    --ink: #e8edeb; --ink-2: #b3bcb8; --ink-3: #8c9692;
    --green: #63d39b; --green-bg: rgba(99, 211, 155, .13);
    --amber: #f0c060; --amber-bg: rgba(240, 192, 96, .13);
    --red: #ff8b7b;   --red-bg: rgba(255, 139, 123, .13);
    --blue: #8ab6ff;  --blue-bg: rgba(138, 182, 255, .13);
    --neutral: #b3bcb8; --neutral-bg: #232a28;
    --accent: var(--accent-d); --on-accent: #0b0f0e;
    --scrim: rgba(0, 0, 0, .6);
    --shadow: none; --shadow-pop: 0 16px 48px rgba(0, 0, 0, .5);
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238c9692' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  }
  :root[data-theme="auto"] .swatch-dot { background: var(--accent-d); color: #0b0f0e; }
}
:root[data-theme="dark"] .swatch-dot { background: var(--accent-d); color: #0b0f0e; }

/* Mouse and trackpad: denser controls and rows. */
@media (pointer: fine) {
  :root {
    --text: 14px;
    --ctl-h: 34px; --ctl-fs: 14px; --ctl-px: 10px;
    --btn-h: 34px; --btn-sm-h: 28px; --btn-fs: 13.5px;
    --icon-btn: 32px;
    --row-h: 42px; --row-py: 6px;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; font: var(--text)/1.42 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
h1 { font-size: 1.05rem; font-weight: 650; letter-spacing: -.01em; line-height: 1.25; }
h2 { font-size: .95rem; font-weight: 650; }
h3 { font-size: .9rem; font-weight: 650; }
small { font-size: .78rem; }
strong, b { font-weight: 650; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
summary { cursor: pointer; }
button, a, input, select, textarea, summary, label { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
img, svg { display: block; }
.icon { width: 18px; height: 18px; flex: none; }
hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

.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; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--surface); color: var(--ink); padding: 8px 12px; border-radius: var(--r-sm); box-shadow: var(--shadow-pop); }
.skip:focus { top: 12px; }
.muted { color: var(--ink-3); }
.help { display: block; color: var(--ink-3); font-size: .75rem; line-height: 1.4; margin-top: 4px; }
.preline { white-space: pre-line; }
.nowrap { white-space: nowrap; }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 650; }
.amount small, .cur { font-size: .75em; font-weight: 600; color: var(--ink-3); margin-left: 2px; }
.text-red { color: var(--red); }
.text-green { color: var(--green); }
.stack > * + * { margin-top: 10px; }
.spacer { flex: 1; }

/* ---------- App shell ---------- */
.shell { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.has-nav .shell { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
.has-nav.subpage .shell { padding-bottom: 0; }

.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 4px;
  min-height: 52px; padding: 4px 8px 4px 14px; padding-top: max(4px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(14px); backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--line);
}
.appbar-back { margin-left: -8px; }
.appbar-mark { margin-right: 6px; }
.appbar-mark:hover { text-decoration: none; }
.appbar-title { flex: 1; min-width: 0; padding-right: 4px; }
.appbar-title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-title p { font-size: .75rem; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-actions { display: flex; align-items: center; gap: 4px; }
.appbar-brand { font-weight: 760; letter-spacing: -.03em; font-size: 1.2rem; color: var(--ink); }
.brand-dot { color: var(--accent); }

main { flex: 1; width: 100%; max-width: 920px; margin: 0 auto; padding: 12px 14px 24px; }
main > * + *, .columns > * + *, .columns > div > * + *, .dash > * + *, .dash > div > * + * { margin-top: var(--gap); }
.footer { text-align: center; color: var(--ink-3); font-size: .72rem; padding: 4px 16px 16px; }

.demo-banner { font-size: .72rem; color: var(--amber); background: var(--amber-bg); border-radius: var(--r-sm); padding: 4px 10px; }

/* Bottom tab bar (phones and tablets) */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  display: flex; align-items: stretch;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.subpage .tabbar { display: none; }
.tab {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .66rem; font-weight: 600; color: var(--ink-3); background: none; border: 0; padding: 0;
}
.tab:hover { text-decoration: none; color: var(--ink); }
.tab .tab-icon { display: grid; place-items: center; width: 48px; height: 28px; border-radius: 999px; transition: background .15s; }
.tab .icon { width: 21px; height: 21px; }
.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"] .tab-icon { background: var(--accent-soft); }
.tab-new .tab-icon { width: 44px; height: 44px; border-radius: 14px; background: var(--accent); color: var(--on-accent); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
.tab-new .icon { width: 23px; height: 23px; }
.tab-new span:last-child { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Sidebar (desktop) */
.sidebar { display: none; }
.brand { display: inline-flex; align-items: center; gap: 9px; font-size: 1.3rem; font-weight: 760; letter-spacing: -.04em; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--on-accent); }
.brand-mark .icon { width: 17px; height: 17px; }
.nav-group { margin-top: 14px; }
.nav-label { font-size: .66rem; font-weight: 650; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3); padding: 0 10px 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 560; font-size: .85rem; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.sidebar-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); }
.me-link { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 9px; color: var(--ink); font-size: .85rem; }
.me-link:hover { background: var(--surface-2); text-decoration: none; }
.me-link small { display: block; color: var(--ink-3); }
.avatar { display: grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .8rem; }
.avatar.lg { width: 44px; height: 44px; font-size: 1.1rem; }

/* Sheets: native popovers (no JS). Bottom sheet on phones, centered card on desktop. */
.sheet[popover] {
  position: fixed; inset: auto 0 0 0; margin: 0; width: 100%; max-height: 85vh; overflow: auto;
  border: 0; border-radius: 16px 16px 0 0; padding: 6px 8px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop);
}
.sheet[popover]::backdrop { background: var(--scrim); }
.sheet-handle { width: 36px; height: 4px; border-radius: 4px; background: var(--line-2); margin: 4px auto 8px; }
.sheet-title { font-size: .7rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); padding: 4px 12px 6px; }
.sheet-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border-radius: 10px; border: 0; background: none; color: var(--ink); font-weight: 560; font-size: .9rem; text-align: left; }
.sheet-item:hover { background: var(--surface-2); text-decoration: none; }
.sheet-item .icon { color: var(--ink-2); }
.sheet-item small { display: block; font-weight: 400; color: var(--ink-3); }
.sheet-item.danger, .sheet-item.danger .icon { color: var(--red); }
.sheet hr { margin: 4px 12px; }
.sheet form { margin: 0; }
@media (prefers-reduced-motion: no-preference) {
  .sheet[popover]:popover-open { animation: sheet-in .2s ease-out; }
  @keyframes sheet-in { from { transform: translateY(24px); opacity: .4; } }
}

/* ---------- Building blocks ---------- */
.section > * + * { margin-top: 6px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 0 2px; }
.section-title { font-size: .7rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.section-head a, .section-head .text-button { font-size: .8rem; font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.card.pad { padding: 12px 14px; }
.card > .card-pad { padding: 10px 14px; }
.card > .card-pad + .card-pad { padding-top: 0; }

/* Rows: the main list primitive. */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 10px; min-height: var(--row-h); padding: var(--row-py) var(--row-px); color: var(--ink); }
a.row:hover, .row-link:hover { background: var(--surface-2); text-decoration: none; }
a.row::after, .row-link::after { content: ""; flex: none; width: 12px; height: 12px; margin-right: -2px; background: var(--chevron) center / 12px no-repeat; transform: rotate(-90deg); opacity: .7; }
label.row-link { cursor: pointer; }
label.row-link::after { content: none; }
.row-split { display: flex; align-items: stretch; }
.row-split > .row-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: var(--row-h); padding: var(--row-py) 4px var(--row-py) var(--row-px); color: var(--ink); }
.row-split > .row-aside { display: flex; align-items: center; padding-right: 8px; }
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; font-weight: 600; font-size: .9rem; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { display: block; font-size: .76rem; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta.wrap, .row-title.wrap { white-space: normal; }
.row-title .badge { vertical-align: 1px; margin-left: 4px; }
.row-end { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: none; text-align: right; }
.row-end .amount { font-size: .9rem; }
.lead { display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); font-weight: 700; font-size: .78rem; font-variant-numeric: tabular-nums; }
.lead.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.lead .icon { width: 16px; height: 16px; }
.list .empty-row { padding: 14px 16px; color: var(--ink-3); text-align: center; font-size: .85rem; }
.list li > * + .disclosure { border-top: 1px solid var(--line); }
.list li > * + .disclosure > summary { padding: 6px var(--row-px); font-size: .76rem; color: var(--ink-3); }
.list .row-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 var(--row-px) 10px; }
.list-head { display: none; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 999px; font-size: .68rem; font-weight: 650; line-height: 1.55; white-space: nowrap; background: var(--neutral-bg); color: var(--neutral); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* Buttons */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--btn-h); padding: 0 14px; border-radius: 9px; border: 1px solid transparent;
  background: var(--accent); color: var(--on-accent); font-weight: 620; font-size: var(--btn-fs); line-height: 1.2; text-align: center; white-space: nowrap;
  transition: filter .15s, background .15s;
}
.button:hover { text-decoration: none; filter: brightness(1.06); }
.button:active { filter: brightness(.95); }
.button.secondary { background: var(--accent-soft); color: var(--accent); }
.button.ghost { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.button.danger { background: var(--red-bg); color: var(--red); }
.button.danger.solid { background: var(--red); color: #fff; }
.button.small { min-height: var(--btn-sm-h); padding: 0 10px; border-radius: 8px; font-size: .78rem; }
.button.full { width: 100%; }
.button .icon { width: 16px; height: 16px; }
.button:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.icon-button { display: inline-grid; place-items: center; flex: none; width: var(--icon-btn); height: var(--icon-btn); border-radius: 9px; border: 0; background: none; color: var(--ink-2); }
.icon-button:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.icon-button.filled { background: var(--accent-soft); color: var(--accent); }
.icon-button.solid { background: var(--accent); color: var(--on-accent); }
.icon-button .icon { width: 19px; height: 19px; }
.text-button { border: 0; background: none; padding: 2px 0; color: var(--accent); font-weight: 600; font-size: .8rem; }
.text-button:disabled { color: var(--ink-3); cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.actions.end { justify-content: flex-end; }
.actions > form { margin: 0; }
.actions .button { flex: 1 1 auto; }
.inline-form { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; margin-top: 8px; }
.inline-form .field { flex: 1 1 150px; margin: 0; }

/* Hero balance */
.hero { position: relative; overflow: hidden; border-radius: 16px; padding: 14px 16px; background: var(--accent); color: var(--on-accent); }
.hero::after { content: ""; position: absolute; right: -40px; top: -60px; width: 160px; height: 160px; border-radius: 50%; background: currentColor; opacity: .07; pointer-events: none; }
.hero-label { font-size: .75rem; font-weight: 600; opacity: .86; }
.hero-amount { margin-top: 1px; font-size: 1.85rem; font-weight: 720; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.hero-amount + .hero-amount { font-size: 1.25rem; }
.hero-amount .cur { color: inherit; opacity: .75; font-size: .5em; margin-left: 4px; }
.hero-meta { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .76rem; opacity: .92; }
.hero-meta strong { font-weight: 700; }
.hero .button { background: var(--on-accent); color: var(--accent); }
.hero .actions { margin-top: 10px; }
.hero-pill { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; background: color-mix(in srgb, var(--on-accent) 18%, transparent); font-weight: 650; }
.hero-pill .icon { width: 14px; height: 14px; }
.card .hero-amount { font-size: 1.6rem; }

/* Stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 8px 12px; box-shadow: var(--shadow); min-width: 0; color: var(--ink); }
a.stat:hover { text-decoration: none; border-color: var(--accent-line); }
.stat .stat-label, .stat .stat-value { display: block; }
.stat .stat-label { font-size: .7rem; color: var(--ink-3); font-weight: 600; }
.stat .stat-value { font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--line); }
.metric-grid > div { background: var(--surface); padding: 7px 12px; min-width: 0; }
.metric-grid dt { font-size: .7rem; color: var(--ink-3); font-weight: 600; }
.metric-grid dd { font-weight: 700; font-size: .92rem; font-variant-numeric: tabular-nums; }
.metric-grid dd.strong { font-size: 1rem; }
.metrics-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.metrics-head strong { font-size: .78rem; letter-spacing: .04em; }

/* Segmented control and filter chips */
.seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: 9px; background: var(--neutral-bg); }
.seg a, .seg button, .seg label { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 7px; border: 0; background: none; color: var(--ink-2); font-size: .8rem; font-weight: 600; white-space: nowrap; }
.seg a:hover { text-decoration: none; color: var(--ink); }
.seg .active, .seg [aria-current="page"], .seg label:has(input:checked) { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin-left: -14px; margin-right: -14px; padding: 1px 14px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 4px; padding: 4px 11px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); font-size: .78rem; font-weight: 600; white-space: nowrap; }
.chip:hover { text-decoration: none; color: var(--ink); }
.chip .icon { width: 14px; height: 14px; }
.chip.active, .chip[aria-current="page"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }

/* Toolbar: search + filter toggle */
.toolbar { display: flex; gap: 6px; align-items: center; }
.toolbar .search { flex: 1; position: relative; }
.toolbar .search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; width: 16px; height: 16px; }
.toolbar .search input { padding-left: 32px; }
.toolbar .icon-button { width: var(--ctl-h); height: var(--ctl-h); }
.filters-panel { padding: 8px 12px 4px; }

/* Period navigation */
.period-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.period-nav .actions { flex-wrap: nowrap; }
.stepper { display: flex; flex: 1 1 auto; justify-content: space-between; align-items: center; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 2px; max-width: 260px; }
.stepper .icon-button { width: 30px; height: 30px; border-radius: 8px; }
.stepper-label { min-width: 0; text-align: center; font-weight: 650; font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Disclosure */
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.disclosure > summary, .more > summary { display: flex; align-items: center; gap: 8px; padding: 9px 12px; font-weight: 600; font-size: .8rem; color: var(--ink-2); }
.disclosure > summary::after, .more > summary::after { content: ""; margin-left: auto; width: 14px; height: 14px; background: var(--chevron) center / 14px no-repeat; transition: transform .15s; }
.disclosure[open] > summary::after, .more[open] > summary::after { transform: rotate(180deg); }
.disclosure > summary .icon { width: 16px; height: 16px; }
.disclosure > summary .badge { margin-left: 2px; }
.disclosure-body { padding: 0 12px 10px; }
.disclosure > summary.row { gap: 10px; padding: var(--row-py) var(--row-px); font-size: inherit; font-weight: inherit; color: inherit; }
.disclosure > summary.row::after { margin-left: 0; }
.list > .disclosure + .disclosure, .card > .disclosure + .disclosure, .card > * + .disclosure { border-top: 1px solid var(--line); }
.hint > summary { display: inline-flex; align-items: center; gap: 5px; font-size: .76rem; color: var(--ink-3); font-weight: 600; padding: 2px; }
.hint > summary .icon { width: 14px; height: 14px; }
.hint[open] > summary { color: var(--ink-2); }
.hint-body { margin-top: 6px; padding: 8px 12px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line); font-size: .78rem; color: var(--ink-2); }
.hint-body > * + * { margin-top: 6px; }

/* Notices and messages */
.notice { padding: 8px 12px; border-radius: var(--r); background: var(--blue-bg); color: var(--ink); font-size: .8rem; border: 1px solid transparent; }
.notice > * + * { margin-top: 4px; }
.notice.success { background: var(--green-bg); }
.notice.error { background: var(--red-bg); }
.notice.warning { background: var(--amber-bg); }
.notice a { font-weight: 600; }
.messages > * + * { margin-top: 6px; }
.notice .errorlist { color: var(--red); }

.empty { text-align: center; padding: 22px 16px; color: var(--ink-3); font-size: .85rem; }
.empty .lead { margin: 0 auto 8px; width: 40px; height: 40px; border-radius: 12px; }
.empty strong { display: block; color: var(--ink); margin-bottom: 2px; }

/* ---------- Forms ---------- */
.form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 12px 14px; box-shadow: var(--shadow); }
.form > * + * { margin-top: 10px; }
.form > :is(input[type=hidden], .sr-only) + * { margin-top: 0; }

/* Field grid. Phones: two columns, short fields pair up. Wider: as many ~190px
   columns as fit. Subgrid keeps labels, inputs and help text on shared rows,
   so a wrapped label never pushes its neighbour's input out of line. */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 10px; row-gap: 0; align-items: start; }
.form-grid > .field { grid-column: 1 / -1; padding-bottom: 10px; }
.form-grid > .field.span-1 { grid-column: auto; }
.form-grid > .field:is(.span-1, .span-2):not(.checkbox-field) { display: grid; grid-template-rows: subgrid; grid-row: span 3; padding-bottom: 0; }
.form-grid > .field:is(.span-1, .span-2):not(.checkbox-field) > .field-foot { padding-bottom: 10px; }
.form-grid > .field.wide { grid-column: 1 / -1; }
.form-grid:last-child > .field:last-child, .form-grid:last-child > .field:last-child > .field-foot { padding-bottom: 0; }
.field, .field > .control { min-width: 0; }
.control > input, .control > select { min-width: 0; max-width: 100%; }
input[type=date], input[type=month] { -webkit-appearance: none; appearance: none; }
.field > label, .field > .label, fieldset legend, .filters-panel label > span, .item-fields label, .apartment-inputs label {
  display: block; margin-bottom: 4px; font-size: .74rem; font-weight: 650; color: var(--ink-2); line-height: 1.3;
}
.field + .field { margin-top: 10px; }
.form-grid > .field + .field { margin-top: 0; }
.field-foot:empty { display: none; }
.field-foot > .actions { margin-top: 4px; gap: 12px; }
:where(input:not([type=checkbox], [type=radio], [type=file], [type=hidden])), :where(select, textarea), .select-trigger {
  width: 100%; min-height: var(--ctl-h); padding: 4px var(--ctl-px); border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink); font-size: var(--ctl-fs); line-height: 1.3; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 72px; padding-top: 7px; padding-bottom: 7px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--ink-3); opacity: .85; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .select-trigger:focus-visible,
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); outline: none; border-radius: 8px; }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--ink-3); }
:where(select) { appearance: none; -webkit-appearance: none; padding-right: 30px; background: var(--surface) var(--chevron) right 9px center / 14px no-repeat; text-overflow: ellipsis; }
select[multiple] { background-image: none; padding-right: 10px; min-height: 110px; }
input[type=checkbox], input[type=radio] { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); flex: none; }
input[type=file] { width: 100%; padding: 8px; border: 1px dashed var(--line-2); border-radius: 8px; background: var(--surface-2); font-size: .82rem; }
.errorlist { margin-top: 4px; color: var(--red); font-size: .75rem; font-weight: 600; }
.field:has(.errorlist) input, .field:has(.errorlist) select, .field:has(.errorlist) textarea { border-color: var(--red); }
.checkbox-field > label, label.check { display: flex; align-items: flex-start; gap: 8px; font-weight: 550; font-size: .85rem; color: var(--ink); margin: 0; }
.checkbox-field > label input, label.check input { margin-top: 1px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }
legend:has(.actions) { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; width: 100%; }
legend .actions { display: inline-flex; flex: none; gap: 10px; }
legend .text-button { font-size: .74rem; padding: 0; }
.form > fieldset + fieldset { margin-top: 14px; }
.field-hint > summary { display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; font-size: .74rem; font-weight: 600; color: var(--ink-3); }
.field-hint > summary .icon { width: 13px; height: 13px; }
.field-hint p { margin-top: 4px; font-size: .75rem; color: var(--ink-3); }

/* Checkbox lists (Django CheckboxSelectMultiple / RadioSelect) as toggle chips */
.field div[id]:has(> div > label > input) { display: flex; flex-wrap: wrap; gap: 6px; }
.field div[id] > div > label:has(> input) {
  display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 4px 10px 4px 8px; min-height: 32px;
  border: 1px solid var(--line-2); border-radius: 999px; background: var(--surface); font-size: .8rem; font-weight: 560; color: var(--ink-2);
}
.field div[id] > div > label:has(> input:checked) { border-color: var(--accent-line); background: var(--accent-soft); color: var(--ink); }
.field div[id] > div > label > input { width: 15px; height: 15px; }

/* Form actions; on phones the main button stays in reach at the bottom. */
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-actions .button { flex: 1 1 auto; }
.sticky-actions {
  position: sticky; bottom: 0; z-index: 15; margin: 14px -14px -24px; padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.form > .sticky-actions { margin: 12px -14px -12px; border-radius: 0 0 var(--r-lg) var(--r-lg); }

/* Themed select (fine pointers only; phones keep the native picker) */
.select-shell { position: relative; }
.select-native { position: absolute !important; opacity: 0; pointer-events: none; inset: 0; width: 100%; height: 100%; }
.select-trigger { display: block; text-align: left; padding-right: 30px; background: var(--surface) var(--chevron) right 9px center / 14px no-repeat; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.select-trigger[aria-expanded="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.select-trigger:disabled { background-color: var(--surface-2); color: var(--ink-3); cursor: not-allowed; }
.select-menu { position: fixed; z-index: 60; margin: 0; padding: 4px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); inset: auto; }
.select-menu[hidden] { display: none; }
.select-menu [role=option] { display: block; width: 100%; padding: 6px 9px; border: 0; border-radius: 6px; background: none; text-align: left; font-size: .85rem; color: var(--ink); }
.select-menu [role=option].focused, .select-menu [role=option]:hover { background: var(--surface-2); }
.select-menu [role=option][aria-selected="true"] { color: var(--accent); font-weight: 650; background: var(--accent-soft); }
.select-menu [role=option]:disabled { color: var(--ink-3); }
.select-validation { display: block; margin-top: 4px; color: var(--red); font-size: .75rem; font-weight: 600; }

/* Accent swatches and theme picker */
.swatches { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.swatch { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: .7rem; font-weight: 600; color: var(--ink-2); cursor: pointer; text-align: center; }
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch-dot { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-l); color: #fff; }
.swatch-dot .icon { width: 15px; height: 15px; opacity: 0; transition: opacity .12s; }
.swatch:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px var(--ring); color: var(--ink); }
.swatch:has(input:checked) .swatch-dot .icon { opacity: 1; }
.swatch:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.save-state { font-size: .75rem; color: var(--green); font-weight: 600; min-height: 1.2em; }
.profile { display: flex; align-items: center; gap: 10px; }
.logout-row { width: 100%; border: 0; background: none; text-align: left; }
.logout-row .row-title, .logout-row .lead { color: var(--red); }
.logout-row:hover { background: var(--red-bg); }

/* Tables (kept for genuinely tabular data) */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th { text-align: left; font-size: .66rem; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); padding: 7px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); }
td { padding: 6px 12px; border-top: 1px solid var(--line); vertical-align: top; }
tbody tr:first-child td { border-top: 0; }
td small { display: block; color: var(--ink-3); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: .8rem; color: var(--ink-3); }

/* ---------- Domain pieces ---------- */
.bill { padding: 8px var(--row-px); }
.bill-head { display: flex; align-items: flex-start; gap: 8px; justify-content: space-between; }
.bill-head a, .bill-head b { font-weight: 600; font-size: .9rem; color: var(--ink); }
.bill-figures { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-top: 4px; font-size: .76rem; color: var(--ink-3); }
.bill-figures b { color: var(--ink); font-variant-numeric: tabular-nums; }
.bill .mini { margin-top: 4px; }
.bill .mini > summary { font-size: .76rem; font-weight: 600; color: var(--accent); display: inline-flex; }
.bill .mini p { font-size: .76rem; color: var(--ink-2); margin-top: 2px; }
.bill .link-action { display: inline-block; margin-top: 4px; font-size: .76rem; font-weight: 600; }
.overdue { color: var(--red); font-weight: 600; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: .82rem; }
.kv dt { color: var(--ink-3); }
.kv dd { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }

.split-line { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: .82rem; }
.split-line + .split-line { border-top: 1px dashed var(--line); }
.split-line small { display: block; color: var(--ink-3); }

.publish-bar { display: flex; align-items: center; gap: 10px; }
.publish-bar p { font-size: .75rem; color: var(--ink-3); }
.notice.publish-bar > * { margin-top: 0; }

/* Expense item editors */
.item-row { border: 1px solid var(--line); border-radius: var(--r); padding: 10px; background: var(--surface-2); }
.item-row + .item-row { margin-top: 8px; }
.item-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-size: .85rem; }
.item-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.item-fields label { margin: 0; }
.item-fields label input, .item-fields label select { margin-top: 4px; }
.apartment-inputs { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; margin-top: 8px; }
.apartment-inputs label { margin: 0; color: var(--ink-3); }
.apartment-inputs input { margin-top: 3px; text-align: center; }
.remove-item { border: 0; background: none; color: var(--red); font-weight: 600; font-size: .76rem; }
.live-preview { font-size: .8rem; padding: 8px 12px; border-radius: var(--r); background: var(--accent-soft); color: var(--ink); }
.review-panel { border: 1px solid var(--accent-line); border-radius: var(--r-lg); padding: 12px 14px; background: var(--accent-soft); font-size: .85rem; }
.review-panel > * + * { margin-top: 6px; }
.review-panel .split-line + .split-line { border-top-color: var(--accent-line); }

dialog { border: 0; border-radius: var(--r-lg); padding: 14px 16px; width: min(420px, calc(100% - 24px)); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); }
dialog::backdrop { background: var(--scrim); }
dialog form > * + * { margin-top: 10px; }

/* Standalone pages (login, family PIN, errors) */
.standalone .appbar { background: transparent; border: 0; -webkit-backdrop-filter: none; backdrop-filter: none; }
.auth { width: 100%; max-width: 380px; margin: 3vh auto 0; }
.auth > * + * { margin-top: 12px; }
.auth-head h1 { font-size: 1.45rem; letter-spacing: -.02em; }
.auth-head p { color: var(--ink-3); margin-top: 2px; font-size: .85rem; }
.auth .form { padding: 16px; }
.auth .form .button.full { margin-top: 4px; }
.auth-links { text-align: center; font-size: .82rem; }
.auth-links p + p { margin-top: 4px; }

/* Compact tiles (apartments in Configurare) */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.tile { display: flex; flex-direction: column; padding: 6px 10px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); color: var(--ink); }
.tile:hover { text-decoration: none; border-color: var(--accent-line); }
.tile strong { font-size: 1rem; font-variant-numeric: tabular-nums; }
.tile small { color: var(--ink-3); font-size: .7rem; }
section[id], details[id] { scroll-margin-top: 64px; }

/* Responsive helpers: phone-only and desktop-only content. */
.d-only { display: none !important; }

/* ---------- Larger screens ---------- */
@media (min-width: 560px) {
  .swatches { grid-template-columns: repeat(8, minmax(0, 1fr)); }
}
@media (min-width: 720px) {
  main { padding: 16px 20px 32px; }
  .appbar { padding-left: 20px; padding-right: 12px; }
  .chips { margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; flex-wrap: wrap; }
  .form-grid { grid-template-columns: repeat(auto-fill, minmax(min(190px, calc(50% - 5px)), 1fr)); column-gap: 12px; }
  .form-grid > .field.span-2 { grid-column: span 2; }
  .metric-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sticky-actions { margin-left: -20px; margin-right: -20px; margin-bottom: -32px; padding-left: 20px; padding-right: 20px; }
  .sticky-actions .button, .actions .button { flex: 0 0 auto; }
  .hero-amount { font-size: 2.1rem; }
}
@media (min-width: 1024px) {
  .has-nav .shell { margin-left: var(--sidebar); padding-bottom: 0; }
  main { max-width: none; margin: 0; padding: 16px 24px 32px; }
  .standalone main { max-width: 1400px; margin: 0 auto; }
  .appbar { min-height: 56px; padding-left: 24px; }
  .sticky-actions { margin-left: -24px; margin-right: -24px; padding-left: 24px; padding-right: 24px; }
  .tabbar { display: none; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 25; width: var(--sidebar);
    display: flex; flex-direction: column; padding: 14px 10px 10px;
    background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto;
  }
  .sidebar .brand { padding: 2px 8px 4px; }
  .sidebar .button { margin: 12px 0 0; }
  h1 { font-size: 1.2rem; }
  .sheet[popover] { inset: 0; margin: auto; width: 340px; height: fit-content; max-height: 80vh; border-radius: 14px; padding: 6px; }
  .sheet-handle { display: none; }
  .m-only { display: none !important; }
  .d-only { display: block !important; }

  /* Two-panel pages; dashboards use up to three columns. */
  .columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
  .columns > * + * { margin-top: 0; }
  .dash { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
  .dash > * + * { margin-top: 0; }
  .dash > .col-b { grid-column: 2; grid-row: 1 / span 2; }
  .dash > .col-c { grid-column: 1; }

  /* Lists become tables: the same rows, laid out on shared columns. */
  .table .row, .table .row-link, .table .list-head .head-cells, .table > .list-head:not(:has(.head-cells)) {
    display: grid; grid-template-columns: var(--cols); column-gap: 16px; align-items: center;
  }
  .table .row-end { display: contents; }
  .table .row-end .amount, .table .cell.num, .table .num { text-align: right; justify-self: stretch; }
  .table .badge { justify-self: start; }
  .table .cell { min-width: 0; font-size: .82rem; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .table .cell.num { font-variant-numeric: tabular-nums; }
  .table > .list-head { display: block; padding: 6px 4px 6px var(--row-px); background: var(--surface-2); font-size: .66rem; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); }
  .table > .list-head:not(:has(.head-cells)) { display: grid; padding-right: var(--row-px); }
  .table > .list-head:has(.head-cells) { display: flex; align-items: center; padding-right: 0; }
  .table > .list-head .head-cells { flex: 1; padding-right: 4px; }
  .table > .list-head .row-aside .icon-button { visibility: hidden; height: 0; }
  .cols-expenses { --cols: minmax(0, 3fr) minmax(0, 1.1fr) minmax(0, .8fr) minmax(90px, .9fr) minmax(90px, .9fr) minmax(112px, 1fr) 12px; }
  .cols-payments { --cols: 32px minmax(0, 1.4fr) minmax(0, .8fr) minmax(0, .9fr) minmax(0, 2fr) minmax(100px, 1fr) 12px; }
  .cols-apartments { --cols: 32px minmax(0, 1.6fr) repeat(5, minmax(76px, 1fr)) minmax(118px, 1fr) 12px; }
  .table .lead { justify-self: start; }

  .bill { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 24px; align-items: center; }
  .bill > * { grid-column: 1; }
  .bill > .bill-figures { grid-column: 2; grid-row: 1 / span 3; margin: 0; display: grid; grid-template-columns: repeat(3, 100px); text-align: right; }
  .bill > .bill-figures span { display: flex; flex-direction: column; }
  .bill > .bill-figures b { font-size: .85rem; }
  .bill-head { justify-content: flex-start; }
}
@media (min-width: 1440px) {
  .dash { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dash > .col-b { grid-column: 2; grid-row: auto; }
  .dash > .col-c { grid-column: 3; grid-row: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

@media print {
  .tabbar, .sidebar, .appbar-actions, .sticky-actions, .skip { display: none !important; }
  .has-nav .shell { margin: 0; padding: 0; }
  body { background: #fff; }
}
