/* The secure portal's own stylesheet — small, and the only one it loads.
 *
 * NOT app.css and NOT office.css, deliberately. Those two carry the household's
 * and the office's frames, their nav, their controls and their fonts, and a
 * counterparty must never be handed a page that a stranger could mistake for
 * (or mine for) either application's chrome. The portal borrows the office's
 * TOKENS — the same ink, paper and slate, the same serif for headings — so a
 * recipient who later sees the office's own letters recognises the hand
 * (screens_brief §01), and it borrows nothing else.
 *
 * No web fonts and no asset from any other origin: the security checklist
 * (design_brief §08) forbids third-party assets on portal pages, and a test
 * scans every template and this file for one. System fonts only.
 *
 * Class names are portal-prefixed: templates outside office/ and house/ are
 * measured as classic house bodies by tests/test_kit_collisions.py, and a bare
 * `btn` or `card` written in one would be a word a house body wears. The
 * doors' templates (prove.html, signin.html) write a handful of bare words of
 * their own — kicker, lede, help, door, code-field — and the block at the foot
 * dresses those, scoped under the page they belong to.
 *
 * Themes are tokens: the light palette on :root, the dark one under
 * prefers-color-scheme (unless data-theme="light" pins it) and again under
 * data-theme="dark", so a future toggle wins in both directions. Nothing here
 * sets data-theme — there is no script for it — the hook simply exists.
 */

:root {
  --portal-ink:          #12151c;
  --portal-ink-soft:     #4a5262;
  --portal-ink-faint:    #7c8697;
  --portal-paper:        #f5f6f8;
  --portal-raised:       #ffffff;
  --portal-line:         #dfe3ea;
  --portal-line-soft:    #eef0f4;
  --portal-accent:       #3d5a8a;
  --portal-accent-soft:  #e9eef6;
  --portal-alert:        #a63a32;
  --portal-shadow:       rgba(18, 21, 28, 0.18);
  --portal-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --portal-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --portal-ink:          #e8eaf0;
    --portal-ink-soft:     #b4bbc8;
    --portal-ink-faint:    #8791a3;
    --portal-paper:        #12151c;
    --portal-raised:       #1a1e27;
    --portal-line:         #2a3040;
    --portal-line-soft:    #222835;
    --portal-accent:       #8fa9d6;
    --portal-accent-soft:  #1f2a3d;
    --portal-alert:        #e07a72;
    --portal-shadow:       rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  --portal-ink:          #e8eaf0;
  --portal-ink-soft:     #b4bbc8;
  --portal-ink-faint:    #8791a3;
  --portal-paper:        #12151c;
  --portal-raised:       #1a1e27;
  --portal-line:         #2a3040;
  --portal-line-soft:    #222835;
  --portal-accent:       #8fa9d6;
  --portal-accent-soft:  #1f2a3d;
  --portal-alert:        #e07a72;
  --portal-shadow:       rgba(0, 0, 0, 0.5);
}

/* ---- the shell ---------------------------------------------------------- */

.portal-body, .portal-body * { box-sizing: border-box; }
html, .portal-body { margin: 0; }
.portal-body {
  font: 17px/1.55 var(--portal-sans);
  background: var(--portal-paper);
  color: var(--portal-ink);
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}
.portal-body a { color: var(--portal-accent); }

.portal-mast {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  background: var(--portal-raised);
  border-bottom: 1px solid var(--portal-line);
}
.portal-mark { display: flex; flex-direction: column; line-height: 1.15; color: inherit; text-decoration: none; }
.portal-mark-name { font-family: var(--portal-serif); font-size: 1.25rem; }
.portal-mark-sub { font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--portal-ink-faint); }
.portal-who { font-size: 0.95rem; text-align: right; }
.portal-who .portal-addr { font-weight: 600; word-break: break-all; }
.portal-who a { margin-left: 0.75rem; color: var(--portal-ink-faint); white-space: nowrap; }

/* A flex column so the inbox below can take exactly the height the mast, the
 * footer and the cookie bar leave it — no constant to drift when one of them
 * changes size — while the prose pages simply stack. */
.portal-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.25rem;
}

.portal-foot {
  padding: 1rem 1.25rem;
  font-size: 0.85rem;
  color: var(--portal-ink-faint);
  border-top: 1px solid var(--portal-line);
}
.portal-foot a { color: var(--portal-ink-faint); }

