/* WellHealth — Rehabilitation Match Assistant */

/* ---------- Tokens ---------- */
:root {
  /* neutral (warm-cool) scale — oklch */
  --bg:         oklch(0.985 0.003 240);
  --surface:    oklch(1 0 0);
  --surface-2: oklch(0.975 0.004 240);
  --hair:       oklch(0.92 0.005 240);
  --hair-2:     oklch(0.95 0.004 240);
  --ink:        oklch(0.22 0.015 250);
  --ink-2:      oklch(0.38 0.015 250);
  --ink-3:      oklch(0.55 0.015 250);
  --ink-4:      oklch(0.72 0.012 250);

  /* accents — all share chroma .09 */
  --accent:     oklch(0.55 0.09 210);  /* teal default */
  --accent-fg:  oklch(0.98 0.01 210);
  --accent-soft: oklch(0.96 0.025 210);
  --accent-ink: oklch(0.38 0.09 210);

  /* signal */
  --good:  oklch(0.62 0.11 155);
  --warn:  oklch(0.68 0.13 55);
  --bad:   oklch(0.58 0.15 25);
  --good-soft: oklch(0.96 0.03 155);
  --warn-soft: oklch(0.96 0.035 55);
  --bad-soft:  oklch(0.96 0.03 25);

  /* fonts */
  --font-display: "Instrument Serif", ui-serif, Georgia, serif;
  --font-ui: "Inter Tight", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* space scale */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;

  /* density */
  --gap: 20px;
  --pad: 24px;
  --field-h: 38px;
  --font-body: 14px;
}

[data-density="compact"] {
  --gap: 12px;
  --pad: 16px;
  --field-h: 32px;
  --font-body: 13px;
}

/* accents */
[data-accent="teal"]  { --accent: oklch(0.55 0.09 210); --accent-soft: oklch(0.96 0.025 210); --accent-ink: oklch(0.38 0.09 210); }
[data-accent="sage"]  { --accent: oklch(0.58 0.08 155); --accent-soft: oklch(0.96 0.025 155); --accent-ink: oklch(0.38 0.08 155); }
[data-accent="slate"] { --accent: oklch(0.48 0.05 255); --accent-soft: oklch(0.95 0.015 255); --accent-ink: oklch(0.32 0.05 255); }
[data-accent="warm"]  { --accent: oklch(0.6 0.1 45);   --accent-soft: oklch(0.97 0.025 60);  --accent-ink: oklch(0.4 0.1 45); }

/* dark */
[data-theme="dark"] {
  --bg:        oklch(0.18 0.01 250);
  --surface:   oklch(0.22 0.012 250);
  --surface-2: oklch(0.25 0.012 250);
  --hair:      oklch(0.32 0.012 250);
  --hair-2:    oklch(0.28 0.012 250);
  --ink:       oklch(0.96 0.005 240);
  --ink-2:     oklch(0.82 0.008 240);
  --ink-3:     oklch(0.65 0.01 240);
  --ink-4:     oklch(0.5 0.01 240);
  --accent-soft: color-mix(in oklch, var(--accent) 18%, var(--surface));
  --good-soft: color-mix(in oklch, var(--good) 18%, var(--surface));
  --warn-soft: color-mix(in oklch, var(--warn) 22%, var(--surface));
  --bad-soft:  color-mix(in oklch, var(--bad) 20%, var(--surface));
}

[data-serif="off"] .panel-title,
[data-serif="off"] .selected-name {
  font-family: var(--font-ui);
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body, #root { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--font-body)/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "ss01", "cv11";
}

button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

.mono { font-family: var(--font-mono); font-size: 0.9em; letter-spacing: -0.01em; }

/* ---------- App frame ---------- */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 600px at 10% -10%, color-mix(in oklch, var(--accent) 6%, transparent), transparent 60%),
    var(--bg);
}

