:root {
  --bg: #f6f7f9;
  --sidebar: #ffffff;
  --surface: #ffffff;
  --surface-raised: #f8f9fb;
  --surface-hover: #f0f2f5;
  --line: #e1e4e8;
  --line-strong: #c9ced6;
  --muted: #69717d;
  --text: #17191c;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --green: #168758;
  --red: #d33c46;
  --warning: #a56813;
  --radius: 6px;
  --sidebar-width: 232px;
  --builder-width: 360px;
  font-family: "Geist Variable", Geist, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
}

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--builder-width);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 34px;
  border: 0;
  border-radius: var(--radius);
  color: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
.conversation-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: 0;
  background: #0f1217;
  color: var(--text);
  padding: 9px 10px;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--line-strong);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
}

textarea {
  resize: vertical;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
}

h3 {
  font-size: 14px;
  line-height: 1.35;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  padding: 16px 12px;
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  font-weight: 750;
}

.mark {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: var(--accent);
  color: #111318;
  font-size: 12px;
  font-weight: 900;
}

.brand-copy {
  min-width: 0;
}

.brand-copy small,
.builder-head small,
.builder-context small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
}

.environment {
  margin-left: auto;
  border: 1px solid #665626;
  border-radius: 3px;
  padding: 2px 4px;
  color: #dfc569;
  font-size: 8px;
  font-weight: 800;
}

.agent-switcher {
  padding: 16px 4px 12px;
}

.field-label,
.eyebrow,
.nav-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.agent-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 6px;
  margin-top: 7px;
}

.icon {
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--surface-raised);
  font-size: 18px;
  line-height: 1;
}

.icon:hover {
  border-color: var(--line-strong);
  background: var(--surface-hover);
}

.sidebar nav {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  padding: 0 2px 12px;
}

.nav-label {
  margin: 13px 8px 5px;
  font-size: 9px;
}

.sidebar nav button {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: #b7bec7;
  padding: 8px 10px;
  text-align: left;
}

.sidebar nav button span {
  width: 17px;
  color: #747e89;
  text-align: center;
}

.sidebar nav button:hover {
  background: var(--surface-raised);
  color: var(--text);
}

.sidebar nav button.active {
  border-color: #313842;
  background: var(--surface-hover);
  box-shadow: inset 2px 0 var(--accent);
  color: #fff;
}

.sidebar nav button.active span {
  color: var(--accent);
}

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding: 13px 6px 0;
  color: var(--muted);
  font-size: 11px;
}

.sidebar-foot span:first-child,
.status-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: var(--accent);
}

main {
  min-width: 0;
  padding: 0 26px 40px;
}

header {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
}

.section-heading {
  min-width: 0;
}

.eyebrow {
  max-width: 45vw;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions,
.item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.revision {
  margin-right: 6px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.primary,
.secondary,
.danger {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
}

.primary {
  background: var(--accent);
  color: #121316;
}

.primary:hover {
  background: var(--accent-hover);
}

.secondary {
  border: 1px solid var(--line);
  background: var(--surface-raised);
}

.secondary:hover {
  border-color: var(--line-strong);
  background: var(--surface-hover);
}

.danger {
  border: 1px solid #67363a;
  background: #3c2024;
  color: #ffb5b5;
}

.danger:hover {
  background: #4b262a;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 12px;
}

.panel {
  min-width: 0;
  grid-column: span 12;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 17px;
}

.panel.half {
  grid-column: span 6;
}

.panel.third {
  grid-column: span 4;
}

.panel-head {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2,
.panel-head h3 {
  margin-bottom: 0;
}

.metric {
  margin: 4px 0 1px;
  font-size: 28px;
  font-weight: 780;
}

.muted {
  color: var(--muted);
}

.caption {
  color: var(--muted);
  font-size: 11px;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.field label {
  display: block;
  margin: 0 0 6px;
  color: #adb5be;
  font-size: 11px;
}

.field textarea.tall {
  min-height: 330px;
}

.item-list {
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
}

.item {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(140px, 0.7fr) minmax(180px, 1.4fr) auto;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 12px 4px;
}

.item > * {
  min-width: 0;
  overflow-wrap: anywhere;
}

.item strong {
  display: block;
  margin-bottom: 4px;
}

.tag {
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  border: 1px solid #4b545e;
  border-radius: 4px;
  padding: 3px 7px;
  color: #cbd1d7;
  font-size: 10px;
  overflow-wrap: anywhere;
}

.tarot-waiting-label {
  border-color: #7c4a09;
  background: #fff7d6;
  color: #6a3e05;
}

.tag.yellow {
  border-color: #705d25;
  color: #f4d570;
}

.tag.green {
  border-color: #286949;
  color: #7adbac;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  color: var(--muted);
  font-size: 10px;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

td {
  border-bottom: 1px solid var(--line);
  padding: 11px 8px;
  vertical-align: top;
}

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 34px;
  color: var(--muted);
  text-align: center;
}

.error-bubble {
  border-color: #703b3f;
  color: #ffc2c2;
}

.messages {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 22px max(18px, calc((100% - 820px) / 2));
  scroll-behavior: smooth;
}

.bubble {
  position: relative;
  max-width: min(74%, 660px);
  border-radius: var(--radius);
  padding: 10px 12px 8px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  box-shadow: 0 8px 22px #0003;
}

.bubble.user {
  align-self: flex-end;
  border: 1px solid #65582b;
  background: #393325;
}

.bubble.assistant {
  align-self: flex-start;
  border: 1px solid var(--line);
  background: var(--surface-raised);
}

.bubble-meta {
  display: block;
  margin-top: 5px;
  color: #8d969f;
  font-size: 9px;
  line-height: 1.2;
  text-align: right;
}

.message-enter {
  animation: message-enter 260ms cubic-bezier(.2, .8, .2, 1) both;
  animation-delay: var(--message-delay, 0ms);
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  width: 22px;
}

.typing-dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  animation: typing-dot 900ms ease-in-out infinite;
}

.typing-dots i:nth-child(2) {
  animation-delay: 120ms;
}

.typing-dots i:nth-child(3) {
  animation-delay: 240ms;
}

.runtime-stages {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  margin-top: 10px;
}

.stage {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  border-top: 1px solid #363e47;
  padding-top: 7px;
  color: #6f7984;
  font-size: 9px;
  line-height: 1.2;
  transition: color 180ms ease, border-color 180ms ease;
}

.stage b,
.stage-check,
.stage-error {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #404953;
  border-radius: 50%;
  font-size: 8px;
}

.stage.active {
  border-color: var(--accent);
  color: var(--text);
}

.stage.active b {
  border-color: var(--accent);
  background: #3c341d;
  color: var(--accent);
  box-shadow: 0 0 0 3px #f3c54412;
}

.stage.complete {
  border-color: #286949;
  color: #79cda4;
}

.stage.complete b {
  border-color: #286949;
  color: transparent;
}

.stage.complete b::after {
  content: "✓";
  color: var(--green);
}

.stage-check {
  border-color: #286949;
  color: var(--green);
}

.stage-error {
  border-color: #703b3f;
  color: var(--red);
}

.button-spinner {
  width: 11px;
  height: 11px;
  display: inline-block;
  border: 2px solid #1114;
  border-top-color: #111;
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin 700ms linear infinite;
}

@keyframes typing-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-3px); opacity: 1; }
}

