/* PBC Research — design tokens + components. Tokens from style.md §2. */

:root {
  color-scheme: light; /* v1 is light-only */

  /* Brand */
  --brand-red: #ed071b; /* logo / icon accent only — never UI */
  --ink: #22292f;
  --ink-soft: #4a545e;
  --ink-faint: #6b7683;

  /* Action */
  --action: #0078e6;
  --action-press: #005bb5;
  --action-tint: #e5f1fc;

  /* Surfaces */
  --bg: #f7f8fc;
  --surface: #ffffff;
  --surface-dim: #edf2f8;
  --line: #cdd8e1;

  /* Semantic (never brand red) */
  --success: #0a8f51;
  --success-bg: #e7f6ee;
  --warning: #b45309;
  --error: #c21807;
  --error-bg: #fcedea;

  /* Type */
  --font: Roboto, -apple-system, "Segoe UI", system-ui, sans-serif;
  --fs-hint: 15px;
  --fs-body: 18px;
  --fs-lead: 20px;
  --fs-title: 24px;
  --fs-display: 30px;
  --lh-body: 1.55;
  --lh-title: 1.25;

  /* Space & shape */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --r-card: 16px;
  --r-bubble: 20px;
  --r-btn: 14px;
  --r-chip: 999px;

  /* Elevation */
  --shadow-1: 0 1px 3px rgba(34, 41, 47, 0.08);
  --shadow-2: 0 4px 16px rgba(34, 41, 47, 0.14);

  /* Motion */
  --t-fast: 150ms;
  --t-base: 220ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.3, 1);
}

* {
  box-sizing: border-box;
}

/* The hidden attribute must always win — classed elements set display and
   would otherwise override it (send/stop buttons, mode chip, status line). */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--ink);
  background: var(--bg);
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

/* ---------- App bar ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: 56px;
  padding: 0 var(--sp-4);
  padding-top: env(safe-area-inset-top);
  height: calc(56px + env(safe-area-inset-top));
  background: var(--ink);
  color: #fff;
}
.appbar__title {
  flex: 1;
  text-align: center;
  font-size: var(--fs-lead);
  font-weight: 700;
  letter-spacing: 0.2px;
}
.appbar__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: #fff;
  cursor: pointer;
  border-radius: 10px;
}
.appbar__btn:active {
  background: rgba(255, 255, 255, 0.12);
}
.appbar__spacer {
  width: 44px;
}
.appbar__btn svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

/* ---------- Layout ---------- */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-4) var(--sp-7);
}
.section-gap {
  margin-top: var(--sp-5);
}

/* ---------- Typography ---------- */
h1 {
  font-size: var(--fs-display);
  line-height: var(--lh-title);
  font-weight: 700;
  margin: 0 0 var(--sp-4);
}
h2 {
  font-size: var(--fs-title);
  line-height: var(--lh-title);
  font-weight: 700;
  margin: var(--sp-5) 0 var(--sp-2);
}
.hint {
  font-size: var(--fs-hint);
  color: var(--ink-faint);
}
.lead {
  font-size: var(--fs-lead);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 100%;
  min-height: 56px;
  padding: 0 var(--sp-5);
  font-family: var(--font);
  font-size: var(--fs-lead);
  font-weight: 700;
  border-radius: var(--r-btn);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition:
    background var(--t-fast) var(--ease-out),
    transform var(--t-fast) var(--ease-out);
}
.btn--primary {
  background: var(--action);
  color: #fff;
}
.btn--primary:active {
  background: var(--action-press);
  transform: scale(0.98);
}
.btn--secondary {
  background: var(--surface);
  color: var(--action-press);
  border-color: var(--line);
}
.btn--secondary:active {
  background: var(--surface-dim);
}
.btn--quiet {
  background: transparent;
  color: var(--action-press);
  min-height: 44px;
  font-size: var(--fs-body);
  font-weight: 500;
}
.btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.btn + .btn {
  margin-top: var(--sp-3);
}

