/* ══ File preview shell (frontend/js/file-preview/file-preview.js) ═══════════
 * Chrome uses the app's tokens; DOCUMENT content (sheets, pages, slides) is
 * drawn on light "paper" in every theme — a workbook's fills and a deck's
 * colours were chosen for white, and a preview must show them as they are.
 * Each viewer's own rules live beside this file (spreadsheet.css, pdf.css …)
 * and load with the viewer. */

.fp-shell {
  --fp-paper: #ffffff;
  --fp-paper-ink: #1f2328;
  --fp-canvas: color-mix(in srgb, var(--surface) 82%, var(--card));
  --fp-line: color-mix(in srgb, var(--surface-b) 85%, transparent);
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--card);
  color: var(--text);
  outline: none;
}
.fp-shell[hidden] { display: none; }
html.light .fp-shell { --fp-canvas: color-mix(in srgb, var(--surface) 70%, #e9edf2); }

/* ── Header: type tile, name, size; Download / Full screen ─────────────── */
.fp-head {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 12px;
  border-bottom: 1px solid var(--fp-line);
}
.fp-shell { --file-accent: var(--file-generic); }
.fp-shell[data-kind="excel"] { --file-accent: var(--file-xlsx); }
.fp-shell[data-kind="pdf"] { --file-accent: var(--file-pdf); }
.fp-shell[data-kind="pptx"] { --file-accent: var(--file-pptx); }
.fp-shell[data-kind="docx"] { --file-accent: var(--file-docx); }
.fp-shell[data-kind="image"] { --file-accent: var(--accent); }
.fp-ext {
  min-width: 38px;
  height: 38px;
  padding: 0 4px;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  border-radius: 9px;
  font: 700 10px/1 var(--font-mono);
  color: var(--file-accent);
  background: color-mix(in srgb, var(--file-accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--file-accent) 28%, transparent);
}
.fp-meta { min-width: 0; }
.fp-name {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fp-sub {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fp-actions { display: flex; align-items: center; gap: 2px; }

.fp-btn {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.fp-btn[hidden] { display: none; }
.fp-btn svg { width: 17px; height: 17px; }
.fp-btn-sm { width: 28px; height: 28px; }
.fp-btn-sm svg { width: 15px; height: 15px; }
.fp-btn:hover:not(:disabled) { color: var(--text); background: var(--btn-hover); border-color: var(--btn-b); }
.fp-btn:focus-visible,
.fp-zoom-label:focus-visible,
.fp-page-input:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.fp-btn:disabled { opacity: 0.38; cursor: default; }
.fp-btn.is-busy { cursor: progress; opacity: 0.6; }

/* ── Controls: the viewer's own navigation + zoom ──────────────────────── */
.fp-controls {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 10px;
  min-height: 40px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--fp-line);
  background: color-mix(in srgb, var(--surface) 45%, var(--card));
}
.fp-controls[hidden] { display: none; }
.fp-slot {
  min-width: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
}
.fp-zoom { display: inline-flex; align-items: center; gap: 1px; margin-inline-start: auto; }
.fp-zoom[hidden] { display: none; }
.fp-zoom-label {
  min-width: 52px;
  height: 28px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font: 600 12px/1 var(--font-sans, inherit);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.fp-zoom-label:hover { background: var(--btn-hover); border-color: var(--btn-b); }

.fp-nav { display: inline-flex; align-items: center; gap: 2px; }
.fp-page-input {
  height: 26px;
  min-width: 3ch;
  padding: 0 4px;
  box-sizing: content-box;
  border: 1px solid var(--btn-b);
  border-radius: 6px;
  background: var(--card);
  color: var(--text);
  text-align: center;
  font: 600 12px/1 var(--font-sans, inherit);
  font-variant-numeric: tabular-nums;
}
.fp-page-total {
  padding-inline: 4px 2px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* Chevrons point in reading order. */
[dir="rtl"] .fp-nav-prev svg,
[dir="rtl"] .fp-nav-next svg { transform: scaleX(-1); }

/* A text button in the controls row (Notes, Formatted/Source …). */
.fp-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 9px;
  border-radius: 7px;
  border: 1px solid var(--btn-b);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.fp-chip svg { width: 14px; height: 14px; }
.fp-chip:hover { color: var(--text); background: var(--btn-hover); }
.fp-chip[aria-pressed="true"] {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}
.fp-chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.fp-note { font-size: 11.5px; color: var(--muted); }

/* ── Body: the viewer's stage, and the loading / error / unsupported state ── */
.fp-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--fp-canvas);
}
.fp-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.fp-shell.is-state .fp-stage { visibility: hidden; }
.fp-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px 24px;
  text-align: center;
  color: var(--muted);
  background: var(--card);
}
.fp-state[hidden] { display: none; }
.fp-state-ico svg { width: 30px; height: 30px; opacity: 0.6; }
.fp-state[data-state="error"] .fp-state-ico { color: var(--danger); }
.fp-state-title { margin: 4px 0 0; font-size: 14px; font-weight: 600; color: var(--text); }
.fp-state-text { margin: 0; max-width: 42ch; font-size: 12.5px; line-height: 1.55; }
.fp-state-text[hidden] { display: none; }
.fp-state-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 10px; }
.fp-state-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--btn-b);
  background: transparent;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.fp-state-btn svg { width: 15px; height: 15px; }
.fp-state-btn:hover { background: var(--btn-hover); }
.fp-state-btn.is-primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink, #fff);
}
.fp-state-btn.is-primary:hover { filter: brightness(1.06); }
.fp-state-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.fp-spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, var(--muted) 30%, transparent);
  border-top-color: var(--accent);
  animation: fp-spin 0.8s linear infinite;
}
@keyframes fp-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .fp-spinner { animation-duration: 2.4s; } }

