/* OCR It — web edition. Warm paper workbench, ink text, teal go-actions. */

:root {
  --paper: #f6f3ec;
  --paper-deep: #efeae0;
  --card: #fdfcf8;
  --ink: #23211d;
  --ink-soft: #57534b;
  --ink-faint: #8a857a;
  --line: #ddd6c8;
  --accent: #0f766e;
  --accent-deep: #0b5751;
  --accent-soft: #d7ebe8;
  --go: #177245;
  --go-deep: #0f5c36;
  --stop: #b3352b;
  --warn-bg: #fdf3df;
  --warn-line: #e3c887;
  --warn-ink: #7a5b16;
  --err-bg: #fbe9e7;
  --err-line: #e5a49e;
  --err-ink: #8c2d24;
  --info-bg: #e9f0ee;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(35, 33, 29, 0.07), 0 4px 14px rgba(35, 33, 29, 0.06);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

kbd {
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--paper-deep);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  white-space: nowrap;
}

code { font-family: var(--mono); font-size: 0.88em; }

/* ------------------------------- top bar ------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { color: var(--accent); display: flex; }
.brand-text h1 { font-size: 18px; margin: 0; letter-spacing: 0.2px; line-height: 1.1; }
.brand-sub { font-size: 11px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 1.4px; }

.topbar-status { display: flex; align-items: center; gap: 8px; flex: 1; flex-wrap: wrap; }
.topbar-actions { display: flex; gap: 8px; }

.pill {
  font-size: 12px;
  font-family: var(--mono);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  background: var(--paper);
  color: var(--ink-soft);
  white-space: nowrap;
}
.pill.muted { color: var(--ink-faint); }
.pill.ready { background: var(--accent-soft); border-color: #a9d3cd; color: var(--accent-deep); }
.pill.busy { background: #e8ecf8; border-color: #b7c4e6; color: #2d4370; }
.pill.queue { background: #fdf3df; border-color: var(--warn-line); color: var(--warn-ink); }
.pill.err { background: var(--err-bg); border-color: var(--err-line); color: var(--err-ink); }
.pill.privacy { color: var(--accent-deep); }

/* -------------------------------- layout ------------------------------- */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 16px;
  padding: 16px 18px 24px;
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
  align-items: start;
}

.viewer-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.source-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.source-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--ink-faint);
  margin-right: 2px;
}

.doc-info {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 13px;
  color: var(--ink-soft);
}
.doc-name { font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60ch; }

/* -------------------------------- stage -------------------------------- */

.stage-wrap { min-width: 0; }

.stage {
  position: relative;
  background: #55524b;
  background-image: repeating-linear-gradient(45deg, rgba(255,255,255,0.025) 0 12px, transparent 12px 24px);
  border-radius: var(--radius);
  border: 1px solid #45423c;
  height: min(72vh, 860px);
  overflow: hidden;
  outline: none;
  box-shadow: var(--shadow);
  touch-action: none; /* drags on the stage draw regions, never scroll */
}
.stage.armed { cursor: crosshair; }
.stage:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }

.stage.empty { background: var(--paper-deep); border-color: var(--line); }

#page-canvas, #screen-video {
  position: absolute;
  display: block;
  background: #fff;
  box-shadow: 0 2px 18px rgba(0, 0, 0, 0.35);
}
.stage.empty #page-canvas { box-shadow: none; }

.welcome {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  touch-action: pan-y; /* the welcome text scrolls; everything else on the stage doesn't */
  padding: 34px clamp(18px, 6vw, 64px);
  background: var(--paper-deep);
  color: var(--ink);
}
.welcome h2 { margin: 0 0 10px; font-size: 24px; }
.welcome p { max-width: 62ch; color: var(--ink-soft); }
.welcome-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 18px 0 14px; }
.welcome-hint { font-size: 13px; color: var(--ink-faint); }
.welcome-how { margin-top: 14px; max-width: 68ch; color: var(--ink-soft); font-size: 14px; }
.welcome-how summary { cursor: pointer; color: var(--accent-deep); font-weight: 600; }
.welcome-how ol { padding-left: 20px; }
.welcome-how li { margin: 4px 0; }

.screen-panel {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  pointer-events: none;
  display: flex;
  justify-content: center;
  z-index: 5;
}
.screen-note {
  background: rgba(35, 33, 29, 0.88);
  color: #f1ede3;
  font-size: 12.5px;
  border-radius: 8px;
  padding: 8px 12px;
  max-width: 66ch;
  text-align: center;
  pointer-events: auto;
}