.portal-btn {
  display: inline-block;
  padding: 0.45rem 0.95rem;
  border: 1px solid var(--portal-line);
  border-radius: 7px;
  background: var(--portal-raised);
  color: var(--portal-ink);
  font: inherit;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
}
.portal-btn.portal-solid { background: var(--portal-ink); color: var(--portal-paper); border-color: var(--portal-ink); }
.portal-btn:focus-visible, .portal-row:focus-visible { outline: 2px solid var(--portal-accent); outline-offset: 2px; }

.portal-addr { color: var(--portal-accent); }
.portal-meta, .portal-recorded { font-size: 0.875rem; color: var(--portal-ink-faint); }
.portal-recorded { margin: 0.6rem 0 0; }

/* ---- the inbox: two panes on a desk, one column in a hand ---------------- */

/* The inbox page alone pins the body to the viewport on a desk: a flex chain
 * can only hand the grid "the remaining height" when the body's height is
 * definite, and `min-height: 100svh` is not. The list then scrolls in its own
 * box and the page never does. On a phone (below) the list IS the page. */
@media (min-width: 721px) {
  .portal-body-inbox { height: 100svh; }
}

.portal-inbox {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 1.25rem;
  flex: 1;
  min-height: 460px;
}

.portal-list {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--portal-raised);
  border: 1px solid var(--portal-line);
  border-radius: 10px;
  overflow: hidden;
}
/* The header is a sibling of the scrolling list rather than a sticky child,
 * so it never moves whatever the browser thinks of sticky inside overflow. */
.portal-list-head { padding: 0.9rem 1rem 0.7rem; border-bottom: 1px solid var(--portal-line); background: var(--portal-raised); }
.portal-list-head h1 { margin: 0; font: 600 1.05rem/1.3 var(--portal-sans); }
.portal-list-head p { margin: 0.15rem 0 0; font-size: 0.85rem; color: var(--portal-ink-faint); }
.portal-rows, .portal-rows-gone { flex: 1; min-height: 0; overflow-y: auto; margin: 0; padding: 0; list-style: none; }
.portal-rows-gone { overflow: visible; }
.portal-month {
  padding: 0.55rem 1rem 0.25rem;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--portal-ink-faint);
  background: var(--portal-paper);
}
.portal-row {
  display: block;
  position: relative;
  padding: 0.75rem 1rem 0.75rem 1.65rem;
  border-bottom: 1px solid var(--portal-line-soft);
  color: inherit;
  text-decoration: none;
}
/* A row is a link, and the shell's `a` rule would paint every subject slate;
 * the row keeps the ink and only the address and the buttons wear the accent. */
.portal-body a.portal-row { color: inherit; }
.portal-row:hover { background: var(--portal-accent-soft); }
.portal-row[aria-current="page"] { background: var(--portal-accent-soft); box-shadow: inset 3px 0 0 var(--portal-accent); }
.portal-row-top { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.85rem; color: var(--portal-ink-soft); }
.portal-subject { display: block; margin: 0.1rem 0; }
/* The glimpse of the note truncates; the tail ("until 27 Nov", "ask the
 * sender") never does — it is the fact the row exists to carry. */
.portal-preview { display: flex; gap: 0.35rem; font-size: 0.9rem; color: var(--portal-ink-faint); }
.portal-preview-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.portal-tail { flex: none; white-space: nowrap; }
.portal-row[data-unread="true"] .portal-subject, .portal-row[data-unread="true"] .portal-sender { font-weight: 600; }
.portal-dot {
  position: absolute;
  left: 0.6rem;
  top: 1.1rem;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--portal-accent);
}
.portal-soon .portal-when { color: var(--portal-alert); font-weight: 600; }
.portal-expired, .portal-revoked { color: var(--portal-ink-faint); }
.portal-expired .portal-dot, .portal-revoked .portal-dot { background: var(--portal-ink-faint); }
.portal-fold summary { cursor: pointer; padding: 0.7rem 1rem; font-size: 0.9rem; color: var(--portal-ink-faint); list-style: none; }
.portal-fold summary::-webkit-details-marker { display: none; }
.portal-fold[open] summary { border-bottom: 1px solid var(--portal-line-soft); }
.portal-empty { padding: 2rem 1rem; text-align: center; color: var(--portal-ink-faint); }

