/* Invoice Desk — "pharmacy ledger": forest rail, warm paper, DIN-style figures (Bahnschrift ships with Windows). */
:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --paper: #fffdf9;
  --raised: #f8f5ef;
  --line: #e4ded2;
  --line-strong: #cfc7b7;
  --control-line: #a39a88;
  --ink: #1d2420;
  --secondary: #4b534d;
  --muted: #626860;
  --rail: #13261f;
  --rail-ink: #dfe9e3;
  --rail-muted: #8fa89b;
  --rail-hover: #1c352b;
  --accent: #1f6b4f;
  --accent-dark: #17543e;
  --accent-soft: #e3efe8;
  --mint: #7fd1a8;
  --danger: #a33a2a;
  --danger-soft: #f8e7e2;
  --amber: #855610;
  --amber-soft: #f7ecd6;
  --radius: 14px;
  --control-radius: 9px;
  --gutter: 36px;
  --display: Bahnschrift, "DIN Alternate", "Segoe UI Variable Display", "Segoe UI", sans-serif;
  --text: "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Mono", Consolas, monospace;
  --ease: 150ms ease-out;
  --shadow: 0 1px 0 #00000008, 0 8px 24px -16px #1d242033;
  font: 100%/1.5 var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--bg); font-size: .9375rem; -webkit-font-smoothing: antialiased; }
