/* OBSCURA OS: PDF.
 *
 * One column: the site bar, the app header and the tool row from
 * app-chrome.css, then three panes (pages, the document, the form and
 * details) and a status line. The document pane is the only thing that
 * scrolls, so the header and the tools stay put, as they do in Docs.
 */

.pdf-shell {
  display: flex; flex-direction: column;
  height: calc(100vh - var(--pdf-top, 56px));
  height: calc(100dvh - var(--pdf-top, 56px));
  min-height: 520px;
  background: var(--paper);
  color: var(--ink);
}
.pdf-name { cursor: default; }
/* The privacy badge sits above the status line rather than on it. */
:root { --pp-bottom: 44px; }

/* The find box lives in the tool row. */
.pdf-find { display: inline-flex; align-items: center; gap: 6px; flex: none; margin: 0 6px; color: var(--ink-soft); font-size: 12px; }
.pdf-find svg { width: 14px; height: 14px; flex: none; }
.pdf-find input {
  width: 150px; min-height: 32px; padding: 4px 8px; border: 1px solid var(--rule); border-radius: 6px;
  background: var(--paper); color: var(--ink); font: inherit; font-size: 13px;
}
.pdf-find input:focus { outline: none; border-color: var(--accent); }
@media (pointer: coarse) { .pdf-find input { min-height: 44px; } }

/* ---------------------------------------------------------- tool options */
.pdf-opts {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 18px;
  padding: 6px 14px; background: var(--paper-inset); border-bottom: 1px solid var(--rule);
  font-size: 12.5px; color: var(--ink-soft); flex-shrink: 0;
}
.pdf-opt { display: inline-flex; align-items: center; gap: 8px; }
.pdf-opt[hidden] { display: none; }
.pdf-opt-label { font-weight: 600; color: var(--ink); }
.pdf-opt input[type="range"] { width: 110px; }
.pdf-hint { color: var(--ink-soft); }
.pdf-swatches { display: inline-flex; gap: 6px; }
.pdf-swatch {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--paper-raised);
  background: var(--sw); cursor: pointer; padding: 0; box-shadow: 0 0 0 1px var(--rule);
}
.pdf-swatch.on { box-shadow: 0 0 0 2px var(--accent-strong); }
.pdf-link { border: 0; background: none; padding: 0; color: var(--accent-strong); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; font: inherit; }

/* ------------------------------------------------------------- the panes */
.pdf-app {
  flex: 1 1 auto; min-height: 0;
  display: grid; grid-template-columns: 168px minmax(0, 1fr) 300px;
}
.pdf-app.no-side { grid-template-columns: 168px minmax(0, 1fr); }
.pdf-app.no-side .pdf-side { display: none; }

.pdf-thumbs {
  border-right: 1px solid var(--rule); background: var(--paper-inset);
  overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 10px;
}
.pdf-thumb {
  position: relative; border: 2px solid transparent; border-radius: 8px; padding: 6px 6px 22px;
  background: var(--paper-raised); box-shadow: 0 1px 2px rgba(0,0,0,0.08); cursor: pointer;
  user-select: none; -webkit-user-select: none; outline: none;
}
.pdf-thumb:focus-visible { border-color: var(--accent); }
.pdf-thumb.on { border-color: var(--accent-strong); }
.pdf-thumb.drop-before { box-shadow: 0 -3px 0 0 var(--accent-strong); }
.pdf-thumb.drop-after { box-shadow: 0 3px 0 0 var(--accent-strong); }
.pdf-thumb.dragging { opacity: 0.4; }
.pdf-thumb canvas { display: block; width: 100%; height: auto; background: #fff; border: 1px solid var(--rule); }
.pdf-thumb-num {
  position: absolute; left: 8px; bottom: 3px; font-size: 11.5px; color: var(--ink-soft); font-weight: 600;
}
.pdf-thumb-tools { position: absolute; right: 4px; bottom: 1px; display: none; gap: 2px; }
.pdf-thumb:hover .pdf-thumb-tools, .pdf-thumb.on .pdf-thumb-tools, .pdf-thumb:focus-within .pdf-thumb-tools { display: flex; }
.pdf-thumb-tools button {
  min-width: 22px; min-height: 22px; border: 0; border-radius: 4px; background: transparent;
  color: var(--ink-soft); font-size: 12px; cursor: pointer; padding: 0 4px;
}
.pdf-thumb-tools button:hover { background: var(--paper-inset); color: var(--ink); }
.pdf-thumb-tools svg { width: 13px; height: 13px; display: block; }

.pdf-stage {
  position: relative; overflow: auto; background: var(--paper);
  outline: none; -webkit-overflow-scrolling: touch;
}
.pdf-stage:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.pdf-stage.drop { box-shadow: inset 0 0 0 3px var(--accent); }
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 22px 18px 60px; }
.pdf-pages:empty { display: none; }

