/* ==========================================================================
   Prototype chrome — device frames, prototype bar, toaster, tour.
   Structural, brand-neutral. Copy into <POC>/assets/css/components.css and
   re-skin with the project's tokens. Requires the token contract.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Phone. A fixed 390x844 canvas scaled to always fit the viewport, so the
   whole device is visible without scrolling the browser. On a real handset
   the frame disappears and the app fills the screen.
   -------------------------------------------------------------------------- */
.phone-stage {
  --phone-fit: 1;
  height: 100dvh; overflow: hidden;
  display: grid; grid-template-columns: auto; place-content: center; place-items: center;
  column-gap: var(--s-10);
  padding: var(--s-4) var(--gutter) calc(var(--pocbar-h) + var(--s-4));
  background: var(--surface-2);
}
.phone {
  position: relative; flex: none;
  width: 390px; height: 844px;
  transform: scale(var(--phone-fit)); transform-origin: center;
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  border: 10px solid var(--device); border-radius: 46px;
  box-shadow: var(--elev-modal);
  overflow: hidden;
}
.phone::before {                      /* notch */
  content: ''; position: absolute; left: 50%; top: 10px; transform: translateX(-50%);
  width: 120px; height: 34px; background: var(--device); border-radius: 20px; z-index: 5;
}
.phone-status {
  display: flex; align-items: center; justify-content: space-between;
  height: 54px; padding: 12px 28px 0; font-size: var(--t-14); font-weight: 600; flex: none;
}
.phone-scroll {
  flex: 1; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain;
  scrollbar-width: none; position: relative; display: flex; flex-direction: column;
}
.phone-scroll::-webkit-scrollbar { display: none; }
.phone-scroll > * { flex-shrink: 0; }   /* or horizontal card rows collapse */
.phone-tabbar {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  height: 84px; padding: 8px 8px 24px; flex: none;
  border-top: 1px solid var(--line); background: var(--surface);
}
.phone-tabbar a {
  position: relative; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  font-size: 10.5px; font-weight: 600; color: var(--muted);
  border-radius: var(--r-ctl); min-height: 44px; text-decoration: none;
}
.phone-tabbar a .ico { width: 24px; height: 24px; }
.phone-tabbar a[aria-current="page"] { color: var(--primary); }
.phone-home {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%);
  width: 134px; height: 5px; border-radius: 3px; background: var(--ink); opacity: .9; z-index: 4;
}
.phone { --app-gutter: var(--s-4); }

/* The narration column beside the device: what this screen proves. */
.phone-caption {
  display: none; align-self: center; max-width: 34ch; text-align: left;
  font-size: var(--t-14); line-height: 1.55; color: var(--ink-2);
}
.phone-caption strong {
  display: block; color: var(--ink); font-family: var(--font-display);
  font-size: var(--t-18); font-weight: 600; margin-bottom: var(--s-2);
}
@media (min-width: 1100px) {
  .phone-stage { grid-template-columns: auto minmax(260px, 34ch); }
  .phone-caption { display: block; }
}

/* Step the scale down so the device always fits the window height. */
@media (max-height: 940px) { .phone-stage { --phone-fit: .95; } }
@media (max-height: 880px) { .phone-stage { --phone-fit: .90; } }
@media (max-height: 820px) { .phone-stage { --phone-fit: .84; } }
@media (max-height: 770px) { .phone-stage { --phone-fit: .78; } }
@media (max-height: 700px) { .phone-stage { --phone-fit: .72; } }
@media (max-height: 640px) { .phone-stage { --phone-fit: .66; } }

/* On an actual handset the app IS the page. The frame, notch, status bar and
   home indicator disappear; the app fills the screen minus the prototype bar. */
@media (max-width: 600px) {
  .phone-stage { --phone-fit: 1; padding: 0; height: 100dvh; grid-template-columns: 1fr; background: var(--bg); }
  .phone { width: 100%; height: 100dvh; border: 0; border-radius: 0; box-shadow: none; transform: none; }
  .phone::before, .phone-status, .phone-home { display: none; }
  .phone-caption { display: none; }
  /* The bar is fixed over the viewport, so the app must give up its height or
     the tab bar hides behind it. */
  body.has-pocbar .phone-stage,
  body.has-pocbar .phone { height: calc(100dvh - var(--pocbar-h)); }
  .phone-tabbar { padding-bottom: 8px; height: 64px; }
}

/* --------------------------------------------------------------------------
   Tablet — staff-facing landscape surfaces (kitchen display, POS, field app).
   -------------------------------------------------------------------------- */
