/* ──────────────────────────────────────────────────────────────────────────
   TunnlAi Collector Lab — B2 stylesheet.
   Tokens copied verbatim from static/tunnl/tunnl.css (canonical Figma
   variables, 2026-07-21) so the Lab matches the Tunnl visual language while
   remaining a fully standalone service. DM Sans loads from the system when
   installed; the stack falls back cleanly (the Lab service does not ship
   the main app's font binary — see B2_NOTES.md).
   ────────────────────────────────────────────────────────────────────────── */

:root {
  --t-bg: #FFFFFF;  --t-wash: #F2F6FC;  --t-card: #FFFFFF;
  --t-ink: #2D3459; --t-sub: #5D646D;   --t-faint: #83879D;
  --t-border: #D9DFE6; --t-accent: #A0B6D6; --t-accent-ink: #2D3459;
  --t-btn-primary: #2D3459; --t-btn-primary-ink: #FFFFFF;
  --t-pos: #1E8E5A; --t-neg: #C3181B; --t-alert: #2249D8;
  --t-r-xxs: 4px; --t-r-s: 12px; --t-r-m: 16px; --t-r-l: 24px;
  --t-shadow: 0 4px 12px rgba(0,0,0,.05);
}
[data-theme="dark"] {
  --t-bg: #1C1C1D;  --t-wash: #232B36;  --t-card: #232B36;
  --t-ink: #FFFFFF; --t-sub: #C8CDD4;   --t-faint: #5D646D;
  --t-border: #5D646D; --t-accent: #A0B6D6; --t-accent-ink: #1C1C1D;
  --t-btn-primary: #A0B6D6; --t-btn-primary-ink: #1C1C1D;
  --t-pos: #34C97F; --t-neg: #E4696B; --t-alert: #4C6EF5;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  background: var(--t-bg); color: var(--t-ink);
  font-family: "DM Sans", system-ui, -apple-system, sans-serif;
  font-weight: 600; font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
kbd { font: 700 10px/1 inherit; padding: 2px 5px; border: 1px solid var(--t-border);
      border-radius: var(--t-r-xxs); color: var(--t-faint); background: transparent;
      margin-left: 6px; vertical-align: 1px; }
.t-sub { color: var(--t-sub); }

/* ── App frame (desktop-first; expert lab) ── */
.lab-app { max-width: 1060px; margin: 0 auto; padding: 0 20px 8px; }

.lab-header { display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 12px 0; position: sticky; top: 0; background: var(--t-bg);
  z-index: 30; }
/* Wordmark always fits ONE line: responsive size, never wraps. */
.lab-wordmark { font-weight: 900; font-size: clamp(15px, 4.7vw, 20px);
  letter-spacing: -.02em; white-space: nowrap; }
.lab-wordmark span { color: var(--t-faint); font-weight: 700; }
.lab-header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.lab-user { color: var(--t-sub); font-size: 13px; margin-right: 4px; }
.lab-iconbtn { width: 38px; height: 38px; border-radius: 50%; background: var(--t-wash);
  border: none; color: var(--t-ink); display: inline-flex; align-items: center;
  justify-content: center; font-size: 15px; }
a.lab-iconbtn { text-decoration: none; }

/* ── Filters / progress ── */
.lab-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 4px 0 14px; border-bottom: 1px solid var(--t-border); }
.lab-select { background: var(--t-wash); color: var(--t-ink); border: 1px solid var(--t-border);
  border-radius: 999px; padding: 7px 14px; font: inherit; font-size: 13px; font-weight: 700; }
.lab-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
  font-weight: 700; color: var(--t-sub); }
.lab-progress { margin-left: auto; font-size: 13px; font-weight: 700; color: var(--t-sub); }

/* ── Question ── */
.lab-question { font-weight: 900; font-size: 21px; line-height: 28px;
  letter-spacing: -.03em; text-align: center; margin: 14px 0 2px; }
