/* Sophia Lab: the page system (tokens, type, components, docs) and the lab's own chrome (sidebar, phone bar, dock slot).
   The frame's controls come from assets/lab-shell.css (Form Factory's lab shell, synced, never edited here).
   Chrome uses the shell's --ls-* tokens; page content keeps Sophia's own. Nav pattern follows the MIND System lab. */
:root {
  /* Brand layer for the lab shell: family and accent only */
  --lab-font: "Source Sans 3", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --lab-font-display: var(--lab-font);
  --lab-accent: #2a3ce8;

  --ink: #081030;
  --paper: #ffffff;
  --panel: #f5f6fa;
  --tint: #bfc2ef;
  --wash: #e8e9f6;
  --blue: #2a3ce8;
  --pink: #ff1f6d;
  --ink-04: rgba(8, 16, 48, .04);
  --ink-06: rgba(8, 16, 48, .06);
  --ink-08: rgba(8, 16, 48, .08);
  --ink-12: rgba(8, 16, 48, .12);
  --ink-60: rgba(8, 16, 48, .6);   /* the lightest ink for text: 5:1 on white */
  --ink-75: rgba(8, 16, 48, .75);
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --ease: cubic-bezier(.33, 0, 0, 1);
  --side: 240px;
  --bar-h: 48px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--paper); scrollbar-gutter: stable; }
body {
  color: var(--ink);
  font-family: var(--lab-font);
  font-size: 17px; line-height: 1.6; letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--ls-focus); outline-offset: 2px; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 1fr; min-height: 100dvh; }
@media (min-width: 1024px) {
  .shell { grid-template-columns: var(--side) minmax(0, 1fr); }
  .sidebar { grid-column: 1; grid-row: 1; }
  .main { grid-column: 2; grid-row: 1; }
}
/* Reserve the top bar before shell.js builds it, so nothing jumps */
@media (max-width: 1023px) { .main:not(:has(> .topbar))::before { content: ""; display: block; height: var(--bar-h); } }
.main { min-width: 0; }
/* Pages with a dock keep their last lines clear of it */
.main[data-scrubber] { padding-bottom: 120px; }

/* ---------- Sidebar: the lab's rail, in the shell's vocabulary ---------- */
.sidebar {
  view-transition-name: sidebar;
  position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(300px, calc(100vw - 48px));
  display: flex; flex-direction: column; padding: 6px 8px 16px;
  background: var(--paper); border-right: 1px solid var(--ls-line);
  overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none;
  box-shadow: 0 0 40px var(--ls-shade);
  transform: translateX(-100%); visibility: hidden;
  transition: transform var(--ls-panel) var(--ls-ease), visibility 0s linear var(--ls-panel);
}
.sidebar::-webkit-scrollbar { display: none; }
.sidebar.is-open { transform: none; visibility: visible; transition: transform var(--ls-panel) var(--ls-ease); }
@media (min-width: 1024px) {
  /* Transparent on desktop so the sliding highlight can pass beneath the text */
  .sidebar { position: sticky; top: 0; height: 100dvh; width: auto; transform: none; visibility: visible; transition: none; background: none; box-shadow: none; }
}
.scrim { position: fixed; inset: 0; z-index: 35; background: var(--ls-scrim); opacity: 0; pointer-events: none; transition: opacity var(--ls-panel) var(--ls-ease); }
.scrim.is-open { opacity: 1; pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 8px; height: 36px; min-width: 0; padding: 0 8px; border-radius: var(--ls-r-ib); text-decoration: none; font: 600 13px/18px var(--lab-font-display); letter-spacing: -.01em; color: var(--ls-fg); white-space: nowrap; }
.brand svg { width: 20px; height: 16px; flex: none; color: var(--ink); }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 4px; height: var(--bar-h); margin-bottom: 12px; }
.side-tools { display: flex; align-items: center; gap: 2px; flex: none; }

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a {
  position: relative; isolation: isolate;
  display: grid; grid-template-columns: 36px minmax(0, 1fr); align-items: center;
  height: 30px; padding: 0 8px; border-radius: var(--ls-r-sm); text-decoration: none; color: var(--ls-muted);
  transition: background-color var(--ls-state) var(--ls-ease), color var(--ls-state) var(--ls-ease);
}
.nav a[aria-current="page"] { color: var(--ls-fg); }
.nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav a .n { position: relative; padding-left: 14px; font-size: 11px; font-variant-numeric: tabular-nums; color: var(--ls-muted); }
.nav a[aria-current="page"] .n { color: var(--ls-fg); }
/* The current item's highlight and dot are real elements so they slide between pages. The dot is Electric Blue. */
.nav-bg { position: absolute; inset: 0; z-index: -1; border-radius: var(--ls-r-sm); background: var(--ls-chip); view-transition-name: nav-bg; }
.nav-mark { position: absolute; left: 0; top: 50%; width: 7px; height: 7px; margin-top: -3.5px; border-radius: 50%; background: var(--lab-accent); view-transition-name: nav-mark; }

