/* Access Portal structure. Brand tokens (colors, --font, --radius,
   --wordmark-spacing) are injected by /brand.css from config.json's `brand`
   block; the values below are fallbacks used only if that file is missing. */

:root {
  --bg: #ffffff;
  --fg: #000000;
  --accent: #ff0060;
  --mark: #ffff00;
  --muted: #666666;
  --line: #000000;
  --font: ui-monospace, 'SF Mono', 'Menlo', 'Consolas', 'DejaVu Sans Mono', monospace;
  --radius: 0px;
  --wordmark-spacing: 0.22em;

  /* Derived from the brand palette so a partial brand still themes cleanly. */
  --field-bg: var(--bg);
  --line-soft: rgba(128,128,128,0.28);
  --line-soft: color-mix(in srgb, var(--line) 22%, transparent);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --fg: #ffffff;
    --accent: #00ff9f;
    --mark: #ffff00;
    --muted: #9a9a9a;
    --line: #ffffff;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: break-word;
}
::selection { background: var(--mark); color: #000; }
.hidden { display: none !important; }

.brand-mark { font-weight: 700; letter-spacing: var(--wordmark-spacing); font-size: 15px; color: var(--fg); }
.brand-mark .rune { color: var(--accent); margin-right: 0.5em; }
.brand-mark .rune svg { height: 1.15em; width: auto; vertical-align: -0.22em; fill: currentColor; }
.brand-mark.sm { font-size: 13px; }

/* slash divider motif (proximum.xyz) */
.rule { color: var(--muted); letter-spacing: 0.1em; margin: 10px 0; user-select: none; }
.rule::before { content: "/////////////////////"; }

/* ── Buttons ── */
.btn {
  font-family: inherit; font-weight: 600; font-size: 13px;
  letter-spacing: 0.08em; text-transform: uppercase;
  border-radius: var(--radius); padding: 11px 18px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg);
  transition: background .12s ease, color .12s ease; width: 100%; margin-top: 12px;
}
.btn.sm { width: auto; padding: 7px 13px; font-size: 12px; margin: 0; }
/* Compact inline buttons (pager, admin actions) — not the full-width form bars. */
.btn.tiny { width: auto; padding: 6px 14px; font-size: 12px; margin: 0; }
.btn-primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.btn-primary:hover { background: var(--bg); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; text-transform: none; letter-spacing: 0; }
.btn-ghost:hover { color: var(--accent); }

/* ── Fields ── */
.field {
  width: 100%; font-family: inherit; font-size: 15px;
  padding: 11px 13px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--field-bg); color: var(--fg); outline: none;
}
.field::placeholder { color: var(--muted); }
.field:focus { border-color: var(--accent); }
.field-label {
  display: block; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.12em; color: var(--muted); margin: 16px 0 6px;
}
.code-field { letter-spacing: 0.5em; text-align: center; font-size: 22px; }
/* Placeholder is a plain hint, not spaced-out digits (only typed input is big). */
.code-field::placeholder { letter-spacing: normal; font-size: 14px; }

/* ── Gate ── */
.gate {
  min-height: 100%; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg);
}
.gate-card {
  width: 100%; max-width: 400px; padding: 34px 30px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
}
.gate-title { font-size: 22px; font-weight: 700; margin: 6px 0 4px; letter-spacing: 0.02em; }
.gate-sub { color: var(--muted); margin: 0; font-size: 13px; }
.gate-msg { min-height: 18px; margin: 14px 0 0; font-size: 13px; color: var(--accent); }
.gate-msg.err { color: var(--accent); font-weight: 700; }
.gate-foot { margin-top: 22px; font-size: 11px; color: var(--muted); }

/* ── Topbar ── */
.portal { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 20px; height: 54px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 14px; min-width: 0; }
.topbar-left { flex: 1; }
.divider-v { color: var(--muted); flex-shrink: 0; }
.divider-v::before { content: "/"; }
.brand-mark.sm { flex-shrink: 0; white-space: nowrap; }
.space-name { font-size: 14px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0; }
/* Open-document breadcrumb: sits inline in the top ribbon on desktop so the viewer
   needs no separate title row. Takes remaining space and ellipsizes if long. */
