/* =====================================================================
   PDF Viewer. Chrome follows the system theme; pages stay white.
   ===================================================================== */
.app-pdf {
  --p-canvas: #e6e8ee;
  --p-brand: #dc2626;
  --p-on: rgba(var(--accent-rgb), .16);
  --p-page-shadow: 0 0 0 .5px rgba(15, 23, 42, .1), 0 2px 6px rgba(15, 23, 42, .08), 0 12px 30px -12px rgba(15, 23, 42, .3);
  background: var(--surface);
}
:root[data-theme="dark"] .app-pdf, :root:not([data-theme]) .app-pdf {
  --p-canvas: #11151d;
  --p-page-shadow: 0 0 0 .5px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .3), 0 16px 36px -14px rgba(0, 0, 0, .8);
}
.win[data-app="pdf"]:has(.pdf-docname) .win-title-text { display: none; }
.pdf-docname { font-size: 13px; font-weight: 600; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px; }
.pdf-savestate { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-3); white-space: nowrap; }
.pdf-savestate .ic { color: #22a565; }
.pdf-savestate.is-warn, .pdf-savestate.is-warn .ic { color: #d97706; }
.pdf-dot { width: 7px; height: 7px; border-radius: 50%; background: #f5a524; animation: pdf-pulse 1s ease-in-out infinite; }
@keyframes pdf-pulse { 50% { opacity: .35; } }

.pdf-root { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }

/* ---------------------------------------------------------- start screen */
.pdf-start { flex: 1; min-height: 0; background: var(--surface); }
.pdf-start-hero {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 36px 24px 28px;
  background: radial-gradient(70% 120% at 50% 0%, rgba(248, 113, 113, .2), transparent 70%), var(--surface-2); border-bottom: 1px solid var(--line);
}
.pdf-start-logo { width: 62px; height: 62px; border-radius: 18px; display: grid; place-items: center; color: #fff; background: linear-gradient(160deg, #f87171, #b91c1c); box-shadow: 0 10px 26px -10px rgba(185, 28, 28, .7), inset 0 1px 0 rgba(255, 255, 255, .3); }
.pdf-start-hero h2 { margin: 10px 0 0; font-size: 21px; font-weight: 700; letter-spacing: -.01em; }
.pdf-start-hero p { margin: 0; max-width: 460px; font-size: 13.5px; color: var(--text-2); }
.pdf-start-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.pdf-start-msg { display: flex; gap: 10px; align-items: flex-start; text-align: left; max-width: 460px; margin-top: 10px; padding: 12px 14px; border-radius: 12px; background: rgba(217, 119, 6, .12); color: var(--text); }
.pdf-start-msg > span { color: #d97706; }
.pdf-start-msg p { margin: 2px 0 0; font-size: 12.5px; }
.pdf-start-sec { max-width: 860px; margin: 0 auto; padding: 22px 24px 28px; }
.pdf-start-sec h3 { margin: 0 0 10px; font-size: 14px; font-weight: 700; }
.pdf-start-list { display: flex; flex-direction: column; }
.pdf-start-row {
  display: grid; grid-template-columns: 34px minmax(0, 2fr) minmax(0, 1fr) 80px; align-items: center; gap: 12px; min-height: 48px; padding: 6px 12px;
  border: 0; border-radius: 10px; background: none; color: var(--text); text-align: left; font: inherit; cursor: pointer;
}
.pdf-start-row:hover { background: var(--hover); }
.pdf-start-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.pdf-start-ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: #fff; background: linear-gradient(160deg, #f87171, #b91c1c); }
.pdf-start-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdf-start-loc, .pdf-start-size { font-size: 12.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdf-start-size { text-align: right; }
.pdf-start-empty { display: flex; align-items: center; gap: 10px; padding: 14px; border-radius: 12px; background: var(--surface-2); font-size: 13px; color: var(--text-2); box-shadow: inset 0 0 0 1px var(--line); margin-top: 6px; }

.pdf-invalid { margin: auto; max-width: 440px; padding: 28px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; }
.pdf-invalid-ic { width: 72px; height: 72px; border-radius: 20px; display: grid; place-items: center; color: #ef4444; background: rgba(239, 68, 68, .12); }
.pdf-invalid h3 { margin: 6px 0 0; font-size: 17px; }
.pdf-invalid p { margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--text-2); }
.pdf-loading { margin: auto; display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--text-2); }

/* ---------------------------------------------------------- toolbar */
.pdf-toolbar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 2px; height: 46px; padding: 0 8px; background: var(--surface);
  border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; position: relative; z-index: 3;
}
.pdf-toolbar::-webkit-scrollbar { display: none; }
.pdf-tb {
  height: 32px; min-width: 32px; padding: 0 7px; border: 0; border-radius: 8px; background: none; color: var(--text); flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: 12.5px; cursor: pointer; transition: background .1s, color .1s;
}
.pdf-tb:hover { background: var(--hover); }
.pdf-tb:active { background: var(--press); }
.pdf-tb:disabled { opacity: .35; pointer-events: none; }
.pdf-tb.on { background: var(--p-on); color: var(--accent); }
.pdf-tb:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.pdf-tsep { width: 1px; height: 22px; background: var(--line-2); margin: 0 5px; flex: 0 0 auto; }
.pdf-tspace { flex: 1; min-width: 8px; }
.pdf-pagebox { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--text-2); flex: 0 0 auto; margin: 0 2px; }
.pdf-pagein { width: 40px; height: 28px; border: 0; border-radius: 7px; text-align: center; background: var(--surface-2); color: var(--text); font: inherit; font-size: 12.5px; font-variant-numeric: tabular-nums; box-shadow: inset 0 0 0 1px var(--line-2); outline: none; }
.pdf-pagein:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.pdf-pagecount { white-space: nowrap; font-variant-numeric: tabular-nums; }
.pdf-zoomsel { height: 28px; border: 0; border-radius: 7px; padding: 0 22px 0 8px; background: var(--surface-2); color: var(--text); font: inherit; font-size: 12.5px; box-shadow: inset 0 0 0 1px var(--line-2); outline: none; appearance: none; flex: 0 0 auto; width: 138px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%); background-position: calc(100% - 12px) 12px, calc(100% - 8px) 12px; background-size: 4px 4px; background-repeat: no-repeat; }
.pdf-zoomsel:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.pdf-toolgroup { display: inline-flex; align-items: center; gap: 1px; padding: 2px; border-radius: 10px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); flex: 0 0 auto; }
.pdf-toolgroup .pdf-tb { height: 30px; min-width: 32px; }
.pdf-colorbtn i { width: 16px; height: 16px; border-radius: 50%; display: block; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .2); }