@keyframes message-enter {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.builder {
  position: sticky;
  top: 0;
  min-width: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  border-left: 1px solid var(--line);
  background: #101419;
}

.builder.hidden {
  display: none;
}

.builder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.builder-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
}

.builder-spark {
  color: var(--accent);
  font-size: 18px;
}

.builder-context {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  border-bottom: 1px solid var(--line);
  background: #12171d;
  padding: 10px 16px;
}

.builder-context > div {
  min-width: 0;
}

.builder-context strong,
.builder-context small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  background: var(--green);
}

.builder-log {
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
}

.builder-message {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-raised);
  padding: 11px 12px;
  margin-bottom: 10px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.builder-message.user {
  border-color: #554a27;
  background: #302c22;
}

.builder-message.pending {
  border-color: #4a432c;
  background: #1d1b16;
}

.builder-message.failed {
  border-color: #703b3f;
  background: #211619;
  color: #ffc2c2;
}

.builder-message.failed p {
  margin: 7px 0 10px;
}

.builder-message pre {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  background: #0b0e12;
  padding: 8px;
  font-size: 11px;
  white-space: pre-wrap;
}

.builder-compose {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  background: #11151a;
  padding: 12px;
}

.builder-compose textarea {
  min-height: 76px;
}

.builder-open {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 14;
  width: 44px;
  height: 44px;
  display: none;
  border: 1px solid #f8dc75;
  background: var(--accent);
  color: #111318;
  font-size: 20px;
  box-shadow: 0 10px 30px #0008;
}

.builder-open.visible {
  display: block;
}

#notice {
  position: fixed;
  top: 12px;
  left: 50%;
  z-index: 30;
  transform: translateX(-50%);
}

.notice {
  max-width: min(520px, calc(100vw - 24px));
  border: 1px solid #35674a;
  border-radius: var(--radius);
  background: #1d392a;
  padding: 9px 14px;
  box-shadow: 0 10px 30px #0008;
  overflow-wrap: anywhere;
}

.notice.error {
  border-color: #733c3c;
  background: #402326;
}

dialog {
  width: min(680px, calc(100vw - 30px));
  max-height: calc(100vh - 30px);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
}

dialog.wide {
  width: min(1040px, calc(100vw - 30px));
}

dialog::backdrop {
  background: #000b;
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 15px 18px;
}

.modal-head h2 {
  margin-bottom: 0;
}

.modal-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.modal-actions + * {
  display: none;
}

#modalBody {
  max-height: calc(100vh - 170px);
  overflow: auto;
  padding: 18px;
}

.stack {
  display: grid;
  gap: 12px;
}

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.conversation-row {
  cursor: pointer;
}

.conversation-row:hover {
  background: var(--surface-raised);
}

.conversation-transcript {
  max-height: 340px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0e1115;
}

.section-subhead {
  margin: 18px 0 10px;
}

.run-list {
  display: grid;
  gap: 10px;
}

.run-evidence {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #11151a;
  padding: 13px;
}

.run-evidence-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.run-evidence-head strong {
  margin-right: 7px;
}

.evidence-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 10px;
}

.evidence-grid .caption {
  display: block;
  margin-bottom: 6px;
}

.run-evidence details {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.run-evidence summary {
  cursor: pointer;
  color: #cbd1d7;
  font-size: 12px;
}

.evidence-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.evidence-list > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #0b0e12;
  padding: 9px;
}

.evidence-list strong,
.evidence-list .caption {
  display: block;
}

