/* Orders — dense desktop-style UI (port of the InvoiceLinesdapper WinForms app). */
:root {
  --bg: #f0f0f0;
  --panel: #ffffff;
  --text: #1b1b1b;
  --muted: #666;
  --border: #c8c8c8;
  --border-strong: #a0a0a0;
  --head: #e9e9e9;
  --alt: #f7f9fc;
  --sel: #cce4ff;
  --sel-strong: #3a7bd5;
  --sel-text: #000;
  --hover: #e5f0ff;
  --accent: #0b5cad;
  --danger: #b3261e;
  --ok: #e3f5e1;
  --ok-strong: #2e7d32;
  --warn: #fff4d6;
  --warn-strong: #a86b00;
  --bad: #fde3e1;
  --info: #e6f0ff;
  --grey-row: #8a8a8a;
  --menu: #fafafa;
  --input: #ffffff;
  --shadow: 0 4px 18px rgba(0,0,0,.22);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="papercut"]) {
    --bg: #1e1f22; --panel: #26282c; --text: #e4e4e4; --muted: #9a9a9a; --border: #3b3e44;
    --border-strong: #555; --head: #2f3237; --alt: #2a2c31; --sel: #23476f; --sel-strong: #5b9cf0;
    --sel-text: #fff; --hover: #2c3b50; --accent: #6aa8ff; --danger: #ff6b60; --ok: #1f3a24;
    --ok-strong: #7fd08a; --warn: #3f3418; --warn-strong: #f0c060; --bad: #4a2522; --info: #20304a;
    --grey-row: #7b7b7b; --menu: #2b2d31; --input: #1b1c1f; --shadow: 0 4px 18px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1e1f22; --panel: #26282c; --text: #e4e4e4; --muted: #9a9a9a; --border: #3b3e44;
  --border-strong: #555; --head: #2f3237; --alt: #2a2c31; --sel: #23476f; --sel-strong: #5b9cf0;
  --sel-text: #fff; --hover: #2c3b50; --accent: #6aa8ff; --danger: #ff6b60; --ok: #1f3a24;
  --ok-strong: #7fd08a; --warn: #3f3418; --warn-strong: #f0c060; --bad: #4a2522; --info: #20304a;
  --grey-row: #7b7b7b; --menu: #2b2d31; --input: #1b1c1f; --shadow: 0 4px 18px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 12px/1.35 var(--font); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--input); border: 1px solid var(--border-strong); border-radius: 2px; padding: 2px 4px; min-height: 22px; }
input[type=checkbox], input[type=radio] { min-height: 0; }
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
button { background: var(--head); border: 1px solid var(--border-strong); border-radius: 2px; padding: 2px 10px; min-height: 23px; cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { background: var(--hover); border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover:not(:disabled) { filter: brightness(1.1); background: var(--accent); }
button.danger { color: var(--danger); }
a { color: var(--accent); }

/* ---- App shell ---- */
#app { display: flex; flex-direction: column; height: 100vh; }
.menubar { display: flex; align-items: center; background: var(--menu); border-bottom: 1px solid var(--border); padding: 0 4px; min-height: 24px; user-select: none; }
.menubar .mb-item { padding: 3px 9px; cursor: default; border-radius: 2px; }
.menubar .mb-item:hover, .menubar .mb-item.open { background: var(--hover); }
.menubar .spacer { flex: 1; }
.menubar .user { color: var(--muted); padding: 0 8px; }
.menubar .dbbadge { padding: 1px 6px; border-radius: 8px; background: var(--warn); color: var(--warn-strong); margin-right: 6px; font-size: 11px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 3px 4px; background: var(--bg); border-bottom: 1px solid var(--border); }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 3px; }
.toolbar label { display: inline-flex; align-items: center; gap: 4px; }
.toolbar .grow { flex: 1; }

.tabs { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.tabstrip { display: flex; gap: 1px; padding: 3px 4px 0; background: var(--bg); border-bottom: 1px solid var(--border-strong); user-select: none; overflow-x: auto; flex: none; }
.tabstrip .tab { padding: 3px 12px; border: 1px solid var(--border); border-bottom: none; background: var(--head); border-radius: 3px 3px 0 0; cursor: pointer; white-space: nowrap; }
.tabstrip .tab.active { background: var(--panel); border-color: var(--border-strong); position: relative; top: 1px; font-weight: 600; }
.tabpanels { flex: 1; min-height: 0; position: relative; background: var(--panel); }
.tabpanel { position: absolute; inset: 0; display: none; flex-direction: column; }
.tabpanel.active { display: flex; }

.split-h { display: flex; flex: 1; min-height: 0; }
.split-v { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.split-h > *, .split-v > * { min-width: 0; min-height: 0; }
.pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; flex: 1; }
.pane-title { padding: 2px 6px; background: var(--head); border-bottom: 1px solid var(--border); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.splitter-v { width: 5px; cursor: col-resize; background: var(--bg); border-left: 1px solid var(--border); border-right: 1px solid var(--border); flex: none; }
.splitter-h { height: 5px; cursor: row-resize; background: var(--bg); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); flex: none; }
.statusbar { display: flex; gap: 12px; padding: 2px 8px; border-top: 1px solid var(--border); background: var(--menu); color: var(--muted); min-height: 20px; align-items: center; }
.statusbar .msg { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Data grid ---- */
.dg { display: flex; flex-direction: column; min-height: 0; min-width: 0; flex: 1; }
.dg-root { display: flex; flex-direction: column; flex: 1; min-height: 0; outline: none; border: 1px solid var(--border); background: var(--panel); }
.dg-root:focus-within { border-color: var(--border-strong); }
.dg-head, .dg-filters { overflow: hidden; flex: none; background: var(--head); border-bottom: 1px solid var(--border); }
.dg-hrow { display: flex; }
.dg-hcell { position: relative; padding: 2px 5px; border-right: 1px solid var(--border); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; user-select: none; flex: none; height: 21px; }
.dg-hcell.asc::after { content: " ▲"; font-size: 9px; color: var(--muted); }
.dg-hcell.desc::after { content: " ▼"; font-size: 9px; color: var(--muted); }
.dg-resize { position: absolute; right: -3px; top: 0; bottom: 0; width: 7px; cursor: col-resize; z-index: 1; }
.dg-fcell { flex: none; border-right: 1px solid var(--border); padding: 1px; }
.dg-fcell input { width: 100%; min-height: 18px; height: 18px; padding: 0 3px; font-size: 11px; border-color: var(--border); }
.dg-viewport { flex: 1; overflow: auto; position: relative; min-height: 40px; }
.dg-canvas { position: relative; }
.dg-body { position: absolute; inset: 0; }
.dg-row { position: absolute; left: 0; height: 20px; display: flex; border-bottom: 1px solid var(--border); background: var(--panel); cursor: default; }
.dg-row.alt { background: var(--alt); }
.dg-cell { flex: none; padding: 1px 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--border); line-height: 17px; }
.dg-row.sel, .dg-row.sel.alt { background: var(--sel) !important; color: var(--sel-text); }
.dg-row.focus { outline: 1px dotted var(--sel-strong); outline-offset: -1px; }
.dg-cell.editable { cursor: text; }
.dg-editor { width: 100%; height: 18px; min-height: 18px; padding: 0 3px; border: 1px solid var(--accent); }
.dg-footer { flex: none; padding: 1px 6px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--border); background: var(--head); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chk { display: inline-block; width: 12px; height: 12px; border: 1px solid var(--border-strong); border-radius: 2px; line-height: 10px; text-align: center; font-size: 10px; vertical-align: -2px; }
.chk.on { color: var(--ok-strong); }

/* Row states shared by all tabs */
.row-ok { background: var(--ok) !important; }
.row-warn { background: var(--warn) !important; }
.row-bad { background: var(--bad) !important; }
.row-info { background: var(--info) !important; }
.row-grey { color: var(--grey-row); }
.row-strike .dg-cell { text-decoration: line-through; }
.row-bold { font-weight: 600; }
.cell-ok { color: var(--ok-strong); font-weight: 600; }
.cell-warn { color: var(--warn-strong); font-weight: 600; }
.cell-bad { color: var(--danger); font-weight: 600; }
.cell-link { color: var(--accent); }
.badge { display: inline-block; padding: 0 5px; border-radius: 7px; font-size: 10px; line-height: 14px; background: var(--head); border: 1px solid var(--border); }
.badge.ok { background: var(--ok); color: var(--ok-strong); border-color: transparent; }
.badge.warn { background: var(--warn); color: var(--warn-strong); border-color: transparent; }
.badge.bad { background: var(--bad); color: var(--danger); border-color: transparent; }

/* ---- Context menu ---- */
.cm { position: fixed; z-index: 99999; min-width: 190px; background: var(--menu); border: 1px solid var(--border-strong); box-shadow: var(--shadow); padding: 2px 0; user-select: none; }
.cm-item { display: flex; align-items: center; padding: 3px 8px 3px 2px; cursor: default; white-space: nowrap; }
.cm-item.hover:not(.disabled) { background: var(--sel); color: var(--sel-text); }
.cm-item.disabled { color: var(--muted); opacity: .6; }
.cm-check { width: 20px; text-align: center; font-size: 11px; }
.cm-label { flex: 1; padding-right: 18px; }
.cm-short { color: var(--muted); font-size: 11px; padding-right: 4px; }
.cm-arrow { width: 10px; font-size: 10px; }
.cm-sep { height: 1px; background: var(--border); margin: 3px 4px 3px 22px; }

/* ---- Dialogs ---- */
.dlg-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.25); display: flex; align-items: center; justify-content: center; }
.dlg { background: var(--panel); border: 1px solid var(--border-strong); box-shadow: var(--shadow); display: flex; flex-direction: column; max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); border-radius: 3px; }
.dlg.resizable { resize: both; overflow: hidden; }
.dlg-title { display: flex; align-items: center; padding: 4px 4px 4px 10px; background: var(--head); border-bottom: 1px solid var(--border); font-weight: 600; cursor: move; user-select: none; }
.dlg-title span { flex: 1; }
.dlg-x { border: none; background: transparent; padding: 0 6px; min-height: 0; }
.dlg-body { padding: 10px 12px; overflow: auto; flex: 1; min-height: 0; }
.dlg-error { display: none; margin: 0 12px 6px; padding: 4px 8px; background: var(--bad); color: var(--danger); border-radius: 2px; white-space: pre-wrap; }
.dlg-buttons { display: flex; justify-content: flex-end; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--border); background: var(--bg); }
.dlg-buttons button { min-width: 76px; }
.dlg-buttons button.left { margin-right: auto; }
.dlg-buttons button.left ~ button.left { margin-right: 0; }
.dlg.busy { cursor: progress; }
.dlg.danger .dlg-title { color: var(--danger); }
.dlg .msg { white-space: normal; line-height: 1.5; }
.pick .msg { margin-bottom: 6px; }
.pick-grid { display: flex; min-height: 120px; }

