/* ── Design tokens ──────────────────────────────────────────────────────── */
:root {
  --accent:       #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #eef2ff;
  --accent-dim:   #a5b4fc;
  --accent-glow:  rgba(99, 102, 241, 0.15);
  --green:        #10b981;
  --green-hover:  #059669;
  --green-light:  #ecfdf5;
  --green-mid:    #6ee7b7;
  --red:          #ef4444;
  --red-hover:    #dc2626;
  --red-light:    #fef2f2;
  --amber:        #f59e0b;
  --amber-hover:  #d97706;
  --amber-light:  #fffbeb;
  --blue:         #3b82f6;
  --blue-light:   #eff6ff;
  --teal:         #14b8a6;
  --teal-light:   #f0fdfa;
  --bg:           #f8fafc;
  --bg-panel:     #ffffff;
  --bg-log:       #0c1222;
  --bg-subtle:    #f1f5f9;
  --bg-hover:     #f8fafc;
  --text:         #1e293b;
  --text-secondary: #475569;
  --text-muted:   #64748b;
  --text-faint:   #94a3b8;
  --border:       #e2e8f0;
  --border-light: #f1f5f9;
  --border-mid:   #cbd5e1;
  --shadow-xs:    0 1px 2px rgba(0,0,0,0.03);
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.03);
  --shadow:       0 4px 16px rgba(0,0,0,0.05), 0 1px 4px rgba(0,0,0,0.03);
  --shadow-md:    0 8px 24px rgba(0,0,0,0.06), 0 2px 8px rgba(0,0,0,0.04);
  --shadow-lg:    0 16px 48px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.04);
  --radius:       12px;
  --radius-sm:    8px;
  --radius-xs:    6px;
  --ease:         cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring:  cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Animations ────────────────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
@keyframes statusPulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50% { box-shadow: 0 0 0 6px transparent; }
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── 3-column grid ──────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 5fr) minmax(0, 2fr);
  gap: 0;
  min-height: 100vh;
  align-items: stretch;
}

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

/* ── Panel headers (shared) ────────────────────────────────────────────── */
.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.panel-header svg {
  color: var(--accent);
  flex-shrink: 0;
}
.panel-header h3 {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.section-header svg {
  color: var(--text-faint);
  flex-shrink: 0;
}
.section-header h4 {
  margin: 0;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

/* ── Left column – call controls ────────────────────────────────────────── */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 24px 16px;
}

.layout > .main-col.container {
  max-width: none;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.main-col {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-height: 100vh;
  overflow: hidden;
}

/* Title group */
.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: -6px;
  margin-bottom: 20px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.main-title-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.main-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.main-col h2 {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.025em;
}

.main-subtitle {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  line-height: 1;
}

.main-col > p {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

/* ── Call / HangUp buttons ──────────────────────────────────────────────── */
.actions {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

button {
  padding: 10px 20px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: none;
  transition: all 0.2s var(--ease);
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

.btn-call {
  background: linear-gradient(135deg, var(--green), var(--green-hover));
  color: #fff;
  box-shadow: 0 2px 8px rgba(16,185,129,0.25);
  padding: 11px 22px;
}
.btn-call:hover:not(:disabled) {
  box-shadow: 0 4px 16px rgba(16,185,129,0.35);
  transform: translateY(-1px);
}

.btn-hangup {
  background: linear-gradient(135deg, var(--red), var(--red-hover));
  color: #fff;
  box-shadow: 0 2px 8px rgba(239,68,68,0.2);
  padding: 11px 22px;
}
.btn-hangup:hover:not(:disabled) {
  box-shadow: 0 4px 16px rgba(239,68,68,0.3);
  transform: translateY(-1px);
}

/* ── Controls card ─────────────────────────────────────────────────────── */
.controls-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 18px;
}

.controls-card .flow-toggle-row:last-child {
  margin-bottom: 0;
}

/* ── Flow toggle ───────────────────────────────────────────────────────── */
.flow-toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 12px;
}

.flow-toggle-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  min-width: 38px;
}

.flow-toggle {
  display: inline-flex;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.flow-toggle-btn {
  padding: 6px 14px;
  font-size: 0.8125rem;
  font-weight: 600;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  line-height: 1;
}
.flow-toggle-btn:hover:not(.active) {
  background: var(--bg-subtle);
  color: var(--text);
}
.flow-toggle-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 4px rgba(99,102,241,0.3);
}

/* ── Client selector ───────────────────────────────────────────────────── */
.client-select {
  flex: 1;
  padding: 7px 12px;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: all 0.2s var(--ease);
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
.client-select:hover {
  border-color: var(--border-mid);
  background-color: var(--bg-hover);
}
.client-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Status badge ───────────────────────────────────────────────────────── */
#status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  padding: 7px 16px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all 0.3s var(--ease);
  width: fit-content;
}

#status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
  transition: all 0.3s var(--ease);
}

#status[data-status="ready"] {
  background: var(--blue-light);
  color: var(--blue);
  border-color: #bfdbfe;
}
#status[data-status="calling"] {
  background: var(--amber-light);
  color: var(--amber);
  border-color: #fde68a;
  animation: statusPulse 2s infinite;
}
#status[data-status="calling"]::before {
  animation: pulse 1.5s infinite;
}
#status[data-status="connected"] {
  background: var(--green-light);
  color: var(--green);
  border-color: var(--green-mid);
}
#status[data-status="connected"]::before {
  box-shadow: 0 0 0 3px rgba(16,185,129,0.2);
}
#status[data-status="disconnecting"] {
  background: #fff7ed;
  color: #ea580c;
  border-color: #fed7aa;
}
#status[data-status="error"] {
  background: var(--red-light);
  color: var(--red);
  border-color: #fecaca;
}

