/* ---------------------------------------------------------------------------
   Bokhald stylesheet.

   Plain CSS, no build step and no framework: what you read here is exactly
   what the browser gets. Every colour, size, radius, shadow and duration is a
   token in :root below, and DESIGN.md at the project root says why each one
   is what it is. Change the look there, not in a component.

   Order: tokens, base, layout, components, pages, assistant, motion, hover,
   breakpoints, then reduced motion and print.
   --------------------------------------------------------------------------- */

:root {
  color-scheme: light;

  /* Neutrals: cool and faintly green, to sit with the teal. */
  --bg: #f5f7f7;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --track: #e9efec;
  --border: #e3e9e7;
  --border-strong: #c8d4d0;
  --border-control: #869693;       /* 3:1 on white: inputs must be findable */
  --text: #192e31;
  --text-muted: #5a6b6e;           /* >= 4.5:1 on every surface and tint */
  --text-faint: #657679;

  /* The signature, and its ink on a tint. */
  --brand: #087f72;
  --brand-dark: #06665c;
  --brand-light: #e7f4ef;
  --brand-line: #cfe5da;
  --on-brand: #ffffff;

  /* Status: semantic only. */
  --ok: #16714c;
  --ok-bg: #e8f4ed;
  --warn: #8b5b10;
  --warn-bg: #fcf3df;
  --bad: #b03f3c;
  --bad-bg: #fcedea;

  /* The dark sidebar, and the launcher and marks that share its plane. */
  --side-bg: #122b2b;
  --side-hover: #203e38;
  --side-active: #294d40;
  --side-chip: #3d5d50;
  --side-line: #35504b;
  --side-text: #c1d1cb;
  --side-text-strong: #eef6f1;
  --side-text-muted: #a8beb6;
  --side-active-text: #e3f4ea;
  --side-accent: #87d8b5;
  --scrim: rgba(16, 43, 43, .5);

  /* The invoice is paper: the neutral ink of the PDF, not the app's teal,
     wherever its totals appear. */
  --paper-ink: #16202b;
  --paper-line: #dfe3e8;
  --paper-muted: #5d6b7a;

  /* Chart series, validated as a pair (see DESIGN.md). */
  --chart-income: #008a7d;
  --chart-expense: #6262ad;

  /* Type. */
  --sans: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --text-2xs: 11px;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 15px;
  --text-lg: 17px;
  --text-xl: 20px;
  --text-2xl: 28px;

  /* Space: 4px base. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Shape. */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  /* Elevation: a shadow means "this floats". Cards have none. */
  --shadow-raised: 0 1px 3px rgba(18, 43, 43, .1);
  --shadow-lift: 0 12px 40px rgba(18, 43, 43, .07), 0 2px 6px rgba(18, 43, 43, .04);
  --shadow-sticky: 0 -4px 14px rgba(18, 43, 43, .04);
  --shadow-float: 0 12px 30px rgba(18, 43, 43, .26), 0 2px 6px rgba(18, 43, 43, .16);
  --shadow-overlay: 0 28px 70px rgba(16, 40, 38, .24), 0 4px 14px rgba(16, 40, 38, .08);
  --shadow-drawer: 10px 0 50px rgba(7, 29, 36, .25);
  --focus-halo: 0 0 0 3px rgba(8, 127, 114, .18);

  /* Motion. */
  --dur-press: 90ms;
  --dur-fast: 150ms;
  --dur: 200ms;
  --dur-slow: 280ms;
  --dur-data: 420ms;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-in: cubic-bezier(.55, 0, 1, .45);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
}

/* ----------------------------------------------------------------- base -- */

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--sans);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}

::selection { background: var(--brand-line); color: var(--text); }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
a, button, summary, select, input[type=file] { -webkit-tap-highlight-color: transparent; }
a, button, summary, select, input[type=checkbox], input[type=radio] { cursor: pointer; }

/* Links inside sentences are underlined: teal against body text is 2.9:1,
   too close for colour alone to say "this is a link". */
:where(p, li, dd, .help, .alert, .note, .empty, .assist-md) a:not(.btn) {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
  transition: text-decoration-color var(--dur-fast) var(--ease-out);
}
:where(p, li, dd, .help, .alert, .note, .empty, .assist-md) a:not(.btn):hover { text-decoration-color: currentColor; }

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 600; text-wrap: balance; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; letter-spacing: -.25px; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; text-wrap: pretty; }
img { max-width: 100%; }

:focus-visible { outline: 3px solid var(--brand); outline-offset: 3px; }
.sidebar :focus-visible { outline-color: var(--side-accent); }

/* --------------------------------------------------------------- layout -- */

.shell { display: flex; min-height: 100dvh; }

.sidebar {
  width: 238px; flex: 0 0 238px; background: var(--side-bg); color: var(--side-text);
  display: flex; flex-direction: column; position: sticky; top: 0;
  height: 100dvh; overflow-y: auto; padding: var(--space-6) 14px 0; scrollbar-width: thin;
  scrollbar-color: var(--side-line) transparent; z-index: 60;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 0 var(--space-3) var(--space-6); color: var(--side-text-strong); }
