:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.25);
  --accent: #8b5cf6;
  --bg-dark: #090d16;
  --bg-sidebar: #0e1322;
  --bg-card: rgba(18, 25, 41, 0.7);
  --bg-card-hover: rgba(26, 36, 58, 0.85);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: rgba(99, 102, 241, 0.4);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
}

/* Sidebar */
.crm-sidebar {
  width: 260px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand-section {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
}

.brand-logo-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px var(--primary-glow);
}

.brand-text h2 {
  font-size: 16px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.3px;
  line-height: 1.2;
}

.brand-text span {
  font-size: 11px;
  font-weight: 600;
  color: #10b981;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.nav-menu {
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: 10px;
  transition: all 0.2s ease;
  cursor: pointer;
  border: 1px solid transparent;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #ffffff;
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(168, 85, 247, 0.12));
  color: #ffffff;
  border: 1px solid var(--border-active);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.15);
}

.nav-item svg {
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  background: rgba(99, 102, 241, 0.2);
  color: #818cf8;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  font-size: 12px;
  color: var(--text-muted);
}

.demo-site-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34d399;
  padding: 9px 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 12px;
  text-decoration: none;
  transition: all 0.2s;
}

.demo-site-btn:hover {
  background: rgba(16, 185, 129, 0.2);
}

/* Main Content Area */
.crm-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
}

.crm-header {
  padding: 20px 32px;
  background: rgba(14, 19, 34, 0.8);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.crm-title h1 {
  font-size: 22px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.5px;
}

.crm-title p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.header-btn-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  outline: none;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #ffffff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-outline {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: #e2e8f0;
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

/* Page Views */
.tab-content-section {
  display: none;
  padding: 32px;
}

.tab-content-section.active {
  display: block;
}

/* Overview Metric Cards */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.metric-icon-box {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-purple { background: rgba(99, 102, 241, 0.15); color: #818cf8; }
.icon-green { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.icon-orange { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.icon-blue { background: rgba(14, 165, 233, 0.15); color: #38bdf8; }

.metric-data h3 {
  font-size: 26px;
  font-weight: 800;
  color: #ffffff;
  line-height: 1;
}

.metric-data p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Section Header */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
}

/* Agents Grid */
.agents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 22px;
}

.agent-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
}

.agent-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-active);
  background: var(--bg-card-hover);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.agent-card-header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.agent-card-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--primary);
}

.agent-card-meta h3 {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
}

.agent-service-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  margin-top: 4px;
}

.agent-card-body {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  flex: 1;
}

.agent-kb-stats {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: #94a3b8;
  padding: 10px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
}

.agent-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
}

/* Leads Table */
.table-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.table-toolbar {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  gap: 16px;
  flex-wrap: wrap;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
  max-width: 320px;
}

.search-input {
  width: 100%;
  background: rgba(14, 19, 34, 0.8);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px 8px 34px;
  font-size: 13px;
  color: #ffffff;
  outline: none;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 9px;
  color: var(--text-muted);
}

.crm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.crm-table th {
  background: rgba(14, 19, 34, 0.6);
  padding: 12px 18px;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-color);
}

.crm-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  color: #e2e8f0;
  vertical-align: middle;
}

.crm-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}

.badge-green { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.badge-blue { background: rgba(14, 165, 233, 0.15); color: #38bdf8; }
.badge-orange { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.badge-purple { background: rgba(168, 85, 247, 0.15); color: #c084fc; }

/* Embed Generator View */
.embed-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.embed-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
}

.code-box {
  background: #070a12;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 16px;
  position: relative;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12.5px;
  color: #38bdf8;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre-wrap;
  margin: 12px 0 16px;
}

.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-color);
  color: #ffffff;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

.preview-iframe-wrapper {
  width: 100%;
  height: 520px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: #000;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

/* Modals & Drawers */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(5, 8, 16, 0.75);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open,
.modal-overlay.active {
  display: flex !important;
}

.modal-container,
.modal-content {
  background: #0f1526;
  border: 1px solid var(--border-active, rgba(255, 255, 255, 0.1));
  border-radius: 18px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  padding: 24px;
  color: #ffffff;
  position: relative;
  z-index: 1001;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 10px;
  border-radius: 8px;
  transition: all 0.2s;
}

.modal-close-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
  color: #ffffff;
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: rgba(10, 15, 26, 0.5);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-control {
  background: rgba(22, 31, 52, 0.7);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13.5px;
  color: #ffffff;
  outline: none;
  transition: border-color 0.2s;
}

.form-control:focus {
  border-color: var(--primary);
}

textarea.form-control {
  min-height: 80px;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* Transcript Drawer in Leads */
.transcript-bubble-box {
  background: rgba(10, 14, 25, 0.7);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.crm-bubble {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.45;
}

.crm-bubble.agent {
  background: rgba(30, 41, 59, 0.9);
  color: #f8fafc;
  align-self: flex-start;
  max-width: 85%;
  border-left: 3px solid var(--primary);
}

.crm-bubble.customer {
  background: rgba(79, 70, 229, 0.35);
  color: #ffffff;
  align-self: flex-end;
  max-width: 85%;
  border-right: 3px solid #818cf8;
}

.crm-bubble-header {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: #94a3b8;
  margin-bottom: 4px;
}

/* Responsive */
@media (max-width: 900px) {
  .crm-sidebar {
    width: 70px;
  }
  .brand-text, .nav-item span, .sidebar-footer span, .nav-badge {
    display: none;
  }
  .nav-item {
    justify-content: center;
    padding: 12px;
  }
  .embed-layout {
    grid-template-columns: 1fr;
  }
}
