/* ── PDFs ─────────────────────────────────────────────────────────────────────
   A PDF block is a CARD inside a note and the READER when it is the whole note.
   Both are always built; #document-container.pdf-only says which shows, so a note
   gaining or losing a neighbour never rebuilds the block. From the mock in
   docs/mocks/pdf-prototype.html. */

:root { --pdf-accent: #e06c75; }

.pdf-block { margin: 12px 0; }
.pdf-block .pdf-reader { display: none; }

/* ── the card ── */
.pdf-card {
  position: relative; display: flex; gap: 16px; padding: 12px; cursor: pointer;
  background: var(--bg-code); border: 1px solid var(--border-soft); border-radius: var(--radius);
  transition: border-color .15s;
}
.pdf-card:hover, .pdf-card:focus-visible { border-color: var(--accent-line); outline: none; }
.pdf-thumb {
  position: relative; flex: none; width: 112px; aspect-ratio: 0.77; border-radius: 3px; overflow: hidden;
  background: var(--bg-raised); border: 1px solid var(--border); display: grid; place-items: center;
}
.pdf-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #fff; }
.pdf-glyph { font-size: 11px; font-weight: 700; letter-spacing: .1em; color: var(--pdf-accent); }
.pdf-pagecount:not(:empty) {
  position: absolute; right: 4px; bottom: 4px; font-size: 9px; padding: 1px 5px;
  border-radius: 3px; background: rgba(0, 0, 0, .65); color: #fff;
}
.pdf-meta { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 5px; font-size: 12px; }
.pdf-kind { font-size: 9px; letter-spacing: .14em; text-transform: uppercase; color: var(--pdf-accent); font-weight: 700; }
.pdf-name { color: var(--fg); font-size: 14px; font-weight: 600; line-height: 1.35; padding-right: 96px; overflow-wrap: anywhere; }
.pdf-sub { color: var(--fg-dim); font-size: 11px; }
.pdf-quote {
  margin-top: auto; font-size: 11.5px; color: var(--fg-dim); line-height: 1.5;
  border-left: 2px solid var(--qc, var(--warn)); padding: 1px 0 1px 9px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pdf-quote.empty { border-color: var(--border); color: var(--fg-faint); font-style: italic; }
.pdf-open {
  position: absolute; right: 12px; top: 10px; font-size: 10px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--fg-faint); transition: color .15s;
}
.pdf-card:hover .pdf-open, .pdf-card:focus-visible .pdf-open { color: var(--accent); }
.pdf-reader-note { padding: 18px; font-size: 12px; color: var(--fg-dim); text-align: center; }
.pdf-reader-note button {
  font: inherit; font-size: 11px; color: var(--fg-dim); background: transparent; cursor: pointer;
  border: 1px solid var(--border); border-radius: 3px; padding: 2px 10px; margin-left: 6px;
}

/* ── a PDF-only note: the reader is the document ── */
#document-container.pdf-only { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
#document-container.pdf-only > .pdf-block {
  flex: 1; min-height: 0; max-width: none; margin: 0; display: flex; flex-direction: column;
}
#document-container.pdf-only .pdf-card,
#document-container.pdf-only .gutter,
#document-container.pdf-only .touch-tools { display: none; }
#document-container.pdf-only .pdf-reader { display: flex; flex: 1; min-height: 0; flex-direction: column; }
#document-container.pdf-only .pdf-reader-note { margin: auto; }

