:root {
  color-scheme: light;
  --ink: #1a2330;
  --muted: #5b6b7c;
  --canvas: #eef1f4;
  --surface: #ffffff;
  --line: #cfd6de;
  --line-strong: #9aa8b8;
  --accent: #1f4b7a;
  --accent-soft: #e7eef6;
  --ok: #1f6b45;
  --warn: #8a5b00;
  --danger: #9b2c2c;
  --danger-soft: #f8e8e8;
  --ok-soft: #e6f3eb;
  --row-hover: #f5f8fb;
  --focus: #2f6fed;
  --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --radius: 4px;
  --nav-h: 48px;
  font: 14.5px/1.45 var(--font);
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.skip {
  position: absolute; left: -9999px; top: 0;
}
.skip:focus { left: 8px; top: 8px; z-index: 20; background: #fff; padding: 8px 12px; border: 1px solid var(--line-strong); }

.top {
  min-height: var(--nav-h);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  background: #16324f;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid #0f2439;
}
.brand {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.02em;
  color: #fff;
  text-decoration: none;
}
.top nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.top nav a {
  color: #c9d7e6;
  text-decoration: none;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-weight: 500;
}
.top nav a:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.top nav a.is-active { background: rgba(255,255,255,0.14); color: #fff; }
.top .nav-end { margin-left: auto; color: #c9d7e6; text-decoration: none; padding: 8px 10px; }
.top .nav-end:hover { color: #fff; text-decoration: none; }

.nav-menu {
  position: relative;
  display: inline-block;
}
.nav-menu > summary {
  list-style: none;
  cursor: pointer;
  color: #c9d7e6;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-weight: 500;
  user-select: none;
}
.nav-menu > summary::-webkit-details-marker { display: none; }
.nav-menu > summary::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 6px;
  vertical-align: middle;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: 0.75;
}
.nav-menu > summary:hover,
.nav-menu[open] > summary {
  background: rgba(255,255,255,0.08);
  color: #fff;
}
.nav-menu > summary.is-active,
.nav-menu.is-active > summary {
  background: rgba(255,255,255,0.14);
  color: #fff;
}
.nav-menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 180px;
  padding: 6px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(22, 50, 79, 0.18);
  z-index: 20;
}
/* Beat .top nav a (light-on-dark) so panel links stay readable on white. */
.top nav .nav-menu-panel a {
  display: block;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--ink);
  font-weight: 500;
  text-decoration: none;
}
.top nav .nav-menu-panel a:hover {
  background: var(--row-hover);
  color: var(--accent);
  text-decoration: none;
}
.top nav .nav-menu-panel a.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.page {
  width: min(1400px, calc(100% - 32px));
  margin: 20px auto 64px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.page-head h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.page-head .meta { color: var(--muted); font-size: 0.92rem; }

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.toolbar .spacer { flex: 1; }

.panel, .sheet, .auth {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
/* overflow:visible so sticky register headers cannot clip the first data row */
.panel, .sheet { padding: 0; overflow: visible; margin-bottom: 16px; }
.panel-body, .sheet-body { padding: 14px 16px; }
.panel-head, .sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.panel-head h2, .sheet-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
}

.auth {
  width: min(440px, calc(100% - 24px));
  margin: 8vh auto;
  padding: 28px 28px 32px;
}
.auth h1 { font-size: 1.5rem; margin: 0 0 8px; }
.eyebrow {
  margin: 0 0 4px;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

label {
  display: grid;
  gap: 4px;
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.field-grid .span-2 { grid-column: span 2; }
.field-grid .span-all { grid-column: 1 / -1; }

input, select, textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font: inherit;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}
textarea { min-height: 72px; resize: vertical; }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  padding: 7px 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .button:hover { filter: brightness(1.05); text-decoration: none; }
button.secondary, .button.secondary {
  background: #fff;
  color: var(--accent);
}
button.danger, .button.danger {
  background: var(--danger);
  border-color: var(--danger);
}
button.ghost, .button.ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink);
}
button.link {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  color: var(--accent);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
button.link:hover { text-decoration: underline; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.inline label { margin: 0; }

.error, .notice {
  padding: 10px 12px;
  border-radius: var(--radius);
  margin: 0 0 12px;
  border: 1px solid transparent;
}
.error { background: var(--danger-soft); color: var(--danger); border-color: #e3bcbc; }
.notice { background: var(--ok-soft); color: var(--ok); border-color: #b9d8c5; }
.muted { color: var(--muted); }

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.metric span { display: block; color: var(--muted); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.metric strong {
  display: block;
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 1.2rem;
  font-weight: 500;
}

.register { width: 100%; border-collapse: collapse; background: #fff; }
.register th, .register td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  text-align: left;
}
.register th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: #f4f7fa;
  border-bottom: 1px solid var(--line-strong);
}
.register-wrap {
  overflow: auto;
  max-width: 100%;
  border-radius: 0 0 var(--radius) var(--radius);
}
.register tbody tr:hover { background: var(--row-hover); }
.register .money, .amount {
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* Summary/detail grids stack label above value — keep both start-aligned. */
.field-grid .amount {
  text-align: left;
}
.register .row-link { color: inherit; font-weight: 600; }
/* Do not set display:flex on the td — that breaks vertical-align in tall rows. */
.register td.row-actions {
  vertical-align: middle;
  white-space: nowrap;
}
.register .row-actions > .action-link,
.register .row-actions > form.inline-action {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  margin: 0 12px 0 0;
}
.register .row-actions > :last-child {
  margin-right: 0;
}
.register .row-actions form.inline-action {
  margin: 0 12px 0 0;
}
.register .row-actions .action-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}
.register .row-actions .action-link:hover {
  text-decoration: underline;
}
.register .row-actions .action-icon {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  display: block;
}

.file-status {
  display: block;
  margin-top: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
}
.file-status.is-selected {
  color: var(--ok);
}

.evidence-cell {
  max-width: 220px;
}
.evidence-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
  color: var(--ink);
  margin-bottom: 4px;
}
.evidence-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.evidence-actions .action-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
}
.evidence-actions .action-link:hover { text-decoration: underline; }
.evidence-actions .action-icon {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  display: block;
}

button .action-icon,
.button .action-icon,
.form-actions .action-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  display: block;
}

.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #edf1f5;
  color: #3d4d5f;
  text-transform: capitalize;
}
.status-pill.overdue, .status-pill.void { background: var(--danger-soft); color: var(--danger); }
.status-pill.paid, .status-pill.confirmed { background: var(--ok-soft); color: var(--ok); }
.status-pill.draft { background: #f3efe4; color: var(--warn); }
.status-pill.partially_paid, .status-pill.issued { background: var(--accent-soft); color: var(--accent); }

.sheet-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.sheet-grid {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.sheet-grid th, .sheet-grid td {
  border: 1px solid var(--line);
  padding: 0;
  vertical-align: middle;
}
.sheet-grid th {
  background: #f4f7fa;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 7px 8px;
  font-weight: 650;
}
.sheet-grid td.money { padding: 7px 8px; text-align: right; font-family: var(--mono); }
.sheet-grid input {
  border: 0;
  border-radius: 0;
  padding: 8px;
  background: transparent;
  width: 100%;
}
.sheet-grid input:focus { outline: 2px solid var(--focus); outline-offset: -2px; background: #fff; }
.sheet-grid select {
  border: 0;
  border-radius: 0;
  width: 100%;
  padding: 8px 6px;
  background: transparent;
  font: inherit;
  line-height: 1.2;
}
.sheet-grid select:focus { outline: 2px solid var(--focus); outline-offset: -2px; background: #fff; }
/* Remaining width goes to description; other columns keep fixed sizes. */
.sheet-grid .col-desc { width: 100%; }
.sheet-grid .col-qty { width: 90px; }
.sheet-grid .col-price { width: 120px; }
.sheet-grid .col-vat { width: 10.5rem; }
.sheet-grid .col-total { width: 120px; }
.sheet-grid .col-action { width: 44px; text-align: center; }
.sheet-grid .col-action button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px;
}
.sheet-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
}
.sheet-total {
  font-family: var(--mono);
  font-size: 1.15rem;
  font-weight: 500;
}

.split-2 {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
}
.stack { display: grid; gap: 16px; }

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

.workbench-block {
  padding: 14px 16px;
  border-top: 1px solid var(--line);
}
.workbench-block h3 {
  margin: 0 0 10px;
  font-size: 0.9rem;
}

.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.codes code, .secret {
  display: block;
  background: #eef2f6;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.85rem;
}

/* Compatibility for pages still using legacy layout helpers */
.grid, .cards, .split { display: grid; gap: 14px; }
.grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cards { grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0 0 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.card span { display: block; color: var(--muted); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; }
.card strong { display: block; margin-top: 4px; font-family: var(--mono); font-size: 1.2rem; font-weight: 500; }
.card small { color: var(--muted); }
.split { grid-template-columns: 1fr 1.4fr; }
table:not(.register):not(.sheet-grid) {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}
table:not(.register):not(.sheet-grid) th,
table:not(.register):not(.sheet-grid) td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table:not(.register):not(.sheet-grid) th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: #f4f7fa;
}
.backup-scopes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.backup-scopes legend {
  padding: 0 4px;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.85rem;
}
label.check {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.25;
}
label.check input[type="checkbox"] {
  width: 1rem;
  min-width: 1rem;
  height: 1rem;
  margin: 0;
  padding: 0;
  flex: 0 0 auto;
  accent-color: var(--accent);
  align-self: center;
  vertical-align: middle;
}
.vat-rate-rows {
  display: grid;
  gap: 10px;
  margin: 12px 0 4px;
  max-width: 28rem;
}
.vat-rate-row {
  display: grid;
  grid-template-columns: minmax(9rem, 1fr) 5.5rem auto;
  gap: 10px;
  align-items: center;
}
.vat-rate-row .check {
  margin: 0;
}
.vat-rate-row .vat-rate-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
}
.vat-rate-row input[type="text"],
.vat-rate-row input[inputmode="decimal"] {
  width: 100%;
  max-width: 5.5rem;
  text-align: right;
}
.vat-rate-fixed {
  display: block;
  width: 100%;
  max-width: 5.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.backup-scopes label.check {
  margin: 0;
}

.panel > h2, .panel > form, .panel > p, .panel > table, .panel > .toolbar, .panel > .grid, .panel > details {
  margin-left: 16px;
  margin-right: 16px;
}
.panel > h2 { margin-top: 14px; font-size: 0.95rem; }
.panel > form:last-child, .panel > table:last-child, .panel > p:last-child { margin-bottom: 14px; }
.panel > .toolbar { margin-top: 10px; }
.status { text-transform: capitalize; }
.top .nav-end { color: #c9d7e6; text-decoration: none; }
.top .nav-end:hover { color: #fff; }

@media (max-width: 900px) {
  .metrics, .sheet-meta, .split-2, .cards { grid-template-columns: 1fr 1fr; }
  .field-grid .span-2 { grid-column: auto; }
}
@media (max-width: 700px) {
  .top { flex-wrap: wrap; height: auto; padding: 8px 12px; }
  .metrics, .sheet-meta, .split-2, .field-grid, .grid, .cards, .split { grid-template-columns: 1fr; }
  .page { width: calc(100% - 20px); }
  .register-wrap { overflow: auto; }
}
