/* ============================================================================
   Invoicing — design system

   Reference points: a ledger book and a precision instrument. Hairline rules
   instead of drop shadows, tabular figures on every number, dense rows that
   respect an accountant's screen, one confident accent instead of a gradient.
   ========================================================================= */

/* ------------------------------------------------------------------ reset */

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

* { margin: 0; }

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

body {
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img, svg, video, canvas { display: block; max-width: 100%; }

input, button, textarea, select { font: inherit; color: inherit; }

button { background: none; border: none; cursor: pointer; }

a { color: inherit; }

h1, h2, h3, h4 { font-weight: 600; line-height: 1.25; text-wrap: balance; }

/* ----------------------------------------------------------------- tokens */

:root {
  /* Warm paper neutrals — a plain white ground reads as unfinished next to
     the ink and green used elsewhere. */
  --paper:        #fbfaf7;
  --surface:      #ffffff;
  --surface-sunk: #f4f2ed;
  --surface-hover:#f7f5f1;

  --ink:          #1a1917;
  --ink-2:        #4a4741;
  --ink-3:        #7a756c;
  --ink-4:        #a8a299;

  --line:         #e5e1d8;
  --line-strong:  #d2cdc1;

  /* Bottle green: the ledger accent. Reserved for primary actions and the
     active navigation state so it keeps its meaning. */
  --accent:       #0e5240;
  --accent-hover: #0a4133;
  --accent-soft:  #e6efeb;
  --accent-line:  #b9d2c9;

  --positive:     #14663f;
  --positive-soft:#e4f0e9;
  --positive-line:#b5d5c4;

  --warning:      #8a5a09;
  --warning-soft: #fbf1de;
  --warning-line: #e8d3a6;

  --danger:       #93251f;
  --danger-soft:  #f9e9e7;
  --danger-line:  #e6bdb8;

  --neutral:      #5c5850;
  --neutral-soft: #efece6;
  --neutral-line: #dcd7cd;

  --focus:        #0e5240;

  /* Type */
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
             "Helvetica Neue", Arial, sans-serif;
  --font-num: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Mono",
              "Roboto Mono", Menlo, Consolas, monospace;

  --t-11: 0.6875rem;
  --t-12: 0.75rem;
  --t-13: 0.8125rem;
  --t-14: 0.875rem;
  --t-16: 1rem;
  --t-20: 1.25rem;
  --t-26: 1.625rem;
  --t-32: 2rem;

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

  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;

  --sidebar-w: 236px;
  --header-h: 56px;

  --speed: 120ms;
  --ease: cubic-bezier(0.2, 0, 0.1, 1);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --paper:        #131311;
    --surface:      #1a1a17;
    --surface-sunk: #101010;
    --surface-hover:#22221e;

    --ink:          #eceae4;
    --ink-2:        #b8b4ab;
    --ink-3:        #8a857b;
    --ink-4:        #625e56;

    --line:         #2c2b27;
    --line-strong:  #3d3b35;

    --accent:       #4bbf95;
    --accent-hover: #63d0a8;
    --accent-soft:  #15271f;
    --accent-line:  #23473a;

    --positive:     #5ec18d;
    --positive-soft:#152418;
    --positive-line:#25422f;

    --warning:      #d9a441;
    --warning-soft: #29200e;
    --warning-line: #4a3a18;

    --danger:       #e07a70;
    --danger-soft:  #2b1614;
    --danger-line:  #4d2723;

    --neutral:      #9d988e;
    --neutral-soft: #212120;
    --neutral-line: #35342f;

    --focus:        #4bbf95;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --paper:        #131311;
  --surface:      #1a1a17;
  --surface-sunk: #101010;
  --surface-hover:#22221e;

  --ink:          #eceae4;
  --ink-2:        #b8b4ab;
  --ink-3:        #8a857b;
  --ink-4:        #625e56;

  --line:         #2c2b27;
  --line-strong:  #3d3b35;

  --accent:       #4bbf95;
  --accent-hover: #63d0a8;
  --accent-soft:  #15271f;
  --accent-line:  #23473a;

  --positive:     #5ec18d;
  --positive-soft:#152418;
  --positive-line:#25422f;

  --warning:      #d9a441;
  --warning-soft: #29200e;
  --warning-line: #4a3a18;

  --danger:       #e07a70;
  --danger-soft:  #2b1614;
  --danger-line:  #4d2723;

  --neutral:      #9d988e;
  --neutral-soft: #212120;
  --neutral-line: #35342f;

  --focus:        #4bbf95;
}

body {
  font-family: var(--font-ui);
  font-size: var(--t-14);
  background: var(--paper);
  color: var(--ink);
}

/* Every figure in this application is money, a count or a date: align them. */
.num, td.num, th.num, .money {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

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

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

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: var(--header-h);
  padding: 0 var(--s-4);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  text-decoration: none;
}

.brand__mark {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: var(--t-12);
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.brand__name {
  font-weight: 600;
  font-size: var(--t-13);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Organization switcher — an accountant lives in this control. */
.org-switch {
  padding: var(--s-3) var(--s-3) var(--s-2);
  border-bottom: 1px solid var(--line);
}

.org-switch__label {
  font-size: var(--t-11);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-4);
  font-weight: 600;
  padding: 0 var(--s-2) var(--s-1);
}

.nav {
  padding: var(--s-3) var(--s-2);
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
}

.nav__section {
  font-size: var(--t-11);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-4);
  font-weight: 600;
  padding: var(--s-4) var(--s-2) var(--s-1);
}

.nav__item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 7px var(--s-2);
  border-radius: var(--r-sm);
  color: var(--ink-2);
  text-decoration: none;
  font-size: var(--t-13);
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}