.pdf-bar {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px; font-size: 11px; white-space: nowrap;
  color: var(--fg-dim); background: var(--bg-raised); border-bottom: 1px solid var(--border-soft);
  overflow-x: auto; scrollbar-width: none;
}
.pdf-back { font: inherit; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 0; }
.pdf-title { color: var(--fg); max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.pdf-tools, .pdf-right { display: inline-flex; align-items: center; gap: 4px; }
.pdf-tools { margin-left: 8px; padding-left: 10px; border-left: 1px solid var(--border); }
.pdf-right { margin-left: auto; }
.pdf-btn {
  font: inherit; font-size: 11px; color: var(--fg-dim); background: transparent; cursor: pointer;
  border: 1px solid transparent; border-radius: 4px; padding: 3px 8px; line-height: 1.3; text-decoration: none;
}
.pdf-btn:hover:not(:disabled) { color: var(--fg); border-color: var(--border); }
.pdf-btn.on { color: var(--bg-page); background: var(--accent); }
.pdf-btn:disabled { opacity: .35; cursor: not-allowed; }
.pdf-sw { width: 14px; height: 14px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.pdf-sw.on { border-color: var(--fg); }
.pdf-ro { color: var(--fg-faint); margin-left: 6px; }
.pdf-page-in {
  width: 42px; font: inherit; font-size: 11px; text-align: right; color: var(--fg);
  background: var(--bg-code); border: 1px solid var(--border); border-radius: 3px; padding: 2px 4px;
}

.pdf-body { flex: 1; min-height: 0; display: flex; }
.pdf-scroll { flex: 1; min-width: 0; overflow: auto; background: var(--bg-page); }
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 22px 24px 80px; }
.pdf-page { position: relative; flex: none; background: #fff; box-shadow: 0 2px 14px rgba(0, 0, 0, .5); }
.pdf-page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

/* pdf.js's text layer — the minimum of its pdf_viewer.css the selection needs */
.pdf-page .textLayer {
  position: absolute; inset: 0; overflow: hidden; line-height: 1; z-index: 2;
  text-size-adjust: none; forced-color-adjust: none; transform-origin: 0 0;
}
.pdf-page .textLayer span, .pdf-page .textLayer br {
  color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%;
}
.pdf-page .textLayer ::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

/* Layers, bottom to top: canvas < highlights < text (selectable) < ink < pins.
   The blend sits on the LAYER: a z-indexed layer is an isolated group, so blending
   each mark only mixed it with its siblings and the highlight hid the words. */
.pdf-hl { position: absolute; inset: 0; z-index: 1; pointer-events: none; mix-blend-mode: multiply; }
.pdf-hl i { position: absolute; border-radius: 2px; }
.pdf-ink { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; pointer-events: none; overflow: visible; }
.pdf-ink polyline { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.pdf-pins { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.pdf-pin {
  position: absolute; transform: translate(-50%, -100%); pointer-events: auto; cursor: pointer;
  font-size: 10px; font-weight: 600; color: #111; padding: 3px 6px 4px;
  border-radius: 6px 6px 6px 0; box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}
.pdf-hl i.flash, .pdf-pin.flash, .pdf-ink polyline.flash { animation: pdf-flash .9s 2; }
@keyframes pdf-flash { 50% { opacity: .25; } }

/* Each tool decides which layer takes the pointer. */
.pdf-reader[data-tool="pen"] .pdf-ink,
.pdf-reader[data-tool="note"] .pdf-ink { pointer-events: auto; cursor: crosshair; touch-action: none; }
.pdf-reader[data-tool="pen"] .textLayer,
.pdf-reader[data-tool="note"] .textLayer,
.pdf-reader[data-tool="erase"] .textLayer { pointer-events: none; }
.pdf-reader[data-tool="erase"] .pdf-hl { z-index: 5; }
.pdf-reader[data-tool="erase"] .pdf-hl i,
.pdf-reader[data-tool="erase"] .pdf-ink polyline { pointer-events: all; cursor: pointer; }
.pdf-reader[data-tool="erase"] .pdf-hl i:hover,
.pdf-reader[data-tool="erase"] .pdf-ink polyline:hover { opacity: .35; }

.pdf-bubble {
  position: fixed; z-index: 60; display: flex; align-items: center; gap: 6px; padding: 5px 8px;
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5); font-size: 11px; color: var(--fg-dim);
}
.pdf-bubble button:not(.pdf-sw) { font: inherit; font-size: 11px; color: var(--fg-dim); background: none; border: 0; cursor: pointer; padding: 2px 4px; }
.pdf-bubble button:not(.pdf-sw):hover { color: var(--fg); }
.pdf-bubble-sep { width: 1px; height: 14px; background: var(--border); }

/* ── the annotation rail ── */
.pdf-rail { flex: 0 0 280px; display: flex; flex-direction: column; min-height: 0;
  border-left: 1px solid var(--border-soft); background: var(--bg-raised); }
.pdf-reader.rail-closed .pdf-rail { display: none; }
.pdf-rail-head { display: flex; gap: 8px; padding: 10px 14px; font-size: 10px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--fg-faint); border-bottom: 1px solid var(--border-soft); }
.pdf-rail-head b { color: var(--fg-dim); font-weight: 500; }
.pdf-rail-list { flex: 1; overflow: auto; padding: 6px 0; }
.pdf-rail-empty { padding: 18px 14px; font-size: 11.5px; color: var(--fg-faint); line-height: 1.6; }
.pdf-ra { padding: 8px 14px 9px; border-bottom: 1px solid var(--border-soft); cursor: pointer; font-size: 11.5px; }
.pdf-ra:hover { background: var(--bg-code); }
.pdf-ra-top { display: flex; align-items: center; gap: 7px; color: var(--fg-faint); font-size: 10px; }
.pdf-ra-dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.pdf-ra-x { margin-left: auto; opacity: 0; font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0 3px; }
.pdf-ra:hover .pdf-ra-x, .pdf-ra-x:focus-visible { opacity: 1; }
.pdf-ra-x:hover { color: var(--danger); }
.pdf-ra-quote { margin-top: 5px; color: var(--fg); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.pdf-ra-c {
  display: block; margin-top: 6px; width: 100%; box-sizing: border-box; font: inherit; font-size: 11px;
  color: var(--fg-dim); resize: none; background: transparent; border: 1px dashed var(--border);
  border-radius: 4px; padding: 4px 6px; min-height: 26px;
}
.pdf-ra-c:focus { outline: none; border-style: solid; border-color: var(--accent-line); color: var(--fg); }
.pdf-ra-c[readonly] { border: 0; padding-left: 0; }

/* ── dropping a PDF from the desktop ── */
body[data-pdf-drop="new"] #sidebar,
body[data-pdf-drop="note"] #document-container {
  outline: 2px dashed var(--accent); outline-offset: -6px;
  background: color-mix(in srgb, var(--accent) 7%, var(--bg-page));
}

@media (max-width: 900px) {
  .pdf-rail { display: none; }
  .pdf-thumb { width: 84px; }
  .pdf-name { padding-right: 0; }
  .pdf-open { position: static; order: 3; }
}