.portal-pane {
  min-height: 0;
  overflow-y: auto;
  background: var(--portal-raised);
  border: 1px solid var(--portal-line);
  border-radius: 10px;
  padding: 1.5rem 1.75rem;
}
.portal-pane .portal-meta { margin: 0 0 0.35rem; }
.portal-pane h2 { margin: 0 0 1rem; font: 400 1.6rem/1.25 var(--portal-serif); overflow-wrap: anywhere; }
.portal-note { margin: 0 0 1rem; font-family: var(--portal-serif); font-size: 1.1rem; white-space: pre-line; }
.portal-from { margin: 0 0 1.25rem; font-size: 0.9rem; color: var(--portal-ink-faint); }
.portal-pane.portal-off h2, .portal-pane.portal-off .portal-note { color: var(--portal-ink-faint); }
.portal-state-off { padding: 0.75rem 1rem; border-radius: 8px; background: var(--portal-paper); color: var(--portal-ink-soft); }

.portal-docs { margin: 0 0 0.5rem; padding: 0; list-style: none; }
.portal-doc {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.85rem 0;
  border-top: 1px solid var(--portal-line-soft);
}
.portal-doc-title { flex: 1 1 240px; overflow-wrap: anywhere; }
.portal-doc-kind { display: block; font-size: 0.85rem; color: var(--portal-ink-faint); }
.portal-docs-off .portal-doc-title { color: var(--portal-ink-faint); }

.portal-viewer-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin: 0 0 0.75rem; }
.portal-viewer iframe, .portal-viewer img {
  display: block;
  width: 100%;
  border: 1px solid var(--portal-line);
  border-radius: 8px;
  background: var(--portal-paper);
}
.portal-viewer iframe { height: 72vh; }
.portal-viewer img { height: auto; max-height: 72vh; object-fit: contain; }

/* The Back link belongs to the phone, where the list is a page of its own;
 * on a desk the list is beside the pane and Back would go nowhere new. */
.portal-back { display: none; margin: 0 0 0.75rem; }
/* …except on the signing pages, which have no list beside them on any width:
 * hidden there, a signer at a desk had only the browser's Back (rule 2's first
 * render, 23 Sep 2026). */
.portal-signing .portal-back { display: inline-block; }
/* R2-3: the component's step panel is pinned to the screen bottom (sign.html's
   own <style> child, inside its shadow root). The spacer sits AFTER the
   "recorded" note, so the paper's last field AND that note — the signer's
   disclosure — both scroll above the pinned panel; the panel is capped at
   45vh, so half the viewport clears it at any width, 375px included. It is
   rendered only with the component, so a page with signing off gets none. */
.portal-sign-spacer { height: 50vh; }

.portal-toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  background: var(--portal-ink);
  color: var(--portal-paper);
  font-size: 0.9rem;
  box-shadow: 0 6px 20px var(--portal-shadow);
}
.portal-toast[hidden] { display: none; }

/* ---- prose pages: the privacy notice, the cookie table, gone ------------- */

.portal-prose { max-width: 42rem; }
.portal-prose h1 { margin: 0.25rem 0 1rem; font: 400 1.9rem/1.25 var(--portal-serif); }
.portal-prose h2 { margin: 1.6rem 0 0.4rem; font: 600 1.05rem/1.3 var(--portal-sans); }
.portal-prose p, .portal-prose li { margin: 0.4rem 0; }
.portal-prose ul { padding-left: 1.2rem; }
.portal-cookies { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.portal-cookies th, .portal-cookies td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--portal-line); text-align: left; vertical-align: top; }
.portal-cookies th { font-weight: 600; }
.portal-cookies code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }

/* The card is shared: the gone page (centred), the doors' prove and sign-in
 * pages (left-aligned, the screens' §03/§04). */
.portal-card {
  width: 100%;
  max-width: 34rem;
  margin: 2rem auto;
  padding: 1.75rem;
  background: var(--portal-raised);
  border: 1px solid var(--portal-line);
  border-radius: 10px;
}
.portal-gone { margin-top: 3rem; text-align: center; }
.portal-card h1, .portal-h1 { margin: 0.15rem 0 0.75rem; font: 400 1.7rem/1.25 var(--portal-serif); }
.portal-p { margin: 0 0 0.9rem; }

.portal-cookie-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--portal-raised);
  border-top: 1px solid var(--portal-line);
  font-size: 0.9rem;
}
.portal-cookie-bar p { margin: 0; }
.portal-cookie-bar form { display: inline; margin-left: 0.5rem; }

/* ---- the doors: prove.html and signin.html (screens_brief §03, §04) ------ */

