/* ══════════════════════════════════════
   PDF Viewer  (pv-*)
══════════════════════════════════════ */

.pv-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: #0a0a0a;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── TopBar ── */
.pv-topbar {
  height: 48px;
  background: rgba(0,0,0,0.85);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 4px;
  flex-shrink: 0;
  backdrop-filter: blur(10px);
  z-index: 10;
}

.pv-tb-left {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.pv-tb-right {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}

.pv-close-btn {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-lg);
  background: transparent;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.pv-close-btn:hover { background: rgba(255,255,255,0.12); }

.pv-page-info-btn {
  height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-lg);
  background: transparent;
  color: #fff;
  cursor: pointer;
  font-size: var(--fs-12);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-sans);
  font-weight: 500;
  transition: background 0.15s;
  white-space: nowrap;
}
.pv-page-info-btn:hover { background: rgba(255,255,255,0.1); }

.pv-tb-btn {
  height: 34px;
  min-width: 34px;
  padding: 0 8px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-lg);
  background: transparent;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  font-size: var(--fs-12);
  font-family: var(--font-sans);
  white-space: nowrap;
  flex-shrink: 0;
}
.pv-tb-btn:hover { background: rgba(255,255,255,0.1); }
.pv-tb-btn-active { background: rgba(60,207,239,0.2); border-color: var(--accent); color: var(--accent); }
.pv-tb-btn-active:hover { background: rgba(60,207,239,0.3); }
.pv-tb-btn-danger { border-color: #ef4444; color: #ef4444; }
.pv-tb-btn-danger:hover { background: rgba(239,68,68,0.15); }

@media (min-width: 541px) { .pv-tb-more-btn { display: none; } }
@media (max-width: 540px) { .pv-tb-hide-mobile { display: none; } }

/* More overflow menu */
.pv-more-wrap { position: relative; }

.pv-more-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: #1a1a1a;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-xl);
  overflow: hidden;
  min-width: 170px;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.pv-more-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  color: #fff;
  font-family: var(--font-sans);
  font-size: var(--fs-12);
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
}
.pv-more-item:last-child { border-bottom: none; }
.pv-more-item:hover { background: rgba(255,255,255,0.08); }
.pv-more-danger { color: #ef4444; }

/* Naming phase inline toolbar */
.pv-tb-naming {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  padding: 0 4px;
}

.pv-tag-input {
  flex: 1;
  height: 32px;
  padding: 0 10px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-lg);
  color: #fff;
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  outline: none;
  min-width: 0;
}
.pv-tag-input:focus { border-color: var(--accent); }
.pv-tag-input::placeholder { color: rgba(255,255,255,0.4); }

.pv-tag-save {
  height: 32px;
  padding: 0 14px;
  background: var(--accent);
  color: #0a0a0a;
  border: none;
  border-radius: var(--radius-lg);
  font-family: var(--font-sans);
  font-size: var(--fs-12);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.pv-tag-save:hover { opacity: 0.88; }

.pv-phase-hint {
  font-size: var(--fs-12);
  color: rgba(255,255,255,0.7);
  padding-left: 4px;
}

/* ── Page area ── */
.pv-page-area {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  cursor: grab;
}
.pv-page-area:active { cursor: grabbing; }
.pv-page-area--grid { touch-action: auto; cursor: default; }
.pv-page-area--grid:active { cursor: default; }

/* ── Single-page frame ── */
.pv-page-frame {
  display: inline-block;
  position: relative;
  transform-origin: center center;
  will-change: transform;
  line-height: 0;
  flex-shrink: 0;
}

.pv-page-img {
  display: block;
  max-width: 100vw;
  max-height: calc(100dvh - 72px);
  width: auto;
  height: auto;
  pointer-events: none;
  user-select: none;
}

/* ── Multi-page grid ── */
.pv-multi-grid {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(250px, 47%), 1fr));
  gap: 12px;
  align-content: start;
  box-sizing: border-box;
  cursor: default;
}

.pv-grid-thumb {
  background: #1a1a1a;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-xl);
  cursor: pointer;
  transition: border-color 0.15s;
  align-self: start;
}
.pv-grid-thumb:hover { border-color: var(--accent); }

.pv-grid-img-wrap {
  width: 100%;
  background: #111;
  border-radius: 8px 8px 0 0;
}

.pv-grid-thumb-img {
  width: 100%;
  height: auto;
  display: block;
  pointer-events: none;
  border-radius: 8px 8px 0 0;
}

.pv-grid-thumb-num {
  font-size: var(--fs-12);
  color: rgba(255,255,255,0.5);
  padding: 4px 8px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ── Reading rects (highlighter) ── */
.pv-reading-rect {
  position: absolute;
  border-radius: var(--radius-sm);
  pointer-events: all;
}

/* The colored fill lives in its own layer, separate from `.pv-reading-rect`
   itself, so `mix-blend-mode` only ever applies to this leaf. A descendant
   can't opt out of an ancestor's own blend-mode compositing (isolation only
   protects blending *among* a group's children) — the reveal popover below
   is a sibling of this fill layer, not a child of it, specifically so it
   never gets swept into the multiply blend and rendered translucent over
   the PDF page. */
.pv-reading-rect-fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  mix-blend-mode: multiply;
}

