:root {
  color-scheme: dark;
  --bg: #111315;
  --panel: #1b1f23;
  --panel-2: #20262b;
  --line: #343b43;
  --text: #eef2f5;
  --muted: #a7b0b8;
  --blue: #6eb7ff;
  --green: #63d991;
  --amber: #e2bd64;
  --red: #ff7b7b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  cursor: pointer;
}

button.primary {
  background: #1d5f42;
  border-color: #2b8a60;
}

button.warn {
  background: #5d4320;
  border-color: #9b6b28;
}

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

textarea, select, input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #121619;
  color: var(--text);
  padding: 0.65rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  background: #171a1d;
}

.topbar h1, h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.topbar-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 170px));
  gap: 0.5rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(380px, 1fr) minmax(280px, 360px);
  gap: 1rem;
  padding: 1rem;
  min-height: calc(100vh - 62px);
}

.composer, .transcript-panel, .side-panel section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.composer, .transcript-panel {
  padding: 1rem;
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.side-panel section {
  padding: 0.85rem;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.status, .badge, .pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.agent-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem;
}

.agent-option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.55rem;
  background: #15191d;
}

.agent-option input {
  width: auto;
  margin-top: 0.2rem;
}

.agent-option strong {
  display: block;
  font-size: 0.9rem;
}

.agent-option span, .item-detail {
  color: var(--muted);
  font-size: 0.82rem;
}

.transcript-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.transcript {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 360px;
  max-height: calc(100vh - 270px);
  overflow: auto;
  padding-right: 0.25rem;
}

.live-agent-status {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.6rem;
  min-height: 42px;
  margin-bottom: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #12171b;
  padding: 0.55rem 0.7rem;
  color: var(--muted);
}

.live-agent-status.working {
  border-color: #315979;
}

.live-agent-status.error {
  border-color: #7a3737;
}

.live-agent-status.done {
  border-color: #35704d;
}

.live-dots {
  display: inline-flex;
  gap: 0.2rem;
}

.live-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--blue);
  animation: livePulse 1.2s infinite ease-in-out;
}

.live-dots span:nth-child(2) { animation-delay: 0.15s; }
.live-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes livePulse {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

#activityText {
  overflow-wrap: anywhere;
}

#activityDetail {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.turn {
  border-left: 3px solid var(--blue);
  background: #151a1e;
  border-radius: 6px;
  padding: 0.75rem;
}

.turn.user { border-left-color: var(--green); }
.turn.facilitator { border-left-color: var(--amber); }
.turn.failed { border-left-color: var(--red); }

.turn-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.45rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.turn-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.log-panel {
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
}

.log-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.65rem 0;
}

.log-tab.active {
  border-color: var(--blue);
}

.log-pane {
  display: none;
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.65rem;
  background: #111518;
}

.log-pane.active { display: block; }

.log-entry {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-bottom: 1px solid #252b31;
  padding: 0.4rem 0;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.item, .session-btn {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #15191d;
  padding: 0.65rem;
}

.session-btn, .artifact-btn {
  text-align: left;
}

.artifact-btn {
  width: 100%;
}

.artifact-btn:hover {
  border-color: var(--blue);
}

.item-title {
  font-weight: 650;
  overflow-wrap: anywhere;
}

.item-hint {
  color: var(--blue);
  font-size: 0.78rem;
  margin-top: 0.35rem;
}

.item-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.55rem;
}

.artifact-preview {
  margin-top: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #111518;
  padding: 0.65rem;
}

.artifact-preview-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: start;
  margin-bottom: 0.65rem;
}

.artifact-preview-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.4rem;
}

.button-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  padding: 0.45rem 0.65rem;
  text-decoration: none;
  font-size: 0.88rem;
}

#artifactBody {
  max-height: 52vh;
  margin: 0;
  overflow: auto;
  border: 1px solid #252b31;
  border-radius: 6px;
  background: #0d1013;
  color: var(--text);
  padding: 0.65rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.45;
}

.empty {
  color: var(--muted);
  font-size: 0.86rem;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(360px, calc(100vw - 2rem));
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
}

.login-error {
  color: var(--red);
  margin: 0;
}

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

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

  .topbar-controls {
    grid-template-columns: 1fr;
  }

  .transcript {
    max-height: none;
  }
}