/* ---------------------------- region overlay --------------------------- */

.region-layer { position: absolute; inset: 0; z-index: 10; touch-action: none; }
.region-layer.picking { cursor: crosshair; }
.region-layer.idle { cursor: crosshair; }
.region-layer.idle .region-box { cursor: move; } /* a drag here slides the pinned region */

.region-shade {
  position: absolute;
  background: rgba(24, 23, 20, 0.45);
}

.region-box {
  position: absolute;
  border: 1.5px dashed #2dd4bf;
  box-shadow: 0 0 0 1px rgba(15, 23, 20, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.25);
  cursor: move;
  touch-action: none;
}
.region-layer.idle .region-box { border-style: solid; border-color: rgba(45, 212, 191, 0.85); }

.region-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 3px;
  transform: translate(-50%, -50%);
  touch-action: none;
}
.region-handle[data-k="nw"] { cursor: nwse-resize; }
.region-handle[data-k="se"] { cursor: nwse-resize; }
.region-handle[data-k="ne"] { cursor: nesw-resize; }
.region-handle[data-k="sw"] { cursor: nesw-resize; }
.region-handle[data-k="n"], .region-handle[data-k="s"] { cursor: ns-resize; }
.region-handle[data-k="e"], .region-handle[data-k="w"] { cursor: ew-resize; }

.region-size {
  position: absolute;
  top: -26px;
  right: -2px;
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--ink);
  color: #f1ede3;
  border-radius: 5px;
  padding: 2px 7px;
  white-space: nowrap;
}