.nav__item:hover { background: var(--surface-hover); color: var(--ink); }

.nav__item[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.nav__item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }

.nav__badge {
  margin-left: auto;
  font-size: var(--t-11);
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  background: var(--surface-sunk);
  padding: 1px 6px;
  border-radius: 20px;
}

.nav__item[aria-current="page"] .nav__badge {
  background: var(--surface);
  color: var(--accent);
}

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--s-4);
  height: var(--header-h);
  padding: 0 var(--s-6);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar__title { font-size: var(--t-14); font-weight: 600; }
.topbar__spacer { margin-left: auto; }

.content { padding: var(--s-6); flex: 1; }
.content--narrow { max-width: 860px; }

.page-head {
  display: flex;
  align-items: flex-start;
  gap: var(--s-4);
  margin-bottom: var(--s-6);
  flex-wrap: wrap;
}

.page-head__text { min-width: 0; }

.page-title {
  font-size: var(--t-26);
  letter-spacing: -0.02em;
  font-weight: 650;
}

.page-sub {
  color: var(--ink-3);
  font-size: var(--t-13);
  margin-top: 2px;
}

.page-head__actions {
  margin-left: auto;
  display: flex;
  gap: var(--s-2);
  align-items: center;
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}

.card__head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--line);
}

.card__title { font-size: var(--t-13); font-weight: 600; }
.card__body { padding: var(--s-5); }
.card__foot {
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--line);
  background: var(--surface-sunk);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* --------------------------------------------------------------- KPI tiles */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--s-3);
  margin-bottom: var(--s-6);
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-4) var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  position: relative;
  overflow: hidden;
}

/* A 2px spine carries the semantic colour instead of tinting the whole tile. */
.kpi::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 2px;
  background: var(--kpi-accent, var(--line-strong));
}

.kpi--positive { --kpi-accent: var(--positive); }
.kpi--danger   { --kpi-accent: var(--danger); }
.kpi--warning  { --kpi-accent: var(--warning); }
.kpi--accent   { --kpi-accent: var(--accent); }

.kpi__label {
  font-size: var(--t-11);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  font-weight: 600;
}

.kpi__value {
  font-size: var(--t-26);
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--kpi-value, var(--ink));
}

.kpi--positive .kpi__value { --kpi-value: var(--positive); }
.kpi--danger   .kpi__value { --kpi-value: var(--danger); }