.pdf-page {
  position: relative; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.18), 0 6px 20px rgba(0,0,0,0.08);
  flex: none; touch-action: none;
}
.pdf-page.on { outline: 2px solid var(--accent-soft); outline-offset: 2px; }
.pdf-page canvas.pdf-canvas { display: block; width: 100%; height: 100%; }
.pdf-page.pending canvas.pdf-canvas { background: repeating-linear-gradient(45deg, #f2f2f2 0 10px, #fafafa 10px 20px); }
.pdf-num {
  position: absolute; top: -18px; left: 0; font-size: 11px; color: var(--ink-faint); font-weight: 600; letter-spacing: .04em;
}
/* pdf.js text, invisible and selectable, so words can be copied and found. */
.pdf-textlayer {
  position: absolute; inset: 0; overflow: hidden; line-height: 1; opacity: 0.25;
  pointer-events: none;
}
.pdf-stage[data-tool="select"] .pdf-textlayer { pointer-events: auto; }
.pdf-textlayer span { position: absolute; color: transparent; white-space: pre; transform-origin: 0 0; }
.pdf-textlayer ::selection { background: rgba(31, 79, 216, 0.35); }
.pdf-textlayer span.hit { background: rgba(255, 200, 0, 0.55); }
.pdf-textlayer span.hit.now { background: rgba(255, 120, 0, 0.7); }

/* The marks a person makes, drawn as SVG over the page. */
.pdf-marks { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.pdf-stage[data-tool="select"] .pdf-marks { pointer-events: none; }
/* "all", so a box with no fill can be picked up by its inside, not only its edge. */
.pdf-stage[data-tool="select"] .pdf-marks .mk { pointer-events: all; cursor: move; }
.pdf-stage:not([data-tool="select"]) .pdf-marks { cursor: crosshair; }
.pdf-marks .mk.sel { outline: none; }
.pdf-marks .mk-sel { fill: none; stroke: var(--accent-strong); stroke-width: 1.5; stroke-dasharray: 5 4; pointer-events: none; vector-effect: non-scaling-stroke; }
.pdf-marks .mk-highlight { mix-blend-mode: multiply; }
.pdf-marks .mk-text { font-family: Helvetica, Arial, sans-serif; white-space: pre; }
.pdf-marks .rubber { fill: rgba(31, 79, 216, 0.12); stroke: var(--accent-strong); stroke-width: 1; stroke-dasharray: 4 3; pointer-events: none; }

/* The floating box where a text mark is typed. */
.pdf-textbox {
  position: absolute; z-index: 3; min-width: 120px; min-height: 1.4em; padding: 2px 4px; margin: 0;
  border: 1px dashed var(--accent-strong); background: rgba(255,255,255,0.92); color: #111;
  font-family: Helvetica, Arial, sans-serif; line-height: 1.2; resize: none; overflow: hidden; outline: none; white-space: pre-wrap;
}

/* ------------------------------------------------------------ empty state */
.pdf-empty { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 30px 16px; }
.pdf-empty[hidden] { display: none; }
.pdf-empty-card {
  max-width: 460px; text-align: center; padding: 34px 30px; border: 1px dashed var(--rule-strong, var(--rule));
  border-radius: 14px; background: var(--paper-raised);
}
.pdf-empty-card h2 { font-size: 22px; margin: 0 0 8px; }
.pdf-empty-card p { color: var(--ink-soft); font-size: 14px; line-height: 1.6; margin: 0 0 16px; }
.pdf-empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.pdf-empty-sub { margin: 14px 0 0 !important; font-size: 12.5px !important; }

/* ----------------------------------------------------------- side panel */
.pdf-side { border-left: 1px solid var(--rule); background: var(--paper-raised); display: flex; flex-direction: column; min-height: 0; }
.pdf-side-tabs { display: flex; border-bottom: 1px solid var(--rule); flex-shrink: 0; }
.pdf-side-tabs button {
  flex: 1 1 0; min-height: 40px; border: 0; border-bottom: 2px solid transparent; background: transparent;
  color: var(--ink-soft); font: 600 13px/1 inherit; font-family: inherit; cursor: pointer;
}
.pdf-side-tabs button.on { color: var(--accent-strong); border-bottom-color: var(--accent-strong); }
.pdf-side-body { overflow-y: auto; padding: 14px; font-size: 13.5px; }
.pdf-side-note { color: var(--ink-soft); font-size: 13px; line-height: 1.55; margin: 0 0 12px; }
.pdf-side-h { font-size: 12px; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-faint); margin: 18px 0 8px; }
.pdf-field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; }
.pdf-field > span { font-size: 12.5px; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.pdf-field .pdf-field-page { font-weight: 400; color: var(--ink-faint); margin-left: 6px; }
.pdf-field input[type="text"], .pdf-field textarea, .pdf-field select, .pdf-meta input {
  width: 100%; box-sizing: border-box; min-height: 34px; padding: 6px 8px; border: 1px solid var(--rule);
  border-radius: 6px; background: var(--paper); color: var(--ink); font: inherit; font-size: 13.5px;
}
.pdf-field textarea { min-height: 70px; resize: vertical; }
.pdf-field.ro input, .pdf-field.ro select { opacity: 0.6; }
.pdf-check { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; line-height: 1.45; color: var(--ink-soft); }
.pdf-check input { margin-top: 3px; }
.pdf-form-actions { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--rule); }
.pdf-dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 0; font-size: 13px; }
.pdf-dl dt { color: var(--ink-faint); }
.pdf-dl dd { margin: 0; overflow-wrap: anywhere; }
.pdf-meta { display: flex; flex-direction: column; gap: 10px; }
.pdf-meta label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; }
.pdf-meta-made { font-size: 12.5px; color: var(--ink-soft); line-height: 1.5; }

