/* ===================== Theme: semantic colours, light by default, dark from the system =====================
   The whole interface follows prefers-color-scheme (also when it changes while the page is open).
   Document images, thumbnails and the paper behind them are never recoloured; overlay colours (--ov-*,
   --select) are fixed because they are drawn on the original page image. */
.review-queue { max-width: 1050px; margin: 24px auto; padding: 0 20px; }
.review-queue article { padding: 16px; margin: 16px 0; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.review-queue nav { display: flex; gap: 12px; flex-wrap: wrap; }
#review-dialog { width: min(560px, calc(100vw - 40px)); max-height: 85vh; overflow: auto; padding: 24px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: var(--panel); }
#review-dialog::backdrop { background: rgb(0 0 0 / 40%); }
#review-sections { display: grid; gap: 10px; margin-bottom: 16px; }
#review-sections label { display: flex; gap: 8px; align-items: center; }
#review-sections [hidden] { display: none; }
.review-section details { margin: 6px 0 0 24px; }
.review-section summary { cursor: pointer; font-size: .9em; }
.review-fields { max-height: 220px; overflow: auto; display: grid; gap: 8px; padding: 8px 0; }
.review-section input[type=search] { width: 100%; margin-top: 8px; }
#review-dialog input[type=checkbox] { width: auto; }
#review-comment { display: block; width: 100%; margin: 8px 0; box-sizing: border-box; }
#review-error { color: var(--error); }
:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --surface-2: #f3f4f6;
  --viewer-bg: #e5e7eb;
  --paper: #ffffff;
  --text: #1f2328;
  --muted: #5f6673;
  --muted-2: #9ca3af;
  --line: #d9dde3;
  --line-strong: #cbd5e1;
  --accent: #1d4ed8;
  --accent-fill: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.10);
  --on-strong: #ffffff;
  --focus: #2563eb;
  --ok: #15803d;
  --ok-border: #16a34a;
  --ok-fill: #15803d;
  --ok-text: #166534;
  --ok-soft: #dcfce7;
  --warn-border: #d97706;
  --warn-soft: #fef3c7;
  --warn-line: #fdba74;
  --warn-text: #92400e;
  --danger-soft: #fef2f2;
  --danger-line: #fecaca;
  --danger-text: #991b1b;
  --error: #b91c1c;
  --error-line: #dc2626;
  --selected-ring: #dc2626;
  --info-soft: #eff6ff;
  --info-line: #93c5fd;
  --info-text: #075985;
  --neutral-strong: #475569;
  --strong-bg: #1f2937;
  --strong-text: #f9fafb;
  --shadow: rgba(0, 0, 0, 0.2);
  --count-bg: rgba(0, 0, 0, 0.08);
  --count-on-strong: rgba(255, 255, 255, 0.22);
  --diag-text: #d1fae5;
  /* fixed: drawn on the original page image in both themes */
  --ov-accent: #2563eb;
  --ov-accent-soft: rgba(37, 99, 235, 0.10);
  --select: #dc2626;
  --select-soft: rgba(220, 38, 38, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --panel: #171b22;
    --surface-2: #1f242d;
    --viewer-bg: #0b0e12;
    --text: #e7e9ec;
    --muted: #a3acb9;
    --muted-2: #6f7886;
    --line: #333a46;
    --line-strong: #4b5465;
    --accent: #8ab4ff;
    --accent-fill: #2f63d6;
    --accent-soft: rgba(138, 180, 255, 0.16);
    --focus: #8ab4ff;
    --ok: #4ade80;
    --ok-border: #22c55e;
    --ok-fill: #15803d;
    --ok-text: #86efac;
    --ok-soft: rgba(34, 197, 94, 0.16);
    --warn-border: #f59e0b;
    --warn-soft: rgba(245, 158, 11, 0.16);
    --warn-line: #a16207;
    --warn-text: #fcd34d;
    --danger-soft: rgba(248, 113, 113, 0.14);
    --danger-line: #7f1d1d;
    --danger-text: #fca5a5;
    --error: #fca5a5;
    --error-line: #f87171;
    --selected-ring: #f87171;
    --info-soft: rgba(96, 165, 250, 0.14);
    --info-line: #1e40af;
    --info-text: #93c5fd;
    --neutral-strong: #64748b;
    --strong-bg: #2a3140;
    --strong-text: #f3f4f6;
    --shadow: rgba(0, 0, 0, 0.55);
    --count-bg: rgba(255, 255, 255, 0.12);
  }
}

* { box-sizing: border-box; }
/* The hidden attribute must win over component display rules (banner, ack bar, panels). */
[hidden] { display: none !important; }
body { margin: 0; font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); }
.muted { color: var(--muted); }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 8px; background: var(--warn-soft); color: var(--warn-text); }

.topbar { height: 44px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; text-decoration: none; color: var(--text); }
.logout { display: flex; gap: 8px; align-items: center; margin: 0; }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 4px 10px; cursor: pointer; font: inherit; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent-fill); color: var(--on-strong); border-color: var(--accent-fill); padding: 6px 14px; }
.btn-link { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

.narrow { max-width: 560px; margin: 32px auto; padding: 0 16px; }
.doc-list { padding-left: 18px; }
.doc-list li { margin: 6px 0; }

/* Two-pane workspace: image left, form right. */
.workspace { display: grid; grid-template-columns: 1fr 420px; height: calc(100vh - 44px); }
.viewer-pane { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--line); }
.viewer-toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs, .zoom, .region-tools { display: flex; gap: 4px; align-items: center; }
.tab { border: 1px solid var(--line); background: var(--panel); padding: 4px 10px; border-radius: 6px; cursor: pointer; font: inherit; }
.tab.active { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--on-strong); }
#zoom-label { min-width: 44px; text-align: center; color: var(--muted); }