.portal-kicker { margin: 0; font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--portal-ink-faint); }
/* The invited address, masked before proof ("d…@example.org", the local-part sweep P1c):
   short by construction, so it never breaks at the ellipsis (the render of 7ac9e9cb at 402
   split it across two lines). */
.portal-masked { white-space: nowrap; }
.portal-invited { margin: 0.1rem 0 1.25rem; font-size: 1.25rem; font-weight: 600; color: var(--portal-accent); word-break: break-all; }
.portal-lede { margin: 0 0 1rem; }
.portal-help { margin: 0.9rem 0 0; font-size: 0.875rem; color: var(--portal-ink-faint); }
.portal-link { color: var(--portal-accent); }
.portal-notice, .portal-state { margin: 0 0 1rem; padding: 0.75rem 1rem; border-radius: 8px; background: var(--portal-accent-soft); color: var(--portal-ink-soft); }
.portal-state { background: var(--portal-paper); }
.portal-doors { display: flex; flex-direction: column; gap: 0.6rem; margin: 0 0 0.75rem; }
.portal-btn.portal-btn-primary { background: var(--portal-ink); color: var(--portal-paper); border-color: var(--portal-ink); }
.portal-btn.portal-btn-link { border: 0; background: none; padding: 0; color: var(--portal-accent); text-decoration: underline; }
.portal-btn.portal-door { display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 1rem; text-align: left; }
/* The doors became forms (17 Oct 2026, the token off the query string): the form takes the
   link's place in the column, and a button does not stretch the way a block link did. */
.portal-door-form { margin: 0; }
.portal-door-form .portal-btn.portal-door { width: 100%; }
.portal-door-mark {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  background: var(--portal-paper);
  font-weight: 700;
  font-size: 0.95rem;
}
.portal-door-caveat { display: block; font-size: 0.78rem; color: var(--portal-ink-faint); }
.portal-or { margin: 0.25rem 0 0.75rem; text-align: center; font-size: 0.85rem; color: var(--portal-ink-faint); }
.portal-code-entry { margin: 0.5rem 0 0; }
.portal-code-field {
  width: 100%;
  max-width: 14rem;
  padding: 0.55rem 0.75rem;
  margin: 0 0.5rem 0.5rem 0;
  border: 1px solid var(--portal-line);
  border-radius: 7px;
  background: var(--portal-raised);
  color: var(--portal-ink);
  font: inherit;
  font-size: 1.6rem;
  letter-spacing: 0.35em;
  text-align: center;
}
.portal-check { display: block; margin: 0.75rem 0 0; font-size: 0.9rem; }
.portal-inline { display: inline; }
.portal-why { margin: 1.25rem 0 0; font-size: 0.9rem; color: var(--portal-ink-soft); }
.portal-why summary { cursor: pointer; color: var(--portal-accent); }
.portal-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- a phone ------------------------------------------------------------- */

@media (max-width: 720px) {
  .portal-main { padding: 0.75rem; }
  .portal-inbox { display: block; min-height: 0; }
  .portal-list { border: 0; border-radius: 0; background: transparent; }
  .portal-list-head { border-radius: 10px 10px 0 0; border: 1px solid var(--portal-line); border-bottom: 0; }
  .portal-rows { border: 1px solid var(--portal-line); border-radius: 0 0 10px 10px; background: var(--portal-raised); overflow: visible; }
  /* One column: the list IS the page, and a selected share is its own page
   * reached by the row's link. Both are in the markup; the width decides. */
  .portal-inbox.portal-has-selected .portal-list { display: none; }
  .portal-inbox:not(.portal-has-selected) .portal-pane { display: none; }
  .portal-pane { padding: 1rem; }
  .portal-back { display: inline-block; }
  .portal-viewer iframe { height: 60vh; }
  .prove, .signin, .portal-card { margin: 0.5rem auto; padding: 1.25rem; }
}

/* ---- paper --------------------------------------------------------------- */