/* ---------- Sticky bottom action ---------- */
.action-bar {
  position: sticky;
  bottom: 0;
  margin: var(--sp-5) calc(-1 * var(--sp-4)) 0;
  padding: var(--sp-3) var(--sp-4);
  padding-bottom: calc(var(--sp-3) + var(--safe-b, env(safe-area-inset-bottom, 0px)));
  background: var(--surface);
  border-top: 1px solid var(--line);
}

/* ---------- Inputs ---------- */
label.field {
  display: block;
  font-size: var(--fs-body);
  font-weight: 500;
  margin-bottom: var(--sp-2);
}
textarea,
input[type="text"],
input[type="email"] {
  display: block;
  width: 100%;
  font-family: var(--font);
  font-size: var(--fs-lead);
  line-height: var(--lh-body);
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-btn);
  padding: var(--sp-4);
}
textarea {
  min-height: 96px;
  resize: none;
  overflow: hidden;
}
textarea:focus,
input:focus {
  outline: none;
  border-color: var(--action);
  border-width: 2px;
}
.field-hint {
  font-size: var(--fs-hint);
  color: var(--ink-faint);
  margin-top: var(--sp-2);
}
.field-error {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--error);
  font-size: var(--fs-hint);
  margin-top: var(--sp-2);
}

/* ---------- Chat bubbles ---------- */
.transcript {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.turn-gap {
  margin-top: var(--sp-5);
}
.bubble {
  max-width: 85%;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-lead);
  border-radius: var(--r-bubble);
}
.bubble--assistant {
  align-self: flex-start;
  background: var(--surface-dim);
  color: var(--ink);
  border-bottom-left-radius: 6px;
}
.bubble--user {
  align-self: flex-end;
  background: var(--action-tint);
  color: var(--ink);
  border-bottom-right-radius: 6px;
}
.answered-row {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: var(--sp-2);
}
.answered-row .bubble--user {
  align-self: flex-end;
}
.answered-row__fix {
  width: auto;
  min-height: 44px;
  padding: 0 var(--sp-3);
  flex: none;
}
.bubble--enter {
  animation: bubble-in var(--t-base) var(--ease-out);
}
@keyframes bubble-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Thinking dots (running) ---------- */
.thinking {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}
.thinking span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--action);
  animation: dot 1.2s infinite ease-in-out;
}
.thinking span:nth-child(2) {
  animation-delay: 0.2s;
}
.thinking span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes dot {
  0%,
  60%,
  100% {
    opacity: 0.3;
  }
  30% {
    opacity: 1;
  }
}
.progress-bar {
  height: 3px;
  background: var(--action-tint);
  overflow: hidden;
  border-radius: 2px;
  margin-top: var(--sp-3);
}
.progress-bar::after {
  content: "";
  display: block;
  height: 100%;
  width: 40%;
  background: var(--action);
  animation: indeterminate 1.4s infinite var(--ease-out);
}
@keyframes indeterminate {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(320%);
  }
}

/* ---------- Cards & lists ---------- */
.card {
  display: block;
  background: var(--surface);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-1);
  padding: var(--sp-4);
  text-decoration: none;
  color: inherit;
}
a.card:active {
  background: var(--surface-dim);
}
.recent-item {
  min-height: 64px;
  margin-top: var(--sp-3);
}
.recent-item__title {
  font-size: var(--fs-body);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.recent-item__problem {
  font-size: var(--fs-body);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.recent-item__problem--sub {
  font-size: var(--fs-hint);
  color: var(--ink-faint);
  -webkit-line-clamp: 1;
  margin-top: 2px;
}

/* ---------- History filter ---------- */
.history-filter {
  margin-top: var(--sp-3);
  margin-bottom: var(--sp-2);
}
.history-filter[type="search"] {
  -webkit-appearance: none;
  appearance: none;
}
.recent-item__meta {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-2);
}
.recent-item__date {
  font-size: var(--fs-hint);
  color: var(--ink-faint);
}

/* ---------- Status chips ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-hint);
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--r-chip);
}
.chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.chip--running {
  background: var(--action-tint);
  color: var(--action-press);
}
.chip--ready {
  background: var(--success-bg);
  color: var(--success);
}
.chip--emailed {
  background: var(--surface-dim);
  color: var(--ink-soft);
}
.chip--failed {
  background: var(--error-bg);
  color: var(--error);
}

/* ---------- Markdown inside chat bubbles ---------- */
.bubble--md {
  font-size: var(--fs-body);
}
.bubble--md > :first-child {
  margin-top: 0;
}
.bubble--md > :last-child {
  margin-bottom: 0;
}
.bubble--md p {
  margin: 0 0 var(--sp-3);
}
.bubble--md ul,
.bubble--md ol {
  margin: 0 0 var(--sp-3);
  padding-left: var(--sp-5);
}
.bubble--md li {
  margin-bottom: var(--sp-1);
}
.bubble--md a {
  color: var(--action-press);
}
.bubble--md h1,
.bubble--md h2,
.bubble--md h3 {
  font-size: var(--fs-lead);
  margin: var(--sp-3) 0 var(--sp-2);
}

/* ---------- Follow-up composer ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
}
.composer__input {
  flex: 1;
  min-height: 56px;
  /* font-size stays at --fs-lead (20px) ≥16px so iOS Safari doesn't auto-zoom */
}
.composer__send {
  flex: none;
  width: 56px;
  min-width: 56px;
  height: 56px;
  padding: 0;
}
.composer__send svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.composer__hint {
  margin-top: var(--sp-2);
}
.hint-seen .composer__hint {
  display: none;
}