.sidebar .brand:hover { text-decoration: none; }
.brand-mark { width: 34px; height: 38px; color: var(--side-text-strong); font-size: 38px; line-height: 1; letter-spacing: -5px; font-weight: 650; }
.brand-mark span { color: var(--side-accent); }
.brand-name { font-weight: 650; font-size: var(--text-xl); letter-spacing: -.7px; }
.brand-sub { font-size: var(--text-2xs); letter-spacing: .02em; color: var(--side-text-muted); }
.workspace-name { display: flex; align-items: center; gap: 10px; margin: 0 var(--space-1) var(--space-5); padding: var(--space-3) 10px; border: 1px solid var(--side-line); border-radius: var(--radius-sm); }
.workspace-avatar { display: grid; place-items: center; width: 30px; height: 30px; flex: 0 0 30px; border-radius: var(--radius-xs); background: var(--side-chip); color: var(--side-text-strong); font-weight: 600; }
.workspace-name div { min-width: 0; }
.workspace-name strong { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: var(--text-xs); font-weight: 600; color: var(--side-text-strong); }
.workspace-name span:not(.workspace-avatar) { display: block; font-size: var(--text-2xs); color: var(--side-text-muted); margin-top: 1px; }
.nav-group { padding-bottom: var(--space-4); }
.nav-label { font-size: var(--text-2xs); letter-spacing: .08em; text-transform: uppercase; font-weight: 600; color: var(--side-text-muted); padding: 0 var(--space-3) var(--space-2); }
.nav a {
  display: flex; align-items: center; gap: 11px; min-height: 44px; margin: 2px 0; padding: 9px var(--space-3);
  border-radius: var(--radius-sm); font-size: var(--text-sm); color: var(--side-text);
  transition: color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
.nav a:hover { text-decoration: none; }
.nav a:active { background: var(--side-hover); }
.nav a.active { background: var(--side-active); color: var(--side-active-text); font-weight: 600; }
.nav a.active .ui-icon { color: var(--side-accent); }
.nav .nav-count { margin-left: auto; padding: 1px 6px; border-radius: var(--radius-xs); background: var(--side-chip); color: var(--side-text-strong); font-size: var(--text-2xs); font-variant-numeric: tabular-nums; }
.sidebar-bottom { margin-top: auto; }
.sidebar-foot { display: flex; gap: 9px; align-items: center; border-top: 1px solid var(--side-line); margin: 14px -1px 0; padding: var(--space-4) 5px; }
.account-avatar { display: grid; place-items: center; width: 31px; height: 31px; border-radius: 50%; background: var(--side-active-text); color: var(--side-bg); flex: 0 0 31px; font-size: var(--text-xs); font-weight: 650; }
.sidebar-foot .who { min-width: 0; flex: 1; }
.sidebar-foot .who strong { font-size: var(--text-xs); color: var(--side-text-strong); display: block; }
.sidebar-foot .who span { display: block; font-size: var(--text-2xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--side-text-muted); }
.sidebar-foot form { margin: 0; }
.sidebar-foot .icon-button { color: var(--side-text-muted); }
.sidebar-foot .icon-button:active { background: var(--side-hover); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 15px; min-height: 70px; padding: var(--space-3) var(--space-8); border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar .spacer { flex: 1; }
.breadcrumb { display: flex; align-items: center; gap: var(--space-3); min-width: 0; color: var(--text-muted); font-size: var(--text-xs); }
.breadcrumb h1 { margin: 0; color: var(--text); font-size: var(--text-sm); line-height: 1.4; font-weight: 600; }
.breadcrumb-separator { color: var(--border-control); }
.topbar-year { border: 1px solid var(--border); border-radius: var(--radius-xs); padding: var(--space-1) 10px; font-size: var(--text-2xs); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.content { padding: 28px var(--space-8) var(--space-8); max-width: 1600px; width: 100%; margin: 0 auto; }

.ui-icon { width: 19px; height: 19px; flex: 0 0 19px; display: inline-block; vertical-align: middle; }
.icon-button {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0;
  background: transparent; border: 0; border-radius: var(--radius-sm); color: var(--text-muted); cursor: pointer;
  transition: color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.icon-button:active { transform: scale(.92); background: var(--surface-2); }
.mobile-menu { display: none; }
.skip-link {
  position: fixed; top: var(--space-2); left: var(--space-2); z-index: 100; padding: var(--space-3) 18px;
  background: var(--surface); border: 2px solid var(--brand); border-radius: var(--radius-sm);
  transform: translateY(-150%); transition: transform var(--dur) var(--ease-out);
}
.skip-link:focus { transform: none; }

.page-intro { display: flex; align-items: center; justify-content: space-between; gap: var(--space-5); margin-bottom: var(--space-6); }
.page-intro h2 { font-size: var(--text-2xl); font-weight: 650; letter-spacing: -1px; margin-bottom: 5px; }
.page-intro p { font-size: var(--text-sm); color: var(--text-muted); margin: 0; max-width: 65ch; }
/* .page-intro .eyebrow outranks .page-intro p, for eyebrows written as <p>. */
.eyebrow, .page-intro .eyebrow { font-size: var(--text-2xs); font-weight: 650; text-transform: uppercase; letter-spacing: .1em; color: var(--brand); margin-bottom: 7px; }
.page-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

.route-tabs, .section-tabs { display: flex; align-items: center; gap: 5px; margin-bottom: var(--space-6); overflow-x: auto; scrollbar-width: thin; }
.route-tabs { border-bottom: 1px solid var(--border); gap: var(--space-6); padding: 0; }
.route-tabs a {
  color: var(--text-muted); padding: 0 2px 13px; min-height: 44px; display: inline-flex; align-items: center;
  border-bottom: 2px solid transparent; font-size: var(--text-sm); white-space: nowrap;
  transition: color var(--dur-fast) var(--ease-out), border-color var(--dur) var(--ease-out);
}
.route-tabs a:hover { text-decoration: none; }
.route-tabs a.active { border-color: var(--brand); color: var(--brand); font-weight: 650; }
/* A segmented control: the track is recessed, the chosen segment lifts. */
.section-tabs { background: var(--track); padding: var(--space-1); border-radius: calc(var(--radius-xs) + 4px); width: fit-content; max-width: 100%; }
.section-tabs a, .section-tabs button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 40px; white-space: nowrap;
  padding: var(--space-2) 17px; color: var(--text-muted); border-radius: var(--radius-xs);
  font: 600 var(--text-sm) var(--sans); border: 0; background: transparent; cursor: pointer;
  transition: color var(--dur-fast) var(--ease-out), background-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
.section-tabs a:hover { text-decoration: none; }
.section-tabs [aria-selected="true"], .section-tabs .active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-raised); }
[data-tab-panel]:focus:not(:focus-visible) { outline: none; }
[data-tab-panel][hidden] { display: none !important; }
[data-passkey-ui][hidden] { display: none !important; }

.workspace-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: var(--space-5); align-items: start; }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-4); margin-bottom: var(--space-6); }
.grid { display: grid; gap: var(--space-5); align-items: start; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid > *, .workspace-grid > *, .summary-grid > * { min-width: 0; }
.grid > .card, .workspace-grid > .card { margin-bottom: 0; }

/* ---------------------------------------------------------------- cards -- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--space-5);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-3);
  min-height: 58px; padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.card-head h2 { margin: 0; font-size: var(--text-md); font-weight: 600; }
.card-head .spacer { flex: 1; }
.card-body { padding: var(--space-5); }
.card-body.tight { padding: 0; }
.card-body > .disclosure:last-child { margin-bottom: 0; }

/* ------------------------------------------------------------ key stats -- */

.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px var(--space-5); min-width: 0;
}
.stat .label { font-size: var(--text-2xs); font-weight: 500; color: var(--text-muted); margin-bottom: 10px; }
.stat .value {
  font-size: clamp(22px, 2.2vw, var(--text-2xl)); font-weight: 600; letter-spacing: -1px; line-height: 1.25;
  font-variant-numeric: tabular-nums;
}
.stat .value small { font-size: var(--text-2xs); font-weight: 500; letter-spacing: 0; color: var(--text-faint); margin-left: .2rem; }
.stat .hint { font-size: var(--text-2xs); color: var(--text-muted); margin-top: 9px; }
.stat.good .value { color: var(--ok); }
.stat.bad .value { color: var(--bad); }
/* The one figure on the page that must be found. */
.stat.brand { background: var(--brand-light); border-color: var(--brand-line); }
.stat.brand .value { color: var(--brand-dark); }
a.stat { display: block; color: inherit; text-decoration: none; transition: border-color var(--dur-fast) var(--ease-out), transform var(--dur-press) var(--ease-out); }
a.stat:active { transform: scale(.99); }

/* --------------------------------------------------------------- tables -- */

