/* Photo extractor — the "workbench" wireframe, built as drawn.
 *
 * The hand-drawn look is deliberate and specified: 1.5px ink strokes, hard
 * offset shadows with no blur, slightly irregular corner radii. Nothing here
 * is a placeholder for a "real" skin later.
 *
 * Fonts are vendored in /static/fonts and never fetched from a CDN — HR
 * machines may be locked down, and a webfont that fails to load silently
 * changes every measurement on the page.
 */

:root {
  --paper:  #fbfaf7;   /* the workbench ground */
  --card:   #ffffff;   /* panel surfaces */
  --rail:   #f4f2ee;   /* tool rail and filmstrip */
  --sunk:   #faf9f6;   /* recessed areas */
  --ink:    #1a1a1a;   /* the pen */
  --pencil: #8a857c;   /* secondary text */
  --rule:   #cfcbc3;   /* light strokes */
  --faint:  #e0ddd6;   /* dividers */
  --blue:   #2f6feb;   /* the one accent: selection, corners, primary action */
  --wash:   #eef4ff;
  --warn:   #fdf7e3;
  --error:  #fdecec;

  --hand: 'Architects Daughter', 'Segoe Print', 'Comic Sans MS', cursive;
  --note: 'Kalam', 'Segoe Print', 'Comic Sans MS', cursive;
  --mono: ui-monospace, 'Cascadia Mono', Menlo, monospace;

  --shadow: 2px 2px 0 rgba(0, 0, 0, .10);
  --stroke: 1.5px solid var(--ink);
  /* Irregular on purpose — a drawn box is never square-cornered. */
  --sketch: 9px 11px 8px 12px;
}

* { box-sizing: border-box; }

/* Several elements below set `display`, which outranks the user-agent's
 * [hidden] { display: none } and leaves them on screen forever. Restore the
 * attribute's meaning once, here, rather than remembering it at every site. */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 18px;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 var(--hand);
  -webkit-text-size-adjust: 100%;
}

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

.shell {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) 210px;
  gap: 14px;
  max-width: 1240px;
  margin: 0 auto;
  align-items: start;
}

.rail, .work, .panel {
  border: var(--stroke);
  border-radius: var(--sketch);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.rail  { background: var(--rail); padding: 12px 11px; }
.work  {
  background: var(--card);
  min-height: 420px;
  max-height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
}
.panel { background: var(--sunk); padding: 12px 11px; display: flex; flex-direction: column; gap: 10px; }

/* --- shared bits -------------------------------------------------------- */

.eyebrow {
  margin: 0;
  font: 600 10px/1.4 var(--mono);
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--pencil);
}

/* --- tool rail ---------------------------------------------------------- */

.rail-brand { margin: 0 0 10px; font-size: 17px; }

.rail-tools { display: flex; flex-direction: column; gap: 7px; }

.tool {
  display: block;
  border-radius: 6px 7px 5px 8px;
  padding: 6px 9px;
  font-size: 14px;
}
.tool-on  { border: 1.5px solid var(--blue); background: var(--wash); }
.tool-off { border: 1.5px dashed var(--rule); color: var(--pencil); }

.rail-pages { margin-top: 16px; }

.filmstrip {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 340px;
  overflow-y: auto;
}