.btn--inline {
  width: auto;
  min-height: 44px;
  padding: 0 var(--sp-3);
}

/* ---------- Report updated banner ---------- */
.report-updated {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-hint);
  color: var(--success);
  margin: 0 0 var(--sp-2);
}
.report-updated__icon {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Destructive link ---------- */
.danger-form {
  margin-top: var(--sp-6);
  text-align: center;
}
.danger-link {
  width: auto;
  color: var(--error);
  min-height: 44px;
}
.danger-link:active {
  background: var(--error-bg);
}

/* ---------- Report view ---------- */
.report {
  background: var(--surface);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-1);
  padding: var(--sp-5) var(--sp-4);
}
.report h1 {
  font-size: var(--fs-title);
}
.report h2 {
  font-size: var(--fs-lead);
}
.report p,
.report li {
  font-size: var(--fs-lead);
  line-height: 1.6;
}
.report a {
  color: var(--action-press);
}
.report ul,
.report ol {
  padding-left: var(--sp-5);
}
.report li {
  margin-bottom: var(--sp-2);
}
.report hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: var(--sp-5) 0;
}

/* ---------- Feedback modal ---------- */
dialog.modal {
  border: none;
  border-radius: var(--r-card);
  padding: var(--sp-5);
  width: min(92vw, 480px);
  box-shadow: var(--shadow-2);
  /* Never taller than the visible viewport (keyboard open included) so
     action buttons can't be pushed under the keyboard or system nav. */
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
}
dialog.modal::backdrop {
  background: rgba(34, 41, 47, 0.5);
}
.feedback-thanks {
  color: var(--success);
  font-weight: 500;
}

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  color: var(--ink-faint);
  padding: var(--sp-6) var(--sp-4);
}

/* ---------- Install steps ---------- */
.install-step {
  display: flex;
  gap: var(--sp-4);
  align-items: flex-start;
  margin-top: var(--sp-4);
}
.install-step__num {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--action);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

/* ---------- Account footer (home) ---------- */
.account-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-top: var(--sp-7);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--line);
}
.account-footer .btn--quiet {
  width: auto;
}
.account-footer__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* ============================================================
   v3 — Chat app shell
   ============================================================ */

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

body.chat-app {
  height: 100dvh;
  overflow: hidden;
  display: flex;
}