.table-wrap { overflow-x: auto; max-width: 100%; scrollbar-width: thin; }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
th, td { padding: 10px var(--space-4); text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  font-size: var(--text-2xs); color: var(--text-faint); font-weight: 600; background: var(--surface-2);
  white-space: nowrap; position: sticky; top: 0;
}
tbody tr { transition: background-color var(--dur-fast) var(--ease-out); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.num { font-weight: 500; }
td.mono, .mono { font-family: var(--mono); font-size: .84em; }
tfoot td { font-weight: 600; background: var(--surface-2); border-top: 2px solid var(--border-strong); }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions form { display: inline; }
.row-actions .btn + .btn { margin-left: var(--space-1); }

.empty { padding: 36px var(--space-5); text-align: center; color: var(--text-muted); font-size: var(--text-sm); }
.empty .big { font-size: 1.6rem; margin-bottom: .4rem; color: var(--text-faint); }
.empty .big .ui-icon { width: 28px; height: 28px; }

.table-pagination {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border); background: var(--surface);
  font-size: var(--text-xs); color: var(--text-muted);
}
.table-pagination > div { display: flex; align-items: center; gap: var(--space-2); }
.table-pagination > div:first-child { display: block; }
.table-pagination[hidden] { display: none !important; }
.table-page-summary { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.table-pagination .table-page-note { margin: 3px 0 0; font-size: var(--text-2xs); }
[data-page-hidden] { display: none !important; }

/* --------------------------------------------------------------- badges -- */

.badge {
  display: inline-block; padding: 3px var(--space-2); border-radius: var(--radius-pill);
  font-size: var(--text-2xs); font-weight: 600; line-height: 1.45; white-space: nowrap;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.brand { background: var(--brand-light); color: var(--brand-dark); border-color: transparent; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 9px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-family: inherit; font-size: var(--text-sm); font-weight: 600; line-height: 1.3;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.btn:hover { text-decoration: none; }
.btn:not([disabled]):active { transform: scale(.98); background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); box-shadow: var(--shadow-raised); }
.btn.primary:not([disabled]):active { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.danger:not([disabled]):active { background: var(--bad-bg); }
.btn.link { min-height: 44px; border-color: transparent; background: transparent; color: var(--brand); padding: var(--space-1) var(--space-2); }
.btn.small { min-height: 44px; padding: 7px var(--space-3); font-size: var(--text-xs); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn .ui-icon { width: 16px; height: 16px; flex-basis: 16px; }
.btn-row { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------------- forms -- */

.field { margin-bottom: var(--space-4); min-width: 0; }
.field label, .label {
  display: block; font-size: var(--text-xs); font-weight: 600;
  margin-bottom: 6px; color: var(--text);
}
.field .help, .help { font-size: var(--text-xs); line-height: 1.6; color: var(--text-muted); margin-top: 6px; }

input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], input[type=url], select, textarea {
  width: 100%; max-width: 100%; min-height: 44px; padding: 10px var(--space-3);
  border: 1px solid var(--border-control); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); caret-color: var(--brand);
  font-family: inherit; font-size: var(--text-sm);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
/* The transparent outline is what forced-colours mode draws instead of the halo. */
input:focus, select:focus, textarea:focus {
  outline: 2px solid transparent; outline-offset: 2px; border-color: var(--brand); box-shadow: var(--focus-halo);
}
input:user-invalid, select:user-invalid, textarea:user-invalid { border-color: var(--bad); }
input:user-invalid:focus, select:user-invalid:focus, textarea:user-invalid:focus { box-shadow: 0 0 0 3px rgba(176, 63, 60, .16); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-faint); border-color: var(--border-strong); cursor: not-allowed; }
::placeholder { color: var(--text-faint); opacity: 1; }
input[type=file] { width: 100%; max-width: 100%; font-size: var(--text-xs); min-height: 44px; }
input[type=file]::file-selector-button {
  border: 1px solid var(--border-control); border-radius: var(--radius-sm); padding: 10px var(--space-3);
  background: var(--surface); font-family: inherit; font-weight: 600; color: var(--text); cursor: pointer; margin-right: 10px;
  transition: background-color var(--dur-fast) var(--ease-out);
}
input[type=checkbox], input[type=radio] { accent-color: var(--brand); }
textarea { min-height: 80px; resize: vertical; }

.field-row { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: start; }

.check { display: flex; align-items: flex-start; gap: var(--space-2); margin-bottom: 10px; min-height: 30px; }
.check input { margin-top: var(--space-1); flex: 0 0 auto; width: auto; }
.check label { font-weight: 500; margin: 0; font-size: var(--text-sm); }

.radio-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.radio-row label {
  min-height: 44px;
  display: flex; align-items: center; gap: 6px;
  padding: 6px var(--space-3); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); cursor: pointer; font-weight: 500; font-size: var(--text-sm);
  margin: 0;
  transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.radio-row input { width: auto; }
.radio-row label:has(input:checked) { border-color: var(--brand); background: var(--brand-light); color: var(--brand-dark); }

.filters {
  display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: flex-end;
  padding: var(--space-4) var(--space-5); background: var(--surface); border-bottom: 1px solid var(--border);
}
.filters .field { margin: 0; }
.filters input, .filters select { min-width: 140px; }
.filters .btn { min-height: 44px; }
.filters > .field { flex: 0 1 160px; }
.filters > .field:has(input[type=search]), .filters > .field:has(input[name=q]) { flex: 1 1 200px; }

.form-actions {
  position: sticky; bottom: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 14px 18px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow-sticky); margin-top: var(--space-4);
}
.form-actions > input { align-self: center; }

.disclosure {
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
  padding: var(--space-3) var(--space-4); margin-bottom: var(--space-4); color: var(--text-muted); font-size: var(--text-xs);
}
.disclosure > summary { color: var(--text); font-weight: 600; min-height: 24px; line-height: 24px; transition: color var(--dur-fast) var(--ease-out); }
.disclosure[open] > summary { margin-bottom: 14px; }
.disclosure > :last-child { margin-bottom: 0; }
.disclosure-chevron { transition: transform var(--dur) var(--ease-out); }
details[open] > summary .disclosure-chevron { transform: rotate(180deg); }

/* ------------------------------------------------------------- messages -- */

.alert {
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm);
  margin-bottom: var(--space-4); font-size: var(--text-sm); border: 1px solid transparent;
}
.alert.success { background: var(--ok-bg); color: var(--ok); }
.alert.error { background: var(--bad-bg); color: var(--bad); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.info { background: var(--brand-light); color: var(--brand-dark); }
.alert a:not(.btn) { color: inherit; }
.alert ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.alert > .disclosure { background: transparent; color: inherit; border: 0; padding: 0; margin: 0; }
.alert > .disclosure > summary { color: inherit; margin: 0; }

.note {
  background: var(--surface-2); border-left: 3px solid var(--brand);
  padding: 10px 14px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: var(--text-xs); color: var(--text-muted); margin-bottom: var(--space-4);
}
.note strong { color: var(--text); }
.note.warn { background: var(--warn-bg); border-left-color: var(--warn); }

/* ------------------------------------------------------------ deadlines -- */

.deadline {
  display: flex; gap: 14px; align-items: center;
  padding: 14px var(--space-5); border-bottom: 1px solid var(--border);
}
.deadline:last-child { border-bottom: none; }
.deadline .when {
  flex: 0 0 42px; text-align: center; border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px; background: var(--surface-2);
}
.deadline .when .day { font-size: var(--text-lg); font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.deadline .when .mon { font-size: var(--text-2xs); text-transform: uppercase; color: var(--text-faint); margin-top: 3px; }
.deadline .what { flex: 1; min-width: 0; }
.deadline .what .t { font-weight: 600; font-size: var(--text-sm); }
.deadline .what .t a { color: var(--text); }
.deadline .what .d { font-size: var(--text-2xs); color: var(--text-muted); margin-top: 3px; }
.deadline .side { text-align: right; white-space: nowrap; }
.deadline.is-overdue .when { background: var(--bad-bg); }
.deadline.is-overdue .when .day { color: var(--bad); }
.deadline.is-soon .when { background: var(--warn-bg); }
.deadline.is-soon .when .day { color: var(--warn); }
.deadline.is-done { opacity: .55; }
.deadline.is-done .what .t { text-decoration: line-through; }

/* ---------------------------------------------------------------- chart -- */

.chart { display: flex; align-items: flex-end; gap: 9px; height: 180px; padding: 0 .25rem; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .25rem; height: 100%; }
.chart .bars {
  display: flex; gap: 4px; align-items: flex-end; height: 100%; width: 100%; justify-content: center;
  background: repeating-linear-gradient(to top, transparent 0, transparent calc(25% - 1px), var(--border) calc(25% - 1px), var(--border) 25%);
}
.chart .bar { width: 45%; max-width: 16px; min-height: 2px; border-radius: 4px 4px 0 0; }
.chart .bar.inc, .swatch.inc { background: var(--chart-income); }
.chart .bar.exp, .swatch.exp { background: var(--chart-expense); }
.chart .lab { font-size: var(--text-2xs); color: var(--text-faint); padding-top: var(--space-2); }
.legend { display: flex; gap: var(--space-4); font-size: var(--text-2xs); color: var(--text-muted); margin-top: 14px; }
.legend span { display: flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* ---------------------------------------------------------------- meter -- */

.meter { height: 8px; background: var(--track); border-radius: var(--radius-pill); overflow: hidden; margin: var(--space-2) 0 6px; }
.meter .fill { height: 100%; max-width: 100%; background: var(--brand); border-radius: var(--radius-pill); }
.meter .fill.warn { background: var(--warn); }
.meter .fill.bad { background: var(--bad); }

/* A figure set larger than the text around it. */
.figure { font-size: var(--text-xl); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ auth page -- */

.auth-page {
  min-height: 100vh; display: grid; place-items: center; position: relative;
  padding: 2rem 1rem; background: var(--bg);
}
.auth-box {
  width: 100%; max-width: 430px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift); padding: 36px;
}
.auth-box.wide { max-width: 560px; }
.auth-box h1 { text-align: center; margin-bottom: 6px; font-size: var(--text-2xl); letter-spacing: -1px; }
.auth-box .sub { text-align: center; color: var(--text-muted); font-size: var(--text-sm); margin-bottom: var(--space-6); }
.auth-box .btn { width: 100%; }
.auth-logo {
  width: 48px; height: 48px; border-radius: var(--radius); background: var(--side-bg);
  color: var(--on-brand); display: grid; place-items: center; font-weight: 700;
  font-size: 1.15rem; margin: 0 auto var(--space-4);
}
.code-input {
  font-family: var(--mono); font-size: 1.5rem; letter-spacing: .4em;
  text-align: center; padding: .6rem;
}
.qr-box { text-align: center; padding: var(--space-4); background: var(--surface); border-radius: var(--radius-sm); margin-bottom: var(--space-4); }
.qr-box img { display: block; margin: 0 auto; }
.secret {
  font-family: var(--mono); font-size: .82rem; word-break: break-all;
  background: var(--surface-2); padding: 10px; border-radius: var(--radius-sm);
  text-align: center; border: 1px dashed var(--border-strong);
}
.codes-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-2);
  font-family: var(--mono); font-size: .95rem; margin: var(--space-4) 0;
}
.codes-grid div {
  padding: 7px; background: var(--surface-2); border-radius: var(--radius-sm);
  text-align: center; border: 1px solid var(--border);
}

.steps { counter-reset: step; list-style: none; padding: 0; margin: 0 0 var(--space-4); }
.steps li {
  counter-increment: step; position: relative; padding-left: 2.1rem;
  margin-bottom: 13px; font-size: var(--text-sm);
}
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 0;
  width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--brand-light); color: var(--brand-dark);
  display: grid; place-items: center; font-size: .75rem; font-weight: 700;
}

