/* Document viewer (pages/document.js): the cited pages, rendered in-app. */

.doc-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
}

/* A panel, like the figure lightbox, not a takeover: the citation sheet stays
   visible behind it, so following a source does not cost the reader their
   place in the answer. */
.doc-root {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(94vw, 1040px);
  max-height: min(92vh, 1100px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sheet);
  overflow: hidden;
}

@media (max-width: 720px) {
  .doc-root {
    width: 100vw;
    max-height: 94vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    top: auto;
    bottom: 0;
    left: 0;
    transform: none;
  }
}

.doc-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.doc-done {
  min-width: 52px;
  text-align: left;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}
.doc-done:hover { opacity: .75; }

.doc-done-spacer { min-width: 52px; flex: 0 0 auto; }

.doc-header-center { flex: 1; min-width: 0; text-align: center; }
.doc-title {
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-subtitle { color: var(--text-faint); font-size: 13px; margin-top: 1px; }

/* The scrolling stage. Mid-grey rather than the surface colour, for the reason
   the figure stage is: a white page on a white panel has no edge, and the page
   looks like it bleeds into the chrome. */
.doc-body {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  background: var(--surface-alt);
  padding: var(--space-md);
  box-sizing: border-box;
}

/* One page. Positioned, because the page number sits over its top corner. */
.doc-page {
  position: relative;
  margin: 0 auto var(--space-md);
  width: min(980px, 100%);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  /* A page is drawn on paper. Its own white stays white in dark mode rather
     than inverting, which would make a page image look like a negative. */
  color-scheme: only light;
  /* Holds the page's shape before the image decodes, so the column does not
     jump as each page arrives. A4 is the corpus's common case; a page of
     another shape corrects itself on load. */
  min-height: 120px;
}
.doc-page:last-child { margin-bottom: 0; }

/* Rendered at 2x server-side and displayed at CSS width: sharp on a 2x
   display without the viewer having to know the device ratio. */
.doc-img { display: block; width: 100%; height: auto; }

.doc-placeholder {
  padding: var(--space-xl);
  text-align: center;
  color: var(--text-faint);
  font-size: 14px;
}

/* Which of the served pages the citation actually points at. The window
   carries a page either side for context, and without this the reader cannot
   tell which one the excerpt came from. */
.doc-page-label {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  z-index: 2;
  padding: 2px var(--space-sm);
  border-radius: var(--radius-pill);
  background: var(--overlay);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
}
.doc-page-label.cited {
  background: var(--accent-solid);
  color: var(--accent-text);
}

.doc-note {
  flex: 0 0 auto;
  padding: var(--space-sm) var(--space-lg);
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 13px;
  text-align: center;
}

.doc-missing {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-xl);
  text-align: center;
}
.doc-missing-text { color: var(--text); font-size: 16px; font-weight: 600; }
.doc-missing-hint {
  color: var(--text-faint);
  font-size: 14px;
  line-height: 1.4;
  max-width: 42ch;
}

.doc-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl);
  color: var(--text-faint);
  font-size: 14px;
}