/* ── Footer (sheet tabs) ─────────────────────────────────────────────────── */
.fp-footer {
  flex-shrink: 0;
  min-height: 34px;
  border-top: 1px solid var(--fp-line);
  background: color-mix(in srgb, var(--surface) 45%, var(--card));
}
.fp-footer[hidden] { display: none; }

.fp-flash {
  position: absolute;
  inset-inline: 12px;
  bottom: 12px;
  z-index: 5;
  padding: 9px 12px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--danger) 14%, var(--card));
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--text);
  font-size: 12.5px;
  box-shadow: var(--shadow-lg);
}
.fp-flash[hidden] { display: none; }

/* ── Full window ─────────────────────────────────────────────────────────── */
.fp-overlay {
  position: fixed;
  inset: 0;
  /* Above the top bar (220) and the dock: this IS the page while it is open. */
  z-index: 300;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  padding: 16px;
  box-sizing: border-box;
  transition: opacity 140ms ease-out;
}
.fp-overlay[hidden] { display: none; }
.fp-overlay.is-entering { opacity: 0; }
html.light .fp-overlay { background: rgba(15, 23, 42, 0.38); }
.fp-overlay > .fp-shell {
  position: relative;
  inset: auto;
  flex: 1 1 auto;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--card-b);
  box-shadow: var(--shadow-lg);
}
html.fp-overlay-open,
html.fp-overlay-open body { overflow: hidden; }
@media (max-width: 767px) {
  .fp-overlay { padding: 0; }
  .fp-overlay > .fp-shell { border-radius: 0; border: 0; }
}
@media (prefers-reduced-motion: reduce) { .fp-overlay { transition: none; } }

/* Narrow dock: keep the header to one tight row. */
@container (max-width: 380px) {
  .fp-head { gap: 8px; padding-inline: 10px 6px; }
  .fp-ext { min-width: 32px; height: 32px; }
}

/* ── Entry points elsewhere: card Preview button, previewable chips ────── */
.msg-file-chip.is-previewable { cursor: pointer; }

/* Files tab: a previewable file's name opens it. */
.files-name.files-name-btn {
  max-width: 100%;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-align: start;
  cursor: pointer;
}
.files-name.files-name-btn:hover { text-decoration: underline; }
.files-name.files-name-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 4px; }
.msg-file-chip.is-previewable:hover { text-decoration: underline; }

/* A Latin file name on an Arabic page keeps its own direction (dir=auto) but
   lines up with the page, like the line under it. */
.fp-name, .fp-sub { text-align: left; }
[dir="rtl"] .fp-name, [dir="rtl"] .fp-sub { text-align: right; }

/* A page's own container for the viewer (FilePreview.open(ref, {container})),
   e.g. the knowledge-base document dialog's "Original" tab. */
.fp-inline-host {
  position: relative;
  height: min(68vh, 640px);
  min-height: 320px;
  border: 1px solid var(--card-b);
  border-radius: 10px;
  overflow: hidden;
}
