/* css/spec-building.css — BRI-5006 owns this file. Do not edit from another ticket.
 *
 * The learning board + the reflecting chips: ONE surface, two modes. Every style for that surface
 * lives HERE — never in the shared css/spec-builder.css or css/lite-form.css. See
 * SPEC-BUILDER-CONTRACT.md at the repo root.
 *
 * ===================== THE MORPH =====================
 * Building and Reflecting are not two screens, and they are not two renders either. The four slice
 * rows are built once and never destroyed; the ONLY thing that changes is `data-mode` on the board
 * root. Everything below keys off that one attribute, so the transition is the browser interpolating
 * properties on nodes that never moved — not a repaint of a new subtree. That is what makes the
 * board *become* the chips instead of being replaced by them.
 *
 * Single-theme (light). brief-homepage has no dark mode — the contract's §3 note corrects the PRD on
 * this, so there is no prefers-color-scheme block here by design (a bespoke dark mode for one tool
 * would be un-auditable against BRI-5028).
 */

.sb {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

/* `hidden` must actually hide — INCLUDING ON THE ROOT ITSELF.
 *
 * The UA sheet's [hidden] { display: none } is the WEAKEST possible rule, so ANY `display` from a
 * class beats it. Two separate bites of this, and the second is the one that matters:
 *
 *  1. DESCENDANTS. The orb (.lite-loading-orb → display:flex) and the progress line (display:flex)
 *     both carry a `display`, so el.hidden = true left them on screen and the reflecting surface
 *     rendered with a live loading orb and "0 of 4 … Reading your product" above the finished chips.
 *
 *  2. THE ROOT. `.sb` is itself `display: flex` — and the SHELL is what toggles `hidden` on this
 *     container, via showSubstate(), to hand the surface to BRI-5007. So `.sb [hidden]` (descendants)
 *     did not cover the one element whose hiding actually matters. After confirm →
 *     setSubstate('refining'), the shell set board.hidden = true and the board CARRIED ON RENDERING:
 *     computed display `flex`, full height, "Here's my read on your business." still on screen —
 *     with 5007's canvas drawn over the top of it. Caught only by driving the REAL merged shell;
 *     every unit test still passed, because `board.hidden` was `true` the whole time.
 *
 * Note the two selectors are NOT the same rule: `.sb[hidden]` (no space) is the root, `.sb [hidden]`
 * (space) is its descendants. We need both. */
.sb[hidden],
.sb [hidden] {
  display: none;
}

/* ── Heading + orb ─────────────────────────────────────────────────────────── */

.sb-orb {
  margin-bottom: var(--space-xs);
}

/* The heading is focused by the shell on entry→building. A focus ring on a heading the user never
 * clicked reads as a rendering bug, so show it only for keyboard users. */
.sb-heading:focus {
  outline: none;
}
.sb-heading:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 4px;
  border-radius: 4px;
}

/* ── Progress: described, never counted ───────────────────────────────────── */

.sb-progress {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-sm);
  margin: 0 0 var(--space-xs);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.sb-progress-count {
  flex: none;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── The board ────────────────────────────────────────────────────────────── */

.sb-board {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.sb-slice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-border-subtle);
  border-radius: 10px;
  background: var(--color-background);
  /* The morph. Both modes are the SAME element, so these interpolate rather than cut. */
  transition: border-color 0.35s ease, background-color 0.35s ease, box-shadow 0.35s ease;
}

.sb-body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0; /* let long values wrap instead of blowing out the row */
  flex: 1;
}

.sb-label {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  transition: font-size 0.35s ease, color 0.35s ease;
}

.sb-value {
  color: var(--color-text);
  overflow-wrap: anywhere; /* a long serviceDefinition must never force a horizontal scroll */
  transition: color 0.35s ease;
}

/* The row's confidence, in words.
 *
 * The contract forbids conveying confidence by colour or glyph alone, and an aria-label on the <li>
 * did NOT satisfy it: naming a plain listitem is unreliable for assistive tech, and it does nothing
 * whatsoever for a sighted user who cannot pick out the amber. This is a real, visible word — so the
 * dashed border and the amber dot become decoration reinforcing text, which is the right way round.
 * Only `soft` rows get one; an `absent` row already says "I couldn't work this out." in its value. */
