:root {
  --bg: #12141a; --panel: #191c24; --line: #272b36; --ink: #e6e8ef;
  --dim: #8b93a7; --accent: #6ea8fe; --high: #f0c85a; --med: #8b93a7;
  --low: #5c6478; --danger: #ff6b6b; --ok: #4ec9a0;
}
* { box-sizing: border-box; }

/* The `hidden` attribute works through the UA stylesheet's `[hidden]{display:none}`,
   which ANY author-level `display:` rule outranks. Several panels below set
   `display: grid`/`flex`, so without this they ignore `hidden` entirely and all
   render stacked on load. Author-level and !important so it always wins. */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 14px/1.5 ui-sans-serif, -apple-system, "Segoe UI", sans-serif; }
body { display: flex; flex-direction: column; }

header { padding: 14px 20px; border-bottom: 1px solid var(--line); display: flex;
  align-items: baseline; gap: 14px; flex: none; }
h1 { font-size: 16px; margin: 0; letter-spacing: .5px; }
.privacy { margin: 0; color: var(--ok); font-size: 12px; }
.build { color: var(--low); font-size: 11px; font-family: ui-monospace, monospace; }
.manifest { margin-left: auto; display: flex; align-items: center; gap: 7px;
  font-size: 11px; color: var(--dim); }
.btn.tiny { padding: 3px 8px; font-size: 11px; }

.drop { flex: 1; display: grid; place-items: center; padding: 40px; }
.drop.over .drop-inner { border-color: var(--accent); background: #1b2130; }
.drop-inner { border: 2px dashed var(--line); border-radius: 12px; padding: 60px 80px;
  text-align: center; display: grid; gap: 10px; justify-items: center; }
.drop-inner strong { font-size: 18px; }
.drop-inner span { color: var(--dim); }
.hint { color: var(--dim); font-size: 12px; margin: 8px 0 0; max-width: 40ch; }

.btn { background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  padding: 7px 14px; border-radius: 7px; cursor: pointer; font-size: 13px; text-decoration: none;
  display: inline-block; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0d1117; font-weight: 600; }
.btn.primary:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary:not(:disabled):hover { filter: brightness(1.1); }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.toolbar { display: flex; gap: 14px; align-items: flex-end; padding: 12px 20px;
  border-bottom: 1px solid var(--line); flex: none; flex-wrap: wrap; }
.spacer { flex: 1; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .6px; }
.field em { text-transform: none; letter-spacing: 0; }
.field input, .field select { background: var(--panel); border: 1px solid var(--line);
  color: var(--ink); padding: 6px 9px; border-radius: 6px; font-size: 13px; min-width: 190px; }
.field.small input, .field.small select { min-width: 0; }
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dim);
  padding-bottom: 6px; cursor: pointer; }

.body { flex: 1; display: flex; min-height: 0; }
/* Flex, not grid: as a grid item a thumb whose only in-flow child is a
   percentage-width canvas collapses its row to zero, and `overflow: hidden`
   then clips the rendered page to a 4px sliver. Flex items size to content. */
.rail { width: 116px; border-right: 1px solid var(--line); overflow-y: auto; padding: 10px;
  display: flex; flex-direction: column; gap: 8px; flex: none; }
