/* ==========================================================================
   Admin Panel Styles
   ========================================================================== */

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --bg: #f5f5f5;
  --card: #ffffff;
  --border: #e5e5e5;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  position: relative;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cg stroke='rgba(99,102,241,0.06)' stroke-width='0.8'%3E%3Cline x1='40' y1='60' x2='120' y2='30'/%3E%3Cline x1='120' y1='30' x2='200' y2='80'/%3E%3Cline x1='200' y1='80' x2='300' y2='40'/%3E%3Cline x1='300' y1='40' x2='360' y2='100'/%3E%3Cline x1='40' y1='60' x2='80' y2='150'/%3E%3Cline x1='120' y1='30' x2='160' y2='120'/%3E%3Cline x1='200' y1='80' x2='160' y2='120'/%3E%3Cline x1='80' y1='150' x2='160' y2='120'/%3E%3Cline x1='160' y1='120' x2='260' y2='160'/%3E%3Cline x1='300' y1='40' x2='260' y2='160'/%3E%3Cline x1='360' y1='100' x2='380' y2='200'/%3E%3Cline x1='260' y1='160' x2='380' y2='200'/%3E%3Cline x1='80' y1='150' x2='40' y2='240'/%3E%3Cline x1='160' y1='120' x2='120' y2='240'/%3E%3Cline x1='260' y1='160' x2='320' y2='260'/%3E%3Cline x1='380' y1='200' x2='320' y2='260'/%3E%3Cline x1='40' y1='240' x2='120' y2='240'/%3E%3Cline x1='120' y1='240' x2='200' y2='280'/%3E%3Cline x1='200' y1='280' x2='320' y2='260'/%3E%3Cline x1='40' y1='240' x2='100' y2='340'/%3E%3Cline x1='200' y1='280' x2='180' y2='360'/%3E%3Cline x1='320' y1='260' x2='360' y2='350'/%3E%3Cline x1='100' y1='340' x2='180' y2='360'/%3E%3Cline x1='180' y1='360' x2='280' y2='380'/%3E%3Cline x1='280' y1='380' x2='360' y2='350'/%3E%3Cline x1='360' y1='100' x2='400' y2='60'/%3E%3Cline x1='380' y1='200' x2='400' y2='240'/%3E%3Cline x1='360' y1='350' x2='400' y2='400'/%3E%3Cline x1='0' y1='60' x2='40' y2='60'/%3E%3Cline x1='0' y1='240' x2='40' y2='240'/%3E%3Cline x1='100' y1='340' x2='0' y2='400'/%3E%3C/g%3E%3Cg fill='rgba(99,102,241,0.08)'%3E%3Ccircle cx='40' cy='60' r='3'/%3E%3Ccircle cx='120' cy='30' r='4'/%3E%3Ccircle cx='200' cy='80' r='3'/%3E%3Ccircle cx='300' cy='40' r='3.5'/%3E%3Ccircle cx='360' cy='100' r='2.5'/%3E%3Ccircle cx='80' cy='150' r='3'/%3E%3Ccircle cx='160' cy='120' r='5'/%3E%3Ccircle cx='260' cy='160' r='3.5'/%3E%3Ccircle cx='380' cy='200' r='3'/%3E%3Ccircle cx='40' cy='240' r='3'/%3E%3Ccircle cx='120' cy='240' r='4'/%3E%3Ccircle cx='200' cy='280' r='3.5'/%3E%3Ccircle cx='320' cy='260' r='3'/%3E%3Ccircle cx='100' cy='340' r='3'/%3E%3Ccircle cx='180' cy='360' r='4'/%3E%3Ccircle cx='280' cy='380' r='2.5'/%3E%3Ccircle cx='360' cy='350' r='3'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 400px 400px;
}
body > * {
  position: relative;
  z-index: 1;
}