.sidebar .nav-group {
  display: flex; width: 100%; height: 24px; align-items: center; justify-content: space-between;
  margin-top: 14px; padding: 0 8px; border-radius: var(--ls-r-sm);
  font-size: 11px; line-height: 16px; color: var(--ls-muted); text-align: left;
}
.nav-count { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.nav-count svg { width: 12px; height: 12px; color: var(--ls-faint); transition: transform var(--ls-state) var(--ls-ease); }
.nav-fold[aria-expanded="true"] .nav-count svg { transform: rotate(90deg); }

/* On-page sections sit under the current item, with an indicator that follows the scroll */
.subnav { position: relative; margin: 2px 0 6px 30px; display: flex; flex-direction: column; border-left: 1px solid var(--ls-line); }
.subnav a { display: block; padding: 5px 12px; font-size: 12px; line-height: 16px; color: var(--ls-muted); text-decoration: none; transition: color var(--ls-state) var(--ls-ease); }
.subnav a.is-active { color: var(--ls-fg); }
.subnav-ind {
  position: absolute; left: -1.5px; top: 0; width: 2px; height: 0; border-radius: 2px; background: var(--ls-fg);
  opacity: 0; pointer-events: none;
  transition: transform .3s var(--ls-ease), height .3s var(--ls-ease), opacity .2s linear;
}
.subnav-ind.is-on { opacity: 1; }

/* Foot: Decimal gets the Internal / Client view switch; everyone gets Sign out */
.side-foot { margin-top: auto; padding: 24px 2px 0 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 56px; font-size: 12px; line-height: 16px; color: var(--ls-muted); }
.signout { margin-left: auto; }
.signout button { padding: 6px; border-radius: var(--ls-r-sm); font-size: 12px; line-height: 16px; color: var(--ls-muted); }
.side-foot .view-seg button { padding: 0 10px; }

/* Client view (Sophia, or Decimal previewing her view): no Decimal-only pages, no notes */
[data-view="client"] .nav-internal, [data-view="client"] .m-notes { display: none; }
.view-flag { margin-left: auto; padding: 0 8px; height: 24px; display: inline-flex; align-items: center; border-radius: 12px; background: var(--ls-chip); font-size: 12px; color: var(--ls-fg); white-space: nowrap; }
.view-flag + .side-tools { margin-left: 4px; }

@media (hover: hover) and (pointer: fine) {
  .nav a:hover, .brand:hover { background: var(--ls-chip); color: var(--ls-fg); }
  .nav-fold:hover, .subnav a:hover { color: var(--ls-fg); }
  .signout button:hover { color: var(--ls-fg); }
}

/* ---------- Top bar (phones and tablets): pages, wordmark, commands ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--bar-h); padding: 0 6px;
  display: flex; align-items: center; gap: 2px;
  background: rgba(255, 255, 255, .9); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--ls-line);
}
.topbar .side-tools { margin-left: auto; }
@media (min-width: 1024px) { .topbar { display: none; } }

/* ---------- Dock slot: the shell's dock floats over the content column, not the sidebar ---------- */

/* The shell's dock and toast sit under the phone drawer and its scrim */
.ls-dock.ls-dock-fixed, .ls-toast.ls-toast-fixed { z-index: 30; }

/* ---------- Shared components (every page uses these) ---------- */
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px); }
.kicker { font: 400 12px/18px var(--mono); color: var(--ink-60); }
.h1 { font-size: clamp(40px, 5.6vw, 64px); line-height: 1; font-weight: 600; letter-spacing: -.025em; }
.h2 { font-size: clamp(30px, 3.8vw, 44px); line-height: 1.12; font-weight: 600; letter-spacing: -.02em; }
.h3 { font-size: clamp(22px, 2.2vw, 28px); line-height: 1.3; font-weight: 600; letter-spacing: -.01em; }
.sub { color: var(--ink-60); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 20px; border-radius: 40px; border: 0;
  font: 600 14px/1 inherit; font-family: inherit; text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background-color .15s ease, transform .15s var(--ease);
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: #1b2556; transition-duration: 0s; }
.btn-soft { background: var(--ink-04); color: var(--ink); }
.btn-soft:hover { background: var(--ink-08); transition-duration: 0s; }
.btn-sm { height: 34px; padding: 0 14px; font-size: 13px; }
.page-head { padding: 48px clamp(16px, 4vw, 40px) 28px; display: flex; align-items: end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head .kicker { margin-bottom: 12px; }
.page-head p.sub { margin-top: 8px; max-width: 62ch; }
.block { padding: 0 clamp(16px, 4vw, 40px); }
.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 24px; padding: 32px clamp(16px, 4vw, 40px) 72px; font-size: 15px; line-height: 1.5; }
.meta dt { font: 400 11px/1 var(--mono); color: var(--ink-60); margin-bottom: 8px; }
.meta dd { color: var(--ink-75); }


/* ---------- Docs (team notes rendered from markdown) ---------- */
.doc { max-width: 760px; padding: 64px clamp(16px, 5vw, 64px) 120px; }
.doc .kicker { font: 400 12px/18px var(--mono); color: var(--ink-60); margin-bottom: 14px; }
.doc h1 { font-size: clamp(32px, 4vw, 44px); line-height: 1.08; font-weight: 600; letter-spacing: -.025em; margin-bottom: 12px; }
.doc .lede { color: var(--ink-60); margin-bottom: 40px; }
.doc h2 { font-size: 24px; line-height: 1.25; font-weight: 600; letter-spacing: -.015em; margin: 56px 0 14px; padding-top: 24px; border-top: 1px solid var(--ink-08); scroll-margin-top: 72px; }
.doc h3 { font-size: 18px; font-weight: 600; margin: 32px 0 8px; scroll-margin-top: 72px; }
.doc h4 { font-size: 15px; font-weight: 500; margin: 24px 0 6px; }
.doc p, .doc ul, .doc ol, .doc table, .doc pre, .doc blockquote { margin-bottom: 14px; }
.doc ul, .doc ol { padding-left: 20px; }
.doc li { margin-bottom: 6px; }
.doc li > ul, .doc li > ol { margin: 6px 0 0; }
.doc strong { font-weight: 600; }
.doc code { font: 400 .88em/1.4 var(--mono); background: var(--ink-04); padding: 1px 5px; border-radius: 4px; }
.doc pre { background: var(--ink-04); padding: 14px 16px; border-radius: 6px; overflow-x: auto; }
.doc pre code { background: none; padding: 0; }
.doc blockquote { border-left: 2px solid var(--tint); padding-left: 14px; color: var(--ink-75); }
.doc .tbl { overflow-x: auto; margin-bottom: 14px; }
.doc table { border-collapse: collapse; font-size: 14px; line-height: 1.45; width: 100%; }
.doc th, .doc td { text-align: left; vertical-align: top; padding: 8px 12px 8px 0; border-bottom: 1px solid var(--ink-08); }
.doc th { font-weight: 500; color: var(--ink-60); }
.doc hr { border: 0; border-top: 1px solid var(--ink-08); margin: 32px 0; }
.doc .loading { color: var(--ink-60); font: 400 13px/1 var(--mono); }

/* ---------- Page transitions ----------
   Same-origin navigations: the sidebar holds still, the highlight and dot slide to the new item,
   the new page fades in over the old one. */
@view-transition { navigation: auto; }
::view-transition-group(*) { animation-duration: .4s; animation-timing-function: var(--ease); }
::view-transition-old(root) { animation: none; }
::view-transition-new(root) { animation: vt-in .22s var(--ease) both; }
::view-transition-old(sidebar) { display: none; }
::view-transition-new(sidebar) { animation: none; }
::view-transition-group(nav-bg) { z-index: 1; }
::view-transition-group(sidebar) { z-index: 2; }
::view-transition-group(nav-mark) { z-index: 3; }
@keyframes vt-in { from { opacity: 0; } }
@media (max-width: 1023px) { .sidebar, .nav-bg, .nav-mark { view-transition-name: none; } }

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  *, *::before, *::after { transition-duration: .001ms !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}