.thumb {
  display: block;
  width: 100%;
  padding: 0;
  border: 1.5px solid var(--rule);
  border-radius: 4px;
  background: var(--card);
  cursor: pointer;
  overflow: hidden;
  line-height: 0;
}
.thumb img { width: 100%; height: auto; display: block; }
.thumb.on { border: 2px solid var(--blue); }
.thumb-n {
  display: block;
  font: 600 9px/1.7 var(--mono);
  color: var(--pencil);
  line-height: 15px;
  background: var(--rail);
}
.thumb.on .thumb-n { background: var(--blue); color: #fff; }

.rail-note {
  margin: 16px 0 0;
  font-family: var(--note);
  font-size: 12px;
  line-height: 1.4;
  color: var(--pencil);
}

.langs { display: flex; gap: 4px; margin-top: 14px; }
.lang {
  flex: 1;
  border: 1.5px solid var(--rule);
  border-radius: 11px 13px 11px 14px;
  background: var(--card);
  color: var(--pencil);
  font: 600 10px/1.6 var(--mono);
  letter-spacing: .04em;
  padding: 3px 0;
  cursor: pointer;
}
.lang.on { border: 2px solid var(--blue); background: var(--wash); color: var(--ink); }
.lang:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* --- work area ---------------------------------------------------------- */

.banner {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  border-bottom: 1.5px solid var(--faint);
  background: var(--wash);
  font-size: 14px;
}
.banner-mark {
  flex: none;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--blue);
}
.banner-text { margin: 0; flex: 1; }
.banner-tag { font-family: var(--note); font-size: 11px; color: var(--pencil); }

.banner.is-warn  { background: var(--warn); }
.banner.is-error { background: var(--error); }
.banner.is-warn .banner-mark,
.banner.is-error .banner-mark {
  width: auto; height: auto; border-radius: 0;
  background: none; font-size: 14px;
}
.banner.is-warn  .banner-mark::before { content: '!'; }
.banner.is-error .banner-mark::before { content: '\00d7'; }

.drop {
  margin: 14px;
  padding: 22px;
  min-height: 170px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  text-align: center;
  border: 2px dashed #b6bcc7;
  border-radius: 12px;
  background: #fdfdfd;
  cursor: pointer;
}
.drop.over { border-color: var(--blue); background: var(--wash); }
.drop:focus-within { outline: 2px solid var(--blue); outline-offset: 3px; }
.drop-big { font-size: 17px; }
.drop-small { font-family: var(--note); font-size: 13px; color: var(--pencil); }

/* The page has to fit beside the preview panel, not push it off screen: the
 * whole point of this layout is seeing the crop and the result at once. */
.stage {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: auto;
}
.frame {
  position: relative;
  line-height: 0;
  touch-action: none;
  user-select: none;
  box-shadow: var(--shadow);
  background: repeating-linear-gradient(135deg, #f2f1ee 0 5px, #e8e6e1 5px 10px);
}
#page {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100vh - 190px);
}
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#quad {
  fill: rgba(47, 111, 235, .12);
  stroke: var(--blue);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}
.handle {
  fill: #fff;
  stroke: var(--blue);
  stroke-width: 3;
  cursor: grab;
  vector-effect: non-scaling-stroke;
}
.handle:focus { outline: none; stroke: var(--ink); stroke-width: 4; }

#loupe {
  position: absolute;
  width: 180px; height: 180px;
  border-radius: 50%;
  border: 2px solid var(--blue);
  background: #fff;
  pointer-events: none;
  display: none;
}

.stage-hint {
  position: absolute;
  right: 10px; bottom: 8px;
  margin: 0;
  padding: 3px 9px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .88);
  font-family: var(--note);
  font-size: 12px;
  color: var(--pencil);
}

/* --- right panel -------------------------------------------------------- */

.preview {
  border: var(--stroke);
  border-radius: 5px 6px 5px 7px;
  background: var(--card);
  display: grid;
  place-items: center;
  min-height: 150px;
  padding: 7px;
}
.preview img { max-width: 100%; max-height: 210px; display: block; }
.preview-empty {
  margin: 0;
  font-family: var(--note);
  font-size: 12px;
  color: var(--pencil);
  text-align: center;
}
.preview.is-stale { opacity: .45; }

.readout { margin: 0; font: 10.5px/1.4 var(--mono); color: var(--pencil); }