.tablet-stage {
  display: flex; flex-direction: column; align-items: center; gap: var(--s-4);
  padding: var(--s-8) var(--gutter) calc(var(--pocbar-h) + var(--s-10));
  min-height: 100dvh; background: var(--surface-3);
}
.tablet {
  --tablet-fit: 1;
  position: relative; width: 1024px; height: 768px;
  transform: scale(var(--tablet-fit)); transform-origin: top center;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg); border: 12px solid var(--device); border-radius: 28px;
  box-shadow: 0 40px 80px -24px rgb(0 0 0 / 0.35);
}
.tablet-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
@media (max-width: 1140px) { .tablet-stage { --tablet-fit: .82; } }
@media (max-width: 940px)  { .tablet-stage { --tablet-fit: .66; } }
@media (max-width: 760px)  { .tablet-stage { --tablet-fit: .50; } }

/* --------------------------------------------------------------------------
   Bottom sheet — the mobile-native alternative to a modal.
   -------------------------------------------------------------------------- */
.sheet-scrim {
  position: absolute; inset: 0; z-index: var(--z-layer);
  background: rgb(0 0 0 / 0.4); opacity: 0; pointer-events: none;
  transition: opacity var(--dur-2) var(--ease);
}
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: calc(var(--z-layer) + 1);
  max-height: 82%; display: flex; flex-direction: column;
  background: var(--bg); border-radius: var(--r-lg) var(--r-lg) 0 0;
  transform: translateY(100%); transition: transform var(--dur-3) var(--ease-out);
}
.sheet::before {
  content: ''; width: 36px; height: 4px; border-radius: 2px; background: var(--line-strong);
  margin: 10px auto 2px; flex: none;
}
.sheet-body { overflow-y: auto; padding: var(--s-4) var(--app-gutter) var(--s-6); }
.layer-open .sheet-scrim { opacity: 1; pointer-events: auto; }
.layer-open .sheet { transform: translateY(0); }

/* In-frame push notification — lands every time in a demo. */
.push {
  position: absolute; left: 8px; right: 8px; top: 58px; z-index: var(--z-toast);
  display: flex; gap: var(--s-3); padding: var(--s-3) var(--s-4);
  background: var(--bg); border-radius: var(--r-card); box-shadow: var(--e-3);
  transform: translateY(-140%); transition: transform var(--dur-3) var(--ease-out);
}
.push.in { transform: translateY(0); }

/* --------------------------------------------------------------------------
   Prototype bar — the client's remote control, on every page.
   -------------------------------------------------------------------------- */
.pocbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-pocbar);
  height: var(--pocbar-h); display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-4); font-size: var(--t-12);
  background: var(--drench); color: var(--on-drench);
  box-shadow: 0 -4px 20px rgb(0 0 0 / 0.2);
}
.pocbar .tagword {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .12em;
  color: var(--accent); font-weight: 500;
}
.pocbar .roles { display: flex; gap: 2px; }
.pocbar .roles a {
  padding: 4px 10px; border-radius: var(--r-full); color: var(--on-drench-muted);
  text-decoration: none; white-space: nowrap;
}
.pocbar .roles a:hover { color: var(--on-drench); background: var(--drench-2); }
.pocbar .roles a[aria-current="true"] { background: var(--primary); color: var(--on-primary); }
.pocbar .mods { display: flex; gap: 4px; }
.pocbar .tag-module {
  font-family: var(--font-mono); font-size: 10px; padding: 2px 6px;
  border: 1px solid var(--drench-line); border-radius: var(--r-full);
  color: var(--on-drench-muted); text-decoration: none;
}
.pocbar .spacer { flex: 1; }
.pocbar .link {
  background: none; border: 0; color: var(--on-drench-muted);
  font: inherit; cursor: pointer; padding: 4px 6px; white-space: nowrap;
}
.pocbar .link:hover { color: var(--on-drench); }
body.has-pocbar { padding-bottom: 0; }
body.web.has-pocbar, body.ds.has-pocbar { padding-bottom: var(--pocbar-h); }
/* Never let the bar clip its own controls: let it scroll instead. */
.pocbar { overflow-x: auto; scrollbar-width: none; }
.pocbar::-webkit-scrollbar { display: none; }
.pocbar > * { flex: none; }
.pocbar .spacer { flex: 1 0 var(--s-4); }
@media (max-width: 1180px) { .pocbar .mods { display: none; } }
@media (max-width: 720px) { .pocbar .hide-sm { display: none; } }
@media (max-width: 420px) { .pocbar .tagword { display: none; } }

/* --------------------------------------------------------------------------
   Toaster
   -------------------------------------------------------------------------- */