.lab-gradebanner { text-align: center; margin: 10px auto 0; padding: 8px 16px;
  max-width: 560px; background: var(--t-wash); border: 1px solid var(--t-accent);
  border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--t-ink); }

/* ── Card panels ── */
.lab-cards { display: grid; grid-template-columns: 1fr 44px 1fr; gap: 10px;
  align-items: start; margin-top: 12px; }
.lab-vs { align-self: center; text-align: center; font-weight: 900;
  color: var(--t-faint); font-size: 14px; text-transform: uppercase; }
.lab-cardpanel { background: var(--t-card); border: 1px solid var(--t-border);
  border-radius: var(--t-r-m); padding: 12px; box-shadow: var(--t-shadow);
  position: relative; outline: none; transition: border-color .12s, box-shadow .12s;
  /* Desktop density: image left, name + metadata right */
  display: grid; grid-template-columns: minmax(150px, 42%) 1fr;
  grid-template-rows: auto 1fr; gap: 6px 14px; }
.lab-cardpanel .lab-imagebox { grid-column: 1; grid-row: 1 / 3; width: 100%; }
.lab-cardpanel .lab-cardname { grid-column: 2; grid-row: 1; }
.lab-cardpanel .lab-meta { grid-column: 2; grid-row: 2; align-self: start; }
[data-theme="dark"] .lab-cardpanel { border-color: transparent; }
.lab-cardpanel.selected { border-color: var(--t-accent);
  box-shadow: 0 0 0 2px var(--t-accent); }
.lab-cardtag { position: absolute; top: 10px; left: 10px; z-index: 2;
  background: var(--t-btn-primary); color: var(--t-btn-primary-ink);
  font-size: 11px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase;
  padding: 4px 10px; border-radius: 999px; }
.lab-cardtag kbd { border-color: transparent; color: inherit; opacity: .7; padding: 0; }
.lab-cardpanel.has-grade .lab-cardname { padding-right: 92px; }
.lab-gradebadge { position: absolute; top: 10px; right: 10px; z-index: 2;
  background: var(--t-accent); color: var(--t-accent-ink); font-size: 11px;
  font-weight: 900; letter-spacing: .04em; text-transform: uppercase;
  padding: 4px 10px; border-radius: 999px; }

/* Image container: consistent, no distortion; trading-card aspect.
   Height capped (~40vh) so cards + answers fit one laptop viewport. */
.lab-imagebox { aspect-ratio: 5 / 7; max-height: min(34vh, 380px); margin: 0 auto;
  border-radius: var(--t-r-s); background: var(--t-wash); overflow: hidden;
  display: flex; align-items: center; justify-content: center; }
.lab-imagebox img { width: 100%; height: 100%; object-fit: contain; display: block; }

/* Intentional missing-image placeholder (no images exist yet). */
.lab-placeholder { width: 100%; height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; color: var(--t-faint);
  background:
    repeating-linear-gradient(-45deg, transparent 0 14px, rgba(160,182,214,.10) 14px 28px),
    var(--t-wash);
  border: 1px dashed var(--t-border); border-radius: var(--t-r-s); }
.lab-placeholder .ph-frame { height: 56%; aspect-ratio: 5 / 7; border-radius: 8px;
  border: 2px solid var(--t-border); display: flex; align-items: center;
  justify-content: center; font-weight: 900; font-size: 22px; letter-spacing: -.02em;
  color: var(--t-accent); background: var(--t-card); }
.lab-placeholder .ph-note { font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; }

/* Title: two lines RESERVED on both cards; longer names WRAP (never clip —
   founder bug fix 2026-07-23). When one side needs a third line, the JS
   row-sync (syncRows in lab.js) grows BOTH panels equally so metadata rows
   stay aligned. */
.lab-cardname { font-weight: 900; font-size: 14px; line-height: 19px;
  letter-spacing: -.02em; margin: 2px 0 0; min-height: 38px;
  overflow-wrap: anywhere; }

