:root {
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-synthesis: none;
  font-size: 14px;
  color-scheme: dark;
  --background: #151718;
  --surface: #202325;
  --inset: #191c1e;
  --hover: #292d30;
  --text: #e8eaed;
  --muted: #afb5bb;
  --line: #3c4146;
  --accent: #ffada3;
  --active: #372725;
  --button: #b83d30;
  --button-hover: #a63529;
  --input: #191c1e;
  --focus: #f0b45a;
  --success-bg: #20372d;
  --success-text: #afe0bd;
  --warning-bg: #382e1d;
  --warning-text: #f2cf88;
  --error-bg: #3b2424;
  --error-text: #ffb9af;
  color: var(--text);
  background: var(--background);
}

:root[data-theme="light"] {
  color-scheme: light;
  --background: #f2f3f4;
  --surface: #ffffff;
  --inset: #f7f8f9;
  --hover: #edeff1;
  --text: #24292e;
  --muted: #59636d;
  --line: #d4d9de;
  --accent: #a63227;
  --active: #f9e9e6;
  --button: #b83d30;
  --button-hover: #a63529;
  --input: #ffffff;
  --focus: #9b5c00;
  --success-bg: #e6f1ea;
  --success-text: #255839;
  --warning-bg: #fff3d9;
  --warning-text: #795309;
  --error-bg: #fbece8;
  --error-text: #a32d20;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }

button, .button {
  display: inline-block;
  padding: 8px 13px;
  border: 1px solid var(--button);
  border-radius: 4px;
  background: var(--button);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  font-weight: 550;
  line-height: 1.4;
}

button:hover, .button:hover { background: var(--button-hover); }
button:disabled { opacity: .45; cursor: not-allowed; }
.quiet { color: var(--text); background: var(--surface); border-color: var(--line); }
.quiet:hover { background: var(--hover); }

button:focus-visible, a:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.topbar {
  height: 60px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: #1f1f1f;
  color: #f4f4f4;
  border-bottom: 1px solid #404040;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.6px;
  color: #fff;
  text-decoration: none;
}

.header-actions, #session { display: flex; align-items: center; gap: 18px; }
#session { font-size: 13px; }
.topbar .quiet { background: transparent; color: #e8eaed; border-color: #61666b; }
.topbar .quiet:hover { background: #333; }
.topbar :focus-visible { outline-color: #f0b45a; }

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border: 0;
  color: #d7dade;
  background: transparent;
  font-size: 12px;
  font-weight: 400;
  white-space: nowrap;
}

.theme-toggle:hover { background: transparent; color: #fff; }
.switch-track { width: 28px; height: 16px; border-radius: 10px; background: #686d72; }
.switch-track::after {
  content: "";
  display: block;
  width: 12px;
  height: 12px;
  margin: 2px;
  border-radius: 50%;
  background: #fff;
}
.theme-toggle[aria-checked="true"] .switch-track { background: #b83d30; }
.theme-toggle[aria-checked="true"] .switch-track::after { transform: translateX(12px); }

main { margin: 0 auto; }
#workspace { display: grid; grid-template-columns: 180px minmax(0, 1fr); min-height: calc(100vh - 60px); }
.work-area { padding: 26px 30px 40px; min-width: 0; max-width: 1520px; width: 100%; margin: 0 auto; }
h1 { font-size: 24px; line-height: 1.25; margin: 0; font-weight: 600; }
h2 { font-size: 16px; margin: 0; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 10px; font-weight: 600; }
p { line-height: 1.5; margin: 8px 0; }
.muted, .meta { color: var(--muted); font-size: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 5px; padding: 18px; margin-bottom: 14px; }
.login { max-width: 380px; margin: 10vh auto; padding: 28px; }
.login h1 { font-size: 21px; }
.login form { margin-top: 24px; display: grid; gap: 16px; }
.login button { margin-top: 4px; }
.page-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 22px; }

#tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 20px 10px;
  border-right: 1px solid var(--line);
  background: var(--inset);
}
#tabs button {
  padding: 10px 14px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
  text-align: left;
  font-weight: 450;
}
#tabs button:hover { background: var(--hover); color: var(--text); }
#tabs .active { border-left-color: var(--accent); background: var(--active); color: var(--accent); font-weight: 600; }
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.search { max-width: 420px; flex: 1; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text); }
input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--input);
  color: var(--text);
  padding: 9px 10px;
  min-width: 0;
  width: 100%;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:disabled, select:disabled { background: var(--inset); color: var(--muted); }
textarea { resize: vertical; }
input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--button); cursor: pointer; flex-shrink: 0; }
.check { display: flex; flex-direction: row; align-items: center; gap: 8px; }
.card-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.card-heading .meta { margin: 5px 0 0; }
.badge { font-size: 12px; background: var(--success-bg); color: var(--success-text); padding: 4px 8px; border-radius: 4px; }
.badge.warn { background: var(--warning-bg); color: var(--warning-text); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 13px; }
th { color: var(--muted); font-size: 12px; font-weight: 600; background: var(--inset); }
td, th { padding: 10px 9px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: var(--hover); }
tbody tr:has(input:checked) { background: var(--active); }
td:first-child:has(input) { width: 34px; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.totals { display: flex; gap: 26px; flex-wrap: wrap; margin-top: 14px; color: var(--muted); font-size: 12px; }
.totals strong { display: block; margin-top: 4px; font-size: 14px; color: var(--text); font-weight: 550; }
.empty { padding: 32px 18px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 5px; }
#notice {
  position: fixed;
  bottom: 20px;
  right: 20px;
  max-width: min(460px, calc(100vw - 40px));
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--success-bg);
  color: var(--success-text);
  box-shadow: 0 5px 20px #0003;
  z-index: 20;
}
.pilot-notice { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; margin: 0; padding: 10px 24px; text-align: center; font-weight: 700; background: var(--warning-bg); color: var(--warning-text); border-top: 3px solid var(--warning-text); }
body:has(.pilot-notice) { padding-bottom: var(--pilot-notice-height, 0px); }
body:has(.pilot-notice) #notice { bottom: calc(20px + var(--pilot-notice-height, 0px)); }
#notice.error { background: var(--error-bg); color: var(--error-text); }
#notice:not([hidden]) { display: flex; align-items: center; gap: 14px; }
#notice button { flex: none; color: inherit; }
#retry-panel { padding: 16px; background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--line); border-radius: 5px; margin-bottom: 18px; }
#last-result { border-left: 3px solid var(--success-text); }
dialog { border: 1px solid var(--line); border-radius: 6px; padding: 24px; width: min(1000px, calc(100vw - 32px)); max-height: 90vh; color: var(--text); background: var(--surface); }
dialog::backdrop { background: #0009; }
.dialog-heading { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 24px; }
.dialog-heading .no-print { display: flex; gap: 8px; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
#order-form > label { margin: 16px 0; }
.entry-line { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; border: 1px solid var(--line); background: var(--inset); border-radius: 4px; padding: 16px; margin-bottom: 12px; }
.entry-line .wide { grid-column: span 2; }
.entry-line button { align-self: end; }
.error-text, #order-error { color: var(--error-text); font-size: 13px; }
.access-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.access-grid .check { font-size: 12px; margin: 12px 0; }
.scope { border-left: 3px solid var(--warning-text); padding: 10px 14px; color: var(--warning-text); background: var(--warning-bg); margin-bottom: 16px; }
.account-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 12px 0; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.account-row > span { flex: 1; }
.account-row select { width: 170px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

@media (max-width: 1000px) {
  #workspace { grid-template-columns: 160px minmax(0, 1fr); }
  .work-area { padding: 22px 18px 32px; }
  .access-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .topbar { padding: 0 16px; gap: 12px; }
  .brand { font-size: 20px; }
  .header-actions, #session { gap: 12px; }
  #operator { display: none; }
  #workspace { display: block; }
  #tabs { flex-direction: row; overflow-x: auto; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  #tabs button { border-left: 0; border-bottom: 2px solid transparent; padding: 10px 12px; }
  #tabs .active { border-bottom-color: var(--accent); }
  .work-area { padding: 20px 14px 24px; }
  .page-heading { margin-bottom: 18px; }
  h1 { font-size: 22px; }
  .card { padding: 14px; }
  .card-heading { flex-wrap: wrap; gap: 10px; }
  .login { margin: 7vh 16px; max-width: none; padding: 24px; }
  .form-grid, .entry-line { grid-template-columns: 1fr; }
  .entry-line .wide { grid-column: auto; }
  .account-row { flex-wrap: wrap; }
  .account-row > span { flex-basis: 100%; }
  .toolbar { gap: 8px; }
  .table-scroll table { min-width: 640px; }
  dialog { padding: 18px; }
  .dialog-heading { align-items: flex-start; }
}

@page finance-report { size: A4 landscape; margin: 10mm; }
@page named-report { size: A4 landscape; margin: 10mm; }
@page archive-report { size: A4 landscape; margin: 10mm; }
@media print {
  :root[data-theme] {
    color-scheme: light;
    --background: #fff;
    --surface: #fff;
    --inset: #f1f1f1;
    --text: #000;
    --muted: #333;
    --line: #bbb;
    --warning-bg: #fff;
    --warning-text: #000;
  }
  body > header, main, .no-print, .pilot-notice, dialog:not(#report-dialog) { display: none !important; }
  body:has(.pilot-notice) { padding-bottom: 0; }
  #report-dialog:not([open]) { display: none !important; }
  #report-dialog[open] { display: block !important; position: static; max-height: none; width: 100%; border: 0; padding: 0; margin: 0; overflow: visible; }
  #report-dialog::backdrop { display: none; }
  body { background: #fff; color: #000; }
  table { font-size: 11px; }
  .table-scroll table { min-width: 0; }
  body:has(#report-dialog[open] .named-report-table) { page: named-report; }
  #report-dialog:has(.named-report-table) .table-scroll { overflow: visible; }
  .named-report-table { table-layout: fixed; width: 100%; }
  .named-report-table th, .named-report-table td { overflow-wrap: anywhere; padding: 4px; font-size: 9px; }
  body:has(#report-dialog[open] #archive-document), body:has(#report-dialog[open] #retained-export-document) { page: archive-report; }
  #archive-document .table-scroll, #retained-export-document .table-scroll { overflow: visible; }
  #archive-document table, #retained-export-document table { table-layout: fixed; width: 100%; }
  #archive-document th, #archive-document td, #retained-export-document th, #retained-export-document td { overflow-wrap: anywhere; padding: 4px; font-size: 9px; }
  body:has(#report-dialog[open] .finance-report-table) { page: finance-report; }
  #report-dialog:has(.finance-report-table) .table-scroll { overflow: visible; }
  .finance-report-table { width: 100%; }
  .finance-report-table thead { display: table-header-group; }
  .finance-report-table th, .finance-report-table td { padding: 5px; overflow-wrap: anywhere; }
  tr { break-inside: avoid; }
}