@media print {
  .portal-list, .portal-who, .portal-foot, .portal-cookie-bar, .portal-toast, .portal-back,
  .portal-viewer-bar, .portal-btn { display: none !important; }
  .portal-inbox { display: block; height: auto; }
  .portal-pane { border: 0; padding: 0; overflow: visible; }
  .portal-body { background: #fff; color: #000; }
}

/* ---- the curator's room (413) --------------------------------------------- */

/* The room borrows the shell's tokens and adds nothing new to :root: the same
 * paper, ink and slate, and — for the Viewer's stage — the ink as ground, so a
 * painting sits on the same dark the office's own viewer uses. Every class is
 * portal-prefixed for the reason base.html gives; nothing here is fetched. */

.portal-room, .portal-work { width: 100%; }
.portal-room-head { margin: 0 0 1rem; }
.portal-room-name { margin: 0.1rem 0 0.35rem; font: 400 1.9rem/1.2 var(--portal-serif); overflow-wrap: anywhere; }
.portal-room-meta { margin: 0; }
.portal-room-until { color: var(--portal-accent); font-weight: 600; }
.portal-room-counts { margin: 0.35rem 0 0; font-size: 0.95rem; color: var(--portal-ink-soft); }
.portal-room-dark { margin: 1rem 0; }
.portal-room-saved { margin: 0 0 1rem; }

/* The chips: a lens row and a scope row, every chip a link. The current one
 * wears the accent tint and a solid edge, the rest a hairline. */
.portal-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 0.6rem; }
.portal-chip {
  display: inline-block;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--portal-line);
  border-radius: 999px;
  background: var(--portal-raised);
  color: var(--portal-ink);
  font-size: 0.9rem;
  text-decoration: none;
}
.portal-body a.portal-chip { color: var(--portal-ink); }
.portal-chip-on, .portal-body a.portal-chip-on { background: var(--portal-accent-soft); border-color: var(--portal-accent); color: var(--portal-accent); }

.portal-room-search { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0.25rem 0 1rem; }
.portal-field {
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--portal-line);
  border-radius: 7px;
  background: var(--portal-raised);
  color: var(--portal-ink);
  font: inherit;
  font-size: 0.95rem;
  min-width: 0;
}
.portal-room-search .portal-field[type="search"] { flex: 1 1 220px; }
.portal-select { padding-right: 1.6rem; }
.portal-textarea { width: 100%; resize: vertical; }
.portal-room-clear { font-size: 0.9rem; }

/* The budget card (D5): the figure large in the serif, its source beneath —
 * a budget is a claim with its source — then the family's tally per currency. */
.portal-budget {
  margin: 0 0 1.25rem;
  padding: 1rem 1.25rem;
  background: var(--portal-raised);
  border: 1px solid var(--portal-line);
  border-radius: 10px;
}
.portal-budget-amount { margin: 0.1rem 0 0.25rem; font: 400 1.7rem/1.2 var(--portal-serif); }
.portal-budget-note { margin: 0 0 0.35rem; font-family: var(--portal-serif); font-size: 1.05rem; }
.portal-cart { margin: 0.75rem 0 0.25rem; padding: 0; list-style: none; }
.portal-cart-line { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; padding: 0.4rem 0; border-top: 1px solid var(--portal-line-soft); font-size: 0.95rem; }
.portal-cart-total { font-weight: 600; }
.portal-cart-state { color: var(--portal-ink-soft); }
.portal-cart-pct { color: var(--portal-accent); }
.portal-cart-pct.portal-over { color: var(--portal-alert); font-weight: 600; }

/* The family's word on a work (D6): one pill per state, the withdrawn pill
 * faint because a withdrawn work is history, not news. */
.portal-pill {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  background: var(--portal-accent-soft);
  color: var(--portal-accent);
  white-space: nowrap;
}
.portal-pill-acquired { background: var(--portal-ink); color: var(--portal-paper); }
.portal-pill-enquired { border: 1px solid var(--portal-accent); background: transparent; }
.portal-pill-passed, .portal-pill-withdrawn { background: var(--portal-line-soft); color: var(--portal-ink-faint); }

/* ---- the wall: tiles ------------------------------------------------------ */
.portal-wall {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.portal-tile { min-width: 0; }
.portal-tile-link {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.6rem;
  background: var(--portal-raised);
  border: 1px solid var(--portal-line);
  border-radius: 10px;
  color: inherit;
  text-decoration: none;
  height: 100%;
}
.portal-body a.portal-tile-link { color: inherit; }
.portal-tile-link:hover { border-color: var(--portal-accent); }
.portal-tile-link:focus-visible { outline: 2px solid var(--portal-accent); outline-offset: 2px; }
.portal-tile-img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: var(--portal-paper);
  border-radius: 6px;
}
.portal-tile-glyph { display: grid; place-items: center; font-size: 2rem; color: var(--portal-ink-faint); }
.portal-tile-title { font-weight: 600; overflow-wrap: anywhere; }
.portal-tile-artist { font-size: 0.9rem; color: var(--portal-ink-soft); }
.portal-tile-price { font-size: 0.9rem; color: var(--portal-ink-faint); }
.portal-tile-withdrawn .portal-tile-img { opacity: 0.45; }
.portal-tile-withdrawn .portal-tile-title { color: var(--portal-ink-faint); }