/* ---------------------------------------------------------------- guide -- */

.guide { max-width: 1100px; }
.guide h2 {
  margin-top: 18px; padding-bottom: 6px; border-bottom: 2px solid var(--border);
  font-size: var(--text-xl);
}
.guide h3 { margin-top: 1.4rem; color: var(--brand-dark); font-size: var(--text-base); }
.guide p, .guide li { font-size: var(--text-sm); max-width: 80ch; }
.guide ul, .guide ol { margin: 0 0 var(--space-4); padding-left: 1.3rem; }
.guide li { margin-bottom: 6px; }
.guide .fo { color: var(--text-faint); font-style: italic; }
.guide .section-tabs { max-width: 100%; }
.guide-article { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-6); max-width: 850px; line-height: 1.7; }
.guide-article > h2:first-child { margin-top: 0; }
.toc { background: var(--surface-2); border-radius: var(--radius-sm); padding: var(--space-4) var(--space-4) var(--space-4) 2.2rem; }
.toc li { margin-bottom: var(--space-1); }

dl.facts { margin: 0; }
dl.facts div {
  display: flex; gap: var(--space-4); padding: var(--space-2) 0; border-bottom: 1px solid var(--border);
}
dl.facts div:last-child { border-bottom: none; }
dl.facts dt { flex: 0 0 42%; font-weight: 600; font-size: var(--text-sm); margin: 0; }
dl.facts dd { flex: 1; margin: 0; font-size: var(--text-sm); color: var(--text-muted); }

/* -------------------------------------------------------------- invoice -- */
/* The invoice is a sheet of paper (--paper-* in :root), so the screen shows
   what the customer will get. */

.invoice-paper {
  background: #fff; color: var(--paper-ink); padding: 2.5rem;
  max-width: 800px; margin: 0 auto; border-radius: var(--radius); border: 1px solid var(--border);
}
.invoice-head { display: flex; justify-content: space-between; gap: 2rem; margin-bottom: 2rem; }
.invoice-head .who { font-size: .85rem; line-height: 1.6; }
.invoice-head h1 { font-size: 1.8rem; margin-bottom: .25rem; }
.invoice-meta { text-align: right; font-size: .85rem; line-height: 1.7; }
.invoice-parties { display: flex; justify-content: space-between; gap: 2rem; margin-bottom: 1.5rem; }
.invoice-total-row { display: flex; justify-content: flex-end; margin-top: 1rem; }
.invoice-totals { min-width: 280px; font-size: .9rem; font-variant-numeric: tabular-nums; }
.invoice-totals div { display: flex; justify-content: space-between; padding: .35rem 0; }
.invoice-totals div.grand {
  border-top: 2px solid var(--paper-ink); margin-top: .3rem; padding-top: .5rem;
  font-weight: 700; font-size: 1.05rem;
}
.invoice-foot { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--paper-line); font-size: .8rem; color: var(--paper-muted); }