/* Metadata list: fixed row set across both cards (union, "—" for gaps).
   Values WRAP — no ellipsis/clipping; row heights are equalized pairwise
   across the two panels by syncRows() so Year always faces Year. */
.lab-meta { display: grid; grid-template-columns: minmax(64px, auto) 1fr;
  gap: 2px 10px; font-size: 12px; line-height: 17px; }
.lab-meta dt { color: var(--t-faint); font-weight: 700; }
.lab-meta dd { color: var(--t-ink); font-weight: 600; overflow-wrap: anywhere; }
.lab-meta dd.empty { color: var(--t-faint); }
.lab-badges { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px;
  margin: 6px 0 2px; min-height: 24px; }
.lab-more { display: none; background: transparent; border: none;
  color: var(--t-sub); font: inherit; font-size: 12px; font-weight: 700;
  padding: 4px 0 0; text-align: left; grid-column: 2; }
.lab-badge { font-size: 11px; font-weight: 900; letter-spacing: .04em;
  text-transform: uppercase; padding: 3px 9px; border-radius: 999px;
  background: var(--t-wash); border: 1px solid var(--t-border); color: var(--t-ink); }

/* ── Bottom dock: answers + follow-up stay in view (sticky) ── */
.lab-dock { position: sticky; bottom: 0; z-index: 25; background: var(--t-bg);
  border-top: 1px solid var(--t-border); margin-top: 12px; padding: 10px 0 12px;
  max-height: 72vh; overflow-y: auto; }

/* Primary answers: Card A / Card B aligned under their cards. */
.lab-answers-primary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lab-answers-primary > * { min-width: 0; }  /* nowrap sub-labels must not widen the grid */
.lab-answer { border: 1px solid var(--t-border); background: var(--t-card);
  color: var(--t-ink); font-weight: 900; font-size: 14px; padding: 8px 12px;
  border-radius: var(--t-r-s); transition: background .1s, border-color .1s;
  display: flex; flex-direction: column; align-items: center; gap: 1px; }
.lab-answer:hover { border-color: var(--t-accent); }
.lab-answer.on { background: var(--t-btn-primary); color: var(--t-btn-primary-ink);
  border-color: var(--t-btn-primary); }
.lab-answer.on kbd { color: inherit; border-color: transparent; opacity: .7; }
.lab-answer-sub { font-size: 11px; font-weight: 700; color: var(--t-sub);
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lab-answer.on .lab-answer-sub { color: inherit; opacity: .85; }
.lab-answer-minor { font-weight: 700; font-size: 13px; }   /* drawer edit buttons */

/* Secondary answers: deliberately demoted — a single CENTERED VERTICAL
   column (equal / cannot evaluate / skip) so no neutral option has any
   horizontal alignment with either card (founder rule). */
.lab-answers-secondary { display: flex; flex-direction: column;
  align-items: center; gap: 6px; margin-top: 10px; }
.lab-answer2 { background: transparent; border: 1px solid var(--t-border);
  color: var(--t-sub); font-size: 12px; font-weight: 700; padding: 6px 14px;
  border-radius: 999px; transition: border-color .1s, color .1s; }
.lab-answer2:hover { border-color: var(--t-accent); color: var(--t-ink); }
.lab-answer2.on { background: var(--t-btn-primary); color: var(--t-btn-primary-ink);
  border-color: var(--t-btn-primary); }
.lab-answer2.on kbd { color: inherit; border-color: transparent; opacity: .7; }
.lab-skip { color: var(--t-faint); border-style: dashed; }

/* No option ever looks selected before the expert acts: suppress the mouse
   focus ring; keep a visible ring for keyboard navigation only. */
[data-sel]:focus { outline: none; }
[data-sel]:focus-visible { outline: 2px solid var(--t-accent); outline-offset: 2px; }

/* ── Follow-up (confidence / reasons / explanation) ── */
.lab-followup { margin-top: 10px; background: var(--t-card); border: 1px solid var(--t-border);
  border-radius: var(--t-r-m); padding: 12px 14px; box-shadow: var(--t-shadow); }
[data-theme="dark"] .lab-followup { border-color: transparent; }
.lab-followup-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 8px; }
.lab-followup-label { font-size: 12px; font-weight: 900; letter-spacing: .06em;
  text-transform: uppercase; color: var(--t-faint); min-width: 96px; }