.toaster {
  position: fixed; right: var(--s-4); bottom: calc(var(--pocbar-h) + var(--s-4));
  z-index: var(--z-toast); display: flex; flex-direction: column-reverse;
  gap: var(--s-2); pointer-events: none;
}
body:not(.has-pocbar) .toaster { bottom: var(--s-4); }
.toast {
  max-width: 42ch; padding: var(--s-3) var(--s-4);
  background: var(--drench); color: var(--on-drench);
  border-radius: var(--r-ctl); box-shadow: var(--e-3);
  font-size: var(--t-14); animation: toast-in var(--dur-3) var(--ease-out);
}
.toast.ok { background: var(--success); } .toast.warn { background: var(--warning); color: var(--on-accent); }
.toast.err { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --------------------------------------------------------------------------
   Guided tour
   -------------------------------------------------------------------------- */
.tour-scrim { position: fixed; inset: 0; z-index: var(--z-tour); background: rgb(0 0 0 / 0.55); }
.tour-hole { position: fixed; z-index: calc(var(--z-tour) + 1); border-radius: var(--r-card);
  box-shadow: 0 0 0 9999px rgb(0 0 0 / 0.55), 0 0 0 3px var(--accent); pointer-events: none; }
.tour-pop {
  position: fixed; z-index: calc(var(--z-tour) + 2); max-width: 34ch;
  padding: var(--s-4); background: var(--bg); color: var(--ink);
  border-radius: var(--r-card); box-shadow: var(--e-3);
}
.tour-pop .step { font-family: var(--font-mono); font-size: var(--t-11); color: var(--muted); }
.tour-pop h3 { font-size: var(--t-16); margin: var(--s-1) 0 var(--s-2); }
.tour-pop p { font-size: var(--t-14); line-height: 1.5; color: var(--ink-2); }
.tour-pop .tour-row { display: flex; flex-wrap: wrap; gap: var(--s-2); justify-content: flex-end; margin-top: var(--s-4); }
.tour-pop .tour-row .btn-ghost { margin-right: auto; }
.tour-pop .tour-do { margin-top: var(--s-3); }
body.touring .tour-pop { right: var(--s-4); bottom: calc(var(--pocbar-h) + var(--s-4)); width: min(380px, calc(100vw - 2 * var(--s-4))); max-width: none; animation: toast-in var(--dur-3) var(--ease-out); }
body.touring:not(.has-pocbar) .tour-pop { bottom: var(--s-4); }
body.touring .toaster { right: auto; left: var(--s-4); }
.tour-spot { outline: 3px solid var(--coral); outline-offset: 3px; animation: spot 1.6s var(--ease) 3; }
@keyframes spot { 50% { outline-offset: 7px; } }
@media (max-width: 600px) {
  body.touring .tour-pop { right: var(--s-2); left: var(--s-2); width: auto; bottom: calc(var(--pocbar-h) + var(--s-2)); padding: var(--s-3) var(--s-4); }
  .tour-pop p { font-size: var(--t-13); }
}
@media (prefers-reduced-motion: reduce) { .tour-spot, body.touring .tour-pop { animation: none; } }

/* Section reveal — set by prototype.js, off under reduced motion. */
.rv.pre { opacity: 0; transform: translateY(14px); }
.rv.in  { opacity: 1; transform: none; transition: opacity var(--dur-3) var(--ease-out), transform var(--dur-3) var(--ease-out); }

/* Accessibility floor */
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 999;
  padding: var(--s-3) var(--s-4); background: var(--primary); color: var(--on-primary);
}
.skip-link:focus { left: 0; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ==========================================================================
   KITH COMPONENTS · Direction 3, "Your People".
   Every radius, rule, shadow, height and padding reads from tokens.css.
   Two registers: BRAND (landing, onboarding, the member app's warm moments)
   may tilt, tape and hand-write; PRODUCT (ops console, settings, safety) sits
   square and plain.
   ========================================================================== */

/* ---- Buttons ----------------------------------------------------------- */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--h-ctl); padding: 0 var(--s-5);
  border: var(--bw-strong) solid var(--primary); border-radius: var(--r-ctl);
  background: var(--primary); color: var(--on-primary); box-shadow: var(--press);
  font: 600 var(--t-16)/1 var(--font-body); text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: transform var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), background-color var(--dur-2) var(--ease);
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 3px 0 var(--primary-strong); text-decoration: none; }
.btn:active { transform: translateY(2px); box-shadow: 0 0 0 var(--primary-strong); }
.btn .ico { width: 18px; height: 18px; }
.btn-secondary { background: var(--bg); color: var(--ink); border-color: var(--ink); box-shadow: var(--press-soft); }
.btn-secondary:hover { box-shadow: 0 3px 0 var(--ink); }
.btn-sea { background: var(--accent); color: var(--on-accent); border-color: var(--ink); box-shadow: var(--press-soft); }
.btn-ghost { background: transparent; color: var(--ink); border-color: transparent; box-shadow: none; padding-inline: var(--s-3); }
.btn-ghost:hover { background: var(--surface-2); box-shadow: none; transform: none; }
.btn-danger { background: var(--danger); border-color: var(--danger-ink); color: var(--on-primary); box-shadow: 0 2px 0 var(--danger-ink); }
.btn-sm { min-height: var(--h-ctl-sm); padding: 0 var(--s-4); font-size: var(--t-14); }
.btn-lg { min-height: 56px; padding: 0 var(--s-6); font-size: var(--t-18); }
.btn-block { width: 100%; white-space: normal; line-height: 1.25; padding-block: 10px; }
.btn-icon { width: var(--h-ctl); padding: 0; }
.btn-icon.btn-sm { width: var(--h-ctl-sm); }
.btn:disabled, .btn[aria-disabled="true"] {
  background: var(--surface-2); color: var(--muted); border-color: var(--line-strong);
  box-shadow: none; transform: none; cursor: not-allowed;
}
.btn.is-loading { color: transparent; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--on-primary); border-right-color: transparent; animation: spin .7s linear infinite;
}
.btn-secondary.is-loading::after { border-color: var(--ink); border-right-color: transparent; }
.spin { display: inline-block; width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.link-btn { padding: 0; border: 0; background: none; font: inherit; font-weight: 600; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; min-height: 44px; }

/* ---- Fields ------------------------------------------------------------ */
.field { display: grid; gap: var(--s-2); align-content: start; }
.label { font-weight: 600; font-size: var(--t-15); color: var(--ink); }
.hint { font-size: var(--t-14); color: var(--muted); margin: 0; }
.input, .select, .textarea {
  width: 100%; min-height: var(--h-ctl); padding: 0 var(--s-4);
  background: var(--bg); color: var(--ink); font-size: var(--t-16);
  border: var(--bw-strong) solid var(--line-strong); border-radius: var(--r-ctl);
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--muted-2); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft-2); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); color: var(--muted); border-color: var(--line); cursor: not-allowed; }
.textarea { min-height: 112px; padding: var(--s-3) var(--s-4); line-height: 1.5; resize: vertical; }
.select {
  appearance: none; padding-right: 44px;
  background: linear-gradient(45deg, transparent 50%, var(--ink) 50%) calc(100% - 22px) 52% / 7px 7px no-repeat,
              linear-gradient(135deg, var(--ink) 50%, transparent 50%) calc(100% - 15px) 52% / 7px 7px no-repeat, var(--bg);
}
.field.is-error .input, .field.is-error .select, .field.is-error .textarea { border-color: var(--danger); }
.field.is-error .input:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
.err { display: flex; gap: var(--s-2); align-items: flex-start; margin: 0; font-size: var(--t-14); color: var(--danger-ink); font-weight: 500; }
.err .ico { width: 16px; height: 16px; margin-top: 2px; }
.search { position: relative; align-self: start; }
.search > .ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-left: 44px; }
.check { display: inline-flex; align-items: center; gap: var(--s-3); min-height: 44px; cursor: pointer; font-size: var(--t-16); }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--primary); cursor: pointer; }
.switch { display: inline-flex; align-items: center; gap: var(--s-3); min-height: 44px; cursor: pointer; }
.switch input {
  appearance: none; position: relative; width: 48px; height: 28px; margin: 0; flex: none; cursor: pointer;
  border-radius: var(--r-full); background: var(--line-strong); transition: background-color var(--dur-2) var(--ease);
}
.switch input::before {
  content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--bg); box-shadow: var(--e-1); transition: transform var(--dur-2) var(--ease-out);
}
.switch input:checked { background: var(--primary); }
.switch input:checked::before { transform: translateX(20px); }
.switch input:disabled { opacity: .5; cursor: not-allowed; }
.seg { display: inline-flex; padding: 4px; gap: 2px; background: var(--surface-2); border-radius: var(--r-ctl); }
.seg button {
  min-height: 38px; padding: 0 var(--s-4); border: 0; border-radius: calc(var(--r-ctl) - 2px);
  background: transparent; color: var(--muted); font-weight: 600; font-size: var(--t-14); cursor: pointer;
  transition: background-color var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--ink); box-shadow: var(--e-1); }
