/* ============================================================
   Companions — Main Stylesheet
   ============================================================ */

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

:root {
  --primary:       #6366f1;
  --primary-dark:  #4f46e5;
  --primary-light: #818cf8;
  --sidebar-bg:    #0f0f23;
  --sidebar-hover: #1a1a3e;
  --sidebar-active:#252550;
  --bg:            #f1f5f9;
  --surface:       #ffffff;
  --border:        #e2e8f0;
  --text:          #0f172a;
  --text-muted:    #64748b;
  --text-light:    #94a3b8;
  --success:       #10b981;
  --warning:       #f59e0b;
  --danger:        #ef4444;
  --info:          #3b82f6;
  --surface-2:     #f8fafc;
  --radius:        8px;
  --radius-lg:     12px;
  --shadow:        0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:     0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --shadow-lg:     0 10px 25px rgba(0,0,0,.1), 0 4px 10px rgba(0,0,0,.06);
  --transition:    150ms ease;
}

html, body { height: 100%; font-family: 'Inter', system-ui, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App Shell ─────────────────────────────────────────────── */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.sidebar-logo-text {
  font-size: 15px; font-weight: 700;
  color: #fff; letter-spacing: -.3px;
}

.sidebar-section-label {
  font-size: 10px; font-weight: 600; letter-spacing: .8px;
  text-transform: uppercase; color: rgba(255,255,255,.3);
  padding: 16px 16px 6px;
}

.sidebar-assistants {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}
.sidebar-assistants::-webkit-scrollbar { width: 4px; }
.sidebar-assistants::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

.assistant-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  color: rgba(255,255,255,.75);
  transition: background var(--transition);
  user-select: none;
}
.assistant-item:hover    { background: var(--sidebar-hover); color: #fff; }
.assistant-item.active   { background: var(--sidebar-active); color: #fff; }

.assistant-avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}

.assistant-info { flex: 1; min-width: 0; }
.assistant-name {
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.assistant-role {
  font-size: 11px; color: rgba(255,255,255,.4);
  text-transform: capitalize;
}

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid rgba(255,255,255,.06);
}

.btn-new-assistant {
  width: 100%;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px dashed rgba(99,102,241,.5);
  background: rgba(99,102,241,.08);
  color: var(--primary-light);
  font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all var(--transition);
}
.btn-new-assistant:hover {
  background: rgba(99,102,241,.18);
  border-color: var(--primary-light);
}

.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px 0;
  margin-top: 8px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.sidebar-user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.sidebar-user-name {
  flex: 1; min-width: 0;
  font-size: 12px; color: rgba(255,255,255,.65);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-logout {
  background: none; border: none;
  color: rgba(255,255,255,.3);
  cursor: pointer; padding: 4px;
  border-radius: 4px;
  transition: color var(--transition);
}
.sidebar-user-logout:hover { color: var(--danger); }
.sidebar-user-settings {
  background: none; border: none;
  color: rgba(255,255,255,.3);
  cursor: pointer; padding: 4px;
  border-radius: 4px;
  transition: color var(--transition);
}
.sidebar-user-settings:hover { color: rgba(255,255,255,.8); }

/* ── Account Settings Full Page ────────────────────────────── */
.acct-page { display: flex; flex-direction: column; height: 100%; overflow: hidden; background: var(--bg); }
.acct-page-header {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.acct-page-title { font-size: 15px; font-weight: 700; color: var(--text); }
.acct-page-body { display: flex; flex: 1; overflow: hidden; }
.acct-nav {
  width: 196px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 14px 8px;
  background: var(--surface);
  display: flex; flex-direction: column; gap: 2px;
}
.acct-nav-item {
  padding: 9px 13px; border-radius: 8px;
  font-size: 13px; font-weight: 500; color: var(--text-muted);
  cursor: pointer; transition: all var(--transition);
  display: flex; align-items: center; gap: 9px;
}
.acct-nav-item:hover { background: var(--bg); color: var(--text); }
.acct-nav-item.active { background: rgba(99,102,241,.08); color: var(--primary); font-weight: 600; }
.acct-content { flex: 1; overflow-y: auto; padding: 28px 32px; }
.acct-card {
  max-width: 580px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  margin-bottom: 20px;
}
.acct-card-title {
  font-size: 14px; font-weight: 700; color: var(--text);
  margin-bottom: 18px; padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.acct-card-desc { font-size: 12px; color: var(--text-muted); margin-top: -10px; margin-bottom: 16px; line-height: 1.5; }
.totp-status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 20px;
}
.totp-status.on  { background: #dcfce7; color: #16a34a; }
.totp-status.off { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.totp-qr { display: block; margin: 0 auto 16px; width: 176px; height: 176px; border-radius: 10px; border: 1px solid var(--border); }
.totp-secret-box {
  font-family: monospace; font-size: 13px; letter-spacing: 2px; word-break: break-all;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; color: var(--text);
}

/* ── Main Area ─────────────────────────────────────────────── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}


/* ── Tab Content ───────────────────────────────────────────── */
.tab-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ── Welcome Screen ────────────────────────────────────────── */
.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-muted);
}
.welcome-screen-icon {
  font-size: 52px;
  opacity: .6;
}
.welcome-screen h2 {
  font-size: 20px; font-weight: 600; color: var(--text);
}
.welcome-screen p {
  font-size: 14px; color: var(--text-muted); text-align: center;
  max-width: 340px; line-height: 1.6;
}

/* ── Email Agent Layout ────────────────────────────────────── */
.email-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.email-sidebar {
  width: 200px;
  min-width: 200px;
  background: #fafbfc;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px 0;
  overflow-y: auto;
}

.email-sidebar-section {
  padding: 4px 8px;
  margin-bottom: 4px;
}
.email-folder {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
}
.email-folder:hover  { background: var(--border); color: var(--text); }
.email-folder.active { background: rgba(99,102,241,.1); color: var(--primary); font-weight: 500; }
.email-folder-badge {
  margin-left: auto;
  background: var(--primary);
  color: #fff;
  font-size: 10px; font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px; text-align: center;
}

.email-center {
  width: 300px;
  min-width: 260px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}

.email-toolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.email-list {
  flex: 1;
  overflow-y: auto;
}
.email-list::-webkit-scrollbar { width: 4px; }
.email-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.email-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}
.email-item:hover    { background: #f8fafc; }
.email-item.active   { background: rgba(99,102,241,.06); border-left: 3px solid var(--primary); }
.email-item.unread   { background: #f0f4ff; }
.email-item.unread .email-item-subject { font-weight: 600; }
.email-item-from    { font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 3px; display: flex; justify-content: space-between; }
.email-item-subject { font-size: 12px; color: var(--text); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.email-item-date    { font-size: 11px; color: var(--text-light); }
.email-item-dot {
  width: 7px; height: 7px;
  border-radius: 50%; background: var(--primary);
  position: absolute; top: 14px; right: 14px;
}

.email-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

.email-view {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  min-height: 0;
}
.email-view::-webkit-scrollbar { width: 4px; }
.email-view::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.email-view-header {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.email-view-subject { font-size: 18px; font-weight: 600; margin-bottom: 10px; line-height: 1.3; }
.email-view-meta    { font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; gap: 3px; }
.email-view-actions { display: flex; gap: 8px; margin-top: 12px; }
.email-view-body    { line-height: 1.7; font-size: 14px; }
.email-view-body iframe { width: 100%; min-height: 300px; border: none; }

.email-empty {
  height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-muted); gap: 10px;
  font-size: 13px;
}
.email-empty-icon { font-size: 36px; opacity: .4; }

/* ── AI Panel ──────────────────────────────────────────────── */
.ai-panel {
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: #fafbfc;
  overflow: hidden;
  min-height: 260px;
  max-height: 42%;
}

.ai-panel-header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 600;
  background: var(--surface);
  flex-shrink: 0;
}
.ai-panel-avatar {
  width: 26px; height: 26px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}

.ai-panel-actions {
  display: flex; gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
  background: var(--surface);
}

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-messages::-webkit-scrollbar { width: 4px; }
.ai-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.ai-bubble {
  max-width: 90%;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}
.ai-bubble.user {
  background: var(--primary);
  color: #fff;
  margin-left: auto;
  border-bottom-right-radius: 3px;
}
.ai-bubble.assistant {
  background: var(--surface);
  border: 1px solid var(--border);
  margin-right: auto;
  border-bottom-left-radius: 3px;
}
.ai-bubble.thinking {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-style: italic;
}

.ai-input-bar {
  display: flex; gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.ai-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  outline: none;
  resize: none;
  height: 36px;
  max-height: 100px;
  overflow: hidden;
  line-height: 1.4;
  font-family: inherit;
  transition: border-color var(--transition);
}
.ai-input:focus { border-color: var(--primary); }

/* ── Email Config Setup ────────────────────────────────────── */
.setup-screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 40px 20px;
  overflow-y: auto;
}
.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 600px;
  box-shadow: var(--shadow-md);
}
.setup-card h2 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.setup-card p  { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }

.config-section {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.config-section h3 {
  font-size: 13px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 12px;
}

/* ── Compose Modal ─────────────────────────────────────────── */
.compose-area {
  display: flex; flex-direction: column; gap: 10px;
}
.compose-field {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.compose-label {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  width: 60px; flex-shrink: 0;
}
.compose-body {
  width: 100%;
  min-height: 240px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  outline: none;
  line-height: 1.6;
  transition: border-color var(--transition);
}
.compose-body:focus { border-color: var(--primary); }

/* ── Auth Pages ────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f0f23 0%, #1a1a3e 50%, #0f0f23 100%);
  padding: 20px;
}
.auth-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 28px;
}
.auth-logo-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.auth-logo-text { font-size: 18px; font-weight: 800; color: var(--text); letter-spacing: -.4px; }
.auth-title    { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.auth-subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-row   { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

.form-label {
  display: block;
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .4px;
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.form-control[disabled] { background: #f8fafc; color: var(--text-muted); }
textarea.form-control   { resize: vertical; min-height: 80px; }
.form-hint { font-size: 11px; color: var(--text-light); margin-top: 4px; }
.char-counter {
  font-size: 11px; color: var(--text-light);
  text-align: right; margin-top: 3px;
}
.char-counter.warning { color: var(--warning); }
.char-counter.error   { color: var(--danger); }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  border: none; cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }
.btn-icon { padding: 7px; border-radius: var(--radius); }

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

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

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

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #059669; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-outline.active-range { border-color: var(--primary); color: var(--primary); background: var(--primary-pale, rgba(124,58,237,.08)); font-weight: 600; }

.w-full { width: 100%; }

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 14px;
  border-left: 3px solid transparent;
}
.alert-error   { background: #fef2f2; color: #991b1b; border-color: var(--danger); }
.alert-success { background: #f0fdf4; color: #14532d; border-color: var(--success); }
.alert-info    { background: #eff6ff; color: #1e3a8a; border-color: var(--info); }
.alert-warning { background: #fffbeb; color: #78350f; border-color: var(--warning); }

/* ── Modals ────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  animation: slideUp .2s ease;
}
.modal-lg { max-width: 680px; }
.modal-xl { max-width: 860px; }
.modal-header {
  display: flex; align-items: center;
  padding: 20px 24px 0;
  gap: 12px;
}
.modal-header h2 { font-size: 17px; font-weight: 700; flex: 1; }
.modal-close {
  width: 28px; height: 28px;
  border-radius: var(--radius);
  border: none; background: none;
  color: var(--text-muted);
  cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);
}
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body   { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
}

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

/* ── Tabs within modal/settings ───────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}
.tab-btn {
  padding: 8px 16px;
  font-size: 13px; font-weight: 500;
  color: var(--text-muted);
  background: none; border: none; cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color var(--transition), border-color var(--transition);
}
.tab-btn:hover  { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; }

/* ── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600;
  text-transform: capitalize;
}
.badge-purple  { background: rgba(99,102,241,.1);  color: var(--primary); }
.badge-green   { background: rgba(16,185,129,.1);  color: var(--success); }
.badge-red     { background: rgba(239,68,68,.1);   color: var(--danger); }
.badge-yellow  { background: rgba(245,158,11,.1);  color: var(--warning); }
.badge-gray    { background: rgba(100,116,139,.1); color: var(--text-muted); }

/* ── Toast Notifications ───────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideInRight .25s ease;
  max-width: 320px;
  display: flex; align-items: center; gap: 8px;
}
.toast-success { background: #1a2e22; color: #4ade80; }
.toast-error   { background: #2e1a1a; color: #f87171; }
.toast-warning { background: #2e2210; color: #fbbf24; }
.toast-info    { background: #1a1f2e; color: #93c5fd; }

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ── Sysadmin specific ─────────────────────────────────────── */
.sysadmin-layout {
  display: flex;
  min-height: 100vh;
  background: #f8fafc;
}
.sysadmin-sidebar {
  width: 220px; min-width: 220px;
  background: var(--sidebar-bg);
  color: rgba(255,255,255,.8);
  display: flex; flex-direction: column;
  padding: 20px 0;
}
.sysadmin-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background var(--transition);
  font-size: 13px;
}
.sysadmin-nav-item:hover  { background: var(--sidebar-hover); }
.sysadmin-nav-item.active { background: var(--sidebar-active); color: #fff; }
.sysadmin-content { flex: 1; padding: 28px; overflow-y: auto; }
.sysadmin-header { margin-bottom: 24px; }
.sysadmin-header h1 { font-size: 22px; font-weight: 700; }
.sysadmin-stats  { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card       { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; text-align: center; }
.stat-card-value { font-size: 28px; font-weight: 800; color: var(--primary); }
.stat-card-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Tables ────────────────────────────────────────────────── */
.table-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  padding: 11px 16px;
  background: #f8fafc;
  text-align: left;
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

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

.loading-overlay {
  height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; color: var(--text-muted);
}

/* ── Emoji picker colors for avatar ───────────────────────── */
.color-swatch {
  width: 24px; height: 24px; border-radius: 6px;
  cursor: pointer; border: 2px solid transparent;
  transition: transform .1s;
}
.color-swatch:hover  { transform: scale(1.15); }
.color-swatch.active { border-color: var(--text); }
.color-swatches { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Utility ───────────────────────────────────────────────── */
.flex        { display: flex; }
.items-center { align-items: center; }
.gap-2       { gap: 8px; }
.gap-3       { gap: 12px; }
.flex-1      { flex: 1; }
.ml-auto     { margin-left: auto; }
.text-muted  { color: var(--text-muted); }
.text-small  { font-size: 12px; }
.font-bold   { font-weight: 700; }
.mt-2        { margin-top: 8px; }
.mt-4        { margin-top: 16px; }
.mb-4        { margin-bottom: 16px; }
.hidden      { display: none !important; }

/* ── Knowledge Base ────────────────────────────────────────── */
.kb-layout {
  display: flex; flex-direction: column;
  height: 100%; overflow: hidden;
}
.kb-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.kb-header-info {
  display: flex; align-items: center; gap: 10px;
}
.kb-avatar {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.kb-body {
  display: flex; flex: 1; overflow: hidden; gap: 0;
}
.kb-editor-pane {
  flex: 1; display: flex; flex-direction: column;
  padding: 16px; overflow: hidden;
  border-right: 1px solid var(--border);
}
.kb-editor-pane textarea {
  flex: 1; min-height: 0;
}
.kb-info-pane {
  width: 260px; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px; overflow-y: auto;
}
/* ── AI Personality Writer Modal ──────────────────────────────── */
.pai-modal-inner {
  max-height: 82vh;
  display: flex;
  flex-direction: column;
}
.pai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
.pai-bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.pai-bubble--user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.pai-bubble--ai {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text);
}
.pai-bubble span { display: block; }
.pai-thinking {
  gap: 4px;
  flex-direction: row;
  align-items: center;
  padding: 12px 16px;
}
.pai-thinking span {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: pai-bounce .9s infinite ease-in-out;
}
.pai-thinking span:nth-child(2) { animation-delay: .15s; }
.pai-thinking span:nth-child(3) { animation-delay: .3s; }
@keyframes pai-bounce {
  0%, 80%, 100% { transform: scale(.7); opacity: .4; }
  40%            { transform: scale(1);  opacity: 1;   }
}
.pai-personality-preview {
  margin-top: 10px;
  background: #f4f4f8;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  max-height: 220px;
  overflow-y: auto;
}

.kb-info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.kb-info-card-title {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); margin-bottom: 8px;
}

/* ── KB Crawl Results Modal ───────────────────────────────────── */
.kb-crawl-item {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  transition: border-color .15s;
}
.kb-crawl-item:hover { border-color: var(--primary-light, #a78bfa); }
.kb-crawl-item--done { opacity: .55; }
.kb-crawl-item-info  { flex: 1; min-width: 0; }
.kb-crawl-item-title {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 2px;
}
.kb-crawl-item-url {
  font-size: 11px; color: var(--primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 4px;
}
.kb-crawl-item-preview {
  font-size: 12px; color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Settings Page ────────────────────────────────────────────── */
.st-layout {
  display: flex; height: 100%; overflow: hidden;
}
.st-nav {
  width: 210px; min-width: 210px; max-width: 210px; flex-shrink: 0;
  background: #fafbfc;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 12px 0;
  overflow: hidden;
}
.st-nav-header {
  padding: 0 12px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  overflow: hidden;
}
.st-nav-item {
  display: block; width: 100%; text-align: left;
  padding: 9px 16px;
  background: none; border: none; cursor: pointer;
  font-size: 13px; color: var(--text-muted);
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
}
.st-nav-item:hover { background: var(--hover); color: var(--text); }
.st-nav-item.active {
  background: rgba(99,102,241,.08);
  color: var(--primary); font-weight: 600;
  border-right: 2px solid var(--primary);
}
.st-nav-danger { color: var(--danger, #ef4444) !important; }
.st-nav-danger:hover { background: rgba(239,68,68,.06) !important; }
.st-content {
  flex: 1; overflow-y: auto; min-width: 0;
  display: flex; flex-direction: column;
}
.st-section {
  padding: 24px 28px;
  width: 100%; box-sizing: border-box;
}
.st-section-title {
  font-size: 16px; font-weight: 700;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* ── Auto Reply Logs Page ─────────────────────────────────────── */
.logs-layout {
  display: flex; flex-direction: column;
  height: 100%; overflow: hidden; position: relative;
}
.logs-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.logs-body {
  flex: 1; overflow-y: auto; min-height: 0;
}
.logs-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.logs-table thead tr {
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.logs-table th {
  padding: 9px 14px; text-align: left;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px;
  color: var(--text-muted); white-space: nowrap;
}
.logs-row { border-bottom: 1px solid var(--border); cursor: pointer; }
.logs-row:hover { background: var(--hover); }
.logs-row td { padding: 10px 14px; }
.logs-clip {
  max-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.logs-empty { padding: 32px; text-align: center; color: var(--text-muted); }
.logs-filter {
  padding: 4px 12px; border-radius: 20px; font-size: 12px;
  border: 1px solid var(--border); background: none;
  cursor: pointer; color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.logs-filter:hover { background: var(--hover); color: var(--text); }
.logs-filter.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.logs-detail {
  position: absolute; right: 0; top: 0; bottom: 0;
  width: 380px; background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  box-shadow: -4px 0 16px rgba(0,0,0,.08);
  z-index: 10;
}
.logs-detail.hidden { display: none; }
.logs-detail-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  flex-shrink: 0; gap: 8px;
}

/* ── Receptionist Agent ───────────────────────────────────────── */
.rcpt-nav-btn {
  display: block; width: 100%; text-align: left;
  padding: 7px 10px; border-radius: var(--radius);
  background: none; border: none; cursor: pointer;
  font-size: 13px; color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
  margin-bottom: 2px;
}
.rcpt-nav-btn:hover  { background: var(--border); color: var(--text); }
.rcpt-nav-btn.active { background: rgba(99,102,241,.1); color: var(--primary); font-weight: 600; }

/* Appointment card */
.appt-card {
  display: flex; align-items: flex-start; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 14px 16px;
  transition: box-shadow var(--transition);
}
.appt-card:hover { box-shadow: var(--shadow-md); }
.appt-card-time { min-width: 110px; }
.appt-date { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.appt-time { font-size: 13px; font-weight: 700; color: var(--text); margin-top: 2px; }
.appt-card-info { flex: 1; min-width: 0; }
.appt-name  { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt-email { font-size: 12px; color: var(--text-muted); }
.appt-reason { font-size: 12px; color: var(--text-muted); margin-top: 2px; font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt-card-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.appt-channel-badge { font-size: 16px; }

/* ── Receptionist Calendar View ─────────────────────────────────── */
.rcal-container { display:flex; min-height:100%; }
.rcal-left {
  width:460px; flex-shrink:0; border-right:1px solid var(--border);
  display:flex; flex-direction:column; padding:20px 16px;
}
.rcal-header {
  display:flex; align-items:center; gap:6px; margin-bottom:18px;
}
.rcal-month-label { flex:1; text-align:center; font-size:15px; font-weight:700; color:var(--text); }
.rcal-nav-btn {
  width:30px; height:30px; border-radius:8px; border:1px solid var(--border);
  background:var(--surface); cursor:pointer; font-size:17px; line-height:1;
  display:flex; align-items:center; justify-content:center;
  color:var(--text-muted); transition:all var(--transition); flex-shrink:0;
}
.rcal-nav-btn:hover { background:var(--bg); color:var(--primary); border-color:var(--primary-light); }
.rcal-today-btn {
  font-size:11px; font-weight:600; padding:4px 11px; border-radius:20px;
  border:1.5px solid var(--border); background:var(--surface); cursor:pointer;
  color:var(--text-muted); transition:all var(--transition); flex-shrink:0;
}
.rcal-today-btn:hover { border-color:var(--primary); color:var(--primary); }
.rcal-grid-header {
  display:grid; grid-template-columns:repeat(7,1fr); margin-bottom:4px;
}
.rcal-dow {
  text-align:center; font-size:10px; font-weight:700; letter-spacing:.06em;
  text-transform:uppercase; color:var(--text-muted); padding:3px 0;
}
.rcal-grid { display:grid; grid-template-columns:repeat(7,1fr); gap:3px; }
.rcal-cell {
  min-height:74px; border-radius:10px; border:1.5px solid transparent;
  padding:6px; cursor:pointer; transition:all var(--transition);
  background:var(--surface); position:relative;
}
.rcal-cell-empty { background:transparent; cursor:default; pointer-events:none; }
.rcal-cell:not(.rcal-cell-empty):hover { background:var(--bg); border-color:var(--border); }
.rcal-cell.rcal-has-appts:hover { border-color:rgba(99,102,241,.35); }
.rcal-cell.rcal-past { opacity:.38; }
.rcal-cell.rcal-selected { border-color:var(--primary); background:rgba(99,102,241,.05); box-shadow:0 0 0 1px rgba(99,102,241,.15); }
.rcal-day-num {
  width:22px; height:22px; border-radius:50%; display:flex;
  align-items:center; justify-content:center; font-size:12px;
  font-weight:600; color:var(--text); margin-bottom:4px;
}
.rcal-cell.rcal-today .rcal-day-num { background:var(--primary); color:#fff; }
.rcal-cell.rcal-selected.rcal-today .rcal-day-num { background:var(--primary-dark); }
.rcal-chips { display:flex; flex-direction:column; gap:2px; }
.rcal-chip {
  font-size:10px; font-weight:500; padding:2px 5px; border-radius:4px;
  background:rgba(99,102,241,.1); color:var(--primary);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; line-height:1.4;
}
.rcal-chip-more { background:var(--bg); color:var(--text-muted); }
.rcal-right { flex:1; min-width:0; overflow-y:auto; }
.rcal-detail-header {
  padding:20px 20px 14px; border-bottom:1px solid var(--border);
  display:flex; align-items:baseline; gap:10px; position:sticky; top:0;
  background:var(--surface); z-index:1;
}
.rcal-detail-title { font-weight:700; font-size:15px; }
.rcal-detail-count { font-size:12px; color:var(--text-muted); }
.rcal-detail-empty {
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  min-height:300px; color:var(--text-muted); font-size:13px; gap:10px;
  padding:40px; text-align:center;
}
.rcal-detail-empty-icon { font-size:36px; opacity:.5; }
.rcal-appt-list { display:flex; flex-direction:column; gap:10px; padding:16px 20px; }

/* Calendar provider cards */
.cal-provider-card.selected,
.cal-provider-card:hover { background: rgba(99,102,241,.06); }

/* Day chips */
.day-chip {
  display: inline-block; padding: 4px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  border: 1.5px solid var(--border); color: var(--text-muted);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.day-chip.selected {
  background: var(--primary); color: #fff; border-color: var(--primary);
}

/* Surface-2 utility */
.surface-2, [style*="--surface-2"] { background: var(--bg); }

/* ── Live Support Agent ───────────────────────────────────────── */
.supp-session-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 14px 16px; cursor: pointer;
  transition: box-shadow var(--transition), border-color var(--transition);
}
.supp-session-card:hover { box-shadow: var(--shadow-md); border-color: var(--primary-light, #a78bfa); }

.supp-status-badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: .03em; text-transform: capitalize;
}
.supp-status-active   { background: rgba(16,185,129,.12); color: #059669; }
.supp-status-resolved { background: rgba(100,116,139,.12); color: var(--text-muted); }

/* ── Widget Customizer ──────────────────────────────────────────────────── */
.wc-container { display:flex;flex-direction:column;height:100%;overflow:hidden }
.wc-header { display:flex;align-items:center;gap:12px;padding:14px 20px;border-bottom:1px solid var(--border);flex-shrink:0;background:var(--surface) }
.wc-header-title { flex:1;font-weight:700;font-size:14px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap }
.wc-body { display:flex;flex:1;overflow:hidden }
.wc-controls { width:400px;flex-shrink:0;overflow-y:auto;padding:20px;border-right:1px solid var(--border) }
.wc-preview-panel { flex:1;padding:24px;overflow-y:auto;background:var(--bg-muted,#f8f9fb) }
.wc-section { margin-bottom:24px }
.wc-section-label { font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.5px;color:var(--text-muted);margin-bottom:10px }
.wc-theme-grid { display:grid;grid-template-columns:repeat(4,1fr);gap:8px }
.wc-theme-swatch { border:2px solid var(--border);border-radius:10px;overflow:hidden;cursor:pointer;transition:border-color .15s }
.wc-theme-swatch:hover,.wc-theme-swatch.active { border-color:var(--primary) }
.wc-theme-swatch.active { box-shadow:0 0 0 2px var(--primary-light,rgba(124,58,237,.15)) }
.wc-swatch-color { height:36px }
.wc-swatch-label { font-size:10px;text-align:center;padding:4px 2px;background:var(--surface);color:var(--text-muted);font-weight:500 }
.wc-icon-grid { display:flex;flex-wrap:wrap;gap:6px }
.wc-icon { width:38px;height:38px;display:flex;align-items:center;justify-content:center;font-size:20px;border-radius:8px;border:2px solid var(--border);cursor:pointer;transition:.15s;user-select:none }
.wc-icon:hover { border-color:var(--primary);background:var(--primary-light,rgba(124,58,237,.08)) }
.wc-icon.active { border-color:var(--primary);background:var(--primary-light,rgba(124,58,237,.12)) }
.wc-color-row { display:flex;gap:16px }
.wc-color-item { flex:1 }
.wc-color-label { display:block;font-size:12px;color:var(--text-muted);margin-bottom:6px }
.wc-color-wrap { display:flex;align-items:center;gap:8px }
.wc-color-input { width:44px;height:36px;border:1.5px solid var(--border);border-radius:8px;padding:2px;cursor:pointer;background:none }
.wc-color-hex { font-size:12px;font-family:monospace;color:var(--text-muted) }
.wc-preview-label { font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.5px;color:var(--text-muted);margin-bottom:12px }
.wc-preview-launcher-wrap { display:flex;justify-content:flex-end;padding-right:8px }

/* Widget preview */
.wcp-widget { border-radius:14px;overflow:hidden;box-shadow:0 4px 24px rgba(0,0,0,.14);max-width:320px }
.wcp-header { display:flex;align-items:center;gap:10px;padding:12px 14px;color:#fff }
.wcp-avatar { width:34px;height:34px;border-radius:8px;background:rgba(255,255,255,.2);display:flex;align-items:center;justify-content:center;font-size:18px;flex-shrink:0;overflow:hidden }
.wcp-name { font-weight:700;font-size:13px;line-height:1.2 }
.wcp-status { font-size:10px;opacity:.8 }
.wcp-msgs { padding:12px;display:flex;flex-direction:column;gap:8px;min-height:120px }
.wcp-bubble { max-width:80%;padding:8px 11px;border-radius:12px;font-size:12px;line-height:1.5 }
.wcp-bot { align-self:flex-start;border-bottom-left-radius:3px }
.wcp-user { align-self:flex-end;color:#fff;border-bottom-right-radius:3px }
.wcp-input-row { display:flex;gap:6px;padding:10px 12px;align-items:center }
.wcp-input-box { flex:1;border:1.5px solid;border-radius:16px;padding:6px 11px;font-size:11px;color:var(--text-muted) }
.wcp-send { width:28px;height:28px;border-radius:50%;display:flex;align-items:center;justify-content:center;color:#fff;font-size:13px;flex-shrink:0 }

/* Launcher preview */
.wcp-launcher { width:52px;height:52px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:24px;box-shadow:0 4px 16px rgba(0,0,0,.2);cursor:pointer }

/* Avatar upload controls */
.wc-avatar-row { display:flex;align-items:center;gap:12px;margin-bottom:12px }
.wc-avatar-current-wrap { width:56px;height:56px;border-radius:12px;border:2px solid var(--border);overflow:hidden;display:flex;align-items:center;justify-content:center;background:var(--bg-muted,#f8f9fb);flex-shrink:0 }
.wc-avatar-thumb { width:100%;height:100%;object-fit:contain }
.wc-avatar-emoji-badge { font-size:28px;line-height:1 }
.wc-avatar-btns { display:flex;flex-direction:column;gap:4px }
.wc-upload-btn { cursor:pointer;display:inline-flex;align-items:center;gap:6px }
.wc-avatar-or { font-size:11px;color:var(--text-muted);margin:8px 0 6px;text-align:center }
.wc-icon-grid-dim .wc-icon { opacity:.4;pointer-events:none }

/* ── Analytics ─────────────────────────────────────────────────────────────── */
.an-stat-grid { display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:12px;margin-bottom:16px }
.an-stat-card {
  background:var(--surface);border:1px solid var(--border);border-top:3px solid var(--ac,var(--primary));
  border-radius:var(--radius);padding:14px 16px;display:flex;align-items:center;gap:12px;
  transition:box-shadow .2s,transform .2s;overflow:hidden;position:relative
}
.an-stat-card:hover { transform:translateY(-2px);box-shadow:var(--shadow-md) }
.an-stat-icon { width:44px;height:44px;border-radius:10px;display:flex;align-items:center;justify-content:center;font-size:20px;flex-shrink:0 }
.an-stat-body { flex:1;min-width:0 }
.an-stat-val { font-size:1.6rem;font-weight:800;color:var(--text);line-height:1;margin-bottom:3px }
.an-stat-lbl { font-size:.68rem;color:var(--text-muted);text-transform:uppercase;letter-spacing:.06em;font-weight:600 }

.an-card { background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);overflow:hidden;box-shadow:var(--shadow-sm) }
.an-card-hdr { display:flex;align-items:center;justify-content:space-between;padding:14px 16px;border-bottom:1px solid var(--border);background:linear-gradient(to right,var(--bg-muted,#f8f9fb),var(--surface)) }

.an-table { width:100%;border-collapse:collapse }
.an-table th { padding:10px 14px;font-size:.7rem;text-transform:uppercase;letter-spacing:.07em;color:var(--text-muted);font-weight:700;border-bottom:2px solid var(--border);text-align:left;background:var(--bg-muted,#f8f9fb) }
.an-table td { padding:10px 14px;border-bottom:1px solid rgba(226,232,240,.6);font-size:.88rem;color:var(--text) }
.an-table tbody tr:last-child td { border-bottom:none }
.an-table tbody tr:hover { background:rgba(99,102,241,.025) }

.an-badge { display:inline-flex;align-items:center;gap:3px;padding:.2rem .55rem;border-radius:99px;font-size:.75rem;font-weight:600;white-space:nowrap }
.an-badge-green { background:rgba(16,185,129,.1);color:#059669 }
.an-badge-blue  { background:rgba(99,102,241,.1);color:#4f46e5 }
.an-badge-gray  { background:rgba(100,116,139,.1);color:#64748b }

/* ── Billing Page ────────────────────────────────────────────────────────── */
.billing-page { max-width:720px;margin:0 auto;padding:24px }
.billing-page-header { display:flex;align-items:center;gap:12px;margin-bottom:24px }
.billing-back-btn { background:none;border:none;cursor:pointer;color:var(--text-muted);font-size:.875rem;display:flex;align-items:center;gap:6px;padding:0;transition:color .15s }
.billing-back-btn:hover { color:var(--text) }
.billing-page-title { font-size:1.25rem;font-weight:700;color:var(--text) }
.billing-page-body { display:flex;flex-direction:column;gap:16px }

.billing-card { background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-lg);padding:20px 24px }
.billing-card-title { font-size:1rem;font-weight:700;color:var(--text);margin-bottom:8px }
.billing-card-desc { font-size:.875rem;color:var(--text-muted);margin-bottom:16px;line-height:1.5 }

.billing-status-card { background:linear-gradient(135deg,#4f46e5,#7c3aed);border-radius:var(--radius-lg);padding:20px 24px;color:#fff }
.billing-status-row { display:flex;align-items:flex-start;justify-content:space-between;gap:1rem;flex-wrap:wrap;margin-bottom:16px }
.billing-status-label { font-size:.7rem;opacity:.75;text-transform:uppercase;letter-spacing:.07em;margin-bottom:4px }
.billing-status-active { display:flex;align-items:center;gap:6px;font-size:1.15rem;font-weight:700 }
.billing-status-dot { width:8px;height:8px;background:#4ade80;border-radius:50%;display:inline-block }
.billing-status-date { font-size:1rem;font-weight:700 }
.billing-status-days { font-size:.78rem;opacity:.7;margin-top:2px }
.billing-status-grid { border-top:1px solid rgba(255,255,255,.2);padding-top:14px;display:grid;grid-template-columns:repeat(auto-fit,minmax(110px,1fr));gap:12px }
.billing-stat-label { font-size:.68rem;opacity:.65;margin-bottom:3px }
.billing-stat-value { font-size:.875rem;font-weight:600 }

.billing-duration-tabs { display:flex;gap:8px;margin-bottom:20px;flex-wrap:wrap }
.billing-dur-btn { padding:6px 16px;border-radius:8px;border:1.5px solid var(--border);background:var(--surface);color:var(--text-muted);font-size:.85rem;font-weight:500;cursor:pointer;transition:all .15s }
.billing-dur-btn.active,.billing-dur-btn:hover { border-color:var(--primary);color:var(--primary);background:rgba(99,102,241,.06) }
.billing-dur-btn.active { font-weight:600 }

.billing-price-display { background:var(--bg);border-radius:var(--radius);padding:16px 20px;margin-bottom:4px;display:flex;align-items:baseline;gap:12px;flex-wrap:wrap }
.billing-price-total { font-size:2rem;font-weight:800;color:var(--text) }
.billing-price-desc { font-size:.85rem;color:var(--text-muted) }

.billing-error { background:#fef2f2;border:1px solid #fecaca;color:#dc2626;border-radius:8px;padding:.6rem .9rem;font-size:.85rem }
.billing-error-card { background:#fef2f2;border:1px solid #fecaca;color:#dc2626;border-radius:var(--radius-lg);padding:20px 24px;font-size:.875rem }

.billing-history-table-wrap { overflow-x:auto }
.billing-history-table { width:100%;border-collapse:collapse }
.billing-history-table th { padding:10px 14px;font-size:.7rem;text-transform:uppercase;letter-spacing:.07em;color:var(--text-muted);font-weight:700;border-bottom:2px solid var(--border);text-align:left;background:var(--bg) }
.billing-history-table td { padding:10px 14px;border-bottom:1px solid rgba(226,232,240,.6);font-size:.875rem;color:var(--text) }
.billing-history-table tbody tr:last-child td { border-bottom:none }
.billing-history-table tbody tr:hover { background:rgba(99,102,241,.025) }

/* ── Billing — assistant list ────────────────────────────────────────────── */
.billing-asst-list { display:flex;flex-direction:column;gap:6px;max-height:320px;overflow-y:auto;padding-right:4px }
.billing-asst-row { display:flex;align-items:center;gap:12px;padding:10px 12px;border:1.5px solid var(--border);border-radius:var(--radius);cursor:pointer;transition:border-color .15s,background .15s;user-select:none }
.billing-asst-row:hover { background:rgba(99,102,241,.04);border-color:var(--primary-light) }
.billing-asst-row input[type=checkbox] { width:16px;height:16px;accent-color:var(--primary);cursor:pointer;flex-shrink:0 }
.billing-asst-row:has(input:checked) { border-color:var(--primary);background:rgba(99,102,241,.06) }
.billing-asst-expired { border-color:#fca5a5;background:rgba(254,242,242,.5) }
.billing-asst-expired:has(input:checked) { border-color:#ef4444;background:rgba(254,242,242,.8) }
.billing-asst-avatar { width:36px;height:36px;border-radius:8px;display:flex;align-items:center;justify-content:center;font-size:1.2rem;flex-shrink:0 }
.billing-asst-info { flex:1;min-width:0 }
.billing-asst-name { font-size:.875rem;font-weight:600;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis }
.billing-asst-role { font-size:.75rem;color:var(--text-muted);text-transform:capitalize }

/* ── Billing badges ───────────────────────────────────────────────────────── */
.billing-badge { display:inline-flex;align-items:center;padding:.15rem .5rem;border-radius:99px;font-size:.7rem;font-weight:700;white-space:nowrap;flex-shrink:0 }
.billing-badge-free    { background:rgba(99,102,241,.1);color:#4f46e5 }
.billing-badge-ok      { background:rgba(16,185,129,.1);color:#059669 }
.billing-badge-warn    { background:rgba(245,158,11,.12);color:#b45309 }
.billing-badge-expired { background:rgba(239,68,68,.1);color:#dc2626 }

/* ── Sidebar expiry badges ────────────────────────────────────────────────── */
.asst-expiry-badge { display:inline-flex;padding:.1rem .45rem;border-radius:99px;font-size:.65rem;font-weight:700;white-space:nowrap;flex-shrink:0;margin-left:auto }
.asst-expiry-warn    { background:rgba(245,158,11,.15);color:#d97706 }
.asst-expiry-expired { background:rgba(239,68,68,.15);color:#dc2626 }
.asst-item-expired .assistant-name { opacity:.6 }
.asst-item-expired .assistant-avatar { opacity:.5 }

/* ── Sidebar marketplace badges ──────────────────────────────────────────── */
.asst-mkt-badge { display:inline-flex;padding:.05rem .35rem;border-radius:99px;font-size:.6rem;font-weight:700;white-space:nowrap;background:rgba(124,58,237,.2);color:#a78bfa;line-height:1.5 }
.asst-mkt-draft { background:rgba(100,116,139,.15);color:#94a3b8 }

/* ── Expired overlay (tab content) ───────────────────────────────────────── */
.asst-expired-overlay { display:flex;align-items:center;justify-content:center;height:100%;min-height:300px;padding:2rem }
.asst-expired-card { text-align:center;max-width:360px }
.asst-expired-icon { font-size:3rem;margin-bottom:16px }
.asst-expired-title { font-size:1.125rem;font-weight:700;color:var(--text);margin-bottom:8px }
.asst-expired-body { font-size:.875rem;color:var(--text-muted);margin-bottom:24px;line-height:1.6 }

/* ── Research Assistant ───────────────────────────────────────────────────── */
.ra-tab { background:none;border:none;padding:10px 16px;font-size:13px;cursor:pointer;color:var(--text-muted);border-bottom:2px solid transparent;transition:color .15s,border-color .15s;white-space:nowrap }
.ra-tab:hover  { color:var(--text) }
.ra-tab.active { color:var(--primary);border-bottom-color:var(--primary);font-weight:600 }

.ra-page-row { display:flex;align-items:center;padding:10px 12px;border:1px solid var(--border);border-radius:8px;background:var(--surface);transition:background .15s,border-color .15s }
.ra-page-row--selected { border-color:var(--primary);background:rgba(99,102,241,.04) }
.ra-page-row:hover { border-color:var(--primary-light,#a78bfa) }

.ra-summary-body { font-size:13px;line-height:1.7;color:var(--text) }
.ra-summary-body h2 { font-size:14px;font-weight:700;margin:16px 0 6px;color:var(--text) }
.ra-summary-body h3 { font-size:13px;font-weight:700;margin:12px 0 4px;color:var(--text) }
.ra-summary-body ul { padding-left:20px;margin:6px 0 }
.ra-summary-body li { margin:3px 0 }
.ra-summary-body p  { margin:8px 0 }
.ra-summary-body strong { font-weight:700 }

.ra-typing-dots { letter-spacing:2px;animation:ra-pulse 1.2s infinite }
@keyframes ra-pulse { 0%,100%{opacity:.3} 50%{opacity:1} }

/* ── Create Wizard ────────────────────────────────────────────────────────── */
.wiz-dot { width:28px;height:28px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:700;background:var(--border);color:var(--text-muted);flex-shrink:0;transition:background .2s,color .2s }
.wiz-dot.active { background:var(--primary);color:#fff }
.wiz-dot.done   { background:var(--primary);color:#fff }
.wiz-line { flex:1;height:2px;background:var(--border);margin:0 6px;transition:background .3s }
.wiz-line.done  { background:var(--primary) }

.wiz-role-card { display:block;padding:14px 16px;border:2px solid var(--border);border-radius:10px;cursor:pointer;transition:border-color .15s,background .15s;background:var(--surface) }
.wiz-role-card:hover  { border-color:var(--primary-light,#a78bfa) }
.wiz-role-card.active { border-color:var(--primary);background:rgba(99,102,241,.06) }
.wiz-role-icon   { font-size:28px;margin-bottom:6px;display:block }
.wiz-role-name   { font-size:13px;font-weight:700;margin-bottom:2px }
.wiz-role-tagline{ font-size:11px;font-weight:600;color:var(--primary);margin-bottom:4px;text-transform:uppercase;letter-spacing:.04em }
.wiz-role-desc   { font-size:12px;color:var(--text-muted);line-height:1.5 }

/* ── Research Executive Document ──────────────────────────── */
.ra-exec-doc {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.07);
  padding: 32px 40px;
  color: #111;
}
.ra-exec-cover {
  border-bottom: 2px solid var(--primary);
  padding-bottom: 20px;
  margin-bottom: 24px;
}
.ra-exec-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 10px;
}
.ra-exec-title {
  font-size: 21px;
  font-weight: 700;
  color: #111;
  margin: 0 0 12px;
  line-height: 1.3;
}
.ra-exec-meta {
  font-size: 12px;
  color: #6b7280;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.ra-exec-meta-dot { color: #d1d5db; }
.ra-exec-body h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: #374151;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 6px;
  margin: 24px 0 10px;
}
.ra-exec-body h3 {
  font-size: 13px;
  font-weight: 700;
  color: #111;
  margin: 16px 0 8px;
}
.ra-exec-body {
  /* Summaries cite raw URLs that can be hundreds of characters — wrap them
     anywhere rather than let them push past the page edge */
  overflow-wrap: anywhere;
  word-break: break-word;
}
.ra-exec-body p {
  font-size: 13px;
  color: #374151;
  line-height: 1.7;
  margin: 0 0 10px;
}
.ra-exec-body ul, .ra-exec-body ol { padding-left: 20px; margin: 6px 0 10px; }
.ra-exec-body li { font-size: 13px; color: #374151; margin: 5px 0; line-height: 1.6; }
.ra-exec-body strong { color: #111; font-weight: 700; }
.ra-exec-body hr { border: none; border-top: 1px solid #e5e7eb; margin: 20px 0; }
.ra-exec-body table { width: 100%; border-collapse: collapse; margin: 12px 0 16px; font-size: 12px; }
.ra-exec-body th { text-align: left; font-weight: 700; padding: 8px 12px; border-bottom: 2px solid #e5e7eb; background: #f9fafb; color: #111; font-size: 11px; }
.ra-exec-body td { padding: 7px 12px; border-bottom: 1px solid #f3f4f6; color: #374151; vertical-align: top; }
.ra-exec-body blockquote { border-left: 3px solid var(--primary); margin: 12px 0; padding: 8px 16px; background: #faf5ff; color: #4b5563; font-style: italic; border-radius: 0 6px 6px 0; }
.ra-exec-footer {
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px solid #e5e7eb;
  font-size: 11px;
  color: #9ca3af;
  text-align: center;
}
.ra-regen-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 64px 0;
  text-align: center;
}
.ra-regen-status { font-size: 14px; font-weight: 600; color: #111; }
.ra-regen-sub    { font-size: 12px; color: #6b7280; }

/* ── Sales Agent ─────────────────────────────────────────────────────────── */
.sa-score-badge,
.sa-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.sa-score-hot  { background: rgba(239,68,68,.12);  color: #dc2626; }
.sa-score-warm { background: rgba(245,158,11,.12); color: #b45309; }
.sa-score-cold { background: rgba(100,116,139,.12); color: #475569; }

.sa-status-new         { background: rgba(99,102,241,.12);  color: #4338ca; }
.sa-status-contacted   { background: rgba(14,165,233,.12);  color: #0369a1; }
.sa-status-qualified   { background: rgba(16,185,129,.12);  color: #047857; }
.sa-status-unqualified { background: rgba(100,116,139,.12); color: #475569; }
.sa-status-converted   { background: rgba(124,58,237,.12);  color: #7c3aed; }


/* ── Custom Expert Agent ──────────────────────────────────────────────────── */
.section-wrap { padding: 24px; max-width: 800px; }
.section-wrap h3 { font-size: 18px; font-weight: 700; margin: 0 0 4px; }
.section-wrap h4 { font-size: 14px; font-weight: 600; margin: 0 0 10px; color: var(--text); }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.section-header h3 { margin: 0; }
.section-hint { font-size: 13px; color: var(--text-muted); margin: 0 0 20px; line-height: 1.5; }
.kb-section { margin-bottom: 28px; }

/* Tool cards */
.tools-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.tool-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.tool-card.tool-disabled { opacity: .55; }
.tool-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.tool-card-name { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.tool-badge { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; background: rgba(99,102,241,.12); color: var(--primary); letter-spacing: .5px; }
.badge-disabled { font-size: 10px; padding: 2px 6px; border-radius: 4px; background: rgba(100,116,139,.12); color: var(--text-muted); }
.tool-card-actions { display: flex; gap: 6px; }
.tool-card-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.tool-card-url { font-size: 11px; color: var(--text-muted); font-family: monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Font mono */
.font-mono { font-family: 'SF Mono', 'Fira Mono', 'Consolas', monospace; font-size: 12px; }
.code-block { background: var(--surface-2, #f8fafc); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-family: monospace; font-size: 12px; white-space: pre-wrap; overflow-x: auto; max-height: 300px; overflow-y: auto; }

/* Form helpers */
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Progress */
.progress-wrap { margin-top: 10px; }
.progress-bar-track { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width .2s; }
.progress-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Upload */
.upload-card { background: var(--surface-2, #f8fafc); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.upload-filename { font-size: 13px; font-weight: 500; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-progress-wrap { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.upload-progress-bar { height: 100%; background: var(--primary); border-radius: 3px; transition: width .3s; }

/* Settings tabs */
.settings-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.stab { background: none; border: none; padding: 8px 14px; font-size: 13px; font-weight: 500; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; border-radius: 0; }
.stab.active { color: var(--primary); border-bottom-color: var(--primary); }
.stab:hover:not(.active) { color: var(--text); }
.settings-section { padding: 4px 0; }
.danger-zone { border: 1px solid rgba(239,68,68,.25); border-radius: 10px; padding: 16px; margin-top: 8px; }
.danger-zone h4 { color: var(--danger, #dc2626); margin-bottom: 12px; }
.danger-item { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.danger-item p { font-size: 13px; color: var(--text-muted); margin: 2px 0 0; }

/* Chat steps (tool call indicators) */
.chat-steps { padding: 8px 16px; display: flex; flex-direction: column; gap: 6px; }
.chat-step { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 6px 10px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); }
.chat-step.step-calling { border-color: rgba(99,102,241,.3); background: rgba(99,102,241,.05); }
.chat-step.step-done    { border-color: rgba(16,185,129,.3); background: rgba(16,185,129,.05); }
.chat-step.step-error   { border-color: rgba(239,68,68,.3);  background: rgba(239,68,68,.05); }
.step-tool    { font-weight: 600; color: var(--primary); }
.step-reason  { color: var(--text-muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-preview { color: var(--text-muted); font-family: monospace; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }

/* Crawl results */
.crawl-results { margin-top: 12px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.crawl-results-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600; }
.crawl-pages-list { max-height: 240px; overflow-y: auto; }
.crawl-page-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; border-bottom: 1px solid var(--border); gap: 12px; }
.crawl-page-item:last-child { border-bottom: none; }
.crawl-page-url { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* Empty / loading / error */
.empty-state { padding: 40px; text-align: center; color: var(--text-muted); font-size: 14px; }
.loading-msg  { padding: 24px; text-align: center; color: var(--text-muted); font-size: 13px; }
.error-msg    { color: var(--danger, #dc2626); font-size: 13px; }

/* Markdown rendered inside chat bubbles */
.chat-md p                    { margin: 0 0 10px; }
.chat-md p:last-child         { margin-bottom: 0; }
.chat-md ul, .chat-md ol      { margin: 4px 0 6px; padding-left: 20px; }
.chat-md li                   { margin-bottom: 3px; }
.chat-md h1,.chat-md h2,
.chat-md h3,.chat-md h4       { margin: 8px 0 4px; font-weight: 700; }
.chat-md code                 { background: rgba(0,0,0,.06); padding: 1px 4px; border-radius: 3px; font-size: 12px; }
.chat-md pre                  { background: rgba(0,0,0,.06); padding: 8px 10px; border-radius: 6px; overflow-x: auto; margin: 6px 0; }
.chat-md pre code             { background: none; padding: 0; }
.chat-md blockquote           { border-left: 3px solid var(--border); margin: 6px 0; padding-left: 10px; color: var(--text-muted); }
.chat-md hr                   { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.chat-md strong               { font-weight: 700; }
.chat-md table                { border-collapse: collapse; width: 100%; margin: 6px 0; font-size: 12px; }
.chat-md th,.chat-md td       { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.chat-md th                   { background: var(--surface-2); font-weight: 600; }