.kpi__meta { font-size: var(--t-12); color: var(--ink-3); }

.kpi__count { display: flex; align-items: baseline; gap: var(--s-2); }

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

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
}

table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--t-13);
}

table.data thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-sunk);
  text-align: left;
  font-size: var(--t-11);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  font-weight: 600;
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

table.data tbody td {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-hover); }

table.data th.num, table.data td.num { text-align: right; }

table.data tfoot td {
  padding: var(--s-3) var(--s-4);
  border-top: 1px solid var(--line-strong);
  font-weight: 600;
  background: var(--surface-sunk);
}

.cell-strong { font-weight: 600; color: var(--ink); }
.cell-muted { color: var(--ink-3); }
.cell-link { color: var(--accent); text-decoration: none; font-weight: 500; }
.cell-link:hover { text-decoration: underline; }

.row-actions { display: flex; gap: var(--s-1); justify-content: flex-end; }

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: var(--t-11);
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  border: 1px solid var(--badge-line, var(--neutral-line));
  background: var(--badge-bg, var(--neutral-soft));
  color: var(--badge-fg, var(--neutral));
}

.badge::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge--paid, .badge--approved, .badge--issued {
  --badge-bg: var(--positive-soft);
  --badge-fg: var(--positive);
  --badge-line: var(--positive-line);
}

.badge--unpaid, .badge--sent, .badge--pending {
  --badge-bg: var(--warning-soft);
  --badge-fg: var(--warning);
  --badge-line: var(--warning-line);
}

.badge--overdue, .badge--rejected, .badge--failed {
  --badge-bg: var(--danger-soft);
  --badge-fg: var(--danger);
  --badge-line: var(--danger-line);
}

.badge--draft, .badge--cancelled, .badge--viewed {
  --badge-bg: var(--neutral-soft);
  --badge-fg: var(--neutral);
  --badge-line: var(--neutral-line);
}

.badge--partially_paid {
  --badge-bg: var(--accent-soft);
  --badge-fg: var(--accent);
  --badge-line: var(--accent-line);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 var(--s-3);
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--t-13);
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  transition: background var(--speed) var(--ease),
              border-color var(--speed) var(--ease),
              color var(--speed) var(--ease);
}

.btn:hover { background: var(--surface-hover); border-color: var(--ink-4); }

.btn[disabled], .btn[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

.btn svg { width: 15px; height: 15px; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 550;
}
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn--primary { color: #0b1a15; }
}
:root[data-theme="dark"] .btn--primary { color: #0b1a15; }

.btn--danger {
  color: var(--danger);
  border-color: var(--danger-line);
  background: var(--danger-soft);
}
.btn--danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover { background: var(--surface-hover); border-color: var(--line); }

.btn--sm { height: 26px; padding: 0 var(--s-2); font-size: var(--t-12); }
.btn--icon { width: 32px; padding: 0; }
.btn--icon.btn--sm { width: 26px; }

.btn-group { display: inline-flex; gap: var(--s-2); }

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

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: var(--s-4); }

.field__label {
  font-size: var(--t-12);
  font-weight: 600;
  color: var(--ink-2);
}

.field__req { color: var(--danger); margin-left: 2px; }

/* The counterpart, for a field whose emptiness means something. */
.field__opt { font-weight: 400; color: var(--ink-4); }

/* A long list of things to tick: one per line, quiet rules between them. */
.check-list { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow-y: auto; }

/* The switcher becomes a way in to the chooser once a dropdown cannot cope. */
.org-switch__all { width: 100%; justify-content: flex-start; }
.check-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 6px 2px;
  border-bottom: 1px solid var(--line);
}
.check-row:last-child { border-bottom: 0; }
.check-row > .small { margin-left: auto; }
.check { display: flex; align-items: center; gap: var(--s-2); cursor: pointer; min-width: 0; }
.check input[disabled] + span { color: var(--ink-3); }

/* A quantity and what it counts, side by side in one cell. */
.qty-cell { display: flex; gap: 4px; align-items: center; }
.qty-cell .input { min-width: 0; flex: 1 1 auto; }
.qty-cell .select { flex: 0 0 auto; width: auto; max-width: 11ch; }