.drop {
  display: grid; justify-items: center; gap: var(--s-2); padding: var(--s-6) var(--s-4); text-align: center;
  border: var(--bw-strong) dashed var(--line-strong); border-radius: var(--r-card); color: var(--muted); cursor: pointer;
  transition: border-color var(--dur-1) var(--ease), background-color var(--dur-1) var(--ease);
}
.drop strong { color: var(--ink); }
.drop:hover, .drop.is-over { border-color: var(--primary); background: var(--primary-soft); }

/* ---- Status pills: states only, always icon + word --------------------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 26px; padding: 0 10px 0 8px;
  border-radius: var(--r-full); background: var(--surface-2); color: var(--ink-2);
  font-size: var(--t-13); font-weight: 600; line-height: 1; white-space: nowrap;
}
.pill .ico { width: 14px; height: 14px; }
.pill.ok   { background: var(--success-soft); color: var(--success-ink); }
.pill.warn { background: var(--warning-soft); color: var(--warning-ink); }
.pill.bad  { background: var(--danger-soft);  color: var(--danger-ink); }
.pill.info { background: var(--info-soft);    color: var(--info-ink); }
.pill.brand { background: var(--primary-soft-2); color: var(--ink); }
.pill.quiet { background: transparent; box-shadow: inset 0 0 0 1px var(--line-strong); color: var(--muted); }

/* ---- Paper surfaces ---------------------------------------------------- */
.card {
  background: var(--bg); border-radius: var(--r-card); padding: var(--pad-card);
  box-shadow: var(--elev-card), 0 0 0 1px oklch(0.27 0.07 258 / 0.06);
}
.card-flat { background: var(--surface); border-radius: var(--r-card); padding: var(--pad-card); }
.tilt { transform: rotate(var(--tilt, var(--tilt-1))); }
.taped { position: relative; }
.taped::before {
  content: ""; position: absolute; top: -10px; left: 50%; width: 76px; height: 22px; z-index: 1;
  background: var(--tape); transform: translateX(-50%) rotate(-4deg);
}

