:root {
  color-scheme: dark;
  --bg: #0b1020;
  --panel: rgba(18, 25, 49, 0.88);
  --panel-border: rgba(148, 163, 184, 0.22);
  --text: #ecf0ff;
  --muted: #94a3b8;
  --accent: #40a870;
  --accent-strong: #58b858;
  --success: #34d399;
  --warning: #f59e0b;
  --danger: #fb7185;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background:
    radial-gradient(circle at top left, rgba(64, 168, 112, 0.18), transparent 32%),
    radial-gradient(circle at top right, rgba(88, 184, 88, 0.18), transparent 28%),
    linear-gradient(180deg, #09101e 0%, #0b1020 100%);
  color: var(--text);
}

.shell {
  width: min(980px, calc(100% - 24px));
  margin: 0 auto;
  padding: 12px 0 20px;
}

.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  min-height: 28px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

[hidden] {
  display: none !important;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 12px;
  font-weight: 700;
}

.chat-head h1 {
  margin: 0;
  font-size: 20px;
}

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 20px;
}

.session-rail {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: calc(100vh - 72px);
  padding: 16px;
}

.session-rail-header {
  margin-bottom: 0;
}

.session-rail-header h2 {
  font-size: 18px;
}

.session-new-button {
  padding: 10px 12px;
  border-radius: 12px;
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.session-rail-empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.session-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(170, 180, 214, 0.14);
  background: rgba(7, 10, 20, 0.48);
  text-align: left;
}

.session-item.active {
  border-color: rgba(64, 168, 112, 0.36);
  background: linear-gradient(135deg, rgba(64, 168, 112, 0.18), rgba(88, 184, 88, 0.16));
}

.session-item-title {
  font-size: 14px;
  font-weight: 700;
}

.session-item-preview,
.session-item-time {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.controls-panel {
  grid-column: 1 / -1;
  min-width: 0;
}

.transcript-panel {
  grid-column: 1 / -1;
}

.dev-panel {
  grid-column: 1 / -1;
}

.panel-half {
  min-height: 280px;
}

.lead-copy {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.7;
}

.single-chat-shell {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: calc(100vh - 72px);
  padding: 16px;
}

.chat-intro {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 2px 0 6px;
}

.chat-intro-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.chat-intro-text {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.identity-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(170, 180, 214, 0.12);
  background: rgba(7, 10, 20, 0.42);
}

.auth-action {
  width: auto;
  padding: 10px 12px;
}

.journey-context-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(170, 180, 214, 0.12);
  background: rgba(7, 10, 20, 0.46);
}

.experience-state-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(170, 180, 214, 0.12);
  background: rgba(7, 10, 20, 0.42);
}

.journey-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(64, 168, 112, 0.12);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.journey-pill.state-active {
  background: linear-gradient(135deg, rgba(64, 168, 112, 0.24), rgba(88, 184, 88, 0.22));
  color: var(--text);
}

.journey-pill.transport-rest {
  background: rgba(245, 158, 11, 0.14);
  color: var(--warning);
}

.journey-pill.transport-ws {
  background: rgba(52, 211, 153, 0.14);
  color: var(--success);
}

.journey-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  flex: 1 1 320px;
}

.experience-surface {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stage-panel,
.support-card {
  border-radius: 18px;
  border: 1px solid rgba(170, 180, 214, 0.14);
  background: rgba(7, 10, 20, 0.52);
}

.stage-panel {
  padding: 18px 16px;
}

.stage-panel-header {
  align-items: flex-start;
}

.stage-kicker {
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
  font-weight: 700;
}

.stage-title {
  margin: 0;
  font-size: 22px;
  line-height: 1.35;
}

.stage-summary {
  margin: 12px 0 0;
  font-size: 15px;
  line-height: 1.7;
}

.stage-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

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

.support-card {
  padding: 14px;
}

.support-card-hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.revisit-support-card {
  border-color: rgba(64, 168, 112, 0.24);
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.88), rgba(7, 10, 20, 0.74));
}

.revisit-entry-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-color: rgba(64, 168, 112, 0.24);
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.88), rgba(7, 10, 20, 0.74));
}

.revisit-entry-actions {
  margin-top: 0;
}

.theatre-card {
  border-color: rgba(88, 184, 88, 0.28);
  background: linear-gradient(180deg, rgba(8, 128, 144, 0.18), rgba(7, 10, 20, 0.64));
}