.doc-crumb { font-size: 14px; font-weight: 400; color: var(--fg); min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who { color: var(--muted); font-size: 13px; max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Layout ── */
.layout { flex: 1; display: grid; grid-template-columns: 250px 1fr; min-height: 0; }
.files-bar, .files-scrim { display: none; } /* narrow screens only (media query below) */
@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
  /* Single column: the stacked file list would bury the auto-opened document, so
     the sidebar becomes a drawer under a sticky Files bar. The bar carries the
     open doc's name; body.files-open (app.js) drops the tree over the viewer. */
  .files-bar {
    display: flex; align-items: center; gap: 8px;
    position: sticky; top: 0; z-index: 55; width: 100%;
    background: var(--bg); color: var(--muted);
    border: none; border-bottom: 1px solid var(--line);
    padding: 10px 14px; cursor: pointer; text-align: left;
  }
  .fb-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em;
    font-weight: 700; flex: none;
  }
  .fb-doc {
    font-size: 13px; color: var(--fg); min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .fb-chev {
    flex: none; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--line); border-radius: var(--radius);
    color: var(--accent); font-size: 12px; line-height: 1; transition: transform .12s;
  }
  body:not(.files-open) .fb-chev { transform: rotate(-90deg); }
  .sidebar { display: none; }
  body.files-open .sidebar {
    display: block; position: fixed;
    top: var(--drawer-top, 90px); left: 0; right: 0; z-index: 60;
    max-height: calc(100dvh - var(--drawer-top, 90px) - 16px); overflow: auto;
    background: var(--bg); border: none; border-bottom: 1px solid var(--line);
  }
  body.files-open .files-scrim {
    display: block; position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.55); z-index: 58; /* drawer 60/scrim 58 sit BELOW the phone chat sheet (70) */
  }
}
/* Phones: shrink the topbar, drop the email + space name, let the doc flow. */
@media (max-width: 640px) {
  .topbar { padding: 0 12px; height: 50px; gap: 8px; }
  .brand-mark.sm { font-size: 11px; letter-spacing: 0.06em; }
  .divider-v, .space-name, .who, .doc-crumb { display: none; }
  .topbar-right { gap: 10px; }
  /* Element-qualified: the base .viewer / .sidebar rules come later in this file
     and would otherwise win on equal specificity. */
  main.viewer { padding: 8px 14px 14px; }
  aside.sidebar { padding: 16px 14px; }
  iframe.viewer-embed { height: 72vh; }
  /* AI chat on phones: a bottom SHEET (not a disorienting full-screen takeover) that
     sits above the on-screen keyboard. --kb (keyboard height) and --vvh (visible height)
     are set from window.visualViewport in app.js; fallbacks keep it sane without JS. */
  .chat-widget { right: 14px; bottom: 14px; }
  .chat-widget:not(.collapsed) {
    /* Sized/positioned from the VISUAL viewport (set by fitChat in app.js) so the
       sheet stays fully on-screen even when iOS has the page zoomed or panned.
       Fallbacks (0 / 100%) apply when JS hasn't run — same as left:0/right:0. */
    left: var(--vvl, 0); right: auto; top: auto;
    width: var(--vvw, 100%);
    bottom: var(--kb, 0);
    height: var(--vvh, 82dvh);
    z-index: 70;
  }
  .chat-widget:not(.collapsed) .chat-panel {
    width: 100%; height: 100%;
    border: 1px solid var(--line); border-bottom: none;
    border-radius: 14px 14px 0 0;
  }
  /* Bigger, obvious dismiss target on touch. */
  .chat-min { font-size: 26px; padding: 2px 10px; }
  /* iOS Safari auto-zooms the whole page when a focused input's font-size is
     under 16px — and stays zoomed, cutting off the right edge. 16px disables
     that zoom entirely (gate fields, chat input, sidebar filter alike). */
  .field, .chat-input .field, .code-field::placeholder { font-size: 16px; }
}

