:root {
  --bg: #f6f6f7;
  --bg-deep: #ececef;
  --surface: #ffffff;
  --surface-2: #f3f3f5;
  --line: #e6e6ea;
  --line-strong: #d5d5dc;
  --ink: #17171c;
  --ink-2: #3c3c46;
  --muted: #6d6d78;
  --accent: #5b4be6;
  --accent-hover: #4a3bd0;
  --accent-soft: #ebe8fc;
  --accent-2: #8b5cf6;
  --citrus: #f5b944;
  --grad: linear-gradient(120deg, #5b4be6 0%, #8b5cf6 55%, #c084fc 100%);
  --focus: 0 0 0 3px rgba(91, 75, 230, 0.28);
  --radius: 22px;
  --radius-sm: 16px;
  --radius-lg: 28px;
  --chat-width: 46rem;
  --shadow: 0 1px 2px rgba(23, 23, 28, 0.04), 0 12px 32px rgba(23, 23, 28, 0.06);
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Charter, Georgia, "Times New Roman", serif;
}

.skip-link { position: fixed; top: -5rem; left: 1rem; z-index: 10; padding: 0.8rem; background: var(--ink); color: white; }
.skip-link:focus { top: 1rem; }

.chat-app {
  display: grid;
  grid-template-columns: 17.5rem minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
  transition: grid-template-columns 160ms ease;
}

.chat-app[data-sidebar-collapsed="true"] { grid-template-columns: 3.75rem minmax(0, 1fr); }
.icon-button { width: 2.35rem; min-width: 2.35rem; height: 2.35rem; min-height: 2.35rem; padding: 0; justify-content: center; border-radius: 999px; }
.icon-button svg { width: 1.15rem; height: 1.15rem; flex: none; }

.chat-app[data-sidebar-collapsed="true"] .chat-rail { padding-inline: 0.7rem; overflow: hidden; }
.chat-app[data-sidebar-collapsed="true"] .rail-head { flex-direction: column; }
.chat-app[data-sidebar-collapsed="true"] .brand-name,
.chat-app[data-sidebar-collapsed="true"] .rail-label,
.chat-app[data-sidebar-collapsed="true"] .chat-list,
.chat-app[data-sidebar-collapsed="true"] .chat-list-empty { display: none; }
.chat-app[data-sidebar-collapsed="true"] .brand,
.chat-app[data-sidebar-collapsed="true"] #new-chat,
.chat-app[data-sidebar-collapsed="true"] #open-settings { margin-inline: auto; }

.run-progress {
  box-sizing: border-box;
  width: 100%;
  margin: 0;
  padding: 0.55rem 0.7rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 0.78rem;
  line-height: 1.4;
}
.run-progress[hidden] { display: none; }
.run-top { display: flex; align-items: center; gap: 0.55rem; cursor: pointer; list-style: none; }
.run-top::-webkit-details-marker { display: none; }
.run-top::after { content: ""; width: 0.5rem; height: 0.5rem; margin: 0.45rem 0.15rem 0; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg); flex: none; }
.run-progress[open] > .run-top::after { transform: rotate(225deg); }
.run-top:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 3px; }
.run-copy { min-width: 0; flex: 1; }
.run-disclosure-label { display: none; }
.run-indicator { display: grid; place-items: center; width: 1.35rem; height: 1.35rem; flex: none; border: 1px solid var(--line-strong); border-radius: 50%; background: var(--surface-2); }
.run-indicator > span { width: 0.52rem; height: 0.52rem; border-radius: 50%; background: var(--accent); }
.run-progress[data-state="running"] .run-indicator { animation: ink-breathe 2s ease-in-out infinite; }
.run-progress[data-state="complete"] .run-indicator > span { background: var(--ok); }
.run-progress[data-state="failed"] .run-indicator > span,
.run-progress[data-state="stopped"] .run-indicator > span { background: var(--bad); }
.run-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; }
.run-heading strong { font-size: 0.78rem; font-weight: 700; color: var(--ink); }
.run-heading > span { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.74rem; }
#run-stage { display: block; color: var(--ink-2); font-weight: 600; margin: 0.05rem 0 0; }
#run-detail { color: var(--muted); margin: 0.28rem 0 0; line-height: 1.35; overflow-wrap: anywhere; }
.run-freshness, .run-event-time { color: var(--muted); font-size: 0.74rem; }
.run-freshness { margin: 0.35rem 0 0; }
.run-diagnostics > summary { cursor: pointer; width: fit-content; color: var(--ink-2); font-size: 0.74rem; margin-top: 0.35rem; }
.run-diagnostics > summary:hover { color: var(--accent); }
.run-diagnostics > summary:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 3px; }
.run-id { overflow-wrap: anywhere; font-family: monospace; }
#run-timeline, .run-history-timeline { max-height: 24rem; overflow: auto; padding-left: 1.3rem; }
.run-history > summary { cursor: pointer; list-style: none; font-weight: 600; }
.run-history > summary::-webkit-details-marker { display: none; }
.run-history > summary:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 3px; }
.run-history-info { margin: 0.55rem 0; color: var(--muted); }
.run-event { padding: 0.5rem 0; border-top: 1px solid var(--line); }
.run-event summary { cursor: pointer; }
.run-event h4 { margin: 0.75rem 0 0.3rem; }
.run-payload { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.8rem; }