.viewer { flex: 1; overflow: auto; padding: 16px; background: var(--viewer-bg); }
.page-stage { position: relative; margin: 0 auto; background: var(--paper); box-shadow: 0 1px 4px var(--shadow); }
.page-stage img, .overlay { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; }
.overlay { touch-action: none; }
.overlay.drawing { cursor: crosshair; }

.region .box { fill: var(--ov-accent-soft); stroke: var(--ov-accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; cursor: move; }
.region.hover .box { fill: rgba(37, 99, 235, 0.25); stroke-width: 3; }
.region.selected .box { fill: var(--select-soft); stroke: var(--select); stroke-width: 2.5; }
.region .handle { fill: var(--select); cursor: nwse-resize; }
.overlay .temp { fill: var(--select-soft); stroke: var(--select); stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }

.form-pane { display: flex; flex-direction: column; background: var(--panel); min-height: 0; }
.form-head { padding: 12px 16px 4px; }
.form-head h1 { font-size: 16px; margin: 0 0 2px; }
.hint { background: var(--warn-soft); border: 1px solid var(--warn-line); padding: 6px 8px; border-radius: 6px; }
#record-form { flex: 1; overflow: auto; padding: 0 16px; }
fieldset { border: 0; border-top: 1px solid var(--line); margin: 8px 0 0; padding: 8px 0; }
legend { font-weight: 600; padding: 0 4px 0 0; }
.row { display: flex; gap: 8px; }
.row .field { flex: 1; min-width: 0; }
.field { padding: 3px 4px; border-radius: 6px; margin: 2px -4px; }
.field label { display: block; font-size: 12px; color: var(--muted); }
.field label::after { content: " ○"; color: var(--muted-2); }
.field.has-region label::after { content: " ●"; color: var(--accent); }
.field input { width: 100%; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; font: inherit; }
.field.hover { background: var(--accent-soft); }
.field.selected { outline: 2px solid var(--selected-ring); }
.item { border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; margin-bottom: 6px; }
.item-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); padding: 2px 4px; border-radius: 4px; cursor: pointer; }
.item-head.has-region .item-id::after { content: " ● wiersz"; color: var(--accent); }
.item-head.hover { background: var(--accent-soft); }
.item-head.selected { outline: 2px solid var(--selected-ring); }

.actions { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 10px 16px; border-top: 1px solid var(--line); }
.status { color: var(--muted); font-size: 13px; }
.status.ok { color: var(--ok); }
.status.error { color: var(--error); }
.exports { padding: 0 16px 12px; font-size: 13px; color: var(--muted); }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; height: auto; }
  .viewer { height: 60vh; }
}

.small { font-size: 12px; }
.notice { background: var(--info-soft); border: 1px solid var(--info-line); padding: 6px 8px; border-radius: 6px; font-size: 13px; margin: 6px 0; }
.review { margin: 0 16px 4px; border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; font-size: 13px; }
.review summary { cursor: pointer; font-weight: 600; }
.review p { margin: 4px 0; }
.review-group { margin: 6px 0; }
.review ul { list-style: none; margin: 4px 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; max-height: 84px; overflow: auto; }
.review li button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 1px 8px; cursor: pointer; font: inherit; font-size: 12px; }
.review li button:hover { border-color: var(--accent); }
.review .none { color: var(--muted); font-size: 12px; }
.field.empty input { border-style: dashed; background: var(--surface-2); }
.item.all-empty { border-color: var(--warn-border); background: var(--warn-soft); }
.item.all-empty .item-id::before { content: "pusta pozycja · "; color: var(--warn-text); }

/* Browser OCR */
.ocr-tools { display: flex; gap: 6px; align-items: center; }
.ocr-status { font-size: 12px; color: var(--muted); max-width: 320px; }
.ocr-status.ok { color: var(--ok); }
.ocr-status.error { color: var(--error); }
.btn.active { background: var(--warn-soft); border-color: var(--warn-border); }
.ocr-word { fill: rgba(245, 158, 11, 0.08); stroke: rgba(217, 119, 6, 0.8); stroke-width: 1; stroke-dasharray: 3 2; vector-effect: non-scaling-stroke; pointer-events: none; }
.ocr-word.picked { fill: rgba(245, 158, 11, 0.35); stroke: #b45309; stroke-dasharray: none; stroke-width: 2; }
.overlay.ocr-pick .ocr-word { pointer-events: all; cursor: pointer; }
.overlay.ocr-pick .ocr-word:hover { fill: rgba(245, 158, 11, 0.25); }
.overlay.ocr-pick g.region { pointer-events: none; opacity: 0.55; }
.proposal { background: var(--warn-soft); border: 1px solid var(--warn-border); border-radius: 6px; padding: 8px; margin: 6px 0; font-size: 13px; }
.proposal-value { font-size: 15px; margin: 4px 0; }
.proposal-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0 4px; }
.trial-banner { background: var(--danger-soft); border: 1px solid var(--danger-line); color: var(--danger-text); padding: 8px 12px; border-radius: 6px; margin: 8px 0; }
.trial-text { width: 100%; min-height: 120px; font: 13px/1.4 ui-monospace, monospace; }
.trial-body { padding: 0 16px; }