.field__hint { font-size: var(--t-12); color: var(--ink-3); }

.field__error {
  font-size: var(--t-12);
  color: var(--danger);
  display: flex;
  align-items: center;
  gap: 5px;
}

.input, .select, .textarea {
  height: 34px;
  padding: 0 var(--s-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--t-13);
  width: 100%;
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}

.textarea { height: auto; padding: var(--s-2) var(--s-3); min-height: 76px; resize: vertical; line-height: 1.5; }

.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-4); }

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--danger); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--danger-soft); }

.input::placeholder { color: var(--ink-4); }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%237a756c' stroke-width='1.6' stroke-linecap='round'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
  padding-right: 30px;
}

.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: 0; }
.input-group > :first-child { border-radius: var(--r-md) 0 0 var(--r-md); }
.input-group > :last-child { border-radius: 0 var(--r-md) var(--r-md) 0; }

.input-affix {
  display: grid;
  place-items: center;
  padding: 0 var(--s-3);
  border: 1px solid var(--line-strong);
  background: var(--surface-sunk);
  color: var(--ink-3);
  font-size: var(--t-13);
}
.input-group .input:not(:first-child) { border-left: 0; }
.input-group .input-affix:not(:first-child) { border-left: 0; }

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--s-4);
}

.checkbox, .radio {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--t-13);
  cursor: pointer;
}

.checkbox input, .radio input {
  width: 15px; height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

fieldset { border: 0; padding: 0; }

legend {
  font-size: var(--t-11);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  font-weight: 600;
  padding-bottom: var(--s-2);
}

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

.alert {
  display: flex;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  border: 1px solid var(--alert-line, var(--line));
  background: var(--alert-bg, var(--surface-sunk));
  color: var(--alert-fg, var(--ink-2));
  font-size: var(--t-13);
  margin-bottom: var(--s-4);
}

.alert--error   { --alert-bg: var(--danger-soft);   --alert-fg: var(--danger);   --alert-line: var(--danger-line); }
.alert--success { --alert-bg: var(--positive-soft); --alert-fg: var(--positive); --alert-line: var(--positive-line); }
.alert--warning { --alert-bg: var(--warning-soft);  --alert-fg: var(--warning);  --alert-line: var(--warning-line); }
.alert--info    { --alert-bg: var(--accent-soft);   --alert-fg: var(--accent);   --alert-line: var(--accent-line); }

.alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.alert strong { font-weight: 600; }

.empty { padding: var(--s-12) var(--s-6); text-align: center; color: var(--ink-3); }
.empty__title { font-size: var(--t-14); font-weight: 600; color: var(--ink-2); margin-bottom: var(--s-1); }
.empty__text { font-size: var(--t-13); max-width: 42ch; margin: 0 auto var(--s-4); }

/* --------------------------------------------------------------- toolbar */

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--surface-sunk);
}

.toolbar + .table-wrap { border-radius: 0 0 var(--r-lg) var(--r-lg); }

.search { position: relative; flex: 1; min-width: 180px; max-width: 320px; }

.search .input { padding-left: 30px; height: 30px; }

.search svg {
  position: absolute;
  left: 9px; top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  color: var(--ink-4);
  pointer-events: none;
}

.seg {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
}

.seg__btn {
  padding: 3px var(--s-3);
  border-radius: var(--r-sm);
  font-size: var(--t-12);
  font-weight: 500;
  color: var(--ink-3);
  text-decoration: none;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}

.seg__btn:hover { color: var(--ink); }

.seg__btn[aria-selected="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* ------------------------------------------------------------- pagination */

.pager {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  font-size: var(--t-12);
  color: var(--ink-3);
  border-top: 1px solid var(--line);
}

.pager__spacer { margin-left: auto; }

/* ---------------------------------------------------- document line editor */

.lines { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--t-13); }

.lines th {
  text-align: left;
  font-size: var(--t-11);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  font-weight: 600;
  padding: 0 var(--s-2) var(--s-2);
}