.thumb { position: relative; border: 2px solid transparent; border-radius: 4px; cursor: pointer;
  background: #fff; overflow: hidden; flex: none; }
.thumb.sel { border-color: var(--accent); }
.thumb canvas { display: block; width: 100%; }
.thumb .n { position: absolute; bottom: 2px; right: 4px; font-size: 10px; color: #333;
  background: #fffc; padding: 0 4px; border-radius: 3px; }
.thumb .warn { position: absolute; top: 2px; left: 4px; font-size: 11px; }

/* The page area scrolls; the pager does not. A tall page otherwise pushes the
   navigation below the fold, which is exactly when it is most needed. */
.stage { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pagearea { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column;
  align-items: center; gap: 10px; }
.wrap { position: relative; line-height: 0; box-shadow: 0 4px 24px #0008; }
.wrap canvas { display: block; }
.overlay { position: absolute; inset: 0; cursor: crosshair; }
.rbox { position: absolute; background: #000; border: 1px solid var(--danger); cursor: pointer; }
.rbox.pending { background: #00000030; border-style: dashed; }
.rbox:hover { outline: 2px solid var(--danger); }
.stagehint { color: var(--dim); font-size: 12px; margin: 0; }
.pager { display: flex; gap: 8px; align-items: center; flex: none;
  padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.pager .btn { padding: 5px 10px; }
.pager .btn:disabled { opacity: .35; cursor: default; border-color: var(--line); }
.pageno { color: var(--dim); font-size: 13px; display: flex; align-items: center; gap: 5px; }
.pageno input { width: 58px; text-align: center; background: var(--panel);
  border: 1px solid var(--line); color: var(--ink); border-radius: 6px; padding: 5px 4px;
  font-size: 13px; }
.pageno input:focus { outline: none; border-color: var(--accent); }
.jumpmark { font-size: 11px; color: var(--high); }
.ocrtag { color: var(--accent); border: 1px solid var(--accent); border-radius: 3px;
  padding: 0 4px; font-size: 10px; }
.thumb .imgmark { position: absolute; bottom: 2px; left: 4px; font-size: 10px;
  color: #333; background: #fffc; padding: 0 3px; border-radius: 3px; }
.sizehint { font-size: 11px; color: var(--dim); max-width: 22ch; line-height: 1.3;
  padding-bottom: 4px; }
/* Placeholders need an explicit height: an empty box with only absolutely
   positioned children collapses, and the rail turns into a stack of slivers. */
.thumb.pending { height: 124px; }
.thumb.hasbox::after { content: ""; position: absolute; top: 3px; right: 3px; width: 7px;
  height: 7px; border-radius: 50%; background: var(--danger); }
.banner { background: #3a2f14; border: 1px solid var(--high); color: var(--high);
  padding: 8px 12px; border-radius: 7px; font-size: 13px; width: 100%; max-width: 900px; }

.side { width: 320px; border-left: 1px solid var(--line); display: flex; flex-direction: column;
  min-height: 0; flex: none; }
.sidehead { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex;
  justify-content: space-between; align-items: center; }
.sidehead h2 { font-size: 12px; margin: 0; text-transform: uppercase; letter-spacing: .8px; color: var(--dim); }
.count { font-size: 12px; color: var(--dim); }
.list { overflow-y: auto; padding: 8px; display: grid; gap: 6px; align-content: start; }
.empty { color: var(--dim); font-size: 13px; padding: 12px; margin: 0; }
.hit { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px;
  display: grid; grid-template-columns: auto 1fr; gap: 8px; cursor: pointer; }
.hit:hover { border-color: var(--accent); }
.hit input { margin: 3px 0 0; }
.hit .m { font-weight: 600; word-break: break-word; }
.hit .meta { font-size: 11px; color: var(--dim); display: flex; gap: 6px; align-items: center;
  flex-wrap: wrap; margin-top: 2px; }
.hit .ctx { font-size: 11px; color: var(--dim); margin-top: 4px; font-family: ui-monospace, monospace;
  word-break: break-word; }
.hit .ctx mark { background: #f0c85a44; color: var(--high); }
.tier { padding: 0 5px; border-radius: 3px; font-size: 10px; text-transform: uppercase;
  letter-spacing: .5px; border: 1px solid; }
.tier.high { color: var(--high); border-color: var(--high); }
.tier.medium { color: var(--med); border-color: var(--med); }
.tier.low { color: var(--low); border-color: var(--low); }
.tier.manual { color: var(--accent); border-color: var(--accent); }

.modal { position: fixed; inset: 0; background: #000b; display: grid; place-items: center; z-index: 20; }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 22px; width: min(560px, 92vw); max-height: 84vh; overflow: auto; }
.sheet h2 { margin: 0 0 14px; font-size: 16px; }
.mactions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.chk { display: flex; gap: 8px; padding: 5px 0; font-size: 13px; align-items: baseline; }
.chk .ic { flex: none; width: 16px; }
.chk.ok .ic { color: var(--ok); } .chk.warn .ic { color: var(--high); }
.chk.bad .ic { color: var(--danger); }
.chk.bad { color: var(--danger); }

.busy { position: fixed; inset: 0; background: #000c; display: grid; place-items: center;
  z-index: 30; gap: 14px; grid-auto-flow: row; align-content: center; justify-items: center; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
