/* Spaces (spaces.js, behind SPACES_ENABLED). The list is a page like Results;
   a Space is the main area given to the canvas, with one slim bar and one
   line of activity above it. Motion: the Add block menu and History use the
   existing popover motion (motion.js `enter`/`leave`, the model picker's
   mp-in / mp-out keyframes) — nothing new. */

#spaces-view { display: none; }
#app.view-spaces #spaces-view { display: flex; }
/* Plum, like the rail's tile. It was red on a blush wash (#196), which made a
   page header the loudest red on the screen; red is the one action per view
   (SHELL-08, DS-15). */
#app.view-spaces { --vh: var(--fill-plum); --vw: var(--plum-wash); --vi: var(--plum); }
#spaces-view {
  flex: 1; min-height: 0; flex-direction: column; overflow-y: auto; padding: 80px 32px 40px;
  background: linear-gradient(to bottom, color-mix(in srgb, var(--vw, var(--card-2)) 70%, var(--window)) 0, var(--window) 300px) local;
}
/* In a Space the canvas is the page: no gradient, no padding but the topbar's. */
#spaces-view.sp-in-space { overflow: hidden; padding: 58px 0 0; background: var(--window); }

.sp-list-page { width: min(1120px, 100%); margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.sp-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sp-head-acts { display: flex; gap: 8px; flex-wrap: wrap; }
.sp-head-words { display: grid; gap: 4px; min-width: 0; }
#spaces-h { margin: 0; font-size: clamp(24px, 4cqi, 28px); font-weight: 600; letter-spacing: -.02em; line-height: 1.15; }
.sp-lede { margin: 0; font-size: 13.5px; color: var(--dim); }

.sp-new-form { display: grid; gap: 12px; background: var(--card); border-radius: var(--card-r); box-shadow: var(--elev-1); padding: 16px; max-width: 520px; }
.sp-new-form.is-entering { animation: mp-in var(--dur-quick) var(--ease-snap) both; }
.sp-field { display: grid; gap: 4px; font-size: 13px; color: var(--dim); }
.sp-field input { font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--line-2); border-radius: 9px; padding: 8px 10px; }
.sp-kinds { display: flex; gap: 14px; border: 0; padding: 0; margin: 0; font-size: 13.5px; }
.sp-kinds legend { font-size: 13px; color: var(--dim); padding: 0; margin-bottom: 4px; }
.sp-form-acts { display: flex; gap: 8px; }
.sp-form-error, .sp-list-error { margin: 0; font-size: 13px; color: var(--err); } /* the error ink (wine): a failure is never brand red */

.sp-cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.sp-card { background: var(--card); border-radius: var(--card-r); box-shadow: var(--elev-1); min-width: 0; }
.sp-open { all: unset; box-sizing: border-box; display: grid; gap: 8px; width: 100%; padding: 14px 16px; cursor: pointer; border-radius: inherit; }
.sp-open:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.sp-card-name { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-card-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; color: var(--dim); }
.sp-kind-pill, .sp-kind { padding: 2px 9px; font-size: 12px; }
.sp-broken { padding: 14px 16px; display: grid; gap: 6px; }
.sp-empty { color: var(--dim); font-size: 13.5px; padding: 8px 0; }