/* ── Auth Gate ─────────────────────────────────────────────────────────────── */
#auth-gate {
  min-height: 100vh;
  background: var(--bg);
}
#auth-gate .app-header {
  margin-bottom: 0;
}
.auth-gate-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 56px);
}
.auth-card {
  background: var(--card);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
}
.auth-card h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
  text-align: center;
  color: var(--primary);
}
.auth-card label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}
.auth-card input[type="email"],
.auth-card input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 14px;
  font-family: inherit;
}
.auth-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.auth-card .btn {
  width: 100%;
  padding: 10px;
  font-size: 15px;
  margin-top: 4px;
}
.auth-error {
  background: #fee2e2;
  color: #991b1b;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 14px;
}
.auth-toggle {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 16px;
}
.auth-toggle a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
.auth-toggle a:hover {
  text-decoration: underline;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */
.app-header {
  background: #312e81;
  color: #fff;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-header h1 { font-size: 18px; font-weight: 600; }
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-email {
  font-size: 13px;
  opacity: .85;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* ── Tabs ───────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}
.tab-btn {
  padding: 10px 20px;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  margin-bottom: 16px;
}

/* ── Collapsible cards ─────────────────────────────────────────────────── */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}
.card-header h2 {
  font-size: 16px;
  margin: 0;
}
.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chevron::after {
  content: "\25BE";
  display: inline-block;
  font-size: 14px;
  color: var(--text-muted);
  transition: transform .2s;
}
.card.collapsed .chevron::after {
  transform: rotate(-90deg);
}
.card-body {
  margin-top: 16px;
}
.card.collapsed .card-body {
  display: none;
}

/* ── Upload ─────────────────────────────────────────────────────────────── */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  color: var(--text-muted);
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: rgba(99,102,241,.04);
}
.dropzone p { margin-top: 8px; font-size: 14px; }