/* ---- the sheet: one batch bar over a table (D8) ------------------------- */
.portal-batch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin: 0 0 0.6rem;
  padding: 0.6rem 0.9rem;
  background: var(--portal-raised);
  border: 1px solid var(--portal-line);
  border-radius: 10px;
  font-size: 0.95rem;
}
.portal-batch-all { display: inline-flex; align-items: center; gap: 0.35rem; }
.portal-batch-count { color: var(--portal-ink-soft); min-width: 6rem; }
.portal-batch-note { flex: 1 1 200px; }
.portal-btn:disabled, .portal-btn-off { opacity: 0.45; cursor: default; }
.portal-sheet-wrap { overflow-x: auto; }
.portal-sheet { width: 100%; border-collapse: collapse; font-size: 0.95rem; background: var(--portal-raised); border: 1px solid var(--portal-line); border-radius: 10px; }
.portal-sheet th, .portal-sheet td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--portal-line-soft); text-align: left; vertical-align: top; }
.portal-sheet th { font-weight: 600; font-size: 0.8rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--portal-ink-faint); }
.portal-sheet-tick { width: 2rem; }
.portal-sheet-link { display: flex; align-items: center; gap: 0.6rem; color: inherit; text-decoration: none; }
.portal-body a.portal-sheet-link { color: inherit; }
.portal-sheet-thumb { width: 44px; height: 44px; object-fit: contain; border-radius: 4px; background: var(--portal-paper); flex: none; display: grid; place-items: center; font-size: 1.2rem; }
.portal-sheet-title { font-weight: 600; }
.portal-sheet-artist { display: block; font-weight: 400; font-size: 0.9rem; color: var(--portal-ink-soft); }
.portal-sheet-price, .portal-sheet-year { white-space: nowrap; }
.portal-sheet-remark-body { display: block; max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.portal-row-withdrawn .portal-sheet-title, .portal-row-withdrawn .portal-sheet-price { color: var(--portal-ink-faint); }
.portal-pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin: 1rem 0; }

/* ---- the viewer: a page per work (D14) ----------------------------------- */
.portal-work-nav { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; margin: 0 0 0.75rem; }
.portal-work-steps { display: inline-flex; gap: 0.4rem; }
.portal-work-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (min-width: 1024px) { .portal-work-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 360px); } }
/* The stage is the ink in both themes: a painting is looked at on a dark
 * ground, and the paper's caption sits beneath it. */
