/* APLYD · Shop-floor digitisation
   Compact stylesheet: tokens, shell, components, pages, responsive. */

:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #fafaf8;
  --ink: #18181b;
  --ink-2: #3f3f46;
  --muted: #6b6b73;
  --border: #e6e6e3;
  --border-2: #f0f0ee;
  --ok: #15803d;      --ok-soft: #ecfdf3;
  --warn: #a35a00;    --warn-soft: #fff4dc;
  --bad: #b91c1c;     --bad-soft: #fde8e8;
  --info: #1d4ed8;    --info-soft: #e8efff;
  --violet: #6d28d9;  --violet-soft: #f1eafe;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.06);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

html.dark-theme {
  --bg: #0b0b0d;
  --surface: #161618;
  --surface-2: #1c1c1f;
  --ink: #f4f4f5;
  --ink-2: #d4d4d8;
  --muted: #a1a1aa;
  --border: #2a2a2e;
  --border-2: #222225;
  --ok: #4ade80;      --ok-soft: #0b2a17;
  --warn: #fbbf24;    --warn-soft: #3a2905;
  --bad: #f87171;     --bad-soft: #3b1111;
  --info: #93b4ff;    --info-soft: #14213f;
  --violet: #c4b5fd;  --violet-soft: #251a3d;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { min-height: 100%; }
html { scrollbar-gutter: stable; } /* no sideways jump between pages with and without a scrollbar */
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3, h4 { color: var(--ink); font-weight: 650; letter-spacing: -0.01em; line-height: 1.25; }
h3 { font-size: 16px; }
p { color: var(--ink-2); }
code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 650; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.req { color: var(--bad); }
:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }

/* ── Shell ─────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 236px;
  background: var(--surface-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto; z-index: 30;
}
.content-shell { margin-left: 236px; min-height: 100vh; display: flex; flex-direction: column; }
.brand-block { display: flex; align-items: center; gap: 10px; padding: 20px 20px 14px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; background: var(--ink); color: var(--bg);
  display: grid; place-items: center; font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.brand-name { font-weight: 700; font-size: 15px; color: var(--ink); letter-spacing: 0.02em; }
.brand-sub { font-size: 11.5px; color: var(--muted); }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; flex: 1; }
.nav-item {
  display: block; padding: 9px 12px; border-radius: var(--radius-xs); text-decoration: none;
  color: var(--ink-2); font-weight: 500; white-space: nowrap;
}
.nav-item:hover { background: var(--border-2); }
.nav-item-active, .nav-item-active:hover { background: var(--ink); color: var(--bg); }
.sidebar-note { padding: 16px 20px; border-top: 1px solid var(--border); font-size: 12px; }
.sidebar-note p { font-size: 12px; color: var(--muted); }
.note-label { text-transform: uppercase; letter-spacing: 0.06em; font-weight: 650; font-size: 10.5px !important; margin-bottom: 2px; }

.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 28px;
}
.page-eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 650; }
.page-title { font-size: 20px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-meta { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user-name { color: var(--ink-2); font-weight: 500; }
.role-pill { font-size: 11px; font-weight: 650; text-transform: capitalize; padding: 3px 9px; border-radius: 999px; background: var(--border-2); border: 1px solid var(--border); color: var(--ink-2); }
.role-supervisor { background: var(--info-soft); color: var(--info); border-color: transparent; }
.role-admin { background: var(--violet-soft); color: var(--violet); border-color: transparent; }
.role-operator { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

.content-main { padding: 22px 28px 120px; width: 100%; max-width: 1440px; display: flex; flex-direction: column; gap: 18px; }
.content-narrow { max-width: 860px; margin: 0 auto; }

.demo-persona-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 8px 10px;
  border: 1px dashed var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
.demo-persona-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 650; color: var(--muted); margin-right: 4px; }
.persona-btn {
  font: inherit; font-size: 12.5px; padding: 5px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink-2);
}
.persona-btn.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* ── Buttons & inputs ─────────────────────────────────────────────── */
.btn {
  font: inherit; font-weight: 600; font-size: 13.5px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 15px; border-radius: var(--radius-xs); border: 1px solid transparent; cursor: pointer;
  text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s, opacity .12s;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--bg); }
