/* ==============================================================================
   Leaf viewer chrome
   Every rule is scoped to .leaf-viewer-root so the viewer never restyles the
   admin console (buttons, headers, dialogs) when both are loaded in one SPA.
   ============================================================================== */

.leaf-viewer-root {
  --lv-ink: var(--color-paper-900, #18211e);
  --lv-graphite: var(--color-paper-600, #5a625d);
  --lv-rule: rgba(24, 33, 30, 0.14);
  --lv-glass: rgba(255, 255, 255, 0.86);
  --lv-accent: var(--color-accent-base, #2e5b4f);

  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #ffffff;
  color: var(--lv-ink);
  font-family: var(--font-sans-ui, system-ui, sans-serif);
  -webkit-font-smoothing: antialiased;
}

.leaf-viewer-root.is-rotating {
  cursor: grab;
}

.leaf-viewer-root .lv-stage {
  position: absolute;
  inset: 0;
  touch-action: none;
}

.leaf-viewer-root .lv-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- Shared button ---------- */
.leaf-viewer-root .lv-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px;
  font: 500 13px/1 var(--font-sans-ui, system-ui, sans-serif);
  color: var(--lv-ink);
  background: var(--lv-glass);
  border: 1px solid var(--lv-rule);
  border-radius: 8px;
  cursor: pointer;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.leaf-viewer-root .lv-btn svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.leaf-viewer-root .lv-btn:hover:not(:disabled) {
  border-color: rgba(24, 33, 30, 0.32);
}

.leaf-viewer-root .lv-btn[aria-pressed='true'] {
  background: var(--lv-ink);
  border-color: var(--lv-ink);
  color: #ffffff;
}

.leaf-viewer-root .lv-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.leaf-viewer-root .lv-btn:focus-visible,
.leaf-viewer-root .lv-icon-btn:focus-visible {
  outline: 2px solid var(--lv-accent);
  outline-offset: 2px;
}

.leaf-viewer-root .lv-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--lv-ink);
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

.leaf-viewer-root .lv-icon-btn:hover:not(:disabled) {
  background: rgba(24, 33, 30, 0.07);
}

.leaf-viewer-root .lv-icon-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.leaf-viewer-root .lv-icon-btn svg {
  width: 18px;
  height: 18px;
}

/* ---------- Top bar ---------- */
.leaf-viewer-root .lv-topbar {
  position: absolute;
  top: 20px;
  left: 24px;
  right: 24px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.leaf-viewer-root .lv-topbar > * {
  pointer-events: auto;
}

.leaf-viewer-root .lv-title {
  min-width: 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.leaf-viewer-root .lv-tools {
  display: flex;
  gap: 8px;
  flex: none;
}

/* ---------- Bottom navigation ---------- */
.leaf-viewer-root .lv-bottom {
  position: absolute;
  bottom: 24px;
  left: 50%;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
}

.leaf-viewer-root .lv-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--lv-glass);
  border: 1px solid var(--lv-rule);
  border-radius: 999px;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.leaf-viewer-root .lv-position {
  min-width: 132px;
  padding: 0 6px;
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.leaf-viewer-root .lv-close-book {
  height: 48px;
  border-radius: 999px;
  white-space: nowrap;
}

.leaf-viewer-root .lv-close-book[hidden] {
  display: none;
}

/* ---------- Rotate hint ---------- */
.leaf-viewer-root .lv-hint {
  position: absolute;
  top: 74px;
  left: 50%;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 6px 14px;
  font-size: 12px;
  color: #ffffff;
  background: rgba(24, 33, 30, 0.86);
  border-radius: 999px;
  transform: translateX(-50%);
  animation: lv-hint-in 240ms ease;
}

.leaf-viewer-root .lv-hint button {
  height: 26px;
  padding: 0 10px;
  font: inherit;
  font-weight: 500;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.14);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

@keyframes lv-hint-in {
  from { opacity: 0; transform: translate(-50%, -4px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Loading ---------- */
.leaf-viewer-root .lv-loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  font-size: 14px;
  color: var(--lv-graphite);
  background: #ffffff;
}

/* ---------- Inspect dialog ---------- */
.lv-inspect {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  color: var(--color-paper-900, #18211e);
  background: #f2f3f0;
  font-family: var(--font-sans-ui, system-ui, sans-serif);
}

.lv-inspect[open] {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.lv-inspect::backdrop {
  background: #f2f3f0;
}

.lv-inspect-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
}

.lv-inspect-label {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.lv-inspect-actions {
  display: flex;
  gap: 8px;
}

.lv-inspect-canvas {
  position: relative;
  overflow: auto;
  overscroll-behavior: contain;
}

.lv-inspect-spread {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 100%;
  min-height: 100%;
  padding: 8px 24px 16px;
  box-sizing: border-box;
  cursor: zoom-in;
}

.lv-inspect-spread.is-zoomed {
  width: max-content;
  height: max-content;
  cursor: zoom-out;
}

.lv-inspect-sheet {
  display: flex;
  box-shadow: 0 18px 40px rgba(24, 33, 30, 0.16), 0 2px 6px rgba(24, 33, 30, 0.08);
}

/* A two-page spread gets a soft gutter shadow where the pages meet */
.lv-inspect-sheet.is-spread {
  position: relative;
}

.lv-inspect-sheet.is-spread::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 48px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.1) 45%, rgba(0, 0, 0, 0.16) 50%, rgba(0, 0, 0, 0.1) 55%, transparent);
  pointer-events: none;
}

.lv-inspect-sheet img {
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  /* Fit mode: the whole view fits the window */
  max-height: calc(100dvh - 150px);
  max-width: calc(100vw - 48px);
  width: auto;
  height: auto;
}

.lv-inspect-sheet.is-spread img {
  max-width: calc((100vw - 48px) / 2);
}

.lv-inspect-spread.is-zoomed .lv-inspect-sheet img {
  max-height: none;
  max-width: none;
}

.lv-inspect-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 20px 18px;
}

.lv-inspect-foot .lv-position {
  min-width: 132px;
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.lv-inspect .lv-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px;
  font: 500 13px/1 var(--font-sans-ui, system-ui, sans-serif);
  color: var(--color-paper-900, #18211e);
  background: #ffffff;
  border: 1px solid rgba(24, 33, 30, 0.14);
  border-radius: 8px;
  cursor: pointer;
}

.lv-inspect .lv-btn:hover {
  border-color: rgba(24, 33, 30, 0.32);
}

.lv-inspect .lv-btn svg {
  width: 16px;
  height: 16px;
}

.lv-inspect .lv-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

.lv-inspect .lv-icon-btn:hover:not(:disabled) {
  background: rgba(24, 33, 30, 0.07);
}

.lv-inspect .lv-icon-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.lv-inspect .lv-icon-btn svg {
  width: 18px;
  height: 18px;
}

.lv-inspect .lv-btn:focus-visible,
.lv-inspect .lv-icon-btn:focus-visible {
  outline: 2px solid var(--color-accent-base, #2e5b4f);
  outline-offset: 2px;
}

/* ---------- Small screens ---------- */
@media (max-width: 680px) {
  .leaf-viewer-root .lv-topbar {
    top: 12px;
    left: 12px;
    right: 12px;
  }

  .leaf-viewer-root .lv-tools .lv-btn {
    width: 38px;
    padding: 0;
    justify-content: center;
  }

  .leaf-viewer-root .lv-btn-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .leaf-viewer-root .lv-bottom {
    bottom: 16px;
  }

  .leaf-viewer-root .lv-position {
    min-width: 112px;
  }

  .lv-inspect-bar {
    padding: 10px 12px;
  }

  .lv-inspect-spread {
    padding: 8px 12px 12px;
  }

  .lv-inspect-sheet img {
    max-width: calc(100vw - 24px);
  }

  .lv-inspect-sheet.is-spread img {
    max-width: calc((100vw - 24px) / 2);
  }
}