.chat-rail {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 1rem 0.8rem 0.75rem;
  background: color-mix(in srgb, var(--surface) 45%, var(--bg-deep));
  border-right: 1px solid var(--line);
  height: 100dvh;
  position: sticky;
  top: 0;
  overflow: auto;
}

.rail-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; min-height: 2.5rem; margin-bottom: 0.8rem; }

.chat-rail .brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.chat-rail .brand-mark { width: 1.7rem; height: 1.7rem; flex: none; border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--line)); border-radius: 50%; background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.chat-rail .brand-mark::after { left: 47%; top: 19%; width: 9%; height: 62%; background: var(--accent); transform: rotate(28deg); }
.chat-rail .brand-name { color: var(--ink); font-size: 1.15rem; font-weight: 700; letter-spacing: -0.04em; }
.brand-but { font-weight: 400; }
.brand-dot { color: var(--accent); }
.rail-caption { margin: 0.75rem 0 2.25rem; font-size: 0.72rem; color: var(--muted); }
#new-chat { min-height: 2.35rem; justify-content: center; background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 25%, var(--line)); color: var(--accent); border-radius: 10px; box-shadow: none; }
#new-chat:hover { background: color-mix(in srgb, var(--accent) 20%, var(--surface)); border-color: var(--accent); }
.chat-rail #sidebar-toggle, .chat-rail #open-settings { border: 1px solid var(--line); border-radius: 10px; color: var(--muted); }
.chat-rail #sidebar-toggle:hover, .chat-rail #open-settings:hover { background: var(--surface); color: var(--ink); }
.rail-label { font-size: 0.72rem; letter-spacing: 0; text-transform: none; margin: 1.3rem 0.65rem 0.55rem; color: var(--muted); font-weight: 500; }
.chat-list-empty { font-size: 0.8rem; line-height: 1.8; color: var(--muted); padding: 0.3rem 0.4rem; }
.chat-list:not(:empty) + .chat-list-empty { display: none; }

.chat-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 0.25rem;
}

.chat-list button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: var(--radius-sm);
}

.chat-row:has([aria-current="true"]) {
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 20%, var(--line));
}
.chat-row:has([aria-current="true"]) .chat-menu-trigger { color: var(--accent); }

.rail-foot {
  display: grid;
  gap: 0.6rem;
  padding-top: 0.65rem;
  margin-top: auto;
}

.voice-card { display: block; width: 100%; min-height: 0; padding: 1.15rem; background: var(--citrus); color: #202c26; border: 0; border-radius: 3px 22px 3px 3px; margin-bottom: 0.7rem; position: relative; text-align: left; white-space: normal; font-size: 1rem; font-weight: 400; }
.voice-card-label { font-size: 0.65rem; letter-spacing: 0.12em; text-transform: uppercase; font-weight: 650; }
.voice-card-title { display: block; font-family: var(--serif); font-size: 1.4rem; line-height: 1.2; margin: 0.65rem 0 1rem; letter-spacing: -0.04em; }
.voice-card-note { font-size: 0.7rem; color: #455135; }
#open-settings { justify-content: center; margin-left: auto; }
.settings-caption { width: 100%; text-align: left; padding-left: 1.55rem; font-size: 0.7rem; color: var(--muted); font-weight: 400; }
#google-sign-in { min-height: 2.75rem; background: transparent; border: 1px solid var(--line-strong); color: var(--ink); box-shadow: none; font-size: 0.8rem; }
#google-sign-in:hover { background: var(--surface); }

.account-email {
  color: var(--muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  padding-bottom: 1.2rem;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  padding: 0.65rem max(1.25rem, calc((100% - var(--chat-width)) / 2));
  min-height: 3rem;
  flex-shrink: 0;
}

.workspace-name { display: flex; align-items: center; gap: 0.65rem; flex-wrap: wrap; }
.workspace-dot { width: 0.45rem; height: 0.45rem; background: var(--accent); border-radius: 50%; }
.workspace-tag { color: var(--muted); font-size: 0.72rem; border-left: 1px solid var(--line-strong); padding-left: 0.9rem; margin-left: 0.25rem; }
.welcome {
  width: min(100% - 3rem, 42rem);
  max-width: 42rem;
  margin: auto;
  padding: 1rem 0 0.65rem;
  text-align: center;
}
.welcome-intro { display: grid; gap: 0.35rem; justify-items: center; }
.welcome h2 { font-family: var(--sans); font-size: 1.45rem; line-height: 1.3; font-weight: 650; letter-spacing: -0.025em; }
.welcome-intro p { color: var(--muted); font-size: 0.88rem; line-height: 1.5; }
.starters { display: flex; flex-wrap: wrap; justify-content: center; margin-top: 0.85rem; gap: 0.45rem; }
.starter {
  min-height: 0;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  box-shadow: none;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: normal;
  text-align: left;
  transition: background-color 120ms, border-color 120ms, color 120ms;
}
.starter:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--accent) 55%, var(--line-strong)); color: var(--ink); }
.chat-main:has(.msg) .welcome, .chat-main:has(.pipeline-board:not([hidden])) .welcome, .chat-main:has(.run-progress:not([hidden])) .welcome { display: none; }
.chat-main:not(:has(.msg)):not(:has(.run-progress:not([hidden]))):not(:has(.pipeline-board:not([hidden]))) .messages { display: none; }