/* ---------- one Space ---------- */
.sp-space { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.sp-space[hidden], .sp-list-page[hidden] { display: none; }
.sp-bar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--card); min-height: 44px; }
.sp-name { font: inherit; font-size: 15px; font-weight: 600; color: var(--text); background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 4px 8px; min-width: 0; flex: 0 1 320px; text-overflow: ellipsis; }
.sp-name:hover { border-color: var(--line-2); }
.sp-name:focus { outline: none; border-color: var(--focus-ring); background: var(--surface); }
.sp-tools { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.sp-add-wrap, .sp-hist-wrap, .sp-board-wrap, .sp-tpl-wrap { position: relative; }
.sp-menu, .sp-hist {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 240px; max-width: 360px; max-height: 360px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--elev-2, 0 8px 24px rgba(0,0,0,.12)); padding: 6px; display: grid; gap: 2px;
}
.sp-menu[hidden], .sp-hist[hidden] { display: none; }
.sp-menu.is-entering, .sp-hist.is-entering { animation: mp-in var(--dur-quick) var(--ease-snap) both; }
.sp-item, .sp-pick-back { all: unset; box-sizing: border-box; display: block; padding: 8px 10px; border-radius: 8px; font-size: 13.5px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-item:hover, .sp-item:focus-visible, .sp-pick-back:hover, .sp-pick-back:focus-visible { background: var(--surface-2); }
.sp-pick-back { color: var(--dim); font-size: 12.5px; }
.sp-pick-wait { margin: 0; padding: 8px 10px; font-size: 13px; color: var(--dim); }
.sp-versions { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sp-versions li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px 4px 10px; font-size: 13px; }
.sp-more { display: none; }
.sp-back, .sp-more { width: 34px; height: 34px; min-height: 0; padding: 0; place-items: center; border-radius: 9px; flex: none; }
.sp-back { display: inline-grid; }

/* The activity strip: one line, never more (the plan's rule). */
.sp-strip { display: flex; gap: 10px; padding: 4px 16px; font-size: 12.5px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 24px; align-items: center; border-bottom: 1px solid var(--line); background: var(--card); }
.sp-act { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.sp-saved { margin-left: auto; flex: none; }
/* An agent's write, undoable from the line that says it. */
.sp-undo { flex: none; min-height: 0; padding: 1px 8px; font-size: 12.5px; }
.sp-undo[hidden] { display: none; }
/* Slice I5b: a selected Interactive card's one-press open, beside the lock. */
.sp-ia-open { flex: none; }
.sp-proof-action button:not([hidden]), .sp-proof-action span:not(:empty) { margin: 4px 16px; }
.sp-proof-action button { min-height: 44px; }
.sp-proof-action button[hidden] { display: none; }
.sp-ia-open[hidden] { display: none; }
/* The person-only lock, shown while one block is selected. */
.sp-lock { flex: none; }
.sp-lock[hidden] { display: none; }
.sp-lock[aria-pressed="true"] { color: var(--ink); font-weight: 600; }
/* A selected board's Columns, and its small in-place editor (slice 5). */
.sp-board-wrap { flex: none; }
.sp-board-edit[hidden] { display: none; }
.sp-cols { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.sp-cols li { display: flex; align-items: center; gap: 6px; }
.sp-col-name { font: inherit; font-size: 13.5px; flex: 1; min-width: 0; padding: 4px 8px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface); color: var(--text); }
.sp-board .sp-form-acts { display: flex; gap: 6px; justify-content: space-between; padding-top: 4px; }
/* The template menu opens under its button on the list page. Its rows are a
   name and a sentence saying what the template holds, and the sentence IS the
   choice: the shared .sp-menu/.sp-item one-line ellipsis cut it to "A board, a
   launch plan a…" on the live site (2026-10-27). So this menu is wider than
   the Add block menu (whose rows are one or two words and keep their look),
   never wider than a 390px phone less its two 16px gutters — the button is
   the first in its row there, so its left edge is the gutter — and each
   sentence wraps under its name, two lines at most. */
.sp-tpl-menu { left: 0; right: auto; width: max-content; min-width: min(280px, calc(100vw - 32px)); max-width: min(380px, calc(100vw - 32px)); }
.sp-tpl-menu .sp-item { display: grid; gap: 2px; white-space: normal; overflow: visible; line-height: 1.35; }
.sp-tpl-name { font-weight: 600; }
.sp-tpl-words {
  color: var(--dim); font-size: 12.5px; overflow: hidden; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
}

.sp-canvas { flex: 1; min-height: 0; position: relative; }
.sp-canvas[hidden] { display: none; }
.sp-missing { margin: 24px; font-size: 14px; color: var(--dim); }

/* Scout's look on Excalidraw, through the custom properties its 0.18
   stylesheet reads. More specific than its own `.excalidraw.theme--dark`
   so ours win in both themes. Library and collaboration are not offered in
   this slice, so their trigger is not drawn. */
#spaces-canvas .excalidraw, #spaces-canvas .excalidraw.theme--dark {
  --color-primary: var(--fill-denim);
  --color-primary-darker: color-mix(in srgb, var(--fill-denim) 85%, black);
  --color-primary-darkest: color-mix(in srgb, var(--fill-denim) 70%, black);
  --color-primary-hover: color-mix(in srgb, var(--fill-denim) 90%, black);
  --color-primary-light: var(--denim-wash);
  --color-primary-light-darker: color-mix(in srgb, var(--denim-wash) 80%, var(--fill-denim));
  --ui-font: inherit;
  --border-radius-lg: 12px;
}
#spaces-canvas .excalidraw .default-sidebar-trigger,
#spaces-canvas .excalidraw .collab-button,
#spaces-canvas .excalidraw .welcome-screen-menu-item--excalidraw-plus { display: none !important; }

/* The phone's sheet (a <dialog>; dialogs.js and phone.css make it the bottom sheet). */
.sp-sheet { border: 0; border-radius: 16px; padding: 0; width: min(420px, 100vw - 32px); background: var(--card); color: var(--text); }
.sp-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sp-sheet-head h2 { margin: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-sheet-body { padding: 8px 12px 16px; display: grid; gap: 4px; }
.sp-sheet-sub { margin: 8px 4px 2px; font-size: 12.5px; color: var(--dim); }
.sp-sheet-rows { display: grid; gap: 2px; }

@media (prefers-reduced-motion: reduce) {
  .sp-menu.is-entering, .sp-hist.is-entering, .sp-new-form.is-entering { animation: cm-fade 80ms linear both; }
}

/* ---------- phones ---------- */
@media (max-width: 720px) {
  #spaces-view { padding: 16px 16px 28px; }
  #spaces-view.sp-in-space { padding: 0; }
  /* The list is a plain list on a phone. */
  .sp-cards { grid-template-columns: 1fr; gap: 0; background: var(--card); border-radius: var(--card-r); box-shadow: var(--elev-1); }
  .sp-card { box-shadow: none; border-radius: 0; border-bottom: 1px solid var(--line); background: transparent; }
  .sp-card:last-child { border-bottom: 0; }
  /* The bar collapses to the name and one "…". */
  .sp-kind, .sp-tools { display: none; }
  .sp-more { display: inline-grid; margin-left: auto; }
  .sp-lock, .sp-ia-open { padding: 0 8px; font-size: 13px; }
  .sp-name { flex: 1 1 auto; }
}
.spacechip .sc-undo:disabled { color: var(--dim); cursor: default; }

/* Undo's question, in place (spaces.js askInPlace): one line where the Undo
   was. Plain inline flow, not a flex row, so on a phone the buttons follow
   the sentence's last word instead of taking a third line of their own: two
   lines at most at 390px. Reuses the ghost small buttons; no motion of its own. */
.undo-asking { white-space: normal; flex-wrap: wrap; }
.undo-asking > [hidden] { display: none !important; }
.undo-ask { display: block; flex: 1 1 auto; min-width: 0; line-height: 20px; }
.undo-ask .ua-text { color: var(--ink); margin-right: 4px; }
.undo-ask .ghost.small { display: inline-block; vertical-align: baseline; min-height: 0; padding: 0 8px; font-size: 12.5px; line-height: 18px; }
.undo-ask .ua-keep { font-weight: 600; margin-left: 4px; }

/* ---------- Interactive block panel (slice I2) ---------- */
/* A panel over the canvas's right edge: the program draws in its sandboxed
   frame here, never on the canvas itself (spaces.js `openInteractive`). */
.sp-space { position: relative; }
.sp-ia {
  position: absolute; right: 12px; top: 96px; bottom: 12px; z-index: 25; width: min(560px, calc(100% - 32px));
  display: flex; flex-direction: column; gap: 8px; padding: 12px;
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--elev-2, 0 8px 24px rgba(0,0,0,.12));
}
.sp-ia[hidden] { display: none; }
/* Slice I5, found by the ui:flows walk at 390x844: with the Share row's
   one-time link and the Stop/Keep confirm showing, the panel's contents ran
   past its foot (New link, Stop the link and Keep it were drawn below the
   panel's border, over the tab bar) and the program box was squeezed to one
   line. Everything keeps its height and the panel scrolls.
   Slice I5b corrects what this said next — "the frame is the one child that
   shrinks (it scrolls inside its own 240px floor)" — because the first real
   browser walk (Chrome 156, 2026-10-29) showed what that meant: the panel
   never scrolled (scrollHeight 594 = clientHeight 594) while the frame's
   host scrolled inside itself (568 in 418 on the desktop, 668 in 334 on a
   phone), so the actions and the Share row never moved and a block was read
   through a slot. The frame says its content height and the host sizes the
   iframe to it, so the host now takes that height whole: no inner scrollbar,
   one scroll for the whole panel. */
.sp-ia { overflow-y: auto; overscroll-behavior: contain; }
.sp-ia > * { flex-shrink: 0; }
.sp-ia-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sp-ia-title { margin: 0; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-ia-close { width: 30px; height: 30px; min-height: 0; padding: 0; flex: none; }
.sp-ia-error { margin: 0; font-size: 13px; color: var(--dim); }
.sp-ia-data { margin: 0; font-size: 12px; color: var(--dim); }
/* Slice I7a: "Remembers 3 values · Clear" — as quiet as the data line, and
   wrapping at 390 rather than pushing Clear off the panel. */
.sp-ia-state { margin: 0; font-size: 12px; color: var(--dim); display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; overflow-wrap: anywhere; }
.sp-ia-state[hidden] { display: none; }
.sp-ia-state-line { min-width: 0; }
.sp-ia-frame { overflow: hidden; flex: none; }
.sp-ia-frame:empty { display: none; }
.sp-ia-acts { display: flex; gap: 6px; flex-wrap: wrap; }
.sp-ia-program { margin: 0; padding: 10px; max-height: 40vh; overflow: auto; font-size: 12px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; background: var(--surface-2); border-radius: 8px; }
.sp-ia-program[hidden] { display: none; }
.sp-item[data-interactive-ask] { white-space: normal; }
@media (max-width: 640px) { .sp-ia { left: 16px; right: 16px; width: auto; top: 72px; } }
/* Slice I5, found by the ui:flows walk at 1024x768: the Ask Scout pill is
   fixed at the window's bottom right (style.css #companion, 64px up, 40px
   tall) and sat over the panel's foot, so the Share row's Copy could not be
   pressed. The panel stops above it, as the receipts already do. */
body:has(#companion[data-shape="pill"]) .sp-ia { bottom: 112px; }
/* Slice I5: the panel's ✕ was 30x30 on a phone, under the 40px every other
   control in the panel has; a coarse pointer gets the full box. */
@media (pointer: coarse) { .sp-ia-close { width: 40px; height: 40px; } }
/* Slice I4: the share row, one quiet line per state. */
/* Slice I6a: Data sources, under Show program. Same rule, type and gaps as the share row below it. */
.sp-ia-src { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 8px 0 0; border: 0; border-top: 1px solid var(--border, rgba(127,127,127,.25)); min-width: 0; }
.sp-ia-src[hidden], .sp-ia-src-off[hidden], .sp-ia-src-line[hidden] { display: none; }
.sp-ia-src-head { padding: 0; font-size: 12px; font-weight: 600; color: var(--dim); }
/* Slice I7b: the write tools' heading inside the list, and the press receipts. */
.sp-ia-src-subhead { margin: 8px 0 0; font-size: 12px; font-weight: 600; color: var(--dim); }
.sp-ia-receipts { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--dim); }
.sp-ia-receipts[hidden] { display: none; }
.sp-ia-receipt { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; overflow-wrap: anywhere; min-width: 0; }
.sp-ia-receipt-text { min-width: 0; }
@media (pointer: coarse) { .sp-ia-receipt-undo { min-height: 44px; } }
.sp-ia-src-list { display: flex; flex-direction: column; gap: 2px; }
.sp-ia-src-row { display: flex; align-items: center; gap: 8px; min-height: 32px; font-size: 13px; color: var(--text, inherit); cursor: pointer; }
.sp-ia-src-row > span { min-width: 0; overflow-wrap: anywhere; }
.sp-ia-src-tick { flex: none; width: 16px; height: 16px; margin: 0; accent-color: var(--accent, currentColor); }
.sp-ia-src-off, .sp-ia-src-line { margin: 0; font-size: 12px; color: var(--dim); }
.sp-ia-src-used[hidden] { display: none; }
/* Slice I6b: a billable row's price, Change, and the two figures it opens. */
.sp-ia-src-item { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sp-ia-src-price { margin: 0 0 4px 24px; font-size: 12px; color: var(--dim); overflow-wrap: anywhere; }
.sp-ia-src-change { padding: 0 4px; min-height: 24px; }
.sp-ia-src-cap { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin: 0 0 6px 24px; min-width: 0; }
.sp-ia-src-cap-field { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--dim); min-width: 0; }
.sp-ia-src-cap-field input { width: 8em; max-width: 100%; box-sizing: border-box; padding: 4px 6px; font: inherit; font-size: 13px; color: var(--text, inherit); background: var(--bg, transparent); border: 1px solid var(--border, rgba(127,127,127,.35)); border-radius: 6px; }
.sp-ia-src-cap-acts { display: flex; gap: 6px; }
.sp-ia-src-used { margin: 0; font-size: 12px; color: var(--text, inherit); }
@media (max-width: 480px) { .sp-ia-src-price, .sp-ia-src-cap { margin-left: 0; } .sp-ia-src-cap-field input { width: 100%; } .sp-ia-src-cap-field { flex: 1 1 8em; } }
@media (pointer: coarse) { .sp-ia-src-row { min-height: 44px; } .sp-ia-src-change, .sp-ia-src-cap-acts button { min-height: 44px; } }
.sp-ia-share { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--border, rgba(127,127,127,.25)); padding-top: 8px; }
.sp-ia-share[hidden], .sp-ia-share-link[hidden], .sp-ia-share-confirm[hidden] { display: none; }
.sp-ia-share-line { margin: 0; font-size: 12px; color: var(--dim); }
.sp-ia-share-link { display: flex; gap: 6px; }
.sp-ia-share-url { flex: 1 1 auto; min-width: 0; font-size: 12px; }
.sp-ia-share-confirm { display: inline-flex; gap: 6px; }
/* Slice I8: the lifetime row, as quiet as the line above it. */
.sp-ia-share-life { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dim); }
.sp-ia-share-life[hidden] { display: none; }
.sp-ia-share-lifetime { font-size: 12px; min-height: 40px; }

/* Slice I5b, seen in the 390 walk's screenshot: with Open block and Lock
   block both showing, the Space's name was cut to "Orders bc" with no sign
   it was cut. The name ellipsizes (above), and on a narrow window or a
   coarse pointer the two buttons drop to one word each. The word is drawn
   by ::after so textContent and the accessible name stay the full phrase
   (aria-label is set beside it in paintLock). */
@media (max-width: 479px), (pointer: coarse) {
  .sp-ia-open, .sp-lock { font-size: 0; }
  .sp-ia-open::after, .sp-lock::after { font-size: 13px; }
  .sp-ia-open::after { content: "Open"; }
  .sp-lock::after { content: "Lock"; }
  .sp-lock[aria-pressed="true"]::after { content: "Unlock"; }
}