.lab-followup-label em { font-style: normal; text-transform: none; letter-spacing: 0;
  font-weight: 700; }
.lab-seg { display: inline-flex; gap: 6px; }
.lab-segbtn { border: 1px solid var(--t-border); background: transparent; color: var(--t-ink);
  font-size: 13px; font-weight: 700; padding: 7px 14px; border-radius: 999px; }
.lab-segbtn.on { background: var(--t-accent); color: var(--t-accent-ink);
  border-color: var(--t-accent); }
.lab-segbtn.on kbd { color: inherit; border-color: transparent; }
.lab-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.lab-chip { border: 1px solid var(--t-border); background: transparent; color: var(--t-sub);
  font-size: 12px; font-weight: 700; padding: 5px 11px; border-radius: 999px; }
.lab-chip.on { background: var(--t-accent); color: var(--t-accent-ink);
  border-color: var(--t-accent); }
.lab-textarea { width: 100%; background: var(--t-wash); border: 1px solid var(--t-border);
  border-radius: var(--t-r-s); color: var(--t-ink); font: inherit; font-size: 14px;
  padding: 10px 12px; resize: vertical; }
.lab-actions { display: flex; gap: 10px; align-items: center; }

.lab-btn-primary { background: var(--t-btn-primary); color: var(--t-btn-primary-ink);
  border: none; border-radius: 999px; font-weight: 900; font-size: 15px;
  padding: 12px 26px; }
.lab-btn-primary:disabled { opacity: .45; cursor: default; }
.lab-btn-primary kbd { color: inherit; border-color: transparent; opacity: .7; }
.lab-btn-ghost { background: transparent; border: 1px solid var(--t-border);
  color: var(--t-sub); border-radius: 999px; font-weight: 700; font-size: 13px;
  padding: 9px 18px; }

.lab-sessionrow { display: flex; align-items: center; justify-content: center;
  min-height: 0; }
.lab-toast { font-size: 12px; font-weight: 700; color: var(--t-pos); margin-top: 4px; }
.lab-toast:empty { display: none; }
.lab-toast.err { color: var(--t-neg); }
.lab-loading, .lab-done { text-align: center; padding: 72px 0; color: var(--t-sub); }
.lab-done .lab-question { margin-bottom: 8px; }

/* ── Recent-answers drawer ── */
.lab-scrim { position: fixed; inset: 0; background: rgba(28,28,29,.45); z-index: 40; }
.lab-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 94vw);
  background: var(--t-bg); border-left: 1px solid var(--t-border); z-index: 50;
  display: flex; flex-direction: column; }
.lab-drawer-head { display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--t-border); }
.lab-drawer-user { font-size: 11px; font-weight: 700; color: var(--t-sub); }
.lab-recent { overflow-y: auto; padding: 12px 16px; display: flex;
  flex-direction: column; gap: 10px; }
.lab-recent-item { background: var(--t-card); border: 1px solid var(--t-border);
  border-radius: var(--t-r-s); padding: 12px; font-size: 13px; }
.lab-recent-item .pick { font-weight: 900; }
.lab-recent-item .names { color: var(--t-sub); margin: 4px 0 8px; }
.lab-recent-item .rowbtns { display: flex; gap: 8px; }
.lab-recent-item .rev { color: var(--t-faint); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; }
.lab-editgrid { display: grid; gap: 8px; margin-top: 10px; }
.lab-history { margin-top: 8px; border-top: 1px dashed var(--t-border); padding-top: 8px;
  color: var(--t-sub); font-size: 12px; display: grid; gap: 4px; }