.sb-flag {
  align-self: flex-start;
  margin-top: 0.15rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  font-size: var(--font-size-xs, 0.75rem);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--color-amber-dark);
  background: color-mix(in srgb, var(--color-amber) 12%, var(--color-background));
}

/* The dot is DECORATION. Every row also carries its state in text (.sb-value) and, when Brief is
 * guessing, in the .sb-flag above — the contract forbids conveying state by colour or glyph alone. */
.sb-dot {
  flex: none;
  width: 10px;
  height: 10px;
  margin-top: 0.45rem;
  border-radius: 50%;
  background: var(--color-background-muted);
  transition: background-color 0.35s ease, box-shadow 0.35s ease;
}

.sb-slice[data-state="pending"] .sb-value {
  color: var(--color-text-muted);
}
.sb-slice[data-state="pending"] .sb-dot {
  animation: sb-pulse 1.4s ease-in-out infinite;
}

.sb-slice[data-state="resolved"] .sb-dot {
  background: var(--color-accent);
}
.sb-slice[data-state="absent"] .sb-dot {
  background: var(--color-border);
}
.sb-slice[data-state="absent"] .sb-value {
  color: var(--color-text-muted);
  font-style: italic;
}

/* A slice landing is the payoff — the user is watching their own business appear. Reuse the
 * discovery stream-in feel from the teardown form rather than inventing a second motion language. */
.sb-slice[data-state="resolved"] .sb-value {
  animation: sb-value-in 0.4s ease-out;
}

@keyframes sb-pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

@keyframes sb-value-in {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

/* A resumed board is not "landing" — the work finished before the user arrived. Replaying the
 * animation would be theatre about work that is already done. */
.sb[data-resumed] .sb-slice .sb-value {
  animation: none;
}

/* ── REFLECTING: the rows become the chips ────────────────────────────────── */

.sb[data-mode="reflecting"] .sb-slice {
  background: var(--color-background-subtle);
  border-color: var(--color-border);
}

/* The label demotes to a caption and the value takes the emphasis: the row stops being a progress
 * line and becomes a fact the user is being asked to check. */
.sb[data-mode="reflecting"] .sb-label {
  font-size: var(--font-size-xs, 0.75rem);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}
.sb[data-mode="reflecting"] .sb-value {
  font-size: var(--font-size-lg, 1.125rem);
}

/* Settled = crawl-grounded. Soft = Brief is guessing (idea-first, or a null field). The colour is
 * the *second* signal; the first is the accessible name and the row's own text. */
.sb[data-mode="reflecting"] .sb-slice[data-confidence="settled"] .sb-dot {
  background: var(--color-accent);
}
.sb[data-mode="reflecting"] .sb-slice[data-confidence="soft"] {
  border-style: dashed;
  border-color: var(--color-amber);
}
.sb[data-mode="reflecting"] .sb-slice[data-confidence="soft"] .sb-dot {
  background: var(--color-amber);
}

/* ── The hero sentence (positioning — the one editable slice) ─────────────── */

.sb-sentence {
  margin: var(--space-xs) 0 0;
  font-size: var(--font-size-lg, 1.125rem);
  line-height: 1.9; /* the chips are taller than the text; give them room to breathe */
  color: var(--color-text);
}

.sb-chip {
  display: inline-flex;
  align-items: center;
  /* ≥44px touch target (contract §3, mobile is P0) without inflating the type size. */
  min-height: 44px;
  padding: 0.25rem 0.7rem;
  margin: 0 0.1rem;
  font: inherit;
  color: var(--color-text);
  background: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.sb-chip:hover {
  border-color: var(--color-primary);
}
.sb-chip:focus-visible {
  outline: none;
  border-color: var(--color-focus-ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-focus-ring) 18%, transparent);
}

/* Soft chips look unfinished ON PURPOSE — attention goes to what Brief is unsure about, not to
 * everything at once. This is the whole mechanism by which correcting feels targeted rather than
 * like unpaid QA over a wall of guesses. */
.sb-chip[data-confidence="soft"] {
  border-style: dashed;
  border-color: var(--color-amber);
  color: var(--color-amber-dark);
  background: color-mix(in srgb, var(--color-amber) 6%, var(--color-background));
}

.sb-chip[data-confidence="settled"] {
  border-color: var(--color-border);
  background: var(--color-background);
}

/* The user's own correction is the one thing on the board that is unambiguously TRUE. Show it. */
.sb-chip[data-confidence="edited"] {
  border-color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 8%, var(--color-background));
  color: var(--color-accent-dark);
  font-weight: 600;
}

