/* Page preview and report viewer (js/core/ui/pdf-preview.js).
   Uses the design tokens when the design system is loaded and plain fallbacks when it is not.
   The paper itself is always white with black ink: it shows what the PDF will look like. */

/* ---------------------------------------------------------------- viewer shell */

.pdfv-viewer {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  color: var(--text, #15171c);
  background: var(--surface, #fff);
  border: 1px solid var(--border, #d9dde3);
  border-radius: 10px;
  overflow: hidden;
}

/* ---------------------------------------------------------------- toolbar */

.pdfv-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 8px 12px;
  background: var(--surface, #fff);
  border-bottom: 1px solid var(--border, #d9dde3);
  font-size: 13px;
  line-height: 1.2;
}

.pdfv-spacer { flex: 1 1 auto; }

.pdfv-zoom {
  display: inline-flex;
  border: 1px solid var(--border, #d9dde3);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface, #fff);
}

.pdfv-zoom .pdfv-btn {
  border: 0;
  border-radius: 0;
  border-left: 1px solid var(--border, #d9dde3);
}

.pdfv-zoom .pdfv-btn:first-child { border-left: 0; }

.pdfv-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 11px;
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text, #15171c);
  background: var(--surface, #fff);
  border: 1px solid var(--border, #d9dde3);
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.pdfv-btn:hover { background: var(--surface-2, #f1f3f6); }

.pdfv-btn:focus-visible {
  outline: 2px solid var(--accent, #2f6bff);
  outline-offset: -2px;
  position: relative;
  z-index: 1;
}

.pdfv-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.pdfv-btn.is-active {
  color: var(--accent-ink, var(--accent, #2f6bff));
  background: var(--surface-2, #f1f3f6);
  box-shadow: inset 0 -2px 0 var(--accent, #2f6bff);
}

.pdfv-btn-primary {
  color: var(--on-candy, #fff);
  font-weight: 700;
  background: var(--accent, #2f6bff);
  border-color: var(--accent, #2f6bff);
}

.pdfv-btn-primary:hover { background: var(--accent, #2f6bff); filter: brightness(1.08); }
.pdfv-btn-primary:disabled { filter: none; }
.pdfv-btn-primary:focus-visible { outline-offset: 2px; }

.pdfv-icon { flex: none; display: block; }

.pdfv-count,
.pdfv-updating {
  color: var(--text-muted, #5b6472);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pdfv-updating {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pdfv-message {
  min-width: 0;
  max-width: 46ch;
  font-size: 12.5px;
  line-height: 1.3;
}

.pdfv-message-error { color: #c62b21; }
.pdfv-message-note { color: var(--text-muted, #5b6472); }

/* ---------------------------------------------------------------- pages */

.pdfv {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  scrollbar-gutter: stable;
  padding: 20px;
  background: var(--surface-2, #e9ecf0);
  outline: none;
}

.pdfv:focus-visible { box-shadow: inset 0 0 0 2px var(--accent, #2f6bff); }

.pdfv-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: max-content;
  min-width: 100%;
}

.pdfv-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.pdfv-sheet {
  flex: none;
  background: #fff;
  color: #000;
  border-radius: 1px;
  box-shadow: 0 0 0 1px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.08), 0 8px 24px rgba(16, 24, 40, 0.1);
  overflow: hidden;
  contain: strict;
}

.pdfv-svg {
  display: block;
  width: 100%;
  height: 100%;
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
  user-select: text;
}

.pdfv-svg text { white-space: pre; }

.pdfv-caption {
  font-size: 11.5px;
  line-height: 1.2;
  color: var(--text-muted, #5b6472);
  font-variant-numeric: tabular-nums;
  user-select: none;
}

/* ---------------------------------------------------------------- loading, empty and error states */

.pdfv-solo {
  display: flex;
  min-height: 220px;
}

.pdfv-state {
  margin: auto;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 44ch;
  text-align: center;
  color: var(--text-muted, #5b6472);
}

.pdfv-state-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text, #15171c);
}

.pdfv-state-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.pdfv-spinner {
  flex: none;
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: pdfv-spin 0.7s linear infinite;
}

.pdfv-spinner-lg {
  width: 26px;
  height: 26px;
  border-width: 3px;
  color: var(--accent, #2f6bff);
}

@keyframes pdfv-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .pdfv-spinner { animation-duration: 2.4s; }
  .pdfv-btn { transition: none; }
}

@media (max-width: 560px) {
  .pdfv { padding: 12px; }
  .pdfv-toolbar { padding: 8px; }
  .pdfv-message { max-width: 100%; flex-basis: 100%; order: 5; }
}
