/* PDF App — plain CSS for Safari 16.0+ (no nesting, no :has, no container queries) */
:root {
  --bg: #eef0f3; --panel: #ffffff; --ink: #1d2330; --muted: #5f6878; --line: #d6dae1;
  --accent: #2456d6; --accent-ink: #ffffff; --page-shadow: 0 1px 4px rgba(0,0,0,.18);
  --hit: rgba(255, 196, 0, .45); --hit-current: rgba(255, 120, 0, .6);
  --bar-h: 52px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1b1e24; --panel: #262a32; --ink: #e8ebf0; --muted: #a2aab8; --line: #3a404b;
    --accent: #6f95ff; --accent-ink: #0d1220; --page-shadow: 0 1px 6px rgba(0,0,0,.6); }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex; flex-direction: column; overflow: hidden; }
[hidden] { display: none !important; }

.bar { display: flex; align-items: center; gap: 6px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top));
  min-height: var(--bar-h); background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.subbar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.grow { flex: 1 1 auto; }
.sep { width: 1px; height: 24px; background: var(--line); margin: 0 2px; }
.info { color: var(--muted); font-size: 13px; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn, .icon { -webkit-appearance: none; appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 7px 12px; font: inherit; font-size: 14px; cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; min-height: 36px; user-select: none; -webkit-user-select: none; }
.icon { width: 36px; padding: 0; font-size: 18px; }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:disabled, .icon:disabled { opacity: .45; cursor: default; }
.icon[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
input[type="search"], input[type="text"], input[type="password"], textarea { font: inherit; font-size: 16px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
#searchInput { flex: 1 1 200px; max-width: 420px; }

#main { flex: 1 1 auto; display: flex; min-height: 0; position: relative; }
#thumbs { width: 150px; flex: 0 0 150px; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 10px; }
.thumb { display: block; width: 100%; margin: 0 0 12px; border: 2px solid transparent; border-radius: 4px; background: none; padding: 0; cursor: pointer; color: var(--muted); font-size: 12px; }
.thumb canvas { display: block; width: 100%; background: #fff; box-shadow: var(--page-shadow); }
.thumb.current { border-color: var(--accent); }
#viewer { flex: 1 1 auto; overflow: auto; -webkit-overflow-scrolling: touch; outline: none; position: relative; }
#pages { padding: 16px 0 40px; }
.page { position: relative; margin: 0 auto 16px; background: #fff; box-shadow: var(--page-shadow); }
.page canvas { display: block; width: 100%; height: 100%; }
.pageNum { position: absolute; right: 6px; bottom: -14px; font-size: 11px; color: var(--muted); }

.empty { max-width: 520px; margin: 10vh auto 0; padding: 0 16px; text-align: center; }
.empty h1 { font-size: 28px; margin: 0 0 8px; }
.emptyActions { display: flex; gap: 10px; justify-content: center; margin: 18px 0; flex-wrap: wrap; }

.modal { position: fixed; inset: 0; background: rgba(10, 14, 22, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.card { background: var(--panel); color: var(--ink); border-radius: 12px; padding: 18px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto;
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.card h2 { margin: 0; font-size: 19px; }
.card textarea { width: 100%; resize: vertical; }
.row { display: flex; gap: 8px; justify-content: flex-end; }
.tabs { display: flex; gap: 6px; }
.tab { border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#imageList { margin: 0; padding-left: 18px; color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 9px 14px; border-radius: 8px; font-size: 14px; z-index: 60; max-width: calc(100vw - 32px); text-align: center; }

/* pdf.js text layer (flattened from pdf_viewer.css; nesting is Safari 16.5+) */
.textLayer { position: absolute; text-align: initial; inset: 0; overflow: hidden; opacity: 1; line-height: 1; letter-spacing: normal; word-spacing: normal;
  -webkit-text-size-adjust: none; text-size-adjust: none; forced-color-adjust: none; transform-origin: 0 0; z-index: 0;
  --min-font-size: 1; --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size)); --min-font-size-inv: calc(1 / var(--min-font-size)); }
.textLayer span, .textLayer br { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%; -webkit-user-select: text; user-select: text; }
.textLayer > :not(.markedContent), .textLayer .markedContent span:not(.markedContent) { z-index: 1; --font-height: 0;
  font-size: calc(var(--text-scale-factor) * var(--font-height)); --scale-x: 1; --rotate: 0deg;
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv)); }
.textLayer .markedContent { display: contents; }
.textLayer ::selection { background: rgba(0, 0, 255, .25); color: transparent; }
.textLayer br::selection { background: transparent; }
.textLayer .endOfContent { display: block; position: absolute; inset: 100% 0 0; z-index: 0; cursor: default; -webkit-user-select: none; user-select: none; }
.textLayer.selecting .endOfContent { top: 0; }
.textLayer span.hit { background: var(--hit); border-radius: 2px; }
.textLayer span.hit.current { background: var(--hit-current); }

#printArea { display: none; }
@media print {
  @page { margin: 0; }
  body { display: block; overflow: visible; background: #fff; height: auto; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; }
  #printArea img { display: block; width: 100vw; height: 100vh; object-fit: contain; page-break-after: always; break-after: page; page-break-inside: avoid; }
  #printArea img:last-child { page-break-after: auto; break-after: auto; }
}

@media (max-width: 640px) {
  .bar { gap: 4px; padding-left: 8px; padding-right: 8px; }
  .btn { padding: 6px 9px; font-size: 13px; }
  .sep { display: none; }
  #pageInfo { order: 10; }
  #thumbs { position: absolute; z-index: 20; top: 0; bottom: 0; left: 0; box-shadow: 4px 0 16px rgba(0,0,0,.2); }
  #pages { padding-top: 10px; }
}
.page { --total-scale-factor: 1; --scale-round-x: 1px; --scale-round-y: 1px; }
.textLayer[data-main-rotation="90"] { transform: rotate(90deg) translateY(-100%); }
.textLayer[data-main-rotation="180"] { transform: rotate(180deg) translate(-100%, -100%); }
.textLayer[data-main-rotation="270"] { transform: rotate(270deg) translateX(-100%); }
/* bars never shrink: on a phone the toolbar wraps to 2 rows and both must stay visible (found in the phone looking pass) */
.bar, .subbar { flex-shrink: 0; }

/* ---------- Stage 2: tools ---------- */
.toolsBar { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.toolsBar::-webkit-scrollbar { display: none; }
.tool { flex: 0 0 auto; border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; min-height: 32px; }
.tool.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#toolHint { padding-left: 4px; }
.toolOverlay { position: absolute; inset: 0; z-index: 5; display: none; }
body[data-tool="highlight"] .toolOverlay, body[data-tool="draw"] .toolOverlay, body[data-tool="box"] .toolOverlay, body[data-tool="place"] .toolOverlay { display: block; touch-action: none; cursor: crosshair; }
body[data-tool="note"] .toolOverlay, body[data-tool="textbox"] .toolOverlay, body[data-tool="edit"] .toolOverlay, body[data-tool="addtext"] .toolOverlay { display: block; touch-action: manipulation; cursor: text; }
body[data-tool="note"] .toolOverlay { cursor: copy; }
.dragRect { position: absolute; pointer-events: none; }
.dragRect.highlight { background: rgba(255, 210, 0, .35); }
.dragRect.box { border: 2px solid #d61f1f; }
.inkPreview { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.inkPreview polyline { fill: none; stroke: #d61f1f; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.placeBox { position: absolute; border: 1.5px dashed var(--accent); background: rgba(36, 86, 214, .06); touch-action: none; cursor: move; }
.placeBox img { width: 100%; height: 100%; display: block; pointer-events: none; }
.placeBox .resize { position: absolute; right: -9px; bottom: -9px; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; cursor: nwse-resize; }
.formLayer { position: absolute; inset: 0; z-index: 6; }
.formField { position: absolute; box-sizing: border-box; margin: 0; padding: 1px 3px; border: 1.5px solid var(--accent); background: #eef3ff; color: #111; border-radius: 2px; font-family: Helvetica, Arial, sans-serif; }
.formField.checkbox, .formField.radio { padding: 0; accent-color: var(--accent); }
.actionBar { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 40; display: flex; align-items: center; gap: 8px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: calc(100vw - 24px); flex-wrap: wrap; justify-content: center; }
.actionBar #actionMsg { font-size: 13px; color: var(--muted); }
#signPad { width: 100%; height: auto; aspect-ratio: 600 / 220; background: #fff; border: 1px solid var(--line); border-radius: 8px; touch-action: none; cursor: crosshair; }
.row.left { justify-content: flex-start; flex-wrap: wrap; }
#promptExtra:empty { display: none; }
#promptExtra select { font: inherit; font-size: 15px; margin-left: 4px; }
/* the toast moves above the action bar while that bar is open (found in the looking pass: it covered the Save/Place buttons) */
body.actionOpen #toast { bottom: auto; top: calc(max(8px, env(safe-area-inset-top)) + 112px); } /* at the top while the action bar is open: on a phone that bar wraps to 2 rows */

/* ---------- review fixes 2026-11-04 (user test + 3 reviewers) ---------- */
.pageBtn { background: none; border: 0; padding: 4px 6px; border-radius: 6px; cursor: pointer; font: inherit; font-size: 13px; color: var(--muted); text-decoration: underline dotted; }
.hintbar { padding: 4px 12px 6px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); flex-shrink: 0; }
/* a fade at the right edge says the tool row scrolls sideways */
.toolsBar { -webkit-mask-image: linear-gradient(to right, #000 85%, transparent); mask-image: linear-gradient(to right, #000 85%, transparent); padding-right: 40px; }
/* page number inside the page (it used to sit under the page and read like the next page's number) */
.pageNum { bottom: 4px; right: 6px; background: rgba(255,255,255,.85); padding: 0 5px; border-radius: 4px; z-index: 4; }
/* form fields: finger-sized targets and 16px text (iOS zooms the page on inputs below 16px) */
.formField.text, textarea.formField { min-height: 28px; font-size: 16px !important; }
.formField.checkbox, .formField.radio { min-width: 28px; min-height: 28px; transform-origin: top left; }
.formNote { position: absolute; font-size: 11px; color: var(--muted); background: var(--panel); padding: 1px 4px; border-radius: 3px; }

/* polish P1: per-word search marks inside the text layer */
.textLayer mark.hit { background: var(--hit); color: transparent; padding: 0; margin: 0; border-radius: 2px; }
.textLayer mark.hit.current { background: var(--hit-current); }