.evidence-list p {
  margin: 6px 0 0;
  color: #cbd1d7;
  font-size: 12px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.run-evidence .item-actions {
  justify-content: flex-end;
  margin-top: 10px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 1180px) {
  body {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .builder {
    position: fixed;
    right: 0;
    z-index: 15;
    width: min(var(--builder-width), 100vw);
    box-shadow: -12px 0 30px #0009;
  }

  .panel.third {
    grid-column: span 6;
  }
}

@media (max-width: 760px) {
  body {
    display: block;
  }

  .sidebar {
    position: relative;
    width: 100%;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding-bottom: 10px;
  }

  .brand {
    padding-bottom: 12px;
  }

  .agent-switcher {
    padding: 12px 2px 8px;
  }

  .sidebar nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    overflow: visible;
    padding-bottom: 0;
  }

  .nav-label,
  .sidebar-foot {
    display: none;
  }

  body.view-preview .sidebar {
    padding: 6px 8px;
  }

  body.view-preview .brand,
  body.view-preview .agent-switcher {
    display: none;
  }

  body.view-preview .sidebar nav button {
    min-height: 38px;
    padding-block: 4px;
  }

  body.view-preview main {
    padding-bottom: 0;
  }

  body.view-preview header {
    align-items: center;
    margin-bottom: 8px;
    padding: 8px 0;
  }

  body.view-preview header .eyebrow,
  body.view-preview header .revision {
    display: none;
  }

  body.view-preview header h1 {
    font-size: 17px;
  }

  body.view-preview .header-actions {
    flex-wrap: nowrap;
    gap: 5px;
  }

  body.view-preview .preview-shell {
    height: calc(100dvh - 172px);
    min-height: 0;
  }

  .sidebar nav button {
    min-width: 0;
    min-height: 48px;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 6px 2px 5px;
    font-size: 0;
  }

  .sidebar nav button::after {
    content: attr(data-mobile-label);
    max-width: 100%;
    color: #aeb6bf;
    font-size: 8px;
    font-weight: 650;
    line-height: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sidebar nav button span {
    width: auto;
    font-size: 16px;
  }

  .sidebar nav button.active::after {
    color: var(--text);
  }

  .sidebar nav button.active {
    box-shadow: inset 0 -2px var(--accent);
  }

  main {
    padding: 0 12px 28px;
  }

  header {
    min-height: 0;
    align-items: flex-start;
    padding: 14px 0;
    margin-bottom: 14px;
  }

  h1 {
    font-size: 20px;
  }

  .header-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .revision {
    width: 100%;
    margin: 0;
    text-align: right;
  }

  .panel.half,
  .panel.third {
    grid-column: span 12;
  }

  .form-grid,
  .evidence-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .item {
    grid-template-columns: minmax(0, 1fr);
    gap: 9px;
  }

  .item-actions {
    flex-wrap: wrap;
  }

  .bubble {
    max-width: 90%;
  }

  .runtime-stages {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .compose-hint {
    display: none;
  }

  .preview-shell {
    height: min(680px, calc(100vh - 120px));
    min-height: 500px;
  }

  .builder {
    width: min(var(--builder-width), 100vw);
  }

  .run-evidence-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 430px) {
  .header-actions .secondary,
  .header-actions .primary {
    padding: 7px 9px;
  }

  .panel {
    padding: 14px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-head > .item-actions {
    width: 100%;
  }

  .panel-head > .item-actions button {
    flex: 1;
  }

  body.view-preview .preview-banner {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 7px;
    padding: 8px 10px;
  }

  body.view-preview .preview-banner span {
    display: none;
  }

  body.view-preview .preview-banner .tag {
    display: inline-flex;
  }

  body.view-preview .messages {
    gap: 8px;
    padding: 12px 10px;
  }

  body.view-preview .preview-compose {
    grid-template-columns: minmax(0, 1fr) 44px;
    align-items: stretch;
    padding: 8px;
  }

  body.view-preview .preview-compose textarea {
    min-height: 44px;
    max-height: 104px;
    resize: none;
    padding: 11px 10px;
  }

  body.view-preview .send-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    overflow: hidden;
    padding: 0;
    font-size: 0;
  }

  body.view-preview .send-button::before {
    content: "➤";
    font-size: 17px;
  }

  body.view-preview .send-button:disabled::before {
    content: "";
  }

  body.view-preview .send-button .button-spinner {
    width: 14px;
    height: 14px;
  }

  body:not(.view-preview) .preview-banner {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .preview-banner .secondary {
    grid-column: 1 / -1;
  }

  .preview-compose {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Compact operational shell */
.appbar {
  grid-area: appbar;
  min-width: 0;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  padding: 0 12px 0 8px;
  z-index: 20;
}

.appbar-product, .appbar-status {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
}

.appbar-product strong { font-size: 13px; white-space: nowrap; }
.appbar-mark {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: #17191c;
  color: #fff;
  font-size: 8px;
  font-weight: 850;
}
.appbar-divider { width: 1px; height: 18px; background: var(--line); }
.appbar-agent {
  max-width: 36vw;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rail-toggle { border-color: transparent; background: transparent; color: #555d68; font-size: 15px; }
.runtime-pill { display: inline-flex; align-items: center; gap: 6px; color: #535b66; font-size: 11px; }
.runtime-pill i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px #16875815;
}

body {
  height: 100vh;
  grid-template-areas: "appbar appbar appbar" "sidebar main builder";
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--builder-width);
  grid-template-rows: 44px minmax(0, 1fr);
  overflow: hidden;
  background: var(--bg);
  transition: grid-template-columns 220ms cubic-bezier(.2, .8, .2, 1);
}
.sidebar {
  grid-area: sidebar;
  position: static;
  height: 100%;
  border-color: var(--line);
  background: var(--sidebar);
  padding: 12px 10px;
  overflow: hidden;
}
.brand { display: none; }
.agent-switcher { padding: 2px 2px 13px; }
.field-label, .eyebrow, .nav-label { color: #7a828e; letter-spacing: .06em; }
.agent-row { grid-template-columns: minmax(0, 1fr) 34px; }
.agent-row select, input, select, textarea { border-color: var(--line); background: #fff; color: var(--text); }
input::placeholder, textarea::placeholder { color: #959ca6; }
.sidebar nav { gap: 1px; padding-inline: 0; }
.nav-label { margin: 12px 10px 5px; }
.sidebar nav button {
  min-height: 36px;
  gap: 10px;
  border: 0;
  border-radius: 5px;
  color: #4f5762;
  padding: 7px 9px;
  transition: background 150ms ease, color 150ms ease, transform 150ms ease;
}
.sidebar nav button b {
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  font-weight: 560;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar nav button span { color: #747d88; font-size: 15px; }
.sidebar nav button:hover { background: #f3f4f6; color: #17191c; }
.sidebar nav button:active { transform: scale(.98); }
.sidebar nav button.active { border: 0; background: #eef2ff; box-shadow: none; color: #1d4ed8; }
.sidebar nav button.active span { color: #2563eb; }
.sidebar-foot { border-color: var(--line); }

main {
  grid-area: main;
  min-height: 0;
  overflow: auto;
  padding: 0 24px 36px;
  background: var(--bg);
}
header {
  position: sticky;
  top: 0;
  z-index: 8;
  min-height: 58px;
  border-color: var(--line);
  margin-bottom: 14px;
  background: rgba(246, 247, 249, .94);
  backdrop-filter: blur(14px);
}
h1 { color: #111317; font-size: 20px; font-weight: 650; }
h2 { color: #202328; font-weight: 640; }
.revision {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 4px 8px;
  color: #5e6671;
}
.primary, .secondary, .danger {
  min-height: 34px;
  transition: background 150ms ease, border-color 150ms ease, box-shadow 150ms ease, transform 120ms ease;
}
.primary:active, .secondary:active, .danger:active { transform: translateY(1px); }
.primary { background: var(--accent); color: #fff; box-shadow: 0 1px 2px #1112; }
.primary:hover { background: var(--accent-hover); }
.secondary { border-color: var(--line); background: #fff; color: #30353c; }
.secondary:hover { border-color: var(--line-strong); background: #f8f9fb; }
.danger { border-color: #f0c8cc; background: #fff6f6; color: #b4232e; }
.danger:hover { background: #feecef; }
#content { animation: view-enter 220ms cubic-bezier(.2, .8, .2, 1) both; }
.panel { border-color: var(--line); background: var(--surface); box-shadow: 0 1px 2px #10182808; }
.panel.third { position: relative; overflow: hidden; }
.panel.third::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: #d9e3fb; }
.metric { color: #111317; font-size: 26px; }
.field label { color: #5c6470; }
.item-list, .item, th, td { border-color: var(--line); }
.item:hover, .conversation-row:hover { background: #fafbfc; }
.tag { border-color: #d5d9df; background: #f8f9fb; color: #525a65; }
.tag.yellow { border-color: #ead6ae; background: #fff9ed; color: #8a5a0a; }
.tag.green { border-color: #b9decf; background: #effaf5; color: #0d7048; }
.tarot-waiting-label { border-color: #d8b257; background: #fff7d6; color: #6a3e05; }
.empty { border-color: #cfd4db; background: #fafbfc; }

.preview-shell {
  height: 100%;
  min-height: 520px;
  border-color: var(--line);
  background: #f7f8fa;
  box-shadow: 0 1px 3px #10182810;
}
body.view-preview main {
  padding: 0;
  overflow: hidden;
}
body.view-preview #content {
  height: 100%;
}
body.view-preview header {
  display: none;
}
.preview-banner {
  min-height: 54px;
  border-color: var(--line);
  background: rgba(255,255,255,.98);
  padding: 8px 14px;
  backdrop-filter: blur(14px);
}
.preview-banner::before {
  content: "MB";
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #17191c;
  color: #fff;
  font-size: 9px;
  font-weight: 800;
}
.preview-banner > .tag { display: none; }
.preview-banner strong { font-size: 13px; }
.preview-banner span { max-width: 58ch; }
.messages {
  gap: 10px;
  padding: 18px max(22px, calc((100% - 920px) / 2));
  scrollbar-gutter: stable;
}
.bubble {
  max-width: min(78%, 720px);
  border-radius: 8px;
  box-shadow: 0 1px 2px #1018280d;
}
.bubble.user { border-color: #2563eb; background: #2563eb; color: #fff; }
.bubble.user .bubble-meta { color: #dbeafe; }
.bubble.user.sending { box-shadow: 0 0 0 3px #2563eb16, 0 8px 24px #2563eb20; }
.bubble.user.sent { transition: box-shadow 180ms ease; }
.bubble.assistant { border-color: #dfe3e8; background: #fff; color: #202328; }
.message-state {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.message-state::before {
  content: "";
  width: 7px;
  height: 7px;
  border: 1px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
.sent .message-state::before {
  content: "✓";
  width: auto;
  height: auto;
  border: 0;
  animation: none;
  font-size: 9px;
}
.preview-activity {
  width: min(100%, 720px);
  border-color: #cbd8f6;
  background: #fff;
  box-shadow: 0 10px 30px #2563eb12;
  transform-origin: left center;
}
.preview-activity:not(.settled):not(.failed) {
  box-shadow: 0 0 0 3px #2563eb0b, 0 12px 32px #2563eb16;
}
.preview-activity.settled {
  width: auto;
  min-width: 210px;
  border-color: #c8e4d8;
  background: #f8fdfb;
  padding: 7px 10px;
  box-shadow: none;
  opacity: .86;
}
.preview-activity.settled .runtime-stages { display: none; }
.preview-activity.settled .typing-line { min-height: 18px; }
.preview-activity.failed { border-color: #efc1c5; background: #fff6f6; }
.typing-dots i { background: var(--accent); }
.stage { border-color: #e1e5ea; color: #848c96; }
.stage b, .stage-check, .stage-error { border-color: #d5dae0; }
.stage.active { border-color: var(--accent); color: #30353c; }
.stage.active b { border-color: var(--accent); background: #edf3ff; color: var(--accent); box-shadow: 0 0 0 3px #2563eb0d; }
.preview-compose {
  border-color: var(--line);
  background: rgba(255,255,255,.98);
  padding: 10px max(22px, calc((100% - 920px) / 2));
  backdrop-filter: blur(14px);
}
.preview-compose textarea {
  min-height: 50px;
  border-color: #cfd4dc;
  background: #fff;
  box-shadow: 0 1px 2px #10182808;
  resize: none;
}
.preview-compose textarea:focus { border-color: #8eabef; box-shadow: 0 0 0 3px #2563eb12; }
.preview-compose.is-busy textarea { background: #f8fafc; color: #6b7280; cursor: progress; }
.compose-hint { color: #858d98; }
.send-button { height: 50px; min-width: 102px; }
.send-button:disabled { opacity: 1; background: #1d4ed8; cursor: progress; }

.builder {
  grid-area: builder;
  position: static;
  min-height: 0;
  height: 100%;
  border-color: var(--line);
  background: #fff;
  box-shadow: -1px 0 #e7e9ed;
}
.builder-head { min-height: 58px; border-color: var(--line); padding: 11px 14px; }
.builder-spark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #17191c;
  color: #fff;
  font-size: 13px;
}
.builder-head small, .builder-context small { color: var(--muted); }
.builder-context { border-color: var(--line); background: #fafbfc; padding: 9px 14px; }
.builder-log { background: #f8f9fb; padding: 14px 12px 20px; }
.builder-message {
  border-color: #dfe3e8;
  border-radius: 8px;
  background: #fff;
  color: #25292f;
  box-shadow: 0 1px 2px #1018280a;
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}
.builder-message.user {
  margin-left: 34px;
  border-color: #2563eb;
  background: #2563eb;
  color: #fff;
  box-shadow: 0 6px 18px #2563eb1f;
}
.builder-message.pending {
  border-color: #cbd8f6;
  background: #f5f8ff;
  box-shadow: 0 0 0 3px #2563eb0a;
}
.builder-message.proposal { border-color: #ccd6e3; box-shadow: 0 8px 24px #1018280d; }
.builder-message.applied { border-color: #b9decf; background: #f5fcf8; }
.builder-message.failed { border-color: #efc1c5; background: #fff6f6; color: #a32630; }
.builder-progress {
  display: grid;
  gap: 9px;
}
.builder-progress .typing-line {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
}
.builder-progress .typing-line strong {
  min-width: 0;
  flex: 1;
  font-size: 11px;
  line-height: 1.35;
}
.builder-progress .elapsed {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
}
.builder-progress-track {
  height: 3px;
  overflow: hidden;
  border-radius: 2px;
  background: #dfe6f5;
}
.builder-progress-track i {
  width: 42%;
  height: 100%;
  display: block;
  background: var(--accent);
  animation: builder-progress 1.2s ease-in-out infinite;
}
.builder-message .proposal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}
.builder-message .proposal-state { color: var(--muted); font-size: 10px; }
.builder-message .apply-proposal.applied { background: var(--green); }
.builder-message pre { border-color: var(--line); background: #f6f7f9; color: #30353c; }
.builder-compose { border-color: var(--line); background: #fff; }
.builder-compose textarea { min-height: 68px; border-color: #cfd4dc; background: #fff; }
.builder-open { border-color: #17191c; background: #17191c; color: #fff; box-shadow: 0 10px 30px #1018282b; }
.notice { border-color: #b9decf; background: #effaf5; color: #0d7048; box-shadow: 0 10px 30px #1018281f; }
.notice.error { border-color: #efc1c5; background: #fff1f2; color: #a32630; }
dialog { border-color: var(--line-strong); background: #fff; color: var(--text); box-shadow: 0 24px 80px #10182838; }
dialog::backdrop { background: #11182766; backdrop-filter: blur(2px); }
.modal-head, .modal-actions { border-color: var(--line); }
.conversation-transcript, .run-evidence, .evidence-list > div { border-color: var(--line); background: #f8f9fb; }
.conversation-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
  margin-top: 10px;
}
.conversation-policy {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 13px;
}
.conversation-policy-head,
.conversation-policy-actions,
.status-control {
  display: flex;
  align-items: center;
  gap: 8px;
}
.conversation-policy-head {
  justify-content: space-between;
}
.conversation-policy-head strong,
.conversation-policy-head .caption {
  display: block;
}
.conversation-policy-head .caption {
  margin-bottom: 3px;
}
.conversation-policy-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}
.conversation-policy-grid > div {
  min-width: 0;
  padding: 9px;
  background: #f8f9fb;
}
.conversation-policy-grid dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}
.conversation-policy-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 12px;
  font-weight: 650;
}
.policy-warning {
  color: var(--warning);
}
.policy-blockers {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.policy-blockers span,
.policy-clear {
  border-radius: 4px;
  background: #fff4e5;
  color: #87530a;
  padding: 5px 7px;
  font-size: 11px;
}
.policy-clear {
  background: #edf8f3;
  color: var(--green);
}
.conversation-policy-actions {
  flex-wrap: wrap;
}
.status-control {
  margin-left: auto;
}
.status-control .selected {
  border-color: var(--accent);
  color: var(--accent);
  opacity: 1;
}
.conversation-compose-main {
  min-width: 0;
  display: grid;
  gap: 7px;
}
.delivery-mode {
  width: fit-content;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #f3f5f8;
}
.delivery-mode label {
  position: relative;
  cursor: pointer;
}
.delivery-mode input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.delivery-mode span {
  min-height: 30px;
  display: grid;
  place-items: center;
  padding: 5px 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}
.delivery-mode input:checked + span {
  background: #fff;
  color: var(--text);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.delivery-mode input:disabled + span {
  cursor: not-allowed;
  opacity: .45;
}
.delivery-mode input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.composer-policy-note {
  color: var(--muted);
  font-size: 10px;
}
.conversation-composer textarea {
  min-height: 54px;
  max-height: 160px;
  background: #fff;
}
.conversation-composer button {
  min-width: 104px;
  min-height: 40px;
}
.run-evidence details { border-color: var(--line); }

body.rail-collapsed { grid-template-columns: 56px minmax(0, 1fr) var(--builder-width); }
body.rail-collapsed .sidebar { padding-inline: 8px; }
body.rail-collapsed .agent-switcher,
body.rail-collapsed .nav-label,
body.rail-collapsed .sidebar-foot,
body.rail-collapsed .sidebar nav button b { display: none; }
body.rail-collapsed .sidebar nav { padding-top: 4px; }
body.rail-collapsed .sidebar nav button { width: 40px; height: 40px; justify-content: center; padding: 0; }
body.rail-collapsed .sidebar nav button span { width: auto; font-size: 16px; }

@keyframes builder-progress {
  from { transform: translateX(-115%); }
  to { transform: translateX(340%); }
}

@keyframes view-enter {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1180px) {
  body, body.rail-collapsed {
    grid-template-areas: "appbar appbar" "sidebar main";
    grid-template-columns: 56px minmax(0, 1fr);
  }
  .sidebar { padding-inline: 8px; }
  .agent-switcher, .nav-label, .sidebar-foot, .sidebar nav button b { display: none; }
  .sidebar nav button { width: 40px; height: 40px; justify-content: center; padding: 0; }
  .sidebar nav button span { width: auto; }
  .builder { position: fixed; top: 44px; right: 0; height: calc(100vh - 44px); box-shadow: -16px 0 42px #10182824; }
}

@media (max-width: 760px) {
  body, body.rail-collapsed {
    height: 100dvh;
    display: grid;
    grid-template-areas: "appbar" "main" "sidebar";
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 44px minmax(0, 1fr) 58px;
  }
  .appbar { padding-right: 8px; }
  .appbar-divider, .appbar-agent, .appbar-status .environment, .rail-toggle { display: none; }
  .sidebar {
    width: 100%;
    height: 58px;
    border-top: 1px solid var(--line);
    border-right: 0;
    border-bottom: 0;
    padding: 4px 6px;
    overflow-x: auto;
  }
  .sidebar nav {
    height: 50px;
    display: grid;
    grid-template-columns: repeat(10, minmax(48px, 1fr));
    gap: 2px;
    overflow-x: auto;
    padding: 0;
  }
  .sidebar nav button, body.rail-collapsed .sidebar nav button {
    width: auto;
    height: 48px;
    min-height: 48px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 2px;
    font-size: 0;
  }
  .sidebar nav button::after { color: #66707c; }
  .sidebar nav button.active { box-shadow: inset 0 -2px var(--accent); }
  main { height: 100%; padding: 0 12px 20px; }
  header { min-height: 58px; padding: 8px 0; margin-bottom: 10px; }
  .header-actions .revision { display: none; }
  body.view-preview main { padding: 0; }
  body.view-preview #content { height: 100%; }
  body.view-preview header { display: none; }
  body.view-preview .preview-shell { height: 100%; padding: 0; border-width: 1px 0 0; border-radius: 0; }
  .builder { top: 44px; width: min(100vw, var(--builder-width)); height: calc(100dvh - 44px); }
  .builder-open { bottom: 70px; }
  dialog.wide { width: calc(100vw - 12px); max-height: calc(100dvh - 12px); }
  #modalBody { padding: 12px; }
  .conversation-policy-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .conversation-policy-actions { align-items: stretch; }
  .status-control { width: 100%; margin-left: 0; }
  .status-control button { flex: 1; }
  .conversation-composer { grid-template-columns: 1fr; }
  .conversation-composer > button { width: 100%; }
}


/* Approval-gated conversational media and controlled actions */
.media-workspace {
  grid-template-columns: minmax(0, 1.65fr) minmax(280px, .85fr);
  align-items: start;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.media-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface, #fff);
}

.media-preview-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #e8edf2;
  cursor: zoom-in;
}

.media-preview-button img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.media-card-body {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.media-card-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.media-card-title strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.media-review-flags {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.actions-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr);
  gap: 14px;
  align-items: start;
}

.action-editor {
  position: sticky;
  top: 88px;
}

.action-metadata {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin: 18px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--line);
}

.action-metadata div {
  display: grid;
  gap: 5px;
  padding: 12px;
  background: var(--surface, #fff);
}

.action-metadata dt {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.action-metadata dd {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

.action-gates {
  display: grid;
  gap: 9px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.action-gates > div {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
}

.action-gates i {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--green);
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  line-height: 1.45;
}

.check-row input {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  accent-color: var(--green);
}

.media-review-dialog {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(240px, .85fr);
  gap: 22px;
  align-items: start;
}

.media-review-image,
.media-lightbox {
  display: block;
  width: 100%;
  max-height: 68vh;
  object-fit: contain;
  border-radius: 6px;
  background: #e8edf2;
}

.bubble.media-bubble {
  padding: 5px;
  overflow: hidden;
}

.conversation-image {
  display: block;
  width: min(320px, 70vw);
  max-width: 100%;
  max-height: 440px;
  object-fit: cover;
  border-radius: 5px;
}

.media-bubble .bubble-meta,
.media-bubble .caption {
  display: block;
  padding: 6px 7px 3px;
}

@media (max-width: 1180px) {
  .media-workspace,
  .actions-workspace { grid-template-columns: 1fr; }
  .action-editor { position: static; }
}

@media (max-width: 760px) {
  .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .media-review-dialog,
  .action-metadata { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
  .appbar-product strong { font-size: 12px; }
  .appbar-status { gap: 5px; }
  .runtime-pill span { display: none; }
  .preview-banner { min-height: 52px; }
  .preview-banner::before { width: 30px; height: 30px; }
  body.view-preview .messages { padding: 14px 10px; }
  .media-grid { grid-template-columns: 1fr; }
}

body.view-preview,
body.view-preview.rail-collapsed {
  grid-template-areas: "appbar appbar" "sidebar main";
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}
body.view-preview.rail-collapsed {
  grid-template-columns: 56px minmax(0, 1fr);
}
body.view-preview .builder-open { display: none; }

/* Messenger-style Preview */
.preview-shell {
  --preview-accent: #7360f2;
  --preview-accent-hover: #6552e6;
  --preview-canvas: #eef1f5;
  --preview-ink: #1f2329;
  --preview-muted: #747c88;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: var(--preview-canvas);
  padding: 0;
  box-shadow: none;
}

.preview-banner {
  min-height: 62px;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 11px;
  padding: 8px max(16px, calc((100% - 920px) / 2));
  border-color: #dfe3e8;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 1px 8px #18202b0b;
}

.preview-banner::before { display: none; }

.preview-avatar {
  position: relative;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #2a2e35;
  color: #fff;
  font-size: 11px;
  font-weight: 750;
}

.preview-avatar i {
  position: absolute;
  right: 0;
  bottom: 1px;
  width: 10px;
  height: 10px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #24a36a;
}

.preview-contact {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.preview-contact strong {
  overflow: hidden;
  color: var(--preview-ink);
  font-size: 14px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-contact span {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 0;
  color: #6f7782;
  font-size: 10px;
}

.preview-contact span i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #24a36a;
}

.preview-sandbox {
  margin: 0 !important;
  border: 1px solid #d9dde3;
  border-radius: 999px;
  background: #f7f8fa;
  padding: 5px 9px;
  color: #68717d !important;
  font-size: 10px !important;
  white-space: nowrap;
}

.preview-reset {
  min-height: 34px;
  border: 0;
  background: transparent;
  color: #555e69;
  padding: 6px 8px;
  font-size: 11px;
}

.preview-reset:hover { background: #f1f3f6; color: #20242a; }

body.view-preview .messages {
  gap: 7px;
  padding: 18px max(22px, calc((100% - 920px) / 2)) 24px;
  background:
    linear-gradient(rgba(255, 255, 255, .74), rgba(255, 255, 255, .74)),
    radial-gradient(circle at 1px 1px, #9ca5b022 1px, transparent 0);
  background-size: auto, 22px 22px;
  overscroll-behavior: contain;
}

.preview-day {
  align-self: center;
  margin: 2px 0 7px;
}

.preview-day span {
  display: block;
  border-radius: 999px;
  background: #dfe4ea;
  padding: 4px 9px;
  color: #68717c;
  font-size: 9px;
  font-weight: 650;
}

body.view-preview .bubble {
  max-width: min(76%, 650px);
  border: 0;
  border-radius: 12px;
  padding: 9px 11px 6px;
  color: var(--preview-ink);
  box-shadow: 0 1px 2px #18202b14;
  transition: background 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

body.view-preview .bubble.user {
  border-bottom-right-radius: 4px;
  background: #e4e1ff;
  color: #24202f;
}

body.view-preview .bubble.assistant {
  border-bottom-left-radius: 4px;
  background: #fff;
}

body.view-preview .bubble-copy {
  display: block;
  font-size: 13px;
  line-height: 1.42;
  white-space: pre-wrap;
}

body.view-preview .bubble-meta {
  min-height: 12px;
  margin-top: 3px;
  color: #7a818b;
  font-size: 9px;
}

body.view-preview .bubble.user .bubble-meta { color: #68627f; }
body.view-preview .bubble.sending { opacity: .78; }
body.view-preview .bubble.failed { background: #fee9ec; box-shadow: 0 0 0 1px #e6aeb6; }

body.view-preview .message-state::before {
  width: 7px;
  height: 7px;
}

body.view-preview .sent .message-state::before {
  content: "✓✓";
  color: var(--preview-accent);
  font-size: 8px;
  letter-spacing: 0;
}

body.view-preview .failed .message-state::before {
  content: "!";
  width: 12px;
  height: 12px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #b42332;
  border-radius: 50%;
  color: #b42332;
  animation: none;
  font-size: 8px;
  font-weight: 700;
}

.message-retry {
  min-height: 0;
  margin-left: 7px;
  border: 0;
  background: transparent;
  padding: 0;
  color: #8f2631;
  font-size: 9px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.preview-activity {
  width: auto;
  max-width: min(82%, 380px);
  display: grid;
  gap: 5px;
  align-self: flex-start;
  border: 0;
  border-radius: 12px 12px 12px 4px;
  background: #fff;
  padding: 8px 11px;
  color: var(--preview-ink);
  box-shadow: 0 1px 2px #18202b14;
}

.preview-activity:not(.settled):not(.failed) { box-shadow: 0 1px 2px #18202b14; }
.preview-activity.failed { border: 1px solid #e6b5bb; background: #fff5f6; }

.typing-presence {
  min-height: 19px;
  display: flex;
  align-items: center;
  gap: 7px;
  color: #5e6671;
  font-size: 11px;
}

.typing-dots {
  width: auto;
  gap: 3px;
  border-radius: 999px;
  background: #f0efff;
  padding: 5px 7px;
}

.typing-dots i { background: var(--preview-accent); }

.runtime-details,
.reply-runtime-details {
  color: #858c96;
  font-size: 9px;
  white-space: normal;
}

.runtime-details summary,
.reply-runtime-details summary {
  width: fit-content;
  display: flex;
  align-items: center;
  gap: 7px;
  color: #858c96;
  cursor: pointer;
  list-style: none;
}

.runtime-details summary::-webkit-details-marker,
.reply-runtime-details summary::-webkit-details-marker { display: none; }
.runtime-details summary::before,
.reply-runtime-details summary::before { content: "›"; font-size: 12px; transition: transform 150ms ease; }
.runtime-details[open] summary::before,
.reply-runtime-details[open] summary::before { transform: rotate(90deg); }

.runtime-stages {
  grid-template-columns: 1fr;
  gap: 4px;
  margin: 7px 0 1px;
  padding: 0;
  list-style: none;
}

.runtime-details .stage,
.reply-runtime-details .stage {
  border: 0;
  padding: 0;
  color: #757d88;
  font-size: 9px;
}

.runtime-details .stage b,
.reply-runtime-details .stage b {
  width: 14px;
  height: 14px;
  flex-basis: 14px;
  border-color: #cbd1d8;
}

.runtime-details .stage.active b { border-color: var(--preview-accent); background: #f0efff; color: var(--preview-accent); box-shadow: none; }
.reply-runtime-details { margin-top: 4px; }
.reply-runtime-details .runtime-stages { min-width: 190px; }

.preview-failure {
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-failure div { display: grid; gap: 1px; }
.preview-failure strong { color: #872630; font-size: 11px; }
.preview-failure div span { color: #a2444e; font-size: 10px; }

.preview-compose {
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: end;
  gap: 8px;
  border-color: #dfe3e8;
  background: rgba(255, 255, 255, .96);
  padding: 10px max(16px, calc((100% - 920px) / 2));
  box-shadow: 0 -1px 8px #18202b08;
}

.preview-compose .compose-field {
  display: flex;
  align-items: center;
  border: 1px solid #d5dae1;
  border-radius: 18px;
  background: #f8f9fb;
  transition: border-color 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

.preview-compose .compose-field:focus-within {
  border-color: #a9a0ee;
  background: #fff;
  box-shadow: 0 0 0 3px #7360f212;
}

.preview-compose textarea {
  width: 100%;
  height: 42px;
  min-height: 42px;
  max-height: 120px;
  overflow-y: hidden;
  border: 0;
  border-radius: 18px;
  background: transparent;
  padding: 11px 14px;
  color: var(--preview-ink);
  line-height: 20px;
  resize: none;
  box-shadow: none;
  transition: height 120ms ease;
}

.preview-compose textarea.is-scrollable { overflow-y: auto; }
.preview-compose textarea:focus { border: 0; box-shadow: none; }
.preview-compose.is-busy textarea { background: transparent; color: var(--preview-ink); cursor: text; }
.preview-photo-button {
  display: grid;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  place-items: center;
  color: #5f6f82;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}
.preview-photo-button:hover { color: var(--preview-accent); }
.preview-photo-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.preview-photo-name {
  max-width: 170px;
  overflow: hidden;
  border: 0;
  background: transparent;
  color: #5f6f82;
  cursor: pointer;
  font-size: 11px;
  text-decoration: underline;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.send-button {
  width: 42px;
  min-width: 42px;
  height: 42px;
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--preview-accent);
  padding: 0;
  box-shadow: 0 2px 7px #5d4cce36;
}

.send-button span { font-size: 20px; line-height: 1; transform: translateY(-1px); }
.send-button:hover { background: var(--preview-accent-hover); }
.send-button:disabled { background: #d8dbe0; box-shadow: none; cursor: default; }
.preview-compose.is-busy .send-button:disabled { background: #d8dbe0; cursor: progress; }

@media (max-width: 1180px) {
  body.view-preview,
  body.view-preview.rail-collapsed {
    grid-template-areas: "appbar appbar" "sidebar main";
    grid-template-columns: 56px minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  body.view-preview,
  body.view-preview.rail-collapsed {
    grid-template-areas: "appbar" "main" "sidebar";
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 44px minmax(0, 1fr) 58px;
  }
  .preview-banner { grid-template-columns: auto minmax(0, 1fr) auto; padding: 7px 11px; }
  .preview-sandbox { display: none !important; }
  .preview-reset { padding-inline: 5px; }
  body.view-preview .messages { padding: 14px 10px 18px; }
  body.view-preview .bubble { max-width: 84%; }
  .preview-compose { padding: 8px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .message-enter, .typing-dots i { animation: none; }
  .messages { scroll-behavior: auto; }
  .runtime-details summary::before, .reply-runtime-details summary::before { transition: none; }
}