/* ---------- Top bar ---------- */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--hair);
  background: color-mix(in oklch, var(--surface) 70%, transparent);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-logo {
  height: 34px;
  width: auto;
  display: block;
  flex-shrink: 0;
}
[data-theme="dark"] .brand-logo {
  /* Lift the gold mark off a dark background */
  filter: brightness(1.18) saturate(1.05);
}
.brand-divider {
  width: 1px;
  height: 24px;
  background: var(--hair);
  flex-shrink: 0;
}
.brand-product {
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.top-nav {
  display: flex; gap: 2px;
  justify-self: center;
  background: var(--surface-2);
  border: 1px solid var(--hair);
  border-radius: 999px;
  padding: 3px;
}
.nav-link {
  border: 0; background: transparent;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--ink-2);
  border-radius: 999px;
  transition: all .15s;
}
.nav-link:hover { color: var(--ink); }
.nav-link-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 0 0 1px var(--hair);
}
.top-actions { justify-self: end; display: flex; align-items: center; gap: 14px; }
.theme-toggle {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--hair);
  color: var(--ink-2);
  transition: all .15s;
}
.theme-toggle:hover {
  color: var(--ink);
  border-color: color-mix(in oklch, var(--accent) 40%, var(--hair));
  background: var(--accent-soft);
}
.user { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.02em;
}
.user-name { font-size: 13px; font-weight: 500; }
.user-role { font-size: 11px; color: var(--ink-3); }
.logout-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--hair);
  color: var(--ink-2);
  cursor: pointer;
  transition: all .15s;
}
.logout-btn:hover {
  color: var(--bad);
  border-color: color-mix(in oklch, var(--bad) 40%, var(--hair));
  background: color-mix(in oklch, var(--bad) 10%, var(--surface-2));
}

/* ---------- Grid ---------- */
.grid {
  flex: 1;
  display: grid;
  grid-template-columns: var(--col1, 1fr) var(--col2, 1.15fr) var(--col3, 1fr);
  gap: var(--gap);
  padding: var(--gap);
  max-width: 1680px;
  width: 100%;
  margin: 0 auto;
  align-items: start;
  position: relative;
}
.grid > .panel {
  align-self: start;
  min-width: 0;
}
.col-resizer {
  position: absolute;
  top: var(--gap);
  bottom: var(--gap);
  width: 10px;
  transform: translateX(-50%);
  cursor: col-resize;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
}
.col-resizer::before {
  content: "";
  width: 2px;
  height: 32px;
  background: var(--hair);
  border-radius: 2px;
  transition: background .15s, height .15s;
}
.col-resizer:hover::before,
.col-resizer.dragging::before {
  background: var(--accent);
  height: 56px;
}

/* ---------- Panel ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--r-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 2px color-mix(in oklch, var(--ink) 3%, transparent);
  container-type: inline-size;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: var(--pad) var(--pad) 14px;
  border-bottom: 1px solid var(--hair-2);
}
.panel-head-text { flex: 1 1 auto; min-width: 0; }
.panel-head-actions { flex: 0 0 auto; }
.panel-step {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.panel-title {
  font: 400 26px/1.15 var(--font-display);
  letter-spacing: -0.01em;
  margin: 0 0 4px;
  color: var(--ink);
}
.panel-sub {
  font-size: 13px;
  color: var(--ink-3);
  margin: 0;
  max-width: 42ch;
  text-wrap: pretty;
}
.panel-body {
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px var(--pad);
  border-top: 1px solid var(--hair-2);
  background: var(--surface-2);
  gap: 12px;
}
.foot-meta {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-2);
}
.foot-meta .muted { color: var(--ink-3); }

/* ---------- Form ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 10px; flex-wrap: wrap;
  font-size: 12px;
  color: var(--ink-2);
  font-weight: 500;
  letter-spacing: 0.005em;
}
.field-hint { font-size: 11px; color: var(--ink-4); font-weight: 400; }
.req { color: var(--bad); margin-left: 2px; }

.input, .textarea {
  width: 100%;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--hair);
  border-radius: var(--r-md);
  padding: 0 12px;
  height: var(--field-h);
  font-size: 13.5px;
  color: var(--ink);
  transition: all .15s;
  outline: none;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-4); }
.input:hover, .textarea:hover { border-color: color-mix(in oklch, var(--ink) 20%, var(--hair)); }
.input:focus, .textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 18%, transparent);
}
.textarea {
  height: auto;
  min-height: 110px;
  padding: 10px 12px;
  line-height: 1.55;
  resize: vertical;
  font-family: var(--font-ui);
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.input-toolbar {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-top: 2px;
}
.btn-tool {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px;
  border: 1px solid var(--hair);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: var(--r-sm);
  font-size: 12px;
  transition: all .15s;
}
.btn-tool:hover:not(:disabled) {
  color: var(--ink);
  border-color: color-mix(in oklch, var(--ink) 25%, var(--hair));
  background: var(--surface-2);
}
.btn-tool-disabled { cursor: not-allowed; opacity: 0.65; }
.soon {
  font-family: var(--font-mono);
  font-size: 9.5px;
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--hair);
  color: var(--ink-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---------- Buttons ---------- */