.pv-reading-rect--pressing {
  cursor: wait;
}

.pv-reading-rect--pressing .pv-reading-rect-fill {
  filter: brightness(0.55);
  transition: filter 0.6s linear;
}

/* ── Highlighter label picker (topbar, post-draw + assign-to-legacy) ── */
.pv-tb-label-pick { flex-wrap: wrap; row-gap: 6px; }

.pv-label-pill {
  --pv-label-color: #3CCFEF;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-lg);
  color: #fff;
  font-family: var(--font-sans);
  font-size: var(--fs-12);
  cursor: pointer;
}
.pv-label-pill:hover { background: rgba(255,255,255,0.18); }

.pv-label-pill-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--pv-label-color);
  flex-shrink: 0;
}

/* ── Highlighter reveal popover (tap/hold an existing highlight) ── */
.pv-rect-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 200px;
  max-width: 280px;
  padding: 10px;
  background: #1a1a1a;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  pointer-events: all;
  cursor: default;
}

.pv-rect-popover-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pv-rect-popover-name {
  color: #fff;
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  font-weight: 600;
  margin-right: auto;
}

/* ── Section markers (bookmarks) ── */
.pv-section-pin {
  position: absolute;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: all;
  cursor: default;
  z-index: 10;
}

.pv-section-label {
  font-size: var(--fs-10);
  font-weight: 600;
  color: #fff;
  background: rgba(0,0,0,0.65);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
  display: none;
}
.pv-section-pin:hover .pv-section-label { display: block; }

.pv-pin-remove {
  position: absolute;
  top: -6px;
  right: -10px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  font-size: var(--fs-12);
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  padding: 0;
}
.pv-section-pin:hover .pv-pin-remove { opacity: 1; }

/* ── Placing pin preview ── */
.pv-placing-pin {
  position: absolute;
  transform: translateX(-50%);
  z-index: 10;
  pointer-events: none;
  opacity: 0.7;
}

/* ── Placing overlay ── */
.pv-placing-overlay {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  z-index: 5;
}

/* ── Drawing overlay ── */
.pv-draw-overlay {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  z-index: 5;
}

.pv-draw-preview {
  position: absolute;
  border: 2px dashed transparent;
  pointer-events: none;
  box-sizing: border-box;
  background: transparent;
}

/* ── Row bracket ── */
.pv-bracket {
  position: absolute;
  pointer-events: all;
  touch-action: none;
  z-index: 8;
  cursor: move;
}

/* Corner L-shapes — no border on parent; each corner carries its own two sides */
.pv-b-corner {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2.5px solid var(--accent);
  border-radius: 1px;
  cursor: move;
  z-index: 3;
}
.pv-b-tl { top: 0; left: 0; border-right: none; border-bottom: none; }
.pv-b-tr { top: 0; right: 0; border-left: none; border-bottom: none; }
.pv-b-bl { bottom: 0; left: 0; border-right: none; border-top: none; }
.pv-b-br { bottom: 0; right: 0; border-left: none; border-top: none; }

/* Edge drag handles */
.pv-b-edge {
  position: absolute;
  z-index: 2;
}
.pv-b-edge-n { top: -5px; left: 14px; right: 14px; height: 14px; cursor: ns-resize; }
.pv-b-edge-s { bottom: -5px; left: 14px; right: 14px; height: 14px; cursor: ns-resize; }
.pv-b-edge-w { left: -5px; top: 14px; bottom: 14px; width: 14px; cursor: ew-resize; }
.pv-b-edge-e { right: -5px; top: 14px; bottom: 14px; width: 14px; cursor: ew-resize; }

/* Dashed line centered in each handle so the resize zone is visible */
.pv-b-edge::after {
  content: '';
  position: absolute;
  pointer-events: none;
  opacity: 0.35;
  transition: opacity 0.15s;
}
.pv-b-edge:hover::after { opacity: 0.8; }
.pv-b-edge-n::after, .pv-b-edge-s::after {
  left: 0; right: 0;
  top: 50%;
  border-top: 1.5px dashed var(--accent);
}
.pv-b-edge-w::after, .pv-b-edge-e::after {
  top: 0; bottom: 0;
  left: 50%;
  border-left: 1.5px dashed var(--accent);
}

/* Center move handle */
.pv-b-move {
  position: absolute;
  inset: 12px;
  cursor: move;
  z-index: 1;
}

/* ── Nav arrows ── */
.pv-nav-arrows {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  padding: 0 8px;
  z-index: 6;
}

.pv-nav-btn {
  width: 36px;
  height: 64px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-lg);
  background: rgba(0,0,0,0.4);
  color: #fff;
  font-size: var(--fs-22);
  line-height: 1;
  cursor: pointer;
  pointer-events: all;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  backdrop-filter: blur(4px);
}
.pv-nav-btn:hover:not(:disabled) { background: rgba(0,0,0,0.65); }
.pv-nav-btn:disabled { opacity: 0.25; cursor: default; }

/* ── Hint bar ── */
.pv-hint-bar {
  height: 24px;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  backdrop-filter: blur(6px);
}
.pv-hint-bar span {
  font-size: var(--fs-12);
  color: rgba(255,255,255,0.45);
  font-family: var(--font-sans);
}
