/* ===== DESIGN SYSTEM ===== */
:root {
  --primary-50: #eff6ff; --primary-100: #dbeafe; --primary-200: #bfdbfe;
  --primary-300: #93c5fd; --primary-400: #60a5fa; --primary-500: #3b82f6;
  --primary-600: #2563eb; --primary-700: #1d4ed8; --primary-800: #1e40af; --primary-900: #1e3a8a;
  
  --gray-50: #f8fafc; --gray-100: #f1f5f9; --gray-200: #e2e8f0; --gray-300: #cbd5e1;
  --gray-400: #94a3b8; --gray-500: #64748b; --gray-600: #475569; --gray-700: #334155;
  --gray-800: #1e293b; --gray-900: #0f172a;
  
  --success: #10b981; --success-light: #d1fae5;
  --warning: #f59e0b; --warning-light: #fef3c7;
  --danger: #ef4444; --danger-light: #fee2e2;
  --info: #06b6d4; --info-light: #cffafe;
  
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --radius: 12px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ===== LAYOUT ===== */
#app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--gray-900);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s ease;
}
.sidebar.collapsed { transform: translateX(-100%); }

.sidebar-header { padding: 24px 20px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon { font-size: 2rem; }
.logo-text { font-size: 0.85rem; line-height: 1.3; color: var(--gray-400); }
.logo-text strong { color: white; font-size: 1.1rem; font-weight: 700; }

.sidebar-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  color: var(--gray-400);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
  cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: white; }
.nav-item.active { background: var(--primary-600); color: white; }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; opacity: 0.8; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.08); }
.version { font-size: 0.75rem; color: var(--gray-500); text-align: center; }

/* Main */
.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.3s ease;
}
.main.expanded { margin-left: 0; }

/* Topbar */
.topbar {
  height: var(--topbar-height);
  background: white;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--gray-600);
  padding: 4px;
}
.topbar-title { font-size: 1.25rem; font-weight: 700; color: var(--gray-900); flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.user-menu {
  align-items: center;
  gap: 8px;
  color: var(--gray-600);
  font-size: 0.9rem;
  font-weight: 600;
}
.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--gray-500);
  padding: 6px 14px;
  background: var(--gray-100);
  border-radius: 20px;
}
.connection-status .status-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--success);
  box-shadow: 0 0 0 3px var(--success-light);
}
.connection-status.offline .status-dot { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-light); }

/* Content */
.content { flex: 1; padding: 28px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* Auth */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--gray-50);
}
.auth-panel {
  width: 100%;
  max-width: 440px;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  padding: 32px;
  box-shadow: var(--shadow-sm);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 32px;
}
.auth-logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--primary-50);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}
.auth-brand h1 {
  font-size: 1.5rem;
  line-height: 1.2;
  color: var(--gray-900);
  margin-bottom: 4px;
}
.auth-brand p {
  color: var(--gray-500);
  font-size: 0.95rem;
}
.auth-submit {
  width: 100%;
}

/* ===== COMPONENTS ===== */

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

/* Cards */
.card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.card-header h3 { font-size: 1.05rem; font-weight: 600; }

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}
.stat-card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, transform 0.2s;
}
.stat-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.stat-icon.blue { background: var(--primary-50); }
.stat-icon.green { background: var(--success-light); }
.stat-icon.yellow { background: var(--warning-light); }
.stat-icon.red { background: var(--danger-light); }
.stat-icon.cyan { background: var(--info-light); }
.stat-info { flex: 1; }
.stat-value { font-size: 1.75rem; font-weight: 800; color: var(--gray-900); line-height: 1; }
.stat-label { font-size: 0.85rem; color: var(--gray-500); margin-top: 6px; }
.stat-change {
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}
.chart-container { position: relative; height: 300px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  font-family: inherit;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary-600); color: white; }
.btn-primary:hover { background: var(--primary-700); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-warning { background: var(--warning); color: white; }
.btn-secondary { background: white; color: var(--gray-700); border-color: var(--gray-300); }
.btn-secondary:hover { background: var(--gray-50); }
.btn-ghost { background: transparent; color: var(--gray-500); }
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-700); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* Forms */
.form-group { margin-bottom: 20px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; }
.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
}
.form-label .optional { font-weight: 400; color: var(--gray-400); font-size: 0.8rem; }
.form-hint { font-size: 0.8rem; color: var(--gray-400); margin-top: 4px; }
input, textarea, select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: white;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px var(--primary-100);
}
input:disabled, textarea:disabled { background: var(--gray-100); cursor: not-allowed; }
textarea { resize: vertical; min-height: 100px; }
input[type="file"] { padding: 8px; }
input[type="checkbox"] { width: auto; margin-right: 8px; }
.checkbox-label { display: flex; align-items: center; font-weight: 500; cursor: pointer; }

/* Table */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--gray-200); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead { background: var(--gray-50); }
th {
  padding: 14px 16px;
  text-align: left;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
.table-sort {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  padding: 0;
  text-align: left;
}
.table-sort:hover { color: var(--primary-700); }
.table-sort-icon {
  color: var(--gray-400);
  font-size: 0.75rem;
}
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}
tbody tr:hover { background: var(--gray-50); }
tbody tr:last-child td { border-bottom: none; }