.btn-primary:hover:not(:disabled) { opacity: 0.88; }
.btn-outline { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn-outline:hover:not(:disabled) { background: var(--surface-2); border-color: var(--muted); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-warn { color: var(--warn); }
.btn-bad { color: var(--bad); }
.btn-small { padding: 6px 11px; font-size: 12.5px; }
.btn-icon { padding: 8px 10px; line-height: 0; display: inline-grid; place-items: center; }
.btn-tiny { padding: 4px 9px; font-size: 12px; align-self: flex-start; }
.btn-large { padding: 12px 22px; font-size: 14.5px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-row-center { justify-content: center; }
.link-btn { font: inherit; background: none; border: 0; color: var(--info); cursor: pointer; text-decoration: underline; padding: 0; }

.form-control, .select-control {
  font: inherit; font-size: 14px; width: 100%; padding: 9px 11px; border-radius: var(--radius-xs);
  border: 1px solid var(--border); background: var(--surface); color: var(--ink); min-height: 40px;
}
.form-control:focus, .select-control:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 12%, transparent); }
.form-control:disabled, .select-control:disabled { background: var(--surface-2); color: var(--ink-2); opacity: 1; cursor: default; }
textarea.form-control { resize: vertical; }

/* ── Badges ───────────────────────────────────────────────────────── */
[class^="badge-"], .tag {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 650; padding: 2px 8px;
  border-radius: 999px; text-transform: capitalize; white-space: nowrap; border: 1px solid transparent;
}
.badge-read { background: var(--ok-soft); color: var(--ok); }
.badge-uncertain { background: var(--warn-soft); color: var(--warn); }
.badge-missing { background: var(--border-2); color: var(--muted); border-color: var(--border); }
.badge-illegible { background: var(--bad-soft); color: var(--bad); }
.badge-invalid { background: var(--bad-soft); color: var(--bad); }
.badge-corrected { background: var(--info-soft); color: var(--info); }
.badge-confirmed { background: var(--violet-soft); color: var(--violet); }
.tag { background: var(--border-2); color: var(--muted); font-weight: 600; text-transform: lowercase; padding: 1px 6px; }

/* ── Cards, panels, tables ────────────────────────────────────────── */
.panel, .hero-panel, .table-card, .kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.panel { padding: 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hero-panel { padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.hero-panel > div { flex: 1 1 320px; display: flex; flex-direction: column; gap: 4px; }
.section-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 650; color: var(--muted); margin-top: 4px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi-grid-tight { margin: 8px 0; }
.kpi-card { padding: 14px 16px; }
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 650; color: var(--muted); }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; margin: 2px 0; }
.kpi-value.warn { color: var(--warn); }
.kpi-value.bad { color: var(--bad); }
.kpi-note { font-size: 12px; color: var(--muted); }

.dash-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart-box { position: relative; height: 260px; }

.table-card { overflow-x: auto; }
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
  font-weight: 650; padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table th.num { text-align: right; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border-2); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table-compact td, .data-table-compact th { padding: 7px 9px; font-size: 12px; }
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover td, .data-table tr.clickable:focus td { background: var(--surface-2); }
.empty-cell { text-align: center; padding: 34px 12px !important; color: var(--muted); }

.filter-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.filter-bar > .form-control { flex: 2 1 220px; width: auto; }
.filter-bar > .select-control { flex: 1 1 150px; width: auto; }
.date-filter { display: flex; gap: 6px; flex: 1 1 190px; }
.tabs-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.tab-strip { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow-x: auto; max-width: 100%; }
.tab-button { font: inherit; font-size: 13px; font-weight: 500; padding: 6px 12px; border: 0; border-radius: var(--radius-xs); background: transparent; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.tab-button-active { background: var(--ink); color: var(--bg); }

.inline-alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; background: var(--surface-2); border: 1px solid var(--border); color: var(--ink-2); }
.inline-alert-warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.inline-alert-bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.inline-alert-ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.inline-alert-info { background: var(--info-soft); border-color: transparent; color: var(--info); }
.inline-alert-info a { font-weight: 600; }
.group-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.status-banner { display: flex; flex-direction: column; gap: 8px; }
kbd { font-family: var(--mono); font-size: 12px; padding: 0 4px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--surface); }