.lines th.num { text-align: right; }

.lines td { padding: 3px var(--s-1); vertical-align: top; }
.lines td:first-child { padding-left: 0; }
.lines td .input, .lines td .select { height: 30px; font-size: var(--t-13); }
.lines td .input.num { text-align: right; }

.lines__drag {
  width: 22px;
  color: var(--ink-4);
  cursor: grab;
  text-align: center;
  padding-top: 9px;
}

.totals {
  margin-left: auto;
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  font-size: var(--t-13);
}

.totals__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-1) 0;
}

.totals__label { color: var(--ink-2); }
.totals__value { font-variant-numeric: tabular-nums; font-weight: 500; }

.totals__row--grand {
  border-top: 1px solid var(--line-strong);
  margin-top: var(--s-2);
  padding-top: var(--s-3);
  font-size: var(--t-16);
  font-weight: 650;
}

.totals__row--grand .totals__value { color: var(--accent); }

/* ------------------------------------------------------------------ misc */

.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.row { display: flex; align-items: center; gap: var(--s-3); }
.row--wrap { flex-wrap: wrap; }
.spacer { margin-left: auto; }
.muted { color: var(--ink-3); }
.small { font-size: var(--t-12); }
.mono { font-family: var(--font-num); font-size: 0.95em; }
.nowrap { white-space: nowrap; }
.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;
}

hr.sep { border: 0; border-top: 1px solid var(--line); margin: var(--s-5) 0; }

/* Utilities.
   These exist because the Content-Security-Policy carries no 'unsafe-inline'
   for styles, so a style="" attribute in a template is blocked outright. That
   is the right trade — the same directive is what makes an injected <style> or
   handler inert — but it means spacing tweaks live here rather than in markup. */

.m-0 { margin: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: var(--s-2); }
.mb-3 { margin-bottom: var(--s-3); }
.mb-4 { margin-bottom: var(--s-4); }
.mb-6 { margin-bottom: var(--s-6); }
.mt-2 { margin-top: var(--s-2); }
.mt-3 { margin-top: var(--s-3); }
.mt-6 { margin-top: var(--s-6); }

.gap-2 { gap: var(--s-2); }
.items-start { align-items: flex-start; }
.text-right { text-align: right; }

/* A table or card nested inside another surface, which should not draw its
   own frame. */
.flush { border: 0 !important; }

.totals-col { min-width: 300px; flex: 1; }
.field-narrow { max-width: 200px; }
.panel-narrow { max-width: 420px; }

/* A block of machine-readable text shown for inspection. It scrolls inside
   its own frame so a long document cannot widen the page. */
.code-block {
  margin: 0;
  padding: var(--s-3);
  max-height: 60vh;
  overflow: auto;
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-family: var(--font-num, ui-monospace, monospace);
  font-size: var(--t-12);
  line-height: 1.5;
  white-space: pre;
  tab-size: 2;
}

/* A settings screen puts the list and its editor side by side on a wide
   viewport, and stacks them once there is no room for both. */
.col-grow { flex: 1 1 460px; min-width: 0; }

/* The language chooser sits in the top bar and should read as a control, not
   as a form field: no frame until it is reached for. */
.lang-switch { display: inline-flex; }

.select--bare {
  border-color: transparent;
  background-color: transparent;
  padding-inline: var(--s-2);
  padding-right: 28px;
  min-width: 0;
  width: auto;
}

.select--bare:hover { border-color: var(--line); }
.select--bare:focus-visible { border-color: var(--accent); }

/* The acceptance mark. Sized in one place so the page, the print sheet and
   the preview all show it at the same scale. */
.stamp-block {
  flex: 0 0 auto;
  width: 150px;
  max-width: 40vw;
}

.stamp-block svg { width: 100%; height: auto; display: block; }

/* A proportion bar inside a table row. Kept deliberately plain: it is there
   to make the ranking scannable, not to be a chart. */
.bar {
  height: 6px;
  min-width: 60px;
  border-radius: 3px;
  background: var(--surface-sunk);
  overflow: hidden;
}

