/* doc-capture stylesheet: no framework, light/dark via prefers-color-scheme, phone-first
   for capture and queue, two-column review on desktop. Extends the T01 base rules. */

:root {
  color-scheme: light dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eaeef2;
  --text: #1b2430;
  --muted: #5b6875;
  --border: #d3dae2;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --info: #1d4ed8;
  --info-bg: #e8f0ff;
  --success: #15803d;
  --success-bg: #e6f6ea;
  --warn: #b45309;
  --warn-bg: #fff4dd;
  --danger: #b91c1c;
  --danger-bg: #fdecec;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  --radius: 8px;
  --topbar-h: 3.25rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181d;
    --surface: #1c2229;
    --surface-2: #242c35;
    --text: #e6ebf0;
    --muted: #98a4b1;
    --border: #313c47;
    --accent: #2dd4bf;
    --accent-text: #08201d;
    --info: #93b4ff;
    --info-bg: #17223b;
    --success: #6ee7a0;
    --success-bg: #113322;
    --warn: #fbbf24;
    --warn-bg: #3a2c0f;
    --danger: #f87171;
    --danger-bg: #3b1717;
    --focus: #60a5fa;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.5rem; }
h3 { font-size: 0.95rem; margin: 0 0 0.4rem; }
code, kbd, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }
kbd { border: 1px solid var(--border); border-radius: 4px; padding: 0 0.3em; background: var(--surface-2); }
pre.json { white-space: pre-wrap; word-break: break-word; margin: 0.25rem 0 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); }
.ok { color: var(--success); }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
.plain { list-style: none; margin: 0; padding: 0; }
.plain li + li { margin-top: 0.25rem; }
[hidden] { display: none !important; }

/* --- chrome ---------------------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: var(--topbar-h);
  padding: 0.4rem 1rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 600; color: inherit; text-decoration: none; }
.nav { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius);
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.user-menu { margin-left: auto; position: relative; }
.user-menu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 0.4rem; }
.user-menu summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute;
  right: 0;
  top: 2.2rem;
  min-width: 14rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem;
  z-index: 30;
}
.content { padding: 1rem; max-width: 60rem; margin: 0 auto; }
.content.narrow { max-width: 28rem; }
.content.wide { max-width: 80rem; }
.content.full { max-width: none; padding: 0.75rem; }
.content.capture-main { padding: 0; }
.footer { padding: 0.5rem 1rem; font-size: 0.8rem; opacity: 0.7; text-align: center; }
.page-head { margin-bottom: 0.75rem; }
.crumbs { margin: 0 0 0.25rem; }

/* --- buttons, badges, chips ----------------------------------------------------------- */