/* ── Capture ──────────────────────────────────────────────────────── */
.ai-status { font-size: 12.5px; padding: 8px 12px; border-radius: var(--radius-xs); background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.ai-status-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.ai-status-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.tips-banner { font-size: 12.5px; color: var(--ink-2); padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.preflight-dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 40px 20px; text-align: center;
  background: var(--surface); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.preflight-dropzone:hover, .preflight-dropzone.dragover { border-color: var(--ink); background: var(--surface-2); }
.dropzone-icon { font-size: 36px; }
.batch-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.batch-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.batch-list { list-style: none; display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow-y: auto; }
.batch-item { display: flex; align-items: center; gap: 12px; padding: 8px; border: 1px solid var(--border-2); border-radius: var(--radius-sm); background: var(--surface-2); min-width: 0; }
.batch-item.batch-reading, .batch-item.batch-retrying { border-color: var(--info); }
.batch-item.batch-failed { border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.batch-thumb { width: 52px; height: 52px; border-radius: 6px; background: #1b1b1f; flex-shrink: 0; overflow: hidden; display: grid; place-items: center; }
.batch-thumb img { width: 100%; height: 100%; object-fit: cover; }
.batch-body { flex: 1; min-width: 0; }
.batch-name { font-size: 13px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.batch-detail { font-size: 12.5px; color: var(--ink-2); overflow-wrap: anywhere; }
.batch-note { font-size: 11.5px; color: var(--warn); }
.batch-actions { display: flex; gap: 6px; flex-shrink: 0; }
.batch-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; flex-wrap: wrap; }
.sample-picker { padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); display: flex; flex-direction: column; gap: 8px; }
.sample-list { display: flex; flex-wrap: wrap; gap: 6px; }
.sample-btn {
  font: inherit; font-size: 12.5px; font-weight: 500; padding: 6px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink);
}
.sample-btn:hover:not(:disabled) { border-color: var(--ink); }
.sample-btn-batch { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.sample-btn:disabled { opacity: 0.5; cursor: wait; }
.preflight-preview-card, .progress-card, .failure-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
}
.preflight-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.preflight-thumb-wrap { background: #121214; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; min-height: 220px; overflow: hidden; }
.preflight-thumb-img { max-width: 100%; max-height: 420px; object-fit: contain; display: block; }
.preflight-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12.5px; color: var(--muted); }
.preflight-meta strong { color: var(--ink); }
.quality-box { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--surface-2); }
.qc-summary { font-weight: 650; font-size: 13px; margin-bottom: 6px; }
.qc-summary-ok { color: var(--ok); }
.qc-summary-warn { color: var(--warn); }
.qc-list { list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.qc-list li { display: flex; gap: 8px; align-items: baseline; }
.qc-icon { width: 18px; height: 18px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.qc-ok .qc-icon { background: var(--ok-soft); color: var(--ok); }
.qc-warn .qc-icon { background: var(--warn-soft); color: var(--warn); }
.preflight-actions { display: flex; justify-content: flex-end; }
.progress-card, .failure-card { align-items: center; text-align: center; padding: 30px 20px; }
.failure-card { border-color: var(--bad); }
.failure-card h3 { color: var(--bad); }
.failure-icon { font-size: 32px; }
.ocr-spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--ink); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress-stepper { display: flex; flex-direction: column; gap: 8px; text-align: left; margin-top: 6px; }
.step-item { display: flex; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); }
.step-icon { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--border-2); flex-shrink: 0; }
.step-item.active { color: var(--ink); font-weight: 600; }
.step-item.active .step-icon { background: var(--ink); color: var(--bg); }
.step-item.done { color: var(--ok); }
.step-item.done .step-icon { background: var(--ok); color: #fff; }
.step-item.failed { color: var(--bad); font-weight: 600; }
.step-item.failed .step-icon { background: var(--bad); color: #fff; }

/* ── Review ───────────────────────────────────────────────────────── */
.detail-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.detail-title { flex: 1; min-width: 180px; }
.detail-title h3 { font-size: 18px; font-family: var(--mono); }
.review-split-container { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.document-viewer-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column; position: sticky; top: 84px; height: calc(100vh - 190px); min-height: 460px;
}
.document-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); gap: 8px; }
.toolbar-actions { display: flex; gap: 4px; align-items: center; }
.toolbar-btn { font: inherit; width: 32px; height: 32px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); cursor: pointer; font-weight: 650; }
.zoom-label { font-size: 12px; color: var(--muted); min-width: 42px; text-align: center; font-variant-numeric: tabular-nums; }
.canvas-viewport { flex: 1; position: relative; overflow: hidden; background: #1b1b1f; display: flex; align-items: center; justify-content: center; cursor: grab; touch-action: none; user-select: none; }
.canvas-viewport:active { cursor: grabbing; }
.document-img { max-width: 94%; max-height: 94%; object-fit: contain; transform-origin: center; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35); pointer-events: none; }
.document-img.animate, .box-highlight.animate { transition: transform .28s ease, left .28s ease, top .28s ease, width .28s ease, height .28s ease; }
.box-highlight { position: absolute; border: 2px solid #f59e0b; border-radius: 4px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.28); pointer-events: none; z-index: 2; }
.box-highlight[data-label]::after { content: attr(data-label); position: absolute; left: -2px; bottom: 100%; margin-bottom: 2px; padding: 1px 6px; border-radius: 4px 4px 0 0; background: #f59e0b; color: #111; font: 600 11px/1.5 system-ui, sans-serif; white-space: nowrap; }
.no-image-note { color: #a1a1aa; font-size: 13px; padding: 20px; text-align: center; }
.viewer-foot { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding: 7px 12px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--border); background: var(--surface-2); }
.image-issues { list-style: none; padding: 8px 12px 10px; font-size: 12px; color: var(--warn); border-top: 1px solid var(--border); }
.image-issues li:not(.section-label)::before { content: '• '; }

.verification-form-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.span-2 { grid-column: span 2; }
.field-verify-group { display: flex; flex-direction: column; gap: 5px; padding: 10px; border: 1px solid var(--border-2); border-radius: var(--radius-sm); background: var(--surface-2); min-width: 0; }
.field-verify-group:focus-within { border-color: var(--ink); background: var(--surface); }
.field-verify-group.is-flagged { border-color: color-mix(in srgb, var(--warn) 55%, transparent); background: color-mix(in srgb, var(--warn-soft) 55%, var(--surface)); }
.field-verify-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.field-verify-label { font-size: 12px; font-weight: 650; color: var(--ink-2); }
.raw-transcription-hint { font-size: 11.5px; color: var(--muted); font-family: var(--mono); overflow-wrap: anywhere; }
.field-reason-pill { font-size: 12px; color: var(--warn); }
.field-value { font-size: 14px; color: var(--ink); padding: 6px 2px; min-height: 32px; overflow-wrap: anywhere; }
.field-value.muted { color: var(--muted); }
.field-hint { font-size: 12px; color: var(--ink-2); }
.locate-btn { font-size: 12px; margin-left: 6px; }
.reason-inline { display: flex; flex-direction: column; gap: 3px; font-size: 12px; font-weight: 600; color: var(--muted); }
.reason-inline .form-control { min-height: 34px; padding: 6px 9px; font-size: 13px; }
.field-msg { font-size: 12px; }
.field-msg.bad { color: var(--bad); }
.field-msg.warn { color: var(--warn); }
.validation-panel { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; background: var(--surface-2); font-size: 13px; }
.validation-panel ul { margin: 4px 0 6px 18px; display: flex; flex-direction: column; gap: 2px; }
.validation-head { font-weight: 650; }
.validation-head.bad { color: var(--bad); }
.validation-head.warn { color: var(--warn); }
.validation-ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; font-weight: 600; }
.attention-label { color: var(--warn); }
.audit-block { border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }

.sticky-action-bar {
  position: sticky; bottom: 14px; z-index: 15; margin-top: 4px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.sticky-action-bar:empty { display: none; }
.approve-group { margin-left: auto; }

/* ── Modals & dialogs ─────────────────────────────────────────────── */
.modal-overlay, .app-dialog-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.app-dialog-overlay { z-index: 200; }
.modal-box, .app-dialog {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 680px; max-height: calc(100vh - 32px); overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-box-sm, .app-dialog { max-width: 460px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.modal-head h3 { font-family: var(--mono); font-size: 17px; margin-bottom: 4px; }
.modal-foot, .app-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 12px; }
.modal-foot { justify-content: space-between; }
.app-dialog-message { font-size: 13px; color: var(--muted); }
.app-dialog-label { font-size: 12.5px; font-weight: 600; }
.app-dialog-error { font-size: 12px; color: var(--bad); }
.kv-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; padding: 12px; background: var(--surface-2); border-radius: var(--radius-sm); }
.kv-grid dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 650; }
.kv-grid dd { font-size: 13px; overflow-wrap: anywhere; }
.audit-list { list-style: none; font-size: 12.5px; display: flex; flex-direction: column; gap: 4px; }
.erp-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.payload-details { margin-top: 8px; font-size: 12.5px; }
.payload-details summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.code-block { font-family: var(--mono); font-size: 11.5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 10px; margin-top: 6px; overflow-x: auto; max-height: 300px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.form-grid label.check { flex-direction: row; align-items: center; gap: 8px; }

/* ── Entry page ───────────────────────────────────────────────────── */
.auth-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-box { width: 100%; max-width: 520px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 28px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.brand-block-inline { padding: 0; }
.auth-title { font-size: 21px; }
.persona-list { display: flex; flex-direction: column; gap: 8px; }
.persona-card { font: inherit; text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); cursor: pointer; color: var(--ink); }
.persona-card span { font-size: 12.5px; color: var(--muted); }
.persona-card:hover { border-color: var(--ink); background: var(--surface); }
.auth-foot { border-top: 1px solid var(--border); padding-top: 12px; }

/* ── Toasts ───────────────────────────────────────────────────────── */
.toast-container { position: fixed; left: 50%; transform: translateX(-50%); top: 76px; z-index: 300; display: flex; flex-direction: column; align-items: center; gap: 8px; width: max-content; max-width: min(460px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-left: 4px solid var(--info);
  border-radius: var(--radius-xs); padding: 10px 14px; font-size: 13px; box-shadow: var(--shadow); max-width: 100%;
  opacity: 0; transform: translateY(-6px); transition: opacity .2s, transform .2s; white-space: pre-line;
  display: flex; align-items: center; gap: 12px;
}
.toast-has-action { pointer-events: auto; }
.toast-action { font: inherit; font-weight: 700; background: none; border: 0; color: var(--info); cursor: pointer; padding: 4px 6px; min-height: 32px; text-decoration: underline; flex-shrink: 0; }
.toast-visible { opacity: 1; transform: none; }
.toast-leaving { opacity: 0; }
.toast-success { border-left-color: var(--ok); }
.toast-warning { border-left-color: var(--warn); }
.toast-error { border-left-color: var(--bad); }

/* ── Shell extras (icons, tab bar, persona switcher) ───────────────── */
.nav-item { display: flex; align-items: center; gap: 10px; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.tabbar, .persona-compact, .show-phone, .more-sheet { display: none; }
.outbox-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.progress-elapsed { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }
.progress-note { font-size: 12.5px; color: var(--warn); }
.persona-options { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }

/* ── Readable small text: nothing below 12 px ───────────────────────── */
.page-eyebrow, .role-pill, .demo-persona-label, .section-label, .kpi-label, .tag, .zoom-label, .note-label, .brand-sub,
.data-table th, .kv-grid dt, .raw-transcription-hint, .batch-note, .viewer-foot, .qc-icon, [class^="badge-"] { font-size: 12px; }
.note-label { font-size: 12px !important; }

/* ── ≤1100 px: single-column review and dashboard ──────────────────── */
@media (max-width: 1100px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
  .review-split-container { grid-template-columns: minmax(0, 1fr); }
  .document-viewer-card { position: relative; top: 0; height: 62vh; min-height: 360px; }
}

/* ── Tablet 768–1099 px: narrow sidebar ────────────────────────────── */
@media (min-width: 768px) and (max-width: 1099px) {
  .sidebar { width: 200px; }
  .content-shell { margin-left: 200px; }
  .brand-sub, .sidebar-note { display: none; }
  .nav-item { padding: 10px; font-size: 13.5px; }
  .topbar { padding: 12px 20px; }
  .content-main { padding: 16px 20px 120px; }
  .chart-grid { grid-template-columns: minmax(0, 1fr); }
  .user-name { display: none; }
}

/* ── Touch screens: every control at least 44 × 44 px ──────────────── */
@media (pointer: coarse), (max-width: 767px) {
  .btn, .btn-small, .btn-tiny, .persona-btn, .persona-compact, .tab-button, .nav-item, .sample-btn, .more-item { min-height: 44px; }
  .btn, .tab-button { min-width: 44px; }
  .data-table td a:not(.btn) { display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; }
  .btn-icon, .toolbar-btn { min-width: 44px; min-height: 44px; }
  .toolbar-btn { width: 44px; height: 44px; }
  .link-btn { display: inline-flex; align-items: center; min-height: 44px; }
  .form-control, .select-control { min-height: 44px; }
  .form-grid label.check, .erp-actions label { min-height: 44px; display: flex; align-items: center; gap: 8px; }
}

/* ── Phones (< 768 px) ─────────────────────────────────────────────── */
@media (max-width: 767px) {
  :root { --tabbar-h: calc(58px + env(safe-area-inset-bottom)); --topbar-h: 58px; }
  /* keep anything the browser scrolls to (focus, find, anchors) clear of the fixed top/bottom bars */
  html { scroll-padding-top: calc(var(--topbar-h) + 8px); scroll-padding-bottom: calc(var(--tabbar-h) + var(--actionbar-h, 0px) + 8px); }
  .hide-phone { display: none !important; }
  .show-phone { display: revert; }
  span.show-phone { display: inline; }

  /* shell */
  .sidebar { display: none; }
  .content-shell { margin-left: 0; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.05);
  }
  .tab-item {
    flex: 1 1 0; min-width: 0; min-height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font: inherit; font-size: 12px; font-weight: 550; color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer; position: relative;
  }
  .tab-item span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .tab-item-active { color: var(--ink); font-weight: 700; }
  .tab-item-active::before { content: ''; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--ink); }
  .more-sheet { display: flex; position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, 0.35); align-items: flex-end; }
  .more-sheet.hidden { display: none !important; }
  .more-sheet-panel { width: 100%; background: var(--surface); border-radius: 16px 16px 0 0; padding: 10px 10px calc(var(--tabbar-h) + 10px); display: flex; flex-direction: column; gap: 2px; }
  .more-item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: var(--radius-xs); text-decoration: none; color: var(--ink); font-weight: 550; }
  .more-item.nav-item-active { background: var(--ink); color: var(--bg); }

  .topbar { position: sticky; top: 0; z-index: 30; padding: 7px 12px; min-height: var(--topbar-h); flex-wrap: nowrap; gap: 8px; }
  .page-eyebrow { display: none; }
  .page-title { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar > div:first-child { min-width: 0; }
  .topbar-actions { gap: 6px; flex-shrink: 0; }
  #themeToggleBtn { margin-right: 0 !important; }
  .user-name, .topbar-actions .user-meta { display: none; }
  .topbar-actions .btn-small { min-width: 44px; padding: 6px 10px; font-size: 18px; }
  .document-toolbar { justify-content: flex-end; }
  .document-toolbar .toolbar-actions { width: 100%; justify-content: space-between; }
  .approve-group > span { width: 100%; text-align: center; }

  .content-main { padding: 12px 12px calc(var(--tabbar-h) + var(--actionbar-h, 0px) + 20px); gap: 12px; }
  .content-narrow { padding-left: 12px; padding-right: 12px; }

  /* persona switcher: one chip that opens the three choices */
  .demo-persona-bar { padding: 0; border: 0; background: none; display: block; }
  .persona-compact {
    display: flex; align-items: center; gap: 6px; width: 100%; font: inherit; font-size: 13px; color: var(--ink-2);
    padding: 8px 12px; border: 1px dashed var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; text-align: left;
  }
  .persona-compact span { margin-left: auto; }
  .persona-options { display: none; margin-top: 6px; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
  .demo-persona-bar.open .persona-options { display: flex; }
  .persona-options .persona-btn { flex: 1 1 100%; }
  .persona-options .demo-persona-label { display: none; }

  /* readable text */
  .section-label, .kpi-label, .demo-persona-label, .tag, .zoom-label, .qc-icon, [class^="badge-"] { font-size: 12px; }
  .note-label { font-size: 12px !important; }
  .brand-sub { font-size: 12px; }

  /* inputs: 16 px stops iPhone zooming in on focus */
  .form-control, .select-control, textarea, input[type="search"], .reason-inline .form-control { font-size: 16px; }

  /* layout blocks */
  .field-grid, .form-grid, .kv-grid { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .hero-panel { padding: 14px; }
  .hero-panel .btn { width: 100%; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi-card { padding: 12px; }
  .kpi-value { font-size: 20px; }
  .btn-large { padding: 12px 16px; }
  .panel { padding: 14px; }
  .filter-bar { padding: 10px; }
  .filter-bar > .form-control, .filter-bar > .select-control { flex: 1 1 100%; }
  .filter-bar > .btn { flex: 1 1 auto; }
  .tabs-row { gap: 6px; }
  .toast-container { left: 12px; right: 12px; transform: none; width: auto; max-width: none; top: calc(var(--topbar-h) + 8px); }
  .toast { width: 100%; }
  .toast-action { min-height: 44px; min-width: 44px; }

  /* tables become stacked cards (cells are labelled by js/layout.js) */
  .table-card, .table-scroll { overflow: visible; border: 0; background: none; }
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 12px 14px; margin-bottom: 8px;
  }
  .data-table td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 3px 0 !important; border: 0 !important; text-align: right; min-width: 0; overflow-wrap: anywhere; }
  .data-table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; flex-shrink: 0; }
  .data-table td:first-child { font-size: 15px; padding-bottom: 6px !important; justify-content: flex-start; text-align: left; }
  .data-table td:first-child::before, .data-table td[data-label=""]::before, .data-table td.empty-cell::before { content: none; }
  .data-table td[data-label=""] { justify-content: flex-end; padding-top: 8px !important; }
  .data-table td[data-label=""] .btn { width: 100%; }
  .data-table td.empty-cell { display: block; text-align: center; }
  .data-table tr:has(td.empty-cell) { border-style: dashed; }
  .data-table-compact td { font-size: 13px; }

  /* collapsible filters (register) */
  .filters-toggle { width: 100%; }
  .filter-bar.collapsible:not(.open) > :not(.filters-toggle) { display: none; }

  /* review: the photo stays visible while scrolling the fields */
  .review-split-container { gap: 10px; }
  .document-viewer-card { position: sticky; top: var(--topbar-h); z-index: 20; height: 38vh; min-height: 220px; box-shadow: var(--shadow); }
  .document-viewer-card.viewer-collapsed { height: auto; min-height: 0; }
  .document-viewer-card.viewer-collapsed .canvas-viewport,
  .document-viewer-card.viewer-collapsed .toolbar-actions > :not(#photoToggleBtn) { display: none; }
  .document-viewer-card .viewer-foot, .document-viewer-card .image-issues { display: none; }
  .document-toolbar { padding: 4px 8px; }
  .verification-form-card { padding: 12px; }
  .detail-head { gap: 8px; }
  .detail-title h3 { font-size: 16px; }

  /* fixed action bar sits just above the tab bar; reviewers get ONE row: ↩ ✕ [ Approve ] */
  .sticky-action-bar {
    position: fixed; left: 0; right: 0; bottom: var(--tabbar-h); z-index: 50; margin: 0;
    border-radius: 0; border-width: 1px 0 0; padding: 8px 12px; box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  }
  .sticky-action-bar .btn { flex: 1 1 auto; }
  .sticky-action-bar .btn-row { width: 100%; flex-wrap: nowrap; }
  .sticky-action-bar:has(.action-secondary) { flex-wrap: nowrap; gap: 8px; }
  .sticky-action-bar .action-secondary { width: auto; flex: 0 0 auto; gap: 6px; }
  .sticky-action-bar .action-secondary .btn { flex: 0 0 auto; width: 48px; padding: 0; font-size: 18px; }
  .btn-label { display: none; }
  .approve-group { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .sticky-action-bar:has(.action-secondary) .approve-group { width: auto; flex: 1 1 auto; flex-wrap: nowrap; }
  .approve-group .btn { width: 100%; }

  /* typing in a field: shrink the pinned photo so the field and the keyboard both fit */
  body.editing-field .document-viewer-card:not(.viewer-collapsed):not(.is-fullscreen) { height: 24vh; min-height: 150px; }

  /* dialogs and modals become bottom sheets */
  .app-dialog-overlay, .modal-overlay { align-items: flex-end; padding: 0; }
  .app-dialog, .modal-box { max-width: 100%; border-radius: 18px 18px 0 0; max-height: 90vh; padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); }
  .app-dialog-actions .btn, .modal-foot .btn { flex: 1 1 auto; }

  /* capture + batch */
  .preflight-dropzone { padding: 24px 14px; }
  .preflight-dropzone .btn-row { flex-direction: column; width: 100%; }
  .preflight-dropzone .btn-row .btn { width: 100%; }
  .preflight-thumb-img { max-height: 46vh; }
  .preflight-actions .btn { width: 100%; }
  .batch-item { flex-wrap: wrap; }
  .batch-actions { width: 100%; justify-content: flex-end; }
  .batch-actions:empty { display: none; }
  .batch-foot .btn { flex: 1 1 auto; }
  .batch-list { max-height: none; }
  .chart-grid { grid-template-columns: minmax(0, 1fr); }
  .chart-box { height: 220px; }
}

/* ── Full-screen photo viewer (any screen size) ────────────────────── */
.document-viewer-card.is-fullscreen {
  position: fixed !important; inset: 0; top: 0 !important; z-index: 400; height: 100dvh !important; min-height: 0; border-radius: 0;
}
.document-viewer-card.is-fullscreen .viewer-foot { display: flex; }
body.viewer-open { overflow: hidden; }
