:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface2: #1a1a26;
  --border: #2a2a3a;
  --text: #e4e4ed;
  --text2: #8888a0;
  --accent: #7c5cfc;
  --accent2: #5c3ce6;
  --green: #34d399;
  --red: #f87171;
  --yellow: #fbbf24;
  --blue: #60a5fa;
  --radius: 10px;
  --sidebar-width: 200px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Login Screen ── */
#loginScreen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #1a1030 0%, var(--bg) 70%);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.login-card .logo { text-align: center; margin-bottom: 32px; }
.login-card .logo h1 {
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.login-card .logo p { font-size: 13px; color: var(--text2); margin-top: 6px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 6px; font-weight: 500; }
.form-group input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}
.form-group input:focus { border-color: var(--accent); }
.login-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s;
  margin-top: 8px;
}
.login-btn:hover { opacity: .9; }
.login-btn:disabled { opacity: .5; cursor: not-allowed; }
.login-error {
  background: rgba(248,113,113,.1);
  border: 1px solid rgba(248,113,113,.2);
  color: var(--red);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

/* ── App Shell ── */
#appShell { display: none; height: 100vh; flex-direction: column; }

.header {
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}
.header h1 { font-size: 17px; font-weight: 600; color: #fff; }
.header .badge {
  background: rgba(255,255,255,.15);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  color: #fff;
}
.header .user-info { display: flex; align-items: center; gap: 12px; font-size: 13px; color: rgba(255,255,255,.8); }
.header .logout-btn {
  background: rgba(255,255,255,.15);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.header .logout-btn:hover { background: rgba(255,255,255,.25); }

/* ── Layout: sidebar + content ── */
.app-body { display: flex; flex: 1; overflow: hidden; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}
.sidebar-section {
  padding: 12px 8px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text2);
  font-weight: 600;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  margin: 2px 6px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
  transition: all .15s;
  border: none;
  background: none;
  width: calc(100% - 12px);
  text-align: left;
  font-family: inherit;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(124,92,252,.15); color: var(--accent); }
.nav-item .nav-icon { font-size: 15px; width: 18px; text-align: center; }

.content-area { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

/* ── Page sections ── */
.page { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.page.active { display: flex; }

/* ── Shared toolbar ── */
.toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-shrink: 0;
}
.toolbar label { font-size: 13px; color: var(--text2); white-space: nowrap; }

/* ── Form elements ── */
input, select, textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border-color .2s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
button:hover { background: var(--accent2); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary { background: var(--surface2); border: 1px solid var(--border); color: var(--text); }
button.secondary:hover { background: var(--border); }
button.danger { background: var(--red); }
button.danger:hover { background: #dc2626; }

/* ── Two-panel layout (flow tester) ── */
.main {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 0;
  flex: 1;
  overflow: hidden;
}
@media (max-width: 1000px) { .main { grid-template-columns: 1fr; } }
.panel { border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.panel:last-child { border-right: none; }
.panel-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  flex-shrink: 0;
}
.panel-header h2 { font-size: 15px; font-weight: 600; }
.panel-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.panel-footer { padding: 12px 20px; border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }

/* Panel visual hierarchy */
.panel.secondary .panel-header { background: var(--bg); }
.panel.secondary .panel-header h2 { font-size: 13px; font-weight: 500; color: var(--text2); }
.panel.secondary .panel-body { background: var(--bg); }
.panel.secondary .panel-footer { background: var(--bg); }
.panel.primary .panel-header { background: var(--surface); border-bottom-color: var(--accent); }
.panel.primary .panel-header h2 { font-size: 16px; }

/* ── Chat ── */
.chat-messages { display: flex; flex-direction: column; gap: 8px; min-height: 200px; }
.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg.bot { align-self: flex-start; background: var(--surface2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg .label { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; opacity: .6; margin-bottom: 4px; }
.msg .buttons-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.msg .btn-option {
  background: var(--accent);
  color: #fff;
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 11px;
  cursor: pointer;
  transition: .2s;
}
.msg .btn-option:hover { background: var(--accent2); }
.chat-input { display: flex; gap: 8px; }
.chat-input input { flex: 1; }

/* ── Status badges ── */
.status-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.status-badge.active { background: rgba(52,211,153,.15); color: var(--green); }
.status-badge.completed { background: rgba(96,165,250,.15); color: var(--blue); }
.status-badge.error { background: rgba(248,113,113,.15); color: var(--red); }
.status-badge.pending { background: rgba(251,191,36,.15); color: var(--yellow); }
.status-badge.running { background: rgba(124,92,252,.15); color: var(--accent); }

/* ── Test Runner ── */
.config-row { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.config-row label { font-size: 12px; color: var(--text2); min-width: 80px; }
.run-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: .2s;
}
.run-card:hover { border-color: var(--accent); }
.run-card .run-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.run-card .run-id { font-size: 12px; color: var(--text2); font-family: monospace; }
.run-card .run-stats { font-size: 12px; color: var(--text2); margin-top: 4px; }
.score-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.score-bar .fill { height: 100%; border-radius: 3px; transition: width .3s; }
.conv-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 8px; }
.conv-card .conv-header { display: flex; justify-content: space-between; align-items: center; }
.conv-card .persona { font-size: 13px; font-weight: 500; }
.conv-card .mode { font-size: 11px; padding: 2px 6px; border-radius: 8px; }
.conv-card .mode.on { background: rgba(124,92,252,.15); color: var(--accent); }
.conv-card .mode.off { background: rgba(136,136,160,.15); color: var(--text2); }
.scores-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.score-item { text-align: center; }
.score-item .score-val { font-size: 18px; font-weight: 700; }
.score-item .score-label { font-size: 10px; color: var(--text2); }
.issues-list { margin-top: 10px; }
.issue { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.issue:last-child { border-bottom: none; }
.issue .sev { font-size: 10px; padding: 1px 6px; border-radius: 8px; font-weight: 600; white-space: nowrap; height: fit-content; }
.sev.critical { background: rgba(248,113,113,.2); color: var(--red); }
.sev.high { background: rgba(251,146,60,.2); color: #fb923c; }
.sev.medium { background: rgba(251,191,36,.2); color: var(--yellow); }
.sev.low { background: rgba(96,165,250,.2); color: var(--blue); }
.empty { text-align: center; padding: 40px; color: var(--text2); font-size: 13px; }
.comparison-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  font-size: 13px;
}
.comparison-box h4 { margin-bottom: 8px; font-size: 13px; }
.transcript-view { max-height: 400px; overflow-y: auto; }
.back-btn { font-size: 12px; cursor: pointer; color: var(--accent); background: none; border: none; padding: 0; }
.back-btn:hover { text-decoration: underline; background: none; }
.loading { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.flex-center { display: flex; align-items: center; gap: 8px; }
.auto-refresh-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text2);
}
.auto-refresh-toggle input { accent-color: var(--accent); }
.compact-select {
  padding: 6px 10px;
  font-size: 12px;
}
.alerts-list {
  display: grid;
  gap: 10px;
}
.alert-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 10px;
  padding: 12px 14px;
}
.alert-item.critical { border-left-color: var(--red); }
.alert-item.warning { border-left-color: var(--yellow); }
.alert-item.info { border-left-color: var(--blue); }
.alert-item.success { border-left-color: var(--green); }
.alert-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.alert-text {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text2);
}
.ops-panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.ops-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.ops-panel-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}
.ops-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.ops-job {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.ops-job:last-child { border-bottom: 0; }
.ops-job-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.ops-job-id {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.ops-job-text {
  font-size: 12px;
  color: var(--text2);
  line-height: 1.4;
}
.ops-job-meta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text3);
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  position: relative;
}
.modal h3 { font-size: 18px; font-weight: 600; margin-bottom: 6px; }
.modal .subtitle { font-size: 13px; color: var(--text2); margin-bottom: 20px; }
.modal .close-btn { position: absolute; top: 12px; right: 16px; background: none; border: none; color: var(--text2); font-size: 20px; cursor: pointer; padding: 4px 8px; }
.modal .close-btn:hover { color: var(--text); background: none; }
.modal textarea { width: 100%; min-height: 100px; resize: vertical; margin-bottom: 12px; font-family: inherit; }
.modal .hint { font-size: 11px; color: var(--text2); margin-bottom: 16px; }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal .or-divider {
  text-align: center;
  color: var(--text2);
  font-size: 12px;
  margin: 14px 0;
  position: relative;
}
.modal .or-divider::before,
.modal .or-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border);
}
.modal .or-divider::before { left: 0; }
.modal .or-divider::after { right: 0; }
.random-btn {
  width: 100%;
  background: var(--surface2);
  border: 1px dashed var(--border);
  color: var(--text2);
  padding: 14px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  transition: .2s;
  margin-bottom: 4px;
}
.random-btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(124,92,252,.05); }
.generating-anim { text-align: center; padding: 30px 0; }
.generating-anim .spinner-lg {
  width: 48px; height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 16px;
}
.generating-anim p { color: var(--text2); font-size: 13px; }
.generating-anim h4 { font-size: 15px; margin-bottom: 6px; }

