/* ═══════════════════════════════════════════════════════════════════
   IN-APP FILE VIEWER — css/file-viewer.css
   Styles for js/features/file-viewer.js. See that file's header for
   why the viewer exists (the iOS standalone PDF trap).

   TOKENS ONLY, and only from the --bg / --surface / --border / --muted
   / --text family, which body.dark-mode flips. Do NOT reach for the
   --color-* Clinical Clarity palette here: it is not flipped in dark
   mode (same rule as css/skeletons.css).
   ═══════════════════════════════════════════════════════════════════ */

.fv-overlay {
  display: none;
  position: fixed;
  inset: 0;
  /* Above every modal (max 9999) and below the terms gate (12000) —
     a clickwrap that has taken the screen must stay on top. */
  z-index: 11000;
  background: var(--bg);
  flex-direction: column;
}
.fv-overlay.open { display: flex; }

/* ── TOP BAR ────────────────────────────────────────────────────────
   Fixed height, never scrolls away: the whole bug was a document with
   no way out, so Close is always on screen. */
.fv-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  /* iPhone notch / Dynamic Island. In a home-screen app there is no
     browser chrome above us, so without this the Close button sits
     under the status bar and cannot be tapped. */
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  padding-left: calc(12px + env(safe-area-inset-left, 0px));
  padding-right: calc(12px + env(safe-area-inset-right, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
}

.fv-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  /* 44px is Apple's minimum touch target; this control is the escape
     hatch, so it does not get to be fiddly. */
  min-height: 44px;
  padding: 10px 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.fv-btn:hover { background: var(--border); }
.fv-btn:focus-visible { outline: 2px solid var(--color-tertiary); outline-offset: 2px; }

/* Close is visually first and strongest — top-left, per the report. */
.fv-close {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
  font-weight: 700;
  padding-left: 16px;
  padding-right: 16px;
}
.fv-close:hover { opacity: .88; background: var(--text); }
.fv-close .lucide { width: 18px; height: 18px; }

.fv-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.fv-actions { flex: 0 0 auto; display: flex; gap: 6px; }

/* ── BODY ─────────────────────────────────────────────────────────── */
.fv-body {
  flex: 1 1 auto;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
}

.fv-status {
  display: none;
  margin: 24px auto;
  max-width: 520px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.fv-pages, .fv-inline-pages {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* A page is a padding-top aspect box until its canvas replaces it, so
   the scrollbar is the right length before anything has rendered. */
.fv-page {
  position: relative;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.fv-canvas {
  display: block;
  width: 100%;
  height: auto;
}
.fv-page-fail {
  padding: 24px 16px;
  font-size: 13px;
  text-align: center;
  color: var(--muted);
}

.fv-img {
  display: block;
  max-width: 100%;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

/* Generated HTML documents (invoices, reports, print layouts) are
   authored for white paper, so the frame stays white in dark mode. */
.fv-frame {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 70vh;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
}

/* The Title 22 page hosts the same renderer inline. */
.fv-inline-pages { max-width: 100%; }

@media (max-width: 600px) {
  .fv-bar { gap: 6px; padding-left: calc(8px + env(safe-area-inset-left, 0px)); }
  .fv-btn { font-size: 13px; padding: 10px 11px; }
  /* The title is the first thing to go when space is tight — the
     buttons are not negotiable. */
  .fv-title { display: none; }
  .fv-body { padding: 8px; }
  .fv-pages { gap: 8px; }
}

/* Nothing here should ever reach paper: printing happens inside the
   frame or through the share sheet, never by printing the overlay. */
@media print {
  .fv-overlay { display: none !important; }
}