/* Prefill verification */
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg { border: 0; background: var(--panel); padding: 4px 10px; font: inherit; cursor: pointer; }
.seg + .seg { border-left: 1px solid var(--line); }
.seg[aria-pressed="true"] { background: var(--warn-soft); font-weight: 600; }
.check { display: inline-flex; gap: 4px; align-items: center; }
.notice.prefill { background: var(--warn-soft); border-color: var(--warn-line); }
.match-panel { margin-top: 4px; }
.match-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 140px; overflow: auto; }
.match-list li { margin: 2px 0; }
.match-list button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 6px; padding: 2px 8px; cursor: pointer; font: inherit; font-size: 12px; text-align: left; width: 100%; }
.match-list button.match-review { border-color: var(--warn-border); }
.match-list button.match-not_found { border-color: var(--muted-2); color: var(--muted); }
.match-box { margin: 6px 16px; }
.match-badge { font-size: 11px; padding: 0 5px; border-radius: 8px; margin-left: 4px; white-space: nowrap; }
.match-badge.match-matched { background: var(--ok-soft); color: var(--ok-text); }
.match-badge.match-review { background: var(--warn-soft); color: var(--warn-text); }
.match-badge.match-not_found { background: var(--surface-2); color: var(--muted); }
.match-prop { fill: none; stroke-width: 2; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; pointer-events: none; }
.match-prop.match-matched { stroke: #16a34a; }
.match-prop.match-review { stroke: #d97706; }
.match-prop.current { stroke-width: 3.5; stroke-dasharray: none; }

/* Active operation banner, cancel/undo */
.op-banner { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 6px 12px; background: var(--strong-bg); color: var(--on-strong); font-size: 13px; }
.op-banner .btn { background: var(--panel); }
.field.op-active { outline: 3px solid var(--warn-border); outline-offset: 1px; }
.item-head.op-active { outline: 3px solid var(--warn-border); }
.region.op-active .box { stroke: #f59e0b; stroke-width: 3.5; }
.exports-note { padding: 0 16px 12px; margin: 0; }
.trial-file { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; font-size: 13px; margin: 8px 0; }
.trial-file dt { color: var(--muted); }
.trial-file dd { margin: 0; overflow-wrap: anywhere; }
.admin-export a { margin: 0 2px; }

/* OCR selection, inline errors, approval */
.select-rect { fill: rgba(245, 158, 11, 0.12); stroke: #d97706; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; pointer-events: none; }
.field-error { color: var(--error); font-size: 12px; margin-top: 2px; }
.field.invalid input { border-color: var(--error-line); background: var(--danger-soft); }
.approve-confirm { margin: 6px 16px; }
.approve-confirm ul { margin: 4px 0; padding-left: 18px; max-height: 140px; overflow: auto; font-size: 12px; }

/* Admin intake */
.narrow.wide { max-width: 1100px; }
.intake-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.intake-table th, .intake-table td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.tag.state-pending { background: var(--info-soft); color: var(--info-text); }
.tag.state-accepted { background: var(--ok-soft); color: var(--ok-text); }
.tag.state-rejected { background: var(--danger-soft); color: var(--danger-text); }
.tag.state-deferred { background: var(--warn-soft); color: var(--warn-text); }
.intake { display: grid; grid-template-columns: 1fr 360px; height: calc(100vh - 44px); }
.intake-variants { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; padding: 12px; overflow: auto; background: var(--viewer-bg); align-content: start; }
.variant { background: var(--panel); border: 2px solid transparent; border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
.variant:has(input:checked), .variant.chosen { border-color: var(--accent); }
.variant img { width: 100%; max-height: 70vh; object-fit: contain; background: var(--surface-2); }
.variant-head { display: flex; flex-direction: column; }
.intake-side { padding: 12px 16px; background: var(--panel); border-left: 1px solid var(--line); overflow: auto; }
.intake-side h1 { font-size: 16px; margin: 4px 0; }
.intake-comment { width: 100%; font: inherit; }
.intake-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; align-items: center; }
.intake-log { padding-left: 16px; }
.legacy { display: grid; grid-template-columns: max-content 1fr; gap: 2px 8px; font-size: 12px; margin: 4px 0; }
.legacy dt { color: var(--muted); }
.legacy dd { margin: 0; overflow-wrap: anywhere; }
.overlay.selecting { cursor: crosshair; }
.overlay.selecting g.region, .overlay.selecting .ocr-word { pointer-events: none; }
.legacy-raw { white-space: pre-wrap; font-size: 11px; max-height: 160px; overflow: auto; background: var(--surface-2); padding: 4px; }
.legacy-products { padding-left: 18px; max-height: 120px; overflow: auto; }

/* Field acknowledgement */
.ack-bar { display: flex; gap: 6px; margin-top: 4px; }
.ack-bar .btn { padding: 2px 8px; font-size: 12px; }
.ack-bar .ack-ok { border-color: var(--ok-border); color: var(--ok-text); }
.field.ack-accepted input { border-color: var(--ok-border); background: var(--ok-soft); }
.field.ack-accepted label::before { content: "✓ "; color: var(--ok-border); font-weight: 700; }
.field.ack-absent input { border-style: dotted; background: var(--surface-2); }
.field.ack-absent label::before { content: "∅ brak · "; color: var(--muted); font-weight: 600; }

/* Menu + tutorial */
.menu { display: flex; gap: 14px; margin-left: 24px; margin-right: auto; font-size: 14px; }
.menu a { text-decoration: none; color: var(--text); }
.menu a:hover { color: var(--accent); }
.tutorial { margin: 8px 16px 0; padding: 8px 10px; border: 1px solid var(--info-line); background: var(--info-soft); border-radius: 8px; font-size: 13px; }
.tutorial-head { display: flex; gap: 8px; align-items: baseline; }
.tutorial-links { margin-left: auto; }
.tutorial-steps { margin: 6px 0; padding-left: 20px; }
.tutorial-steps li { margin: 2px 0; }
.tutorial-nav { display: flex; gap: 8px; align-items: center; }
.tutorial-reset { margin: 0 0 0 auto; }

/* ===================== UX v3 shell: sticky chrome, two independent vertical scrolls ===================== */
html, body { height: 100%; }
body { overflow-x: hidden; }
.topbar { position: sticky; top: 0; z-index: 20; min-width: 0; gap: 12px; }
.brand { white-space: nowrap; }
.menu { min-width: 0; overflow: hidden; }
.logout { min-width: 0; }
.logout .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 16ch; }

/* Desktop editor: the page itself never scrolls; the image and the fields scroll separately. */
body:has(.workspace) { overflow: hidden; }
.workspace { height: calc(100vh - 44px); height: calc(100dvh - 44px); grid-template-columns: minmax(0, 1fr) minmax(320px, 420px); min-height: 0; }
.viewer-pane { min-height: 0; min-width: 0; overflow: hidden; }
.viewer-toolbar { flex: none; row-gap: 6px; }
.viewer-toolbar > * { min-width: 0; }
.op-banner { flex: none; }
.viewer { flex: 1 1 auto; min-height: 0; min-width: 0; overflow: auto; overscroll-behavior: contain; }
.form-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; }
.form-head { flex: none; padding: 10px 16px 6px; border-bottom: 1px solid var(--line); min-width: 0; }
.form-head h1 { margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { margin: 2px 0 0; overflow-wrap: anywhere; }
.prefill-tag { background: var(--warn-soft); color: var(--warn-text); }
.fields-scroll, #record-form.fields-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 0 16px 12px; }
.fields-scroll .field, .fields-scroll .row, .fields-scroll .item { min-width: 0; }
.fields-scroll .field { scroll-margin: 12px; }
.form-footer { flex: none; border-top: 1px solid var(--line); background: var(--panel); min-width: 0; }
.form-footer .proposal { margin: 8px 16px 0; max-height: 30vh; overflow: auto; }
.form-footer .actions { border-top: 0; }
.status { min-width: 0; overflow-wrap: anywhere; }
.tutorial { flex: none; max-height: 32vh; overflow: auto; }

/* Long content never widens the layout. */
.doc-list li, .intake-table td, .match-list button, .legacy dd, .approve-confirm li, .ocr-status, #op-text, .tag { overflow-wrap: anywhere; }
.doc-list a { overflow-wrap: anywhere; }
.intake-table { table-layout: fixed; }
.intake-table .cell-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field input { min-width: 0; text-overflow: ellipsis; }
.intake { min-width: 0; }
.intake-side { min-width: 0; overflow-wrap: anywhere; }
.intake-side h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.narrow { max-width: min(560px, 100%); }
.narrow.wide { max-width: min(1100px, 100%); }

/* Field rows wrap instead of being clipped by the fields pane. */
.row { flex-wrap: wrap; }
.row .field { flex: 1 1 88px; }
.field label { overflow-wrap: anywhere; }

/* Narrow viewports: stack panes, page scrolls, save stays reachable. */
@media (max-width: 900px) {
  .topbar { height: auto; min-height: 44px; flex-wrap: wrap; padding: 6px 12px; row-gap: 4px; }
  .menu { overflow: visible; flex-wrap: wrap; margin-right: 0; }
  .logout .muted { display: none; }
  body:has(.workspace) { overflow: auto; }
  .workspace { display: flex; flex-direction: column; height: auto; }
  .viewer-pane { height: 60vh; height: 60dvh; border-right: 0; border-bottom: 1px solid var(--line); }
  .viewer { height: auto; }
  .form-pane { overflow: visible; }
  .fields-scroll, #record-form.fields-scroll { overflow: visible; }
  .form-footer { position: sticky; bottom: 0; z-index: 10; }
  .menu { margin-left: 8px; gap: 8px; }
  .intake { grid-template-columns: 1fr; height: auto; }
}

/* ===================== UX v4: continuous pages + canonical form ===================== */
.viewer { padding: 12px 16px 24px; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 18px; min-width: 0; }
.page-wrap { display: flex; flex-direction: column; align-items: stretch; gap: 4px; max-width: 100%; }
.page-bar { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.page-bar .btn-rotate { padding: 0 8px; font-size: 14px; line-height: 22px; }
.page-label { margin-right: auto; font-weight: 600; }
.page-stage { position: relative; background: var(--paper); box-shadow: 0 1px 4px var(--shadow); flex: none; }
.page-img { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; }
.pages.selecting .overlay { cursor: crosshair; }
.pages.selecting g.region, .pages.selecting .ocr-word { pointer-events: none; }
.match-badge.match-location { background: var(--info-soft); color: var(--info-text); }
.canon-form fieldset.canon-section { border: 0; border-top: 1px solid var(--line); margin: 8px 0 0; padding: 6px 0; }
.canon-form legend { font-weight: 600; padding-right: 6px; }
.canon-sub { margin: 4px 0 6px; padding-left: 8px; border-left: 2px solid var(--line); }
.canon-sub-title { font-size: 12px; font-weight: 600; color: var(--muted); margin: 4px 0 2px; }
.canon-row { border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; margin-bottom: 6px; }
.canon-scalar-row { display: flex; gap: 6px; align-items: end; }
.canon-scalar-row .field { flex: 1 1 auto; }
.canon-add, .canon-add-row { margin: 2px 0 4px; }
.canon-remove { float: right; }
.canon-leaves .field { flex: 1 1 120px; }
.field textarea { width: 100%; min-width: 0; font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; resize: vertical; }
.field select { width: 100%; min-width: 0; font: inherit; padding: 3px 4px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); }
.field.ack-accepted select, .field.ack-accepted textarea { border-color: var(--ok-border); background: var(--ok-soft); }
.ack-bar .btn-link { font-size: 12px; }

/* UX v5: page load error on the page itself; ?diag=1 layout metrics */
.page-error { position: absolute; left: 12px; right: 12px; top: 12px; padding: 8px 10px; background: var(--danger-soft); color: var(--danger-text); border: 1px solid var(--danger-line); border-radius: 6px; font-size: 13px; z-index: 2; }
.diag { flex: none; margin: 0; padding: 4px 12px; font: 11px/1.4 ui-monospace, monospace; background: var(--strong-bg); color: var(--diag-text); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 25vh; overflow: auto; }

/* UX v5: compact "Więcej pól", fallback action, inline item discounts, item checklist, location */
.canon-more { margin: 4px 0 6px; font-size: 13px; }
.canon-more > summary { cursor: pointer; color: var(--muted); font-size: 12px; padding: 2px 0; overflow-wrap: anywhere; }
.canon-more[open] > summary { color: inherit; }
.canon-more-sections { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 6px; }
.canon-fallback, .canon-add-discount, .canon-add-location { font-size: 12px; margin: 2px 0; }
.canon-item-discounts { margin: 4px 0 2px 10px; padding-left: 8px; border-left: 2px solid var(--warn-line); }
.canon-item-discounts .canon-row { background: var(--warn-soft); }
/* Item checklist: always the full width of its block (never a half-width column of stacked rows),
   checkbox and label on one line, as many grid columns as the width allows. */
.field.idset { display: block; flex: 1 1 100% !important; max-width: 100%; min-width: 0; }
.idset-label { display: block; font-size: 12px; color: var(--muted); }
.idset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 12.5em), 1fr)); gap: 2px 14px; margin: 2px 0; }
.idset-grid:empty { display: none; }
.idset-item { font-size: 13px; display: flex; gap: 6px; align-items: baseline; min-width: 0; line-height: 1.3; padding: 1px 0; cursor: pointer; }
.field.idset label.idset-item { display: flex; color: inherit; font-size: 13px; padding-right: 0; }
.field.idset label.idset-item::after { content: none; }
.field.idset .idset-item input[type="checkbox"] { flex: none; width: auto; min-width: 0; margin: 0; padding: 0; transform: translateY(1px); }
.idset-item span { min-width: 0; overflow-wrap: anywhere; }
.idset-more > summary { font-size: 12px; }
.idset-scope-note { font-size: 12px; color: var(--muted); }
.idset-unknown { color: var(--danger-text); }
.canon-hint { margin: 2px 0 6px; font-size: 12px; }

