:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3348;
  --text: #e8eaef;
  --muted: #8b92a8;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 12px;
  font-family: Inter, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); min-height: 100vh; }

.hidden { display: none !important; }

/* Auth */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 40px; width: 100%; max-width: 420px; }
.auth-logo { font-size: 1.25rem; font-weight: 700; color: var(--text); text-decoration: none; }
.auth-card h1 { margin: 16px 0 8px; font-size: 1.5rem; }
.auth-sub { color: var(--muted); font-size: 0.9rem; margin-bottom: 24px; line-height: 1.5; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.auth-tabs button { flex: 1; padding: 10px; border: 1px solid var(--border); background: transparent; color: var(--muted); border-radius: 8px; cursor: pointer; }
.auth-tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.auth-card label { display: block; margin-bottom: 14px; font-size: 0.85rem; color: var(--muted); }
.auth-card input { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 1rem; }
.auth-error { color: var(--danger); font-size: 0.85rem; margin-top: 12px; }
.auth-footer { margin-top: 20px; font-size: 0.85rem; color: var(--muted); text-align: center; }
.auth-footer a { color: var(--accent); }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 20px 12px; flex-shrink: 0; }
.sidebar-brand { font-weight: 700; padding: 8px 12px 24px; font-size: 1.1rem; }
.sidebar-brand span { color: var(--accent); font-size: 0.75rem; margin-left: 4px; }
.sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.nav-item { text-align: left; padding: 10px 14px; border: none; background: transparent; color: var(--muted); border-radius: 8px; cursor: pointer; font-size: 0.9rem; }
.nav-item:hover, .nav-item.active { background: var(--surface2); color: var(--text); }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); margin-top: 12px; }
.plan-badge { font-size: 0.8rem; color: var(--muted); margin-bottom: 8px; }

.main { flex: 1; overflow: auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 20px 28px; border-bottom: 1px solid var(--border); }
.topbar h2 { font-size: 1.25rem; }
.topbar-user { font-size: 0.85rem; color: var(--muted); }
.view { padding: 24px 28px; }
.view-actions { margin-bottom: 16px; }

/* Components */
.btn-primary { background: var(--accent); color: #fff; border: none; padding: 10px 18px; border-radius: 8px; cursor: pointer; font-size: 0.9rem; font-weight: 500; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 0.85rem; }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-danger { background: var(--danger); color: #fff; border: none; padding: 8px 14px; border-radius: 8px; cursor: pointer; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card h3 { margin-bottom: 12px; font-size: 1rem; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stat-card .label { font-size: 0.8rem; color: var(--muted); margin-bottom: 8px; }
.stat-card .value { font-size: 1.75rem; font-weight: 700; }
.stat-card .sub { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }

.bots-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.bot-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; cursor: pointer; transition: border-color 0.15s; }
.bot-card:hover { border-color: var(--accent); }
.bot-card h4 { margin-bottom: 6px; }
.bot-card .meta { font-size: 0.8rem; color: var(--muted); }
.bot-status { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 0.7rem; margin-top: 8px; }
.bot-status.ready { background: rgba(34,197,94,0.15); color: var(--success); }
.bot-status.training { background: rgba(99,102,241,0.15); color: var(--accent); }
.bot-status.embedding { background: rgba(168,85,247,0.15); color: #a855f7; }

.bot-detail { margin-top: 20px; }
.embed-box { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-family: monospace; font-size: 0.75rem; overflow-x: auto; white-space: pre-wrap; word-break: break-all; margin: 12px 0; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.form-row label, .field { display: block; margin-bottom: 12px; font-size: 0.85rem; color: var(--muted); }
.form-row input, .field input, .field select, .field textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.field textarea { min-height: 80px; resize: vertical; }
.color-input { width: 60px !important; height: 40px; padding: 4px !important; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; }
tr:hover td { background: var(--surface); }

.quick-steps { padding-left: 20px; line-height: 2; color: var(--muted); }
.quick-steps code { background: var(--surface2); padding: 2px 6px; border-radius: 4px; font-size: 0.85rem; }

.integrations-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.integration-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.integration-card h4 { margin-bottom: 8px; }
.integration-card p { font-size: 0.85rem; color: var(--muted); margin-bottom: 12px; }

.api-key-row { display: flex; gap: 12px; align-items: center; margin-top: 8px; }
.api-key-row code { flex: 1; background: var(--bg); padding: 10px; border-radius: 8px; font-size: 0.8rem; word-break: break-all; }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 24px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; width: 100%; max-width: 480px; }
.modal h3 { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 20px; }

.gap-list { margin-top: 12px; }
.gap-item { padding: 10px; background: var(--bg); border-radius: 8px; margin-bottom: 8px; font-size: 0.85rem; }

.msg-list { max-height: 400px; overflow-y: auto; }
.msg { padding: 10px; margin-bottom: 8px; border-radius: 8px; font-size: 0.9rem; }
.msg.user { background: var(--accent); color: #fff; margin-left: 20%; }
.msg.assistant { background: var(--surface2); margin-right: 20%; }

/* Onboarding */
.onboarding-banner { background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(99,102,241,0.05)); border: 1px solid var(--accent); border-radius: var(--radius); padding: 16px 20px; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.onboarding-banner p { font-size: 0.9rem; color: var(--text); }
.onboarding-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.75); z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 24px; }
.onboarding-wizard { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 32px; width: 100%; max-width: 520px; }
.wizard-progress { height: 4px; background: var(--surface2); border-radius: 99px; margin-bottom: 24px; overflow: hidden; }
.wizard-bar { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.3s; width: 25%; }
.wizard-step h2 { font-size: 1.35rem; margin-bottom: 8px; }
.wizard-step p { color: var(--muted); font-size: 0.9rem; line-height: 1.6; margin-bottom: 20px; }
.wizard-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 8px; }