/* ---------- Drawer / sidebar ---------- */
.drawer {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(85vw, 320px);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform var(--t-base) var(--ease-out);
  z-index: 60;
  padding-top: max(env(safe-area-inset-top), var(--sp-2));
}
.drawer--open {
  transform: none;
  box-shadow: var(--shadow-2);
}
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(34, 41, 47, 0.5);
  z-index: 50;
}
.drawer__top {
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.drawer__new {
  min-height: 48px;
  font-size: var(--fs-body);
}
.drawer__new svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
}
.drawer__search {
  font-size: var(--fs-body) !important;
  padding: var(--sp-3) var(--sp-4) !important;
}
.drawer__list {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--sp-2) var(--sp-4);
}
.drawer__label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--ink-faint);
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
}
.drawer__row {
  display: flex;
  align-items: center;
  border-radius: 10px;
}
.drawer__row--active {
  background: var(--action-tint);
}
.drawer__row:not(.drawer__row--active):active {
  background: var(--surface-dim);
}
.drawer__link {
  flex: 1;
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 0 var(--sp-3);
  color: var(--ink);
  text-decoration: none;
  font-size: var(--fs-body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drawer__more {
  flex: none;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--ink-faint);
  border-radius: 10px;
  cursor: pointer;
}
.drawer__more svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
.drawer__more:active {
  background: var(--surface-dim);
}
.drawer__empty {
  padding: var(--sp-4);
}
.drawer__foot {
  border-top: 1px solid var(--line);
  padding: var(--sp-3) var(--sp-4);
  padding-bottom: calc(var(--sp-3) + var(--safe-b, env(safe-area-inset-bottom, 0px)));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-1);
}
.drawer__foot .btn--quiet {
  width: auto;
  min-height: 44px;
  padding: 0 var(--sp-2);
}
.drawer__account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: var(--sp-2);
}

/* ---------- Main column ---------- */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  /* Follow the body's JS-corrected height — an own 100dvh here spans the
     full screen (under the Android nav bar) in standalone/edge-to-edge. */
  height: 100%;
}
.chatbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-2);
  padding-top: env(safe-area-inset-top);
  min-height: calc(52px + env(safe-area-inset-top));
  background: var(--ink);
  color: #fff;
}
.chatbar__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: #fff;
  border-radius: 10px;
  cursor: pointer;
}
.chatbar__btn svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chatbar__btn:active {
  background: rgba(255, 255, 255, 0.12);
}
.chatbar__title {
  flex: 1;
  border: none;
  background: transparent;
  color: #fff;
  font-family: var(--font);
  font-size: var(--fs-body);
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 44px;
  cursor: pointer;
  letter-spacing: 0.2px;
}
.chatbar__title:disabled {
  cursor: default;
}

/* ---------- Thread ---------- */
.thread-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.thread {
  max-width: 768px;
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-4) var(--sp-5);
}
.msg {
  margin-top: var(--sp-4);
}
.msg--user {
  display: flex;
  justify-content: flex-end;
}
.msg--user .bubble--user {
  white-space: pre-wrap;
  font-size: var(--fs-body);
}
.msg--assistant .msg__body {
  font-size: var(--fs-body);
  line-height: 1.6;
}
.msg-notice {
  text-align: center;
  font-size: var(--fs-hint);
  color: var(--ink-faint);
  margin-top: var(--sp-4);
}

/* Markdown typography (assistant messages + report cards) */
.md > :first-child {
  margin-top: 0;
}
.md > :last-child {
  margin-bottom: 0;
}
.md p {
  margin: 0 0 var(--sp-3);
}
.md ul,
.md ol {
  margin: 0 0 var(--sp-3);
  padding-left: var(--sp-5);
}
.md li {
  margin-bottom: var(--sp-1);
}
.md a {
  color: var(--action-press);
  word-break: break-word;
}
.md h1,
.md h2,
.md h3 {
  font-size: var(--fs-lead);
  line-height: var(--lh-title);
  margin: var(--sp-4) 0 var(--sp-2);
}
.md hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: var(--sp-4) 0;
}
.md pre {
  overflow-x: auto;
  background: var(--surface-dim);
  border-radius: 10px;
  padding: var(--sp-3);
  font-size: 15px;
}
.md code {
  background: var(--surface-dim);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.92em;
}
.md table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 0 0 var(--sp-3);
}
.md th,
.md td {
  border: 1px solid var(--line);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-hint);
}

.caret {
  display: inline-block;
  width: 9px;
  height: 1.15em;
  vertical-align: text-bottom;
  background: var(--action);
  margin-left: 2px;
  border-radius: 2px;
  animation: caret-blink 1s steps(1) infinite;
}
@keyframes caret-blink {
  50% {
    opacity: 0;
  }
}