.lab-view-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
  color: var(--ink-2);
  font-family: var(--sans);
}

.pipeline-board {
  flex: 1;
  overflow: auto;
  padding: 1rem 1.25rem 0;
  display: grid;
  align-content: start;
  gap: 1.5rem;
}

.flow-row {
  display: flex;
  align-items: stretch;
  gap: 0.35rem;
  overflow-x: auto;
  padding-bottom: 0.4rem;
}

.flow-node {
  flex: 0 0 16rem;
  display: grid;
  align-content: start;
  gap: 0.35rem;
  padding: 0.7rem 0.75rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.flow-node.is-current {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.flow-node-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.flow-node h3 {
  font-family: var(--sans);
  font-size: 1.05rem;
  font-weight: 500;
}

.flow-status, .flow-fails-title, .flow-current-note, .flow-empty, .flow-pending {
  color: var(--muted);
  font-size: 0.82rem;
}

.flow-node.is-current .flow-status {
  color: var(--accent);
  font-weight: 600;
}

.flow-io-label {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.flow-io {
  margin: 0;
  max-height: 9rem;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
  font-size: 0.75rem;
  line-height: 1.35;
  background: transparent;
}

.flow-reason {
  margin: 0;
  color: var(--bad);
  font-size: 0.85rem;
}

.flow-arrow {
  width: 2.6rem;
  height: 1.4rem;
  flex: 0 0 auto;
  align-self: center;
  stroke: var(--ink);
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.flow-arrow.back {
  width: 2.2rem;
  stroke: var(--bad);
}

.flow-fails {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.fail-arrow {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-family: var(--sans);
}

.flow-missing {
  display: grid;
  gap: 0.4rem;
  max-width: 42rem;
}

.chat-head h1 {
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 600;
}

.google-doc-choices {
  display: grid;
  gap: 0.4rem;
  max-height: 16rem;
  overflow: auto;
  margin: 0.75rem 0;
}

.mail-preview p {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.key-status {
  padding: 0 2.8rem;
}
.key-status:empty { display: none; }

.messages {
  list-style: none;
  margin: 0;
  padding: 1.5rem max(3rem, calc((100% - var(--chat-width)) / 2)) 1.5rem;
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.msg {
  max-width: 42rem;
  flex-shrink: 0;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  overflow-wrap: anywhere;
  line-height: 1.85;
}

.msg.user {
  align-self: flex-end;
  width: fit-content;
  max-width: min(34rem, 86%);
  background: var(--accent-soft);
  border-radius: 1.35rem;
  padding: 0.8rem 1.05rem;
}
.user-text { white-space: pre-wrap; }

.msg.assistant {
  align-self: flex-start;
  background: transparent;
  border-left: 2px solid var(--line-strong);
  border-radius: 0;
}

.msg.pending {
  align-self: flex-start;
  color: var(--muted);
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--line);
  background: var(--surface);
  line-height: 1;
}
.msg.run-entry { align-self: flex-start; width: 100%; max-width: 46rem; padding: 0; line-height: 1.5; }
.msg.assistant > .run-progress { border: 0; border-top: 1px solid var(--line); border-radius: 0; box-shadow: none; }
.pending-dots { display: flex; align-items: center; gap: 0.24rem; height: 0.95rem; }
.pending-dots i { width: 0.27rem; height: 0.27rem; border-radius: 50%; background: var(--accent); animation: ink-dot 1.15s ease-in-out infinite; }
.pending-dots i:nth-child(2) { animation-delay: 140ms; }
.pending-dots i:nth-child(3) { animation-delay: 280ms; }

.msg.failed {
  align-self: flex-start;
  width: min(100%, 30rem);
  padding: 0.5rem 0;
  border-radius: 0;
  background: transparent;
  line-height: 1.5;
}
.failed-text { color: var(--bad); }
.msg.failed > .run-progress { margin-top: 0.4rem; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.msg.failed > .message-meta { margin-top: 0.4rem; }
.msg.failed .run-top { width: fit-content; max-width: 100%; gap: 0.4rem; flex-wrap: wrap; }
.msg.failed .run-top::after { margin: 0 0.15rem 0.2rem 0; }
.msg.failed .run-indicator { display: none; }
.msg.failed .run-copy { flex: 0 1 auto; }
.msg.failed .run-heading { justify-content: flex-start; flex-wrap: wrap; gap: 0.4rem; }
.msg.failed .run-heading strong { color: var(--muted); font-weight: 500; }
.msg.failed .run-heading > span::before { content: "·"; margin-right: 0.4rem; }
.msg.failed .run-disclosure-label { display: inline; margin-left: 0.35rem; color: var(--ink-2); font-size: 0.74rem; }
.msg.failed .run-top:hover .run-disclosure-label { text-decoration: underline; text-underline-offset: 0.2em; }
.msg.failed .run-progress:not([open]) #run-stage { display: none; }
.msg.failed .run-history > summary { width: fit-content; color: var(--ink-2); font-size: 0.78rem; font-weight: 500; }

.composer {
  margin: 0.5rem auto 0;
  width: min(100% - 6rem, var(--chat-width));
  flex-shrink: 0;
  padding: 0.85rem 0.95rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--accent); box-shadow: var(--focus), var(--shadow); }
.composer-hint { width: min(100% - 6rem, var(--chat-width)); margin: 0.7rem auto 0; display: flex; justify-content: space-between; gap: 1rem; color: var(--muted); font-size: 0.65rem; }
#send { margin-left: 0.1rem; background: var(--accent); color: #fff; border-radius: 999px; }
#send:hover:not(:disabled) { background: var(--accent-hover); }
#send svg { width: 1.15rem; height: 1.15rem; }

.composer textarea {
  border: 0;
  resize: none;
  min-height: 3.25rem;
  max-height: 12rem;
  overflow-y: auto;
  padding: 0.55rem 0.2rem 0.55rem;
  line-height: 1.5;
  background: transparent;
  font-size: 1rem;
}
.composer textarea::placeholder { color: var(--muted); }

.composer-bar {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  padding: 0.35rem 0 0;
}

.harness-pick {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  max-width: 100%;
  height: 2.35rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.harness-pick:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.harness-label { flex: none; color: var(--ink-2); font-size: 0.73rem; font-weight: 650; }

.harness-pick select {
  width: auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-width: 13rem;
  border: 0;
  border-radius: inherit;
  padding: 0 2rem 0 0.7rem;
  background-color: transparent;
  font-size: 0.75rem;
  font-weight: 650;
}
.harness-pick select:focus-visible { box-shadow: none; outline: none; }

.style-pick { flex: none; }
.style-menu-button {
  min-height: 2.35rem;
  height: 2.35rem;
  padding: 0 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 0.75rem;
  font-weight: 650;
}
.style-menu-button:hover,
.style-menu-button[aria-expanded="true"] { border-color: var(--accent); color: var(--ink); }
.style-menu-button:focus-visible { outline: none; box-shadow: var(--focus); }
.style-menu {
  position: absolute;
  z-index: 6;
  bottom: calc(100% + 0.45rem);
  left: 0;
  width: min(19rem, 100%);
  max-height: min(26rem, calc(100dvh - 24rem));
  overflow-y: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.55rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.style-menu[hidden] { display: none; }
@media (max-height: 600px) {
  .style-menu {
    position: fixed;
    inset: 1rem auto auto 50%;
    transform: translateX(-50%);
    width: min(19rem, calc(100vw - 2rem));
    max-height: calc(100dvh - 2rem);
  }
}
.style-menu-title { margin: 0; font-size: 0.84rem; font-weight: 700; color: var(--ink); }
.style-note { margin: 0; color: var(--muted); font-size: 0.75rem; line-height: 1.4; }
.style-field { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.7fr); align-items: center; gap: 0.6rem; margin: 0; font-size: 0.84rem; color: var(--ink); }
.style-field select,
.style-field input {
  width: 100%;
  min-width: 0;
  min-height: 2rem;
  margin: 0;
  font-size: 0.8rem;
}
.style-reset {
  justify-self: start;
  min-height: 2rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 650;
}
.style-reset:hover { color: var(--accent-hover); }
.style-reset:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }

.harness-note {
  color: var(--muted);
  font-size: 0.72rem;
}
.add-writing { display: inline-flex; align-items: center; gap: 0.35rem; flex: none; margin-left: auto; min-height: 2.35rem; height: 2.35rem; padding: 0 0.55rem; border: 0; border-radius: 10px; background: transparent; color: var(--ink-2); font-size: 0.76rem; font-weight: 650; }
.add-writing:hover { color: var(--ink); background: var(--surface-2); }
.add-writing svg { width: 0.95rem; height: 0.95rem; }
.paste-writing-form { display: grid; gap: 0.75rem; padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.paste-writing-form h4 { margin: 0; font-size: 0.96rem; }
.paste-writing-form textarea { min-height: 7rem; }
.paste-writing-form button { justify-self: start; }
.writing-divider { color: var(--muted); font-size: 0.77rem; }

#composer-error {
  margin: 0.75rem auto 0;
  width: min(100% - 6rem, var(--chat-width));
}

.settings {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(52rem, 100%);
  height: 100dvh;
  max-height: 100dvh;
  max-width: 100%;
  margin: 0 0 0 auto;
  color: var(--ink);
  border: 0;
  background: var(--bg);
  border-left: 1px solid var(--line);
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  flex-direction: column;
  padding: 0;
  z-index: 3;
}
.settings[open] { display: flex; }
.settings::backdrop { background: rgba(25, 21, 39, 0.45); backdrop-filter: blur(3px); }

.settings-head, .list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.settings-head { padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); flex: none; }
.settings-head h2 { font-size: 1.2rem; letter-spacing: -0.02em; margin: 0; }
.settings h3 { font-size: 1.05rem; }
.settings .drop { background: var(--surface); }

.settings h2, .settings h3 { font-family: var(--sans); font-weight: 650; }

.settings-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 11.75rem minmax(0, 1fr);
}

.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.9rem 0.7rem;
  border-right: 1px solid var(--line);
  background: var(--bg-deep);
  overflow-y: auto;
}

.settings-nav-group + .settings-nav-group,
.settings-nav-group + .settings-nav-item,
.settings-nav-item + .settings-nav-group { margin-top: 0.85rem; }
.settings-nav-label {
  margin: 0 0 0.2rem;
  padding: 0 0.7rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
}
.settings-nav-item {
  justify-content: flex-start;
  width: 100%;
  min-height: 2.75rem;
  padding: 0 0.7rem;
  color: var(--ink-2);
  font-weight: 400;
  white-space: nowrap;
}
.settings-nav-item:hover { background: var(--surface-2); color: var(--ink); }
.settings-nav-item[aria-current="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  font-weight: 500;
}

.settings-body { overflow-y: auto; padding: 1.4rem 1.6rem 2.5rem; }
.settings textarea,
.editor-dialog textarea { max-height: 18rem; overflow-y: auto; }

.editor-dialog {
  width: min(34rem, calc(100% - 2rem));
  max-height: min(44rem, calc(100dvh - 2rem));
  padding: 0;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: 0 18px 60px rgba(25, 21, 39, 0.22);
  overflow: hidden;
}
.editor-dialog::backdrop { background: rgba(25, 21, 39, 0.4); backdrop-filter: blur(2px); }
.editor-dialog .custom-harness-form { margin: 0; max-height: inherit; overflow: auto; }
.editor-dialog .editor-body { display: grid; gap: 0.85rem; padding: 1.1rem 1.25rem 1.35rem; }
.editor-dialog .settings-head h2 { margin: 0; }

.settings-panel { display: none; }
.settings-panel.is-active { display: grid; gap: 0.85rem; align-content: start; }

.custom-harness-list { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line); }
.custom-harness-list li { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; padding: 0.7rem 0; border-bottom: 1px solid var(--line); }
.custom-harness-list li > span { min-width: 0; overflow-wrap: anywhere; }
.custom-harness-list strong { display: block; font-size: 0.91rem; font-weight: 600; }
.custom-harness-list small { display: block; color: var(--muted); font-size: 0.78rem; }
.custom-harness-list .custom-harness-row-actions { display: flex; gap: 0.35rem; flex: none; }
.custom-harness-list .custom-harness-row-actions button { min-height: 2rem; }
.custom-harness-form { display: grid; gap: 0.85rem; margin-top: 0.35rem; }
.custom-harness-form h4 { margin: 0; font-size: 1rem; }
.custom-harness-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.custom-harness-actions { display: flex; flex-wrap: wrap; gap: 0.55rem; }

.account-facts { display: grid; gap: 0; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.account-facts > div { display: flex; justify-content: space-between; gap: 1rem; padding: 0.7rem 0.85rem; }
.account-facts > div + div { border-top: 1px solid var(--line); }
.account-facts dt { color: var(--muted); font-size: 0.85rem; }
.account-facts dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 0.82rem; }

.lab textarea { min-height: 6rem; }

#open-settings-mobile {
  display: none;
}

@media (min-width: 801px) and (max-height: 800px) {
  .chat-head { min-height: 3rem; padding-top: 0.65rem; padding-bottom: 0.65rem; }
}

@media (min-width: 801px) {
  .chat-head:has(#lab-view-toggle[hidden]):not(:has(.workspace-link)) { display: none; }
}

@media (max-width: 800px) {
  .chat-app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
  }

  .chat-rail {
    position: relative;
    height: auto;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: 1rem 1.25rem;
    gap: 0.75rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-list {
    grid-column: 1 / -1;
    display: flex;
    overflow-x: auto;
    max-width: 100%;
  }
  .rail-head { margin-bottom: 0; }
  .chat-list:empty { display: none; }
  .chat-list li { flex: 0 0 auto; max-width: 12rem; }
  .chat-list button { display: block; }
  .rail-caption, .rail-label, .chat-list-empty, .voice-card, #open-settings { display: none; }
  .rail-foot { grid-column: 1 / -1; padding: 0; margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
  #google-sign-in { width: auto; min-height: 2.3rem; font-size: 0.75rem; }
  .account-email { margin-right: auto; }
  .account-email:empty { display: none; }
  .rail-foot .banner { font-size: 0.73rem; }
  .new-chat-arrow { display: none; }
  .chat-main { height: auto; min-height: 0; max-height: none; padding-bottom: 1rem; }
  .chat-head { min-height: 3rem; padding: 0.65rem 1.5rem; }
  .workspace-tag { display: none; }
  .welcome { width: calc(100% - 3rem); padding: 1rem 0 0.65rem; }
  .composer, .composer-hint, #composer-error { width: calc(100% - 3rem); }
  .messages { padding: 1rem 1.5rem; overflow: auto; }
  .key-status { padding: 0 1.5rem; }
  .starters { gap: 0.5rem; }

  #open-settings-mobile {
    display: inline-flex;
  }

  .harness-pick select { max-width: 15rem; }
  .harness-note { display: none; }
  .composer-hint > span:last-child { display: none; }

  .settings { width: 100%; border-radius: 0; }
  .settings-layout { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr); }
  .settings[data-depth="index"] .settings-body { display: none; }
  .settings[data-depth="detail"] .settings-nav { display: none; }
  .settings[data-depth="detail"] .settings-head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
  }
  .settings[data-depth="detail"] .settings-head h2 { text-align: center; }
  .settings-nav {
    flex-direction: column;
    align-items: stretch;
    overflow-x: hidden;
    overflow-y: auto;
    border-right: 0;
    border-bottom: 0;
    padding: 0.75rem 0.85rem 1.5rem;
    background: var(--bg);
  }
  .settings-nav-item { width: 100%; }
  .settings-body { padding: 1.1rem 1.25rem 2rem; }
}