.bar__fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
}

/* The uploaded letterhead, shown against a chequerboard so a transparent
   PNG is visibly transparent rather than mistaken for a white background. */
.logo-preview {
  display: inline-flex;
  padding: var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background-color: var(--surface);
  background-image:
    linear-gradient(45deg, var(--surface-sunk) 25%, transparent 25%),
    linear-gradient(-45deg, var(--surface-sunk) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--surface-sunk) 75%),
    linear-gradient(-45deg, transparent 75%, var(--surface-sunk) 75%);
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0;
}

.logo-preview img {
  max-width: 320px;
  max-height: 110px;
  width: auto;
  height: auto;
}



/* Column proportions for the document line editor. Percentages rather than
   pixels so the table reflows on a narrow screen instead of clipping. */
.lines th:nth-child(1) { width: 34%; min-width: 200px; }
.lines th:nth-child(2) { width: 16%; min-width: 130px; }
.lines th:nth-child(3) { width: 10%; min-width: 80px; }
.lines th:nth-child(4) { width: 14%; min-width: 110px; }
.lines th:nth-child(5) { width: 10%; min-width: 80px; }
.lines th:nth-child(6) { width: 14%; min-width: 100px; }
.lines th:nth-child(7) { width: 40px; }

/* The computed net sits on the same baseline as the inputs beside it. */
.lines .line-net { padding-top: 9px; }

.avatar-sm { width: 22px; height: 22px; font-size: 10px; }

/* One organization in the chooser. */
.org-choice {
  width: 100%;
  height: auto;
  padding: var(--s-3) var(--s-4);
  justify-content: flex-start;
  gap: var(--s-3);
}

.org-choice__text { text-align: left; }
.org-choice__name { display: block; font-weight: 600; }

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

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--s-6);
  background:
    radial-gradient(1000px 500px at 50% -10%, var(--accent-soft), transparent 70%),
    var(--paper);
}

.auth__card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-8);
}

.auth__brand { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-6); }
.auth__title { font-size: var(--t-20); letter-spacing: -0.02em; margin-bottom: var(--s-1); }
.auth__sub { color: var(--ink-3); font-size: var(--t-13); margin-bottom: var(--s-6); }
.auth__foot { margin-top: var(--s-5); text-align: center; font-size: var(--t-12); color: var(--ink-3); }
.auth__foot a { color: var(--accent); text-decoration: none; }
.auth__foot a:hover { text-decoration: underline; }

.auth .btn--primary { width: 100%; height: 36px; }

/* Six-digit TOTP entry */
.code-input {
  font-family: var(--font-num);
  font-size: var(--t-20);
  letter-spacing: 0.4em;
  text-align: center;
  height: 44px;
  padding-left: 0.4em;
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 180ms var(--ease);
  }

  .sidebar[data-open="true"] { transform: none; }

  .scrim { position: fixed; inset: 0; background: rgb(0 0 0 / 0.4); z-index: 50; }

  .content { padding: var(--s-4); }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
}

@media (min-width: 901px) {
  .nav-toggle, .scrim { display: none; }
}

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

/* ------------------------------------------------------------------ print */

@media print {
  .sidebar, .topbar, .page-head__actions, .toolbar, .pager, .row-actions {
    display: none !important;
  }
  .app { grid-template-columns: 1fr; }
  .content { padding: 0; }
  .card, .table-wrap { border: 0; }
  table.data thead th { background: transparent; }
  body { background: #fff; }
}

/* ------------------------------------------------------------------- htmx */

.htmx-indicator { opacity: 0; transition: opacity var(--speed) var(--ease); }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }

.htmx-request.btn { pointer-events: none; opacity: 0.7; }

/* A thin progress line while a request is in flight. */
#progress {
  position: fixed;
  top: 0; left: 0;
  height: 2px;
  width: 0;
  background: var(--accent);
  z-index: 100;
  transition: width 200ms var(--ease), opacity 200ms var(--ease);
  opacity: 0;
}

#progress[data-active="true"] { opacity: 1; }