/* ── Live View ── */
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); animation: livePulse 1.2s ease-in-out infinite; display: inline-block; }
@keyframes livePulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.live-mode-tag { font-size: 10px; padding: 2px 6px; border-radius: 8px; font-weight: 600; }
.live-mode-tag.on { background: rgba(52,211,153,.15); color: var(--green); }
.live-mode-tag.off { background: rgba(136,136,160,.15); color: var(--text2); }

/* Panel body in live mode — remove padding, use flex column */
.panel-body.in-live-mode { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
#liveView { display: flex; flex-direction: column; flex: 1; overflow: hidden; }

/* Persona bubbles strip */
.live-personas-strip {
  display: flex;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
  align-items: flex-end;
  scroll-behavior: smooth;
}
.live-personas-strip::-webkit-scrollbar { height: 3px; }
.live-personas-strip::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.live-waiting-msg { font-size: 12px; color: var(--text2); margin: auto; padding: 4px 0; }

.persona-bubble {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 58px;
  transition: transform .25s ease;
}
.persona-bubble.active { transform: translateY(-4px); }

.persona-avatar-wrap { position: relative; width: 48px; height: 48px; }
.persona-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 2px solid var(--border);
  transition: border-color .3s, box-shadow .3s;
  display: block;
}
.persona-bubble.active .persona-avatar {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124,92,252,.3), 0 4px 16px rgba(124,92,252,.2);
}
.persona-bubble.done .persona-avatar { filter: brightness(.75); }