@media (max-width: 480px) {
  .custom-harness-fields { grid-template-columns: 1fr; }
  .welcome { padding: 0.75rem 0 0.55rem; }
  .starters { margin-top: 0.7rem; }
  .harness-pick select { max-width: 11rem; }
  .composer-bar { flex-wrap: wrap; gap: 0.55rem; }
  .harness-pick { flex: 1 1 100%; }
  .harness-pick select { flex: 1; max-width: none; }
  .add-writing { flex: 1 1 0; min-width: 0; margin-left: 0; padding-inline: 0.2rem; white-space: normal; line-height: 1.2; }
  #send { margin-left: auto; }
  .workspace-name { gap: 0.4rem; }
  .chat-head h1 { font-size: 0.76rem; }
  .lab-view-toggle { font-size: 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  .starter, .chat-app button, .chat-app input, .chat-app select, .chat-app textarea { transition: none; }
  .starter:hover { transform: none; }
  .run-progress[data-state="running"] .run-indicator, .pending-dots i { animation: none; }
}

/* Opt-in reduced motion from preferences */
:root[data-motion="reduced"] *,
:root[data-motion="reduced"] *::before,
:root[data-motion="reduced"] *::after { transition: none !important; animation: none !important; }
:root[data-motion="reduced"] .starter:hover { transform: none; }

/* Run progress bar */
.run-bar { height: 0.25rem; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 0.55rem 0 0.45rem; }
.run-bar-fill { display: block; height: 100%; width: 0%; background: var(--accent); border-radius: 999px; transition: width 400ms ease; }
.run-bar[data-state="complete"] .run-bar-fill { background: var(--ok, #2f6b4f); }
.run-bar[data-state="failed"] .run-bar-fill,
.run-bar[data-state="stopped"] .run-bar-fill { background: var(--bad, #a3372a); }
.run-stages { display: flex; align-items: center; gap: 0.32rem; max-width: 100%; padding: 0; list-style: none; overflow-x: auto; scrollbar-width: thin; }
.run-stages:empty { display: none; }
.run-stage-chip { flex: none; padding: 0.18rem 0.45rem; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 0.74rem; line-height: 1.2; }
.run-stage-chip[data-state="active"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.run-stage-chip[data-state="complete"] { color: var(--ok); }
.run-stage-chip[data-state="failed"] { color: var(--bad); }
@keyframes ink-breathe { 50% { border-color: var(--accent); box-shadow: 0 0 0 0.25rem var(--accent-soft); } }
@keyframes ink-dot { 50% { opacity: 0.32; transform: translateY(-0.12rem); } }

/* Conversation row menu */
.chat-list li { position: relative; }
.chat-row { display: flex; align-items: stretch; gap: 0; border: 1px solid transparent; border-radius: 12px; }
.chat-row:hover:not(:has([aria-current="true"])) { background: var(--surface); }
.chat-row .chat-open { display: block; flex: 1 1 auto; min-width: 0; min-height: 2.55rem; padding-inline: 0.65rem; border-color: transparent; border-radius: inherit; background: transparent; font-size: 0.86rem; }
.chat-row .chat-open:hover:not(:disabled) { background: transparent; }
.chat-menu { position: relative; flex: none; }
.chat-list .chat-menu-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 100%;
  min-height: 2.1rem;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  border-radius: 999px;
  font-size: 1.1rem;
  line-height: 1;
}
.chat-menu-trigger:hover, .chat-menu-trigger[aria-expanded="true"] { background: color-mix(in srgb, var(--ink) 8%, transparent); color: var(--ink); }
.chat-menu-list {
  position: fixed;
  inset: auto;
  margin: 0;
  display: grid;
  min-width: 8.5rem;
  max-width: calc(100vw - 1rem);
  max-height: calc(100dvh - 1rem);
  overflow: auto;
  padding: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg, 0 10px 30px rgba(38, 52, 37, 0.18));
}
.chat-menu-list:not(:popover-open) { display: none; }
.chat-menu-list button { justify-content: flex-start; width: 100%; }

button.danger { color: var(--bad, #a3372a); }
button.danger:hover:not(:disabled) { background: var(--bad-soft, #fbe9e5); }

/* Data controls panel */
.data-group { display: grid; gap: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.data-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.85rem 1rem; }
.data-row + .data-row { border-top: 1px solid var(--line); }
.data-row > span { display: grid; gap: 0.15rem; min-width: 0; }
.data-row .row-title { display: block; font-weight: 600; font-size: 0.95rem; }
.data-row .row-note { display: block; font-size: 0.82rem; color: var(--muted); line-height: 1.45; }
.data-row button { flex: none; }

/* Settings polish: grouped panes, inset rows, and honest control labels. */
.settings-panel.is-active { gap: 1rem; }
.settings-panel h3 { letter-spacing: -0.01em; margin: 0; }
.settings-panel > .note { margin-top: -0.35rem; line-height: 1.5; }
.settings .field { gap: 0.4rem; }
.settings-nav-item { border-radius: var(--radius-sm); }
.settings-group { display: grid; gap: 0.35rem; }
.settings-group-title {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}
.settings-group-foot { margin: 0 0.15rem; color: var(--muted); font-size: 0.78rem; line-height: 1.4; }
.settings-group-body {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.settings-group-body > .field,
.settings-group-body > .switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  min-height: 2.75rem;
  margin: 0;
  padding: 0.7rem 0.9rem;
  border: 0;
  border-radius: 0;
  background: transparent;
}
.settings-group-body > * + * { border-top: 1px solid var(--line); }
.settings-group-body > .field > span:first-child,
.settings-group-body > .switch-row > span:first-child { flex: 1; min-width: 0; }
.settings-group-body > .field > span:first-child { color: var(--ink); font-size: 0.92rem; font-weight: 500; }
.settings-group-body > .field select { width: auto; flex: 0 1 13rem; min-width: 7.5rem; }
.settings-group-body .note { margin: 0; text-align: right; }
.settings-group-body > .field:has(p) { flex-direction: column; align-items: flex-start; }
.settings-group-body > .field:has(p) .note { text-align: left; }
.settings-jump {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  min-height: 2.75rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-align: left;
  white-space: normal;
}
.settings-jump:hover { background: var(--surface-2); }
.settings-jump::after {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  flex: none;
}
.settings .data-group { border-radius: var(--radius); }
.settings .list-head,
.settings .guide summary {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.78rem;
  font-weight: 650;
}

/* Message density */
:root[data-density="compact"] .messages { gap: 0.9rem; }
:root[data-density="compact"] .msg { line-height: 1.6; }
:root[data-density="compact"] .msg.user { padding: 0.6rem 0.9rem; }
:root[data-density="compact"] .msg.assistant .reply-text { padding: 0.6rem 1rem 0.35rem; line-height: 1.6; }

/* Replies stay in the conversation flow; controls appear when they are useful. */
.msg.assistant {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  width: 100%;
  max-width: 46rem;
  overflow: visible;
}
.msg.assistant > .run-progress { border: 0; border-top: 1px solid var(--line); border-radius: 0; box-shadow: none; }
.msg.assistant .reply-text {
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.7;
  max-width: none;
  margin: 0;
  padding: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: text;
}
.reply-text > :first-child { margin-top: 0; }
.reply-text > :last-child { margin-bottom: 0; }
.reply-text h1, .reply-text h2, .reply-text h3,
.reply-text h4, .reply-text h5, .reply-text h6 { margin: 1.15em 0 0.4em; font-family: var(--sans); line-height: 1.25; letter-spacing: -0.025em; }
.reply-text h1 { font-size: 1.45rem; }
.reply-text h2 { font-size: 1.25rem; }
.reply-text h3 { font-size: 1.1rem; }
.reply-text p { margin: 0.65em 0; }
.reply-text ul, .reply-text ol { margin: 0.65em 0; padding-left: 1.4rem; }
.reply-text li + li { margin-top: 0.25em; }
.reply-text pre { max-width: 100%; overflow-x: auto; padding: 0.8rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.reply-text code { padding: 0.08em 0.28em; border-radius: 4px; background: var(--surface-2); font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 0.88em; }
.reply-text pre code { padding: 0; background: transparent; }
.reply-text a, .reply-sources a { color: var(--accent); text-underline-offset: 0.16em; }

.message-meta { display: flex; align-items: center; gap: 0.25rem; min-height: 1.8rem; margin-top: 0.25rem; color: var(--muted); font-size: 0.72rem; opacity: 0.85; transition: opacity 120ms ease; }
.msg:hover > .message-meta, .msg:focus-within > .message-meta { opacity: 1; }
.msg.user .message-meta { justify-content: flex-end; }
.message-meta time:empty { display: none; }
.message-copy.icon-button { width: 1.75rem; min-width: 1.75rem; height: 1.75rem; min-height: 1.75rem; border-radius: 999px; }
.message-copy svg { width: 1rem; height: 1rem; }

.reply-sources { margin-top: 0.75rem; padding-top: 0.55rem; border-top: 1px solid var(--line); color: var(--ink-2); font-size: 0.78rem; }
.reply-sources > summary { width: fit-content; cursor: pointer; color: var(--muted); }
.reply-sources > summary:hover { color: var(--accent); }
.reply-sources ol { margin: 0.45rem 0 0; padding-left: 1.2rem; }
.reply-sources li + li { margin-top: 0.3rem; }

.msg.assistant .comment-list { padding: 0.45rem 0 0; }
.msg.assistant .reply-foot { margin-top: 0.3rem; padding: 0.45rem 0 0; border-top: 1px solid var(--line); background: transparent; opacity: 0.72; }
.msg.assistant .reply-foot:hover, .msg.assistant .reply-foot:focus-within { opacity: 1; }
.rating-label { font-size: 0.75rem; }
.rating-scale button { min-width: 1.8rem; min-height: 1.75rem; font-size: 0.75rem; }
.msg.assistant .verification-note {
  margin: 0.5rem 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.note-details { flex-basis: 100%; }
.note-details > summary { cursor: pointer; font-size: 0.82rem; color: var(--muted); list-style: none; }
.note-details > summary::-webkit-details-marker { display: none; }
.note-details > summary:hover { color: var(--ink); }
.note-details[open] > summary { margin-bottom: 0.5rem; }
.reply-text mark { cursor: pointer; }

:root[data-font="serif"] .messages,
:root[data-font="serif"] .composer textarea,
:root[data-font="serif"] .welcome,
:root[data-font="serif"] .reply-text,
:root[data-font="serif"] .reply-text h1,
:root[data-font="serif"] .reply-text h2,
:root[data-font="serif"] .reply-text h3,
:root[data-font="serif"] .reply-text h4,
:root[data-font="serif"] .reply-text h5,
:root[data-font="serif"] .reply-text h6 { font-family: var(--serif); }

:root[data-bubbles="cards"] .msg.user,
:root[data-bubbles="cards"] .msg.assistant {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
:root[data-bubbles="cards"] .msg.assistant { padding: 0.85rem 1.05rem; }
:root[data-bubbles="cards"] .msg.user { background: var(--accent-soft); }

@media (max-width: 800px) {
  .chat-app[data-sidebar-collapsed="true"] { grid-template-columns: 1fr; }
  .chat-app[data-sidebar-collapsed="true"] .rail-head { flex-direction: row; }
  .msg { max-width: min(42rem, 92%); }
  .msg.assistant { max-width: 100%; }
}

.writing-controls { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .5rem; }
.writing-controls .select { max-width: 100%; min-width: 0; flex: 1 1 10rem; }
.workspace-link { display: inline-flex; align-items: center; min-height: 2.5rem; padding: .5rem .8rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink-2); font-size: .8rem; font-weight: 600; text-decoration: none; }
.workspace-link:hover { background: var(--surface-2); color: var(--ink); }
.workspace-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
#writing-engine-hint { flex-basis: 100%; font-size: .75rem; color: var(--muted); line-height: 1.5; }
#writing-draft-text { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; }
#writing-run-actions { padding: .5rem 0; }
@media (max-width: 600px) {
  .writing-controls .select { min-height: 44px; font-size: 16px; }
  #manage-voices, .workspace-link { min-height: 44px; }
  #style-menu-button, #add-writing { height: 44px; min-height: 44px; }
  #send { width: 44px; min-width: 44px; height: 44px; min-height: 44px; }
}
