/* ── Theme palette (consumed by Tailwind config via rgb(var(--x))) ──────────── */
/* Values are space-separated RGB channels so Tailwind opacity modifiers work. */
:root {
  /* Dark theme (default) */
  --surface-50: 248 250 252;
  --surface-100: 241 245 249;
  --surface-200: 226 232 240;
  --surface-600: 71 85 105;
  --surface-700: 51 65 85;
  --surface-800: 30 41 59;
  --surface-900: 15 23 42;

  --accent-400: 96 165 250;
  --accent-500: 59 130 246;
  --accent-600: 37 99 235;

  /* Lifted vs stock Tailwind so muted labels stay readable on slate surfaces.
     gray-400/500/600 were ~3:1 on surface-800 — well under WCAG AA. */
  --gray-100: 248 250 252;
  --gray-200: 241 245 249;
  --gray-300: 226 232 240;
  --gray-400: 203 213 225;
  --gray-500: 163 177 194;
  --gray-600: 132 146 164;
  --gray-700: 71 85 105;
  --gray-800: 51 65 85;
  --gray-900: 30 41 59;
}

html.light {
  /* Light theme: surfaces become light, text grays become dark */
  --surface-900: 255 255 255;
  --surface-800: 241 245 249;
  --surface-700: 226 232 240;
  --surface-600: 203 213 225;
  --surface-200: 30 41 59;
  --surface-100: 15 23 42;
  --surface-50: 2 6 23;

  --gray-100: 17 24 39;
  --gray-200: 31 41 55;
  --gray-300: 55 65 81;
  --gray-400: 71 85 105;
  --gray-500: 100 116 139;
  --gray-600: 148 163 184;
  --gray-700: 203 213 225;
  --gray-800: 226 232 240;
  --gray-900: 241 245 249;
}