.persona-status-dot {
  position: absolute; bottom: 1px; right: 1px;
  width: 13px; height: 13px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--border);
  transition: background .3s;
}
.persona-bubble.active .persona-status-dot { background: var(--accent); animation: livePulse 1s ease-in-out infinite; }
.persona-bubble.done .persona-status-dot { background: var(--green); animation: none; }

.persona-bubble-name {
  font-size: 10px; color: var(--text2);
  text-align: center; max-width: 60px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  line-height: 1.2;
}
.persona-bubble.active .persona-bubble-name { color: var(--accent); font-weight: 600; }
.persona-bubble-score {
  font-size: 9px; font-weight: 700;
  padding: 1px 6px; border-radius: 8px;
}

/* Current persona info bar */
.live-current-bar {
  padding: 8px 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  min-height: 44px;
}
.live-current-avatar { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; }
.live-current-name { font-size: 13px; font-weight: 600; white-space: nowrap; }
.live-current-desc { font-size: 11px; color: var(--text2); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Chat messages */
.live-chat {
  flex: 1;
  display: flex; flex-direction: column; gap: 8px;
  overflow-y: auto; overflow-x: hidden;
  padding: 14px 16px;
  scroll-behavior: smooth;
}
.live-msg {
  max-width: 82%; padding: 8px 12px; border-radius: 12px;
  font-size: 13px; line-height: 1.5; word-wrap: break-word; white-space: pre-wrap;
  animation: fadeSlideIn .25s ease-out;
}
@keyframes fadeSlideIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.live-msg.bot { align-self: flex-start; background: var(--surface2); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.live-msg.user { align-self: flex-end; color: #fff; border-bottom-right-radius: 3px; }
.live-msg .live-sender { font-size: 9px; text-transform: uppercase; letter-spacing: .5px; opacity: .6; margin-bottom: 3px; }
.live-event-badge {
  align-self: center; font-size: 11px; color: var(--text2);
  padding: 4px 14px; background: var(--surface2); border: 1px dashed var(--border); border-radius: 20px;
  flex-shrink: 0;
}
.live-score-badge { align-self: center; font-size: 12px; font-weight: 600; padding: 6px 16px; border-radius: 20px; border: 1px solid; flex-shrink: 0; }

/* ── Health Page ── */
.health-page { padding: 28px 32px; overflow-y: auto; }
.health-page h2 { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.health-page .health-subtitle { font-size: 13px; color: var(--text2); margin-bottom: 24px; }
.hc-section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--text2); font-weight: 600; margin-bottom: 12px; }
.hc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 28px; }
.hc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: border-color .2s;
}
.hc-card:hover { border-color: var(--accent); }
.hc-card-inner { display: flex; flex-direction: column; gap: 10px; }
.hc-card-title { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text2); font-weight: 600; }
.hc-card-status { display: flex; align-items: center; gap: 8px; }
.hc-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.loading-dot { background: var(--text2); animation: livePulse 1s ease-in-out infinite; }
.hc-card-sub { font-size: 11px; color: var(--text2); }
.hc-stat-value { font-size: 32px; font-weight: 700; color: var(--text); line-height: 1; }
.hc-footer { display: flex; align-items: center; justify-content: space-between; }
.hc-updated { font-size: 11px; color: var(--text2); }

/* ── Metrics Dashboard ── */
.metrics-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)) !important; }
.metric-value { font-size: 30px; font-weight: 700; line-height: 1.1; }
.metric-card { transition: border-color .2s, transform .15s; }
.metric-card:hover { border-color: var(--accent); transform: translateY(-2px); }

/* ── Recent Users Table ── */
.recent-users-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 28px;
}
.ru-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ru-table thead { background: var(--surface2); }
.ru-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text2);
  font-weight: 600;
}
.ru-table td { padding: 10px 16px; border-top: 1px solid var(--border); }
.ru-name { font-weight: 500; }
.ru-email { color: var(--text2); }
.ru-date { color: var(--text2); font-size: 12px; white-space: nowrap; }