/* ---- Tables (product register) ------------------------------------------ */
.table-wrap { overflow-x: auto; background: var(--bg); border-radius: var(--r-card); box-shadow: var(--elev-card), 0 0 0 1px oklch(0.27 0.07 258 / 0.06); }
.table { width: 100%; font-size: var(--t-15); }
.table th {
  height: 42px; padding: 0 var(--s-4); text-align: left; white-space: nowrap;
  font-size: var(--t-13); font-weight: 700; color: var(--muted); border-bottom: var(--rule-strong);
}
.table td { height: var(--h-row-dense); padding: var(--s-2) var(--s-4); border-bottom: var(--row-rule); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color var(--dur-1) var(--ease); }
.table tbody tr:hover { background: var(--surface); }
.table tbody tr[aria-selected="true"] { background: var(--primary-soft); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .cb { width: 44px; padding-right: 0; }
.table .cb input:not([role="switch"]) { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.sort { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; }
.sort .ico { width: 14px; height: 14px; }
.sort[aria-sort="ascending"], .sort[aria-sort="descending"] { color: var(--ink); }
.bulkbar {
  display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-4);
  background: var(--drench); color: var(--on-drench); font-size: var(--t-14); font-weight: 600;
}
.bulkbar .btn { min-height: var(--h-ctl-sm); padding: 0 var(--s-3); font-size: var(--t-14); background: var(--drench-2); border-color: var(--drench-line); box-shadow: none; color: var(--on-drench); }
.bulkbar .spacer { flex: 1; }

/* ---- Rows, tabs, accordion -------------------------------------------- */
.row { display: flex; align-items: center; gap: var(--s-3); min-height: var(--h-row); padding: var(--s-3) 0; border-bottom: var(--rule-tear); text-decoration: none; color: inherit; }
.row .meta { display: block; font-size: var(--t-14); color: var(--muted); }
.row .chev { margin-left: auto; color: var(--muted); }
a.row:hover .chev { color: var(--ink); transform: translateX(2px); transition: transform var(--dur-1) var(--ease); }
.tabs { display: flex; gap: var(--s-1); border-bottom: var(--rule); overflow-x: auto; scrollbar-width: none; }
.tabs button {
  position: relative; flex: none; min-height: 46px; padding: 0 var(--s-4); border: 0; background: none;
  font-weight: 600; font-size: var(--t-15); color: var(--muted); cursor: pointer;
}
.tabs button::after {
  content: ""; position: absolute; left: var(--s-3); right: var(--s-3); bottom: -1px; height: 3px; border-radius: 2px;
  background: var(--ink); transform: scaleX(0); transition: transform var(--dur-2) var(--ease-out);
}
.tabs button[aria-selected="true"] { color: var(--ink); }
.tabs button[aria-selected="true"]::after { transform: scaleX(1); }
.acc { border-bottom: var(--rule); }
.acc summary {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  min-height: 56px; list-style: none; cursor: pointer; font-weight: 700; font-size: var(--t-16);
}
.acc summary::-webkit-details-marker { display: none; }
.acc summary .ico { transition: transform var(--dur-2) var(--ease); }
.acc[open] summary .ico { transform: rotate(180deg); }
.acc > div { padding: 0 0 var(--s-4); color: var(--ink-2); }

/* ---- Layers: modal, drawer, tooltip, popover, toast -------------------- */
dialog.modal {
  width: calc(100% - 32px); max-width: 520px; padding: 0; border: 0; border-radius: var(--r-lg);
  background: var(--bg); color: var(--ink); box-shadow: var(--elev-modal);
}
dialog.modal::backdrop { background: oklch(0.22 0.06 258 / 0.45); }
dialog.modal[open] { animation: settle var(--dur-3) var(--ease-out); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); padding: var(--s-5) var(--s-5) 0; }
.modal-head h2 { font-size: var(--t-22); margin: 0; letter-spacing: -0.02em; }
.modal-body { padding: var(--s-3) var(--s-5) var(--s-5); color: var(--ink-2); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-4) var(--s-5); border-top: var(--rule); }
.drawer-scrim { position: fixed; inset: 0; z-index: var(--z-layer); background: oklch(0.22 0.06 258 / 0.35); opacity: 0; pointer-events: none; transition: opacity var(--dur-2) var(--ease); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: calc(var(--z-layer) + 1); width: min(440px, 100%);
  display: flex; flex-direction: column; background: var(--bg); box-shadow: var(--elev-modal);
  transform: translateX(100%); transition: transform var(--dur-3) var(--ease-out);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s-4) var(--s-5); border-bottom: var(--rule); }