.compact-row {
  margin-bottom: 10px;
}

.compact-row h3 {
  margin: 0;
  font-size: 15px;
}

.compact-summary {
  gap: 8px 10px;
  font-size: 13px;
}

.compact-summary dt {
  color: var(--muted);
}

.compact-summary dd {
  line-height: 1.6;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.compact-status {
  margin: 0;
  font-size: 14px;
}

.session-module-title-row {
  margin-top: 4px;
  margin-bottom: 0;
}

.flow-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.flow-pill-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(170, 180, 214, 0.14);
  background: rgba(7, 10, 20, 0.5);
}

.flow-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.flow-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(64, 168, 112, 0.18);
  background: rgba(64, 168, 112, 0.12);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.flow-pill.active {
  background: linear-gradient(135deg, rgba(64, 168, 112, 0.26), rgba(88, 184, 88, 0.24));
  color: var(--text);
}

.agent-switches {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.agent-switches .flow-pill {
  cursor: pointer;
}

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

.intent-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
  border: 1px solid rgba(170, 180, 214, 0.14);
  background: rgba(7, 10, 20, 0.52);
}

.intent-card strong {
  font-size: 15px;
}

.intent-card span {
  color: var(--muted);
  line-height: 1.6;
  font-size: 13px;
}

.intent-card.active {
  border-color: rgba(64, 168, 112, 0.36);
  background: linear-gradient(135deg, rgba(64, 168, 112, 0.18), rgba(88, 184, 88, 0.16));
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-title-row h2 {
  margin: 0;
  font-size: 20px;
}

.transcript-title-row {
  margin-top: 18px;
  margin-bottom: 12px;
}

.transcript-title-row h3 {
  margin: 0;
  font-size: 18px;
}

.hint,
.message-box,
code {
  color: var(--muted);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status-badge.idle {
  background: rgba(64, 168, 112, 0.16);
  color: var(--accent);
}

.status-badge.loading {
  background: rgba(245, 158, 11, 0.16);
  color: var(--warning);
}

.status-badge.success {
  background: rgba(52, 211, 153, 0.16);
  color: var(--success);
}

.status-badge.error {
  background: rgba(251, 113, 133, 0.16);
  color: var(--danger);
}

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

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
}

input {
  border: 1px solid rgba(170, 180, 214, 0.22);
  background: rgba(8, 12, 24, 0.68);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 14px;
}

textarea {
  border: 1px solid rgba(170, 180, 214, 0.22);
  background: rgba(8, 12, 24, 0.68);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 14px;
  resize: vertical;
  min-height: 96px;
}

textarea:focus {
  outline: 2px solid rgba(64, 168, 112, 0.35);
  border-color: rgba(64, 168, 112, 0.42);
}

input:focus {
  outline: 2px solid rgba(64, 168, 112, 0.35);
  border-color: rgba(64, 168, 112, 0.42);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.chip-button {
  background: rgba(64, 168, 112, 0.12);
  color: var(--accent);
  border: 1px solid rgba(64, 168, 112, 0.22);
}

.chip-button:hover {
  background: rgba(64, 168, 112, 0.18);
}

.runtime-compose {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: end;
}

.composer-label {
  gap: 0;
}

.composer-hint {
  display: block;
  margin-top: 10px;
  font-size: 12px;
}

.runtime-button {
  min-width: 140px;
  min-height: 56px;
}

.handoff-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.handoff-hint {
  color: var(--muted);
  line-height: 1.6;
  flex: 1 1 320px;
}

.secondary-action {
  background: rgba(52, 211, 153, 0.14);
  color: var(--success);
  border: 1px solid rgba(52, 211, 153, 0.22);
}

.secondary-action:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.runtime-turn-meta {
  color: var(--muted);
  line-height: 1.6;
}

.chat-transcript {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
  padding: 4px 2px 2px;
}

.single-chat-panel {
  min-height: 360px;
  border-radius: 20px;
  padding: 16px;
  background: rgba(7, 10, 20, 0.58);
  border: 1px solid rgba(170, 180, 214, 0.1);
}

.chat-empty {
  border: 1px dashed rgba(170, 180, 214, 0.18);
  border-radius: 18px;
  padding: 20px;
  color: var(--muted);
  background: rgba(7, 10, 20, 0.42);
}

.chat-bubble {
  max-width: min(80%, 720px);
  border-radius: 22px;
  padding: 14px 16px;
  border: 1px solid rgba(170, 180, 214, 0.14);
  background: rgba(7, 10, 20, 0.82);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.chat-bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(64, 168, 112, 0.22), rgba(88, 184, 88, 0.2));
}

.chat-bubble.assistant {
  align-self: flex-start;
}

.chat-bubble.assistant.guide {
  border-color: rgba(52, 211, 153, 0.26);
  background: rgba(8, 18, 18, 0.72);
}

.chat-bubble.pending {
  opacity: 0.78;
  border-style: dashed;
}

.chat-bubble.pending .chat-bubble-meta {
  opacity: 0.92;
}

.chat-bubble-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chat-bubble-text {
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

button {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 700;
  background: rgba(170, 180, 214, 0.12);
  color: var(--text);
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  background: rgba(170, 180, 214, 0.2);
}

button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.message-box {
  margin: 0;
  line-height: 1.5;
}

.minimal-message {
  font-size: 13px;
}

body.user-mode .status-badge.idle,
body.user-mode .status-badge.success,
body.user-mode #runtimeTurnMeta[hidden],
body.user-mode #messageBox[hidden] {
  display: none !important;
}

body.user-mode .layout {
  grid-template-columns: 280px minmax(0, 1fr);
}

body.user-mode .controls-panel {
  grid-column: auto;
}

body.user-mode .transcript-panel {
  min-height: 420px;
}

.probe-box {
  margin-top: 16px;
  border-radius: 16px;
  padding: 14px 16px;
  border: 1px solid rgba(170, 180, 214, 0.14);
  background: rgba(7, 10, 20, 0.68);
  color: var(--muted);
  line-height: 1.6;
}

.probe-box.ok {
  border-color: rgba(52, 211, 153, 0.28);
  color: var(--success);
}

.probe-box.warn {
  border-color: rgba(245, 158, 11, 0.28);
  color: var(--warning);
}

.probe-box.error {
  border-color: rgba(251, 113, 133, 0.28);
  color: var(--danger);
}

.dev-details {
  margin-top: 4px;
}

.dev-details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 16px;
}

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