* {
  box-sizing: border-box;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

select,
input[type="number"],
input[type="text"],
input[type="password"],
textarea {
  color-scheme: dark;
}

.sc-filter-btn {
  color: #cbd5e1;
  background: transparent;
}
.sc-filter-btn:hover {
  color: #fff;
  background: #1e293b;
}
.sc-filter-btn.active {
  color: #fff;
  background: #334155;
  border-color: #64748b;
}
.js-open-session,
.js-copy-session {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
}
.js-open-session:hover,
.js-copy-session:hover {
  color: #fff;
  text-decoration: underline;
}

/* Tab buttons */
.tab-btn {
  color: #cbd5e1;
  background: transparent;
}
.tab-btn:hover {
  color: #f8fafc;
  background: #1e293b;
}
.tab-btn.active {
  color: #fff;
  background: #334155;
}

/* KB card hover */
.kb-card {
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.kb-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* Conversation card entrance animation */
.conv-enter {
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Conversation card hover lift */
.conv-card {
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.conv-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* Settings tooltips */
.setting-label {
  position: relative;
  cursor: help;
}
.setting-tip {
  display: none;
  position: absolute;
  left: 0;
  bottom: calc(100% + 6px);
  width: 260px;
  padding: 8px 10px;
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 8px;
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.5;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
.setting-label:hover .setting-tip {
  display: block;
}

/* Toggle switch refinement */
.peer:checked ~ div {
  background-color: #2563eb;
}

/* Modal backdrop transition */
#conv-modal {
  transition: opacity 0.2s ease;
}

/* Pulse for live badge */
@keyframes livePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@keyframes spin {
  from { display: inline-block; transform: rotate(0deg); }
  to   { display: inline-block; transform: rotate(360deg); }
}

#connection-badge {
  animation: livePulse 2s ease-in-out infinite;
}

/* Toast animation */
#settings-toast {
  animation: fadeInUp 0.25s ease-out;
}

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

/* Pipeline toggle buttons */
.pipeline-toggle {
  cursor: pointer;
  user-select: none;
}
.pipeline-toggle:hover {
  color: #94a3b8;
}

/* Turn blocks with timeline connector */
.turn-block {
  border-left: 2px solid #334155;
  padding-left: 16px;
  margin-left: 4px;
  padding-bottom: 8px;
  position: relative;
}
.turn-block:last-child {
  border-left-color: transparent;
}
.turn-block::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #475569;
  border: 2px solid #0f172a;
}
.turn-block-focus {
  border-left-color: #3b82f6;
}
.turn-block-focus::before {
  background: #3b82f6;
}

.turn-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.turn-pipeline {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Pipeline step rows */
.pipeline-step {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  line-height: 1.5;
  min-height: 24px;
}
.pipeline-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  width: 52px;
  flex-shrink: 0;
  text-align: right;
}
.pipeline-content {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Live traffic feed ───────────────────────────────────────────────────── */
.traffic-pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
  animation: trafficPulse 1.6s ease-out infinite;
}
@keyframes trafficPulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45); }
  70% { box-shadow: 0 0 0 12px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.traffic-card {
  border: 1px solid rgb(var(--surface-700));
  background: rgb(var(--surface-800) / 0.7);
  border-radius: 12px;
  padding: 12px 14px;
  animation: trafficIn 0.25s ease-out;
}
@keyframes trafficIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.traffic-card.is-start { border-color: rgba(59, 130, 246, 0.45); }
.traffic-card.is-routed { border-color: rgba(168, 85, 247, 0.4); }
.traffic-card.is-done { border-color: rgba(34, 197, 94, 0.35); }
.traffic-card.is-error { border-color: rgba(239, 68, 68, 0.5); }

.traffic-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 11px;
}
.traffic-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.traffic-badge.start { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
.traffic-badge.routed { background: rgba(168, 85, 247, 0.2); color: #d8b4fe; }
.traffic-badge.done { background: rgba(34, 197, 94, 0.2); color: #86efac; }
.traffic-badge.error { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.traffic-badge.channel-proxy { background: rgba(14, 165, 233, 0.15); color: #7dd3fc; }
.traffic-badge.channel-chat { background: rgba(245, 158, 11, 0.15); color: #fcd34d; }
.traffic-badge.routing-inject { background: rgba(34, 197, 94, 0.2); color: #86efac; }
.traffic-badge.routing-retain { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
.traffic-badge.routing-skip { background: rgba(148, 163, 184, 0.18); color: #e2e8f0; }
.traffic-badge.routing-offer { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.traffic-badge.routing-miss { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }

.traffic-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  align-items: start;
  padding: 4px 0;
  font-size: 12px;
  line-height: 1.45;
}
.traffic-row + .traffic-row {
  border-top: 1px solid rgb(var(--surface-700) / 0.6);
}
.traffic-stage {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-align: right;
  padding-top: 2px;
  color: #94a3b8;
}
.traffic-stage.in { color: #60a5fa; }
.traffic-stage.route { color: #c084fc; }
.traffic-stage.rag { color: #818cf8; }
.traffic-stage.llm { color: #34d399; }
.traffic-stage.out { color: #fbbf24; }
.traffic-stage.err { color: #f87171; }
.traffic-body {
  min-width: 0;
  color: #e2e8f0;
  white-space: pre-wrap;
  word-break: break-word;
}
.traffic-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.traffic-chip {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgb(var(--surface-900));
  color: #e2e8f0;
  border: 1px solid rgb(var(--surface-700));
}
.traffic-card.is-start .traffic-body.pending::after,
.traffic-card.is-routed .traffic-body .pending::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: #60a5fa;
  animation: trafficPulse 1.2s ease-out infinite;
  vertical-align: middle;
}

.traffic-payload {
  margin-top: 8px;
  border: 1px solid rgb(var(--surface-700) / 0.8);
  border-radius: 8px;
  background: rgb(var(--surface-900) / 0.55);
  overflow: hidden;
}
.traffic-payload > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  color: #cbd5e1;
  user-select: none;
}
.traffic-payload > summary::-webkit-details-marker { display: none; }
.traffic-payload > summary::before {
  content: '▸';
  color: #94a3b8;
  font-size: 10px;
}
.traffic-payload[open] > summary::before { content: '▾'; }
.traffic-payload-meta {
  margin-left: auto;
  font-weight: 400;
  color: #94a3b8;
  font-size: 10px;
}
.traffic-payload-body {
  margin: 0;
  padding: 10px 12px 12px;
  border-top: 1px solid rgb(var(--surface-700) / 0.7);
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 11px;
  line-height: 1.45;
  color: #e2e8f0;
  background: rgb(15 23 42 / 0.45);
}

/* Modal body spacing for session view */
#modal-body > div + div {
  margin-top: 12px;
}

/* Responsive: stack panels on small screens */
@media (max-width: 768px) {
  #dashboard > div:last-child {
    flex-direction: column;
  }
  aside {
    width: 100% !important;
    max-height: 50vh;
    border-right: none !important;
    border-top: 1px solid #334155;
  }
}

/* ── Light theme overrides for hardcoded colors ──────────────────────────── */
html.light select,
html.light input[type="number"],
html.light input[type="text"],
html.light input[type="password"],
html.light textarea {
  color-scheme: light;
}

html.light ::-webkit-scrollbar-thumb { background: #cbd5e1; }
html.light ::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

html.light .tab-btn { color: #334155; }
html.light .tab-btn:hover { color: #0f172a; background: #e2e8f0; }
html.light .tab-btn.active { color: #0f172a; background: #cbd5e1; }

html.light .traffic-body,
html.light .traffic-payload-body { color: #1e293b; }
html.light .traffic-chip { color: #334155; background: #f8fafc; }
html.light .traffic-payload > summary { color: #334155; }
html.light .traffic-payload > summary::before,
html.light .traffic-payload-meta,
html.light .traffic-stage { color: #475569; }
html.light .traffic-payload-body { background: rgb(248 250 252 / 0.8); }

html.light .setting-tip {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #334155;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.15);
}

html.light .turn-block { border-left-color: #cbd5e1; }
html.light .turn-block::before { background: #94a3b8; border-color: #ffffff; }
html.light .turn-block-focus { border-left-color: #3b82f6; }
html.light .turn-block-focus::before { background: #3b82f6; }

@media (max-width: 768px) {
  html.light aside { border-top-color: #e2e8f0; }
}

/* Keep semantic accent text legible on light surfaces */
html.light .text-blue-300 { color: #1d4ed8; }
html.light .text-green-300,
html.light .text-green-400 { color: #15803d; }
html.light .text-red-300,
html.light .text-red-400 { color: #b91c1c; }
html.light .text-amber-300 { color: #b45309; }
html.light .text-sky-300 { color: #0369a1; }
html.light .text-purple-200,
html.light .text-purple-300,
html.light .text-purple-400 { color: #7e22ce; }
html.light .text-violet-100,
html.light .text-violet-200,
html.light .text-violet-300,
html.light .text-violet-400 { color: #6d28d9; }
html.light .text-indigo-300,
html.light .text-indigo-400 { color: #4338ca; }
html.light .text-indigo-200,
html.light .text-indigo-200\/80 { color: #4f46e5; }
html.light .text-indigo-400\/70 { color: #6366f1; }
html.light .text-cyan-100,
html.light .text-cyan-200,
html.light .text-cyan-400 { color: #0e7490; }
html.light .text-cyan-200\/80 { color: #0e7490; }
html.light .text-cyan-500\/70 { color: #0891b2; }