.drawer-head h2 { font-size: var(--t-22); margin: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--s-5); }
.drawer-open .drawer { transform: none; }
.drawer-open .drawer-scrim { opacity: 1; pointer-events: auto; }
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 8px); z-index: var(--z-toast);
  padding: 6px 10px; border-radius: 4px; background: var(--drench); color: var(--on-drench);
  font: 500 var(--t-13)/1.3 var(--font-body); white-space: nowrap; pointer-events: none;
  opacity: 0; transform: translate(-50%, 4px); transition: opacity var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }
.popover {
  margin: 0; inset: auto; padding: var(--s-3); min-width: 240px; border: 0; border-radius: var(--r-card);
  background: var(--bg); color: var(--ink); box-shadow: var(--elev-pop), 0 0 0 1px oklch(0.27 0.07 258 / 0.08);
}
.popover a, .popover button.item { display: flex; align-items: center; gap: var(--s-2); width: 100%; min-height: 40px; padding: 0 var(--s-2); border: 0; border-radius: 4px; background: none; text-decoration: none; font-size: var(--t-15); cursor: pointer; text-align: left; }
.popover a:hover, .popover button.item:hover { background: var(--surface-2); }
.toast { display: flex; gap: var(--s-2); align-items: flex-start; }
.toast.ok { background: var(--success-ink); }
.toast.err { background: var(--danger-ink); }

/* ---- Navigation -------------------------------------------------------- */
.topnav { position: sticky; top: 0; z-index: var(--z-sticky); background: var(--bg); border-bottom: var(--rule); }
.topnav .in { display: flex; align-items: center; gap: var(--s-5); min-height: 64px; }
.brandmark { display: inline-flex; align-items: center; gap: var(--s-2); font: 800 var(--t-22)/1 var(--font-display); letter-spacing: -0.03em; color: var(--ink); text-decoration: none; }
.brandmark svg { width: 34px; height: 26px; fill: currentColor; }
.topnav nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.topnav nav a {
  display: inline-flex; align-items: center; gap: var(--s-2); min-height: 40px; padding: 0 var(--s-3);
  border-radius: var(--r-ctl); color: var(--muted); font-weight: 600; font-size: var(--t-15); text-decoration: none; white-space: nowrap;
}
.topnav nav a:hover { color: var(--ink); background: var(--surface); }
.topnav nav a[aria-current="page"] { color: var(--ink); background: var(--surface-2); }
.topnav .who { margin-left: auto; display: flex; align-items: center; gap: var(--s-2); font-size: var(--t-14); }
.phone-tabbar { background: var(--bg); border-top: var(--rule-tear); }
.phone-tabbar a { color: var(--muted); font-size: 11px; }
.phone-tabbar a[aria-current="page"] { color: var(--ink); font-weight: 800; }
.phone-tabbar a[aria-current="page"]::after { content: ""; position: absolute; top: 2px; width: 5px; height: 5px; border-radius: 50%; background: var(--coral); }
.phone-tabbar .badge { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--ink); color: var(--on-primary); font-size: 11px; line-height: 18px; text-align: center; }

/* ==========================================================================
   DOMAIN COMPONENTS
   ========================================================================== */

/* Stamp: identity for a person, a companion or a moment. Perforated edge. */
.stamp {
  --sc: var(--sea); --stbg: var(--bg); --perf: 11px; --sw: 64px;
  position: relative; display: inline-block; flex: none; width: var(--sw); aspect-ratio: 4 / 5;
  padding: calc(var(--perf) * 0.55);
  background: radial-gradient(circle, var(--stbg) calc(var(--perf) * 0.27), transparent calc(var(--perf) * 0.3))
              calc(var(--perf) * -0.5) calc(var(--perf) * -0.5) / var(--perf) var(--perf), var(--sc);
}
.stamp > span {
  display: grid; place-items: center; width: 100%; height: 100%; background: var(--sc);
  outline: 1.5px solid oklch(1 0 0 / 0.55); outline-offset: -4px;
  font: 800 calc(var(--sw) * 0.32)/1 var(--font-display); color: var(--ink);
}
.stamp svg { width: 72%; height: auto; fill: var(--ink); }
.stamp.sm { --sw: 40px; --perf: 7px; }
.stamp.lg { --sw: 104px; --perf: 14px; }
.stamp.sea { --sc: var(--sea); } .stamp.sun { --sc: var(--sun); } .stamp.coral { --sc: var(--coral); }
.stamp.paper { --sc: var(--primary-soft-2); }
.stamp.ink { --sc: var(--ink); } .stamp.ink > span { color: var(--on-primary); } .stamp.ink svg { fill: var(--on-primary); }