/* ── Log ────────────────────────────────────────────────────────────────── */
.log-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--text-faint);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.log-header-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}
.log-header-btn:hover { color: var(--text); background: var(--bg-subtle); }
.log-header-btn.active { color: var(--accent); }

#log {
  background: var(--bg-log);
  border: 1px solid rgba(30,41,59,0.8);
  border-radius: var(--radius);
  padding: 16px 18px;
  flex: 1;
  min-height: 0;
  max-height: calc(100vh - 420px);
  overflow-y: auto;
  font-family: "JetBrains Mono", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.7;
  color: #94a3b8;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

#log div {
  padding: 2px 0;
  border-bottom: 1px solid rgba(255,255,255,0.025);
  animation: fadeIn 0.15s var(--ease);
}

#log div[data-type="user"] { color: #60a5fa; }
#log div[data-type="user"] strong { color: #93c5fd; }

#log div[data-type="bot"] { color: #c084fc; }
#log div[data-type="bot"] strong { color: #d8b4fe; }

#log div[data-type="bot-template-hardcoded"] { color: #a78bfa; font-style: italic; font-size: 10.5px; }
#log div[data-type="bot-template-dynamic"]  { color: #e879f9; font-style: italic; font-size: 10.5px; }

#log div[data-type="partial"] { color: #475569; font-style: italic; }

#log div[data-type="intents"] { color: #fbbf24; }

#log div[data-type="orchestrator"] { color: #2dd4bf; }

#log div[data-type="error"] { color: #f87171; }

#log div[data-type="info"] { color: #94a3b8; }

/* ── Orchestrator panel ─────────────────────────────────────────────────── */
.orch-panel {
  background: var(--bg-panel);
  padding: 24px 18px 40px;
  border-left: 1px solid var(--border);
  overflow-y: auto;
  max-height: 100vh;
  position: sticky;
  top: 0;
  min-width: 0;
}

.orch-panel h4 {
  margin: 0;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.orch-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0 0 12px;
  line-height: 1.5;
}

.orch-hint.small { margin-bottom: 8px; }

.orch-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.orch-row {
  display: flex;
  gap: 6px;
  margin-bottom: 0;
}

.orch-row-toolbar {
  flex-wrap: wrap;
  align-items: center;
}

.orch-row-toolbar button {
  padding: 7px 12px;
  font-size: 0.75rem;
  white-space: nowrap;
  border-radius: var(--radius-xs);
  font-weight: 600;
}

.btn-icon-text {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border-mid);
  background: var(--bg-panel);
  color: var(--text-muted);
}
.btn-icon-text:hover {
  background: var(--accent-light);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.orch-btn-restart {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--amber-light);
  border: 1px solid #fbbf24;
  color: #92400e;
}
.orch-btn-restart:hover {
  background: #fef3c7;
  border-color: var(--amber);
}