button, select, input, textarea, output { font: inherit; color: inherit; }
button, select, a, summary { cursor: pointer; }
button:disabled, select:disabled { cursor: default; opacity: .5; }
input, select, textarea { background: var(--paper); border: 1px solid var(--control-line); border-radius: var(--control-radius); padding: 7px 11px; min-width: 0; min-height: 38px; }
input:hover, select:hover, textarea:hover { border-color: #b3aa98; }
input, textarea { width: 100%; }
textarea { resize: vertical; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
main:focus { outline: none; }
h1, h2, p, dl, dd { margin: 0; }
h1 { font-family: var(--display); font-size: clamp(1.9rem, 3vw, 2.6rem); line-height: 1.05; letter-spacing: -.01em; font-weight: 600; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
h2 { font-family: var(--display); font-size: 1.0625rem; line-height: 1.3; font-weight: 600; letter-spacing: .005em; }
p { color: var(--secondary); }
strong { font-weight: 600; }
svg { width: 18px; height: 18px; flex: 0 0 auto; vertical-align: middle; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
.skip-link { position: absolute; z-index: 3; inset: 12px auto auto 12px; padding: 8px 12px; background: var(--paper); transform: translateY(calc(-100% - 20px)); }
.skip-link:focus { transform: none; }
.numeric, .stat-value, .detail-total, .document-number, .heading-number { font-variant-numeric: tabular-nums; }
.numeric { font-family: var(--display); font-weight: 500; white-space: nowrap; letter-spacing: .01em; }
.zero { color: var(--muted); }
.hint, .footnote { font-size: .8125rem; color: var(--muted); }
.footnote { margin: 12px 4px 32px; max-width: 90ch; }

/* Shell */
.shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { background: var(--rail); color: var(--rail-ink); height: 100dvh; position: sticky; top: 0; padding: 22px 14px 16px; display: flex; flex-direction: column; overflow: auto;
  }
.sidebar-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.brand { display: inline-flex; gap: 10px; align-items: center; padding: 4px 8px; font-family: var(--display); font-size: 1.2rem; font-weight: 600; letter-spacing: .01em; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--mint); color: var(--rail); }
.overline { display: block; font-family: var(--display); font-size: .72rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.business { margin: 22px 0 8px; padding: 12px; border: 1px solid #ffffff14; border-radius: 12px; background: #ffffff08; }
.business .overline { color: var(--rail-muted); margin-bottom: 6px; }
.business-name { font-weight: 600; line-height: 1.3; }
.business-picker { width: 100%; background: var(--rail-hover); color: var(--rail-ink); border-color: #ffffff22; font-weight: 600; }
.business-picker option { background: var(--paper); color: var(--ink); }
.nav-group { display: grid; gap: 2px; margin-top: 12px; }
.nav-item { width: 100%; display: flex; align-items: center; gap: 11px; min-height: 40px; padding: 6px 12px; border: 0; border-radius: 9px; background: transparent; color: var(--rail-muted); text-align: left; white-space: nowrap; font-weight: 500; }
.nav-item:hover { background: var(--rail-hover); color: var(--rail-ink); }
.nav-item.current { background: var(--paper); color: var(--rail); font-weight: 600; }
.nav-item.current svg { color: var(--accent); }
.nav-item span { flex: 1; }
.count { min-width: 22px; padding: 0 7px; border-radius: 99px; background: var(--danger); color: white; font: 600 .75rem/20px var(--display); text-align: center; }
.sidebar-bottom { margin-top: auto; display: flex; gap: 10px; align-items: baseline; padding: 14px 10px 0; border-top: 1px solid #ffffff14; }
.sidebar-bottom strong, .sidebar-bottom small { display: block; font-size: .8125rem; }
.sidebar-bottom small { color: var(--rail-muted); }
.sidebar-bottom i { width: 8px; height: 8px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 3px #7fd1a833; flex: 0 0 auto; }
.btn.nav-toggle { display: none; }
main { max-width: 1480px; margin: 0 auto; padding: 34px var(--gutter) 72px; min-width: 0; }
.workspace { min-width: 0; }
.loading { padding: 2rem 0; }

/* Page header */
.hero { position: relative; z-index: 3; display: flex; align-items: end; justify-content: space-between; flex-wrap: wrap; gap: 16px 24px; margin-bottom: 26px; }
.hero p { margin-top: 8px; color: var(--muted); }
.hero-actions, .modal-actions, .row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row-actions { justify-content: flex-end; gap: 6px; }

/* Buttons */
.btn { display: inline-flex; gap: 7px; align-items: center; justify-content: center; min-height: 38px; padding: 7px 14px; background: var(--paper); color: var(--ink); border: 1px solid var(--line-strong); border-radius: var(--control-radius); font-weight: 600; font-size: .875rem; line-height: 1.2; white-space: nowrap; }
.btn:hover { border-color: #a99f8b; background: #fff; }
.btn.primary { color: white; background: var(--accent); border-color: var(--accent); box-shadow: inset 0 1px 0 #ffffff22, 0 1px 2px #17543e44; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: .8125rem; }
.btn.small svg { width: 15px; height: 15px; }
.btn.quiet { border-color: transparent; background: transparent; }
.btn.quiet:hover { background: var(--raised); border-color: var(--line); }
.btn.subtle { color: var(--danger); border-color: transparent; background: transparent; }
.btn.subtle:hover { background: var(--danger-soft); }
.btn:active:not(:disabled), .nav-item:active, .chip:active { transform: translateY(1px); }
.text-btn { display: inline-flex; align-items: center; gap: 6px; border: 0; padding: 0; min-height: 28px; margin-bottom: 14px; background: none; color: var(--muted); font-weight: 600; font-size: .875rem; }
.text-btn:hover { color: var(--accent); }
.icon-btn { display: grid; place-items: center; width: 32px; height: 32px; border: 1px solid transparent; border-radius: 8px; padding: 0; background: transparent; color: var(--muted); }
.icon-btn:enabled:hover { background: var(--danger-soft); color: var(--danger); }
.compact { min-height: 38px; padding-block: 4px; font-size: .875rem; font-weight: 600; }

/* Panels */
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-heading, .section-head { display: flex; gap: 12px; justify-content: space-between; align-items: center; }
.panel-heading p { margin-top: 2px; font-size: .8125rem; color: var(--muted); }
.panel > .panel-heading { padding: 18px 20px 6px; }
.activity > .panel-heading { padding: 0 2px 12px; }
.activity { margin-top: 28px; }
.setup { display: flex; justify-content: space-between; gap: 16px; align-items: center; padding: 16px 20px; margin-bottom: 22px; background: var(--amber-soft); border: 1px solid #e7d3a8; border-radius: var(--radius); }
.setup p { font-size: .875rem; margin-top: 2px; }

/* Overview */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 18px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat { min-width: 0; padding: 18px 22px; border-left: 1px solid var(--line); }
.stat:first-child { border-left: 0; }
.stat-label { font-family: var(--display); font-size: .78rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.stat-value { font-family: var(--display); font-size: clamp(1.45rem, 2.2vw, 1.95rem); font-weight: 600; line-height: 1.1; margin-top: 10px; letter-spacing: -.005em; overflow-wrap: anywhere; }
.stat p { font-size: .8125rem; color: var(--muted); margin-top: 6px; }
.stat.alert .stat-value, .stat.alert p { color: var(--danger); }
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr); gap: 18px; align-items: start; margin-bottom: 18px; }
.weeks .table-wrap { border-top: 1px solid var(--line); }
.weeks .table-wrap { overflow-x: auto; }
.register.week-table { min-width: 600px; }
.week-table th, .week-table td { padding-block: 9px; }
.week-name { font-family: var(--display); font-weight: 600; white-space: nowrap; }
.week-table tbody th { border-bottom: 1px solid var(--line); text-align: left; }
.week-table tr.todo, .week-table tr.todo:hover { background: var(--amber-soft); }
.week-table tr.gap, .week-table tr.todo { cursor: default; }
.attention-list .row-open { min-height: 32px; align-items: center; }
.week-table tr.gap td, .week-table tr.gap th { color: var(--muted); }
.week-todo { font-weight: 600; color: var(--amber); }
.week-gap { color: var(--muted); }
.draft-row { background: var(--raised); }
.days { display: inline-flex; gap: 3px; }
.days i { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 5px; border: 1px solid var(--line); font: 600 .68rem var(--display); font-style: normal; color: var(--muted); }
.days i.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chart-panel { padding-bottom: 14px; }
.chart { display: block; width: 100%; height: auto; padding: 8px 14px 0; }
.chart .bar { fill: #9cc4ae; }
.chart .bar.now { fill: var(--accent); }
.chart g:hover .bar { fill: var(--accent-dark); }
.chart .axis { stroke: var(--line-strong); }
.bar-label, .bar-value { font: 600 11px var(--display); text-anchor: middle; fill: var(--muted); }
.bar-value { fill: var(--secondary); font-size: 10.5px; }
.attention-list { list-style: none; margin: 0; padding: 4px 12px 12px; display: grid; gap: 6px; }
.attention-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "doc amt act" "when when act"; gap: 2px 12px; align-items: center; padding: 10px 12px; border-radius: 10px; background: var(--amber-soft); }
.attention-list li.late { background: var(--danger-soft); }
.attention-list .row-open { grid-area: doc; display: flex; gap: 10px; min-width: 0; border: 0; padding: 0; background: none; text-align: left; font-weight: 600; }
.attention-list .row-open span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--secondary); font-weight: 500; }
.attention-list .when { grid-area: when; font-size: .8rem; color: var(--amber); font-weight: 600; }
.attention-list .late .when { color: var(--danger); }
.attention-list strong { grid-area: amt; }
.mini-actions { grid-area: act; display: flex; gap: 6px; }
.all-clear { display: flex; gap: 10px; align-items: center; margin: 4px 20px 18px; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; font-size: .875rem; }

/* Tables */
.table-wrap { overflow-x: auto; }
@media screen and (min-width: 1100px) { .table-wrap { overflow: visible; } }
.table-wrap:focus-visible { outline-offset: -2px; }
table { border-collapse: collapse; width: 100%; text-align: left; }
th, td { padding: 11px 16px; border-bottom: 1px solid var(--line); }
thead th { position: sticky; top: 0; z-index: 1; color: var(--muted); background: var(--raised); font-family: var(--display); font-size: .72rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; white-space: nowrap; }
.panel > .table-wrap:first-child thead th:first-child, .activity .table-wrap thead th:first-child { border-top-left-radius: var(--radius); }
.panel > .table-wrap:first-child thead th:last-child, .activity .table-wrap thead th:last-child { border-top-right-radius: var(--radius); }
td { font-size: .875rem; vertical-align: middle; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
tbody tr { transition: background-color var(--ease); }
tbody tr:hover { background: #faf7f1; }
td small, th small { display: block; color: var(--muted); font-size: .75rem; font-weight: 400; letter-spacing: 0; text-transform: none; }
.right { text-align: right; }
.activity .table-wrap { border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); }
.register { min-width: 860px; }
.register tbody tr { cursor: pointer; }
.register tr.is-late td:first-child, .register tr.is-late .check + td { box-shadow: inset 3px 0 0 var(--danger); }
.register .check { width: 44px; padding-inline: 16px 4px; }
.register .check input { width: 16px; min-height: 16px; accent-color: var(--accent); }
.register .client-col { max-width: 28ch; overflow-wrap: anywhere; }
.register .actions { width: 1%; padding-inline: 8px 12px; }
.row-date { white-space: nowrap; color: var(--secondary); }
.table-link { min-height: 24px; padding: 0; color: var(--ink); background: transparent; border: none; font-weight: 600; text-align: left; }
.table-link:hover { color: var(--accent); text-decoration: underline; text-underline-offset: .2em; }
.document-number, .heading-number { font-family: var(--display); letter-spacing: .02em; }
.clip { display: block; max-width: 36ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted-row td { color: var(--muted); }
.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 99px; font: 600 .75rem/1.6 var(--display); letter-spacing: .04em; white-space: nowrap; background: #ece8df; color: var(--secondary); }
h1 .badge { font-size: .8rem; padding: 3px 11px; }
.badge.paid, .badge.converted { background: var(--accent-soft); color: var(--accent-dark); }
.badge.overdue { background: var(--danger-soft); color: var(--danger); }
.badge.unpaid, .badge.part-paid { background: var(--amber-soft); color: var(--amber); }
.badge.draft { background: transparent; border: 1px dashed var(--line-strong); }
.empty { display: grid; justify-items: start; gap: 4px; padding: 28px; }
.empty p { font-size: .875rem; }
.empty .btn { margin-top: 10px; }

/* Row action menu (native <details>) */
.menu { position: relative; }
.menu summary { list-style: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; color: var(--muted); }
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover, .menu[open] summary { background: var(--raised); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 5; display: grid; min-width: 210px; padding: 6px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 40px -12px #1d242040, 0 2px 6px #1d242014; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px; background: none; text-align: left; font-size: .875rem; font-weight: 500; white-space: nowrap; }
.menu-item svg { width: 16px; height: 16px; color: var(--muted); }
.menu-item:hover, .menu-item:focus-visible { background: var(--raised); }
.menu-item.danger { color: var(--danger); margin-top: 4px; border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; }
.menu-item.danger svg { color: currentColor; }

/* Register toolbar */
.toolbar { display: flex; padding: 14px 16px; gap: 12px; flex-wrap: wrap; align-items: center; border-bottom: 1px solid var(--line); }
.search { display: flex; align-items: center; gap: 8px; padding-inline: 12px 4px; width: min(320px, 100%); background: var(--paper); color: var(--muted); border: 1px solid var(--line-strong); border-radius: var(--control-radius); }
.search:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.search input { border: 0; padding-inline: 0 8px; outline: 0; background: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; padding: 3px; border-radius: 11px; background: var(--raised); border: 1px solid var(--line); }
.chip { border: 0; padding: 5px 11px; border-radius: 8px; background: transparent; font-size: .8125rem; font-weight: 600; color: var(--secondary); }
.chip:hover { background: #fff; }
.chip.on { background: var(--rail); color: #fff; }
.result-count { margin-left: auto; font-size: .8125rem; color: var(--muted); }
.bulk-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 16px; background: var(--accent-soft); border-bottom: 1px solid #cfe0d5; }
.bulk-bar > div { display: flex; gap: 6px; flex-wrap: wrap; }
.bulk-bar:empty { display: none; }

/* Forms */
.form-panel { padding: 22px; min-width: 0; }
.form-panel > p { margin-top: 4px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 16px 0; }
.fields.four { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); margin: 0 0 14px; }
.fields.four:has(> :nth-child(2):last-child) { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.form-panel label, .modal-fields label, .forward { display: flex; flex-direction: column; gap: 5px; font-size: .8125rem; font-weight: 600; color: var(--secondary); }
.form-panel :is(input, select, textarea), .modal-fields :is(input, select, textarea) { font-size: .9375rem; font-weight: 400; color: var(--ink); }
.fields label:has(textarea) { grid-column: span 1; }
.with-action { display: flex; gap: 8px; }
.with-action select { flex: 1; }
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.settings-aside { display: grid; gap: 18px; }
.backup .btn { margin-top: 14px; }
.form-panel .hint { margin: -4px 0 16px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Editor */
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; align-items: start; }
.editor-grid:not(.frozen) .preview-side { position: static; max-width: 860px; }
@media screen and (min-width: 1200px) {
  .editor-grid:not(.frozen) { grid-template-columns: minmax(0, 1.2fr) minmax(420px, .8fr); }
  .editor-grid:not(.frozen) .preview-side { position: sticky; }
}
.editor-grid.frozen { grid-template-columns: minmax(280px, .55fr) minmax(0, 1.2fr); }
.editor-side { min-width: 0; }
.section-head { margin: 22px 0 8px; padding-top: 18px; border-top: 1px solid var(--line); }
.lines { container-type: inline-size; display: grid; gap: 6px; }
.line-row { display: grid; gap: 6px; align-items: center; grid-template-columns: 9.25rem minmax(0, 1fr) 4.25rem 4.5rem 5.5rem 4rem 6rem 2rem; grid-template-areas: "date desc qty unit rate tax amt x"; }
.line-row > .c-date { grid-area: date; } .line-row > .c-desc { grid-area: desc; } .line-row > .c-qty { grid-area: qty; } .line-row > .c-unit { grid-area: unit; }
.line-row > .c-rate { grid-area: rate; } .line-row > .c-tax { grid-area: tax; } .line-row > .c-amt { grid-area: amt; } .line-row > .c-x { grid-area: x; }
.line-row .cell { display: block; min-width: 0; margin: 0; }
.line-row .cell input { width: 100%; }
.cell-label { display: none; }
.line-row input { min-height: 36px; padding: 6px 8px; font-size: .875rem; }
.line-row input[type="number"] { text-align: right; font-variant-numeric: tabular-nums; }
.line-head { font-family: var(--display); font-size: .7rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 0 2px; }
.line-head .c-qty, .line-head .c-rate, .line-head .c-tax, .line-head .c-amt { text-align: right; }
.c-amt { text-align: right; padding-right: 2px; }
@container (max-width: 720px) {
  .line-row { grid-template-columns: 9.25rem minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.2fr) minmax(0, 1fr) 5.5rem 2rem; grid-template-areas: "date qty unit rate tax amt x" "desc desc desc desc desc desc desc"; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
  .line-head { grid-template-areas: "date qty unit rate tax amt x"; border: 0; padding-bottom: 0; }
  .line-head .c-desc { display: none; }
}
@container (max-width: 520px) {
  .line-head { display: none; }
  .line-row { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-areas: "date date date x" "desc desc desc desc" "qty unit rate tax" "amt amt amt amt"; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .line-row:last-of-type { border-bottom: 0; }
  .cell-label { display: block; margin-bottom: 3px; font: 600 .7rem var(--display); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
  .line-row > .c-x { justify-self: end; align-self: end; }
  .line-row > .c-amt { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; }
}
.line-actions { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; margin: 14px 0 20px; }
.line-actions .spacer { flex: 1; }
.form-panel .forward { flex-direction: row; align-items: center; gap: 8px; }
.forward input { width: 4.5rem; min-height: 32px; text-align: right; }
.preview-side { position: sticky; top: 18px; min-width: 0; }
.balance-card .detail-total { font-family: var(--display); font-size: clamp(1.9rem, 3vw, 2.6rem); font-weight: 600; line-height: 1.1; margin: 8px 0 4px; }
.balance-card .detail-total small { font-size: .875rem; color: var(--muted); font-weight: 500; }
.balance-card .when { font-size: .875rem; font-weight: 600; color: var(--accent); margin-bottom: 22px; }
.balance-card.late .when, .balance-card.late .detail-total { color: var(--danger); }
.balance-card h2 { padding-top: 16px; border-top: 1px solid var(--line); }
.balance-card .hint { margin-top: 14px; }
.detail-total { font-family: var(--display); font-size: 2rem; font-weight: 600; margin-top: 12px; }
.payment-list { margin-top: 8px; }
.payment-list > div { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.payment-list small { display: block; color: var(--muted); font-size: .8rem; }

/* The document itself — also used for printing */
.paper { container-type: inline-size; background: #fff; border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 1px 2px #1d242012, 0 24px 48px -28px #1d242055; padding: 34px 34px 28px; font-size: .8125rem; color: #1d2420; }
.inv { display: grid; gap: 22px; }
.inv-head { display: flex; justify-content: space-between; align-items: start; gap: 18px; padding-bottom: 18px; border-bottom: 3px solid var(--rail); }
.inv-logo { display: block; max-width: 190px; max-height: 76px; width: auto; height: auto; object-fit: contain; margin-bottom: 10px; }
.inv-co { font-family: var(--display); font-size: 1.0625rem; font-weight: 600; overflow-wrap: anywhere; }
.inv-muted { color: #5d645e; font-size: .78rem; line-height: 1.5; overflow-wrap: anywhere; }
.inv-title { display: grid; justify-items: end; text-align: right; gap: 2px; }
.inv-kind { font-family: var(--display); font-size: 1.45rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--rail); white-space: nowrap; }
.inv-no { font-family: var(--display); font-size: 1rem; letter-spacing: .06em; color: var(--accent); }
.inv-label { display: block; margin-bottom: 4px; font-family: var(--display); font-size: .66rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: #5f6660; }
.inv-parties { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, .8fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.inv-parties strong { display: block; font-size: .875rem; overflow-wrap: anywhere; }
.inv-dates { display: grid; gap: 6px; }
.inv-dates dt { font-family: var(--display); font-size: .66rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: #5f6660; }
.inv-dates dd { font-weight: 600; }
.inv-due { display: grid; gap: 2px; padding: 12px 14px; border-radius: 8px; background: var(--rail); color: #e8f1ec; text-align: right; }
.inv-due span { font-family: var(--display); font-size: .66rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--mint); }
.inv-due strong { font-family: var(--display); font-size: 1.45rem; line-height: 1.1; color: #fff; font-variant-numeric: tabular-nums; }
.inv-due small { font-size: .72rem; color: #a9c2b5; }
.inv-lines th, .inv-lines td { padding: 8px 6px; font-size: .78rem; border-bottom: 1px solid #ebe6dc; }
.inv-lines th { position: static; background: transparent; border-bottom: 1.5px solid #1d2420; color: #1d2420; font-size: .64rem; padding-top: 0; }
.inv-lines td { font-variant-numeric: tabular-nums; vertical-align: top; }
.inv-lines td:first-child { width: 48%; overflow-wrap: anywhere; padding-left: 0; }
.inv-lines th:first-child { padding-left: 0; }
.inv-lines td:last-child, .inv-lines th:last-child { padding-right: 0; font-weight: 600; }
.inv-lines tbody tr:hover { background: none; }
.inv-foot { display: grid; grid-template-columns: minmax(0, 1fr) minmax(200px, .8fr); gap: 24px; align-items: start; }
.inv-pay { font-size: .78rem; }
.inv-pay .inv-muted { margin-top: 8px; }
.kv { display: grid; gap: 2px; }
.kv div { display: grid; grid-template-columns: 9.5em minmax(0, 1fr); gap: 8px; }
.kv dt { color: #6b726c; }
.kv dd { font-weight: 600; font-variant-numeric: tabular-nums; }
.inv-totals { display: grid; font-variant-numeric: tabular-nums; }
.inv-totals div { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; }
.inv-totals dt { color: #5d645e; }
.inv-totals .inv-total { margin-top: 4px; padding: 8px 0; border-top: 1.5px solid #1d2420; font-family: var(--display); font-size: .95rem; font-weight: 700; }
.inv-totals .inv-total dt { color: #1d2420; }
.inv-notes { padding-top: 14px; border-top: 1px solid #ebe6dc; }

@container (max-width: 620px) {
  .inv-head { flex-direction: column-reverse; }
  .inv-title { justify-items: start; text-align: left; }
  .inv-parties { grid-template-columns: minmax(0, 1fr) auto; }
  .inv-due { grid-column: 1 / -1; text-align: left; }
  .inv-foot { grid-template-columns: minmax(0, 1fr); }
}

/* Reports */
.report th[scope="row"] { font-family: var(--display); font-weight: 600; white-space: nowrap; }
.report tr.current { background: var(--accent-soft); }
.report tfoot th, .report tfoot td { border-top: 2px solid var(--ink); border-bottom: 0; background: var(--raised); font-weight: 600; }
.report tfoot th:first-child { border-bottom-left-radius: var(--radius); }
.report tfoot td:last-child { border-bottom-right-radius: var(--radius); }
.strong { color: var(--accent-dark); font-weight: 700; }
.share { width: 80px; height: 6px; margin-right: 10px; vertical-align: middle; }
.share-bg { fill: #ece8df; } .share-fill { fill: var(--accent); }

/* Dialog + toast */
dialog { padding: 0; border: 1px solid var(--line); border-radius: 16px; width: min(480px, calc(100vw - 32px)); color: var(--ink); background: var(--paper); box-shadow: 0 30px 70px -20px #0b1410aa; }
dialog::backdrop { background: #0f1a15b3; backdrop-filter: blur(2px); }
.modal-head, .modal-actions, .modal-fields { padding: 16px 20px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.modal-head .icon-btn:hover { background: var(--raised); color: var(--ink); }
.modal-fields { display: grid; gap: 14px; max-height: min(66dvh, calc(100dvh - 160px)); overflow-y: auto; }
.modal-actions { border-top: 1px solid var(--line); justify-content: flex-end; background: var(--raised); border-radius: 0 0 16px 16px; }
#modal-error { color: var(--danger); }
#toast:empty, #print { display: none; }
#toast { position: fixed; bottom: 20px; right: 20px; max-width: min(420px, calc(100vw - 32px)); color: #fff; background: var(--rail); padding: 12px 16px; border-radius: 11px; box-shadow: 0 12px 32px -8px #0b141099; z-index: 10; pointer-events: none; font-weight: 500; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .nav-item, .icon-btn, .table-link, .chip, .menu summary { transition: background-color var(--ease), border-color var(--ease), color var(--ease), transform var(--ease); }
  main > * { animation: rise 320ms cubic-bezier(.2, .7, .2, 1) both; }
  main > :nth-child(2) { animation-delay: 40ms; } main > :nth-child(3) { animation-delay: 80ms; } main > :nth-child(4) { animation-delay: 120ms; }
  .menu[open] .menu-list { animation: pop 140ms ease-out; }
  #toast:not(:empty) { animation: pop 200ms ease-out; }
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }

@media screen and (max-width: 1280px) {
  :root { --gutter: 26px; }
  .shell { grid-template-columns: 220px minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-grid { grid-template-columns: minmax(0, 1fr); }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
}
@media screen and (max-width: 1199px) {
  .editor-grid, .editor-grid.frozen { grid-template-columns: minmax(0, 1fr); }
  .preview-side { position: static; max-width: 820px; }
}
@media screen and (max-width: 767px) {
  .stat, .stat:nth-child(3) { border-left: 0; border-top: 1px solid var(--line); }
  .stat:first-child { border-top: 0; }
  .week-table .days-col { display: none; }
  .register.week-table { min-width: 0; }
  :root { --gutter: 16px; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; padding: 10px var(--gutter); overflow: visible; }
  .btn.nav-toggle { display: inline-flex; background: transparent; color: var(--rail-ink); border-color: #ffffff33; }
  .nav-group, .business { display: none; }
  .nav-group { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar:has(.nav-toggle[aria-expanded="true"]) :is(.nav-group, .business) { display: grid; }
  .sidebar-bottom { display: none; }
  main { padding-top: 24px; }
  .stats, .settings-grid, .fields, .fields.four, .inv-parties, .inv-foot { grid-template-columns: minmax(0, 1fr); }
  .paper { padding: 18px; }
  .inv-due { text-align: left; }
  .result-count { margin-left: 0; }
}
@media (pointer: coarse) {
  .btn, .nav-item, input, select { min-height: 44px; }
  .icon-btn, .menu summary { width: 44px; height: 44px; }
  .register .check input { width: 22px; min-height: 22px; }
}

@page { size: A4; margin: 14mm; }
@media print {
  .shell, dialog, #toast { display: none !important; }
  #print:not(:empty) { display: block; }
  body { background: white; color: black; font-size: 11px; }
  #print .inv-due { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #print .inv-head { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #print tr, #print .inv-foot, #print .inv-notes { break-inside: avoid; }
  #print .inv-lines thead { display: table-header-group; }
}

/* States */
.btn[aria-busy="true"] { cursor: progress; opacity: .65; }
.form-error { margin: -10px 0 18px; padding: 12px 16px; border: 1px solid #eccabf; border-radius: var(--control-radius); background: var(--danger-soft); color: var(--danger); font-weight: 600; font-size: .875rem; }
.date-note { margin: -4px 0 14px; padding: 9px 12px; border-radius: var(--control-radius); background: var(--amber-soft); color: var(--amber); font-size: .8125rem; font-weight: 600; }
.more-menu summary.btn { width: auto; height: auto; display: inline-flex; color: var(--ink); }
.more-menu summary.btn svg { width: 16px; height: 16px; }
::selection { background: #cfe3d8; color: var(--ink); }

/* Logins, people, import, report range */
body.auth .shell { grid-template-columns: 1fr; }
body.auth .sidebar { display: none; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(420px, 100%); display: grid; gap: 14px; }
.auth-card h1 { font-size: 1.75rem; }
.auth-card .form-error, .auth-card .hint { margin: 0; }
.auth-card .btn { justify-content: center; }
.auth-brand { display: flex; gap: 10px; align-items: center; font-family: var(--display); font-weight: 600; font-size: 1.1rem; }
.sidebar-bottom { align-items: center; }
.sidebar-bottom > div { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.sidebar-bottom .icon-btn { color: var(--rail-muted); }
.sidebar-bottom .icon-btn:hover { background: #ffffff14; color: #fff; }
.check-row { flex-direction: row !important; align-items: flex-start; gap: 10px !important; margin: 0 0 16px; }
.check-row input { width: 18px; min-height: 18px; margin: 2px 0 0; accent-color: var(--accent); }
.check-row small { display: block; font-weight: 400; color: var(--muted); }
.people { list-style: none; margin: 12px 0 16px; padding: 0; border-top: 1px solid var(--line); }
.people li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.people small { display: block; color: var(--muted); font-size: .8125rem; }
.invite-form { display: flex; gap: 8px; align-items: flex-end; }
.invite-form label { flex: 1; }
.link-box { margin-top: 14px; padding: 12px 14px; border: 1px solid #cfe0d5; border-radius: var(--control-radius); background: var(--accent-soft); display: grid; gap: 8px; }
.link-box p { font-size: .8125rem; }
.steps { margin: 10px 0 14px; padding-left: 20px; color: var(--secondary); font-size: .875rem; display: grid; gap: 4px; }
kbd, code { font-family: ui-monospace, Consolas, monospace; font-size: .8125rem; padding: 1px 5px; border: 1px solid var(--line); border-radius: 5px; background: var(--raised); }
.file-btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
#import-result:not(:empty) { margin-top: 12px; }
.report-toolbar .inline-field { display: flex; align-items: center; gap: 8px; font-size: .8125rem; font-weight: 600; color: var(--secondary); }
.report-toolbar input[type=date] { width: auto; }
#password-form { display: grid; gap: 10px; }
#password-form .btn { justify-self: start; }
.report .row-actions { flex-wrap: nowrap; white-space: nowrap; }