.portal-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem;
  min-height: 240px;
  background: var(--portal-ink);
  color: var(--portal-paper);
  border-radius: 12px;
}
.portal-stage-img { display: block; max-width: 100%; height: auto; max-height: 72svh; object-fit: contain; border-radius: 6px; }
.portal-stage-withdrawn .portal-stage-img { opacity: 0.6; }
.portal-stage-glyph { font-size: 3rem; color: var(--portal-ink-faint); padding: 3rem 0 0; }
.portal-stage-none { margin: 0; color: var(--portal-ink-faint); }
.portal-stage-caption { margin: 0; font-size: 0.9rem; text-align: center; overflow-wrap: anywhere; }
.portal-stage-more { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0; padding: 0; list-style: none; }
.portal-stage-more img { width: 56px; height: 56px; object-fit: cover; border-radius: 4px; }
.portal-rail { min-width: 0; padding: 1rem 1.25rem; background: var(--portal-raised); border: 1px solid var(--portal-line); border-radius: 10px; }
.portal-rail-title { margin: 0 0 0.75rem; font: 400 1.5rem/1.25 var(--portal-serif); overflow-wrap: anywhere; }
.portal-rail-h2 { margin: 1.25rem 0 0.5rem; font: 600 1rem/1.3 var(--portal-sans); }
.portal-rail-note { display: block; margin-top: 0.2rem; }
.portal-facts { display: grid; grid-template-columns: minmax(0, 6rem) minmax(0, 1fr); gap: 0.3rem 0.75rem; margin: 0; font-size: 0.95rem; }
.portal-facts dt { color: var(--portal-ink-faint); }
.portal-facts dd { margin: 0; overflow-wrap: anywhere; }
.portal-remark { padding: 0.5rem 0; border-top: 1px solid var(--portal-line-soft); }
.portal-remark-body { margin: 0 0 0.15rem; font-family: var(--portal-serif); font-size: 1.05rem; white-space: pre-line; }
.portal-remark-form { display: flex; flex-direction: column; gap: 0.5rem; margin: 0.75rem 0 0; }
.portal-verbs { margin: 1.25rem 0 0; padding-top: 0.75rem; border-top: 1px solid var(--portal-line); }
.portal-verb-form { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.portal-verb-form .portal-field { flex: 1 1 200px; }

/* ---- the inbox's shelf: your collections ------------------------------- */
.portal-rooms { padding: 0.9rem 1rem 0.5rem; border-bottom: 1px solid var(--portal-line); background: var(--portal-accent-soft); }
.portal-rooms-title { margin: 0 0 0.35rem; font: 600 0.8rem/1.3 var(--portal-sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--portal-ink-faint); }
.portal-rooms-list { margin: 0; padding: 0; list-style: none; }
.portal-rooms-item { padding: 0.35rem 0; }
.portal-rooms-link { display: flex; flex-direction: column; color: inherit; text-decoration: none; }
.portal-body a.portal-rooms-link { color: inherit; }
.portal-rooms-name { font-family: var(--portal-serif); font-size: 1.1rem; }
.portal-rooms-link:hover .portal-rooms-name { color: var(--portal-accent); }

/* ---- the portal's user adds (Phase 3): the door in, the receipt, the catalogue page ---- */
/* The room's own tokens, nothing new on :root. A work read from their catalogue
 * wears its own page (D10): the same tile frame as a photograph, a caption
 * beneath saying where the picture came from, and on the stage a lighter
 * ground because a scanned page on the ink reads as a hole in the wall. */
.portal-room-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.6rem 0 0; }
.portal-tile-page { background: var(--portal-raised); object-fit: contain; }
.portal-tile-caption, .portal-stage-source { font-size: 0.78rem; color: var(--portal-ink-faint); }
.portal-stage-page { background: var(--portal-paper); padding: 0.4rem; }
.portal-stage-source { margin: 0; color: var(--portal-line); }

.portal-add-form, .portal-receipt-card {
  max-width: 42rem;
  margin: 0.75rem 0 1rem;
  padding: 1rem 1.25rem;
  background: var(--portal-raised);
  border: 1px solid var(--portal-line);
  border-radius: 10px;
}
.portal-add-form { display: flex; flex-direction: column; gap: 0.9rem; }
.portal-add-choice { margin: 0; padding: 0.75rem 1rem; border: 1px solid var(--portal-line-soft); border-radius: 8px; }
.portal-add-choice legend { padding: 0 0.3rem; font-weight: 600; }
.portal-add-choice label { display: block; margin: 0 0 0.5rem; font-size: 0.95rem; color: var(--portal-ink-soft); }
.portal-file { font: inherit; font-size: 0.95rem; max-width: 100%; }
.portal-add-form .portal-or { margin: 0; }
.portal-receipt-line { margin: 0 0 0.5rem; font-family: var(--portal-serif); font-size: 1.15rem; }
.portal-receipt-works { margin: 0.25rem 0 0.75rem; padding-left: 1.4rem; }
.portal-repriced { margin: 0.5rem 0 0.25rem; padding: 0; list-style: none; font-size: 0.95rem; }
.portal-repriced li { padding: 0.35rem 0; border-top: 1px solid var(--portal-line-soft); color: var(--portal-alert); }

/* Correct a fact (D13): a fold under the facts, their fields as one column. */
.portal-fold-facts { margin: 1rem 0 0; padding-top: 0.6rem; border-top: 1px solid var(--portal-line-soft); font-size: 0.95rem; }
.portal-fold-facts summary { cursor: pointer; color: var(--portal-accent); font-weight: 600; }
.portal-facts-form { display: flex; flex-direction: column; gap: 0.3rem; margin: 0.6rem 0 0; }
.portal-fact-label { margin-top: 0.35rem; font-size: 0.85rem; color: var(--portal-ink-faint); }
.portal-facts-form .portal-btn { align-self: flex-start; margin-top: 0.5rem; }