.orch-row input {
  flex: 1;
  min-width: 0;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-family: inherit;
  font-size: 0.8125rem;
  background: var(--bg-panel);
  color: var(--text);
  outline: none;
  transition: all 0.2s var(--ease);
}
.orch-row input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* State + Flow summary */
.orch-summary {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.orch-summary-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 0.8125rem;
}

.orch-summary .label {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  min-width: 38px;
  flex-shrink: 0;
}

.orch-state-badge {
  font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  padding: 4px 12px;
  border-radius: 6px;
  transition: all 0.3s var(--ease);
}

.orch-summary #orchType {
  font-size: 0.8125rem;
  color: var(--text);
  font-weight: 500;
}

.orch-section {
  margin-bottom: 20px;
  animation: fadeIn 0.2s var(--ease);
}

/* Capabilities list */
.orch-caps {
  margin: 0;
  padding-left: 1rem;
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--text-muted);
}
.orch-caps li {
  margin-bottom: 4px;
  transition: color 0.15s var(--ease);
}
.orch-caps li:hover {
  color: var(--text);
}

/* History */
.orch-history {
  font-size: 0.6875rem;
  font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  color: var(--text-muted);
  max-height: 130px;
  overflow-y: auto;
  scrollbar-width: thin;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.orch-hist-line {
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--radius-xs);
  transition: background 0.15s var(--ease);
  animation: slideIn 0.2s var(--ease);
}
.orch-hist-line:hover {
  background: var(--bg-panel);
}

.orch-hist-line::before {
  content: "→";
  color: var(--accent-dim);
  flex-shrink: 0;
  font-weight: 600;
}

/* Manual current state */
.orch-manual-current {
  margin: 0 0 10px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  background: var(--bg-subtle);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}

/* Transition option buttons */
.orch-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.orch-opt-btn {
  text-align: left;
  font-family: inherit;
  font-size: 0.75rem;
  padding: 10px 14px;
  line-height: 1.45;
  white-space: pre-line;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  cursor: pointer;
  color: var(--text);
  transition: all 0.2s var(--ease);
}
.orch-opt-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent-dim);
  color: var(--accent);
  transform: translateX(3px);
}

.orch-no-opts {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: 0;
  padding: 10px 0;
  text-align: center;
}