.form { display: flex; flex-direction: column; gap: 5px; }
.form-row { display: grid; grid-template-columns: var(--label-w, 130px) 1fr; gap: 8px; align-items: start; }
.form-row > label { padding-top: 4px; color: var(--muted); }
.form-row > label.req::after { content: " *"; color: var(--danger); }
.form-input { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-width: 0; }
.form-input > input:not([type=checkbox]):not([type=radio]), .form-input > select, .form-input > textarea { flex: 1; min-width: 0; }
.form-input .readonly { padding: 3px 0; white-space: pre-wrap; }
.form-input .help { flex-basis: 100%; color: var(--muted); font-size: 11px; }
.form-input .suffix { color: var(--muted); }
.form-section { font-weight: 600; margin-top: 6px; padding-bottom: 2px; border-bottom: 1px solid var(--border); }
.radio-group { display: flex; flex-wrap: wrap; gap: 4px 12px; padding-top: 3px; }
.radio-group label { display: inline-flex; align-items: center; gap: 3px; }

/* ---- Busy + toast ---- */
#busy { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(0,0,0,.15); }
.busy-box { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--border-strong); padding: 12px 18px; box-shadow: var(--shadow); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 30px; left: 50%; transform: translate(-50%, 20px); opacity: 0; background: var(--text); color: var(--bg); padding: 6px 14px; border-radius: 3px; transition: all .25s; z-index: 100000; pointer-events: none; }
.toast.show { opacity: .92; transform: translate(-50%, 0); }

