:root {
  --ink: #101412;
  --panel: #171c19;
  --panel-2: #1f2622;
  --line: rgba(232, 240, 230, 0.1);
  --text: #e8f0e6;
  --muted: #9aa89c;
  --accent: #d4f06a;
  --accent-ink: #13200a;
  --stage: #f3efe6;
  --stage-ink: #1a1f1b;
  --ai: #dfe8dc;
  --me: #fff8e8;
  --danger: #e26d5a;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --radius: 22px;
  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--ink);
}

body {
  min-height: 100vh;
  overflow-x: hidden;
}

.bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 50% at 12% 18%, rgba(212, 240, 106, 0.14), transparent 55%),
    radial-gradient(ellipse 55% 45% at 88% 12%, rgba(98, 168, 140, 0.18), transparent 50%),
    radial-gradient(ellipse 60% 50% at 70% 90%, rgba(60, 90, 70, 0.35), transparent 55%),
    linear-gradient(160deg, #0c100e 0%, #151a17 45%, #0f1311 100%);
  z-index: -2;
}

.noise {
  position: fixed;
  inset: 0;
  opacity: 0.07;
  pointer-events: none;
  z-index: -1;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

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

.top {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(212, 240, 106, 0.12);
  animation: pulse 2.4s ease-in-out infinite;
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 3vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}

.status {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: right;
  max-width: 420px;
}

.workspace {
  /* базы | основной диалог (шире) | логи справа (уже диалога, но крупные) */
  display: grid;
  grid-template-columns: 200px minmax(480px, 1.5fr) minmax(400px, 1fr);
  gap: 16px;
  height: min(86vh, 920px);
  min-height: 640px;
  align-items: stretch;
}

.bases-panel,
.stage {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.bases-panel {
  background: linear-gradient(180deg, var(--panel) 0%, #121714 100%);
  border: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow: hidden;
}

.bases-panel h2 {
  margin: 0 4px 4px;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.bases-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  min-height: 0;
  flex: 1;
}

.base-card {
  appearance: none;
  border: 1px solid transparent;
  background: var(--panel-2);
  color: var(--text);
  border-radius: 16px;
  padding: 14px 14px 12px;
  text-align: left;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.base-card:hover {
  transform: translateY(-1px);
  border-color: rgba(212, 240, 106, 0.28);
}

.base-card.active {
  border-color: rgba(212, 240, 106, 0.55);
  background: linear-gradient(160deg, #243028 0%, #1a221d 100%);
}

.base-card .name {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
}

.base-card .desc {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
  margin-bottom: 10px;
}

.base-card .progress {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: #c5d4c3;
}

.progress-bar {
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.progress-bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.3s ease;
}

.stage {
  background: var(--stage);
  color: var(--stage-ink);
  border: 1px solid rgba(255, 255, 255, 0.35);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.logs-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  /* visual marker so cache miss is obvious */
  outline: 2px solid rgba(212, 240, 106, 0.35);
  outline-offset: 2px;
  border-radius: 20px;
  padding: 2px;
}

.stage-log-panel {
  background: linear-gradient(180deg, #f7f4ee 0%, #efeae1 100%);
  border: 1px solid rgba(26, 31, 27, 0.1);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px 14px 12px;
  min-height: 0;
  /* три окна одинаковой высоты, один под другим */
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

.flow-log-panel,
.speech-log-panel {
  flex: 1 1 0;
}

.stage-log-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.stage-log-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.92rem;
  letter-spacing: -0.02em;
}

.stage-log-hint {
  font-size: 0.72rem;
  color: #6d766e;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stage-log {
  overflow-x: hidden;
  overflow-y: auto;
  font-family: "IBM Plex Mono", "Consolas", monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  color: #2c342e;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 0;
  flex: 1;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.stage-log-line {
  display: grid;
  grid-template-columns: 56px minmax(44px, 64px) 1fr auto;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.62);
}

.stage-log-line .tag {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stage-log-line[data-stage="stt"] .tag { color: #2a6f97; }
.stage-log-line[data-stage="llm"] .tag { color: #3d5a12; }
.stage-log-line[data-stage="tts"] .tag { color: #8a5a12; }
.stage-log-line[data-stage="control"] .tag { color: #5a3d8a; }
.stage-log-line[data-stage="e2e"] .tag { color: #8a2f22; }
.stage-log-line[data-stage="router"] .tag { color: #1f6f5a; }
.stage-log-line[data-stage="turn"] .tag,
.stage-log-line[data-stage="other"] .tag { color: #5a635b; }
.stage-log-line[data-stage="speech"] .tag { color: #6b4f1d; }
.stage-log-line[data-stage="flow"] .tag { color: #5a3d8a; }
.stage-log-line[data-stage="tool"] .tag { color: #1f6f5a; }
.stage-log-line[data-kind="node"] {
  background: rgba(90, 61, 138, 0.1);
}
.stage-log-line[data-kind="tool_start"] {
  background: rgba(31, 111, 90, 0.12);
}
.stage-log-line[data-kind="tool_end"] {
  background: rgba(61, 90, 18, 0.12);
}

.stage-log-line[data-kind="false_barge_in"] {
  background: rgba(226, 109, 90, 0.12);
}
.stage-log-line[data-kind="real_barge_in"] {
  background: rgba(61, 90, 18, 0.14);
}
.stage-log-line[data-kind="garbage"] {
  background: rgba(107, 118, 110, 0.12);
}
.stage-log-line[data-kind="normal"] {
  background: rgba(42, 111, 151, 0.1);
}

.node-now {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: #5a635b;
  font-weight: 500;
}

.stage-log-line .metric {
  color: #6d766e;
}

.stage-log-line .detail {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #4d564f;
}

.stage-log-line .ms {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--stage-ink);
}

.stage-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  padding: 20px 22px 12px;
  border-bottom: 1px solid rgba(26, 31, 27, 0.08);
  flex-shrink: 0;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #6d766e;
}

.stage-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.head-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.latency-board {
  display: flex;
  gap: 8px;
}

.latency-item {
  min-width: 88px;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(26, 31, 27, 0.06);
  text-align: right;
}

.latency-label {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #6d766e;
}

.latency-value {
  display: block;
  margin-top: 2px;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--stage-ink);
  font-variant-numeric: tabular-nums;
}

.latency-value.fresh {
  color: #3d5a12;
}

.live-pill {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(26, 31, 27, 0.08);
  color: #4d564f;
}

.msg-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.latency-badge {
  align-self: flex-start;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(61, 90, 18, 0.12);
  color: #3d5a12;
  font-variant-numeric: tabular-nums;
}

.msg.me .latency-badge {
  align-self: flex-end;
}

.live-pill[data-state="connecting"],
.live-pill[data-state="running"] {
  background: rgba(212, 240, 106, 0.35);
  color: #2c3b12;
}

.live-pill[data-state="failed"] {
  background: rgba(226, 109, 90, 0.2);
  color: #8a2f22;
}

.transcript {
  padding: 18px 22px;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overscroll-behavior: contain;
}

.empty {
  margin: auto;
  text-align: center;
  color: #7a847b;
  max-width: 280px;
  line-height: 1.45;
}

.msg {
  display: flex;
  gap: 10px;
  max-width: min(86%, 520px);
  animation: rise 0.28s ease;
}

.msg.ai {
  align-self: flex-start;
}

.msg.me {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 600;
  flex-shrink: 0;
}

.msg.ai .avatar {
  background: #2b3830;
  color: #e7f0e4;
}

.msg.me .avatar {
  background: #c9a24d;
  color: #1a160c;
}

.bubble {
  border-radius: 16px;
  padding: 11px 14px;
  line-height: 1.45;
  font-size: 0.95rem;
  width: fit-content;
  max-width: 100%;
}

.msg.ai .bubble {
  background: var(--ai);
}

.msg.me .bubble {
  background: var(--me);
}

.bubble.interim {
  opacity: 0.7;
}

.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  padding: 18px 22px 24px;
  border-top: 1px solid rgba(26, 31, 27, 0.08);
  flex-shrink: 0;
}

.start-btn,
.stop-btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 700;
  transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

.start-btn {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e9f99a, var(--accent) 55%, #a8c83a);
  color: var(--accent-ink);
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  box-shadow:
    0 10px 28px rgba(160, 190, 60, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.start-btn:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.02);
}

.start-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.stop-btn {
  min-width: 88px;
  height: 44px;
  border-radius: 999px;
  padding: 0 18px;
  background: rgba(26, 31, 27, 0.08);
  color: var(--stage-ink);
  font-size: 0.95rem;
}

.stop-btn:hover:not(:disabled) {
  background: rgba(226, 109, 90, 0.16);
  color: #8a2f22;
}

.stop-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 6px rgba(212, 240, 106, 0.12);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(212, 240, 106, 0.05);
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1200px) {
  .workspace {
    grid-template-columns: 200px minmax(360px, 1.3fr) minmax(320px, 0.85fr);
  }
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .logs-column {
    height: min(72vh, 720px);
  }

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

  .status {
    text-align: left;
  }

  .stage {
    min-height: 480px;
    height: min(70vh, 640px);
  }
}