.button, button.button, a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  min-height: 2.4rem;
}
.button:hover:not(:disabled) { background: var(--surface-2); }
.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.button.primary:hover:not(:disabled) { filter: brightness(1.05); background: var(--accent); }
.button.success { background: var(--success); color: var(--bg); border-color: transparent; }
.button.success:hover:not(:disabled) { background: var(--success); filter: brightness(1.08); }
.button.danger { background: var(--danger); color: var(--bg); border-color: transparent; }
.button.danger.ghost { background: transparent; color: var(--danger); border-color: var(--danger); }
.button.ghost { background: transparent; }
.button.small { padding: 0.25rem 0.55rem; min-height: 1.9rem; font-size: 0.9rem; }
.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}
.file-button { position: relative; overflow: hidden; }
.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
}
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted { background: var(--surface-2); color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.chip.is-active { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.chip-count { font-weight: 600; opacity: 0.8; }
.action-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.action-row.compact { gap: 0.3rem; }

/* --- cards, notices, dialogs ------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.cards { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
.cards.stack { grid-template-columns: 1fr; }
.link-card { color: inherit; text-decoration: none; }
.link-card:hover { border-color: var(--accent); }
.card-head { display: flex; justify-content: space-between; gap: 0.5rem; align-items: flex-start; margin-bottom: 0.5rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.notice, .banner {
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  margin: 0 0 0.75rem;
}
.notice.info, .banner.info { background: var(--info-bg); border-color: var(--info); }
.notice.success, .banner.success { background: var(--success-bg); border-color: var(--success); }
.notice.warn, .banner.warn { background: var(--warn-bg); border-color: var(--warn); }
.notice.danger, .banner.danger { background: var(--danger-bg); border-color: var(--danger); }
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  z-index: 50;
  max-width: min(90vw, 28rem);
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}
.toast-success { background: var(--success); color: var(--bg); }
.toast-warn { background: var(--warn); color: var(--bg); }
.toast-danger { background: var(--danger); color: var(--bg); }
dialog.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1.25rem;
  width: min(92vw, 30rem);
}
dialog.dialog.wide { width: min(96vw, 60rem); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }

/* --- forms ------------------------------------------------------------------------------ */

.form fieldset { border: none; padding: 0; margin: 0 0 0.75rem; min-width: 0; }
.form legend { font-weight: 600; padding: 0; margin-bottom: 0.4rem; }
.stack > * + * { margin-top: 0.75rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem 0.75rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.6rem 0.75rem; }
.field { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; position: relative; }
.field > span { font-size: 0.8rem; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 0.4rem; }
.field.grow { flex: 1; }
.check { display: flex; align-items: center; gap: 0.5rem; margin: 0.4rem 0; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
  min-width: 0;
  width: 100%;
}
input[type="checkbox"] { width: auto; }
input:focus, select:focus, textarea:focus, .button:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}
input.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.field .conf { font-size: 0.72rem; color: var(--muted); min-height: 0.9rem; }
.field.low-confidence input, .field.low-confidence select, .field.low-confidence textarea {
  border-color: var(--warn);
  background: var(--warn-bg);
}
.field.low-confidence .conf { color: var(--warn); }
.field.user-edited input, .field.user-edited select, .field.user-edited textarea { border-color: var(--success); }
.field.user-edited .conf { color: var(--success); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.field.has-error .conf { color: var(--danger); }
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: flex-end; }
.filters .field.inline { flex-direction: column; align-items: stretch; gap: 0.2rem; }
.filters .field.inline > span { font-size: 0.75rem; }

/* --- login ------------------------------------------------------------------------------ */

.login-card { margin-top: 2rem; }

/* --- queue ------------------------------------------------------------------------------ */

.queue-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.queue-list:focus { outline: none; }
.queue-row { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.queue-row.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.queue-link {
  display: grid;
  grid-template-columns: 3.25rem minmax(0, 1fr) auto;
  grid-template-areas: "thumb main meta" "thumb badges badges";
  gap: 0.25rem 0.75rem;
  padding: 0.6rem;
  color: inherit;
  text-decoration: none;
  align-items: center;
}
.queue-link:hover { background: var(--surface-2); }
.queue-link .thumb { grid-area: thumb; }
.queue-main { grid-area: main; min-width: 0; }
.queue-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-meta { grid-area: meta; text-align: right; }
.queue-amount { font-weight: 600; font-variant-numeric: tabular-nums; }
.queue-badges { grid-area: badges; display: flex; flex-wrap: wrap; gap: 0.3rem; }
.thumb {
  width: 3.25rem;
  height: 4.25rem;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: block;
}
.thumb-empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.8rem; }
.queue-foot { margin: 0.75rem 0; display: flex; gap: 0.75rem; align-items: center; }
.kbd-hint { margin: 0.5rem 0 0; }
@media (max-width: 600px) {
  .queue-link { grid-template-columns: 2.75rem minmax(0, 1fr); grid-template-areas: "thumb main" "thumb meta" "badges badges"; }
  .queue-meta { text-align: left; display: flex; gap: 0.5rem; }
  .thumb { width: 2.75rem; height: 3.5rem; }
  .kbd-hint { display: none; }
}

/* --- review ----------------------------------------------------------------------------- */

.review { display: grid; gap: 0.75rem; grid-template-columns: 1fr; }
@media (min-width: 960px) {
  .review { grid-template-columns: minmax(0, 1fr) minmax(26rem, 34rem); align-items: start; }
  .viewer { position: sticky; top: calc(var(--topbar-h) + 0.75rem); height: calc(100vh - var(--topbar-h) - 1.5rem); }
}
.viewer {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 24rem;
}
@media (max-width: 959px) { .viewer { height: 60vh; } }
.viewer-toolbar { display: flex; align-items: center; gap: 0.25rem; padding: 0.4rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.viewer-stage { flex: 1; overflow: auto; background: #2a2f36; display: flex; align-items: flex-start; justify-content: center; padding: 0.5rem; }
.viewer-stage img { width: 100%; height: auto; max-width: none; transform-origin: center center; transition: transform 0.15s ease; background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4); }
.viewer-stage.is-zoomed { justify-content: flex-start; }
.viewer-stage .muted { color: #c7ced6; margin: auto; }
.thumbs { display: flex; gap: 0.4rem; overflow-x: auto; padding: 0.4rem; border-top: 1px solid var(--border); }
.thumb-button { background: none; border: 2px solid transparent; border-radius: 6px; padding: 0; cursor: pointer; flex: 0 0 auto; }
.thumb-button.is-active { border-color: var(--accent); }
.thumb-item { position: relative; margin: 0; flex: 0 0 auto; text-align: center; }
.thumb-item .thumb { width: 4rem; height: 5.25rem; }
.thumb-remove {
  position: absolute;
  top: -0.4rem;
  right: -0.4rem;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; min-width: 0; }
.panel.is-readonly .form { opacity: 0.85; }
.panel-head { display: flex; justify-content: space-between; gap: 0.75rem; align-items: flex-start; margin-bottom: 0.75rem; }
.doc-title { font-size: 1.2rem; margin: 0; word-break: break-word; }
.panel-badges { display: flex; flex-wrap: wrap; gap: 0.3rem; justify-content: flex-end; }
.vendor-box { border: 1px solid var(--border) !important; border-radius: var(--radius); padding: 0.75rem !important; }
.vendor-box .field + .field, .vendor-box .field + .check { margin-top: 0.5rem; }
.combo { position: relative; }
.combo-results {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 10;
  list-style: none;
  margin: 0.15rem 0 0;
  padding: 0.25rem 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 14rem;
  overflow: auto;
}
.combo-results li { padding: 0.35rem 0.6rem; cursor: pointer; }
.combo-results li:hover, .combo-results li:focus { background: var(--surface-2); outline: none; }
.lines-box { border: 1px solid var(--border) !important; border-radius: var(--radius); padding: 0.75rem !important; overflow-x: auto; }
table.lines { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.lines th, table.lines td { padding: 0.25rem 0.3rem; text-align: left; vertical-align: top; }
table.lines th { color: var(--muted); font-weight: 500; font-size: 0.78rem; border-bottom: 1px solid var(--border); }
table.lines tfoot td { border-top: 1px solid var(--border); padding-top: 0.5rem; }
table.lines input, table.lines select { padding: 0.3rem 0.4rem; }
table.lines td.num input { width: 7rem; }
tr.line-row.low-confidence td { background: var(--warn-bg); }
tr.line-row.has-error td { background: var(--danger-bg); }
.hint { display: block; margin-top: 0.15rem; }
.totals { margin-top: 0.5rem; }
.warnings { border: 1px solid var(--warn); background: var(--warn-bg); border-radius: var(--radius); padding: 0.6rem 0.8rem; margin: 0.75rem 0; }
.warnings ul { margin: 0; padding-left: 1.1rem; }
.actions { margin-top: 0.75rem; }
.gate-reasons { margin: 0.5rem 0 0; padding-left: 1.1rem; color: var(--warn); font-size: 0.9rem; }
.history { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 0.75rem; }
.dup-row { display: flex; justify-content: space-between; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-top: 0.4rem; }
.compare-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin: 0.75rem 0; }
.compare-thumb { width: 100%; max-height: 22rem; object-fit: contain; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
@media (max-width: 700px) { .compare-grid { grid-template-columns: 1fr; } }

/* --- upload ------------------------------------------------------------------------------ */

.upload { display: flex; flex-direction: column; gap: 0.75rem; }
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  text-align: center;
  background: var(--surface);
  cursor: pointer;
}
.dropzone:focus-visible { outline: 2px solid var(--focus); }
.dropzone.is-over { border-color: var(--accent); background: var(--surface-2); }
.dropzone-title { font-weight: 600; margin: 0 0 0.25rem; }
.dropzone p { margin: 0.25rem 0; }
.upload-list { list-style: none; margin: 1rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.upload-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.8rem; }
.upload-item.is-created { border-left: 4px solid var(--success); }
.upload-item.is-duplicate { border-left: 4px solid var(--warn); }
.upload-item.is-rejected, .upload-item.is-error { border-left: 4px solid var(--danger); }
.upload-head { display: flex; justify-content: space-between; gap: 0.5rem; }
.upload-name { font-weight: 600; word-break: break-all; }
progress { width: 100%; height: 0.5rem; accent-color: var(--accent); }
.upload-progress { margin: 0.35rem 0; }

/* --- capture ----------------------------------------------------------------------------- */

.capture { display: flex; flex-direction: column; min-height: calc(100vh - var(--topbar-h)); background: #000; color: #fff; }
.capture-stage { position: relative; flex: 1; min-height: 50vh; display: flex; align-items: center; justify-content: center; background: #000; }
.capture-stage video, .capture-stage img { max-width: 100%; max-height: 70vh; width: 100%; object-fit: contain; display: block; }
.camera-fallback { padding: 1.5rem; text-align: center; max-width: 26rem; }
.camera-fallback .muted { color: #b8c0c8; }
.capture-controls {
  background: var(--surface);
  color: var(--text);
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.capture-row { display: flex; align-items: center; justify-content: center; gap: 0.75rem; flex-wrap: wrap; }
.capture-row .field.inline { flex: 0 1 auto; }
.shutter {
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 50%;
  border: 4px solid var(--accent);
  background: var(--surface);
  cursor: pointer;
  box-shadow: inset 0 0 0 3px var(--surface), inset 0 0 0 100px var(--accent);
}
.shutter:disabled { opacity: 0.4; cursor: not-allowed; }
.shutter:active:not(:disabled) { transform: scale(0.95); }
.capture-controls .thumbs { border-top: none; padding: 0.25rem 0; }
.capture-controls .thumbs:empty { display: none; }

/* --- audit and tables ---------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.9rem; }
table.table th, table.table td { padding: 0.4rem 0.5rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
table.table th { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
table.table details summary { cursor: pointer; color: var(--accent); }

/* --- legal ---------------------------------------------------------------------------------- */

.legal p { max-width: 60ch; }