.msg__actions {
  margin-top: var(--sp-1);
}
.msg__action {
  border: none;
  background: transparent;
  color: var(--ink-faint);
  font-family: var(--font);
  font-size: var(--fs-hint);
  min-height: 40px;
  padding: 0 var(--sp-2);
  border-radius: 8px;
  cursor: pointer;
}
.msg__action:active {
  background: var(--surface-dim);
}
.msg__error {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--error);
  font-size: var(--fs-hint);
  margin-top: var(--sp-2);
  flex-wrap: wrap;
}

/* ---------- Empty state ---------- */
.empty-hero {
  padding: var(--sp-5) var(--sp-2) 0;
  text-align: center;
}
.empty-hero h1 {
  font-size: var(--fs-title);
  margin-bottom: var(--sp-2);
}
.chip-row {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
  align-items: center;
}
.suggest-chip {
  font-family: var(--font);
  font-size: var(--fs-body);
  color: var(--action-press);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-chip);
  min-height: 48px;
  padding: var(--sp-2) var(--sp-4);
  cursor: pointer;
}
.suggest-chip:active {
  background: var(--action-tint);
}

/* ---------- Composer dock ---------- */
.composer-dock {
  flex: none;
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: var(--sp-2) var(--sp-3);
  padding-bottom: calc(var(--sp-2) + var(--safe-b, env(safe-area-inset-bottom, 0px)));
}
.composer-dock > * {
  max-width: 768px;
  margin-left: auto;
  margin-right: auto;
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
}
.composer__input {
  flex: 1;
  min-height: 52px;
  max-height: 160px;
  overflow-y: auto !important;
  resize: none;
  font-size: var(--fs-body) !important;
  border-radius: 24px !important;
  padding: var(--sp-3) var(--sp-4) !important;
}
.composer__send {
  flex: none;
  width: 52px;
  height: 52px;
  margin-bottom: 2px;
  border: none;
  border-radius: 50%;
  background: var(--action);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease-out);
}
.composer__send:active {
  background: var(--action-press);
}
.composer__send svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.composer__send--stop {
  background: var(--ink);
}
.composer__send--stop svg {
  fill: currentColor;
  stroke: none;
}
.composer__hint {
  text-align: center;
  margin: var(--sp-1) 0 0;
}
.hint-seen .composer__hint {
  display: none;
}

/* Segmented mode control — always-visible state, one tap to switch. */
.mode-seg {
  display: flex;
  gap: 4px;
  background: var(--surface-dim);
  border-radius: var(--r-chip);
  padding: 4px;
  margin-bottom: var(--sp-2);
}
.mode-seg__opt {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 44px;
  border: none;
  border-radius: var(--r-chip);
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font);
  font-size: var(--fs-body);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease-out);
}
.mode-seg__opt svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.mode-seg__opt[aria-pressed="true"] {
  background: var(--action);
  color: #fff;
  font-weight: 700;
}
.mode-seg__opt[aria-pressed="false"]:active {
  background: var(--surface);
}
.status-line {
  font-size: var(--fs-hint);
  color: var(--ink-faint);
  padding: 0 var(--sp-2) var(--sp-1);
}
/* Inline activity while an answer is forming (thinking / searching). */
.msg__status {
  font-size: var(--fs-hint);
  color: var(--ink-faint);
  min-height: 0;
}
.msg__status:not(:empty) {
  margin-bottom: var(--sp-2);
  animation: status-pulse 1.6s ease-in-out infinite;
}
@keyframes status-pulse {
  50% {
    opacity: 0.45;
  }
}
.sheet__option--danger {
  color: var(--error);
}
.sheet__option--danger svg {
  stroke: var(--error);
}
.sheet__option--danger:active {
  background: var(--error-bg);
}