.dev-card {
  border: 1px solid rgba(170, 180, 214, 0.14);
  border-radius: 18px;
  padding: 16px;
  background: rgba(7, 10, 20, 0.5);
}

.dev-card-wide {
  grid-column: 1 / -1;
}

.json-preview {
  margin: 0;
  min-height: 260px;
  max-height: 520px;
  overflow: auto;
  border-radius: 18px;
  background: rgba(7, 10, 20, 0.82);
  border: 1px solid rgba(170, 180, 214, 0.12);
  padding: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.compact-preview {
  min-height: 160px;
  max-height: 360px;
}

.summary-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 10px 14px;
  margin: 0;
}

.summary-list dt {
  color: var(--muted);
}

.summary-list dd {
  margin: 0;
}

.ordered-list {
  margin: 16px 0 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.7;
}

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

.agent-card {
  border: 1px solid rgba(170, 180, 214, 0.14);
  border-radius: 18px;
  padding: 14px;
  background: rgba(7, 10, 20, 0.68);
}

.agent-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.agent-card h3 {
  margin: 0;
  font-size: 16px;
}

.agent-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 13px;
}

.agent-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.agent-tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(64, 168, 112, 0.14);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.agent-tag.ready {
  background: rgba(52, 211, 153, 0.14);
  color: var(--success);
}

.agent-tag.pending {
  background: rgba(245, 158, 11, 0.14);
  color: var(--warning);
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  body.user-mode .layout {
    grid-template-columns: 1fr;
  }

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

  .flow-strip,
  .intent-grid,
  .support-grid {
    grid-template-columns: 1fr;
  }

  .dev-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100% - 20px, 1000px);
    padding-top: 12px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-direction: column;
  }

  .hero-actions {
    flex-direction: column;
  }

  .runtime-compose {
    grid-template-columns: 1fr;
  }

  .journey-context-bar {
    align-items: flex-start;
  }

  .identity-bar {
    align-items: flex-start;
  }

  .handoff-row {
    flex-direction: column;
    align-items: stretch;
  }

  button {
    width: 100%;
  }

  .agent-grid {
    grid-template-columns: 1fr;
  }

  .chat-bubble {
    max-width: 100%;
  }
}