/* find bar */
.pdf-findbar { display: none; align-items: center; gap: 4px; padding: 6px 10px; background: var(--surface); border-bottom: 1px solid var(--line); }
.pdf-findbar.on { display: flex; }
.pdf-findfield { width: 280px; max-width: 50%; }
.pdf-findfield .input { height: 30px; }
.pdf-findcount { font-size: 12px; color: var(--text-2); min-width: 72px; padding: 0 6px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pdf-findcount.none { color: #e5484d; }
.pdf-case { height: 26px; padding: 0 9px; font-weight: 700; }

/* ---------------------------------------------------------- body: sidebar + pages */
.pdf-body { flex: 1; min-height: 0; display: flex; position: relative; }
.pdf-side { width: 0; flex: 0 0 auto; overflow: hidden; display: flex; flex-direction: column; background: var(--sidebar); border-right: 1px solid transparent; transition: width .2s var(--ease); }
.pdf-root.side-on .pdf-side { width: 200px; border-right-color: var(--line); }
.pdf-sidetabs { margin: 8px 8px 4px; min-width: 184px; display: flex; }
.pdf-sidetabs button { flex: 1; justify-content: center; padding: 0; }
.pdf-sidebody { flex: 1; min-width: 200px; padding: 6px 8px 12px; }
.pdf-side-empty { display: flex; justify-content: center; padding: 18px 10px; font-size: 12.5px; color: var(--text-2); text-align: center; line-height: 1.5; }
.pdf-thumb { display: flex; flex-direction: column; align-items: center; gap: 5px; width: 100%; padding: 8px 18px 6px; border: 0; border-radius: 10px; background: none; color: var(--text-2); cursor: pointer; }
.pdf-thumb:hover { background: var(--hover); }
.pdf-thumb-img { display: block; width: 100%; background: #fff; border-radius: 3px; overflow: hidden; box-shadow: 0 0 0 1px var(--line-2), 0 2px 6px rgba(0, 0, 0, .12); }
.pdf-thumb-img canvas { display: block; width: 100%; height: 100%; }
.pdf-thumb.on .pdf-thumb-img { box-shadow: 0 0 0 2.5px var(--accent), 0 4px 10px rgba(0, 0, 0, .2); }
.pdf-thumb-n { font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pdf-thumb.on .pdf-thumb-n { color: var(--accent); }
.pdf-outline { display: flex; flex-direction: column; }
.pdf-ol-row { display: flex; align-items: center; min-height: 30px; }
.pdf-ol-tw { width: 18px; height: 18px; flex: 0 0 auto; border: 0; padding: 0; background: none; color: var(--text-3); display: grid; place-items: center; border-radius: 4px; transition: transform .15s; }
button.pdf-ol-tw:hover { background: var(--hover); color: var(--text); }
.pdf-ol-row.closed button.pdf-ol-tw { transform: rotate(-90deg); }
.pdf-ol-item { flex: 1; min-width: 0; border: 0; background: none; color: var(--text); text-align: left; font: inherit; font-size: 12.5px; padding: 6px 6px; border-radius: 7px; line-height: 1.3; cursor: pointer; }
.pdf-ol-item:hover { background: var(--hover); }
.pdf-note-row { display: flex; gap: 8px; align-items: flex-start; width: 100%; padding: 8px; border: 0; border-radius: 9px; background: none; color: var(--text); text-align: left; font: inherit; cursor: pointer; }
.pdf-note-row:hover { background: var(--hover); }
.pdf-note-row.on { background: var(--p-on); }
.pdf-note-ic { flex: 0 0 auto; margin-top: 1px; }
.pdf-note-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: 12px; }
.pdf-note-text strong { font-size: 12px; font-weight: 600; }
.pdf-note-text span { color: var(--text-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }

.pdf-main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.pdf-viewer { flex: 1; min-height: 0; overflow: auto; background: var(--p-canvas); outline: none; }
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 18px 24px 40px; min-width: min-content; }
.pdf-page { position: relative; flex: 0 0 auto; background: #fff; box-shadow: var(--p-page-shadow); overflow: hidden; }
.pdf-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.pdf-page.is-stale .pdf-canvas { filter: blur(.4px); }
.pdf-pageload { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.pdf-page.is-ready .pdf-pageload { display: none; }

/* pdf.js text layer (from pdf_viewer.css, Apache-2.0) */
.app-pdf .textLayer { user-select: text; -webkit-user-select: text; position: absolute; text-align: initial; inset: 0; overflow: hidden; opacity: 1; line-height: 1; text-size-adjust: none; -webkit-text-size-adjust: none; forced-color-adjust: none; transform-origin: 0 0; z-index: 2; }
.app-pdf .textLayer :is(span, br) { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%; }
.app-pdf .textLayer span.markedContent { top: 0; height: 0; }
.app-pdf .textLayer .highlight { margin: -1px; padding: 1px; background-color: rgba(250, 204, 21, .45); border-radius: 3px; }
.app-pdf .textLayer .highlight.appended { position: initial; }
.app-pdf .textLayer .highlight.selected { background-color: rgba(249, 115, 22, .6); box-shadow: 0 0 0 1.5px rgba(234, 88, 12, .9); }
.app-pdf .textLayer ::selection { background: rgba(37, 99, 235, .3); }
.app-pdf .textLayer br::selection { background: transparent; }
.app-pdf .textLayer .endOfContent { display: block; position: absolute; inset: 100% 0 0; z-index: -1; cursor: default; user-select: none; }
.app-pdf .textLayer .endOfContent.active { top: 0; }
.app-pdf .pdf-page [data-main-rotation="90"] { transform: rotate(90deg) translateY(-100%); }
.app-pdf .pdf-page [data-main-rotation="180"] { transform: rotate(180deg) translate(-100%, -100%); }
.app-pdf .pdf-page [data-main-rotation="270"] { transform: rotate(270deg) translateX(-100%); }

/* annotation layer */
.pdf-annlayer { position: absolute; left: 0; top: 0; z-index: 3; transform-origin: 0 0; pointer-events: none; }
.pdf-annsvg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.pdf-annhtml { position: absolute; inset: 0; }
.pdf-a-hl rect { mix-blend-mode: multiply; opacity: .55; }
.pdf-a-draft { opacity: .45; mix-blend-mode: multiply; }
.pdf-a-selbox { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 2; vector-effect: non-scaling-stroke; }
.pdf-a-hl.sel rect { opacity: .75; }
.pdf-root[data-tool="select"] .pdf-a-hl, .pdf-root[data-tool="select"] .pdf-a-ink .pdf-a-hit, .pdf-root[data-tool="select"] .pdf-a-sign { pointer-events: auto; cursor: move; }
.pdf-root[data-tool="select"] .pdf-a-ink .pdf-a-hit { pointer-events: stroke; }
.pdf-root[data-tool="pen"] .pdf-annlayer, .pdf-root[data-tool="note"] .pdf-annlayer, .pdf-root[data-tool="sign"] .pdf-annlayer { pointer-events: auto; cursor: crosshair; }
.pdf-root[data-tool="note"] .pdf-annlayer { cursor: copy; }
.pdf-root[data-tool="highlight"] .textLayer span { cursor: text; }
.pdf-root[data-tool="highlight"] .textLayer { cursor: crosshair; }
.pdf-a-note {
  position: absolute; display: grid; place-items: center; padding: 0; border: 0; border-radius: 4px 4px 4px 1px; pointer-events: auto; cursor: pointer;
  background: var(--c, #facc15); color: #713f12; box-shadow: 0 1px 3px rgba(0, 0, 0, .35); min-width: 14px; min-height: 14px;
}
.pdf-a-note .ic { width: 62%; height: 62%; }
.pdf-a-note.sel { box-shadow: 0 0 0 2px var(--accent), 0 2px 6px rgba(0, 0, 0, .35); }
.pdf-a-sign { position: absolute; }
.pdf-a-sign img { width: 100%; height: 100%; display: block; pointer-events: none; user-select: none; }
.pdf-a-sign.sel { outline: 1.5px dashed var(--accent); outline-offset: 2px; }
.pdf-a-resize { position: absolute; right: -7px; bottom: -7px; width: 12px; height: 12px; border-radius: 3px; background: #fff; box-shadow: 0 0 0 1.5px var(--accent); cursor: nwse-resize; pointer-events: auto; }

/* tool hint */
.pdf-hint {
  position: absolute; left: 50%; bottom: 18px; transform: translate(-50%, 10px); display: flex; align-items: center; gap: 12px; z-index: 6;
  padding: 8px 10px 8px 16px; border-radius: 22px; background: var(--glass-solid); color: var(--text); font-size: 12.5px; box-shadow: var(--shadow-pop), inset 0 0 0 1px var(--line);
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; white-space: nowrap; max-width: calc(100% - 24px);
}
.pdf-hint.on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.pdf-hint .link { padding: 4px 10px; border-radius: 14px; background: var(--p-on); }

/* note popover */
.pdf-notepop { position: absolute; z-index: 20; width: 260px; padding: 10px; border-radius: 12px; background: #fefce8; color: #1f2328; box-shadow: var(--shadow-pop), inset 0 0 0 1px rgba(202, 138, 4, .35); display: flex; flex-direction: column; gap: 8px; animation: pdf-pop .12s var(--ease); }
@keyframes pdf-pop { from { opacity: 0; transform: translateY(-4px); } }
.pdf-notepop-head { display: flex; align-items: baseline; justify-content: space-between; font-size: 12.5px; }
.pdf-notepop-head .muted { color: #6b7280; font-size: 11.5px; }
.pdf-notepop .textarea { background: #fff; color: #1f2328; box-shadow: inset 0 0 0 1px rgba(202, 138, 4, .4); resize: none; font-size: 13px; }
.pdf-notepop .textarea:focus { box-shadow: inset 0 0 0 2px #ca8a04; }
.pdf-notepop-actions { display: flex; align-items: center; gap: 6px; }
.pdf-notepop .btn:not(.btn-primary) { background: rgba(0, 0, 0, .06); color: #1f2328; box-shadow: none; }

/* modals (signature, properties) */
.pdf-modal { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(10, 14, 22, .4); animation: pdf-fade .14s; }
@keyframes pdf-fade { from { opacity: 0; } }
.pdf-sign { width: min(560px, 100%); padding: 18px; border-radius: 18px; display: flex; flex-direction: column; gap: 12px; background: var(--glass-strong); }
.pdf-sign-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pdf-sign-head h3, .pdf-props h3 { margin: 0; font-size: 16px; }
.pdf-sign-pad { position: relative; background: #fff; border-radius: 12px; box-shadow: inset 0 0 0 1px var(--line-2); overflow: hidden; }
.pdf-sign-canvas { display: block; width: 100%; aspect-ratio: 3 / 1; cursor: crosshair; touch-action: none; position: relative; z-index: 1; }
.pdf-sign-line { position: absolute; left: 8%; right: 8%; bottom: 24%; height: 1px; background: #cbd5e1; pointer-events: none; }
.pdf-sign-type { position: absolute; left: 12px; right: 12px; bottom: 10px; z-index: 2; background: rgba(255, 255, 255, .92); color: #111827; }
.pdf-sign-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pdf-sign-colors { display: flex; gap: 6px; margin-right: 4px; }
.pdf-sign-color { width: 22px; height: 22px; border-radius: 50%; border: 0; padding: 0; cursor: pointer; }
.pdf-sign-color.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.pdf-sign-saved { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; }
.pdf-sign-savedbtn { height: 44px; padding: 4px 10px; border: 0; border-radius: 10px; background: #fff; box-shadow: inset 0 0 0 1px var(--line-2); cursor: pointer; }
.pdf-sign-savedbtn:hover { box-shadow: inset 0 0 0 2px var(--accent); }
.pdf-sign-savedbtn img { height: 100%; display: block; }
.pdf-props { width: min(440px, 100%); padding: 20px; border-radius: 18px; background: var(--glass-strong); }
.pdf-props dl { display: grid; grid-template-columns: 110px 1fr; gap: 8px 14px; margin: 14px 0 16px; font-size: 13px; }
.pdf-props dt { color: var(--text-2); }
.pdf-props dd { margin: 0; overflow-wrap: anywhere; }
.pdf-props-foot { display: flex; justify-content: flex-end; }

.pdf-progress { position: absolute; left: 50%; top: 60px; transform: translateX(-50%); z-index: 25; display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: 22px; background: var(--glass-solid); font-size: 13px; box-shadow: var(--shadow-pop); }
.pdf-printframe { position: fixed; right: 0; bottom: 0; width: 0; height: 0; border: 0; visibility: hidden; }

/* presentation */
.pdf-present { position: absolute; inset: 0; z-index: 40; background: #000; display: grid; place-items: center; outline: none; cursor: none; }
.pdf-present:fullscreen { width: 100vw; height: 100vh; }
.pdf-present-page canvas { display: block; box-shadow: 0 0 40px rgba(0, 0, 0, .6); }
.pdf-present-count { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); padding: 6px 12px; border-radius: 14px; background: rgba(255, 255, 255, .14); color: #fff; font-size: 13px; font-variant-numeric: tabular-nums; opacity: 0; transition: opacity .3s; }
.pdf-present-count.on { opacity: 1; }

/* drop */
.pdf-root.drop-on::after { content: 'Drop a PDF to open it'; position: absolute; inset: 10px; z-index: 50; border-radius: 14px; display: grid; place-items: center; font-size: 15px; font-weight: 600; color: var(--text); background: rgba(var(--accent-rgb), .16); box-shadow: inset 0 0 0 2px var(--accent); pointer-events: none; }

/* narrow + phone */
.pdf-root.is-narrow .pdf-hide-sm { display: none; }
.pdf-root.is-narrow .pdf-zoomsel { width: 112px; }
.pdf-root.is-narrow .pdf-pages { padding: 10px 8px 30px; gap: 10px; }
.pdf-root.is-narrow.side-on .pdf-side { position: absolute; left: 0; top: 0; bottom: 0; z-index: 8; width: 210px; box-shadow: var(--shadow-pop); background: var(--glass-solid); }
.pdf-root.is-narrow .pdf-findfield { flex: 1; max-width: none; width: auto; }
.pdf-root.is-narrow .pdf-start-row { grid-template-columns: 34px minmax(0, 1fr) 64px; }
.pdf-root.is-narrow .pdf-start-loc { display: none; }
.pdf-root.is-narrow .pdf-hint { white-space: normal; bottom: 10px; }