.btn-primary {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--ink);
  color: var(--bg);
  border: 0;
  height: 38px;
  padding: 0 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.005em;
  transition: all .15s;
  box-shadow: 0 1px 0 color-mix(in oklch, white 30%, transparent) inset,
              0 2px 8px color-mix(in oklch, var(--ink) 25%, transparent);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-ghost {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--hair);
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12.5px;
  transition: all .15s;
}
.btn-ghost:hover:not(:disabled) {
  color: var(--ink);
  border-color: color-mix(in oklch, var(--accent) 40%, var(--hair));
  background: var(--accent-soft);
}
.btn-ghost:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.kbd {
  display: inline-grid; place-items: center;
  min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 4px;
  background: color-mix(in oklch, white 15%, transparent);
  border: 1px solid color-mix(in oklch, white 25%, transparent);
  font-family: var(--font-mono);
  font-size: 10px;
  margin-left: 2px;
}

/* ---------- Recommendation / selected ---------- */
.selected-card {
  border: 1px solid var(--hair);
  border-radius: var(--r-md);
  padding: 14px 16px;
  background: var(--surface-2);
}
.selected-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 12px;
}
.selected-eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 2px;
}
.selected-name {
  font: 400 19px/1.2 var(--font-display);
  letter-spacing: -0.005em;
  margin-bottom: 3px;
}
.selected-meta { font-size: 12px; color: var(--ink-3); }
.selected-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  border-top: 1px solid var(--hair-2);
  padding-top: 12px;
}
.selected-stats > div { display: flex; flex-direction: column; gap: 2px; }
.selected-stats dt {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-4);
  margin: 0;
}
.selected-stats dd {
  font-size: 12.5px;
  color: var(--ink);
  margin: 0;
  line-height: 1.35;
}

/* fit score */
.fit {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  padding: 6px 12px;
  border-radius: var(--r-md);
  background: var(--accent-soft);
  min-width: 80px;
  text-align: right;
}
.fit-strong { background: var(--good-soft); color: var(--good); }
.fit-fair   { background: var(--accent-soft); color: var(--accent-ink); }
.fit-caution{ background: var(--warn-soft); color: var(--warn); }
.fit-num {
  font: 400 24px/1 var(--font-display);
  letter-spacing: -0.02em;
}
.fit-label {
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.85;
}
.fit-sm { padding: 4px 10px; min-width: 54px; }
.fit-sm .fit-num { font-size: 18px; }

/* stream */
.streaming-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.pulse {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.3; transform: scale(0.75); }
}

.stream {
  display: flex; flex-direction: column; gap: 6px;
  animation: fadeIn .3s ease;
}
.stream-h {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 600;
  margin: 10px 0 2px;
}
.stream-h:first-child { margin-top: 0; }
.stream-p {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink);
  margin: 0;
  text-wrap: pretty;
}
.stream-li {
  display: flex; gap: 10px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink);
}
.stream-bullet {
  flex-shrink: 0;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 9px;
}
.caret {
  display: inline-block;
  width: 2px; height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: -2px;
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.stream-thinking {
  display: flex; align-items: center; gap: 6px;
  color: var(--ink-3);
  font-size: 13px;
}
.stream-thinking .dot {
  width: 5px; height: 5px; border-radius: 50%; background: currentColor;
  animation: bounce 1.2s ease-in-out infinite;
}
.stream-thinking .dot:nth-child(2) { animation-delay: .15s; }
.stream-thinking .dot:nth-child(3) { animation-delay: .3s; }
.thinking-label { margin-left: 4px; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* empty state */
.empty {
  display: flex; flex-direction: column; align-items: center;
  gap: 8px;
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-3);
}
.empty-icon {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px dashed var(--hair);
  color: var(--ink-3);
  margin-bottom: 4px;
}
.empty-title { font-size: 14px; color: var(--ink-2); font-weight: 500; }
.empty-body { font-size: 12.5px; max-width: 34ch; text-wrap: pretty; line-height: 1.5; }

/* ---------- Options ---------- */
.options-body { gap: 12px; }
.option {
  border: 1px solid var(--hair);
  border-radius: var(--r-md);
  padding: 14px 16px;
  background: var(--surface);
  transition: all .18s;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 10px;
  position: relative;
}
.option:hover {
  border-color: color-mix(in oklch, var(--accent) 35%, var(--hair));
  transform: translateY(-1px);
  box-shadow: 0 4px 14px color-mix(in oklch, var(--ink) 6%, transparent);
}
.option-selected {
  border-color: var(--accent);
  background: color-mix(in oklch, var(--accent-soft) 50%, var(--surface));
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 15%, transparent);
}
.option-selected::before {
  content: "Selected";
  position: absolute;
  top: -8px; left: 14px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-fg);
  background: var(--accent);
  padding: 2px 7px;
  border-radius: 4px;
}
.option-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.option-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.005em;
}
.option-meta { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }

.option-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--hair);
  line-height: 1.5;
}
.chip-good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.chip-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip-icon { display: inline-flex; }

.option-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.option-col-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 4px;
}
.option-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.option-list li {
  display: flex; gap: 6px;
  font-size: 12px;
  color: var(--ink-2);
  line-height: 1.45;
}
.li-mark {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.35;
  flex-shrink: 0;
  width: 12px;
  text-align: center;
}
.li-good { color: var(--good); }
.li-bad  { color: var(--bad); }

.option-risk {
  display: flex; gap: 8px;
  padding: 8px 10px;
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: var(--r-sm);
  font-size: 11.5px;
  align-items: flex-start;
}
.option-risk svg { flex-shrink: 0; margin-top: 2px; }
.risk-label {
  font-weight: 600;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.risk-body { color: color-mix(in oklch, var(--ink) 70%, var(--warn)); line-height: 1.45; }

.option-foot {
  border-top: 1px solid var(--hair-2);
  padding-top: 10px;
}
.why { display: flex; flex-direction: column; gap: 4px; }
.why-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.why-body { font-size: 12px; color: var(--ink-2); line-height: 1.5; text-wrap: pretty; }

/* ---------- Footer ---------- */
.footer {
  display: flex;
  justify-content: space-between;
  padding: 16px 28px;
  font-size: 11.5px;
  color: var(--ink-3);
  border-top: 1px solid var(--hair);
}
.footer-meta { display: flex; gap: 8px; }

/* ---------- Chat drawer ---------- */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px 10px 14px;
  background: var(--ink);
  color: var(--bg);
  border: 0;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px color-mix(in oklch, var(--ink) 30%, transparent);
  z-index: 40;
  transition: all .2s;
}
.chat-fab:hover { transform: translateY(-2px); }
.chat-fab-open { opacity: 0; pointer-events: none; transform: scale(0.9); }

.chat-drawer {
  position: fixed;
  top: 0; right: 0;
  width: 380px;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--hair);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.2,.8,.2,1);
  z-index: 60;
  box-shadow: -8px 0 40px color-mix(in oklch, var(--ink) 12%, transparent);
}
.chat-drawer-open { transform: translateX(0); }

.chat-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--hair-2);
}
.chat-title { font: 400 18px/1.2 var(--font-display); }
.chat-status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px;
  color: var(--good);
  margin-top: 3px;
}
.chat-close {
  width: 28px; height: 28px;
  border: 0; background: transparent;
  border-radius: 6px;
  color: var(--ink-3);
  display: grid; place-items: center;
}
.chat-close:hover { background: var(--surface-2); color: var(--ink); }

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.msg { display: flex; gap: 8px; animation: fadeIn .25s; }
.msg-user { justify-content: flex-end; }
.msg-avatar {
  width: 26px; height: 26px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-fg);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.msg-bubble {
  max-width: 78%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
}
.msg-assistant .msg-bubble {
  background: var(--surface-2);
  border: 1px solid var(--hair-2);
  border-top-left-radius: 4px;
}
.msg-user .msg-bubble {
  background: var(--ink);
  color: var(--bg);
  border-top-right-radius: 4px;
}
.msg-typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.msg-typing .dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--ink-3);
  animation: bounce 1.2s ease-in-out infinite;
}
.msg-typing .dot:nth-child(2) { animation-delay: .15s; }
.msg-typing .dot:nth-child(3) { animation-delay: .3s; }

.chat-quick {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 10px 20px 6px;
}
.quick {
  background: var(--surface-2);
  border: 1px solid var(--hair);
  color: var(--ink-2);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  transition: all .15s;
}
.quick:hover { color: var(--ink); border-color: var(--accent); }