.sizes, .formats { margin: 0; padding: 0; border: 0; }
.sizes { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.sizes legend, .formats legend { padding: 0 0 5px; }
.formats { display: flex; gap: 5px; flex-wrap: wrap; }
.formats legend { width: 100%; }

.size, .fmt {
  border: 1.5px solid var(--rule);
  background: var(--card);
  color: var(--ink);
  font-family: var(--hand);
  font-size: 13px;
  cursor: pointer;
  padding: 7px 5px;
  border-radius: 5px 6px 5px 7px;
}
.size small { display: block; font-family: var(--note); font-size: 10px; color: var(--pencil); }
.fmt { flex: 1; border-radius: 14px; padding: 5px; }
.size.on, .fmt.on { border: 2px solid var(--blue); background: var(--wash); }
.size:focus-visible, .fmt:focus-visible, .thumb:focus-visible,
.go:focus-visible, summary:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.custom { font-size: 13px; }
.custom summary {
  cursor: pointer;
  padding: 6px 8px;
  border: 1.5px dashed var(--rule);
  border-radius: 5px 6px 5px 7px;
}
.custom-row { display: flex; flex-direction: column; gap: 6px; padding: 8px 2px 0; }
.custom-row label { display: flex; align-items: center; gap: 6px; }
.custom-row input {
  width: 62px;
  border: 1.5px solid var(--rule);
  border-radius: 4px;
  padding: 4px 6px;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--card);
  color: var(--ink);
}
.custom-row span { font-family: var(--note); font-size: 11px; color: var(--pencil); }