/* ── Memory panel ────────────────────────────────────────────────────────── */
.mem-panel {
  border-top: 1px solid var(--border);
  padding-top: 18px;
  margin-top: 4px;
}
.mem-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px;
}
.mem-refresh {
  padding: 5px 12px;
  font-size: 0.6875rem;
  font-weight: 600;
  border: 1px solid var(--border-mid);
  background: var(--bg-panel);
  color: var(--text-muted);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all 0.2s var(--ease);
}
.mem-refresh:hover {
  background: var(--accent-light);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.mem-stats {
  display: flex;
  gap: 8px;
  margin: 0 0 16px;
  flex-wrap: wrap;
}
.mem-stat {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  color: var(--text);
  transition: all 0.2s var(--ease);
}
.mem-stat:hover {
  border-color: var(--accent-dim);
}
.mem-stat .label {
  font-size: 0.5625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.mem-section { margin-bottom: 16px; }
.mem-section-title {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 8px;
}

.mem-summary {
  background: var(--bg-subtle);
  border-left: 3px solid var(--accent);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  line-height: 1.55;
  color: var(--text-secondary);
  font-style: italic;
  min-height: 36px;
}

.mem-facts {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.mem-empty {
  list-style: none;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 12px 0;
  text-align: center;
}
.mem-fact {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.75rem;
  line-height: 1.45;
  transition: all 0.2s var(--ease);
  animation: fadeIn 0.2s var(--ease);
}
.mem-fact:hover {
  border-color: var(--accent-dim);
  transform: translateX(2px);
}
.mem-fact.imp-critical { border-left-color: var(--red); }
.mem-fact.imp-high     { border-left-color: var(--amber); }
.mem-fact.imp-medium   { border-left-color: var(--accent); }
.mem-fact.imp-low      { border-left-color: var(--border-mid); }

.mem-fact-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.mem-fact-cat {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}
.mem-fact-imp {
  font-size: 0.5625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-faint);
  background: var(--bg-subtle);
}
.mem-fact.imp-critical .mem-fact-imp { color: var(--red); background: var(--red-light); }
.mem-fact.imp-high     .mem-fact-imp { color: var(--amber); background: var(--amber-light); }
.mem-fact-label {
  font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.6875rem;
  color: var(--text-muted);
}
.mem-fact-value {
  font-weight: 600;
  color: var(--text);
  margin-top: 3px;
}
.mem-fact-meta {
  font-size: 0.625rem;
  color: var(--text-faint);
  margin-top: 4px;
}

.mem-turns {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 140px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.mem-turn {
  font-size: 0.75rem;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  line-height: 1.45;
  box-shadow: var(--shadow-xs);
  transition: all 0.15s var(--ease);
  animation: fadeIn 0.15s var(--ease);
}
.mem-turn:hover {
  box-shadow: var(--shadow-sm);
}
.mem-turn-role {
  font-weight: 700;
  font-size: 0.5625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-right: 5px;
}
.mem-turn-user      { border-left: 3px solid #60a5fa; }
.mem-turn-assistant { border-left: 3px solid #c084fc; }

/* ── Flowchart panel ─────────────────────────────────────────────────────── */
.flowchart-panel {
  background: var(--bg-panel);
  padding: 24px 20px 8px;
  overflow-x: auto;
  overflow-y: auto;
  max-height: 100vh;
  position: sticky;
  top: 0;
  min-width: 0;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.flowchart-panel > * {
  min-width: fit-content;
}
.flowchart-panel > .panel-header {
  position: sticky;
  left: 0;
  min-width: 100%;
}

.flowchart-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  margin-bottom: 12px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s var(--ease);
}
.flowchart-back-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.flowchart-back-btn[hidden] { display: none; }

.flowchart-panel svg g.node[style*="cursor"] rect.basic {
  transition: filter 0.15s ease, stroke-width 0.15s ease;
}
.flowchart-panel svg g.node[style*="cursor"]:hover rect.basic {
  filter: brightness(0.92);
  stroke-width: 2.5;
}

.flowchart-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0 0 16px;
  line-height: 1.5;
  padding: 8px 12px;
  background: var(--bg-subtle);
  border-radius: var(--radius-xs);
  border-left: 3px solid var(--accent-dim);
}

.flowchart-pane[hidden] { display: none !important; }
.flowchart-pane.centered-diagram {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: calc(100vh - 120px);
}
.flowchart-pane.centered-diagram .flowchart-back-btn {
  align-self: flex-start;
}
.flowchart-pane.centered-diagram svg {
  margin: auto;
}

/* Diagram sizing */
.mermaid-wrap { min-height: 100px; }

.mermaid-wrap pre.mermaid {
  margin: 0;
  background: transparent;
  border: none;
  font-size: 18px;
  line-height: 1.25;
  white-space: pre;
}

.mermaid-wrap svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* ── Live Logs floating panel ────────────────────────────────────────────── */
.live-logs-float {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 600px;
  height: 400px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(15, 23, 42, 0.18);
  display: flex;
  flex-direction: column;
  z-index: 900;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  resize: both;
  overflow: hidden;
  min-width: 360px;
  min-height: 200px;
}
.live-logs-float[hidden] { display: none; }
.live-logs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  cursor: grab;
  font-family: "Inter", sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  user-select: none;
  flex-shrink: 0;
}
.live-logs-controls { display: flex; gap: 4px; }
.live-logs-ctrl-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}
.live-logs-ctrl-btn:hover { color: var(--text); background: var(--bg-panel); }
.live-logs-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 8px 10px;
}
.ll-line {
  white-space: pre;
  line-height: 1.5;
  color: var(--text-muted);
}
.ll-error { color: var(--red); }
.ll-warn  { color: #d97706; }
.ll-debug { color: var(--accent-dim); }

/* ── Config gear button ────────────────────────────────────────────────── */
.config-gear-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  padding: 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.3s var(--ease);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.config-gear-btn:hover {
  background: var(--accent-light);
  color: var(--accent);
  transform: rotate(45deg);
}
a.config-gear-btn { text-decoration: none; }
a.config-gear-btn:hover { transform: none; color: var(--red); background: var(--red-light); }

.orch-logout-btn { margin-left: auto; padding: 0; }

/* ── Config modal overlay ──────────────────────────────────────────────── */
.config-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s var(--ease);
}
.config-modal-overlay[hidden] { display: none; }

.config-modal {
  background: var(--bg-panel);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  width: 900px;
  max-width: 94vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  animation: fadeIn 0.25s var(--ease-spring);
}

.config-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 28px 20px;
  border-bottom: 1px solid var(--border);
}
.config-modal-header h3 {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.config-modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.config-close-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-faint);
  cursor: pointer;
  padding: 6px 10px;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: all 0.2s var(--ease);
}
.config-close-btn:hover {
  background: var(--red-light);
  color: var(--red);
  transform: scale(1.1);
}