/* ===================== UX v6: usable nested layout, help, clear acceptance ===================== */
/* fields keep a usable width and wrap to a single column instead of collapsing */
.canon-leaves .field, .row .field { flex: 1 1 140px; min-width: 140px; max-width: 100%; }
.field { position: relative; }
.field > label, .field .idset-label { padding-right: 22px; overflow-wrap: break-word; word-break: normal; hyphens: auto; }
.canon-sub { padding-left: 6px; }
.canon-sub .canon-sub { padding-left: 4px; }
.canon-row { padding: 4px 6px; }
.canon-obj-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 2px 0; }
.canon-obj-title { font-size: 12px; font-weight: 600; color: var(--muted); min-width: 0; }
.canon-remove { float: none; flex: none; font-size: 12px; }
.canon-more > summary { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.canon-add-discount { font-size: 12px; padding: 2px 10px; margin: 4px 0; }
.canon-offtype { border: 1px dashed var(--warn-border); border-radius: 6px; padding: 2px 6px; background: var(--warn-soft); }
.canon-offtype > summary { color: var(--warn-text); }
.canon-dedicated { margin-top: 2px; }
.vat-note { color: var(--muted); margin: -2px 0 2px; }
.vat-note.vat-warn { color: var(--warn-text); background: var(--warn-soft); border-radius: 4px; padding: 2px 6px; }
/* "?" help: tiny glyph, larger hit target, outside the layout flow */
.help-btn { position: absolute; top: 2px; right: 2px; width: 16px; height: 16px; padding: 0; border: 1px solid var(--line-strong); border-radius: 50%;
  background: var(--panel); color: var(--muted); font: 600 10px/14px system-ui, sans-serif; cursor: help; }
.help-btn::before { content: ""; position: absolute; inset: -6px; }
.help-btn:hover, .help-btn:focus-visible { border-color: var(--accent); color: var(--accent); }
.help-tip { position: fixed; z-index: 50; background: var(--strong-bg); color: var(--strong-text); font-size: 12px; line-height: 1.4; padding: 6px 8px;
  border-radius: 6px; box-shadow: 0 4px 12px var(--shadow); pointer-events: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
/* acceptance result is visible on the field itself */
.field.ack-accepted > input, .field.ack-accepted > select, .field.ack-accepted > textarea { border-color: var(--ok-border); background: var(--ok-soft); }
.field.ack-absent > input { border-color: var(--muted); background: var(--surface-2); }
#ack-accept.done { background: var(--ok-fill); color: var(--on-strong); border-color: var(--ok-fill); }
#ack-absent.done { background: var(--neutral-strong); color: var(--on-strong); }
.ack-bar { flex-wrap: wrap; }
.ack-msg { font-size: 12px; color: var(--danger-text); background: var(--danger-soft); border-radius: 4px; padding: 2px 6px; margin-top: 3px; }

/* ===================== UX v6: document library (tiles / table) ===================== */
.library { max-width: 1200px; margin: 0 auto; padding: 12px 16px 24px; }
.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.lib-head h1 { margin: 4px 0; font-size: 20px; }
.lib-filters { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 12px; }
.segmented a { display: inline-block; padding: 4px 10px; font-size: 13px; color: inherit; text-decoration: none; border-right: 1px solid var(--line); }
.segmented a:last-child { border-right: 0; }
.segmented a.on { background: var(--strong-bg); color: var(--on-strong); }
.segmented .count { display: inline-block; min-width: 1.6em; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--count-bg); font-size: 12px; text-align: center; }
.segmented a.on .count { background: var(--count-on-strong); }
.tiles { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tile a { display: flex; flex-direction: column; gap: 3px; height: 100%; padding: 8px; border: 2px solid var(--line); border-radius: 8px; background: var(--panel); color: inherit; text-decoration: none; }
.tile.status-approved a { border-color: var(--ok-border); }
.tile.status-pending a { border-color: var(--warn-border); border-style: dashed; }
.tile a:hover, .tile a:focus-visible { box-shadow: 0 2px 8px var(--shadow); }
.thumb { display: flex; align-items: center; justify-content: center; height: 180px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.thumb img { max-width: 100%; max-height: 180px; object-fit: contain; }
.no-thumb { font-size: 12px; color: var(--muted); padding: 8px; text-align: center; }
.tile-title { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.badge { display: inline-block; align-self: flex-start; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 10px; }
.badge-ok { background: var(--ok-soft); color: var(--ok-text); }
.badge-todo { background: var(--warn-soft); color: var(--warn-text); }
.lib-table { width: 100%; border-collapse: collapse; background: var(--panel); }
.lib-table th, .lib-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
.lib-table tr.status-approved td:first-child { border-left: 3px solid var(--ok-border); }
.lib-table tr.status-pending td:first-child { border-left: 3px dashed var(--warn-border); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 14px 0; font-size: 13px; flex-wrap: wrap; }
.empty { padding: 24px 0; text-align: center; }
@media (max-width: 600px) {
  .tiles { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
  .thumb { height: 140px; } .thumb img { max-height: 140px; }
  .lib-table th:nth-child(3), .lib-table td:nth-child(3) { display: none; }
}

/* ===================== Theme: controls, focus, images ===================== */
html { background: var(--bg); }
input, select, textarea, button { color: var(--text); }
.field input, .field select, .field textarea, .btn, input[type="text"], input[type="password"], input[type="search"], textarea, select {
  background-color: var(--panel); color: var(--text); border-color: var(--line); }
.btn.primary { background: var(--accent-fill); color: var(--on-strong); border-color: var(--accent-fill); }
.field input::placeholder, textarea::placeholder { color: var(--muted-2); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* images of documents are shown exactly as stored — never inverted, filtered or blended */
.page-img, .thumb img, .variant img, img.page { filter: none !important; mix-blend-mode: normal !important; }
.save-buttons { display: inline-flex; gap: 6px; flex-wrap: nowrap; flex: none; }

/* ===================== Selection flow ===================== */
.intake-toolbar { position: sticky; top: 0; z-index: 2; background: var(--panel); padding: 4px 0; }
.intake-error { color: var(--danger-text); background: var(--danger-soft); border: 1px solid var(--danger-line); border-radius: 6px; padding: 6px 8px; font-size: 13px; }
.intake-nav { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.variant-img { position: relative; display: block; min-height: 120px; background: var(--surface-2); border-radius: 4px; }
.variant-img img.failed { visibility: hidden; height: 120px; }
.img-state { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; text-align: center; font-size: 12px; color: var(--muted); padding: 8px; }
.intake.busy .intake-actions { opacity: .7; }

/* ===================== V7: price basis, move confirmation, time prompt ===================== */
.price-basis { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin: 4px 0 6px; padding: 4px 6px; border: 1px dashed var(--line); border-radius: 6px; position: relative; padding-right: 26px; }
.price-basis-choice { font-size: 13px; display: inline-flex; gap: 4px; align-items: center; }
.price-basis select { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 4px; padding: 2px 4px; font: inherit; }
.help-btn.help-inline { top: 6px; right: 6px; }
.move-confirm { margin: 6px 16px; }
.move-confirm ul { margin: 4px 0; padding-left: 18px; font-size: 12px; max-height: 30vh; overflow: auto; }
/* the ack buttons keep their size when their text changes (✓ Akceptuj ↔ ✓ Zaakceptowano), so an
   automatic acknowledgement on blur never shifts the layout under a click in progress */
#ack-accept { min-width: 9.2em; }
#ack-absent { min-width: 5.6em; }
.ack-bar .btn { white-space: nowrap; text-align: center; }

/* ===================== Reservations ===================== */
.claim-banner { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin: 6px 16px; padding: 6px 10px;
  border: 1px solid var(--warn-border); background: var(--warn-soft); color: var(--text); border-radius: 6px; font-size: 13px; }
.claim-actions { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.canon-form.readonly input, .canon-form.readonly select, .canon-form.readonly textarea { background: var(--surface-2); color: var(--text); cursor: default; }
.claim-tools { display: inline-flex; gap: 10px; flex: none; }
.badge-mine { background: var(--info-soft); color: var(--info-text); }
.badge-busy { background: var(--warn-soft); color: var(--warn-text); }
.take-next { margin: 0; }
.inline-form { display: inline; margin: 0; }
.inline-form input { font-size: 12px; padding: 1px 4px; }
.variant .variant-chosen { display: none; font-size: 12px; font-weight: 700; color: var(--on-strong); background: var(--accent-fill); border-radius: 8px; padding: 0 6px; margin-left: 4px; }
.variant:has(input:checked) .variant-chosen, .variant.chosen .variant-chosen { display: inline-block; }
.variant:has(input:checked), .variant.chosen { border-color: var(--accent-fill); box-shadow: 0 0 0 2px var(--accent-soft); }
.variant.unavailable { opacity: .75; }
.intake-flag { display: block; margin: 4px 0; }
/* footer: status, reservation tools and the two saves wrap instead of overflowing the pane */
.form-footer .actions { flex-wrap: wrap; row-gap: 6px; }
.claim-tools { flex-wrap: wrap; }
.form-head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.form-head-row h1 { min-width: 0; }
#next-field { flex: none; font-size: 12px; padding: 3px 8px; }
.field[data-field] { cursor: text; }
.field[data-field] > select, .field.idset { cursor: default; }
.tutorial-note { margin: 2px 0 6px; }
.tutorial-steps li.done { color: var(--muted, inherit); }
.tutorial-ok { color: var(--ok, #1a7f37); font-weight: 600; white-space: nowrap; }

/* Accounts, login, dashboard (colours from the theme variables: light and dark follow the system) */
.login-error { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger-text); }
#login-form input[type="password"] { width: 100%; max-width: 360px; font: 16px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 6px 8px; }
.account-create { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 10px 0; }
.account-create input { padding: 4px 6px; }
.secret-box code { display: inline-block; font-size: 20px; letter-spacing: 1px; padding: 10px 14px; border: 1px dashed var(--line-strong); border-radius: 6px; background: var(--surface-2); user-select: all; }
.inline-form { display: inline; }

/* Admin statistics and review: shared system-theme surfaces, local table scroll. */
.admin-page { max-width: 1200px; margin: 0 auto; padding: 16px; min-width: 0; }
.admin-page h1 { font-size: 22px; margin: 4px 0; }
.admin-page h2 { font-size: 16px; margin: 0 0 8px; overflow-wrap: anywhere; }
.admin-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; min-width: 0; margin-bottom: 12px; }
.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 16px 0 0; }
.metric-grid .admin-card { margin: 0; }
.metric-grid dt { font-size: 12px; color: var(--muted); }
.metric-grid dd { margin: 4px 0 0; font-size: 23px; font-weight: 650; font-variant-numeric: tabular-nums; }
.admin-help { margin: 12px 0; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.admin-help summary { cursor: pointer; padding: 8px 0; }
.table-scroll { max-width: 100%; overflow: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--line); }
.admin-table thead { background: var(--surface-2); }
.admin-table td { font-variant-numeric: tabular-nums; }
.admin-table td:not(:last-child) { white-space: nowrap; }
.actor-time { display: inline-block; margin-right: 10px; white-space: nowrap; }
.review-cards { display: grid; gap: 12px; }
.review-cards .admin-card { margin: 0; }
.review-links { display: flex; flex-wrap: wrap; gap: 8px; }
.review-links .btn { overflow-wrap: anywhere; max-width: 100%; }
.review-comment { border-left: 3px solid var(--line-strong); padding-left: 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.review-queue .segmented a, .admin-page .btn { min-height: 44px; display: inline-flex; align-items: center; }
#review-dialog { width: min(600px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 16px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel); color: var(--text); }
#review-dialog::backdrop { background: rgb(0 0 0 / .5); }
#review-dialog h2 { margin: 0 0 12px; font-size: 18px; }
#review-sections { max-height: 42dvh; overflow: auto; border: 1px solid var(--line); border-radius: 6px; margin: 0; padding: 8px; min-width: 0; }
.review-section + .review-section { border-top: 1px solid var(--line); }
.review-section label { display: flex; align-items: center; gap: 8px; min-height: 44px; overflow-wrap: anywhere; }
.review-section input[type="checkbox"] { flex: none; width: 18px; height: 18px; accent-color: var(--accent-fill); }
.review-section details { margin: 0 0 8px 26px; }
.review-section summary { cursor: pointer; font-size: 12px; padding: 8px 0; color: var(--muted); }
.review-section input[type="search"] { width: 100%; min-height: 44px; }
.review-fields { max-height: 220px; overflow: auto; }
.review-fields label { font-size: 13px; }
.review-fields label[hidden] { display: none; }
.review-context { flex: none; margin: 8px 16px 0; padding: 8px 10px; border: 1px solid var(--warn-border); border-radius: 6px; background: var(--warn-soft); font-size: 13px; max-height: 24vh; overflow: auto; overflow-wrap: anywhere; }
.review-context summary { cursor: pointer; font-weight: 600; }
.review-context p { margin: 6px 0; white-space: pre-wrap; }
#review-comment { display: block; width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; margin: 6px 0; }
#review-error:not(:empty) { padding: 8px; border: 1px solid var(--danger-line); border-radius: 6px; background: var(--danger-soft); color: var(--danger-text); }
#review-error:empty { display: none; }
#review-dialog > .btn { min-height: 44px; }
@media (max-width: 600px) {
  .admin-page { padding: 12px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .metric-grid dd { font-size: 19px; overflow-wrap: anywhere; }
  .admin-table { min-width: 540px; }
  #review-dialog { padding: 12px; }
}


/* queue actions: review return / unreadable / restore */
.notice.notice-error { background: var(--danger-soft, var(--warn-soft)); border-color: var(--danger-line, var(--warn-line)); }
.review-return-form { display: grid; gap: 6px; margin-top: 6px; }
.review-return-form textarea { width: 100%; }
.unreadable-dialog { display: grid; gap: 6px; }
.unreadable-dialog textarea { width: 100%; }
.discount-badge { display: inline-block; font-size: 11px; line-height: 1.4; padding: 0 6px; border-radius: 9px; background: var(--warn-soft); border: 1px solid var(--warn-line); color: inherit; white-space: nowrap; }
.canon-row.has-discount > .item-head { border-left: 3px solid var(--warn-line); }
.item-discount-more > summary { white-space: normal; }
.row-tools { display: inline-flex; gap: 2px; margin-left: auto; margin-right: 8px; }
.row-tool { font-size: 12px; padding: 0 4px; text-decoration: none; }

/* admin activity (all states) */
.activity-filters { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end; margin: 8px 0; }
.activity-filters label { display: grid; gap: 2px; }
.activity-filters select { min-width: 10em; max-width: 100%; }
.activity-docs { display: grid; gap: 10px; }
.activity-doc { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.activity-doc h3 { font-size: 15px; margin: 0; overflow-wrap: anywhere; }
.activity-history { margin: 4px 0; padding-left: 18px; }
.admin-table.compact th, .admin-table.compact td { padding: 2px 6px; font-size: 13px; }

/* ---- admin two-pane review (Do sprawdzenia / Do akceptacji): document left, data + actions right */
.review-split { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(340px, 1fr); gap: 0; height: calc(100vh - 45px); min-height: 0; }
.review-split .doc-pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--bg); }
.review-split .doc-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.review-split .doc-jump a { padding: 2px 6px; }
.review-split .doc-scroll { flex: 1; min-height: 0; overflow: auto; padding: 12px; outline-offset: -3px; }
.review-split .doc-page { margin: 0 auto 16px; width: calc(100% * var(--doc-zoom, 1)); max-width: none; }
.review-split .doc-scroll:not(.zoomed) .doc-page { max-width: 100%; }
.review-split .doc-page img { display: block; width: 100%; height: auto; background: #fff; border: 1px solid var(--line); }
.review-split .data-pane { display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.review-split .data-scroll { flex: 1; min-height: 0; overflow: auto; padding: 12px 16px; }
.review-split .data-scroll .lib-table { width: 100%; table-layout: fixed; word-break: break-word; }
.review-split .action-bar { position: sticky; bottom: 0; display: grid; gap: 6px; padding: 10px 16px; border-top: 1px solid var(--line-strong); background: var(--panel); box-shadow: 0 -2px 8px rgb(0 0 0 / .08); }
.review-split .action-bar textarea { width: 100%; box-sizing: border-box; }
.review-split .training-buttons { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.review-split .review-comment-box { border-top: 1px solid var(--line); padding-top: 6px; }
@media (max-width: 900px) {
  .review-split { display: block; height: auto; }
  .review-split .doc-pane { border-right: 0; border-bottom: 1px solid var(--line); }
  .review-split .doc-scroll { max-height: 70vh; }
  .review-split .data-scroll { overflow: visible; padding-bottom: 260px; }      /* room for the fixed action bar */
  .review-split .action-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; max-height: 45vh; overflow: auto; }
  .review-split .action-bar textarea { min-height: 2.2em; }
}
.review-split .action-bar .decision { display: grid; gap: 4px; }
.review-split .action-bar .decision + .decision { border-top: 1px dashed var(--line); padding-top: 6px; }