/* ------------------------------------------------------------- status */
.pdf-status {
  display: flex; align-items: center; gap: 16px; padding: 6px 14px; min-height: 30px;
  border-top: 1px solid var(--rule); background: var(--paper-raised);
  font: 12px var(--font-mono, monospace); color: var(--ink-soft); flex-shrink: 0;
}
.pdf-status span:last-child { margin-left: auto; }

/* ------------------------------------------------------------- menus */
.pdf-menu-wrap { position: relative; }
.pdf-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 240px;
  background: var(--paper-raised); border: 1px solid var(--rule); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18); padding: 6px; display: flex; flex-direction: column;
}
.pdf-menu[hidden] { display: none; }
.pdf-menu button {
  text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 6px;
  font: inherit; font-size: 13.5px; color: var(--ink); cursor: pointer; min-height: 36px;
}
.pdf-menu button:hover { background: var(--paper-inset); }

/* ------------------------------------------------------------- dialog */
.pdf-dialog { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.pdf-dialog[hidden] { display: none; }
.pdf-dialog-card { width: 100%; max-width: 580px; background: var(--paper-raised); border-radius: 14px; padding: 22px 24px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.pdf-dialog-card h2 { margin: 0 0 12px; font-size: 20px; }
.pdf-sig-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.pdf-sig-tabs button { border: 1px solid var(--rule); background: var(--paper); border-radius: 20px; padding: 6px 14px; font: 600 13px inherit; font-family: inherit; color: var(--ink-soft); cursor: pointer; min-height: 36px; }
.pdf-sig-tabs button.on { border-color: var(--accent); color: var(--accent-strong); background: var(--accent-soft); }
#pdfSigPad { display: block; width: 100%; height: 180px; background: #fff; border: 1px solid var(--rule); border-radius: 8px; touch-action: none; color: #14213d; }
#pdfSigName { width: 100%; box-sizing: border-box; min-height: 40px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px; font: inherit; background: var(--paper); color: var(--ink); }
.pdf-sig-preview { margin-top: 10px; min-height: 70px; display: flex; align-items: center; padding: 8px 14px; background: #fff; border: 1px solid var(--rule); border-radius: 8px; color: #14213d; font: italic 400 34px "Spectral", Georgia, serif; overflow: hidden; }
.pdf-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* ------------------------------------------------------------- print */
@media print { .os-topbar, .app-head, .app-menu, .pdf-opts, .pdf-thumbs, .pdf-side, .pdf-status, .os-rel { display: none !important; } }

/* ------------------------------------------------------------- phone */
@media (max-width: 900px) {
  .pdf-app, .pdf-app.no-side { grid-template-columns: minmax(0, 1fr); }
  .pdf-thumbs { display: none; }
  .pdf-side { display: none; }
  .pdf-app.show-side .pdf-side { display: flex; position: fixed; right: 0; top: 0; bottom: 0; width: min(92vw, 340px); z-index: 30; box-shadow: -8px 0 30px rgba(0,0,0,0.25); }
  .pdf-pages { padding: 14px 8px 40px; gap: 14px; }
  .pdf-status span:nth-child(2) { display: none; }
}
@media (pointer: coarse) {
  .pdf-swatch { width: 30px; height: 30px; }
  .pdf-side-tabs button, .pdf-menu button, .pdf-thumb-tools button, .pdf-link { min-height: 44px; }
  .pdf-thumb-tools button { min-width: 44px; }
  .pdf-thumb { padding-bottom: 46px; }
  .pdf-sig-tabs button { min-height: 44px; }
}
