:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --stage: #e3e6ea;
  --border: #d8dce2;
  --text: #171a1f;
  --muted: #5d6673;
  --accent: #1f4fd8;
  --accent-text: #ffffff;
  --accent-soft: #e6edff;
  --danger: #b42318;
  --mark: rgba(214, 40, 40, .28);
  --mark-border: #c81e1e;
  --hit: rgba(250, 200, 0, .45);
  --ok: #0b6b3a;
  --ok-soft: #e3f4ea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .08), 0 6px 20px rgba(16, 24, 40, .10);
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --surface: #1e2126;
    --surface-2: #24282e;
    --stage: #111316;
    --border: #353a42;
    --text: #e8eaed;
    --muted: #9aa3af;
    --accent: #6b93ff;
    --accent-text: #0c1020;
    --accent-soft: #1f2a48;
    --danger: #ff8a7a;
    --mark: rgba(255, 80, 80, .32);
    --mark-border: #ff6b6b;
    --ok: #6fd69c;
    --ok-soft: #173225;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .45);
  }
}

/* Inter, served from this site (no font services are contacted). SIL Open Font License, see vendor/inter/LICENSE. */
@font-face {
  font-family: "Inter"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url("../vendor/inter/inter-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url("../vendor/inter/inter-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "cv11", "ss03";
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
h1, h2, p { margin: 0; }
h2 {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.spacer { flex: 1; }

/* ---------- sign-in ---------- */
.app-root { display: contents; }
.gate {
  flex: 1; overflow: auto; display: grid; place-items: center; padding: 40px 24px;
  background:
    radial-gradient(900px 500px at 12% 10%, var(--accent-soft), transparent 60%),
    radial-gradient(700px 500px at 95% 95%, var(--accent-soft), transparent 55%),
    var(--bg);
}
.gate-shell {
  width: min(980px, 100%); display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 56px; align-items: center;
}
.brand-lg { font-size: 22px; gap: 10px; }
.brand-lg .logo { width: 40px; height: 40px; }
.gate-h1 { font-size: clamp(26px, 3.4vw, 36px); line-height: 1.15; letter-spacing: -.02em; margin: 26px 0 14px; font-weight: 700; }
.gate-lead { color: var(--muted); font-size: 16px; max-width: 46ch; }
.gate-feats { list-style: none; padding: 0; margin: 30px 0 0; display: grid; gap: 18px; }
.gate-feats li { display: flex; gap: 14px; align-items: flex-start; }
.gate-feats b { display: block; font-weight: 600; }
.gate-feats span { color: var(--muted); font-size: 13.5px; }
.feat-ico {
  flex: none; width: 38px; height: 38px; border-radius: 10px; background: var(--surface);
  border: 1px solid var(--border); display: grid; place-items: center; box-shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
.feat-ico svg { width: 22px; height: 22px; }
.fi-line { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.fi-fill { fill: var(--surface); }
.fi-soft { fill: var(--border); }
.fi-ink { fill: var(--text); }

.gate-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  padding: 36px 32px 28px; display: flex; flex-direction: column; align-items: stretch; text-align: center;
}
.gate-title { font-size: 22px; font-weight: 650; letter-spacing: -.01em; text-transform: none; color: var(--text); margin: 0 0 4px; display: block; }
.gate-sub { color: var(--muted); margin-bottom: 26px; }
.gate-msg { color: var(--muted); font-size: 14px; margin-bottom: 18px; min-height: 1.45em; }
.gate[data-state="error"] .gate-msg, .gate[data-state="setup"] .gate-msg {
  color: var(--danger); background: color-mix(in srgb, var(--danger) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); border-radius: 8px; padding: 10px 12px; text-align: left;
}
.gate[data-state="ready"] .gate-msg { display: none; }
.gate[data-state="info"] .gate-msg { color: var(--text); }
.gate-spin {
  width: 28px; height: 28px; margin: 0 auto 14px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .gate-spin { animation-duration: 3s; } }

/* Follows Microsoft's sign-in button guidance: plain background, four-square mark, Segoe UI. */
.ms-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 12px; width: 100%; height: 44px;
  font: 600 15px "Segoe UI", system-ui, sans-serif; color: #5e5e5e; background: #fff; border: 1px solid #8c8c8c;
  border-radius: 6px; cursor: pointer; transition: background .15s, box-shadow .15s;
}
.ms-btn:hover:not(:disabled) { background: #f6f6f6; box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }
.ms-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ms-btn:disabled { opacity: .6; cursor: progress; }
.ms-logo { width: 21px; height: 21px; flex: none; }
.gate-note {
  display: flex; gap: 8px; align-items: flex-start; text-align: left; margin-top: 24px; padding-top: 18px;
  border-top: 1px solid var(--border); color: var(--muted); font-size: 12.5px;
}
.gate-note svg { width: 16px; height: 16px; flex: none; margin-top: 1px; fill: none; stroke: var(--ok); stroke-width: 2; stroke-linecap: round; }

@media (prefers-color-scheme: dark) {
  .ms-btn { background: #2f2f2f; color: #fff; border-color: #2f2f2f; }
  .ms-btn:hover:not(:disabled) { background: #3a3a3a; }
}
@media (max-width: 820px) {
  .gate { place-items: start center; padding: 28px 16px; }
  .gate-shell { grid-template-columns: 1fr; gap: 28px; }
  .gate-h1 { margin-top: 18px; }
  .gate-feats { display: none; }   /* keeps the sign-in button on the first screen */
  .gate-lead { font-size: 15px; }
  .gate-card { padding: 28px 20px 22px; }
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  user-select: none;
}
.brand { font-weight: 650; font-size: 16px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { width: 26px; height: 26px; flex: none; display: block; }
.logo-page { fill: var(--accent); }
.logo-fold { fill: #fff; opacity: .5; }
.logo-line { fill: #fff; }
.logo-bar { fill: #0d1117; }
.pill {
  font-size: 12px;
  color: var(--ok);
  background: var(--ok-soft);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------- controls ---------- */
.btn {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, .input:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.danger-ghost { color: var(--danger); }
.btn.icon { padding: 6px 10px; min-width: 32px; font-size: 16px; line-height: 1; }
.btn.icon:has(svg.i) { padding: 6px 8px; display: inline-flex; align-items: center; justify-content: center; }
svg.i { width: 20px; height: 20px; display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg.i .i-hl { stroke: #e0a800; stroke-width: 3; }
svg.i .i-thin { stroke-width: 1.4; }
.btn.with-icon { display: inline-flex; align-items: center; gap: 6px; }
.btn.with-icon svg.i { width: 18px; height: 18px; }
#btnDelPage .i-res, #btnDelPage.restore .i-del { display: none; }
#btnDelPage.restore .i-res { display: block; }
#btnDelPage:hover:not(:disabled) .i-del { color: var(--danger); }
label.btn.toggle { cursor: pointer; position: relative; }   /* keeps its hidden checkbox inside the button */
label.btn.toggle:has(input:checked) { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
label.btn.toggle:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.btn.big { padding: 10px 22px; font-size: 15px; }
.input {
  font: inherit;
  width: 100%;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
}
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text); cursor: pointer; user-select: none; }
.check input { accent-color: var(--accent); margin: 0; }
.field { display: block; color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.field .input { margin-top: 4px; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; }
#modeHint { margin: -2px 0 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- layout ---------- */
.layout { flex: 1; display: grid; grid-template-columns: 230px minmax(0, 1fr) auto; min-height: 0; }
.side { background: var(--surface); padding: 14px; overflow: auto; min-height: 0; }
.files { border-right: 1px solid var(--border); }
.panel { border-left: 1px solid var(--border); width: 300px; display: flex; flex-direction: column; gap: 18px; }
/* Sections keep their full height. Only the Changes list gives up space (down to a minimum, then it
   scrolls inside itself); when even that isn't enough, as at high browser zoom, the whole panel scrolls. */
.panel section { display: flex; flex-direction: column; flex-shrink: 0; }
.panel section.grow { flex: 1 1 0; min-height: 160px; }

.file-list, .red-list { list-style: none; margin: 0; padding: 0; }
.file-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 4px;
}
.file-list li:hover { background: var(--surface-2); }
.file-list li.active { background: var(--accent-soft); border-color: var(--accent); }
.file-meta { flex: 1; min-width: 0; }

/* ---------- page thumbnails ---------- */
.thumbs-section { margin-top: 20px; }
.thumb-actions { display: flex; gap: 6px; margin-bottom: 6px; }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.thumbs { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 10px; }
.thumb { position: relative; cursor: pointer; padding: 4px; border-radius: 6px; border: 2px solid transparent; user-select: none; }
.thumb:hover { background: var(--surface-2); }
.thumb.current { border-color: var(--accent); }
.thumb-img { display: block; width: 100%; background: #fff; box-shadow: 0 0 0 1px var(--border); border-radius: 2px; overflow: hidden; }
.thumb-img canvas { display: block; width: 100%; height: 100%; }
.thumb.picked .thumb-img { box-shadow: 0 0 0 2px var(--accent); }
.thumb-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 5px; font-size: 12px; color: var(--muted); }
.thumb-foot input { margin: 0; accent-color: var(--accent); cursor: pointer; }
.thumb.removed .thumb-img { opacity: .3; }
.thumb.removed .thumb-num::after { content: " · deleted"; }
.thumb.dragging { opacity: .4; }
.thumbs.reordering, .thumbs.reordering .thumb { cursor: grabbing; }
.thumb-img { touch-action: pan-y; -webkit-user-drag: none; }
.thumb.drop-before::before, .thumb.drop-after::after {
  content: ""; position: absolute; top: -4px; bottom: -4px; width: 3px; border-radius: 2px; background: var(--accent);
}
.thumb.drop-before::before { left: -7px; }
.thumb.drop-after::after { right: -7px; }
.file-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-sub { font-size: 12px; color: var(--muted); }
.notext { color: #b54708; font-weight: 600; }
@media (prefers-color-scheme: dark) { .notext { color: #fdb022; } }
.x {
  border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1;
  padding: 2px 6px; border-radius: 4px;
}
.x:hover { color: var(--danger); background: var(--surface-2); }
.count {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 0 7px; font-size: 11px; letter-spacing: 0;
}

/* ---------- viewer ---------- */
.viewer { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px;
  padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
  user-select: none;
}
.group { display: flex; align-items: center; gap: 6px; }
/* Every control in the toolbar is the same height, so text buttons, icon buttons and the page box line up. */
#toolbar .btn {
  height: 34px; padding-top: 0; padding-bottom: 0; line-height: 1;
  font-size: 13.5px; font-weight: 500; letter-spacing: -0.006em;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
#toolbar .btn.icon { width: 34px; min-width: 34px; padding: 0; }
#toolbar .btn.primary { font-weight: 600; }
#toolbar .pagebox input { height: 34px; padding-top: 0; padding-bottom: 0; }
/* Plain number box: no up/down arrows (Firefox draws them by default, Chrome and Edge on hover). */
.pagebox input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
.pagebox input[type="number"]::-webkit-inner-spin-button,
.pagebox input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; appearance: none; margin: 0; }
.seg { gap: 0; }
.seg-btn { border-radius: 0; }
.seg-btn + .seg-btn { margin-left: -1px; }
.seg-btn:first-child { border-radius: 6px 0 0 6px; }
.seg-btn:last-child { border-radius: 0 6px 6px 0; }
.seg-btn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; position: relative; z-index: 1; }

.fmtbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px;
  padding: 6px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); user-select: none;
}
.fmt-field { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.fmt-field .input { width: auto; padding: 4px 6px; font-size: 13px; }
.sw { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); cursor: pointer; padding: 0; }
.sw.active { box-shadow: 0 0 0 2px var(--accent); }
.sw:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pagebox { color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.pagebox input {
  width: 52px; font: inherit; text-align: center; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 5px 4px;
}
.zoom-label { min-width: 44px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }

.stage { flex: 1; overflow: auto; scrollbar-gutter: stable; background: var(--stage); padding: 24px; position: relative; }
.pages { width: max-content; min-width: 100%; }
.page {
  position: relative; margin: 0 auto 16px; background: #fff; box-shadow: var(--shadow);
  --scale-factor: 1;
}
.page:last-child { margin-bottom: 0; }
.canvas-holder canvas { display: block; width: 100%; height: 100%; }
.canvas-holder { position: absolute; inset: 0; }

/* pdf.js text layer (invisible, selectable) */
.textLayer {
  position: absolute; inset: 0; overflow: hidden; line-height: 1; z-index: 2;
  text-align: initial; text-size-adjust: none; -webkit-text-size-adjust: none; forced-color-adjust: none;
  transform-origin: 0 0;
}
.textLayer span, .textLayer br { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%; }
.textLayer span.markedContent { top: 0; height: 0; }
.textLayer .bgtext { user-select: none; -webkit-user-select: none; pointer-events: none; }
.textLayer ::selection { background: rgba(31, 79, 216, .35); color: transparent; }

.sel-prev { position: absolute; inset: 0; z-index: 3; pointer-events: none; }

/* fillable form fields: above the page text, below redaction marks */
.formLayer { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.formLayer .field {
  position: absolute; margin: 0; pointer-events: auto; box-sizing: border-box; border: 1px solid transparent;
  border-radius: 2px; background: rgba(31, 79, 216, .10); color: #111; padding: 0 2px;
  font-family: Helvetica, Arial, sans-serif; line-height: 1.15;
}
.formLayer textarea.field { resize: none; padding: 1px 2px; overflow: auto; }
.formLayer input.field.comb {
  background: linear-gradient(rgba(31, 79, 216, .10), rgba(31, 79, 216, .10)) no-repeat 0 0;
  border-color: transparent; overflow: hidden;
}
.formLayer input.field.comb:focus { background: linear-gradient(rgba(255, 255, 255, .96), rgba(255, 255, 255, .96)) no-repeat 0 0; outline-offset: -1px; }
.formLayer .field:hover:not(:disabled) { border-color: rgba(31, 79, 216, .55); }
.formLayer .field:focus { outline: 2px solid #1f4fd8; outline-offset: 0; background: rgba(255, 255, 255, .96); }
.formLayer .field:disabled { background: transparent; cursor: default; }
.formLayer input.field-checkbox, .formLayer input.field-radio { padding: 0; accent-color: #1f4fd8; cursor: pointer; }
.formLayer select.field { padding: 0 1px; }
.pages.tool-box .formLayer .field, .pages.tool-addtext .formLayer .field, .pages.tool-ink .formLayer .field { pointer-events: none; }
.selbox { position: absolute; background: rgba(31, 79, 216, .35); }
/* Actions for text picked with the Select tool */
.pick-bar {
  position: absolute; z-index: 8; display: flex; gap: 2px; padding: 3px; pointer-events: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
  transform: translateY(calc(-100% - 6px)); white-space: nowrap;
}
.pick-bar.below { transform: translateY(6px); }
.pick-bar button {
  font: 500 13px "Inter", system-ui, sans-serif; color: var(--text); background: none; border: 0; border-radius: 5px;
  padding: 5px 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.pick-bar button:hover { background: var(--surface-2); }
.pick-bar button svg.i { width: 16px; height: 16px; }
.pick-bar .sw-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.pick-bar [data-act="redact"] { color: var(--danger); }
.pages.tool-select .textLayer span { cursor: text; }
.marks { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.mark {
  position: absolute; background: var(--mark); outline: 1.5px solid var(--mark-border);
  border-radius: 1px; pointer-events: auto; cursor: pointer;
}
.mark.hot { background: rgba(214, 40, 40, .55); }
.hit { position: absolute; background: var(--hit); outline: 1px solid #b58900; pointer-events: none; }
.pages.preview .mark { background: #000; outline-color: #000; }
.pages.preview .mark.hot { outline: 2px solid var(--mark-border); outline-offset: 1px; }

.draw-layer { position: absolute; inset: 0; z-index: 4; display: none; cursor: crosshair; touch-action: none; }
.pages.tool-box .draw-layer, .pages.tool-addtext .draw-layer, .pages.tool-ink .draw-layer { display: block; }
.pages.tool-addtext .draw-layer { cursor: text; }
.pages.tool-box .mark { pointer-events: none; }
.ink-live { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* highlights sit in their own layer so they can darken the page beneath instead of covering it */
.hls { position: absolute; inset: 0; z-index: 3; pointer-events: none; mix-blend-mode: multiply; }
.hl { position: absolute; pointer-events: auto; cursor: pointer; }
.pages.tool-box .hl { pointer-events: none; }

/* things added on top of the page: typed text, drawings, images */
.annots { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
.annot { position: absolute; pointer-events: auto; cursor: move; user-select: none; -webkit-user-select: none; touch-action: none; }
.annot:hover, .annot.sel { outline: 1.5px dashed #1f4fd8; outline-offset: 2px; }
.pages.tool-ink .annot { pointer-events: none; }
.a-text { white-space: pre; line-height: 1.25; font-family: Arial, Helvetica, sans-serif; min-width: 4px; }
.a-text.editing {
  cursor: text; user-select: text; -webkit-user-select: text; outline: 1.5px solid #1f4fd8;
  background: rgba(255, 255, 255, .85); min-width: 40px; min-height: 1.25em;
}
.a-img img { width: 100%; height: 100%; display: block; pointer-events: none; }
.a-ink svg { width: 100%; height: 100%; display: block; overflow: visible; }
.a-ink path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.annot .del {
  position: absolute; top: -12px; right: -12px; width: 20px; height: 20px; border-radius: 50%; border: 0;
  background: #c81e1e; color: #fff; font: 700 13px/20px system-ui, sans-serif; padding: 0; cursor: pointer; text-align: center;
}
.annot .rz {
  position: absolute; right: -7px; bottom: -7px; width: 12px; height: 12px; background: #fff;
  border: 2px solid #1f4fd8; border-radius: 2px; cursor: nwse-resize;
}

.gone {
  display: none; position: absolute; inset: 0; z-index: 7; background: rgba(243, 244, 246, .9); color: #171a1f;
  place-items: center; text-align: center; padding: 16px;
}
.page.removed .gone { display: grid; }
.gone p { margin-bottom: 10px; font-weight: 600; }
.gone .btn { background: #fff; color: #171a1f; border-color: #d8dce2; }
.rubber { position: absolute; z-index: 6; pointer-events: none; background: var(--mark); outline: 1.5px dashed var(--mark-border); }

/* ---------- empty state ---------- */
.empty { height: 100%; display: grid; place-items: center; }
.empty-card {
  max-width: 480px; text-align: center; padding: 40px 32px;
  border: 2px dashed var(--border); border-radius: 14px; background: var(--surface);
}
.empty-card h1 { font-size: 20px; margin: 14px 0 8px; }
.empty-card p { color: var(--muted); margin-bottom: 18px; }
.empty-card .fine { font-size: 12px; margin: 18px 0 0; }
.empty-icon {
  width: 56px; height: 70px; margin: 0 auto; border: 2px solid var(--muted); border-radius: 6px;
  background:
    linear-gradient(var(--text), var(--text)) 10px 16px / 34px 7px no-repeat,
    linear-gradient(var(--border), var(--border)) 10px 30px / 34px 4px no-repeat,
    linear-gradient(var(--text), var(--text)) 10px 41px / 20px 7px no-repeat,
    linear-gradient(var(--border), var(--border)) 10px 55px / 30px 4px no-repeat;
}

/* ---------- panel bits ---------- */
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  font: inherit; font-size: 12px; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.result { font-size: 13px; color: var(--muted); min-height: 20px; margin-bottom: 8px; }
.result.err { color: var(--danger); }
.red-list { overflow: auto; flex: 1; margin: 0 -6px; }
.red-list li {
  display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.red-list li:hover { background: var(--surface-2); }
.red-list .pg { color: var(--muted); font-size: 12px; min-width: 34px; font-variant-numeric: tabular-nums; }
.red-list .tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; white-space: nowrap; }
.red-list .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- overlays ---------- */
.drop-overlay {
  position: fixed; inset: 0; background: rgba(31, 79, 216, .18); z-index: 50; display: grid; place-items: center;
  pointer-events: none;
}
.drop-overlay div {
  background: var(--surface); padding: 18px 28px; border-radius: 12px; font-size: 18px; font-weight: 600;
  border: 2px dashed var(--accent); box-shadow: var(--shadow);
}
.busy { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 60; display: grid; place-items: center; }
.busy-card { background: var(--surface); padding: 22px 26px; border-radius: 12px; width: min(380px, 90vw); box-shadow: var(--shadow); }
.busy-title { font-weight: 600; margin-bottom: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.busy-sub { color: var(--muted); font-size: 12px; margin-top: 8px; min-height: 18px; }
.bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.offer {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 65;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 10px 12px 10px 16px; max-width: min(720px, 94vw); font-size: 13.5px;
}
.offer .btn { padding: 6px 12px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 70;
  background: #171a1f; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow);
  max-width: min(560px, 92vw); font-size: 13px;
}

/* ---------- narrow screens ---------- */
/* ---------- touch screens ---------- */
/* Buttons react straight away to a tap instead of waiting to see if it is a double-tap zoom. */
button, .btn, .chip, .thumb, label.check { touch-action: manipulation; }
@media (pointer: coarse) {
  /* Bigger targets on tablets in the full layout. */
  #toolbar .btn { height: 40px; }
  #toolbar .btn.icon { width: 40px; min-width: 40px; }
  #toolbar .pagebox input { height: 40px; }
  /* With Redact text or Highlight, a finger drag on the words selects them; drags elsewhere on the
     page still scroll. The phone's own text-selection menu is kept out of the way. */
  .pages.tool-text .textLayer, .pages.tool-hl .textLayer { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  .pages.tool-text .textLayer span, .pages.tool-hl .textLayer span { touch-action: none; }
}

/* Only used by the compact layout below. */
.sheet-head, .sheet-actions, .mobile-nav, .sheet-backdrop { display: none; }

/* ---------- compact layout: phones, and tablets held upright ---------- */
@media (max-width: 1000px) {
  body { height: 100vh; height: 100dvh; overflow: hidden; }
  .topbar { padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .pill, #btnDownloadAll, #btnClearAll { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); }

  /* The document fills the screen; the tools sit along the bottom, within reach of a thumb. */
  .viewer > .stage { order: 1; }
  .viewer > .fmtbar { order: 2; border-top: 1px solid var(--border); border-bottom: 0; flex-wrap: nowrap; overflow-x: auto; }
  .viewer > .toolbar { order: 3; border-top: 1px solid var(--border); border-bottom: 0; }
  .stage { padding: 10px 8px; }
  .toolbar {
    flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain; gap: 10px; padding: 8px 10px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar .spacer { display: none; }
  .toolbar .group { flex: none; }
  #toolbar .btn { height: 44px; font-size: 14px; }
  #toolbar .btn.icon { width: 44px; min-width: 44px; }
  #toolbar .btn.icon svg.i { width: 22px; height: 22px; }
  #toolbar .pagebox input { height: 44px; width: 48px; }
  #toolbar #btnDownload { display: none; }  /* it lives in the bottom bar */

  /* Bottom bar */
  .mobile-nav {
    display: flex; flex: none; background: var(--surface); border-top: 1px solid var(--border);
    padding: 4px 6px; padding-bottom: max(4px, env(safe-area-inset-bottom));
  }
  body:not(.has-file) .mobile-nav { display: none; }
  .mobile-nav button {
    flex: 1; min-width: 0; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font: 500 11.5px "Inter", system-ui, sans-serif; color: var(--muted); background: none; border: 0; border-radius: 10px; cursor: pointer;
  }
  .mobile-nav button svg.i { width: 22px; height: 22px; }
  .mobile-nav button.active { color: var(--accent); }
  .mobile-nav .nav-primary { color: var(--accent); font-weight: 650; }
  .nav-count { font-weight: 600; font-size: 10.5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 5px; margin-left: 2px; }

  /* The two side panels become sheets that slide up from the bottom. */
  .side.files, .panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 46; width: auto; max-height: 82vh; max-height: 82dvh;
    border: 0; border-top: 1px solid var(--border); border-radius: 16px 16px 0 0; box-shadow: 0 -10px 40px rgba(0, 0, 0, .28);
    padding: 0 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain;
    transform: translateY(110%); visibility: hidden; transition: transform .24s ease, visibility 0s linear .24s;
  }
  body.sheet-files .side.files, body.sheet-panel .panel { transform: none; visibility: visible; transition: transform .24s ease; }
  .panel section.grow { flex: none; min-height: 0; }
  .red-list { max-height: none; overflow: visible; }
  .sheet-head {
    display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 2;
    background: var(--surface); margin: 0 -16px 12px; padding: 14px 16px 10px; border-bottom: 1px solid var(--border);
    font-weight: 650; font-size: 15px;
  }
  .sheet-close { font: 400 26px/1 system-ui, sans-serif; width: 40px; height: 40px; border: 0; background: var(--surface-2); color: var(--text); border-radius: 50%; cursor: pointer; }
  .sheet-actions { display: flex; gap: 8px; margin-bottom: 16px; }
  .sheet-actions .btn { flex: 1; height: 44px; }
  .sheet-backdrop { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(0, 0, 0, .35); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.sheet-files .sheet-backdrop, body.sheet-panel .sheet-backdrop { opacity: 1; pointer-events: auto; }
  .thumbs { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .thumb-foot input { width: 22px; height: 22px; }
  .file-list li { padding: 10px 8px; }
  .file-list .x { font-size: 20px; padding: 6px 10px; }
  .red-list li { padding: 9px 6px; }
  .red-list .x { font-size: 20px; padding: 4px 10px; }

  /* Safari zooms the whole page into any text box under 16px; this keeps it from doing that. */
  .input, .pagebox input, select { font-size: 16px; }

  /* Messages sit above the bottom bars. */
  .toast, .offer { bottom: calc(130px + env(safe-area-inset-bottom)); }
  .offer { width: calc(100vw - 24px); }
  .empty { padding: 16px; }
}
