:root {
  color-scheme: light dark;
  --page: light-dark(#edf2f1, #0c1018);
  --panel: light-dark(#ffffff, #181f2d);
  --panel-soft: light-dark(#f5f8f7, #111823);
  --text: light-dark(#182b26, #edf2fb);
  --muted: light-dark(#526b61, #a7b5ca);
  --border: light-dark(#dce5df, #34435d);
  --control-border: light-dark(#dce5df, #62758f);
  --brand: light-dark(#087568, #106963);
  --brand-strong: light-dark(#075e54, #117871);
  --brand-soft: light-dark(#e4f2ec, #143333);
  --link: light-dark(#087568, #71e0d0);
  --on-brand: #ffffff;
  --good: light-dark(#17613e, #83e6b2);
  --good-soft: light-dark(#e8f4ec, #16382b);
  --bad: light-dark(#a72d24, #ffa9bb);
  --bad-soft: light-dark(#fff0ed, #402435);
}

#bob-chat {
  --brand: light-dark(#326793, #395da5);
  --brand-strong: light-dark(#28547a, #456bb7);
  --brand-soft: light-dark(#e8eff7, #202f50);
  --link: light-dark(#2b608d, #a4b9ff);
}

#protocol-rail {
  --brand: light-dark(#087568, #6854a6);
  --link: light-dark(#087568, #bcb0ff);
}

* { box-sizing: border-box; }
html { scroll-padding-top: 12px; }
body { min-height: 100dvh; margin: 0; background: var(--page); color: var(--text); font: 15px/1.5 system-ui, sans-serif; }
h1, h2, h3, p, dl, dd { margin: 0; }
button, select, textarea { font: inherit; }
button, summary { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: var(--link); text-underline-offset: 4px; }
:focus-visible { outline: 3px solid var(--link); outline-offset: 3px; }
[hidden] { display: none !important; }

.topbar, .workspace, footer { width: min(100%, 1600px); margin-inline: auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 24px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; color: var(--on-brand); background: var(--brand); font-size: 22px; font-weight: 750; }
h1 { font-size: 20px; line-height: 1.15; letter-spacing: -.035em; }
.brand p { margin-top: 3px; color: var(--muted); font-size: 12px; }
.clear-chats { min-height: 44px; margin-inline-start: auto; padding: 8px 12px; border: 1px solid var(--control-border); border-radius: 8px; background: var(--panel); color: var(--bad); font-size: 13px; font-weight: 650; }
.clear-chats:hover:not(:disabled) { background: var(--bad-soft); }
.clear-chats:disabled { color: var(--muted); }
.workspace-nav { display: none; }
.workspace { display: grid; gap: 16px; padding-inline: 24px; }
.chat-panel, .protocol-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; border: 1px solid var(--border); border-radius: 16px; background: var(--panel); }

.chat-header { display: flex; align-items: center; gap: 12px; padding: 16px; border-bottom: 1px solid var(--border); }
.avatar { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--brand-soft); color: var(--link); font-weight: 750; }
h2 { font-size: 20px; line-height: 1.2; letter-spacing: -.025em; }

.conversation { display: flex; flex: 1; flex-direction: column; gap: 16px; min-height: 0; padding: 16px; overflow-y: auto; overscroll-behavior-y: contain; scrollbar-gutter: stable; background: var(--panel-soft); }
.conversation:focus-visible { outline-offset: -3px; }
.empty-state { margin: auto; color: var(--muted); font-size: 14px; text-align: center; }
.message { display: grid; justify-items: start; gap: 4px; align-self: start; min-width: 0; max-width: 92%; }
.message-sent { justify-items: end; align-self: end; }
.message-bubble { min-width: 0; max-width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 4px 12px 12px; background: var(--panel); white-space: pre-wrap; overflow-wrap: anywhere; }
.message-sent .message-bubble { border-color: var(--brand); border-radius: 12px 4px 12px 12px; background: var(--brand); color: var(--on-brand); }
.message-meta { display: flex; gap: 8px; color: var(--muted); font-size: 12px; }
.message-details { max-width: 100%; color: var(--muted); font-size: 12px; }
.message-details summary { min-height: 32px; padding: 5px 0; overflow-wrap: anywhere; }
.message-details dl { display: grid; gap: 6px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.message-details dl div { display: flex; justify-content: space-between; gap: 10px; }
.message-details dd { min-width: 0; text-align: end; overflow-wrap: anywhere; }

.composer-area { padding: 12px 16px; border-top: 1px solid var(--border); }
.message-form label, .channel-control label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 650; }
.composer { display: flex; align-items: end; gap: 6px; padding: 5px; border: 1px solid var(--control-border); border-radius: 10px; background: var(--panel); }
.composer:focus-within { border-color: var(--brand); }
.composer textarea { flex: 1; min-width: 0; min-height: 44px; max-height: 112px; padding: 10px 6px; border: 0; border-radius: 6px; resize: none; color: var(--text); background: transparent; font-size: 16px; line-height: 24px; }
.composer textarea::placeholder { color: var(--muted); }
.composer textarea:focus-visible { outline-offset: -2px; }
.composer button { min-width: 56px; min-height: 44px; padding: 8px 12px; border: 0; border-radius: 7px; background: var(--brand); color: var(--on-brand); font-size: 13px; font-weight: 650; }
.composer button:hover:not(:disabled) { background: var(--brand-strong); }
.composer button:disabled { color: var(--muted); background: var(--panel-soft); }
.composer-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 8px; margin-top: 6px; color: var(--muted); font-size: 11px; }
.character-count { margin-left: auto; font-variant-numeric: tabular-nums; }
.action-note { margin-top: 6px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.action-note:empty { display: none; }
.error { color: var(--bad); }
.composer-progress { display: none; }

.protocol-header { padding: 19px 16px 12px; }
.channel-control { padding: 0 16px 14px; border-bottom: 1px solid var(--border); }
.channel-control select { width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--control-border); border-radius: 8px; background: var(--panel-soft); color: var(--text); }
#channel-description { min-height: 36px; margin-top: 6px; color: var(--muted); font-size: 12px; }
.protocol-body { min-height: 0; padding: 14px 16px 16px; overflow-y: auto; scrollbar-gutter: stable; }
.progress-copy { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
#protocol-status { font-weight: 650; }
#protocol-count { flex-shrink: 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.progress-track { height: 5px; margin-top: 7px; overflow: hidden; border-radius: 4px; background: var(--border); }
.progress-track span { display: block; width: 0; height: 100%; background: var(--link); transition: width .2s ease; }

.protocol-steps { margin: 16px 0; padding: 0; list-style: none; }
.protocol-steps li { position: relative; display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 8px; min-height: 34px; padding-bottom: 7px; }
.protocol-steps li:last-child { padding-bottom: 0; }
.protocol-steps li:not(:last-child)::after { position: absolute; top: 26px; bottom: 0; left: 12px; width: 1px; content: ""; background: var(--border); }
.step-marker { display: grid; place-items: center; width: 26px; height: 26px; border: 1px solid var(--border); border-radius: 50%; color: var(--muted); font-size: 11px; font-weight: 650; }
.step-heading { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0 6px; padding-top: 4px; }
.step-heading strong { font-size: 12px; }
.step-state { color: var(--muted); font-size: 11px; }
.protocol-steps p { display: none; margin: 3px 0 4px; color: var(--muted); font-size: 12px; }
.protocol-steps li.current p { display: block; }
.protocol-steps li.current .step-marker { border-color: var(--brand); color: var(--on-brand); background: var(--brand); }
.protocol-steps li.complete .step-marker { border-color: transparent; color: var(--good); background: var(--good-soft); font-size: 0; }
.protocol-steps li.complete .step-marker::after { content: "✓"; font-size: 13px; }
.protocol-steps li.complete:not(:last-child)::after { background: var(--good); }
.protocol-steps li.failed .step-marker { border-color: var(--bad); color: var(--bad); background: var(--bad-soft); }
.protocol-steps li.failed .step-state { color: var(--bad); }

.metrics { padding-top: 12px; border-top: 1px solid var(--border); }
.metrics h3 { font-size: 14px; }
.metrics p { margin-top: 5px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.metrics p.error { color: var(--bad); }
.metrics dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 10px; }
.metrics dl div { padding: 5px 7px; border-radius: 6px; background: var(--panel-soft); }
.metrics dt { color: var(--muted); font-size: 11px; }
.metrics dd { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; padding: 12px 24px; color: var(--muted); font-size: 12px; }

@media (min-width: 921px) {
  body { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100dvh; min-height: 700px; }
  .workspace { grid-template-columns: minmax(0, 1fr) clamp(300px, 27vw, 400px) minmax(0, 1fr); }
}

@media (max-width: 920px) {
  .workspace { max-width: 640px; padding-inline: 16px; }
  .topbar { flex-wrap: wrap; padding-inline: 16px; }
  .workspace-nav { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; }
  .workspace-nav a, .composer-progress { align-items: center; min-height: 44px; }
  .workspace-nav a, .composer-progress:not([hidden]) { display: inline-flex; }
  .composer-progress { font-size: 12px; }
  .chat-panel { height: 440px; }
  .protocol-body { overflow: visible; }
  footer { padding-inline: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .progress-track span { transition: none; }
}

@media (prefers-color-scheme: dark) {
  .composer:focus-within { border-color: var(--link); }
  .conversation, .protocol-body { scrollbar-color: var(--control-border) var(--panel-soft); }
}