.config-reset-all {
  padding: 8px 18px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border-mid);
  background: var(--bg-panel);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s var(--ease);
}
.config-reset-all:hover {
  background: var(--amber-light);
  border-color: var(--amber);
  color: #92400e;
}

.config-badge {
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 9999px;
  background: var(--accent-light);
  color: var(--accent);
}

/* ── Config modal body ─────────────────────────────────────────────────── */
.config-modal-body {
  padding: 0 28px 28px;
  overflow-y: auto;
  flex: 1;
}

/* Category sections */
.config-category {
  margin-bottom: 16px;
  background: var(--bg-subtle);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 18px 20px;
  transition: all 0.2s var(--ease);
}
.config-category:last-child { margin-bottom: 0; }
.config-category:hover {
  border-color: var(--border-mid);
}

.config-category-header {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: color 0.15s var(--ease);
}
.config-category-header:hover {
  color: var(--text-muted);
}
.config-category-header::before {
  content: "▾ ";
  font-size: 0.6875rem;
}
.config-category-collapsed .config-category-header::before {
  content: "▸ ";
}
.config-category-collapsed .config-row {
  display: none;
}

/* Parameter rows */
.config-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  transition: all 0.15s var(--ease);
  margin-bottom: 2px;
}
.config-row:hover { background: var(--bg-panel); box-shadow: var(--shadow-xs); }

.config-row.config-modified {
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
}
.config-row.config-modified:hover {
  background: #e0e7ff;
}

.config-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  cursor: default;
  white-space: nowrap;
}
.config-modified .config-label {
  font-weight: 700;
  color: var(--accent);
}

.config-description {
  display: block;
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  line-height: 1.5;
  grid-column: 1 / -1;
}

.config-default {
  font-size: 0.6875rem;
  color: var(--text-faint);
  white-space: nowrap;
}

/* Input styles */
.config-input.config-select,
.config-input.config-number,
.config-input.config-text {
  padding: 8px 12px;
  font-size: 0.8125rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  color: var(--text);
  outline: none;
  transition: all 0.2s var(--ease);
  min-width: 0;
  max-width: 200px;
}
.config-input.config-select:focus,
.config-input.config-number:focus,
.config-input.config-text:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: #fff;
}

.config-input.config-number { width: 100px; }

.config-input.config-toggle {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Per-row reset button */
.config-row-reset {
  background: none;
  border: none;
  font-size: 0.8125rem;
  color: var(--text-faint);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s var(--ease);
  line-height: 1;
  opacity: 0;
}
.config-row:hover .config-row-reset { opacity: 1; }
.config-row-reset:hover {
  background: var(--amber-light);
  color: var(--amber);
  opacity: 1;
}
.config-row-reset[hidden] { display: none; }

.config-prompt-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.config-barge-inline {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.config-barge-inline:hover { color: var(--text); }
.config-barge-text { user-select: none; }

/* Tab bar */
.config-tab-bar {
  display: flex;
  gap: 4px;
  padding: 20px 0 16px;
  margin-bottom: 4px;
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  z-index: 1;
}
.config-tab {
  padding: 9px 20px;
  border: none;
  background: var(--bg-subtle);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s var(--ease);
}
.config-tab:hover {
  color: var(--text);
  background: var(--border);
}
.config-tab-active {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(99,102,241,0.3);
}
.config-tab-active:hover {
  background: var(--accent-hover);
  color: #fff;
}

/* Textarea for prompts */
.config-input.config-textarea {
  width: 100%;
  max-width: 100%;
  min-height: 3rem;
  padding: 10px 14px;
  font-size: 0.8125rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  color: var(--text);
  outline: none;
  resize: vertical;
  transition: all 0.2s var(--ease);
  line-height: 1.6;
  grid-column: 1 / -1;
}
.config-input.config-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: #fff;
}

/* TTS preview button */
.config-play-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--accent);
  cursor: pointer;
  padding: 7px 14px;
  transition: all 0.2s var(--ease);
  line-height: 1;
  align-self: flex-start;
  white-space: nowrap;
}
.config-play-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.config-play-btn:disabled {
  opacity: 0.4;
  cursor: wait;
  transform: none;
}