.upload-form { margin-top: 16px; }
.upload-form label { display: block; font-weight: 500; margin-bottom: 4px; font-size: 14px; }
.upload-form input[type="text"],
.upload-form textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 12px;
}
.upload-form textarea { min-height: 120px; resize: vertical; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #d97706; }
.btn-dark { background: #1a1a1a; color: #fff; }
.btn-dark:hover { background: #333; }
.btn-amber { background: #fef3c7; color: #92400e; }
.btn-amber:hover { background: #fde68a; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ── Documents table ────────────────────────────────────────────────────── */
.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.doc-table th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13px;
}
.doc-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.doc-table tr:last-child td { border-bottom: none; }

/* ── Status cards ───────────────────────────────────────────────────────── */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.status-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  border-left: 4px solid var(--border);
  text-align: center;
}
.status-card.healthy { border-left-color: var(--success); }
.status-card.unhealthy { border-left-color: var(--danger); }
.status-card.unknown { border-left-color: var(--warning); }
.status-card h3 { font-size: 15px; margin-bottom: 8px; text-align: center; }
.status-card .badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-healthy { background: #dcfce7; color: #166534; }
.badge-unhealthy { background: #fee2e2; color: #991b1b; }
.badge-unknown { background: #fef3c7; color: #92400e; }
.badge-draft { background: #fef3c7; color: #92400e; }
.badge-live { background: #dcfce7; color: #166534; }
.status-card .detail { margin-top: 8px; font-size: 13px; color: var(--text-muted); }

/* ── Response form ──────────────────────────────────────────────────────── */
.response-form label {
  display: block;
  font-weight: 500;
  margin-bottom: 4px;
  font-size: 14px;
}
.response-form input[type="text"],
.response-form textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 12px;
}
.response-form textarea { min-height: 80px; resize: vertical; }

/* ── Collapsible chat panels ────────────────────────────────────────────── */
.chat-preview-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.chat-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #fafafa;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid transparent;
  transition: background .15s;
}
.chat-preview-header:hover { background: #f0f0f0; }
.chat-preview-panel.open .chat-preview-header { border-bottom-color: var(--border); }
.chat-preview-header h3 {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-preview-header .chevron {
  font-size: 12px;
  color: var(--text-muted);
  transition: transform .2s;
}
.chat-preview-panel.open .chat-preview-header .chevron { transform: rotate(90deg); }
.chat-preview-body {
  display: none;
  height: 350px;
}
.chat-preview-panel.open .chat-preview-body { display: flex; flex-direction: column; }
.chat-preview-body .chat-container {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: var(--radius);
  color: #fff;
  font-size: 14px;
  z-index: 10000;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .3s, transform .3s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

/* ── Loading spinner ────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(0,0,0,.1);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

/* ── Integrations headings ─────────────────────────────────────────────── */
.card h2 { color: var(--primary); }
.card h3 { color: var(--primary); }
.security-note {
  background: #fef3c7;
  border-left: 3px solid #f59e0b;
  padding: 10px 14px;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 13px;
  color: #92400e;
  margin-bottom: 16px;
  line-height: 1.5;
}

/* ── Integration note ──────────────────────────────────────────────────── */
.integration-note {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-left: 4px solid #3b82f6;
  color: #1e3a5f;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 20px;
}
.integration-note code {
  background: rgba(59,130,246,.12);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

/* ── Code snippets ─────────────────────────────────────────────────────── */
.code-snippet {
  background: #f0f0f0;
  color: #1a1a1a;
  padding: 16px;
  border-radius: var(--radius);
  font-size: 13px;
  overflow-x: auto;
  white-space: pre-wrap;
  line-height: 1.6;
  border: 1px solid var(--border);
}
.code-snippet mark {
  background: #fde68a;
  color: #92400e;
  padding: 1px 3px;
  border-radius: 3px;
  font-weight: 600;
}

/* ── API endpoint cards ───────────────────────────────────────────────── */
.api-endpoint {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
}
.api-endpoint:last-child { margin-bottom: 0; }
.api-endpoint-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.api-endpoint-method {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  font-family: var(--font-mono, monospace);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.api-endpoint-method.get { background: #dcfce7; color: #166534; }
.api-endpoint-method.post { background: #dbeafe; color: #1e40af; }
.api-endpoint-method.patch { background: #fef3c7; color: #92400e; }
.api-endpoint-method.delete { background: #fee2e2; color: #991b1b; }
.api-endpoint-path {
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-mono, monospace);
  color: var(--text);
}
.api-endpoint-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.5;
}
.api-endpoint pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  line-height: 1.5;
  margin: 0;
}

/* ── KB bar ────────────────────────────────────────────────────────────── */
.kb-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

/* ── KB selector ───────────────────────────────────────────────────────── */
.kb-selector {
  padding: 10px 14px;
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 700;
  background: var(--card);
  color: var(--text);
  flex: 1;
  min-width: 0;
}

/* ── KB counter ────────────────────────────────────────────────────────── */
.kb-counter {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  padding: 4px 10px;
  background: #f0f0f0;
  border-radius: 20px;
  font-weight: 500;
}

/* ── Billing ───────────────────────────────────────────────────────────── */
.billing-overview {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
.billing-kpi {
  text-align: center;
  padding: 24px 16px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #f0f0ff 0%, #f8f8ff 100%);
  border: 1px solid rgba(99,102,241,.12);
}
.billing-kpi-value {
  display: block;
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.1;
}
.billing-kpi-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.billing-kb-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.billing-kb-name {
  font-weight: 600;
  font-size: 14px;
}
.billing-kb-meta {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Analytics ──────────────────────────────────────────────────────────── */
.analytics-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.analytics-period-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  color: var(--text-muted);
}
.analytics-period-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.analytics-period-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.analytics-kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
.analytics-kpi {
  text-align: center;
  padding: 24px 16px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #f0f0ff 0%, #f8f8ff 100%);
  border: 1px solid rgba(99,102,241,.12);
}
.analytics-kpi-value {
  display: block;
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.1;
}
.analytics-kpi-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.analytics-kpi-missed .analytics-kpi-value {
  color: var(--danger);
}
.analytics-kpi-missed {
  background: linear-gradient(135deg, #fff5f5 0%, #fff8f8 100%);
  border-color: rgba(239,68,68,.12);
}
.analytics-line-chart {
  position: relative;
  width: 100%;
}
.analytics-line-chart svg {
  display: block;
  width: 100%;
  height: auto;
}
.analytics-source-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.analytics-source-name {
  width: 140px;
  min-width: 140px;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.analytics-source-bar-wrap {
  flex: 1;
  height: 20px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
}
.analytics-source-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width .3s;
}
.analytics-source-count {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 30px;
  text-align: right;
}

/* ── Conversation rows (expandable) ────────────────────────────────────── */
.convo-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: pointer;
  transition: box-shadow .15s;
}
.convo-row:hover {
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.convo-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
}
.convo-time {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 130px;
}
.convo-question {
  flex: 1;
  font-size: 13px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.convo-chevron::after {
  content: "\25B8";
  font-size: 12px;
  color: var(--text-muted);
  transition: transform .2s;
}
.convo-row.expanded .convo-chevron::after {
  transform: rotate(90deg);
}
.convo-detail {
  display: none;
  padding: 0 14px 12px;
  border-top: 1px solid var(--border);
}
.convo-row.expanded .convo-detail {
  display: block;
}
.convo-detail-row {
  font-size: 13px;
  line-height: 1.6;
  padding: 4px 0;
  word-break: break-word;
}
.convo-detail-row strong {
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 4px;
}

/* ── Chat Messages (analytics) ────────────────────────────────────────── */
.chat-msg {
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}
.chat-msg-user {
  background: #eef2ff;
  border-left: 3px solid #6366f1;
}
.chat-msg-bot {
  background: #f3f4f6;
  border-left: 3px solid #9ca3af;
}
.chat-msg strong {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .3px;
  display: block;
  margin-bottom: 2px;
}
.chat-msg-user strong { color: #6366f1; }
.chat-msg-bot strong { color: #6b7280; }

/* ── Excess KB Overlay ─────────────────────────────────────────────────── */
.excess-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6); z-index: 9999;
  display: flex; align-items: center; justify-content: center;
}
.excess-modal {
  background: var(--card); border-radius: 12px;
  padding: 32px; max-width: 480px; width: 90%; max-height: 80vh; overflow-y: auto;
}
.excess-modal h2 { margin: 0 0 12px; }
.excess-modal p { color: var(--text-muted); margin-bottom: 20px; }
.excess-kb-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 8px; cursor: pointer;
}
.excess-kb-item:hover { border-color: var(--primary); }
.excess-kb-item input[type="checkbox"] { width: 18px; height: 18px; }
#excess-delete-btn { width: 100%; margin-top: 16px; padding: 12px; }

/* ── Usage Bars ────────────────────────────────────────────────────────── */
.usage-bar-wrap {
  margin-bottom: 12px;
}
.usage-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text);
}
.usage-bar-label span:last-child {
  color: var(--text-muted);
}
.usage-bar-track {
  height: 8px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
}
.usage-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .3s;
}

/* ── Upgrade Prompt ───────────────────────────────────────────────────── */
.upgrade-prompt {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: linear-gradient(135deg, #f0f0ff 0%, #f8f8ff 100%);
  border: 1px solid rgba(99,102,241,.15);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.upgrade-prompt-icon {
  font-size: 24px;
  flex-shrink: 0;
}
.upgrade-prompt-text {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}
.upgrade-prompt-text strong {
  color: var(--primary);
}

/* ── Tier-gated hidden state ──────────────────────────────────────────── */
.tier-hidden {
  display: none !important;
}

/* ── Mobile responsive ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-header {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .app-header h1 { font-size: 16px; }
  .header-right { gap: 8px; }
  .user-email { font-size: 12px; }

  .container { padding: 16px 12px; }

  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tab-btn {
    padding: 8px 14px;
    font-size: 13px;
    white-space: nowrap;
  }

  .card { padding: 14px; }
  .dropzone { padding: 24px 16px; }

  .doc-table { font-size: 12px; }
  .doc-table th,
  .doc-table td { padding: 8px 6px; }
  .doc-table td code { font-size: 11px; word-break: break-all; }

  .doc-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .status-grid {
    grid-template-columns: 1fr;
  }

  .chat-preview-header { padding: 10px 12px; }
  .chat-preview-header h3 { font-size: 13px; }
  .chat-preview-body { height: 300px; }

  .btn { padding: 6px 12px; font-size: 13px; }
  .btn-sm { padding: 4px 8px; font-size: 12px; }

  .auth-card { padding: 20px 16px; margin: 0 12px; }
  .auth-gate-body { min-height: calc(100vh - 50px); }

  .response-form textarea { min-height: 60px; }
  .upload-form textarea { min-height: 80px; }

  .kb-bar { flex-wrap: wrap; }
  .kb-selector { width: 100%; flex: none; }

  .billing-overview { grid-template-columns: 1fr 1fr; }
  .analytics-controls { flex-wrap: wrap; }
  .analytics-kpi-grid { grid-template-columns: 1fr; }
  .analytics-source-name { width: 100px; min-width: 100px; font-size: 12px; }
  .convo-time { min-width: 0; font-size: 11px; }
  .convo-summary { gap: 6px; padding: 8px 10px; }
}

/* ── Business Info Form ─────────────────────────────────────────────────── */
.biz-label {
  font-size: 13px;
  font-weight: 600;
  display: block;
  margin-bottom: 4px;
}
.biz-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  line-height: 1.5;
}
.biz-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}
.biz-input::placeholder { color: #9ca3af; }