/* ── Auth screen ── */
.lab-auth { min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 20px; }
.lab-auth-card { width: 100%; max-width: 400px; background: var(--t-card);
  border: 1px solid var(--t-border); border-radius: var(--t-r-l); padding: 32px 28px;
  box-shadow: var(--t-shadow); }
.lab-auth-sub { color: var(--t-sub); font-size: 13px; margin: 8px 0 22px; }
.lab-label { display: block; font-size: 12px; font-weight: 900; letter-spacing: .05em;
  text-transform: uppercase; color: var(--t-faint); margin: 14px 0 6px; }
.lab-input { width: 100%; background: var(--t-wash); border: 1px solid var(--t-border);
  border-radius: var(--t-r-s); color: var(--t-ink); font: inherit; padding: 11px 13px; }
.lab-auth-error { color: var(--t-neg); font-size: 13px; margin-top: 12px; }
.lab-auth .lab-btn-primary { width: 100%; margin-top: 20px; }

/* ── Image zoom overlay (tap a card image to inspect it full-screen) ── */
.lab-zoom { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.88);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  cursor: zoom-out; }
.lab-zoom img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ── Mobile: BOTH cards stay visible side by side (founder fix — no
      recency bias), collapsed metadata, answer bar pinned to the bottom. ── */
@media (max-width: 760px) {
  .lab-app { padding: 0 10px 8px; }
  /* Header: wordmark + three icons on ONE clean row; the user's name
     lives in the menu (Recent answers drawer) instead. */
  .lab-header { padding: 10px 0; }
  .lab-wordmark { font-size: clamp(14px, 4.9vw, 18px); letter-spacing: -.025em; }
  .lab-user { display: none; }
  .lab-iconbtn { width: 34px; height: 34px; font-size: 13px; }
  .lab-header-right { gap: 6px; }
  .lab-question { font-size: 17px; line-height: 23px; margin-top: 12px; }
  .lab-cards { grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
  .lab-vs { display: none; }
  .lab-cardpanel { display: block; padding: 8px; }
  .lab-cardtag { font-size: 9px; padding: 3px 7px; top: 6px; left: 6px; }
  .lab-gradebadge { font-size: 9px; padding: 3px 7px; top: 6px; right: 6px; }
  .lab-imagebox { max-height: 30vh; }
  .lab-cardname { font-size: 12px; line-height: 16px; min-height: 32px;
    margin: 8px 0 2px; }
  .lab-meta { grid-template-columns: minmax(52px, auto) 1fr; font-size: 11px;
    line-height: 15px; gap: 2px 6px; }
  .lab-badge { font-size: 9px; padding: 2px 6px; }
  .lab-badges { min-height: 20px; gap: 4px; margin: 4px 0 2px; }
  /* Collapsed by default: chips + the disambiguating core rows only. */
  .lab-cardpanel:not(.expanded) .lab-meta .m-x { display: none; }
  .lab-more { display: block; grid-column: auto; }
  /* Answer bar pinned to the viewport bottom. */
  .lab-dock { position: sticky; bottom: 0; border-top: 1px solid var(--t-border);
    margin-top: 12px; padding: 8px 0 10px; }
  .lab-answer { font-size: 13px; padding: 8px 6px; }
  .lab-answer-sub { font-size: 10px; }
  .lab-answer2 { font-size: 11px; padding: 5px 10px; }
  /* Keep Submit reachable: reasons collapse to one swipeable line. */
  .lab-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    -webkit-overflow-scrolling: touch; max-width: 100%; }
  .lab-chips::-webkit-scrollbar { display: none; }
  .lab-chip { white-space: nowrap; flex: 0 0 auto; }
  .lab-textarea { height: 40px; min-height: 40px; }
  .lab-followup { padding: 10px 12px; }
  .lab-progress { margin-left: 0; width: 100%; }
}
/* Very narrow fallback only: stack the cards. */
@media (max-width: 339px) {
  .lab-cards { grid-template-columns: 1fr; }
}