/* Wren's note: the only place the hand appears. */
.note {
  position: relative; padding: var(--s-4) var(--s-5) var(--s-5);
  background: var(--sun); color: var(--ink); box-shadow: var(--elev-card);
  font: 400 var(--t-16)/var(--lh-hand) var(--font-hand); transform: rotate(var(--tilt, var(--tilt-1)));
}
.note.white { background: var(--bg); box-shadow: var(--elev-card), 0 0 0 1px oklch(0.27 0.07 258 / 0.06); }
.note::before {
  content: ""; position: absolute; top: -10px; left: 28px; width: 72px; height: 20px;
  background: var(--tape); transform: rotate(-5deg);
}
.note .sig { display: block; margin-top: var(--s-2); font: 700 var(--t-13)/1.3 var(--font-body); }
.writes .c { opacity: 0; animation: write-in 120ms linear forwards; animation-delay: calc(var(--i) * var(--write-step)); }
.writes.done .c { opacity: 1; animation: none; }
@keyframes write-in { to { opacity: 1; } }

/* Print: a real photograph with a white border and a handwritten caption. */
.print { position: relative; margin: 0; padding: 10px 10px 34px; background: var(--bg); box-shadow: var(--elev-card); transform: rotate(var(--tilt, 0deg)); }
.print img { width: 100%; aspect-ratio: var(--ar, 4 / 3); object-fit: cover; }
.print figcaption { position: absolute; left: 12px; right: 12px; bottom: 7px; font: 400 var(--t-13)/1.4 var(--font-hand); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Postmark: the date something was kept. */
.postmark {
  display: inline-grid; place-items: center; width: 78px; height: 78px; flex: none; border-radius: 50%;
  border: 2px solid currentColor; color: var(--ink); opacity: .88; text-align: center;
  font: 800 10px/1.2 var(--font-body); letter-spacing: .05em; text-transform: uppercase;
  box-shadow: inset 0 0 0 5px var(--bg), inset 0 0 0 6.5px currentColor; transform: rotate(-8deg);
}
.postmark b { display: block; font-size: 13px; letter-spacing: 0; }

/* Memory slip: one thing Wren keeps, in the member's own words. */
.slip {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s-3); align-items: center;
  padding: var(--s-4) var(--s-4) var(--s-4) calc(var(--s-4) + 12px);
  background: var(--bg); border-radius: 2px; box-shadow: var(--elev-card), 0 0 0 1px oklch(0.27 0.07 258 / 0.06);
}
.slip::before {           /* punched holes, like a page torn from a ring binder */
  content: ""; position: absolute; left: 4px; top: 6px; bottom: 6px; width: 8px;
  background: radial-gradient(circle, var(--surface-3) 2.6px, transparent 3px) 0 0 / 8px 14px repeat-y;
}
.slip .txt { font-size: var(--t-16); line-height: 1.45; }
.slip .src { display: block; margin-top: 2px; font-size: var(--t-13); color: var(--muted); }
.slip .used { display: inline-flex; align-items: center; gap: 4px; margin-left: var(--s-2); font-weight: 700; color: var(--ink); }
.slip.gone .txt > span:first-child { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--coral); text-decoration-thickness: 2px; }
.slip.gone { box-shadow: 0 0 0 1px var(--line); }

/* Memory chip: the dashed "you told me this" link under a reply. */
.chip-mem {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 var(--s-3);
  border: var(--bw) dashed var(--ink); border-radius: var(--r-ctl); background: transparent;
  color: var(--ink); font: 600 var(--t-13)/1 var(--font-body); cursor: pointer;
}
.chip-mem .ico { width: 15px; height: 15px; }
.chip-mem:hover { background: var(--sun-soft); }

/* AI label: always visible wherever Wren speaks. */
.ai-label { display: inline-flex; align-items: center; gap: 5px; min-height: 26px; padding: 0 9px; border-radius: var(--r-full); background: var(--ink); color: var(--on-primary); font: 700 var(--t-12)/1 var(--font-body); }
.ai-label .ico { width: 13px; height: 13px; }

/* Presence: Wren's stamp and what it is doing. */
.presence { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--app-gutter, var(--s-4)) var(--s-3); border-bottom: var(--rule-tear); }
.presence .who b { display: block; font: 800 var(--t-22)/1.1 var(--font-display); letter-spacing: -0.02em; }
.presence .who span { font: 400 var(--t-13)/1.5 var(--font-hand); color: var(--muted); }
.presence .ai-label { margin-left: auto; align-self: flex-start; margin-top: 4px; }
.presence[data-state="speaking"] .stamp { animation: hop .5s var(--ease-out) infinite alternate; }
.presence[data-state="thinking"] .stamp { animation: sway 1s ease-in-out infinite alternate; }
@keyframes hop { to { transform: translateY(-4px) rotate(-2deg); } }
@keyframes sway { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }

