:root {
  --bg: #e9edf2;
  --ink: #111827;
  --glass: rgba(17, 24, 39, 0.82);
  --glass-2: rgba(255, 255, 255, 0.92);
  --line: rgba(255, 255, 255, 0.16);
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
  --radius: 14px;
  --toolbar-h: 52px;
  --accent: #10b981;
  --focus: #22c55e;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app { position: fixed; inset: 0; overflow: hidden; background: var(--bg); }

.topbar {
  position: absolute;
  z-index: 50;
  top: calc(8px + var(--safe-top));
  left: calc(8px + var(--safe-left));
  right: calc(8px + var(--safe-right));
  min-height: var(--toolbar-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--glass);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(14px) saturate(130%);
  -webkit-backdrop-filter: blur(14px) saturate(130%);
  transition: opacity .2s ease, transform .2s ease;
}

.toolbar-group { display: flex; align-items: center; gap: 4px; min-width: 0; }
.toolbar-group--left { justify-self: start; }
.toolbar-group--center { justify-self: center; }
.toolbar-group--right { justify-self: end; }

.icon-btn, .zoom-value, .mini-btn, .text-btn, .edge-nav, .drawer-handle {
  border: 0;
  cursor: pointer;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  color: #fff;
  background: transparent;
  text-decoration: none;
  transition: background .15s ease, transform .12s ease, opacity .15s ease;
}
.icon-btn:hover { background: rgba(255,255,255,.12); }
.icon-btn:active { transform: scale(.95); }
.icon-btn[disabled] { opacity: .34; cursor: default; }
.icon-btn svg, .edge-nav svg, .search-box svg { width: 21px; height: 21px; fill: currentColor; }

.zoom-value {
  min-width: 60px;
  height: 34px;
  padding: 0 8px;
  border-radius: 9px;
  color: rgba(255,255,255,.92);
  background: rgba(255,255,255,.08);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.zoom-value:hover { background: rgba(255,255,255,.14); }

.page-counter {
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 9px;
  border-radius: 9px;
  color: rgba(255,255,255,.78);
  background: rgba(255,255,255,.08);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.page-counter input {
  width: 34px;
  padding: 0;
  border: 0;
  outline: 0;
  color: #fff;
  background: transparent;
  text-align: right;
  font-weight: 650;
}

.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  cursor: default;
  background:
    radial-gradient(circle at 50% 35%, rgba(255,255,255,.9), rgba(255,255,255,0) 55%),
    var(--bg);
}
.stage.is-pannable { cursor: grab; }
.stage.is-panning { cursor: grabbing; }

.page-frame {
  position: absolute;
  z-index: 10;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  transform-origin: center;
  will-change: transform, width, height;
  background: #fff;
  box-shadow: var(--shadow);
  contain: layout style;
}
.page-visual { position: relative; width: 100%; height: 100%; overflow: visible; }
.pdf-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #fff;
}
.hiddenCanvasElement { position: absolute !important; width: 0 !important; height: 0 !important; overflow: hidden !important; visibility: hidden !important; }

.page-visual.page-enter-next { animation: pageInNext .2s ease both; }
.page-visual.page-enter-prev { animation: pageInPrev .2s ease both; }
@keyframes pageInNext {
  from { opacity: .74; transform: translateX(8px) scale(.995); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes pageInPrev {
  from { opacity: .74; transform: translateX(-8px) scale(.995); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

.annotation-layer, .highlight-layer, .textLayer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.highlight-layer { z-index: 2; pointer-events: none; overflow: hidden; }

/*
 * PDF.js text layer. Textul rămâne INVIZIBIL: utilizatorul vede exclusiv
 * canvas-ul PDF original. Stratul există doar pentru selecție, copiere,
 * căutare și accesibilitate. Nu înlocuiește și nu redesenează fonturile PDF.
 */
.textLayer {
  z-index: 3;
  overflow: hidden;
  overflow: clip;
  opacity: 1;
  line-height: 1;
  text-align: initial;
  text-size-adjust: none;
  -webkit-text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  pointer-events: none;
  user-select: text;
  -webkit-user-select: text;
  caret-color: transparent;
}
.textLayer :is(span, br) {
  color: transparent !important;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0 0;
  user-select: text;
  -webkit-user-select: text;
  letter-spacing: 0;
  word-spacing: 0;
}
.textLayer span { pointer-events: auto; }
.textLayer span.markedContent {
  top: 0;
  height: 0;
  pointer-events: none;
}
.textLayer span.markedContent span { pointer-events: auto; }
.textLayer > :not(.markedContent), .textLayer .markedContent span:not(.markedContent) { z-index: 1; }
.textLayer span[role="img"] { user-select: none; -webkit-user-select: none; cursor: default; }
.textLayer ::selection { background: rgba(37, 99, 235, .28); }
.textLayer br::selection { background: transparent; }
.textLayer .endOfContent {
  display: block;
  position: absolute;
  inset: 100% 0 0;
  z-index: 0;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
}
.textLayer.selecting .endOfContent { top: 0; }
.textLayer .search-hit {
  background: rgba(250, 204, 21, .40);
  box-shadow: 0 0 0 1px rgba(202, 138, 4, .18);
  border-radius: 2px;
}

.annotation-layer { z-index: 4; pointer-events: none; }
.annotation-link {
  position: absolute;
  pointer-events: auto;
  display: block;
  background: transparent;
  border-radius: 2px;
  text-decoration: none;
}
.annotation-link:hover { outline: 2px solid rgba(16,185,129,.45); background: rgba(16,185,129,.07); }
.search-highlight {
  position: absolute;
  background: rgba(250, 204, 21, .42);
  border: 1px solid rgba(202, 138, 4, .25);
  border-radius: 2px;
  mix-blend-mode: multiply;
}

.edge-nav {
  position: absolute;
  z-index: 20;
  top: 50%;
  width: 46px;
  height: 74px;
  display: grid;
  place-items: center;
  transform: translateY(-50%);
  color: rgba(17,24,39,.72);
  background: rgba(255,255,255,.16);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  transition: opacity .2s ease, background .15s ease, transform .15s ease;
}
.edge-nav:hover { background: rgba(255,255,255,.52); }
.edge-nav:active { transform: translateY(-50%) scale(.96); }
.edge-nav svg { width: 28px; height: 28px; }
.edge-nav--prev { left: var(--safe-left); border-radius: 0 14px 14px 0; }
.edge-nav--next { right: var(--safe-right); border-radius: 14px 0 0 14px; }
.edge-nav[disabled] { opacity: .12; pointer-events: none; }

.loading-overlay {
  position: absolute;
  z-index: 80;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(233,237,242,.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity .2s ease, visibility .2s ease;
}
.loading-overlay.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-card {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 360px;
  padding: 14px 16px;
  border: 1px solid rgba(15,23,42,.08);
  border-radius: 14px;
  background: rgba(255,255,255,.92);
  box-shadow: 0 14px 40px rgba(15,23,42,.12);
}
.loader-card strong { display: block; font-size: 14px; }
.loading-detail { margin-top: 3px; color: #64748b; font-size: 12px; }
.spinner {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border: 3px solid #dbe3ea;
  border-top-color: #111827;
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-panel {
  position: absolute;
  z-index: 90;
  left: 50%;
  top: 50%;
  width: min(92vw, 480px);
  transform: translate(-50%, -50%);
  padding: 22px;
  border-radius: 16px;
  background: rgba(255,255,255,.97);
  box-shadow: var(--shadow);
}
.error-panel h1 { margin: 0 0 8px; font-size: 18px; }
.error-panel p { margin: 0 0 16px; color: #475569; line-height: 1.45; }
.error-panel code { padding: 2px 5px; border-radius: 5px; background: #eef2f7; }
.text-btn { padding: 9px 13px; border-radius: 9px; background: #111827; color: #fff; font-weight: 650; }

.search-panel {
  position: absolute;
  z-index: 60;
  top: calc(var(--safe-top) + 70px);
  right: calc(var(--safe-right) + 10px);
  width: min(430px, calc(100vw - 20px - var(--safe-left) - var(--safe-right)));
  max-height: min(72vh, 620px);
  overflow: hidden;
  border: 1px solid rgba(15,23,42,.1);
  border-radius: 16px;
  background: var(--glass-2);
  box-shadow: 0 20px 60px rgba(15,23,42,.2);
  backdrop-filter: blur(16px) saturate(130%);
  -webkit-backdrop-filter: blur(16px) saturate(130%);
}
.search-panel[hidden] { display: none; }
.search-head { display: flex; align-items: center; gap: 8px; padding: 10px; border-bottom: 1px solid rgba(15,23,42,.08); }
.search-box {
  flex: 1;
  min-width: 0;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border-radius: 10px;
  background: #f1f5f9;
}
.search-box svg { flex: 0 0 auto; width: 19px; height: 19px; color: #64748b; }
.search-box input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: #111827; }
.search-box input::-webkit-search-cancel-button { display: none; }
.mini-btn { width: 27px; height: 27px; border-radius: 7px; background: transparent; color: #64748b; font-size: 21px; line-height: 1; }
.mini-btn:hover { background: rgba(15,23,42,.08); }
.icon-btn--panel { flex: 0 0 auto; color: #334155; background: #eef2f7; font-size: 24px; }
.icon-btn--panel:hover { background: #e2e8f0; }
.search-status { padding: 8px 12px; color: #64748b; font-size: 12px; border-bottom: 1px solid rgba(15,23,42,.06); }
.search-results { max-height: calc(min(72vh, 620px) - 105px); overflow: auto; overscroll-behavior: contain; }
.search-result {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  padding: 11px 12px;
  border: 0;
  border-bottom: 1px solid rgba(15,23,42,.06);
  background: transparent;
  color: #111827;
  text-align: left;
  cursor: pointer;
}
.search-result:hover { background: rgba(15,23,42,.045); }
.search-result-page {
  min-width: 44px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e2e8f0;
  color: #334155;
  font-size: 12px;
  font-weight: 750;
}
.search-result-copy { min-width: 0; }
.search-result-count { margin-bottom: 3px; color: #0f766e; font-size: 11px; font-weight: 750; }
.search-result-snippet { color: #475569; font-size: 12px; line-height: 1.35; }
.search-empty { padding: 26px 14px; color: #64748b; text-align: center; font-size: 13px; }

.thumb-drawer {
  position: absolute;
  z-index: 55;
  left: calc(8px + var(--safe-left));
  right: calc(8px + var(--safe-right));
  bottom: calc(8px + var(--safe-bottom));
  height: min(190px, 28vh);
  padding: 19px 8px 8px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 16px;
  background: rgba(17,24,39,.86);
  box-shadow: 0 16px 50px rgba(15,23,42,.25);
  backdrop-filter: blur(15px) saturate(120%);
  -webkit-backdrop-filter: blur(15px) saturate(120%);
  transform: translateY(calc(100% + 24px));
  opacity: 0;
  pointer-events: none;
  transition: transform .22s ease, opacity .2s ease;
}
.app.thumbs-open .thumb-drawer { transform: translateY(0); opacity: 1; pointer-events: auto; }
.drawer-handle {
  position: absolute;
  top: 4px;
  left: 50%;
  width: 54px;
  height: 15px;
  transform: translateX(-50%);
  border-radius: 99px;
  background: transparent;
}
.drawer-handle span { display: block; width: 30px; height: 3px; margin: 3px auto 0; border-radius: 99px; background: rgba(255,255,255,.52); }
.thumb-strip {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 4px 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.28) transparent;
  overscroll-behavior-inline: contain;
}
.thumb-card {
  position: relative;
  flex: 0 0 auto;
  width: 100px;
  height: calc(100% - 6px);
  display: grid;
  grid-template-rows: 1fr 20px;
  place-items: center;
  gap: 3px;
  padding: 5px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: rgba(255,255,255,.05);
  color: rgba(255,255,255,.76);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .12s ease;
}
.thumb-card:hover { background: rgba(255,255,255,.1); }
.thumb-card:active { transform: scale(.97); }
.thumb-card.is-active { border-color: rgba(52,211,153,.78); background: rgba(16,185,129,.12); color: #fff; }
.thumb-canvas-wrap {
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  display: grid;
  place-items: center;
  border-radius: 4px;
  overflow: hidden;
  background: rgba(255,255,255,.08);
}
.thumb-canvas { display: block; max-width: 100%; max-height: 100%; background: #fff; }
.thumb-number { font-size: 11px; font-weight: 650; font-variant-numeric: tabular-nums; }

.toast {
  position: absolute;
  z-index: 100;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translate(-50%, 20px);
  max-width: min(90vw, 440px);
  padding: 9px 13px;
  border-radius: 10px;
  background: rgba(17,24,39,.92);
  color: #fff;
  box-shadow: 0 10px 30px rgba(15,23,42,.18);
  opacity: 0;
  pointer-events: none;
  font-size: 13px;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 820px) {
  :root { --toolbar-h: 46px; }
  .topbar {
    top: calc(5px + var(--safe-top));
    left: calc(5px + var(--safe-left));
    right: calc(5px + var(--safe-right));
    min-height: var(--toolbar-h);
    gap: 2px;
    padding: 4px;
    border-radius: 13px;
  }
  .toolbar-group { gap: 1px; }
  .icon-btn { width: 35px; height: 35px; border-radius: 9px; }
  .icon-btn svg { width: 19px; height: 19px; }
  .zoom-value { min-width: 50px; height: 32px; padding: 0 5px; font-size: 12px; }
  .page-counter { height: 32px; gap: 3px; padding: 0 6px; }
  .page-counter input { width: 28px; }
  .edge-nav { width: 34px; height: 62px; color: rgba(17,24,39,.58); background: rgba(255,255,255,.06); }
  .edge-nav svg { width: 23px; height: 23px; }
  .thumb-drawer { left: calc(4px + var(--safe-left)); right: calc(4px + var(--safe-right)); bottom: calc(4px + var(--safe-bottom)); height: min(170px, 27vh); border-radius: 14px; }
  .thumb-card { width: 84px; }
  .search-panel { top: calc(var(--safe-top) + 57px); right: calc(var(--safe-right) + 5px); width: calc(100vw - 10px - var(--safe-left) - var(--safe-right)); max-height: 68vh; }
  .search-results { max-height: calc(68vh - 105px); }
}

@media (max-width: 590px) {
  .topbar { grid-template-columns: 1fr auto; }
  .toolbar-group--center { display: none; }
  .toolbar-group--right { justify-self: end; }
  .optional-mobile { display: none; }
  .page-counter { padding-inline: 5px; }
  .page-counter input { width: 24px; }
}

@media (max-width: 390px) {
  .topbar { left: calc(3px + var(--safe-left)); right: calc(3px + var(--safe-right)); }
  .icon-btn { width: 33px; }
  .page-counter { font-size: 12px; }
}

@media (hover: none) and (pointer: coarse) {
  .edge-nav { opacity: .55; }
  .app.controls-hidden .topbar { opacity: 0; transform: translateY(-8px); pointer-events: none; }
  .app.controls-hidden .edge-nav { opacity: .14; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