/* ---- the shelf, rearranged (Phase 3b) ------------------------------------ */
/* THE ART FIRST. The room is a two-column grid whose first row is the head
 * band: the header at the left, the budget chip at the right, bottom-aligned
 * with the header's action row so "Add works" and "Budget & cart" read as one
 * row. The budget's <details> is written AFTER the art in the document (the
 * template says why) and only this placement brings it up here; everything
 * else spans both columns and stacks. */
.portal-room { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-content: start; }
.portal-room > * { grid-column: 1 / -1; min-width: 0; }
.portal-room > .portal-room-head { grid-column: 1; grid-row: 1; }
.portal-room > .portal-budget-fold { grid-column: 2; grid-row: 1; align-self: end; justify-self: end; margin: 0 0 1rem 1rem; }

/* A summary wearing the chip reads as a chip whatever fold it sits in: the
 * inbox's fold rule pads and fades every summary, and a chip is neither. */
.portal-fold summary.portal-chip { padding: 0.3rem 0.8rem; font-size: 0.9rem; color: var(--portal-ink); list-style: none; border-bottom: 0; }
.portal-fold[open] summary.portal-chip { background: var(--portal-accent-soft); border-color: var(--portal-accent); color: var(--portal-accent); }

/* The budget and the cart drop down from their chip as a panel over the
 * page, right-aligned to the chip, and never push the art. */
.portal-budget-fold { position: relative; }
.portal-budget-fold > .portal-budget {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  z-index: 5;
  width: min(36rem, calc(100vw - 2.5rem));
  margin: 0;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.14);
}
.portal-budget-marked { font-weight: 600; }

/* The filters and the art: one column, the filters folded above the art;
 * two columns from 1024px, the filters standing at the left. Exactly one of
 * the two renderings of the form shows at any width. */
.portal-room-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; align-items: start; }
.portal-room-filters { display: none; }
.portal-room-fold { margin: 0 0 1rem; }
.portal-room-fold > .portal-room-form { margin: 0.75rem 0 0; padding: 0.9rem 1rem; background: var(--portal-raised); border: 1px solid var(--portal-line); border-radius: 10px; }
@media (min-width: 1024px) {
  .portal-room-grid { grid-template-columns: 260px minmax(0, 1fr); gap: 1.25rem; }
  .portal-room-filters { display: block; position: sticky; top: 1rem; max-height: calc(100svh - 2rem); overflow-y: auto; }
  .portal-room-fold { display: none; }
}

/* The form as a column: the search row, then the facet groups, then the
 * order, the scope and the lens, each under a small label. */
.portal-room-form { flex-direction: column; align-items: stretch; gap: 0.9rem; margin: 0; }
.portal-room-searchrow { display: flex; gap: 0.5rem; align-items: center; }
.portal-room-searchrow .portal-field[type="search"] { flex: 1 1 auto; }
.portal-facets { display: flex; flex-direction: column; gap: 0.9rem; }
.portal-fgroup { min-width: 0; }
.portal-fgroup-label { display: block; margin: 0 0 0.35rem; font: 600 0.75rem/1.3 var(--portal-sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--portal-ink-faint); }
.portal-fgroup .portal-chips { margin: 0; }
.portal-fgroup .portal-select { width: 100%; }
.portal-chip-count { margin-left: 0.25rem; font-size: 0.8rem; color: var(--portal-ink-faint); }
.portal-chip-on .portal-chip-count { color: inherit; }

@media (max-width: 720px) {
  .portal-wall { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.6rem; }
  .portal-stage { padding: 0.6rem; }
  .portal-stage-img { max-height: 60svh; }
  .portal-rail { padding: 0.9rem; }
  .portal-sheet-remark-body { max-width: 12rem; }
  /* Phase 3b: the head band keeps its two cells — the chip's <details> is
   * placed into row 1 by the rule above and auto-placement would carry it
   * back below the art — and the panel takes the width of the page. */
  .portal-budget-fold > .portal-budget { width: calc(100vw - 2.5rem); }
  .portal-room-grid { gap: 0.6rem; }
  .portal-room-fold > .portal-room-form { padding: 0.75rem; }
}

@media print {
  .portal-chips, .portal-room-search, .portal-batch, .portal-work-nav, .portal-verbs,
  .portal-remark-form, .portal-pager, .portal-room-actions, .portal-fold-facts,
  .portal-add-form, .portal-room-filters, .portal-room-fold,
  .portal-budget-fold { display: none !important; }
  .portal-stage { background: #fff; color: #000; }
}