.region-hintbar {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  background: rgba(35, 33, 29, 0.92);
  color: #f1ede3;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 8px;
  white-space: nowrap;
  max-width: calc(100% - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 12;
}
.region-hintbar kbd { background: #45423c; border-color: #5c584f; color: #f1ede3; }
.region-hintbar b { color: #7be8dc; }

/* -------------------------------- toast -------------------------------- */

.toast {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 20;
  background: rgba(35, 33, 29, 0.92);
  color: #f1ede3;
  font-size: 13px;
  border-radius: 8px;
  padding: 8px 13px;
  max-width: min(70%, 480px);
  pointer-events: none;
}
.toast.ok { border-left: 3px solid #34d399; }
.toast.warn { border-left: 3px solid #f0b64b; }
.toast.err { border-left: 3px solid #f07060; }

/* ------------------------------ toolbars ------------------------------- */

.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.pager { display: flex; align-items: center; gap: 8px; }
.page-indicator { font-family: var(--mono); font-size: 13px; color: var(--ink-soft); min-width: 11ch; text-align: center; }

.region-controls { display: flex; align-items: center; gap: 10px; }
.region-info { font-family: var(--mono); font-size: 12.5px; color: var(--ink-soft); }

.capture-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.capture-side { flex: 1; min-width: 220px; }

.note { font-size: 13px; border-radius: 8px; padding: 7px 11px; }
.note.info { background: var(--info-bg); color: var(--accent-deep); border: 1px solid #c3d4d0; }
.note.warn { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); }
.note.err { background: var(--err-bg); color: var(--err-ink); border: 1px solid var(--err-line); }
.muted-note { color: var(--ink-faint); font-size: 13px; padding: 7px 11px; }

/* ------------------------------- buttons ------------------------------- */

.btn {
  font: inherit;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 7px 13px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
}
.btn:hover:not(:disabled) { background: var(--paper-deep); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.small { font-size: 13px; padding: 5px 10px; }
.btn.big { font-size: 15px; padding: 10px 18px; font-weight: 600; }
.btn.big kbd { margin-left: 6px; background: rgba(255,255,255,0.2); border-color: rgba(255,255,255,0.3); color: inherit; }

.btn.primary { background: var(--accent); border-color: var(--accent-deep); color: #f6f3ec; }
.btn.primary:hover:not(:disabled) { background: var(--accent-deep); }
.btn.go { background: var(--go); border-color: var(--go-deep); color: #f6f3ec; }
.btn.go:hover:not(:disabled) { background: var(--go-deep); }
.btn.stop { background: var(--stop); border-color: #8c2d24; color: #f6f3ec; }
.btn.stop:hover:not(:disabled) { background: #8c2d24; }
.btn.danger { color: var(--stop); border-color: #e0b3ad; }
.btn.danger:hover:not(:disabled) { background: var(--err-bg); }

.link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 13px;
  color: var(--accent-deep);
  text-decoration: underline;
  cursor: pointer;
}

/* ------------------------------ transcript ----------------------------- */

.transcript-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  max-height: calc(100vh - 90px);
  position: sticky;
  top: 12px;
}

.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.list-head h2 { font-size: 15px; margin: 0; }

.pages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 160px;
}

.empty-transcript {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  padding: 26px 18px;
  color: var(--ink-faint);
  font-size: 14px;
  text-align: center;
  background: var(--card);
}

.page {
  display: flex;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
}
.page.dup { border-color: var(--warn-line); background: #fffcf4; }
.page.error { border-color: var(--err-line); }

.thumb {
  width: 96px;
  min-width: 96px;
  height: auto;
  align-self: flex-start;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  cursor: zoom-in;
}
.thumb-missing {
  width: 96px;
  min-width: 96px;
  height: 60px;
  border: 1px dashed var(--line);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-faint);
  font-size: 11px;
}

.page-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 7px; }

.page-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-n { font-weight: 700; font-size: 13.5px; }
.page-meta { font-size: 12px; color: var(--ink-faint); font-family: var(--mono); }

.chip {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  border-radius: 4px;
  padding: 2px 6px;
}
.chip.reading { background: #e8ecf8; color: #2d4370; }
.chip.error { background: var(--err-bg); color: var(--err-ink); }
.chip.dup { background: var(--warn-bg); color: var(--warn-ink); }

.preview {
  font-size: 13.5px;
  color: var(--ink-soft);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: text;
  max-height: 132px;
  overflow: hidden;
  position: relative;
}
.preview.collapsed { mask-image: linear-gradient(#000 70%, transparent); }
.preview.error-text { color: var(--err-ink); white-space: pre-wrap; cursor: default; }

.editor {
  font: inherit;
  font-size: 13.5px;
  width: 100%;
  min-height: 110px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px;
  background: #fff;
  color: var(--ink);
}
.editor:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.page-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.transcript-footer {
  display: flex;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

/* ------------------------------- settings ------------------------------ */

.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(35, 33, 29, 0.35);
  z-index: 40;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(430px, 94vw);
  background: var(--card);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 30px rgba(35, 33, 29, 0.18);
  z-index: 41;
  display: flex;
  flex-direction: column;
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.settings-head h2 { margin: 0; font-size: 16px; }

.settings-body { padding: 16px 18px 30px; overflow-y: auto; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-soft); margin: 8px 0; }
.field select, .field input {
  font: inherit;
  font-size: 14px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

.check { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; margin: 10px 0 2px; cursor: pointer; }
.check input { margin-top: 2px; accent-color: var(--accent); }

.settings-note { font-size: 12.5px; color: var(--ink-faint); margin: 3px 0 12px; }
.settings-body hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.settings-body .label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.2px; color: var(--ink-faint); margin-bottom: 6px; }

/* -------------------------------- fatal -------------------------------- */

.fatal {
  margin: 40px auto;
  max-width: 620px;
  background: var(--err-bg);
  border: 1px solid var(--err-line);
  color: var(--err-ink);
  border-radius: var(--radius);
  padding: 22px 26px;
}
.fatal pre {
  background: #fff;
  border: 1px solid var(--err-line);
  border-radius: 7px;
  padding: 10px 12px;
  overflow-x: auto;
  font-size: 13px;
}

/* ------------------------------- drop cue ------------------------------ */

.stage.drag-over { outline: 3px dashed var(--accent); outline-offset: -8px; }

/* ------------------------------- responsive ---------------------------- */

@media (max-width: 1023px) {
  .layout { grid-template-columns: 1fr; }
  .transcript-col { position: static; max-height: none; }
  .pages { max-height: none; overflow: visible; }
  .stage { height: min(60vh, 640px); }
  .topbar { gap: 10px; }
  .pill.privacy { display: none; }
}

@media (max-width: 560px) {
  body { font-size: 14px; }
  .layout { padding: 10px 10px 20px; }
  .topbar { padding: 8px 10px; }
  .capture-bar .btn.big { flex: 1 1 100%; }
  .thumb, .thumb-missing { width: 72px; min-width: 72px; }
  .welcome { padding: 22px 16px; }
  .welcome h2 { font-size: 20px; }
}