.go {
  margin-top: auto;
  border: var(--stroke);
  border-radius: 6px 8px 6px 9px;
  background: var(--blue);
  color: #fff;
  font-family: var(--hand);
  font-size: 15px;
  padding: 9px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.go:disabled { background: #b9c9ef; border-color: var(--rule); cursor: default; box-shadow: none; }
.go:not(:disabled):active { transform: translate(2px, 2px); box-shadow: none; }

.status { margin: 0; font-family: var(--note); font-size: 12px; color: var(--pencil); min-height: 1.2em; }

.notes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.notes li {
  border: var(--stroke);
  border-radius: 5px 6px 5px 7px;
  padding: 7px 9px;
  font-family: var(--note);
  font-size: 12px;
  line-height: 1.35;
  background: var(--warn);
}
.notes li.is-error { background: var(--error); }

/* --- form reader --------------------------------------------------------- */

/* The field panel needs room for a label, a crop strip and a value; the
 * wireframe measured the photo extractor's 210px panel as unreadable for
 * exactly this content, which is why the forms page widens its column. */
.shell--forms { grid-template-columns: 150px minmax(0, 1fr) 360px; }

a.tool { text-decoration: none; color: inherit; cursor: pointer; }
a.tool:hover { border-style: solid; color: var(--ink); }

.banner-act {
  flex: none;
  border: 1.5px solid var(--ink);
  border-radius: 6px 7px 5px 8px;
  background: var(--card);
  color: var(--ink);
  font-family: var(--hand);
  font-size: 13px;
  padding: 5px 12px;
  cursor: pointer;
}

.tpl {
  margin: 0 14px 14px;
  border: 1.5px dashed var(--rule);
  border-radius: var(--sketch);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tpl-name { margin: 0; font-size: 15px; }
.tpl-meta { margin: 0; font: 10.5px/1.4 var(--mono); color: var(--pencil); }
.tpl-note { margin: 0; font-family: var(--note); font-size: 12px; color: var(--pencil); }

#marks { position: absolute; inset: 0; }
.mark {
  position: absolute;
  border: 1.5px solid rgba(47, 111, 235, .55);
  background: rgba(47, 111, 235, .05);
  cursor: pointer;
}
.mark.is-needs { border-style: dashed; border-color: #b58900; background: rgba(181, 137, 0, .08); }
.mark.is-sel { border: 2.5px solid var(--blue); background: rgba(47, 111, 235, .14); }

.manualbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1.5px solid var(--faint);
  width: 100%;
}
.manualbar-hint { margin: 0; flex: 1; font-family: var(--note); font-size: 13px; color: var(--pencil); }
.go--inline { margin-top: 0; }
.go--ghost { background: var(--card); color: var(--ink); }

.panel--fields { max-height: calc(100vh - 36px); overflow-y: auto; }

.fields-head { margin: 0; font-size: 15px; line-height: 1.3; }

.fieldlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.fieldrow {
  border: 1.5px solid var(--rule);
  border-radius: 6px 7px 5px 8px;
  background: var(--card);
  padding: 8px 9px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
}
.fieldrow.is-sel { border: 2px solid var(--blue); }
.fieldrow-head { display: flex; align-items: baseline; gap: 7px; }
.f-label { font-size: 13.5px; flex: 1; }

.chip {
  font-family: var(--note);
  font-size: 10.5px;
  padding: 1px 8px;
  border-radius: 9px;
  border: 1.5px solid var(--rule);
  color: var(--pencil);
  white-space: nowrap;
}
.chip-read      { border-color: var(--rule); }
.chip-unsure    { border-color: #b58900; background: var(--warn); color: var(--ink); }
.chip-failed    { border-color: #b04a4a; background: var(--error); color: var(--ink); }
.chip-empty     { border-style: dashed; }
.chip-fixed,
.chip-confirmed,
.chip-blank     { border-color: var(--blue); background: var(--wash); color: var(--ink); }

.f-crop { border: 1.5px solid var(--faint); border-radius: 3px; background: #fff; line-height: 0; overflow: hidden; }
.f-crop img { width: 100%; height: 34px; object-fit: contain; display: block; }
/* Unsure and failed rows get a bigger crop: that is the row a person actually
 * has to look at (wireframe 1e). */
.fieldrow.is-needs .f-crop img { height: 56px; }

.f-value { font: 600 14px/1.3 var(--mono); word-break: break-all; min-height: 1.2em; }
.f-value.is-empty { color: var(--pencil); font-weight: 400; }
.f-was, .f-check { margin: 0; font-family: var(--note); font-size: 11px; color: var(--pencil); }
.f-check { color: #8a3030; }

.f-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.f-btn {
  border: 1.5px solid var(--rule);
  border-radius: 5px 6px 5px 7px;
  background: var(--card);
  color: var(--ink);
  font-family: var(--hand);
  font-size: 12px;
  padding: 4px 9px;
  cursor: pointer;
}
.f-btn--primary { border-color: var(--ink); background: var(--blue); color: #fff; }
.f-btn--copy { margin-left: auto; font-family: var(--mono); font-size: 10px; }
.f-btn--copy.is-done { border-color: var(--blue); background: var(--wash); }

.f-edit { display: flex; flex-direction: column; gap: 5px; }
.f-edit input {
  border: 2px solid var(--blue);
  border-radius: 4px;
  padding: 6px 8px;
  font: 600 14px var(--mono);
  background: var(--card);
  color: var(--ink);
  width: 100%;
}
.f-hint { margin: 0; font: 10.5px/1.4 var(--mono); color: var(--pencil); }
.f-hint.is-bad { color: #8a3030; }

.verifyfoot { display: flex; flex-direction: column; gap: 7px; border-top: 1.5px dashed var(--faint); padding-top: 9px; }
.progress { margin: 0; font: 10.5px/1.5 var(--mono); color: var(--pencil); }
.jump {
  border: 1.5px solid var(--rule);
  border-radius: 5px 6px 5px 7px;
  background: var(--card);
  color: var(--ink);
  font-family: var(--hand);
  font-size: 12.5px;
  padding: 6px;
  cursor: pointer;
}
.jump:disabled { opacity: .45; cursor: default; }
.honest { margin: 0; font-family: var(--note); font-size: 11px; line-height: 1.4; color: var(--pencil); }

.exportbox { display: flex; flex-direction: column; gap: 7px; border-top: 1.5px dashed var(--faint); padding-top: 9px; }
.exportwarn {
  border: var(--stroke);
  border-radius: 5px 6px 5px 7px;
  background: var(--warn);
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.exportwarn p { margin: 0; font-family: var(--note); font-size: 12px; line-height: 1.35; }
.exportnames { color: var(--pencil); }
.copymarked { margin: 0; font-family: var(--note); font-size: 10.5px; color: var(--pencil); }

/* --- admin template editor ----------------------------------------------- */

.admin-tag {
  margin: 14px 0 0;
  font: 600 10px ui-monospace, Menlo, monospace;
  letter-spacing: .08em;
  color: #8a3030;
  border: 1.5px dashed #b04a4a;
  border-radius: 4px;
  padding: 3px 7px;
  text-align: center;
}
.frame--draw { cursor: crosshair; touch-action: none; user-select: none; }
.frame--draw #marks { cursor: crosshair; }
#rubber {
  position: absolute;
  border: 2px dashed var(--blue);
  background: rgba(47, 111, 235, .10);
  pointer-events: none;
}
.mark-n {
  position: absolute;
  left: -1px; top: -1px;
  background: var(--blue);
  color: #fff;
  font: 600 10px ui-monospace, Menlo, monospace;
  padding: 1px 5px;
  border-radius: 0 0 4px 0;
}
.tplmeta { display: flex; flex-direction: column; gap: 7px; }
.tpl-input { display: flex; flex-direction: column; gap: 3px; }
.tpl-input input, .tpl-input select {
  border: 1.5px solid var(--rule);
  border-radius: 4px;
  padding: 5px 8px;
  font-family: var(--hand);
  font-size: 13px;
  background: var(--card);
  color: var(--ink);
  width: 100%;
}
.tpl-input select { font-family: var(--note); }
a.go { text-align: center; text-decoration: none; display: block; }

.batchlist { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.batchlist li { display: flex; justify-content: space-between; font-family: var(--note); font-size: 12px; }
.batch-state { color: var(--pencil); }
.batch-state.is-done { color: var(--blue); }

@media (max-width: 940px) {
  .shell--forms { grid-template-columns: minmax(0, 1fr); }
  .panel--fields { max-height: none; }
}

/* --- narrow screens ----------------------------------------------------- */

@media (max-width: 940px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-start; }
  .rail-tools { flex-direction: row; flex-wrap: wrap; }
  .rail-pages { margin-top: 0; width: 100%; }
  .filmstrip { flex-direction: row; max-height: none; overflow-x: auto; }
  .thumb { width: 74px; flex: none; }
  .rail-note { margin-top: 0; }
  .go { margin-top: 8px; }
  /* Stacked, the preview sits below the page. Keep the page short enough that
   * adjusting a corner and checking the result is not a long scroll. */
  #page { max-height: 58vh; }
}

/* --- Russian ------------------------------------------------------------ */

/* Architects Daughter and Kalam publish latin and latin-ext only, so Cyrillic
 * would fall back to a system sans and lose the sketch identity entirely --
 * and Russian is the default language, so that would be most users. Caveat is
 * the hand-drawn face that does ship cyrillic.
 *
 * The whole stack swaps rather than letting the browser pick per glyph: a
 * string like "Страница 1" would otherwise be drawn by two different pens,
 * since the digits are Latin. Caveat sits smaller and lighter than Architects
 * Daughter, hence the size bump; the two type roles are kept apart by weight
 * instead of by family. */
html[lang="ru"] {
  --hand: 'Caveat', 'Segoe Script', cursive;
  --note: 'Caveat', 'Segoe Script', cursive;
}
html[lang="ru"] body { font-size: 17.5px; font-weight: 600; }
html[lang="ru"] .rail-note,
html[lang="ru"] .status,
html[lang="ru"] .notes li,
html[lang="ru"] .preview-empty,
html[lang="ru"] .drop-small,
html[lang="ru"] .stage-hint,
html[lang="ru"] .banner-tag,
html[lang="ru"] .size small { font-weight: 400; }
/* The monospace roles (.eyebrow, .readout, .thumb-n, .lang) need no rule here:
 * each sets a `font:` shorthand, which already pins family, size and weight
 * against the body changes above. An earlier attempt to "protect" them with
 * `font-size: unset` did the opposite — unset means inherit, so they took the
 * 17.5px body size and the panel labels wrapped. */

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