/* ── Mismatch card (BRI-5000: surface + ask, never silently blend) ─────────── */

.sb-mismatch {
  padding: 0.9rem 1rem;
  border: 1px solid var(--color-amber);
  border-radius: 10px;
  background: color-mix(in srgb, var(--color-amber) 6%, var(--color-background));
}
.sb-mismatch-title {
  margin: 0 0 0.25rem;
  font-weight: 600;
  color: var(--color-amber-dark);
}
.sb-mismatch-body {
  margin: 0 0 var(--space-xs);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}
.sb-mismatch-ack {
  min-height: 44px;
}

/* ── Actions ──────────────────────────────────────────────────────────────── */

.sb-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
}

/* .lite-microcopy carries a negative margin-top tuned for text sitting under a FIELD; under a 50px
 * button it yanks the note up into the CTA and clips it (the same trap #btn-build-help hit in
 * css/spec-builder.css). Reset it here. */
.sb-note {
  margin-top: var(--space-xs);
  text-align: center;
}

.sb-recover {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  align-items: stretch;
}
.sb-restart {
  min-height: 44px;
  align-self: center;
}

/* ── The editor: one <dialog>, two skins ──────────────────────────────────── */

.sb-editor {
  width: min(28rem, calc(100vw - 2rem));
  padding: var(--space-md, 1.25rem);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background: var(--color-surface);
  box-shadow: var(--shadow-large);
  color: var(--color-text);
}

.sb-editor::backdrop {
  background: rgb(0 0 0 / 35%);
}

.sb-editor-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.sb-editor-label {
  font-weight: 600;
  font-size: var(--font-size-sm);
}

.sb-editor-input {
  width: 100%;
  box-sizing: border-box;
  min-height: 44px;
  font-family: var(--font-family-sans);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
}
.sb-editor-input:focus-visible {
  outline: none;
  border-color: var(--color-focus-ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-focus-ring) 18%, transparent);
}

/* Brief showing its working. Correcting a guess is cheap when you can see where the guess came
 * from; it is an audit when you cannot. */
.sb-editor-evidence {
  margin: 0;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.sb-editor-actions {
  display: flex;
  gap: var(--space-xs);
  align-items: center;
  margin-top: var(--space-xs);
}
.sb-editor-save {
  flex: 1;
  min-height: 44px;
}
.sb-editor-cancel {
  min-height: 44px;
}

/* ── The live region ──────────────────────────────────────────────────────── */

/* Visually hidden, but never `display: none` / `visibility: hidden` — either would stop screen
 * readers announcing it, which is the entire point of the element. */
.sb-live {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ── Mobile (P0 — SEO traffic skews mobile) ───────────────────────────────── */

@media (max-width: 768px) {
  /* Single column throughout; the rows already stack. Keep the primary action reachable without
     scrolling back up — the confirm is the whole point of the Reflecting screen. */
  .sb-actions {
    position: sticky;
    bottom: 0;
    z-index: 1;
    padding-bottom: env(safe-area-inset-bottom, 0);
    background: linear-gradient(to bottom, transparent, var(--color-background) 30%);
  }

  /* The inline editor becomes a bottom sheet: thumb-reachable, and it does not cover the chip the
     user is editing. Same element, same focus trap — only the geometry changes. */
  .sb-editor {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    border-radius: 14px 14px 0 0;
    padding-bottom: calc(var(--space-md, 1.25rem) + env(safe-area-inset-bottom, 0));
  }

  .sb-sentence {
    line-height: 2.1; /* chips wrap on narrow screens; keep the rows from colliding */
  }
}

/* ── Reduced motion (contract §3) ─────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .sb-slice,
  .sb-label,
  .sb-value,
  .sb-dot,
  .sb-chip {
    transition: none;
  }
  .sb-slice[data-state="pending"] .sb-dot,
  .sb-slice[data-state="resolved"] .sb-value {
    animation: none;
  }
}