.sidebar { background: var(--bg); border-right: 1px solid var(--line); padding: 18px 14px; }
.sidebar-head, .chat-head, .viewer-head {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--muted); font-weight: 700; margin-bottom: 12px;
}
.file-list { list-style: none; margin: 0; padding: 0; }
.file-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 6px;
  border: 1px solid var(--line-soft); border-radius: var(--radius); cursor: pointer; transition: border-color .12s;
}
.file-item:hover { border-color: var(--accent); }
.file-item.active { border-color: var(--accent); }
.file-name { font-size: 13px; min-width: 0; overflow-wrap: anywhere; }
.file-cat { margin-left: auto; flex: none; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.file-ico { color: var(--accent); font-size: 14px; }

/* Folder tree — Drive-backed spaces mirror their subfolder structure. Children
   nest inside .folder-group, whose inset + guide line accumulate per level, so
   a file's box visibly sits under its folder instead of running full-width. */
.folder-group { list-style: none; margin: 0 0 6px 8px; padding: 0 0 0 8px; border-left: 1px solid var(--line-soft); }
.folder-item:not(.open) > .folder-group { display: none; }
.folder-row {
  display: flex; align-items: center; gap: 7px; padding: 8px 6px 8px 2px; margin-bottom: 4px;
  border-radius: var(--radius); cursor: pointer; user-select: none;
  color: var(--muted); font-weight: 700; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.1em;
}
.folder-row:hover { color: var(--fg); }
.folder-row:hover .folder-chev { border-color: var(--accent); }
.folder-name { line-height: 1.45; min-width: 0; }  /* wraps — never truncate a folder name */
.folder-chev {
  flex: none; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--accent); font-size: 12px; line-height: 1; transition: transform .12s;
}
.folder-item:not(.open) > .folder-row .folder-chev { transform: rotate(-90deg); }
/* Boxes narrow as the tree deepens: tighten the row and step the type label
   down, then drop it entirely (the icon still conveys type) so the filename
   always keeps the room it needs. */
.folder-group .file-item { gap: 7px; }
.folder-group .file-cat { font-size: 9px; letter-spacing: 0.05em; }
.folder-group .folder-group .file-cat { font-size: 8px; }
.folder-group .folder-group .folder-group .file-cat { display: none; }

.note-card {
  margin-top: 14px; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 12px; color: var(--muted);
}
.note-card b { display: block; font-size: 13px; font-weight: 700; color: var(--fg); margin-top: 2px; letter-spacing: 0.02em; }

/* ── Viewer ── */
.viewer { background: var(--bg); padding: 10px 24px 14px; overflow: auto; }
.viewer-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); }
.ve-icon { font-size: 34px; color: var(--accent); margin-bottom: 10px; }
.viewer-head { border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 10px; font-size: 16px; text-transform: none; letter-spacing: 0; font-weight: 700; color: var(--fg); }
/* The open doc's name is already on screen (the top-ribbon breadcrumb on desktop,
   the Files bar on narrow screens), so the separate title row is redundant — hide
   it and hand that vertical space to the pages. */
.viewer-head { display: none; }
.viewer-body { white-space: pre-wrap; font-family: inherit; font-size: 13px; line-height: 1.7; color: var(--fg); background: var(--bg); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 20px; margin: 0; }

