/* ─── Variables ────────────────────────────────────────────────────────── */
:root {
  --bg-base: #0f172a;
  --bg-card: #1e293b;
  --bg-hover: #263248;
  --bg-input: #0f172a;
  --border: #334155;
  --border-focus: #6366f1;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #38bdf8;
  --radius: 8px;
  --radius-sm: 4px;
  --sidebar-w: 220px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

/* ─── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-base);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
#app { height: 100vh; display: flex; }

#main-app {
  display: flex;
  width: 100%;
  height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  min-width: 0;
}

/* ─── Auth overlay ──────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 420px;
  max-width: 95vw;
  box-shadow: var(--shadow);
}

.auth-logo { text-align: center; margin-bottom: 28px; }
.logo-mark { font-size: 40px; margin-bottom: 8px; }
.auth-logo h1 { font-size: 22px; font-weight: 700; color: var(--text); }
.auth-tagline { font-size: 13px; color: var(--text-muted); margin-top: 6px; }

.auth-form { margin-bottom: 24px; }
.auth-error { color: var(--danger); font-size: 13px; text-align: center; margin-top: 10px; min-height: 18px; }

.auth-features {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.feature-pill {
  background: rgba(99,102,241,0.15);
  border: 1px solid rgba(99,102,241,0.3);
  color: #a5b4fc;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.brand-icon { font-size: 20px; }
.brand-name { font-weight: 700; font-size: 14px; letter-spacing: -0.02em; }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  font-size: 13.5px;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: rgba(99,102,241,0.2); color: #a5b4fc; font-weight: 500; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.api-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
}

.status-dot.ok { background: var(--success); }
.status-dot.warn { background: var(--warning); }
.status-dot.err { background: var(--danger); }
.sidebar-version { font-size: 11px; color: var(--text-dim); }

/* ─── View container ────────────────────────────────────────────────────── */
.view { animation: fadeIn 0.2s ease; }
.hidden { display: none !important; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ─── Page header ───────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-header h2 { font-size: 22px; font-weight: 700; }
.page-header p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ─── Stat cards ────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; }
.stat-sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }
.stat-value.danger { color: var(--danger); }

/* ─── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── Tables ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px;
  border-bottom: 1px solid rgba(51,65,85,0.5);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tr:hover td { background: var(--bg-hover); }

.table-empty {
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
}

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 13.5px;
  line-height: 1;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary { background: transparent; color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); }

.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,0.1); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: #16a34a; }

/* ─── Forms ─────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="email"],
select,
textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text);
  transition: border-color 0.15s;
  outline: none;
}

input:focus, select:focus, textarea:focus { border-color: var(--border-focus); }
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--bg-card); }

.form-hint { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; }

/* ─── Badges & tags ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 500;
  gap: 4px;
}

.badge-green { background: rgba(34,197,94,0.15); color: #86efac; border: 1px solid rgba(34,197,94,0.25); }
.badge-yellow { background: rgba(245,158,11,0.15); color: #fcd34d; border: 1px solid rgba(245,158,11,0.25); }
.badge-red { background: rgba(239,68,68,0.15); color: #fca5a5; border: 1px solid rgba(239,68,68,0.25); }
.badge-blue { background: rgba(56,189,248,0.15); color: #7dd3fc; border: 1px solid rgba(56,189,248,0.25); }
.badge-gray { background: rgba(100,116,139,0.2); color: var(--text-muted); border: 1px solid var(--border); }
.badge-purple { background: rgba(99,102,241,0.15); color: #a5b4fc; border: 1px solid rgba(99,102,241,0.25); }

/* ─── Score display ─────────────────────────────────────────────────────── */
.score-ring {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid var(--border);
  font-size: 22px;
  font-weight: 800;
}

.score-ring.score-high { border-color: var(--success); color: var(--success); }
.score-ring.score-med { border-color: var(--warning); color: var(--warning); }
.score-ring.score-low { border-color: var(--danger); color: var(--danger); }
.score-ring.score-none { color: var(--text-dim); }

.score-bar-wrap { margin-bottom: 10px; }
.score-bar-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.score-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.score-bar-fill { height: 100%; border-radius: 3px; transition: width 0.5s ease; }
.score-bar-fill.high { background: var(--success); }
.score-bar-fill.med { background: var(--warning); }
.score-bar-fill.low { background: var(--danger); }

/* ─── Scenario cards ────────────────────────────────────────────────────── */
.scenario-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.scenario-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  user-select: none;
}

.scenario-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.scenario-card.selected { border-color: var(--primary); background: rgba(99,102,241,0.08); }

.scenario-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 8px;
}

.scenario-card h3 { font-size: 13.5px; font-weight: 600; }
.scenario-card p { font-size: 12.5px; color: var(--text-muted); line-height: 1.5; }

.scenario-meta {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.difficulty-easy { background: rgba(34,197,94,0.15); color: #86efac; }
.difficulty-medium { background: rgba(245,158,11,0.15); color: #fcd34d; }
.difficulty-hard { background: rgba(239,68,68,0.15); color: #fca5a5; }

/* ─── Conversation view ─────────────────────────────────────────────────── */
.conversation {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 4px;
}

.msg { display: flex; gap: 10px; }
.msg-bubble {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.6;
  max-width: 85%;
}

.msg-user .msg-bubble { background: rgba(99,102,241,0.15); border: 1px solid rgba(99,102,241,0.25); margin-left: auto; }
.msg-agent .msg-bubble { background: var(--bg-hover); border: 1px solid var(--border); }
.msg-role { font-size: 11px; color: var(--text-dim); margin-bottom: 4px; font-weight: 600; text-transform: uppercase; }
.msg-user { flex-direction: row-reverse; }

/* ─── Modal ─────────────────────────────────────────────────────────────── */
.modal-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 20px;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 600px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  position: relative;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h3 { font-size: 18px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 20px;
  padding: 4px;
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ─── Progress bar ──────────────────────────────────────────────────────── */
.progress-bar-wrap { background: var(--border); border-radius: 4px; height: 8px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.5s ease; }

/* ─── Trust badge preview ───────────────────────────────────────────────── */
.badge-preview {
  background: #1a1f2e;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  margin: 20px 0;
}

.badge-svg-wrap img, .badge-svg-wrap svg { max-width: 100%; }

.code-block {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12.5px;
  color: #a5b4fc;
  word-break: break-all;
  position: relative;
}

/* ─── Toasts ─────────────────────────────────────────────────────────────── */
#toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slideIn 0.2s ease;
  max-width: 320px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--info); }

@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ─── Run status ─────────────────────────────────────────────────────────── */
.run-status { display: inline-flex; align-items: center; gap: 5px; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); animation: pulse 1.5s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ─── Checkbox custom ────────────────────────────────────────────────────── */
.scenario-checkbox {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.scenario-card { position: relative; }

/* ─── Filters bar ────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-bar input, .filter-bar select { max-width: 200px; }

/* ─── Big score display ───────────────────────────────────────────────────── */
.trust-score-display {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.trust-score-number {
  font-size: 56px;
  font-weight: 900;
  line-height: 1;
  min-width: 100px;
  text-align: center;
}

.trust-score-breakdown { flex: 1; }
.trust-score-breakdown h3 { margin-bottom: 12px; font-size: 14px; color: var(--text-muted); }

/* ─── Loading spinner ─────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 60px; min-width: 60px; }
  .brand-name, .nav-item span:last-child, .sidebar-footer > * { display: none; }
  .nav-item { justify-content: center; }
  .main { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