/* Conversation */
.msg { margin: 0 0 var(--s-4); }
.msg .who { display: block; margin-bottom: 3px; font: 700 var(--t-12)/1.3 var(--font-body); color: var(--muted); }
.msg-me { margin-left: 56px; padding: 10px 14px; border-radius: var(--r-ctl); background: var(--primary-soft); font-size: var(--t-16); line-height: 1.45; }
.msg-wren { --tilt: -1deg; margin-right: 6px; padding: 14px 16px 16px; }
.msg-wren .m { background: linear-gradient(transparent 58%, var(--sun) 58%) no-repeat 0 0 / 0 100%; transition: background-size var(--dur-3) var(--ease-out); }
.msg-wren .m.on { background-size: 100% 100%; }

/* Kith circle: you in the middle, Wren in the ring, never the centre. */
.kith {
  position: relative; width: 100%; max-width: 440px; aspect-ratio: 1; margin-inline: auto; border-radius: 50%;
  background: radial-gradient(circle, var(--surface-2) 0 29%, transparent 29.3%),
              radial-gradient(circle, transparent 0 63%, var(--line) 63.2% 63.6%, transparent 63.9%),
              radial-gradient(circle, transparent 0 46%, var(--line) 46.2% 46.6%, transparent 46.9%);
}
.kith .person {
  position: absolute; transform: translate(-50%, -50%); display: grid; justify-items: center; gap: 4px; padding: 0;
  border: 0; background: none; color: var(--ink); font: 600 var(--t-14)/1.2 var(--font-body); text-align: center; cursor: pointer; min-width: 44px;
}
.kith .person small { font: 400 var(--t-12)/1.4 var(--font-hand); color: var(--muted); white-space: nowrap; }
.kith .person .stamp { transition: transform var(--dur-2) var(--ease-out); }
.kith .person[aria-pressed="true"] .stamp { transform: rotate(-6deg) translateY(-3px); }
.kith .person:disabled { cursor: default; }

/* Safety card: when it matters, the scrapbook steps back. Square, plain, ink. */
.safety { padding: var(--s-5); background: var(--bg); border: var(--bw-strong) solid var(--ink); border-radius: var(--r-lg); }
.safety h3 { font-size: var(--t-22); letter-spacing: -0.02em; }
.safety .line { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); min-height: 60px; border-top: var(--rule); }
.safety .line b { display: block; font-size: var(--t-18); }
.safety .line span { font-size: var(--t-14); color: var(--muted); }

/* Break reminder and gentle notices */
.notice { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-4); border-radius: var(--r-card); background: var(--accent-soft); color: var(--ink); }
.notice .ico { margin-top: 2px; }
.notice p { margin: 0; }
.banner { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) var(--s-4); border-radius: var(--r-ctl); font-size: var(--t-15); }
.banner p { margin: 0; }
.banner.warn { background: var(--warning-soft); color: var(--warning-ink); }
.banner.bad  { background: var(--danger-soft);  color: var(--danger-ink); }
.banner.ok   { background: var(--success-soft); color: var(--success-ink); }
.banner.info { background: var(--info-soft);    color: var(--info-ink); }

/* Feedback states */
.empty { display: grid; justify-items: center; gap: var(--s-3); padding: var(--s-7) var(--s-5); text-align: center; }
.empty h3 { font-size: var(--t-22); margin: 0; }
.empty p { max-width: 36ch; color: var(--muted); margin: 0; }
.skeleton { display: block; height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-2) 0 40%, var(--surface-3) 50%, var(--surface-2) 60% 100%) 0 0 / 300% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* KPI row: a measure, its threshold and whether the gate is open. Not a hero metric. */
.kpi { display: grid; grid-template-columns: minmax(0, 1.6fr) 90px 120px minmax(0, 1fr) 150px; gap: var(--s-4); align-items: center; min-height: 60px; border-bottom: var(--row-rule); font-size: var(--t-15); }
.kpi b { font-weight: 700; }
.kpi .v { font: 700 var(--t-22)/1 var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.kpi .t { color: var(--muted); font-size: var(--t-14); }
.kpi .pill { justify-self: end; }
.kpi svg { width: 100%; height: 32px; }
@media (max-width: 700px) { .kpi { grid-template-columns: 1fr auto; } .kpi .t, .kpi svg { display: none; } }

/* Paper settles: brand-register entrance. Slight turn, no bounce. */
@keyframes settle { from { opacity: 0; transform: translateY(10px) rotate(calc(var(--tilt, 0deg) + 2deg)); } to { opacity: 1; transform: rotate(var(--tilt, 0deg)); } }
.settle { animation: settle var(--dur-3) var(--ease-out) both; }