/* ---------- Mode sheet ---------- */
dialog.sheet {
  border: none;
  border-radius: var(--r-card) var(--r-card) 0 0;
  padding: var(--sp-3) var(--sp-4);
  padding-bottom: calc(var(--sp-4) + var(--safe-b, env(safe-area-inset-bottom, 0px)));
  width: 100vw;
  max-width: 100vw;
  margin: auto 0 0;
  box-shadow: var(--shadow-2);
}
dialog.sheet::backdrop {
  background: rgba(34, 41, 47, 0.5);
}
.sheet__handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 0 auto var(--sp-3);
}
.sheet__option {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  width: 100%;
  min-height: 64px;
  border: none;
  background: transparent;
  border-radius: var(--r-btn);
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
}
.sheet__option:active {
  background: var(--action-tint);
}
.sheet__option svg {
  width: 26px;
  height: 26px;
  stroke: var(--action-press);
  fill: none;
  stroke-width: 2;
  flex: none;
}
.sheet__option strong {
  display: block;
  font-size: var(--fs-body);
}
.sheet__option small {
  display: block;
  font-size: var(--fs-hint);
  color: var(--ink-faint);
  line-height: 1.4;
}
.sheet__cancel {
  margin-top: var(--sp-2);
}

@media (min-width: 640px) {
  dialog.sheet {
    width: min(92vw, 420px);
    border-radius: var(--r-card);
    margin: auto;
  }
}

/* ---------- Report card ---------- */
.report-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-1);
  padding: var(--sp-4);
  margin-top: var(--sp-4);
}
.report-card__head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
  flex-wrap: wrap;
}
.report-card__head svg {
  width: 20px;
  height: 20px;
  stroke: var(--action-press);
  fill: none;
  stroke-width: 2;
  flex: none;
}
.report-card__title {
  font-weight: 700;
  font-size: var(--fs-body);
}
.report-card__body {
  font-size: var(--fs-body);
}
.md--collapsed {
  max-height: 380px;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(#000 78%, transparent);
  mask-image: linear-gradient(#000 78%, transparent);
}
.report-card__expand {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--action-press);
  font-family: var(--font);
  font-size: var(--fs-body);
  font-weight: 500;
  min-height: 44px;
  cursor: pointer;
}
.report-card__actions {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-top: var(--sp-3);
}
.report-card__actions .btn {
  width: auto;
  flex: none;
}
.report-card__updating {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
  color: var(--ink-soft);
  font-size: var(--fs-hint);
}
.report-card__sent {
  margin: var(--sp-2) 0 0;
}
.email-flow {
  margin-top: var(--sp-3);
  border-top: 1px solid var(--line);
  padding-top: var(--sp-3);
}
.email-flow__actions {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
}

/* ---------- Research progress / run ---------- */
.run-bar {
  margin-top: var(--sp-4);
}
.run-bar .btn svg {
  margin-right: var(--sp-1);
}
.progress-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: var(--sp-4);
  margin-top: var(--sp-4);
  font-size: var(--fs-body);
  color: var(--ink-soft);
}
.progress-card p {
  margin: var(--sp-2) 0;
}
.progress-activity {
  font-size: var(--fs-hint);
  color: var(--action-press);
  animation: status-pulse 1.6s ease-in-out infinite;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.progress-card--error {
  border-color: var(--error);
  color: var(--error);
}
.progress-card--error .btn {
  margin-top: var(--sp-2);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-b, env(safe-area-inset-bottom, 0px)));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: var(--fs-hint);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-chip);
  box-shadow: var(--shadow-2);
  z-index: 90;
  max-width: 88vw;
  text-align: center;
  animation: toast-in var(--t-base) var(--ease-out);
}
.toast--out {
  opacity: 0;
  transition: opacity 300ms ease-in;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%);
  }
}

/* ---------- Desktop ---------- */
@media (min-width: 1024px) {
  .drawer {
    position: static;
    transform: none;
    width: 300px;
    flex: none;
    box-shadow: none;
  }
  .scrim {
    display: none !important;
  }
  #drawer-toggle {
    display: none;
  }
  .chatbar {
    background: var(--surface);
    color: var(--ink);
    border-bottom: 1px solid var(--line);
  }
  .chatbar__btn,
  .chatbar__title {
    color: var(--ink);
  }
  .chatbar__btn:active {
    background: var(--surface-dim);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
  .caret {
    animation: none !important;
    opacity: 1;
  }
}