.leads-table-wrap {
  max-width: 100%;
}
.leads-table {
  table-layout: fixed;
  min-width: 920px;
}
.leads-table th,
.leads-table td {
  padding: 12px 14px;
  vertical-align: middle;
}
.leads-table td {
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
}
.leads-table td:not(:first-child) {
  max-width: 240px;
}
.leads-table a,
.leads-table strong {
  overflow-wrap: anywhere;
}
.lead-columns-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.lead-column-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  color: var(--gray-700);
  font-weight: 500;
  cursor: pointer;
  background: white;
}
.lead-column-option:hover {
  background: var(--gray-50);
  border-color: var(--gray-300);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
}
.badge-draft { background: var(--gray-100); color: var(--gray-600); }
.badge-draft::before { background: var(--gray-400); }
.badge-queued { background: #ede9fe; color: #7c3aed; }
.badge-queued::before { background: #7c3aed; }
.badge-running { background: var(--primary-50); color: var(--primary-700); }
.badge-running::before { background: var(--primary-500); }
.badge-completed { background: var(--success-light); color: #065f46; }
.badge-completed::before { background: var(--success); }
.badge-failed { background: var(--danger-light); color: #991b1b; }
.badge-failed::before { background: var(--danger); }
.badge-paused { background: var(--warning-light); color: #92400e; }
.badge-paused::before { background: var(--warning); }
.badge-sent { background: var(--primary-50); color: var(--primary-700); }
.badge-delivered { background: #cffafe; color: #155e75; }
.badge-read { background: #e0e7ff; color: #3730a3; }
.badge-responded { background: var(--success-light); color: #065f46; }
.badge-pending { background: var(--gray-100); color: var(--gray-600); }
.badge-online { background: var(--success-light); color: #065f46; }
.badge-offline { background: var(--danger-light); color: #991b1b; }
.badge-admin { background: var(--primary-50); color: var(--primary-700); }
.badge-admin::before { background: var(--primary-500); }
.badge-user { background: var(--gray-100); color: var(--gray-600); }
.badge-user::before { background: var(--gray-400); }

/* Search & Filters */
.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}
.search-box {
  position: relative;
  flex: 1;
  min-width: 240px;
}
.search-box input {
  padding-left: 40px;
}
.search-box::before {
  content: '🔍';
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  opacity: 0.5;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-400);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h3 { color: var(--gray-600); margin-bottom: 8px; }
.empty-state p { font-size: 0.9rem; }

/* Loading */
.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary-600);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton {
  background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-100) 50%, var(--gray-200) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
  background: white;
  border-radius: var(--radius);
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  animation: modalIn 0.3s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-400);
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  transition: all 0.2s;
}
.modal-close:hover { background: var(--gray-100); color: var(--gray-700); }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
}

/* Toast */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: 16px 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 320px;
  max-width: 420px;
  animation: toastIn 0.3s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
.toast-icon { font-size: 1.3rem; }
.toast-content { flex: 1; }
.toast-title { font-weight: 700; font-size: 0.9rem; }
.toast-message { font-size: 0.85rem; color: var(--gray-500); margin-top: 2px; }
.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-warning { border-left: 4px solid var(--warning); }
.toast-info { border-left: 4px solid var(--info); }

/* Wizard */
.wizard-steps {
  display: flex;
  gap: 8px;
  margin-bottom: 32px;
}
.wizard-step {
  flex: 1;
  text-align: center;
  padding: 12px;
  border-radius: 8px;
  background: var(--gray-100);
  color: var(--gray-500);
  font-size: 0.85rem;
  font-weight: 600;
  position: relative;
}
.wizard-step.active { background: var(--primary-600); color: white; }
.wizard-step.done { background: var(--success-light); color: var(--success); }

/* Progress Bar */
.progress-bar {
  height: 8px;
  background: var(--gray-200);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-500), var(--primary-400));
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* Timeline */
.timeline { position: relative; padding-left: 28px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--gray-200);
}
.timeline-item {
  position: relative;
  padding-bottom: 20px;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -24px;
  top: 4px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--gray-300);
  border: 2px solid white;
}
.timeline-item.success::before { background: var(--success); }
.timeline-item.error::before { background: var(--danger); }
.timeline-item.info::before { background: var(--primary-500); }
.timeline-time { font-size: 0.8rem; color: var(--gray-400); }
.timeline-text { font-size: 0.9rem; margin-top: 2px; }

/* Preview Message */
.message-preview {
  background: #d9fdd3;
  border-radius: 8px;
  padding: 12px 16px;
  max-width: 400px;
  position: relative;
  font-size: 0.9rem;
}
.message-preview::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 16px;
  width: 12px; height: 12px;
  background: #d9fdd3;
  transform: rotate(45deg);
}
.message-preview .time {
  font-size: 0.7rem;
  color: var(--gray-500);
  text-align: right;
  margin-top: 4px;
}

/* Roadmap */
.roadmap-item {
  display: flex;
  gap: 16px;
  padding: 20px;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  margin-bottom: 12px;
}
.roadmap-status {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.roadmap-status.done { background: var(--success-light); }
.roadmap-status.in-progress { background: var(--primary-50); }
.roadmap-status.planned { background: var(--gray-100); }
.roadmap-content h4 { font-size: 1rem; margin-bottom: 4px; }
.roadmap-content p { font-size: 0.85rem; color: var(--gray-500); }
.roadmap-tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 8px;
}
.roadmap-tag.done { background: var(--success-light); color: #065f46; }
.roadmap-tag.in-progress { background: var(--primary-50); color: var(--primary-700); }
.roadmap-tag.planned { background: var(--gray-100); color: var(--gray-600); }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: block; }
  .charts-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 16px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .search-box { min-width: auto; }
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-fade-in { animation: fadeIn 0.4s ease; }