/* Phoneme editor */
.phoneme-table {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.phoneme-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  transition: all 0.15s var(--ease);
}
.phoneme-row:hover {
  background: var(--bg-panel);
  box-shadow: var(--shadow-xs);
}
.phoneme-word {
  font-weight: 600;
  font-size: 0.8125rem;
  min-width: 120px;
  color: var(--text);
}
.phoneme-arrow {
  color: var(--text-faint);
  font-size: 0.75rem;
}
.phoneme-ipa {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.8125rem;
  color: var(--accent);
  flex: 1;
  background: var(--accent-light);
  padding: 4px 10px;
  border-radius: 6px;
}
.phoneme-delete-btn {
  background: none;
  border: none;
  font-size: 0.75rem;
  color: var(--text-faint);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s var(--ease);
  opacity: 0;
}
.phoneme-row:hover .phoneme-delete-btn { opacity: 1; }
.phoneme-delete-btn:hover {
  background: var(--red-light);
  color: var(--red);
}
.phoneme-add-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 14px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  border: 1.5px dashed var(--border);
  transition: all 0.2s var(--ease);
}
.phoneme-add-row:hover {
  border-color: var(--accent-dim);
}
.phoneme-add-btn {
  padding: 8px 18px;
  font-size: 0.8125rem;
  font-weight: 600;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.2s var(--ease);
}
.phoneme-add-btn:hover {
  background: var(--accent);
  color: #fff;
}
.phoneme-reset-btn {
  display: block;
  margin-top: 14px;
  padding: 8px 18px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s var(--ease);
}
.phoneme-reset-btn:hover {
  background: var(--amber-light);
  border-color: var(--amber);
  color: #92400e;
}

/* ── Scrollbar styling ─────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-mid);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
}

/* ── Floating client profile card ──────────────────────────────────────── */
.profile-float {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 340px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(15, 23, 42, 0.12), 0 2px 8px rgba(15, 23, 42, 0.06);
  z-index: 900;
  animation: fadeIn 0.2s var(--ease);
  overflow: hidden;
}
.profile-float[hidden] { display: none; }

.profile-float-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  cursor: grab;
  user-select: none;
}
.profile-float-title {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-float-close {
  background: none;
  border: none;
  font-size: 1.125rem;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  border-radius: 4px;
  transition: all 0.15s var(--ease);
}
.profile-float-close:hover {
  background: var(--red-light);
  color: var(--red);
}

.profile-float-body {
  padding: 12px 14px;
  font-size: 0.75rem;
  max-height: 460px;
  overflow-y: auto;
}

.pf-loading, .pf-error {
  text-align: center;
  color: var(--text-muted);
  margin: 0;
  padding: 20px 0;
}
.pf-error { color: var(--red); }

.pf-ids {
  font-size: 0.6875rem;
  color: var(--text-muted);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  margin-bottom: 8px;
}

.pf-debt {
  background: var(--red-light);
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: baseline;
}
.pf-debt-amt {
  font-weight: 700;
  color: var(--red-hover);
  font-size: 0.8125rem;
}
.pf-debt-info {
  font-size: 0.6875rem;
  color: #991b1b;
}

.pf-grid {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 3px 8px;
  margin-bottom: 10px;
  font-size: 0.75rem;
}
.pf-lbl {
  color: var(--text-faint);
  font-weight: 600;
  font-size: 0.6875rem;
}

.pf-accts-title {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 4px;
}
.pf-acct {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.6875rem;
  border-bottom: 1px solid var(--border-light, #f1f5f9);
}
.pf-acct code {
  font-size: 0.625rem;
  background: var(--bg-subtle);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text-muted);
}
.pf-acct strong {
  margin-left: auto;
  color: var(--text);
}

#clientProfileBtn.active {
  background: var(--accent-light);
  border-color: var(--accent-dim);
  color: var(--accent);
}

#log::-webkit-scrollbar-thumb {
  background: #334155;
}
#log::-webkit-scrollbar-thumb:hover {
  background: #475569;
}
