/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f5f7fa; --surface: #ffffff; --border: #e2e8f0;
  --text: #1a202c; --text-secondary: #64748b; --text-muted: #94a3b8;
  --primary: #3b82f6; --primary-hover: #2563eb; --primary-light: #eff6ff;
  --success: #10b981; --warning: #f59e0b; --danger: #ef4444;
  --sidebar-bg: #1e293b; --sidebar-text: #cbd5e1; --sidebar-active: #3b82f6;
  --radius: 8px; --shadow: 0 1px 3px rgba(0,0,0,.1);
}
html { font-size: 14px; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }

/* ── Layout ──────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; z-index: 10;
}
.sidebar-brand { padding: 20px; font-size: 1.1rem; font-weight: 700; color: #fff; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 20px;
  color: var(--sidebar-text); font-size: .93rem; transition: all .15s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav a.active { background: var(--sidebar-active); color: #fff; border-radius: 0; }
.sidebar-nav .nav-section { padding: 16px 20px 6px; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.1); font-size: .85rem; }
.sidebar-footer .user-email { color: #fff; font-weight: 500; }
.sidebar-footer button { background: none; border: none; color: var(--sidebar-text); cursor: pointer; font-size: .85rem; margin-top: 4px; }
.sidebar-footer button:hover { color: #fff; }
.main { margin-left: 240px; flex: 1; padding: 24px 32px; min-width: 0; }

/* ── Page Header ─────────────────────────────────────────── */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; }

/* ── Cards & Stat Grid ───────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat-card .label { font-size: .8rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-size: 1.8rem; font-weight: 700; margin-top: 4px; }
.stat-card .sub { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); margin-bottom: 20px; }
.card h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 16px; }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
thead th { text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--border); color: var(--text-secondary); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: var(--primary-light); }
tbody tr { cursor: pointer; }

/* ── Badges ──────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: .78rem; font-weight: 600; }
.badge-active, .badge-confirmed, .badge-paid { background: #d1fae5; color: #065f46; }
.badge-ended, .badge-completed, .badge-delivered { background: #e0e7ff; color: #3730a3; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-cancelled, .badge-suspended, .badge-refunded { background: #fee2e2; color: #991b1b; }
.badge-owner { background: #dbeafe; color: #1e40af; }
.badge-admin { background: #ede9fe; color: #5b21b6; }
.badge-member, .badge-viewer { background: #f1f5f9; color: #475569; }

/* ── Forms & Inputs ──────────────────────────────────────── */
input, select, textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: .9rem; font-family: inherit; background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
textarea { resize: vertical; min-height: 80px; }
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; color: var(--text-secondary); }
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { display: flex; gap: 8px; margin-top: 20px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
  border: none; border-radius: var(--radius); font-size: .9rem; font-weight: 500;
  cursor: pointer; transition: all .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 4px 10px; font-size: .82rem; }

/* ── Toolbar / Filters ───────────────────────────────────── */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }

/* ── Transcript ──────────────────────────────────────────── */
.transcript { max-height: 500px; overflow-y: auto; }
.turn { padding: 10px 14px; margin-bottom: 6px; border-radius: var(--radius); }
.turn-user { background: #eff6ff; margin-left: 40px; }
.turn-assistant { background: #f0fdf4; margin-right: 40px; }
.turn-system { background: #fefce8; font-size: .85rem; font-style: italic; }
.turn .role { font-size: .75rem; font-weight: 700; text-transform: uppercase; margin-bottom: 2px; color: var(--text-secondary); }

/* ── Detail View ─────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.detail-item .label { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; }
.detail-item .value { font-weight: 500; }
.back-link { display: inline-flex; align-items: center; gap: 4px; font-size: .85rem; margin-bottom: 16px; color: var(--text-secondary); }
.back-link:hover { color: var(--primary); }

/* ── Config ──────────────────────────────────────────────── */
.config-section { border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.config-section h3 { font-size: 1rem; margin-bottom: 4px; }
.config-section .desc { font-size: .82rem; color: var(--text-muted); margin-bottom: 12px; }

/* ── Login Page ──────────────────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--sidebar-bg); }
.login-box { background: var(--surface); border-radius: 12px; padding: 40px; width: 100%; max-width: 420px; box-shadow: 0 4px 24px rgba(0,0,0,.2); }
.login-box h1 { text-align: center; margin-bottom: 8px; }
.login-box .subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 24px; font-size: .9rem; }
.login-box .toggle { text-align: center; margin-top: 16px; font-size: .85rem; }
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: .85rem; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #d1fae5; color: #065f46; }

/* ── Nav Icons ──────────────────────────────────────────── */
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; stroke: currentColor; }

/* ── Loading / Empty ─────────────────────────────────────── */
.loading { text-align: center; padding: 40px; color: var(--text-muted); }
.loading-spinner {
  display: inline-block; width: 32px; height: 32px;
  border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite;
}
.loading-spinner.sm { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading .loading-spinner { margin-bottom: 12px; }
.empty { text-align: center; padding: 40px; color: var(--text-muted); }
.empty-icon { font-size: 2.5rem; margin-bottom: 8px; opacity: .5; }
.empty-msg { font-size: .95rem; }
.empty-sub { font-size: .82rem; margin-top: 4px; }

/* ── Toast Notifications ────────────────────────────────── */
.toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  pointer-events: auto; padding: 12px 20px; border-radius: var(--radius);
  font-size: .88rem; font-weight: 500; color: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.18);
  animation: toastIn .3s ease-out; min-width: 260px; max-width: 400px;
  display: flex; align-items: center; gap: 8px;
}
.toast.removing { animation: toastOut .25s ease-in forwards; }
.toast-success { background: #059669; }
.toast-error { background: #dc2626; }
.toast-info { background: #2563eb; }
.toast-icon { font-size: 1.1rem; flex-shrink: 0; }
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(40px); } }

/* ── Pagination ─────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 12px; margin-top: 16px; font-size: .85rem; color: var(--text-secondary); }
.pagination .btn:disabled { opacity: .4; cursor: not-allowed; }
.pagination .page-info { flex: 1; text-align: center; }

/* ── Billing Page ───────────────────────────────────────── */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin-bottom: 24px; }
.plan-card {
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
  padding: 24px; text-align: center; transition: border-color .2s, box-shadow .2s;
}
.plan-card:hover { border-color: var(--primary); box-shadow: 0 4px 12px rgba(59,130,246,.12); }
.plan-card.current { border-color: var(--primary); background: var(--primary-light); }
.plan-card .plan-name { font-size: 1.1rem; font-weight: 700; margin-bottom: 4px; }
.plan-card .plan-price { font-size: 1.8rem; font-weight: 700; color: var(--primary); margin-bottom: 12px; }
.plan-card .plan-price span { font-size: .85rem; font-weight: 400; color: var(--text-muted); }
.plan-card .plan-features { list-style: none; text-align: left; margin-bottom: 16px; }
.plan-card .plan-features li { padding: 4px 0; font-size: .85rem; color: var(--text-secondary); }
.plan-card .plan-features li::before { content: "\2713 "; color: var(--success); font-weight: 700; margin-right: 4px; }
.usage-bar-wrap { margin-bottom: 16px; }
.usage-bar-label { display: flex; justify-content: space-between; font-size: .82rem; color: var(--text-secondary); margin-bottom: 4px; }
.usage-bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.usage-bar-fill { height: 100%; border-radius: 4px; background: var(--primary); transition: width .4s ease; }
.usage-bar-fill.warning { background: var(--warning); }
.usage-bar-fill.danger { background: var(--danger); }

/* ── Knowledge Base Page ────────────────────────────────── */
.kb-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }
.kb-result { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; }
.kb-result .kb-result-q { font-weight: 600; margin-bottom: 4px; }
.kb-result .kb-result-a { font-size: .88rem; color: var(--text-secondary); }
.kb-result .kb-result-score { font-size: .78rem; color: var(--text-muted); margin-top: 4px; }
.kb-stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }

/* ── Analytics Page ─────────────────────────────────────── */
.analytics-chart { margin-bottom: 24px; }
.analytics-chart h3 { font-size: .95rem; font-weight: 600; margin-bottom: 12px; }
.bar-chart-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.bar-chart-label { width: 120px; font-size: .82rem; color: var(--text-secondary); text-align: right; flex-shrink: 0; }
.bar-chart-bar { flex: 1; height: 24px; background: var(--border); border-radius: 4px; overflow: hidden; position: relative; }
.bar-chart-fill { height: 100%; border-radius: 4px; background: var(--primary); transition: width .4s ease; display: flex; align-items: center; padding-left: 8px; }
.bar-chart-fill span { font-size: .75rem; color: #fff; font-weight: 600; white-space: nowrap; }
.bar-chart-value { width: 50px; font-size: .82rem; font-weight: 600; flex-shrink: 0; }
.sparkline { display: flex; align-items: flex-end; gap: 2px; height: 60px; }
.sparkline-bar { flex: 1; background: var(--primary); border-radius: 2px 2px 0 0; min-width: 4px; transition: height .3s ease; opacity: .7; }
.sparkline-bar:hover { opacity: 1; }
.top-intents-list { list-style: none; }
.top-intents-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .88rem; }
.top-intents-list li:last-child { border-bottom: none; }
.top-intents-list .intent-name { font-weight: 500; }
.top-intents-list .intent-count { color: var(--text-muted); }
.analytics-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ── Onboarding Banner ──────────────────────────────────── */
.onboarding-banner {
  background: linear-gradient(135deg, #eff6ff 0%, #e0e7ff 100%);
  border: 1px solid #bfdbfe; border-radius: var(--radius);
  padding: 20px 24px; margin-bottom: 24px;
}
.onboarding-banner .ob-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.onboarding-banner .ob-title { font-size: 1rem; font-weight: 700; color: var(--text); }
.onboarding-banner .ob-progress { font-size: .82rem; color: var(--text-secondary); }
.onboarding-banner .ob-dismiss { font-size: .82rem; color: var(--text-muted); cursor: pointer; border: none; background: none; }
.onboarding-banner .ob-dismiss:hover { color: var(--primary); }
.ob-progress-bar { height: 6px; background: #dbeafe; border-radius: 3px; overflow: hidden; margin-bottom: 16px; }
.ob-progress-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width .4s ease; }
.ob-steps { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.ob-step { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: var(--radius); background: rgba(255,255,255,.6); font-size: .85rem; }
.ob-step.complete { color: var(--success); }
.ob-step.complete .ob-check { color: var(--success); }
.ob-step .ob-check { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: .7rem; flex-shrink: 0; }
.ob-step.complete .ob-check { border-color: var(--success); background: #d1fae5; }
.ob-step .ob-mark-btn { margin-left: auto; font-size: .75rem; padding: 2px 8px; }

/* ── Audio Player ───────────────────────────────────────── */
.audio-player-inline { margin-top: 6px; }
.audio-player-inline audio { height: 32px; width: 260px; }
.play-btn { background: none; border: 1px solid var(--primary); color: var(--primary); padding: 2px 10px; border-radius: var(--radius); font-size: .78rem; cursor: pointer; }
.play-btn:hover { background: var(--primary-light); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-brand, .sidebar-nav a span, .sidebar-nav .nav-section, .sidebar-footer .user-email { display: none; }
  .sidebar-nav a { justify-content: center; padding: 12px; }
  .main { margin-left: 60px; padding: 16px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .kb-grid { grid-template-columns: 1fr; }
  .analytics-two-col { grid-template-columns: 1fr; }
  .plan-grid { grid-template-columns: 1fr; }
  .ob-steps { grid-template-columns: 1fr; }
}
