/* Knowledge Base SaaS — Admin Panel Styles */
:root {
  --sidebar-width: 240px;
  --sidebar-bg: #ffffff;
  --sidebar-hover: rgba(139,54,217,0.08);
  --sidebar-active: #8b36d9;
  --sidebar-text: #6b7280;
  --sidebar-text-active: #ffffff;
  --primary: #8b36d9;
  --primary-hover: #7a2ec4;
  --primary-light: rgba(139,54,217,0.1);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #21c45d;
  --success-bg: rgba(33,196,93,0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245,159,10,0.1);
  --info: #2463eb;
  --info-bg: rgba(36,99,235,0.1);
  --bg: #f8f8fc;
  --card-bg: #ffffff;
  --text: #030711;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --radius: 12px;
  --radius-sm: 10px;
  --shadow: 0 1px 1px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 30px -3px rgba(139,54,217,0.12);
  --transition: 150ms ease;
  --accent: #8b36d9;
  --accent-hover: #7a2ec4;
  --hover-bg: var(--border-light);
  --bg-card: #ffffff;
  --gradient-brand: linear-gradient(135deg, #ff6b8a 0%, #c084fc 100%);
}

/* ─── Dark Mode (OPTION B.2) ─── */
[data-theme="dark"] {
  --sidebar-bg: #150f1f;
  --sidebar-hover: rgba(168,85,247,0.12);
  --sidebar-active: #a855f7;
  --sidebar-text: #b8aed0;
  --sidebar-text-active: #ffffff;
  --bg: #120f1a;
  --bg-card: #1c1626;
  --card-bg: #1c1626;
  --text: #f0eaf9;
  --text-secondary: #b8aed0;
  --text-muted: #8b8b96;
  --border: #2e2440;
  --border-light: #241c33;
  --accent: #a855f7;
  --accent-hover: #9333ea;
  --hover-bg: #241c33;
  --hover: #241c33;
  --primary: #a855f7;
  --primary-hover: #9333ea;
  --primary-light: #3b2a54;
  --info: #6c9bff;
  --info-bg: rgba(108,155,255,0.15);
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 30px -3px rgba(0,0,0,0.5);
  --success-bg: #052e16;
  --warning-bg: #451a03;
}

[data-theme="dark"] .logout-btn:hover { background: #3b1a1a; border-color: var(--danger); color: #fca5a5; }
[data-theme="dark"] thead th { background: #1e1f28; }
[data-theme="dark"] tbody tr:hover { background: #22232b; }
[data-theme="dark"] .badge-default { background: #2a2b33; color: #c0c0cc; }
[data-theme="dark"] .badge-primary { background: #252a4a; color: #8ba3ff; }
[data-theme="dark"] .error-msg { background: #3b1a1a; color: #fca5a5; }
[data-theme="dark"] .sr-snippet mark { background: #554400; color: #fef08a; }
[data-theme="dark"] .form-group input,
[data-theme="dark"] .form-group select,
[data-theme="dark"] .form-group textarea { background: #1a1b23; color: #e1e1e6; }
[data-theme="dark"] .search-input-container input { background: #1a1b23; color: #e1e1e6; border-color: #2a2b33; }
[data-theme="dark"] .settings-section { border: 1px solid #2a2b33; }
[data-theme="dark"] table th { background: #1e1f2e; color: #c8c8d4; }
[data-theme="dark"] table td { background: #181923; color: #d4d4dc; }
[data-theme="dark"] table tr:hover td { background: #232438; }
[data-theme="dark"] .empty-state { color: #8b8b96; }
[data-theme="dark"] .modal-content { background: #1a1b23; color: #e1e1e6; }
[data-theme="dark"] .sidebar-link { color: #b0b0ba; }
[data-theme="dark"] .sidebar-link:hover { background: #22232b; color: #e1e1e6; }
[data-theme="dark"] .btn-outline { border-color: #3a3b45; color: #d4d4dc; }
[data-theme="dark"] .btn-outline:hover { background: #2a2b35; }
[data-theme="dark"] .btn-ghost { color: #b0b0ba; }
[data-theme="dark"] .btn-ghost:hover { background: #22232b; color: #e1e1e6; }
[data-theme="dark"] .tab { color: #b0b0ba; }
[data-theme="dark"] .tab.active { color: #e1e1e6; border-bottom-color: #6c8cff; }
[data-theme="dark"] .page-header,
[data-theme="dark"] .subtitle { color: #8b8b96; }
[data-theme="dark"] .mini-stat { background: var(--bg-card); border: 1px solid #2a2b33; }

* { margin: 0; padding: 0; box-sizing: border-box; }
body { 
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5;
  overflow-x: hidden;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Sidebar (floating card, sits below the header) ─── */
#sidebar {
  position: fixed; left: 16px; top: 92px; bottom: 16px; width: calc(var(--sidebar-width) - 16px);
  background: var(--sidebar-bg); display: flex; flex-direction: column;
  z-index: 100; overflow-y: auto; border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow-md);
}
.sidebar-new-chat-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin: 16px 12px 4px; padding: 10px 14px; border: none; border-radius: var(--radius-sm);
  background: var(--border-light); color: var(--text-secondary); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all var(--transition);
}
.sidebar-new-chat-btn:hover { background: var(--sidebar-hover); color: var(--primary); }
.sidebar-nav { padding: 12px 12px 8px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  color: var(--sidebar-text); text-decoration: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; transition: all var(--transition);
  margin-bottom: 4px;
}
.sidebar-nav a:hover { background: var(--sidebar-hover); color: var(--primary); }
.sidebar-nav a.active { background: var(--sidebar-active); color: var(--sidebar-text-active); box-shadow: var(--shadow); }
.sidebar-nav .nav-icon { display: flex; align-items: center; justify-content: center; width: 24px; flex-shrink: 0; }
.sidebar-nav .nav-icon svg { width: 15.79px; height: 15.79px; }
.sidebar-recent-chats { flex: 1; overflow-y: auto; padding: 8px 12px; border-top: 1px solid var(--border); min-height: 60px; }
.sidebar-recent-chats-label {
  font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--text-muted); padding: 8px 10px 4px;
}
.sidebar-recent-chat-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 13px; cursor: pointer; transition: background var(--transition);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-recent-chat-item:hover { background: var(--sidebar-hover); }
.sidebar-recent-chat-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.sidebar-recent-chat-item span:last-child { overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer {
  padding: 12px 8px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted); text-align: center;
}

/* ─── Header (full-width: brand + product selector + page title) ─── */
.header-brand {
  display: flex; align-items: center; gap: 14px; flex-shrink: 0;
  padding-right: 20px; border-right: 1px solid var(--border);
}
.sidebar-logo-row { display: flex; align-items: center; gap: 10px; font-weight: 700; white-space: nowrap; }
.sidebar-logo-row .logo-icon {
  display: block; width: 32px; height: 32px;
  border-radius: 10px; object-fit: contain; flex-shrink: 0;
}
.sidebar-logo-row .logo-text { color: #000; font-weight: 700; font-size: 24px; }
.sidebar-logo-row .os-gradient,
.os-gradient {
  background: linear-gradient(90deg, #ff6b9d, #b85ce8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 700;
}
.sidebar-selector { width: 160px; }
.sidebar-selector select {
  width: 100%;
  padding: 6px 26px 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: all 150ms ease;
}
.sidebar-selector select:hover {
  border-color: var(--primary);
  background: var(--card-bg);
}
.sidebar-selector select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}
.sidebar-selector select option {
  background: var(--card-bg);
  color: var(--text);
}

/* ─── Top Bar ─── */
#topbar {
  position: fixed; left: 0; top: 0; right: 0; height: 76px;
  background: var(--card-bg); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 0 28px; z-index: 101;
}
.topbar-left { display: flex; align-items: center; gap: 20px; min-width: 0; }
#topbar h1 { font-size: 15px; font-weight: 600; color: var(--text-secondary); white-space: nowrap; }
.topbar-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 14px; width: 320px; max-width: 30vw; cursor: pointer;
  color: var(--text-muted); font-size: 14px; transition: all var(--transition);
}
.topbar-search:hover { border-color: var(--primary); }
.topbar-search .shortcut-hint { margin-left: auto; }
.topbar-right { display: flex; align-items: center; gap: 16px; flex-shrink: 0; }
.topbar-user { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: default; }
.topbar-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--gradient-brand);
  color: white; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
}
.logout-btn {
  background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 14px; cursor: pointer; font-size: 13px; color: var(--text-muted);
  transition: all var(--transition);
}
.logout-btn:hover { background: #fef2f2; border-color: var(--danger); color: var(--danger); }

/* Dark mode toggle button */
.theme-toggle-btn {
  background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  width: 36px; height: 36px; cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.theme-toggle-btn:hover { background: var(--border-light); }

/* ─── Content ─── */
#app-content {
  margin-left: var(--sidebar-width); min-height: 100vh;
  padding: 108px 32px 32px;
}

/* ─── Login Page ─── */
.login-page {
  margin: 0 !important; padding: 0; min-height: 100vh;
  display: flex; align-items: flex-start; justify-content: center; background: var(--bg);
  position: fixed; inset: 0; z-index: 1;
}
.login-container {
  display: flex; flex-direction: column; align-items: center;
  max-width: 440px; width: 100%; padding: 120px 40px 40px;
}
.login-brand-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}
.login-logo {
  display: block; width: 32px; height: 32px;
  object-fit: contain; flex-shrink: 0;
}
.login-brand {
  font-size: 24px; font-weight: 700; color: var(--text); line-height: 1;
}
.login-subtitle {
  font-size: 14px; color: var(--text-muted); margin-bottom: 32px;
}
.login-page .form-group { margin-bottom: 20px; width: 100%; }
.login-page .form-group label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; color: var(--text-secondary); }
.login-page .form-group input { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 15px; transition: all var(--transition); background: var(--card-bg); }
.login-page .form-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.login-btn {
  width: 100%; justify-content: center; padding: 11px; font-size: 15px;
}
.login-footer {
  text-align: center; margin-top: 20px; font-size: 14px; color: var(--text-muted);
}
.login-page #login-form {
  width: 100%; display: flex; flex-direction: column;
}
.login-page #login-error { width: 100%; }
.login-page #login-error .error-msg { margin-bottom: 16px; }

/* ─── Components ─── */
.container { max-width: 1200px; margin: 0 auto; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; }
.page-header h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.page-header .subtitle { font-size: 14px; color: var(--text-secondary); margin-top: 6px; }
.page-eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 4px; }

/* Cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px; margin-bottom: 32px; }
.stat-card {
  background: var(--card-bg); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 16px;
  transition: all var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-card-top { display: flex; align-items: center; justify-content: space-between; }
.stat-icon {
  width: 44px; height: 44px; border-radius: var(--radius-sm); display: flex;
  align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0;
}
.stat-icon.blue { background: var(--info-bg); color: var(--info); }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.orange { background: var(--warning-bg); color: var(--warning); }
.stat-icon.purple { background: var(--primary-light); color: var(--primary); }
.stat-info h3 { font-size: 30px; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; color: var(--text); }
.stat-info p { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.stat-trend {
  display: inline-flex; align-items: center; gap: 3px; padding: 3px 10px;
  border-radius: 9999px; font-size: 12px; font-weight: 500;
}
.stat-trend.positive { background: var(--success-bg); color: var(--success); }
.stat-trend.negative { background: rgba(239,68,68,0.1); color: var(--danger); }

/* Product Grid */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.product-card {
  background: var(--card-bg); border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow); cursor: pointer; transition: all var(--transition);
  border: 1px solid var(--border);
}
.product-card:hover { box-shadow: var(--shadow-md); border-color: var(--primary); transform: translateY(-2px); }
.product-icon {
  width: 48px; height: 48px; border-radius: 14px; display: flex;
  align-items: center; justify-content: center; font-size: 24px; margin-bottom: 12px;
}
.product-card h3 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.product-card p { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.product-meta { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); }
.product-meta span { display: flex; align-items: center; gap: 4px; }

/* Dashboard content cards (AI Usage / Integrations / Quick Actions / Recent Activity row) */
.dashboard-row { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; margin-top: 24px; }
.dashboard-card {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px; min-width: 0;
}
.dashboard-card-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; gap: 12px; }
.dashboard-card-head h3 { font-size: 16px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); flex-shrink: 0; }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.bar-chart-horizontal .bar-label { width: 70px; text-transform: capitalize; }
.dashboard-card-head p { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.dashboard-card-link { font-size: 13px; color: var(--primary); text-decoration: none; white-space: nowrap; }
.dashboard-card-link:hover { text-decoration: underline; }

/* Quick Actions */
.quick-actions-list { display: flex; flex-direction: column; gap: 10px; }
.quick-action-btn {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card-bg); color: var(--text); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all var(--transition);
}
.quick-action-btn:hover { border-color: var(--primary); background: var(--primary-light); }
.quick-action-icon {
  display: flex; align-items: center; justify-content: center; width: 30px; height: 30px;
  border-radius: var(--radius-sm); background: var(--info-bg); font-size: 15px; flex-shrink: 0;
}

/* Integrations donut chart */
#integrations-donut { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.donut-chart { width: 150px; height: 150px; border-radius: 50%; position: relative; }
.donut-hole { position: absolute; inset: 20px; background: var(--card-bg); border-radius: 50%; }
.donut-legend { display: flex; gap: 18px; font-size: 13px; color: var(--text-secondary); }
.donut-legend span { display: flex; align-items: center; gap: 6px; }
.donut-legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* Integrations */
.integrations-toolbar { display: flex; gap: 16px; margin-bottom: 24px; }
.form-select-inline {
  padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card-bg); color: var(--text); font-size: 14px; cursor: pointer;
}
.integration-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }

/* Document Cards Grid */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.doc-card {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px; cursor: pointer;
  display: flex; flex-direction: column; gap: 16px;
  transition: all var(--transition);
}
.doc-card:hover { box-shadow: var(--shadow-md); border-color: var(--primary); transform: translateY(-2px); }
.doc-card-head { display: flex; align-items: flex-start; gap: 12px; }
.doc-icon {
  width: 44px; height: 44px; border-radius: var(--radius-sm); background: var(--border-light);
  display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0;
}
.doc-card-head h3 { font-size: 15px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-product { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.doc-meta-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.doc-size { font-size: 12px; color: var(--text-muted); margin-left: auto; }
.integration-card {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px; display: flex; flex-direction: column; gap: 14px;
}
.integration-card-head { display: flex; align-items: flex-start; gap: 12px; }
.integration-icon {
  width: 44px; height: 44px; border-radius: var(--radius-sm); background: var(--border-light);
  display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0;
}
.integration-card-head h3 { font-size: 15px; font-weight: 600; color: var(--text); }
.integration-category { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.integration-badge {
  padding: 3px 10px; border-radius: 9999px; font-size: 11px; font-weight: 600; white-space: nowrap;
}
.integration-badge.connected { background: var(--primary-light); color: var(--primary); }
.integration-badge.available { background: var(--border-light); color: var(--text-secondary); }
.integration-desc { font-size: 13px; color: var(--text-secondary); line-height: 1.5; flex: 1; }
.integration-meta { font-size: 12px; color: var(--text-muted); }
.integration-actions { display: flex; align-items: center; gap: 8px; }
.integration-disconnect {
  background: none; border: none; color: var(--danger); font-size: 13px; font-weight: 500;
  cursor: pointer; margin-left: auto; padding: 5px 8px;
}
.integration-disconnect:hover { text-decoration: underline; }
.btn-connect {
  background: var(--gradient-brand); color: white; border: none; border-radius: var(--radius-sm);
  padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer; transition: opacity var(--transition);
}
.btn-connect:hover { opacity: 0.9; }

/* Tables */
.table-container {
  background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: 12px 16px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted);
  background: var(--border-light); border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px 16px; font-size: 14px; border-bottom: 1px solid var(--border-light); }
tbody tr:hover { background: var(--border-light); }
tbody tr:last-child td { border-bottom: none; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px;
  border-radius: 100px; font-size: 12px; font-weight: 500;
}
.badge-healthy { background: var(--success-bg); color: var(--success); }
.badge-invalid { background: #fef2f2; color: var(--danger); }
.badge-pending { background: var(--warning-bg); color: var(--warning); }
.badge-default { background: var(--border-light); color: var(--text-secondary); }
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.badge-healthy::before { background: var(--success); }
.badge-invalid::before { background: var(--danger); }
.badge-pending::before { background: var(--warning); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
  border-radius: var(--radius-sm); font-size: 14px; font-weight: 500;
  border: 1px solid var(--border); background: var(--card-bg); color: var(--text);
  cursor: pointer; transition: all var(--transition); text-decoration: none;
}
.btn:hover { background: var(--border-light); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-ghost { background: transparent; border: none; color: var(--text-muted); }
.btn-ghost:hover { background: var(--border-light); color: var(--text); }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text-secondary); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit; transition: all var(--transition);
  background: var(--card-bg);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Tabs */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 10px 20px; font-size: 14px; font-weight: 500; color: var(--text-muted);
  cursor: pointer; border-bottom: 2px solid transparent; transition: all var(--transition);
  background: none; border-top: none; border-left: none; border-right: none;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 150ms ease;
}
.modal {
  background: var(--card-bg); border-radius: var(--radius); padding: 0;
  box-shadow: var(--shadow-lg); max-width: 520px; width: 90%;
  max-height: 85vh; overflow-y: auto; animation: slideUp 200ms ease;
}
.modal-header { padding: 20px 24px 0; display: flex; justify-content: space-between; align-items: center; }
.modal-header h2 { font-size: 18px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); padding: 4px; }
.modal-body { padding: 16px 24px 24px; }
.modal-footer { padding: 0 24px 20px; display: flex; justify-content: flex-end; gap: 8px; }

/* Document viewer modal */
.doc-viewer { max-width: 720px; }
.doc-viewer .doc-title { font-size: 20px; font-weight: 600; margin-bottom: 8px; }
.doc-viewer .doc-meta { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.doc-viewer .doc-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.doc-tag { padding: 2px 8px; border-radius: 4px; background: var(--border-light); font-size: 11px; color: var(--text-muted); }
.doc-viewer .doc-content {
  background: var(--border-light); padding: 16px; border-radius: 8px;
  font-size: 13px; white-space: pre-wrap; word-break: break-word;
  max-height: 50vh; overflow-y: auto; line-height: 1.6;
}

/* Search */
.search-page { max-width: 640px; margin: 0 auto; padding-top: 40px; }
.search-input-container {
  position: relative; margin-bottom: 24px;
}
.search-input-container input {
  width: 100%; padding: 14px 20px; font-size: 18px;
  border: 2px solid var(--border); border-radius: var(--radius);
  transition: all var(--transition);
}
.search-input-container input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-light); }
.search-results { margin-top: 8px; }
.search-result {
  padding: 16px; border-radius: var(--radius-sm); cursor: pointer;
  transition: all var(--transition); border-bottom: 1px solid var(--border-light);
}
.search-result:hover { background: var(--border-light); }
.search-result h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.search-result p { font-size: 13px; color: var(--text-muted); }
.search-result .sr-meta { display: flex; gap: 8px; margin-top: 6px; }

/* Settings */
.settings-section { background: var(--card-bg); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; box-shadow: var(--shadow); }
.settings-section h2 { font-size: 16px; font-weight: 600; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border-light); }
.settings-row { display: flex; padding: 12px 0; border-bottom: 1px solid var(--border-light); }
.settings-row:last-child { border-bottom: none; }
.settings-label { width: 140px; font-size: 13px; color: var(--text-muted); flex-shrink: 0; }
.settings-value { font-size: 14px; }

/* Loading & Empty */
.loading { display: flex; align-items: center; justify-content: center; padding: 60px; }
.spinner { 
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 600ms linear infinite;
}
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.error-msg { padding: 12px 16px; background: #fef2f2; color: var(--danger); border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.success-msg { padding: 12px 16px; background: var(--success-bg); color: var(--success); border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }

/* User Management */
.users-table-container { overflow-x: auto; }
.users-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.users-table th { text-align: left; padding: 12px 10px; font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 2px solid var(--border); cursor: pointer; user-select: none; }
.users-table th:hover { color: var(--text); background: rgba(79,110,247,0.05); }
.users-table td { padding: 12px 10px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.users-table tbody tr:hover { background: var(--hover-bg); }
.inactive-row { opacity: 0.5; }
/* Skeleton Loading */
.skeleton-stats { display:grid;grid-template-columns:repeat(4,1fr);gap:20px; }
.skeleton-card { height:100px;background:var(--border-light);border-radius:var(--radius);animation:pulse 1.5s ease-in-out infinite; }
.skeleton-grid { display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:20px; }
.skeleton-product { height:160px;background:var(--border-light);border-radius:var(--radius);animation:pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity:0.5; } 50% { opacity:1; } }

/* Activity List */
.activity-list { max-height: 400px; overflow-y: auto; }
.activity-item { display: flex; align-items: flex-start; gap: 12px; padding: 10px; border-radius: var(--radius-sm); transition: background var(--transition); }
.activity-item:hover { background: var(--border-light); }
.activity-icon {
  font-size: 15px; flex-shrink: 0; width: 30px; height: 30px; border-radius: var(--radius-sm);
  background: var(--border-light); display: flex; align-items: center; justify-content: center;
}
.activity-body { flex: 1; }
.activity-title { font-size: 14px; color: var(--text); }
.activity-time { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* Bar Chart */
.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-item { display: flex; align-items: center; gap: 12px; }
.bar-label { width: 40px; font-size: 12px; color: var(--text-muted); text-align: right; flex-shrink: 0; }
.bar-track { flex: 1; height: 24px; background: var(--border-light); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 6px; transition: width 0.5s; min-width: 4px; }
.bar-value { font-size: 13px; font-weight: 600; color: var(--text); width: 30px; text-align: right; }

/* Search result snippet with highlights */
.sr-snippet { font-size: 13px; color: var(--text-muted); margin: 4px 0; line-height: 1.5; }
.sr-snippet mark { background: #fef08a; color: #333; padding: 1px 3px; border-radius: 2px; }

/* Inactive row */
.inactive-row { opacity: 0.6; }

/* Success card */
.success-card { background: var(--success-bg,#ecfdf5); border-radius: var(--radius); padding: 24px; }

/* Agent Activity */
.agent-widget { background: var(--card-bg); border-radius: var(--radius); padding: 20px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.mini-stat { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--radius-sm); background: var(--bg); transition: background 0.2s; }
.mini-stat:hover { background: var(--border-light); }
.mini-stat-icon { font-size: 24px; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); }
.progress-bar-track { display: inline-block; width: 80px; height: 6px; background: var(--border-light); border-radius: 4px; overflow: hidden; vertical-align: middle; }
.progress-bar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.5s; }

/* Trend chart for user activity */
.trend-chart {
  padding: 16px; background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.trend-chart .bar-fill { background: var(--accent); }

.offline-banner {
  background: #ff6b35;
  color: white;
  text-align: center;
  padding: 6px;
  font-size: 12px;
  font-weight: 600;
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
}
[data-theme="dark"] .offline-banner {
  background: #cc5500;
}

/* Keyboard shortcut hint badge */
.shortcut-hint {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--text-muted); padding: 3px 8px;
  background: var(--border-light); border-radius: 4px;
  cursor: help;
}
.shortcut-hint kbd {
  font-family: monospace; background: var(--bg-card);
  padding: 1px 4px; border-radius: 3px; font-size: 11px;
  border: 1px solid var(--border);
}

/* Agent task type badges */
#agent-list-container .badge { font-size: 11px; text-transform: uppercase; letter-spacing: 0.3px; }


.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.status-dot.active { background: var(--success); }
.status-dot.inactive { background: var(--text-muted); }
.btn-sm { padding: 5px 10px; font-size: 12px; margin-left: 6px; }
.btn-danger { background: var(--danger); color: #fff; border: none; }
.btn-danger:hover { opacity: 0.85; }
.form-error { padding: 8px 12px; background: #fef2f2; color: var(--danger); border-radius: var(--radius-sm); margin-bottom: 12px; font-size: 13px; }

/* Toggle Switch */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: var(--border); transition: .3s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background: #fff; transition: .3s; border-radius: 50%; }
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider:before { transform: translateX(20px); }
.success-msg { padding: 12px 16px; background: var(--success-bg); color: var(--success); border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }

/* Audit logs specific */
#audit-content .badge-healthy { background: var(--success-bg); color: var(--success); }

/* Animations */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* Responsive */
@media (max-width: 768px) {
  #sidebar { left: 8px; width: 52px; }
  .sidebar-nav a { justify-content: center; padding: 12px; }
  .sidebar-nav .nav-text, .sidebar-footer, .sidebar-new-chat-btn, .sidebar-recent-chats { display: none; }
  .header-brand .logo-text, .header-brand .sidebar-selector, #topbar h1 { display: none; }
  #topbar { padding: 0 16px; }
  #app-content { margin-left: 60px; padding: 96px 16px 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-row { grid-template-columns: 1fr; }
  .product-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .login-left { display: none; }
  .login-right { flex: none; width: 100%; }
}

/* ══════════════════════════════════════════════════════════
   Chat Module Styles
   ══════════════════════════════════════════════════════════ */

/* Connection Status Dot */
.ws-status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-left: 8px;
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}
.ws-status-connected {
  background: #22c55e;
  box-shadow: 0 0 6px 2px rgba(34, 197, 94, 0.5);
}
.ws-status-reconnecting {
  background: #f59e0b;
  box-shadow: 0 0 6px 2px rgba(245, 158, 11, 0.5);
  animation: wsPulse 1.5s ease-in-out infinite;
}
.ws-status-disconnected {
  background: #ef4444;
  box-shadow: 0 0 6px 2px rgba(239, 68, 68, 0.3);
}

@keyframes wsPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Chat Nav Badge */
.chat-nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: #ef4444;
  border-radius: 9px;
  margin-left: auto;
  line-height: 1;
}

/* Chat Layout */
.chat-layout {
  display: flex;
  height: calc(100vh - 60px - 32px); /* viewport - topbar - padding */
  margin: -24px; /* offset container padding */
  overflow: hidden;
  border-radius: 0;
  background: var(--card-bg);
}

[data-theme="dark"] .chat-layout {
  background: var(--bg-card);
}

.chat-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: var(--primary);
  border-radius: 10px;
  flex-shrink: 0;
}

/* Main Chat Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-group-detail {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Messages Area */
.chat-messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 14px;
  padding: 40px;
  text-align: center;
}

/* Individual Message */
.chat-message {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: fadeInMsg 0.2s ease;
}

.chat-message.mine {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-message.system {
  align-self: center;
  max-width: 100%;
}

.chat-message.agent-reply {
  align-self: flex-start;
}

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

.chat-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 4px;
}

.chat-msg-avatar.mine {
  background: var(--accent);
}

.chat-msg-avatar.agent-avatar {
  background: #f0abfc;
  font-size: 16px;
}

[data-theme="dark"] .chat-msg-avatar.agent-avatar {
  background: #701a75;
}

.chat-msg-bubble {
  background: var(--bg);
  border-radius: 12px;
  padding: 8px 14px;
  min-width: 60px;
  max-width: 100%;
  border: 1px solid var(--border);
}

.chat-message.mine .chat-msg-bubble {
  background: var(--primary-light);
  border-color: var(--primary);
}

.chat-message.agent-reply .chat-msg-bubble {
  background: #faf5ff;
  border-color: #e9d5ff;
}

[data-theme="dark"] .chat-message.agent-reply .chat-msg-bubble {
  background: #1a0a2e;
  border-color: #3b0764;
}

.chat-msg-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.chat-msg-user {
  font-size: 13px;
  font-weight: 600;
}

.chat-msg-role {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 600;
}

.agent-label {
  background: #e9d5ff;
  color: #6b21a8;
}

[data-theme="dark"] .agent-label {
  background: #3b0764;
  color: #d8b4fe;
}

.chat-msg-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
}

.chat-msg-content {
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-system-msg {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 6px 12px;
  background: var(--hover-bg);
  border-radius: 20px;
  max-width: 500px;
}

/* Input Area */
.chat-input-container {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  background: var(--card-bg);
}

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  background: var(--bg);
  color: var(--text);
  max-height: 120px;
  outline: none;
  transition: border-color 0.15s;
}

.chat-input:focus {
  border-color: var(--primary);
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.chat-send-btn:hover {
  background: var(--primary-hover);
}

.chat-send-btn:active {
  transform: scale(0.95);
}

/* Typing Indicator */
.chat-typing-indicator {
  font-size: 12px;
  color: var(--text-muted);
  padding: 2px 4px 6px;
  font-style: italic;
  animation: typingPulse 1.5s ease-in-out infinite;
}

@keyframes typingPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* Load More */
.chat-load-more {
  text-align: center;
  padding: 8px 0;
}

/* Members Panel */
.chat-member-panel {
  width: 220px;
  min-width: 220px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

[data-theme="dark"] .chat-member-panel {
  background: var(--bg-card);
}

.chat-member-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.chat-member-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.chat-member-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
  transition: background 0.15s;
}

.chat-member-item:hover {
  background: var(--hover-bg);
}

.chat-member-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.chat-member-info {
  flex: 1;
  min-width: 0;
}

.chat-member-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-admin-badge {
  font-size: 10px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 600;
}

/* Online Dots */
.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.3s;
}
.online-dot.online {
  background: #22c55e;
  box-shadow: 0 0 4px 1px rgba(34, 197, 94, 0.4);
}
.online-dot.offline {
  background: #9ca3af;
}

/* Responsive Chat */
@media (max-width: 768px) {
  .chat-member-panel {
    display: none;
  }
  .chat-message {
    max-width: 95%;
  }
}

/* Danger button variant */
.btn-danger {
  background: var(--danger);
  color: #fff;
  border: 1px solid var(--danger);
}
.btn-danger:hover {
  background: var(--danger-hover);
}

/* Extra small button */
.btn-xs {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-ghost {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
}
.btn-ghost:hover {
  background: var(--hover-bg);
  color: var(--text);
}

/* ─── Chat UI ─────────────────────────────────────────────── */