/* ------------------------------------------------- receipts and review -- */

.snap { max-width: 520px; margin: 0 auto; }
.snap-button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  min-height: 200px; padding: var(--space-6); border: 1.5px dashed var(--border-control); border-radius: var(--radius);
  background: var(--surface-2); cursor: pointer; text-align: center;
  transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.snap-button:hover { text-decoration: none; }
.snap-button:active { transform: scale(.99); border-color: var(--brand); background: var(--brand-light); }
.snap-icon, .snap-icon .ui-icon { width: 36px; height: 36px; font-size: 28px; color: var(--brand); }
.snap-label { font-size: var(--text-lg); font-weight: 650; }
.snap-sub { font-size: var(--text-xs); color: var(--text-muted); }
.install-hint { position: relative; }

.review-item { overflow: hidden; }
.review-summary { padding: var(--space-4) var(--space-5); cursor: pointer; font-size: var(--text-xs); background: var(--surface); }
.review-summary::marker { color: var(--brand); }
.review-item[open] > .review-summary { border-bottom: 1px solid var(--border); }
.review-summary .badge { margin-left: var(--space-2); }
.upload-disclosure > summary { padding: var(--space-4) var(--space-5); min-height: 52px; font-size: var(--text-sm); font-weight: 600; cursor: pointer; }