/* ---- Misc ---- */
.notes-editor { flex: 1; width: 100%; resize: none; border: none; padding: 6px; font-family: ui-monospace, Consolas, monospace; }
.doc-frame { flex: 1; border: none; width: 100%; background: #fff; }
.empty { color: var(--muted); padding: 16px; text-align: center; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; }
.kv > :nth-child(odd) { color: var(--muted); }
.md-report { font-size: 13px; line-height: 1.5; }
.md-report table { border-collapse: collapse; margin: 6px 0; }
.md-report th, .md-report td { border: 1px solid var(--border); padding: 2px 6px; }
.md-report pre { background: var(--alt); padding: 6px; overflow: auto; }

/* ---- Login ---- */
.login-wrap { display: flex; align-items: center; justify-content: center; height: 100vh; padding: 16px; }
.login-box { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--border-strong); box-shadow: var(--shadow); padding: 22px; border-radius: 4px; }
.login-box h1 { font-size: 18px; margin: 0 0 4px; }
.login-box p { margin: 0 0 16px; color: var(--muted); }
.login-box label { display: block; margin: 10px 0 3px; color: var(--muted); }
.login-box input { width: 100%; min-height: 28px; }
.login-box button { width: 100%; margin-top: 16px; min-height: 30px; }
.login-box .err { color: var(--danger); margin-top: 10px; min-height: 16px; }

@media (max-width: 700px) {
  body { overflow: auto; }
  .split-h { flex-direction: column; }
  .splitter-v { display: none; }
}