.chat-input {
  display: flex; gap: 8px;
  padding: 12px 20px 18px;
  border-top: 1px solid var(--hair-2);
}
.chat-text {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--hair);
  border-radius: 999px;
  padding: 0 14px;
  height: 36px;
  font-size: 13px;
  outline: none;
  transition: all .15s;
}
.chat-text:focus { border-color: var(--accent); background: var(--surface); }
.chat-send {
  width: 36px; height: 36px;
  border: 0; border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  display: grid; place-items: center;
  transition: transform .15s;
}
.chat-send:hover { transform: scale(1.06); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid { grid-template-columns: 1fr !important; }
  .col-resizer { display: none; }
}
@media (max-width: 1024px) {
  .user-text { display: none; }
  .brand-divider, .brand-product { display: none; }
}
@media (max-width: 820px) {
  .topbar {
    grid-template-columns: 1fr auto;
    gap: 12px;
    padding: 12px 16px;
  }
  .top-nav {
    grid-column: 1 / -1;
    justify-self: stretch;
    overflow-x: auto;
  }
  .brand-divider, .brand-product { display: none; }
  .user-text { display: none; }
  .grid { padding: 12px; gap: 12px; }
  .panel-head,
  .panel-body,
  .panel-foot { padding-left: 16px; padding-right: 16px; }
  .panel-title { font-size: 22px; }
  .selected-stats { grid-template-columns: 1fr 1fr; }
  .chat-drawer { width: 100%; }
  .footer { flex-direction: column; gap: 4px; padding: 14px 16px; }
}
@media (max-width: 560px) {
  .top-nav { display: none; }
  .chat-fab span { display: none; }
  .chat-fab { padding: 12px; border-radius: 50%; }
}

/* ---------- Container queries ---------- */
/* Collapse grids inside a panel when the panel itself is narrow.
   Placed at end so they override earlier .grid-2 / .option-body defaults. */
@container (max-width: 420px) {
  .grid-2 { grid-template-columns: 1fr; }
  .option-body { grid-template-columns: 1fr; }
  .selected-stats { grid-template-columns: 1fr 1fr; }
  .selected-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .fit { align-self: flex-start; align-items: flex-start; text-align: left; min-width: 0; }
  .panel-foot { flex-direction: column; align-items: stretch; gap: 10px; }
  .panel-foot .btn-primary { width: 100%; justify-content: center; }
  .input-toolbar { flex-direction: column; align-items: stretch; }
  .btn-tool { justify-content: center; }
  .field-hint { display: none; }
  .panel-head { padding: 16px 16px 12px; gap: 10px; }
  .panel-body { padding: 14px 16px; }
  .panel-title { font-size: 20px; line-height: 1.2; margin-bottom: 8px; }
  .panel-sub { font-size: 12.5px; }
}
@container (max-width: 320px) {
  .selected-stats { grid-template-columns: 1fr; }
}

/* ---------------- Language pill ---------------- */
.lang-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  background: var(--surface-2);
}
.lang-opt {
  appearance: none;
  border: 0;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  color: var(--ink-3);
  background: transparent;
  transition: background 120ms ease, color 120ms ease;
}
.lang-opt:hover { color: var(--ink); }
.lang-opt-active {
  color: var(--accent-fg);
  background: var(--accent);
}

/* ---------------- Magic-link auth gate ----------------
   Layout mirrors the b2c AuthScreen: a centered single column (max 440px) with a
   square brand logo, a centered language pill, the email field, the pill button,
   and the sent/error message below it, plus a build-version footer pinned to the
   bottom of the screen. */
.gate {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
}
.gate-screen {
  flex: 1;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 0 28px;
}
.gate-logo {
  width: 100%;
  aspect-ratio: 1;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gate-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.gate-lang {
  display: flex;
  justify-content: center;
}
.gate-form { display: flex; flex-direction: column; gap: 14px; }
.gate-input {
  font-family: var(--font-ui);
  font-size: 15px;
  min-height: 50px;
  padding: 0 14px;
  border: 1px solid var(--hair);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
}
.gate-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.gate-submit {
  appearance: none;
  border: 0;
  cursor: pointer;
  min-height: 50px;
  padding: 0 16px;
  border-radius: 25px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-fg);
  background: var(--accent);
  transition: opacity 120ms ease;
}
.gate-submit:disabled { opacity: 0.6; cursor: progress; }
.gate-error {
  font-size: 13px;
  line-height: 1.4;
  color: var(--bad);
  text-align: center;
}
.gate-sent {
  font-size: 13px;
  line-height: 1.4;
  color: var(--accent-ink);
  text-align: center;
}
.gate-version {
  padding: 0 28px 16px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
}