/* ------------------------------------------------------------ utilities -- */

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: .82rem; }
.tiny { font-size: .74rem; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }
.strong { font-weight: 600; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }
.mb0 { margin-bottom: 0; }
.flex { display: flex; gap: .6rem; align-items: center; }
.flex-between { display: flex; gap: .6rem; align-items: center; justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.hidden { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* Off-canvas pieces that only exist on small screens. */
.tabbar, .nav-scrim, .nav-close { display: none; }

/* ------------------------------------------------------------ hjálparin -- */
/* The chat assistant: a launcher on every page, a panel it opens, and the
   full page at /assistant. The thread markup is shared by both. */

.assist-launcher {
  position: fixed; right: var(--space-6); bottom: var(--space-6); z-index: 45;
  display: inline-flex; align-items: center; gap: 9px; height: 48px; padding: 0 19px 0 15px;
  border-radius: var(--radius-pill); background: var(--side-bg); color: var(--side-text-strong); font: 600 var(--text-sm) var(--sans);
  box-shadow: var(--shadow-float);
  transition: transform var(--dur) var(--ease-out), background-color var(--dur-fast) var(--ease-out), opacity var(--dur) var(--ease-out);
}
.assist-launcher:hover { text-decoration: none; }
.assist-launcher:active { transform: scale(.96); }
.assist-launcher .ui-icon { color: var(--side-accent); }
.assist-is-open .assist-launcher { opacity: 0; transform: scale(.9); pointer-events: none; }

/* Opens with an animation; closes with a transition that holds the panel on
   screen (allow-discrete) until it has faded. Older browsers close it at once. */
.assist-panel {
  position: fixed; right: var(--space-6); bottom: var(--space-6); z-index: 70;
  width: min(440px, calc(100vw - 48px)); height: min(720px, calc(100dvh - 48px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay);
  transform-origin: 100% 100%;
  animation: assist-in var(--dur-slow) var(--ease-out);
  transition: opacity var(--dur) var(--ease-in), transform var(--dur) var(--ease-in), display var(--dur) allow-discrete;
}
.assist-panel[hidden] { display: none; opacity: 0; transform: translateY(8px) scale(.985); }
.assist-panel-head { display: flex; align-items: center; gap: 2px; padding: 10px var(--space-2) 10px 14px; border-bottom: 1px solid var(--border); }
.assist-panel-head form { margin: 0; }
.assist-panel-title { flex: 1; min-width: 0; margin-left: 9px; }
.assist-panel-title h2 { margin: 0; font-size: var(--text-md); letter-spacing: -.2px; }
.assist-panel-title span { display: block; font-size: var(--text-2xs); color: var(--text-muted); }

.assist-avatar, .assist-mark {
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
  background: var(--side-bg); color: var(--side-text-strong); font-weight: 650; letter-spacing: -2px; line-height: 1;
}
.assist-avatar { width: 30px; height: 30px; border-radius: var(--radius-sm); font-size: 18px; padding-right: 2px; }
.assist-mark { width: 54px; height: 54px; border-radius: 15px; font-size: 32px; padding-right: 3px; margin: 0 auto 14px; }
.assist-avatar span, .assist-mark span { color: var(--side-accent); }

.assist-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 18px var(--space-4); background: var(--surface-2); scroll-behavior: smooth; }
.assist-thread { display: flex; flex-direction: column; gap: 14px; }
.assist-loading { padding: 48px 0; text-align: center; color: var(--text-faint); font-size: var(--text-sm); }

.assist-msg.user { align-self: flex-end; max-width: 86%; }
.assist-bubble {
  background: var(--brand); color: var(--on-brand); padding: 9px 14px; border-radius: 17px 17px 5px 17px;
  font-size: var(--text-base); line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere;
}
.assist-msg.bot { display: flex; gap: 10px; align-items: flex-start; }
.assist-body { flex: 1; min-width: 0; }
.assist-steps { display: flex; align-items: center; gap: 5px; margin: 5px 0; font-size: var(--text-2xs); color: var(--text-faint); }
.assist-steps .ui-icon { width: 13px; height: 13px; flex-basis: 13px; }
.assist-md { font-size: var(--text-base); line-height: 1.55; overflow-wrap: anywhere; }
.assist-md > :first-child { margin-top: 3px; }
.assist-md p { margin: 0 0 .6rem; }
.assist-md > :last-child { margin-bottom: 0; }
.assist-md ul, .assist-md ol { margin: .2rem 0 .65rem; padding-left: 1.25rem; }
.assist-md li { margin: .15rem 0; }
.assist-md h4 { font-size: var(--text-base); margin: .75rem 0 .3rem; }
.assist-md code { font-family: var(--mono); font-size: .86em; background: var(--track); padding: 1px 5px; border-radius: 4px; }
.assist-md pre { background: var(--track); padding: 10px var(--space-3); border-radius: var(--radius-sm); overflow-x: auto; }
.assist-md pre code { background: none; padding: 0; }
.assist-md .table-wrap { margin: .35rem 0 .7rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.assist-md table { font-size: var(--text-sm); }
.assist-md th { font-size: var(--text-2xs); position: static; }
.assist-md th, .assist-md td { padding: 6px 10px; }
.assist-md td a { white-space: nowrap; }

.assist-card {
  margin-left: 40px; padding: var(--space-3) 14px; background: var(--surface);
  border: 1px solid var(--border-strong); border-left: 3px solid var(--warn); border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
}
.assist-card.is-done { border-left-color: var(--ok); box-shadow: none; }
.assist-card.is-failed { border-left-color: var(--bad); box-shadow: none; }
.assist-card.is-cancelled { border-left-color: var(--border-strong); box-shadow: none; opacity: .72; }
.assist-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); }
.assist-card-kicker { flex-basis: 100%; font-size: var(--text-2xs); font-weight: 650; text-transform: uppercase; letter-spacing: .1em; color: var(--brand); }
.assist-card-head strong { flex: 1 1 auto; font-size: var(--text-base); }
.assist-fields { margin: 10px 0; display: grid; gap: 1px; }
.assist-fields div { display: flex; justify-content: space-between; gap: 14px; padding: var(--space-1) 0; border-bottom: 1px dashed var(--border); font-size: var(--text-sm); }
.assist-fields div:last-child { border-bottom: 0; }
.assist-fields dt { color: var(--text-muted); }
.assist-fields dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.assist-card-body {
  margin: 0 0 10px; padding: 10px var(--space-3); max-height: 280px; overflow: auto;
  white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: var(--text-sm); line-height: 1.5;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.assist-card-note { margin: 0 0 10px; font-size: var(--text-xs); color: var(--text-muted); }
.assist-card-note.bad { color: var(--bad); margin: 0; }
.assist-card .btn-row form { margin: 0; }
.assist-card .btn .ui-icon { width: 15px; height: 15px; flex-basis: 15px; margin: -2px 2px 0 -2px; }
.assist-card-link { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--text-sm); font-weight: 600; }
.assist-card-link .ui-icon { width: 15px; height: 15px; flex-basis: 15px; transition: transform var(--dur-fast) var(--ease-out); }
.assist-error { margin: 0; }
.assist-reload { margin: 0; text-align: center; font-size: var(--text-xs); }

.assist-welcome, .assist-setup { text-align: center; padding: 26px 6px 6px; }
.assist-welcome h3, .assist-setup h3 { font-size: var(--text-lg); letter-spacing: -.3px; margin-bottom: 6px; }
.assist-welcome p, .assist-setup p { font-size: var(--text-sm); color: var(--text-muted); max-width: 36ch; margin: 0 auto; }
.assist-starters { display: grid; gap: var(--space-2); margin-top: var(--space-5); text-align: left; }
.assist-starters form { margin: 0; }
.assist-chip {
  width: 100%; min-height: 44px; padding: 10px 13px; text-align: left; cursor: pointer;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: 500 var(--text-sm) var(--sans);
  transition: border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.assist-chip:active { transform: scale(.98); border-color: var(--brand); }

.assist-composer { display: flex; align-items: flex-end; gap: var(--space-2); margin: 0; padding: var(--space-3) var(--space-3) 6px; border-top: 1px solid var(--border); background: var(--surface); }
.assist-composer textarea { flex: 1; min-height: 44px; max-height: 160px; resize: none; padding: 11px 14px; border-radius: var(--radius); font-size: var(--text-base); line-height: 1.4; }
.assist-send {
  display: grid; place-items: center; width: 44px; height: 44px; flex: 0 0 44px; cursor: pointer;
  border: 0; border-radius: var(--radius); background: var(--brand); color: var(--on-brand);
  transition: background-color var(--dur-fast) var(--ease-out), opacity var(--dur-fast) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.assist-send:not([disabled]):active { transform: scale(.92); background: var(--brand-dark); }
.assist-send[disabled] { opacity: .4; cursor: not-allowed; }
.assist-disclaimer { margin: 0; padding: 0 var(--space-3) 10px; background: var(--surface); text-align: center; font-size: var(--text-2xs); color: var(--text-faint); }

.assist-dots { display: inline-flex; gap: var(--space-1); padding: 11px 2px; }
.assist-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); animation: assist-dot 1.2s infinite var(--ease-in-out); }
.assist-dots i:nth-child(2) { animation-delay: .15s; }
.assist-dots i:nth-child(3) { animation-delay: .3s; }

.assist-page { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: var(--space-5); align-items: start; }
.assist-page-chat { display: flex; flex-direction: column; height: calc(100dvh - 250px); min-height: 520px; margin: 0; }
.assist-page-chat .assist-scroll { padding: var(--space-6); }
.assist-page-chat .assist-thread { max-width: 780px; margin: 0 auto; }
.assist-page-chat .assist-composer { padding: 14px 18px 6px; }
.assist-page-chat .assist-composer, .assist-page-chat .assist-disclaimer { width: 100%; }
.assist-can { list-style: none; margin: 0; padding: 0; }
.assist-can li { position: relative; padding-left: 28px; margin-bottom: var(--space-3); font-size: var(--text-sm); color: var(--text-muted); }
.assist-can li:last-child { margin-bottom: 0; }
.assist-can li strong { color: var(--text); }
.assist-can li::before {
  position: absolute; left: 0; top: 1px; display: grid; place-items: center; width: 19px; height: 19px;
  border-radius: 50%; font-size: var(--text-2xs); font-weight: 700;
}
.assist-can li.yes::before { content: "✓"; background: var(--ok-bg); color: var(--ok); }
.assist-can li.ask::before { content: "?"; background: var(--warn-bg); color: var(--warn); }
.assist-can li.no::before { content: "×"; background: var(--bad-bg); color: var(--bad); }
/* Earlier chats: in the panel in place of the thread, and in the page's side column. */
.assist-history-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.assist-history-head h3 { margin: 0; font-size: var(--text-md); letter-spacing: -.2px; }
.assist-history-head a { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--text-xs); font-weight: 600; }
.assist-history-head .ui-icon { width: 14px; height: 14px; flex-basis: 14px; }
.assist-history { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.assist-history form { margin: 0; }
.assist-history-item {
  display: grid; gap: 2px; width: 100%; padding: 9px var(--space-3); text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font: inherit;
  transition: border-color var(--dur-fast) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.assist-history-item:active { transform: scale(.99); border-color: var(--brand); }
.assist-history-item.is-current { border-color: var(--brand); box-shadow: inset 3px 0 0 var(--brand); }
.assist-history-title { font-size: var(--text-sm); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.assist-history-meta { font-size: var(--text-2xs); color: var(--text-muted); }
.assist-history-meta strong { color: var(--brand-dark); font-weight: 600; }
.assist-history-empty { margin: 0; font-size: var(--text-sm); color: var(--text-muted); }
.assist-history-card { max-height: 340px; overflow-y: auto; }
.assist-history-card .assist-history-item { background: var(--surface-2); }
.assist-cost { display: grid; gap: 2px; }
.assist-cost span { font-size: var(--text-xs); color: var(--text-muted); }
.assist-cost strong { font-size: var(--text-xl); letter-spacing: -.4px; font-variant-numeric: tabular-nums; }
.assist-cost small { font-size: var(--text-xs); font-weight: 500; color: var(--text-muted); }
.assist-cost a { font-size: var(--text-xs); margin-top: var(--space-1); }

/* --------------------------------------------------------------- motion -- */
/* Motion explains a change of state; a page that is just sitting there does
   not move. Everything here is opacity and transform, so nothing reflows.

   Deliberately no page-to-page crossfade (@view-transition): while one runs,
   clicks land on the transition instead of the page, which costs a
   data-entry tool more than the fade is worth. The browser already holds the
   old page on screen until the new one can paint, so there is no flash. */

@keyframes rise-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes drop-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes grow-up { from { transform: scaleY(0); } to { transform: none; } }
@keyframes grow-right { from { transform: scaleX(0); } to { transform: none; } }
@keyframes assist-in { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes assist-dot { 0%, 70%, 100% { opacity: .35; transform: none; } 35% { opacity: 1; transform: translateY(-3px); } }

/* A tab's panel, and what a disclosure reveals, rise into place. */
[data-tab-panel]:not([hidden]) { animation: rise-in var(--dur) var(--ease-out); }
details[open] > :not(summary) { animation: rise-in var(--dur) var(--ease-out); }

/* The message after a save or a refusal arrives from above, where the eye is. */
.alert.flash { animation: drop-in var(--dur-slow) var(--ease-out) backwards; }

/* Figures grow to their value, left to right like the months they show. */
.chart .bar { transform-origin: 50% 100%; animation: grow-up var(--dur-data) var(--ease-out) backwards; }
.chart .col:nth-child(2) .bar { animation-delay: 16ms; }
.chart .col:nth-child(3) .bar { animation-delay: 32ms; }
.chart .col:nth-child(4) .bar { animation-delay: 48ms; }
.chart .col:nth-child(5) .bar { animation-delay: 64ms; }
.chart .col:nth-child(6) .bar { animation-delay: 80ms; }
.chart .col:nth-child(7) .bar { animation-delay: 96ms; }
.chart .col:nth-child(8) .bar { animation-delay: 112ms; }
.chart .col:nth-child(9) .bar { animation-delay: 128ms; }
.chart .col:nth-child(10) .bar { animation-delay: 144ms; }
.chart .col:nth-child(11) .bar { animation-delay: 160ms; }
.chart .col:nth-child(12) .bar { animation-delay: 176ms; }
.meter .fill { transform-origin: 0 50%; animation: grow-right var(--dur-data) var(--ease-out) 120ms backwards; }

/* The assistant: the question you just sent, the thinking dots, and the
   newest answer (whatever sits last, just before the end marker) arrive;
   the rest of the thread, redrawn on every reply, stays put. */
.assist-msg.user:has(+ .assist-thinking) { animation: rise-in var(--dur) var(--ease-out); }
.assist-thinking { animation: fade-in var(--dur) var(--ease-out) 120ms backwards; }
.assist-thread > :has(+ #assistant-end), .assist-thread > .assist-error { animation: rise-in var(--dur-slow) var(--ease-out); }

/* ---------------------------------------------------------------- hover -- */
/* Only for a real pointer. On a phone a tap would leave these stuck on, so
   touch gets the :active states above instead. */

@media (hover: hover) {
  .nav a:hover { background: var(--side-hover); color: var(--side-text-strong); }
  .nav a.active:hover { background: var(--side-active); color: var(--side-active-text); }
  .sidebar-foot .icon-button:hover { background: var(--side-hover); color: var(--side-text-strong); }
  .icon-button:hover { background: var(--surface-2); color: var(--brand); }
  .route-tabs a:hover, .section-tabs a:hover, .section-tabs button:hover { color: var(--brand); }
  .section-tabs [aria-selected="true"]:hover, .section-tabs .active:hover { color: var(--text); }
  .btn:hover { background: var(--surface-2); border-color: var(--border-control); }
  .btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
  .btn.danger:hover { background: var(--bad-bg); border-color: var(--bad); }
  .btn.link:hover { background: var(--brand-light); border-color: transparent; }
  .btn[disabled]:hover { background: var(--surface); border-color: var(--border-strong); }
  .btn.primary[disabled]:hover { background: var(--brand); border-color: var(--brand); }
  tbody tr:hover { background: var(--surface-2); }
  .assist-md tbody tr:hover { background: transparent; }
  input[type=text]:hover:not(:focus):not(:disabled), input[type=email]:hover:not(:focus):not(:disabled),
  input[type=password]:hover:not(:focus):not(:disabled), input[type=date]:hover:not(:focus):not(:disabled),
  input[type=number]:hover:not(:focus):not(:disabled), input[type=search]:hover:not(:focus):not(:disabled),
  input[type=url]:hover:not(:focus):not(:disabled), select:hover:not(:focus):not(:disabled),
  textarea:hover:not(:focus):not(:disabled) { border-color: var(--text-faint); }
  input[type=file]::file-selector-button:hover { background: var(--surface-2); }
  .radio-row label:hover { border-color: var(--border-control); }
  .radio-row label:has(input:checked):hover { border-color: var(--brand); }
  .disclosure > summary:hover { color: var(--brand); }
  a.stat:hover { border-color: var(--brand-line); text-decoration: none; }
  .snap-button:hover { border-color: var(--brand); background: var(--brand-light); }
  .assist-launcher:hover { background: var(--side-hover); color: var(--on-brand); transform: translateY(-1px); }
  .assist-chip:hover { border-color: var(--brand); color: var(--brand); }
  .assist-send:not([disabled]):hover { background: var(--brand-dark); }
  .assist-history-item:hover { border-color: var(--brand); }
  .assist-card-link:hover .ui-icon { transform: translateX(2px); }
}

/* ---------------------------------------------------------- breakpoints -- */

@media (max-width: 1200px) {
  .sidebar { width: 218px; flex-basis: 218px; padding-left: 10px; padding-right: 10px; }
  .content { padding: var(--space-6); }
  .topbar { padding: var(--space-3) var(--space-6); }
  .stat { padding: var(--space-4); }
  .summary-grid { gap: var(--space-3); }
  .page-intro h2 { font-size: 24px; }
}
@media (max-width: 1000px) {
  .grid.cols-4, .summary-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .workspace-grid { grid-template-columns: 1fr; }
  .page-intro { align-items: flex-start; }
  .page-actions { justify-content: flex-end; }
  .grid.cols-3 { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .assist-page { grid-template-columns: 1fr; }
  .assist-page-side { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .assist-page-side .card { margin: 0; }
  .assist-page-side #assist-history { grid-column: 1 / -1; }
}
@media (max-width: 800px) {
  /* The menu is a drawer: it slides in fast and decelerates, and leaves
     quicker than it came. It opens with no JavaScript, through :target. */
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(86vw,290px); height: 100dvh; transform: translateX(-102%); visibility: hidden; transition: transform var(--dur) var(--ease-in), visibility var(--dur); padding-top: max(24px,env(safe-area-inset-top)); }
  .sidebar:target { transform: none; visibility: visible; box-shadow: var(--shadow-drawer); transition: transform var(--dur-slow) var(--ease-out), visibility var(--dur-slow); }
  .nav-scrim { display: block; position: fixed; z-index: 55; inset: 0; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease-out); }
  .sidebar:target ~ .nav-scrim { opacity: 1; pointer-events: auto; }
  .nav-close { display: grid; place-items: center; position: absolute; right: 10px; top: 13px; width: 44px; height: 44px; color: var(--side-text-strong); }
  .mobile-menu { display: inline-flex; }
  .topbar { padding: var(--space-2) var(--space-4); min-height: 62px; gap: var(--space-2); padding-top: max(8px,env(safe-area-inset-top)); }
  .topbar .breadcrumb > span { display: none; }
  .topbar-help { display: none; }
  .content { padding: 22px var(--space-5) calc(100px + env(safe-area-inset-bottom)); }
  .tabbar { display: grid; grid-template-columns: repeat(5,1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 50; border-top: 1px solid var(--border); background: var(--surface); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { display: flex; position: relative; flex-direction: column; align-items: center; justify-content: center; gap: 5px; min-height: 64px; font-size: var(--text-2xs); color: var(--text-muted); transition: color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out); }
  .tabbar a:hover { text-decoration: none; }
  .tabbar a .ui-icon { transition: transform var(--dur-press) var(--ease-out); }
  .tabbar a:active .ui-icon { transform: scale(.88); }
  .tabbar a.active { color: var(--brand); background: var(--brand-light); font-weight: 600; }
  .tabbar .tdot { position: absolute; top: 10px; right: calc(50% - 15px); width: 7px; height: 7px; background: var(--warn); border-radius: 50%; }
  .form-actions { bottom: calc(66px + env(safe-area-inset-bottom)); }
  .btn.small, .btn.link { min-height: 44px; }
  .assist-launcher { right: var(--space-4); bottom: calc(78px + env(safe-area-inset-bottom)); width: 52px; height: 52px; padding: 0; justify-content: center; }
  .assist-launcher span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  /* Full screen on a phone, so it rises like a sheet rather than growing
     out of the corner. */
  .assist-panel { inset: 0; width: 100%; height: 100dvh; border: 0; border-radius: 0; z-index: 80; padding-top: env(safe-area-inset-top); transform-origin: 50% 100%; }
  .assist-panel[hidden] { transform: translateY(24px); }
  .assist-panel .assist-disclaimer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  html.assist-is-open body { overflow: hidden; }
  .assist-page-chat { height: calc(100dvh - 300px); min-height: 440px; }
  .assist-page-chat .assist-scroll { padding: 18px 14px; }
  .assist-page-side { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  body { font-size: 16px; }
  .content { padding-left: var(--space-4); padding-right: var(--space-4); }
  .topbar-year { padding: var(--space-1) 7px; }
  .page-intro { flex-direction: column; gap: 14px; margin-bottom: var(--space-5); }
  .page-intro h2 { font-size: 24px; }
  .page-intro p { font-size: var(--text-sm); }
  .page-actions { width: 100%; justify-content: flex-start; }
  .page-actions .btn { flex: 1; }
  .section-tabs { gap: 2px; margin-bottom: 18px; }
  .section-tabs a, .section-tabs button { padding: 8px 12px; font-size: var(--text-xs); min-height: 44px; }
  .route-tabs { gap: var(--space-5); margin-bottom: var(--space-5); }
  .route-tabs a { font-size: var(--text-xs); }
  .grid.cols-2, .grid.cols-3, .workspace-grid { grid-template-columns: 1fr; }
  .grid.cols-4, .summary-grid { gap: 10px; }
  .stat { padding: 14px; }
  .stat .value { font-size: 22px; }
  .stat .label { font-size: var(--text-2xs); }
  .stat .hint { font-size: var(--text-xs); line-height: 1.5; }
  .chart .lab, .legend { font-size: var(--text-xs); }
  .check label { min-height: 44px; display: flex; align-items: center; flex: 1; cursor: pointer; }
  .check { align-items: center; }
  .check input { margin-top: 0; }
  .card-head { padding: var(--space-3) var(--space-4); }
  .card-head h2 { flex: 1 1 140px; }
  .card-head .spacer { display: none; }
  .card-body { padding: var(--space-4); }
  .card-body.tight { padding: 0; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], input[type=url], select, textarea { font-size: 16px; }
  .filters { padding: var(--space-4); gap: var(--space-3); }
  .filters > .field { flex: 1 1 120px; }
  .filters input, .filters select { min-width: 0; }
  .filters .btn { flex: 1 1 auto; }
  .btn-row { flex-wrap: wrap; }
  .btn-row .btn { justify-content: center; }
  .check input[type=checkbox], .radio-row input[type=radio] { width: 20px; height: 20px; }
  .deadline { flex-wrap: wrap; padding: 13px var(--space-4); }
  .deadline .side { white-space: normal; padding-left: 56px; }
  dl.facts div { flex-wrap: wrap; gap: var(--space-1); }
  dl.facts dt { flex-basis: 100%; }
  .invoice-paper { padding: var(--space-5); }
  .invoice-head, .invoice-parties { gap: var(--space-5); flex-wrap: wrap; }
  .invoice-meta { text-align: left; }
  .invoice-totals { min-width: 0; width: 100%; }
  .auth-box { padding: 28px 22px; }
  .auth-page { padding: var(--space-6) var(--space-4); }
  .chart { height: 155px; gap: var(--space-1); }
  .form-actions { padding: 10px; }
  .table-stack thead { display: none; }
  .table-stack table, .table-stack tbody, .table-stack tfoot, .table-stack tr { display: block; width: 100%; }
  .table-stack tr { border-bottom: 1px solid var(--border); padding: var(--space-3) var(--space-4); }
  .table-stack td { border: none; padding: var(--space-1) 0; display: flex; gap: var(--space-3); white-space: normal; text-align: left; overflow-wrap: anywhere; }
  .table-stack td[data-label]::before { content: attr(data-label); flex: 0 0 90px; color: var(--text-muted); font-size: var(--text-2xs); font-weight: 500; }
  .table-stack td[data-label=""]::before { display: none; }
  .table-stack .row-actions { flex-wrap: wrap; }
  .table-stack tfoot { background: var(--surface-2); }
  .table-pagination { flex-wrap: wrap; }
  .table-pagination > div { margin-left: auto; }
  .guide { overflow-wrap: anywhere; }
  .guide p, .guide li { font-size: var(--text-base); }
  .guide-article { padding: 18px; }
  .assist-composer textarea { font-size: 16px; }
  .assist-card { margin-left: 0; }
}

/* ----------------------------------------------- reduced motion, print -- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
@media print {
  /* An entrance animation caught mid-way would print a faded or empty panel. */
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .sidebar, .topbar, .no-print, .btn, .tabbar, .nav-scrim, .nav-close, .route-tabs, .section-tabs, .form-actions, .skip-link, .assist-launcher, .assist-panel { display: none !important; }
  [data-tab-panel][hidden] { display: block !important; }
  [data-page-hidden] { display: table-row !important; }
  .table-pagination { display: none !important; }
  .table-wrap { overflow: visible; }
  .table-stack table { display: table; }
  .table-stack thead { display: table-header-group; }
  .table-stack tbody { display: table-row-group; }
  .table-stack tfoot { display: table-footer-group; }
  .table-stack tr { display: table-row; }
  .table-stack td { display: table-cell; }
  .table-stack td::before { display: none; }
  .shell, .main { display: block; }
  body, .invoice-paper { background: #fff; color: #000; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .invoice-paper { box-shadow: none; border: none; padding: 0; max-width: none; }
}