/* ---- Header (filters above the main tabs) ---- */
.header { display: flex; align-items: stretch; gap: 6px; padding: 4px; background: var(--bg); border-bottom: 1px solid var(--border); flex: none; overflow-x: auto; }
.hpanel { background: var(--panel); border: 1px solid var(--border); padding: 3px 6px 4px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.hpanel-title { font-weight: 600; }
.hrow { display: flex; align-items: center; gap: 4px; flex-wrap: nowrap; }
.hrow.period-types { gap: 8px; }
.hrow.period-types label, label.small { display: inline-flex; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.hgrid { display: grid; grid-template-columns: auto auto auto auto; gap: 3px 6px; align-items: center; }
.hgrid > label { color: var(--muted); white-space: nowrap; }
.hpanel .hint { color: var(--muted); font-size: 11px; }
.hslot { display: flex; }
.hbuttons { display: flex; gap: 4px; }
.hbtncol { display: flex; flex-direction: column; gap: 3px; }
.hbtncol button { width: 100%; }

/* ---- Lines ---- */
.dg-row.lines-ingroup-income { background: #90ee90; color: #000; }   /* Constants.IncomeColor (LightGreen) */
.dg-row.lines-ingroup-cost { background: #db7093; color: #000; }     /* Constants.CostColor (PaleVioletRed) */
.dg-cell.lines-dupref { background: #ff0000; color: #fff; }          /* duplicate-reference striping */
.addlines { display: flex; flex-direction: column; gap: 4px; height: 100%; }
.addlines .toolbar { padding: 0 0 3px; border-bottom: none; }
.addlines-label { font-weight: 600; }
.addlines-grid { display: flex; height: 200px; min-height: 120px; flex: 1; }
.addlines-detail { border-top: 1px solid var(--border); padding-top: 6px; }
.addlines-dlg .dlg-body { display: flex; flex-direction: column; min-height: 520px; }

/* ---- Misc ---- (orphan lines, settings, fuel dialogs, assistant) */
.misc-orphans-dlg .dlg-body, .misc-fuel-dlg .dlg-body, .misc-weeks-dlg .dlg-body, .misc-chat-dlg .dlg-body { display: flex; flex-direction: column; }
.misc-orphans, .misc-fuel-defaults, .misc-chat { display: flex; flex-direction: column; gap: 6px; flex: 1; min-height: 0; }
.misc-params, .misc-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; flex: none; }
.misc-actions.right { justify-content: flex-end; }
.misc-params > label { color: var(--muted); }
.misc-check { display: inline-flex; align-items: center; gap: 3px; color: var(--text) !important; }
.misc-status { color: var(--muted); margin-left: 6px; }
.misc-grid { display: flex; flex: 1; min-height: 160px; }
.misc-grid.short { flex: none; height: 170px; }
.misc-banner { color: var(--muted); flex: none; }
.misc-fuel-tabs { display: flex; flex: 1; min-height: 0; }
.misc-fuel-tabs .tabpanel.active { display: flex; }
.misc-keyrow { display: inline-flex; align-items: center; gap: 6px; }
.dg-row.misc-has-ritid { background: #c6efce; color: #000; }
.dg-row.misc-has-ritid.sel { background: #64b478; color: #000; }
.dg-row.misc-dirty .dg-cell:first-child { font-weight: 600; }
.dg-cell.misc-changed { background: #ffffe0; color: #000; }
.misc-chat-log { flex: 1; min-height: 200px; overflow: auto; border: 1px solid var(--border); background: var(--input); padding: 6px; white-space: pre-wrap; line-height: 1.45; }
.misc-chat-entry { margin-bottom: 6px; }
.misc-chat-entry.who-you b { color: #00008b; }
.misc-chat-entry.who-tool { color: var(--muted); font-size: 11px; }
.misc-chat-entry.who-error { color: #8b0000; }
.misc-chat-bottom { display: flex; gap: 6px; flex: none; }
.misc-chat-input { flex: 1; resize: vertical; }
.misc-chat-buttons { display: flex; flex-direction: column; gap: 4px; }
.misc-chat-buttons button { min-width: 90px; }
@media (prefers-color-scheme: dark) { .misc-chat-entry.who-you b { color: #8fb6ff; } .misc-chat-entry.who-error { color: var(--danger); } }

/* ---- Groups ---- */
.grp-bar { gap: 3px; }
.grp-bar button { padding: 2px 7px; }
.grp-grid { display: flex; flex: 1; min-height: 0; }
.grp-detail { display: flex; flex: 1; min-height: 0; }
.grp-quick { align-items: flex-end; }
.grp-quick label { font-size: 11px; color: var(--muted); }
.grp-stack { display: inline-flex; flex-direction: column; gap: 2px; }
.grp-stack button { min-height: 20px; padding: 0 8px; font-size: 11px; }
.grp-profit { font-size: 11px; color: var(--muted); white-space: nowrap; padding: 2px 0; }
.dg-row.grp-red { background: #ff0000 !important; color: #000; }
.dg-row.grp-approved { background: #90ee90 !important; color: #000; }
.dg-row.grp-pre { background: #20b2aa !important; color: #000; }
.dg-row.grp-dim { color: #808080; font-style: italic; }
.dg-row.grp-cost { background: #db7093 !important; }
.dg-row.grp-income { background: #90ee90 !important; }
.dg-row.grp-l-ok { color: #000; }
.dg-row.grp-l-pre { color: #2f4f4f; }
.dg-row.grp-l-none { color: #8b0000; }
.dg-row.sel.grp-red, .dg-row.sel.grp-approved, .dg-row.sel.grp-pre, .dg-row.sel.grp-cost, .dg-row.sel.grp-income { background: var(--sel) !important; color: var(--sel-text); }
.grpcopy-tabs { display: flex; gap: 2px; margin-bottom: 8px; border-bottom: 1px solid var(--border-strong); }
.grpcopy-tab { border-radius: 3px 3px 0 0; border-bottom: none; }
.grpcopy-tab.active { background: var(--panel); font-weight: 600; }
.grpcopy-page { min-height: 150px; }
.grpcopy-days { display: flex; flex-direction: column; font-family: ui-monospace, Consolas, monospace; }
.grpcopy-common { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--border); }
.grpcopy-chk { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.grpcopy-summary { margin-top: 6px; }
.grp-overview-wrap { display: flex; flex-direction: column; gap: 6px; }
.grp-overview { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 12px; white-space: pre; }

/* ---- Invoices ---- */
.inv-tab { display: flex; flex-direction: column; min-height: 0; }
.inv-tab > .split-h { flex: 1; min-height: 0; }
.inv-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; padding: 4px 6px; border-bottom: 1px solid var(--border); background: var(--panel); }
.inv-bar > label { color: var(--muted); }
.inv-bar .inv-check { color: var(--text); white-space: nowrap; }
.inv-bar .inv-template { width: 280px; }
.inv-bar .inv-search { width: 220px; }
.inv-status { color: var(--text); margin-left: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.inv-combo { display: inline-flex; align-items: center; gap: 4px; width: 140px; text-align: left; background: var(--input); padding: 2px 4px; }
.inv-combo:disabled { opacity: .7; }
.inv-combo-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv-combo-mark, .inv-invoiced { color: firebrick; font-size: 11px; }
.inv-combo-arrow { color: var(--muted); font-size: 10px; }
.inv-combo-list { position: fixed; z-index: 3000; background: var(--panel); border: 1px solid var(--border-strong); box-shadow: var(--shadow); max-height: 340px; overflow-y: auto; }
.inv-combo-item { display: flex; justify-content: space-between; gap: 12px; padding: 2px 6px; cursor: default; }
.inv-combo-item:hover { background: var(--hover); }
.inv-combo-item.sel { background: var(--sel-strong); color: #fff; }
.inv-combo-item.sel .inv-invoiced { color: #fff; }
.inv-combo-item.empty { color: var(--muted); }
.inv-grid { height: 100%; }
.inv-preview { display: flex; flex-direction: column; min-width: 0; }
.inv-preview > .tabs { flex: 1; min-height: 0; }
.inv-pane { position: relative; height: 100%; display: flex; flex-direction: column; background: var(--panel); }
.inv-pane-links { padding: 2px 6px; }
.inv-pane-links:empty { display: none; }
.inv-pane-msg { padding: 16px; color: var(--muted); }
.inv-frame { flex: 1; width: 100%; border: 0; background: #fff; }
.dg-row.inv-draft .dg-cell { color: var(--grey-row); font-style: italic; }
.dg-row.inv-draft.sel .dg-cell { color: var(--sel-text); }
.inv-rc-dlg .dlg-body { display: flex; flex-direction: column; min-height: 0; }
.inv-rc { display: flex; flex-direction: column; gap: 6px; height: 100%; min-height: 0; }
.inv-rc-prompt { white-space: pre-line; }
.inv-rc-tools { display: flex; gap: 12px; align-items: center; }
.inv-rc-scroll { flex: 1; min-height: 120px; overflow: auto; border: 1px solid var(--border); outline: none; }
.inv-rc-table { border-collapse: collapse; table-layout: fixed; width: max-content; }
.inv-rc-table th { position: sticky; top: 0; background: var(--head); font-weight: normal; text-align: left; padding: 2px 4px; border-bottom: 1px solid var(--border); }
.inv-rc-table td { padding: 1px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-bottom: 1px solid var(--alt); }
.inv-rc-table td.c { text-align: center; cursor: pointer; }
.inv-rc-table td.r { text-align: right; }
.inv-rc-table tr.current td { background: var(--sel); }
.inv-rc-table tr.extra td { color: #0000a0; }
.inv-rc-table tr.warn td { color: #b00000; }
.inv-rc-table tr.dim td { color: var(--grey-row); }
.inv-rc-table tr.line td { font-size: 12px; }
.inv-rc-indent { padding-left: 14px; }
.inv-rc-chk { display: inline-block; width: 13px; height: 13px; line-height: 12px; font-size: 10px; border: 1px solid var(--border-strong); background: var(--input); text-align: center; }
.inv-rc-chk.on { color: var(--accent); }
.inv-rc-chk.partial { color: var(--muted); }
.inv-rc-total { color: var(--muted); }
.inv-mail-form { --label-w: 90px; }
.inv-mail-info, .inv-mail-attach { margin: 4px 0; }
.inv-mail-test { margin: 4px 0; padding: 4px 6px; background: var(--warn); color: var(--warn-strong); border-radius: 3px; }
.inv-mailset { --label-w: 120px; }
.inv-mailset-dlg .dlg-body { overflow-y: auto; }
.inv-group { border: 1px solid var(--border); border-radius: 3px; margin: 0 0 8px; padding: 4px 8px 6px; }
.inv-group legend { color: var(--muted); padding: 0 4px; }
.inv-tpl { display: flex; gap: 8px; margin-bottom: 6px; }
.inv-tpl-btns { display: flex; flex-direction: column; gap: 4px; }
.dlg-overlay:has(> .inv-fuel-dlg) { background: transparent; pointer-events: none; justify-content: flex-start; }
.inv-fuel-dlg { pointer-events: auto; margin-left: 24px; }
.inv-fuel-form { --label-w: 110px; }
.inv-fuel-hintrow { margin: -2px 0 6px calc(var(--label-w) + 8px); }
.inv-fuel-hint { font-size: 12px; }
.inv-fuel-number { margin-top: 6px; color: var(--muted); }
.inv-fuel-number.warn { color: firebrick; }

/* ---- RouteBuilder ---- */
.rb { min-height: 0; }
.rb-main { display: grid; grid-template-columns: minmax(0, 1fr) 96px minmax(0, 1fr); flex: 1; min-height: 0; gap: 0; }
.rb-left, .rb-right { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.rb-left { border-right: 1px solid var(--border); }
.rb-right { border-left: 1px solid var(--border); }
.rb-lefttop label { font-size: 12px; }
.rb-src { flex: 1; min-height: 0; display: flex; }
.rb-src > .tabs { flex: 1; }
.rb-src .tabpanel { display: none; }
.rb-src .tabpanel.active { display: flex; flex-direction: column; }
.rb-grid { flex: 1; min-height: 0; display: flex; }
.rb-grid > .dg-root, .rb-grid.dg { flex: 1; }
.rb-comments { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; height: 21%; min-height: 60px; border-top: 1px solid var(--border); }
.rb-comments textarea { resize: none; width: 100%; height: 100%; }
.rb-mid { display: flex; flex-direction: column; gap: 4px; padding: 30px 4px 4px; background: var(--bg); }
.rb-mid button, .rb-mid select { width: 100%; }
.rb-mid label { font-size: 11px; color: var(--muted); margin-top: 6px; }
.rb-mid .rb-gap { height: 18px; }
.rb-right .split-v { flex: 1; }
.rb-right .pane { display: flex; }
.rb-hpanel .hgrid { grid-template-columns: auto auto auto auto auto auto; }
.rb-ghost { position: fixed; z-index: 5000; pointer-events: none; padding: 2px 8px; background: var(--accent); color: #fff; border-radius: 3px; font-size: 11px; }
/* wizard */
.wz-dlg .dlg-body { padding: 6px 8px; }
.wz { display: flex; flex-direction: column; gap: 6px; }
.wz-page { display: flex; flex-direction: column; gap: 3px; }
.wz-pagehead { font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.wz-row { display: grid; grid-template-columns: 110px minmax(0, 1fr); align-items: center; gap: 6px; }
.wz-row > label { color: var(--muted); }
.wz-ctl { display: flex; align-items: center; gap: 6px; min-width: 0; }
.wz-btns { display: flex; gap: 4px; }
.wz-invalid { color: #d00 !important; }
.wz-warn { background: #ffb3b3 !important; color: #000; }
.wz-stale { background: #ffb3b3 !important; color: #000; }
.wz-bad { outline: 1px solid #d00; }
.wz-prices { border: 1px solid var(--border); padding: 4px; margin: 4px 0; }
.wz-tabs { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 1px solid var(--border-strong); margin-bottom: 4px; }
.wz-tab { border-radius: 3px 3px 0 0; border-bottom: none; font-size: 11px; padding: 2px 6px; }
.wz-tab.active { background: var(--panel); font-weight: 600; }
.wz-grid { display: grid; grid-template-columns: repeat(6, auto); justify-content: start; align-items: center; gap: 4px 6px; }
.wz-num { text-align: right; }
.wz-ratebar { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.wz-total { font: 600 20px ui-monospace, Consolas, monospace; }
.wz-shellbar { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--border); padding-top: 6px; }
.wz-boxes { display: flex; gap: 8px; flex-wrap: wrap; }
.wz-box { border: 1px solid var(--border); padding: 2px 8px 6px; display: flex; gap: 10px; align-items: center; margin: 0; }
.wz-box legend { font-size: 11px; color: var(--muted); padding: 0 3px; }
.wz-buttons { display: flex; gap: 6px; justify-content: flex-end; }
/* order dialogs */
.eo { height: 600px; display: flex; flex-direction: column; }
.eo .tabpanel { overflow: auto; padding: 6px; }
.eo-cols { display: grid; grid-template-columns: minmax(0, 1fr) 120px minmax(0, 1fr); gap: 8px; margin-top: 6px; }
.eo-mid { display: flex; flex-direction: column; gap: 4px; padding-top: 40px; }
.eo-mid .eo-sep { height: 120px; }
.of { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 6px; height: 620px; }
.of-left { display: flex; flex-direction: column; min-height: 0; }
.of-grid { flex: 1; min-height: 0; display: flex; }
.of-preview { border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; overflow: auto; background: var(--bg); }
.of-preview iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.of-preview img { max-width: 100%; max-height: 100%; }
.aa { display: flex; flex-direction: column; gap: 4px; }
.aa-grid { height: 170px; display: flex; flex: none; }
.aa-new { display: flex; align-items: flex-end; gap: 8px; }
.aa-new .form { flex: 1; }
.aa-label { font-weight: 600; align-self: flex-start; white-space: nowrap; }
.pd-grid { height: 230px; display: flex; flex: none; }
.pd-text { max-height: 220px; overflow: auto; font-size: 11px; border: 1px solid var(--border); padding: 4px; white-space: pre-wrap; }
.lk-grid { height: 300px; display: flex; flex: none; margin: 6px 0; }
.ca-grid { height: 300px; display: flex; flex: none; margin: 6px 0; }
.ca-status { color: var(--muted); min-height: 18px; }

/* ---- WinForms layout engine (js/bis/ui/winforms.js) ---- */
.wf { position: absolute; box-sizing: border-box; margin: 0; }
.wf-form { position: absolute; overflow: hidden; font: 12px/1.25 "Segoe UI", Tahoma, system-ui, sans-serif; }
.wf-form button, .wf-form input, .wf-form select, .wf-form textarea { font-size: 12px; min-height: 0; }
.wf-form button.wf { padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.wf-form button.wf img { max-height: 16px; }
.wf-form input.wf, .wf-form select.wf { padding: 1px 3px; }
.wf-form textarea.wf { resize: none; padding: 2px 4px; }
.wf-label { white-space: pre; overflow: visible; padding-top: 1px; }
.wf-label.wf-label-wrap { white-space: pre-wrap; }
.wf-check { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; cursor: pointer; }
.wf-check input { margin: 0; }
.wf-check.wf-disabled { color: var(--muted); cursor: default; }
.wf-form input:disabled, .wf-form select:disabled, .wf-form textarea:disabled { opacity: .6; cursor: default; }
.wf-border { border: 1px solid var(--border-strong); }
.wf-border3d { border: 2px inset var(--border); }
.wf-panel, .wf-splitpanel, .wf-tabpage, .wf-SplitContainer { overflow: hidden; }
.wf-group { border: 1px solid var(--border-strong); border-radius: 3px; padding: 0; overflow: hidden; }
.wf-group > legend { font-size: 12px; padding: 0 3px; margin-left: 6px; }
/* GroupBox children are placed from the box's top edge, as in WinForms: the legend must not push them down. */
.wf-group { border: none; }
.wf-group::before { content: ''; position: absolute; inset: 6px 0 0 0; border: 1px solid var(--border-strong); border-radius: 3px; pointer-events: none; }
.wf-group > legend { position: absolute; top: 0; left: 0; line-height: 13px; background: var(--panel); z-index: 1; }
.wf-list { overflow-y: auto; }
.wf-browser { border: 1px solid var(--border); background: var(--panel); }
.wf-grid { background: var(--panel); border: 1px solid var(--border-strong); overflow: hidden; }
.wf-grid > .dg { height: 100%; }
/* TabControl */
.wf-TabControl { background: var(--bg); }
.wf-tabheader { position: absolute; left: 0; top: 0; right: 0; height: 22px; display: flex; align-items: flex-end; gap: 1px; padding-left: 2px; border-bottom: 1px solid var(--border-strong); overflow: hidden; }
.wf-tab { padding: 2px 9px 3px; border: 1px solid var(--border-strong); border-bottom: none; border-radius: 3px 3px 0 0; background: var(--head); cursor: pointer; white-space: nowrap; user-select: none; }
.wf-tab.active { background: var(--panel); position: relative; top: 1px; padding-bottom: 4px; font-weight: 600; }
.wf-tabpage { display: none; background: var(--panel); border: 1px solid var(--border-strong); border-top: none; }
.wf-tabpage.active { display: block; }
/* SplitContainer */
.wf-splitbar-v { cursor: col-resize; background: var(--border); }
.wf-splitbar-h { cursor: row-resize; background: var(--border); }
/* ToolStrip / StatusStrip / MenuStrip */
.wf-toolstrip, .wf-statusstrip { display: flex; align-items: center; gap: 2px; padding: 0 3px; background: var(--head); border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; }
.wf-statusstrip { border-top: 1px solid var(--border); border-bottom: none; }
.wf-tlabel { padding: 0 3px; }
.wf-tsep { width: 1px; align-self: stretch; margin: 3px 3px; background: var(--border-strong); }
.wf-tbutton { border: 1px solid transparent; background: transparent; padding: 1px 4px; min-height: 0; display: inline-flex; align-items: center; gap: 3px; }
.wf-tbutton:hover:not(:disabled) { border-color: var(--accent); background: var(--hover); }
.wf-tbutton img { width: 16px; height: 16px; }
.wf-toolstrip select, .wf-toolstrip input, .wf-statusstrip select { height: 21px; }
.wf-right { margin-left: auto; }
.wf-MenuStrip .menubar { height: 24px; }
/* Items inside a strip flow; only the strip itself is placed. */
.wf-toolstrip > .wf, .wf-statusstrip > .wf { position: static; flex: none; }
.wf-tlabel { flex: none; }
/* A form in a dialog (js/bis/forms.js) */
.wf-dialog .dlg-body { padding: 0; position: relative; overflow: hidden; }
.wf-dialog .dlg-buttons, .wf-dialog .dlg-error { display: none !important; }
.wf-host { position: absolute; inset: 0; }
.dlg-overlay:has(> .wf-modeless) { background: transparent; pointer-events: none; }
.wf-modeless { pointer-events: auto; }
/* A DataGridView cell highlighted as matching (FormCheckInvoiceAmount: back 198,239,206, fore 0,97,0, bold). */
.dg-cell.cell-match { background: var(--ok); color: var(--ok-strong); font-weight: bold; }
/* TreeView and CheckedListBox (winforms.js treeView / checkedList) */
.wf-tree { background: var(--panel); border: 1px solid var(--border-strong); overflow: auto; user-select: none; }
.wf-tree ul { list-style: none; margin: 0; padding: 0 0 0 16px; }
.wf-tree > ul { padding: 2px 0 0 2px; }
.wf-tree-row { display: flex; align-items: center; gap: 2px; cursor: default; white-space: nowrap; }
.wf-tree-toggle { width: 12px; text-align: center; color: var(--muted); cursor: pointer; flex: none; }
.wf-tree-text { padding: 0 3px; }
.wf-tree-row.sel .wf-tree-text { background: var(--accent); color: #fff; }
.wf-checklist { background: var(--panel); border: 1px solid var(--border-strong); overflow-y: auto; }
.wf-checklist-item { display: flex; align-items: center; gap: 3px; padding: 0 2px; white-space: nowrap; }
.wf-checklist-item input { margin: 0; }
.wf-checklist-item.sel { background: var(--accent); color: #fff; }
.dg-cell.wf-cellsel { background: var(--accent); color: #fff; }   /* DataGridView cell selection (SelectionMode CellSelect) */
/* A DataGridViewButtonColumn cell's button (render: '<button class="dg-cellbtn">') */
.dg-cell .dg-cellbtn { height: 17px; min-height: 0; width: 100%; padding: 0 2px; font-size: 11px; line-height: 1; vertical-align: top; }
/* The main window's grids (js/bis/main/wingrid.js): white text on the row colour from CellFormatting,
   the system highlight for the selection, the row header, filtered headers yellow. */
html body .wf-form .wg-main .dg-row, html body .wf-form .wg-main .dg-row.alt { color: #fff; background: #000; }
/* The system highlight; stronger than the theme's selection (html[data-theme] … .dg-row.sel). */
html body .wf-form .wg-main .dg-row.sel, html body .wf-form .wg-main .dg-row.sel.alt { background: #0078d7 !important; color: #fff; box-shadow: none; }
html body .wf-form .wg-main .dg-row.focus { outline: 1px dotted #fff; outline-offset: -2px; }
.wg-main .dg-cell.wg-rowheader, .wg-main .dg-hcell:first-child { position: sticky; left: 0; z-index: 1; }
.wg-main .dg-cell.wg-rowheader { background: var(--head); color: var(--text); border-right: 1px solid var(--border-strong); overflow: hidden; text-overflow: clip; }
.wg-main .dg-row.wg-lastfrozen { box-shadow: inset 0 -3px 0 var(--border-strong); }
.wg-main .dg-hcell.wg-hfiltered { background: yellow; color: #000; }
/* Edit mode (DataGridViewChangeManager2): an edited cell is DarkOrange (lefttabs.js). */
.wg-main .dg-cell.wg-cellmod { background: DarkOrange; }
.wf-wrap { flex-wrap: wrap; align-content: flex-start; overflow: visible; height: auto; }
.wf-loading { cursor: progress; }
.wf-loading::after { content: 'Loading…'; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--panel); border: 1px solid var(--border-strong); padding: 10px 18px; box-shadow: var(--shadow); }
.vf-list { overflow: auto; background: var(--input); border: 1px solid var(--border-strong); }
.vf-tree { overflow: auto; }
.vf-tree ul { list-style: none; margin: 0; padding-left: 14px; }
.wf-tgroup { display: inline-flex; align-items: center; gap: 2px; flex: none; height: 26px; }
.wf-tgroup > .wf { position: static; flex: none; }
/* righttabs.js: an edited cell in the plain grids (companies), and a WinGrid with the default
   DataGridView colours (black on white, All Journal Entries). */
.dg-cell.wg-cellmod { background: DarkOrange; }
html body .wf-form .wg-main.wg-plain .dg-row, html body .wf-form .wg-main.wg-plain .dg-row.alt { color: var(--text); background: var(--panel); border-bottom-color: var(--border); }
/* Tabs that don't fit: the strip scrolls sideways (wheel or drag), where WinForms shows its arrows. */
.wf-tabheader { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.wf-tabheader::-webkit-scrollbar { display: none; }

/* Grid lines, as the WinForms DataGridView draws them: a thin dark line between every column and
   every row, in both styles (html body … outranks the themes' lighter cell borders). */
:root { --grid-line: #6b6b6b; }
html body .dg-row { border-bottom: 1px solid var(--grid-line); }
html body .dg-cell, html body .dg-hcell { border-right: 1px solid var(--grid-line); }
html body .dg-head { border-bottom: 1px solid var(--grid-line); }
/* Frozen (bookmarked) rows stay at the top while the rest scrolls under them (ui/grid.js),
   with the divider below the last one as DataGridView draws it (DividerHeight). */
.dg-row.dg-frozen { z-index: 2; }
.dg-frozen-divider { position: absolute; left: 0; z-index: 2; background: var(--grid-line, #6b6b6b); }