/* ── Chat ── */
/* Floating AI chat widget (Intercom-style) */
.chat-widget { position: fixed; right: 20px; bottom: 20px; z-index: 60; }
.chat-launcher {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--accent); color: #000; border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 12px 18px;
  font-family: var(--font-display, monospace); font-weight: 600; font-size: 13px;
  letter-spacing: 0.05em; text-transform: uppercase; box-shadow: 0 8px 28px rgba(0,0,0,0.45);
}
.chat-launcher:hover { filter: brightness(1.08); }
.chat-launcher .cl-dot { font-size: 14px; }
.chat-panel {
  width: 380px; height: min(560px, 78vh); display: flex; flex-direction: column;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0,0,0,0.55); overflow: hidden;
}
.chat-widget.collapsed .chat-panel { display: none; }
.chat-widget:not(.collapsed) .chat-launcher { display: none; }
.chat-head {
  display: flex; flex-direction: row; justify-content: space-between; align-items: flex-start;
  gap: 8px; margin-bottom: 0; padding: 13px 15px; border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.chat-head-title { display: flex; flex-direction: column; gap: 3px; }
.chat-min { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 22px; line-height: 1; padding: 0 4px; }
.chat-min:hover { color: var(--accent); }
.chat-badge { font-size: 10px; text-transform: none; letter-spacing: 0; color: var(--accent); font-weight: 400; }
.chat-log { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 14px 15px; }
.msg { padding: 10px 13px; border-radius: var(--radius); font-size: 13px; max-width: 92%; white-space: pre-wrap; border: 1px solid var(--line-soft); }
.msg-ai { align-self: flex-start; }
.msg-user { border-color: var(--line); align-self: flex-end; }
.msg-src { display: block; margin-top: 6px; font-size: 10px; color: var(--muted); }
/* Rendered Markdown inside AI messages. */
.msg-ai strong { font-weight: 700; }
.msg-ai em { font-style: italic; }
.msg-ai code { font-family: var(--font-display, monospace); font-size: .92em;
  background: color-mix(in srgb, var(--fg) 8%, transparent); padding: 1px 4px; border-radius: 3px; }
.msg-ai .md-h { font-weight: 700; margin: 8px 0 3px; font-family: var(--font-display, var(--font)); }
.msg-ai .md-h:first-child { margin-top: 0; }
.msg-ai ul, .msg-ai ol { margin: 4px 0 4px; padding-left: 18px; }
.msg-ai li { margin: 2px 0; }
.msg-ai br { line-height: 0.5; }
/* Thinking indicator: the Eˣ brand mark with a live, cycling exponent + rotating label. */
.msg-thinking { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.ex-thinking { font-family: var(--font-display, var(--font)); font-weight: 700;
  font-size: 20px; line-height: 1; position: relative; display: inline-flex;
  align-items: flex-start; color: var(--fg); animation: ex-breathe 1.8s ease-in-out infinite; }
.ex-thinking .ex-base { letter-spacing: .5px; }
.ex-thinking .ex-exp { font-size: .62em; color: var(--accent); margin-left: 1px;
  position: relative; top: -.15em; min-width: .7em; text-align: left;
  text-shadow: 0 0 8px color-mix(in srgb, var(--accent) 55%, transparent); }
.ex-thinking .ex-exp.flip { animation: ex-flip .32s ease-out; }
.thinking-label { font-size: 12px; opacity: .85; }
/* Neutral fallback (brands without a thinkingBase glyph): three pulsing dots. */
.thinking-dots { display: inline-flex; gap: 3px; }
.thinking-dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor;
  display: inline-block; opacity: .35; animation: think-bounce 1.2s infinite ease-in-out; }
.thinking-dots i:nth-child(2) { animation-delay: .18s; }
.thinking-dots i:nth-child(3) { animation-delay: .36s; }
@keyframes think-bounce { 0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); } }
@keyframes ex-breathe { 0%, 100% { opacity: .7; } 50% { opacity: 1; } }
@keyframes ex-flip {
  0% { transform: translateY(-3px) scale(.6); opacity: 0; }
  60% { transform: translateY(0) scale(1.12); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .ex-thinking, .ex-thinking .ex-exp.flip, .thinking-dots i { animation: none; }
  .ex-thinking { opacity: .9; } .thinking-dots i { opacity: .6; } }
.chat-input { display: flex; gap: 8px; padding: 10px 15px; border-top: 1px solid var(--line-soft); flex-shrink: 0; }
/* Let the input shrink so the Send button always fits (min-width:0 defeats the
   default flex min-content width that otherwise pushes Send off a narrow screen). */
.chat-input .field { font-size: 14px; flex: 1; min-width: 0; }
.chat-input .btn { flex-shrink: 0; }
.chat-disclaimer { font-size: 9px; line-height: 1.35; color: var(--muted); opacity: .8;
  margin: 0; padding: 6px 15px 10px; flex-shrink: 0; }

/* ══════════════════════════════════════════════════════════════════
   Exponential Capital brand layer (dedicated instance)
   Structural type → Kode Mono (--font-display); body stays Roboto (--font).
   Signature motifs: blueprint dot-grid + a single radial "flare" glow.
   ══════════════════════════════════════════════════════════════════ */

/* Kode Mono on all structural / uppercase elements; body copy stays Roboto. */
.brand-mark, .gate-title, .field-label, .code-field,
.sidebar-head, .chat-head > span:first-child, .viewer-head,
.file-cat, .folder-row, .fb-label, .note-card b, .btn, .space-name, .divider-v, .doc-crumb {
  font-family: var(--font-display, var(--font));
}

/* Faint blueprint dot-grid on the near-black canvas (barely perceptible). */
body {
  background-color: var(--bg);
  background-image: radial-gradient(rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 28px 28px;
}

/* The flare: one radial glow bleeding from a corner. Colors are overridable per
   brand via optional glow1..glow3 palette tokens (see lib/brand.js); the defaults
   are the original amber→orange→red. */
.gate { position: relative; overflow: hidden; }
.gate::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(circle at 90% 88%,
    var(--glow1, rgba(246,159,30,0.20)) 0%, var(--glow2, rgba(239,103,15,0.14)) 26%,
    var(--glow3, rgba(199,50,17,0.09)) 46%, transparent 68%);
}
.gate-card { position: relative; z-index: 1; background: rgba(0,0,0,0.55); backdrop-filter: blur(3px); }

/* Uppercase, tracked structural labels — the "engineered" rhythm. */
.gate-title { text-transform: uppercase; letter-spacing: 0.04em; }

/* Flare-filled primary buttons keep black text on the gradient-adjacent accent. */
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: #000; color: var(--accent); }

/* Replace Proximum's /////-slash divider with a thin white hairline rail. */
.rule::before { content: ""; }
.rule { border-top: 1px solid var(--line); height: 0; margin: 16px 0; }

/* Inline document viewer (PDFs/images render in the room, not a new tab). */
.viewer-content { position: relative; }
.viewer-embed { width: 100%; border: 1px solid var(--line-soft); border-radius: var(--radius); background: #0d0d0d; }
iframe.viewer-embed { height: calc(100vh - 84px); }
img.viewer-embed { height: auto; max-height: calc(100vh - 150px); object-fit: contain; }
video.viewer-embed { height: auto; max-height: calc(100vh - 150px); background: #000; }
audio.viewer-embed { border: none; background: transparent; margin-top: 24px; }

/* Download lockdown (admin toggle off): no selection anywhere in the room. */
body.no-download .viewer, body.no-download .sidebar, body.no-download .viewer-body {
  -webkit-user-select: none; user-select: none;
}

/* Control strip above HTML document embeds (print view, fullscreen). */
.pdf-bar.html-bar { justify-content: flex-end; gap: 8px; }
iframe.viewer-embed.viewer-html { height: calc(100vh - 121px); }
.viewer-content:fullscreen { background: #000; }
.viewer-content:fullscreen iframe.viewer-embed { height: calc(100vh - 37px); border: none; border-radius: 0; }
.viewer-content:-webkit-full-screen { background: #000; }
.viewer-content:-webkit-full-screen iframe.viewer-embed { height: calc(100vh - 37px); border: none; border-radius: 0; }
.viewer-content.pseudo-fs { position: fixed; inset: 0; z-index: 200; background: #000; margin: 0; padding: 0; }
.viewer-content.pseudo-fs iframe.viewer-embed { height: calc(100vh - 37px); height: calc(100dvh - 37px); border: none; border-radius: 0; }
/* While an HTML doc is open, the chat launcher docks bottom-left so it never
   covers controls the document draws in its own bottom-right corner. */
body.html-doc-open .chat-widget { right: auto; left: 20px; }

/* Per-viewer watermark tiled over the open document — deters/traces screenshots. */
.wm-overlay {
  position: absolute; inset: 0; z-index: 2; pointer-events: none; overflow: hidden;
  display: flex; flex-wrap: wrap; align-content: space-around; justify-content: space-around;
  gap: 90px 70px;
  transform: rotate(-24deg) scale(1.25); transform-origin: center;
  /* difference blend keeps the mark legible over both light and dark content */
  mix-blend-mode: difference; opacity: 0.35;
}
.wm-overlay span {
  color: #ffffff; font-family: var(--font-display, monospace);
  font-size: 11px; letter-spacing: 0.04em; white-space: nowrap;
}

/* Locked PDF viewer: pages rendered to canvas (no native plugin, watermark baked in). */
.pdf-host { display: flex; flex-direction: column; height: calc(100vh - 100px); }
/* Everything the pager shows (bar, progress line, stage) sits in one frame, so a
   phone held upright can turn the whole thing a quarter turn (.rotated below). */
.pdf-frame { position: relative; display: flex; flex-direction: column; flex: 1; min-height: 0; }
.pdf-bar {
  position: relative;
  display: flex; align-items: center; justify-content: center; gap: 16px;
  padding: 6px 8px; border-bottom: 1px solid var(--line-soft); flex-shrink: 0;
}
.pdf-ind {
  font-family: var(--font-display, monospace); font-size: 12px;
  color: var(--muted); min-width: 66px; text-align: center;
}
.pdf-stage {
  flex: 1; overflow: auto; display: flex; justify-content: center; align-items: flex-start; padding: 8px 14px;
}
.pdf-page {
  max-width: 100%; height: auto; border: 1px solid var(--line-soft);
  border-radius: var(--radius); box-shadow: 0 1px 2px rgba(0,0,0,0.35);
}
.pdf-loading { color: var(--muted); margin: 24px 0; }
/* Loading indicator: a thin accent bar along the top of the page area (sliding
   while busy, filling when the download size is known) and, until the first page
   shows, a page-shaped placeholder with a spinner and a label. */
.doc-progress { position: relative; height: 2px; flex-shrink: 0; overflow: hidden; }
.doc-progress i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--accent); transition: width .2s ease; }
.pdf-host.loading .doc-progress:not(.known) i { width: 28%; animation: doc-slide 1.1s ease-in-out infinite; }
.doc-progress.known i { animation: none; }
@keyframes doc-slide { from { transform: translateX(-110%); } to { transform: translateX(370%); } }
.doc-loading { width: 100%; display: flex; justify-content: center; padding: 8px 0; }
.doc-loading-page {
  width: min(100%, 960px, calc((100vh - 170px) / var(--doc-aspect, 0.5625)));
  aspect-ratio: 1 / var(--doc-aspect, 0.5625);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  border: 1px solid var(--line-soft); border-radius: var(--radius);
  background: linear-gradient(100deg, transparent 30%, rgba(128,128,128,0.10) 50%, transparent 70%) 0 0 / 300% 100%;
  animation: doc-shimmer 1.6s linear infinite;
}
@keyframes doc-shimmer { from { background-position: 100% 0; } to { background-position: -50% 0; } }
.doc-spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--line-soft); border-top-color: var(--accent);
  animation: doc-spin .8s linear infinite;
}
@keyframes doc-spin { to { transform: rotate(360deg); } }
.doc-loading-label { font-family: var(--font-display, monospace); font-size: 12px; color: var(--muted); letter-spacing: .04em; }
.doc-loading.failed .doc-spinner { display: none; }
.doc-loading.failed .doc-loading-page { animation: none; background: none; }
@media (prefers-reduced-motion: reduce) {
  .doc-loading-page, .doc-spinner { animation: none; }
  .pdf-host.loading .doc-progress:not(.known) i { animation: none; width: 100%; opacity: .5; }
}
.btn.tiny[disabled] { opacity: 0.4; cursor: default; }
/* Full-screen toggle: a labeled text button (inherits .btn.tiny — uppercase,
   like PREV/NEXT) accent-outlined so it clearly reads as an action, pinned right
   of the centered pager. Labeled "Full screen" / "Exit" so the state is obvious. */
.pdf-fs {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  width: auto; margin: 0;
  border-color: var(--accent); color: var(--accent);
}
.pdf-fs:hover { background: var(--accent); color: #000; }
.pdf-fs .lbl { margin-left: 6px; }
/* The stand-in full screen a phone turned into, on a wide bar: ⛶ (the real thing is
   still available) and ✕ are both shown, side by side at the right. */
.pdf-bar.two-fs .pdf-fs:not(.pdf-exit) { right: 90px; }
/* Diagnostics readout (?fsdebug=1): over the page, never turned with the frame. */
.pdf-hud {
  position: absolute; left: 4px; top: 4px; z-index: 6; margin: 0; max-width: calc(100% - 8px);
  padding: 4px 6px; font: 10px/1.35 monospace; color: #7CFC00; background: rgba(0,0,0,.7);
  white-space: pre-wrap; word-break: break-all; pointer-events: none; border-radius: 3px;
}
.pdf-dl {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: auto; margin: 0;
  border-color: var(--accent); color: var(--accent);
}
.pdf-dl:hover { background: var(--accent); color: #000; }
/* A PDF (or office preview) in a single-document space keeps the pager bar, so
   Sign out lives IN that bar (the corner cluster would sit on the bar's own
   buttons): a left-pinned group holding Sign out and, if the space allows it,
   the ↓ PDF button. Phones flow it inline with the rest of the bar. */
.pdf-left { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); display: flex; gap: 6px; }
.pdf-left .pdf-dl { position: static; transform: none; }
/* Full screen: native, or the CSS stand-in (.pseudo-fs) where the API is blocked
   (an embedded frame, iPhones before iOS 17.2). app.js keeps .is-fs on the host
   in both cases. Fill with the brand background, center the page. */
/* height: use dvh so mobile browser chrome (address/tool bars) doesn't push the
   page area off-screen — 100vh overshoots the visible viewport on iOS Safari. */
.pdf-host:fullscreen, .pdf-host:-webkit-full-screen { background: var(--bg); height: 100vh; height: 100dvh; }
.pdf-host.pseudo-fs { position: fixed; inset: 0; z-index: 200; width: 100%; height: 100vh; height: 100dvh; margin: 0; background: var(--bg); }
.pdf-host.is-fs .pdf-stage { align-items: center; padding: 8px; }
/* In full screen the pager bar floats OVER the page, so the page gets the full
   height, and hides after a moment like a video player's controls (a tap on the
   page, a mouse move or a key brings it back). */
.pdf-host.is-fs .pdf-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 3;
  border-bottom: none;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  transition: opacity .25s ease, visibility .25s;
}
.pdf-host.is-fs.controls-hidden .pdf-bar { opacity: 0; visibility: hidden; pointer-events: none; }
/* The page number, flashed after a swipe or a key press while the bar is hidden. */
.pdf-toast {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 3;
  padding: 4px 10px; border: 1px solid var(--line-soft); border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  font-family: var(--font-display, monospace); font-size: 12px; color: var(--fg);
  white-space: nowrap; opacity: 0; transition: opacity .2s ease; pointer-events: none;
}
.pdf-toast.show { opacity: 1; }
/* A phone held upright showing a landscape deck in full screen: the frame is
   turned a quarter turn so the slide spans the phone's long side (app.js sizes
   the frame to the host's height x width). Off again as soon as the viewport is
   landscape: the phone was turned (rotation not locked), or Android locked it. */
.pdf-host.rotated .pdf-frame {
  position: absolute; left: 50%; top: 50%; flex: none;
  transform: translate(-50%, -50%) rotate(90deg);
}
@media (prefers-reduced-motion: reduce) { .pdf-host.is-fs .pdf-bar, .pdf-toast { transition: none; } }
/* Phones: one row of compact controls (the full-screen button is its icon alone,
   inline at the end of the pager rather than overlapping it) and no padding to
   spare around the page. */
@media (max-width: 640px) {
  /* The pager bleeds over the viewer's side padding (pages edge to edge) and
     fills the rest of the visible height: 50px top bar + 39px Files bar + 8px
     viewer padding above it, 14px below (dvh: the browser's own bars are not
     part of it, so the page itself never scrolls). */
  .pdf-host { height: calc(100vh - 111px); height: calc(100dvh - 111px); margin: 0 -14px; }
  .pdf-fs, .pdf-dl { position: static; transform: none; }
  .pdf-left { display: contents; }
  .pdf-fs .lbl { display: none; }
  .pdf-bar { gap: 10px; padding: 6px; flex-wrap: wrap; }
  .pdf-bar .btn.tiny { padding: 7px 11px; }
  .pdf-ind { min-width: 52px; }
  .pdf-stage { padding: 4px 0; }
  .pdf-host.is-fs .pdf-stage { padding: 0; }
}
/* A phone held sideways is wider than the phone block above: keep the compact bar
   (icons inline, so ⛶ and ✕ never overlap) and the edge-to-edge page there too. */
@media (pointer: coarse) and (max-height: 500px) {
  .pdf-fs, .pdf-dl { position: static; transform: none; }
  .pdf-left { display: contents; }
  .pdf-fs .lbl { display: none; }
  .pdf-host.is-fs .pdf-stage { padding: 0; }
}

/* ── Single-document space (body.single-doc; config `single`) ──
   The document is the page: no ribbon, no file list, no Files bar, no chat. The
   viewer fills the viewport and the embed fills the viewer. The only control is
   the corner cluster #single-bar (Sign out; print / download where allowed), drawn
   small and faded so it stays out of the document's own chrome until it is needed. */
body.single-doc .topbar, body.single-doc .files-bar, body.single-doc .files-scrim,
body.single-doc .sidebar, body.single-doc .chat-widget { display: none; }
body.single-doc .layout { grid-template-columns: 1fr; }
body.single-doc main.viewer { padding: 0; overflow: hidden; }
body.single-doc .viewer-empty { height: 100vh; height: 100dvh; padding: 0 24px; text-align: center; }
body.single-doc .viewer-content { height: 100vh; height: 100dvh; }
body.single-doc .viewer-embed { border: none; border-radius: 0; }
body.single-doc iframe.viewer-embed, body.single-doc iframe.viewer-embed.viewer-html { display: block; height: 100vh; height: 100dvh; }
body.single-doc .pdf-host { height: 100vh; height: 100dvh; margin: 0; }
body.single-doc .viewer-body { border: none; border-radius: 0; min-height: 100vh; min-height: 100dvh; overflow: auto; }
body.single-doc img.viewer-embed, body.single-doc video.viewer-embed { width: 100%; height: 100vh; height: 100dvh; max-height: none; object-fit: contain; }
.single-bar { display: none; }
body.single-doc .single-bar {
  position: fixed; top: 10px; right: 10px; z-index: 50;
  display: flex; gap: 6px; padding: 4px;
  background: var(--bg); background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--line-soft); border-radius: var(--radius);
  opacity: 0.6; transition: opacity .15s;
}
body.single-doc .single-bar:hover, body.single-doc .single-bar:focus-within { opacity: 1; }
body.single-doc .single-bar[hidden] { display: none; }