.setup-steps { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.setup-step { padding: 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); }
.setup-step.done { border-color: var(--success); background: rgba(34,197,94,0.06); }
.setup-step.active { border-color: var(--accent); background: rgba(99,102,241,0.06); }
.setup-step .step-num { font-size: 0.75rem; color: var(--muted); margin-bottom: 6px; }
.setup-step h4 { font-size: 0.9rem; margin-bottom: 4px; }
.setup-step p { font-size: 0.8rem; color: var(--muted); }

/* Bot detail split + preview */
.bot-detail-layout { display: grid; grid-template-columns: 1fr 380px; gap: 20px; align-items: start; }
.bot-preview-panel { position: sticky; top: 20px; }
.preview-widget { background: #f8f9fb; border-radius: 16px; overflow: hidden; border: 1px solid #e5e7eb; box-shadow: 0 8px 32px rgba(0,0,0,0.12); height: 520px; display: flex; flex-direction: column; }
.preview-header { padding: 14px 16px; color: #fff; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.preview-messages { flex: 1; overflow-y: auto; padding: 14px; background: #fff; }
.preview-msg { margin-bottom: 10px; padding: 10px 12px; border-radius: 12px; font-size: 0.85rem; line-height: 1.5; max-width: 88%; white-space: pre-wrap; }
.preview-msg.bot { background: #f3f4f6; color: #111; }
.preview-msg.user { margin-left: auto; color: #fff; }
.preview-input-row { display: flex; gap: 8px; padding: 12px; background: #fff; border-top: 1px solid #e5e7eb; }
.preview-input-row input { flex: 1; border: 1px solid #d1d5db; border-radius: 8px; padding: 10px; font-size: 0.85rem; }
.preview-input-row button { border: none; color: #fff; border-radius: 8px; padding: 0 14px; cursor: pointer; font-size: 1rem; }
.preview-meta { font-size: 0.75rem; color: var(--muted); margin-top: 10px; text-align: center; }
.preview-sources { font-size: 0.7rem; color: var(--muted); margin-top: 4px; }
.vector-badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 0.7rem; background: rgba(99,102,241,0.15); color: var(--accent); margin-left: 8px; }

@media (max-width: 1024px) {
  .bot-detail-layout { grid-template-columns: 1fr; }
  .bot-preview-panel { position: static; }
}

@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; }
  .form-row { grid-template-columns: 1fr; }
}
