/* =====================================================
   BeautyCRM - Estilos principales
   ===================================================== */

:root {
  --primary: #7C3AED;
  --primary-dark: #6D28D9;
  --primary-light: #A78BFA;
  --primary-bg: #F5F3FF;
  --secondary: #EC4899;
  --success: #10B981;
  --danger: #EF4444;
  --warning: #F59E0B;
  --info: #3B82F6;

  --bg: #F3F4F6;
  --surface: #FFFFFF;
  --border: #E5E7EB;
  --text: #111827;
  --text-light: #6B7280;
  --text-muted: #9CA3AF;

  --sidebar-width: 260px;
  --sidebar-bg: #FFFFFF;
  --header-height: 70px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.08);

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

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

html, body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* =====================================================
   LAYOUT
   ===================================================== */
.app-wrapper, .app-container { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: transform 0.3s;
}

.sidebar-brand {
  padding: 20px 24px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.sidebar-brand .logo {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  transition: all 0.2s;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--primary-bg);
  color: var(--primary);
}

.nav-item.active {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
}

.nav-item .icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.nav-item.active .icon {
  background: var(--primary);
  color: #fff;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-info .name { font-weight: 600; font-size: 14px; color: var(--text); }
.user-info .status { font-size: 12px; color: var(--success); display: flex; align-items: center; gap: 4px; }
.user-info .status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--success); }

/* =====================================================
   MAIN
   ===================================================== */
.main, .main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar .menu-toggle, .topbar .btn-menu {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.topbar .topbar-brand {
  display: none;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 0.2s;
  position: relative;
}

.icon-btn:hover { background: var(--primary-bg); border-color: var(--primary-light); }

.icon-btn .badge-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid #fff;
}

.content {
  padding: 24px;
  flex: 1;
}

/* =====================================================
   PAGE HEADER
   ===================================================== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-header h1 {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.page-header p {
  color: var(--text-light);
  font-size: 14px;
  margin-top: 4px;
}

/* =====================================================
   BUTTONS
   ===================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-color: var(--primary-dark);
}
.btn-primary:hover { color: #fff; }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 24px; font-size: 16px; }

.btn-block { width: 100%; }

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
}

/* =====================================================
   CARDS
   ===================================================== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

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

.card-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.card-body { padding: 20px; }

/* Stat cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.stat-card .stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  margin-bottom: 14px;
}

.stat-icon.bg-purple { background: #F5F3FF; color: var(--primary); }
.stat-icon.bg-pink { background: #FCE7F3; color: var(--secondary); }
.stat-icon.bg-green { background: #D1FAE5; color: var(--success); }
.stat-icon.bg-blue { background: #DBEAFE; color: var(--info); }
.stat-icon.bg-yellow { background: #FEF3C7; color: var(--warning); }
.stat-icon.bg-red { background: #FEE2E2; color: var(--danger); }

.stat-card .label {
  color: var(--text-light);
  font-size: 13px;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -1px;
}

.stat-card .change {
  font-size: 12px;
  margin-top: 4px;
  color: var(--text-light);
}

/* =====================================================
   TABLE
   ===================================================== */
.table-wrapper {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table thead th {
  background: #F9FAFB;
  padding: 14px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.table tbody td {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: 0; }

.table tbody tr:hover { background: #FAFAFB; }

.table .text-right { text-align: right; }
.table .text-center { text-align: center; }

.table-responsive { overflow-x: auto; }

/* =====================================================
   BADGES
   ===================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-blue { background: #DBEAFE; color: #1E40AF; }
.badge-purple { background: #F5F3FF; color: #6D28D9; }
.badge-pink { background: #FCE7F3; color: #BE185D; }
.badge-green { background: #D1FAE5; color: #065F46; }
.badge-yellow { background: #FEF3C7; color: #92400E; }
.badge-red { background: #FEE2E2; color: #991B1B; }
.badge-orange { background: #FED7AA; color: #9A3412; }
.badge-gray { background: #F3F4F6; color: #374151; }

/* =====================================================
   SEARCH BAR
   ===================================================== */
.search-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.search-bar input {
  flex: 1;
  border: 0;
  background: transparent;
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  color: var(--text);
}

.search-bar input::placeholder { color: var(--text-muted); }
.search-bar .icon { color: var(--text-muted); font-size: 18px; }

/* =====================================================
   FORMS
   ===================================================== */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
}

.form-control,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus,
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.1);
}

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

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

.form-row-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.required { color: var(--danger); }

/* =====================================================
   ALERTS
   ===================================================== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-success { background: #D1FAE5; color: #065F46; border-left: 4px solid var(--success); }
.alert-danger { background: #FEE2E2; color: #991B1B; border-left: 4px solid var(--danger); }
.alert-warning { background: #FEF3C7; color: #92400E; border-left: 4px solid var(--warning); }
.alert-info { background: #DBEAFE; color: #1E40AF; border-left: 4px solid var(--info); }

/* =====================================================
   PROFILE CELL (table)
   ===================================================== */
.profile-cell {
  display: flex;
  align-items: center;
  gap: 12px;
}

.profile-cell .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FBBF24, #F59E0B);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.profile-cell .avatar.purple { background: linear-gradient(135deg, var(--primary), var(--secondary)); }
.profile-cell .avatar.green { background: linear-gradient(135deg, #10B981, #059669); }
.profile-cell .avatar.blue { background: linear-gradient(135deg, #3B82F6, #1E40AF); }

.profile-cell .info .name { font-weight: 600; color: var(--text); }
.profile-cell .info .meta { font-size: 13px; color: var(--text-light); margin-top: 2px; }
.profile-cell .info .ref { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; margin-top: 2px;}

/* =====================================================
   ACTIONS COLUMN
   ===================================================== */
.action-buttons { display: flex; flex-direction: column; gap: 4px; align-items: stretch; }

.action-btn {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  justify-content: flex-start;
}

.action-btn:hover { background: var(--primary-bg); border-color: var(--primary-light); color: var(--primary); }
.action-btn.edit { color: var(--info); }
.action-btn.invite { color: var(--primary); }
.action-btn.call { color: var(--success); }
.action-btn.delete { color: var(--danger); }
.action-btn.whatsapp { color: #25D366; border-color: #25D366; }

.urgency-overdue { color: var(--danger); font-weight: 600; }
.urgency-today { color: var(--warning); font-weight: 600; }
.urgency-week { color: var(--info); }

/* =====================================================
   FAB - Floating chat button
   ===================================================== */
.fab-chat {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  border: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  box-shadow: 0 8px 24px rgba(124,58,237,0.4);
  z-index: 100;
  transition: all 0.3s;
}

.fab-chat:hover { transform: scale(1.05); }

/* =====================================================
   MODAL
   ===================================================== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(17,24,39,0.6);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.show { display: flex; }

.modal {
  background: #fff;
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

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

.modal-header h3 { font-size: 17px; font-weight: 600; }
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal .close {
  background: none;
  border: 0;
  cursor: pointer;
  font-size: 24px;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal .close:hover { background: var(--bg); }

/* =====================================================
   AUTH
   ===================================================== */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #7C3AED 0%, #EC4899 100%);
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: #fff;
  border-radius: 20px;
  padding: 40px;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo .icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin-bottom: 12px;
}

.auth-logo h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -1px;
}

.auth-logo p {
  color: var(--text-light);
  font-size: 14px;
  margin-top: 4px;
}

/* =====================================================
   KANBAN
   ===================================================== */
.kanban {
  display: grid;
  grid-template-columns: repeat(4, minmax(260px, 1fr));
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 12px;
}

.kanban-col {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 200px;
}

.kanban-col h4 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kanban-col .count {
  background: #fff;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.kanban-card {
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 8px;
  border-left: 3px solid var(--primary);
  box-shadow: var(--shadow-sm);
}

.kanban-card.overdue { border-left-color: var(--danger); }
.kanban-card.today { border-left-color: var(--warning); }
.kanban-card.week { border-left-color: var(--info); }

.kanban-card .name { font-weight: 600; margin-bottom: 4px; }
.kanban-card .meta { font-size: 12px; color: var(--text-light); margin-bottom: 8px; }
.kanban-card .actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* =====================================================
   TABS
   ===================================================== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab {
  padding: 10px 18px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  font-weight: 500;
  color: var(--text-light);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* =====================================================
   TREE - MLM Network
   ===================================================== */
.tree { padding-left: 0; }
.tree ul { padding-left: 28px; }

.tree li {
  list-style: none;
  position: relative;
  padding: 8px 0 8px 18px;
}

.tree li::before {
  content: '';
  position: absolute;
  left: 0; top: 24px;
  width: 14px; height: 1px;
  background: var(--border);
}

.tree li::after {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 1px;
  height: 100%;
  background: var(--border);
}

.tree li:last-child::after { height: 24px; }

.tree-node {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.tree-node .role-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
  text-transform: uppercase;
}

/* =====================================================
   AI CHAT
   ===================================================== */
.chat-container {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  height: calc(100vh - 200px);
  min-height: 500px;
}

.chat-sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-y: auto;
}

.chat-main {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
}

.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

.chat-input-bar {
  border-top: 1px solid var(--border);
  padding: 16px;
  display: flex;
  gap: 10px;
}

.chat-input-bar input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  outline: none;
}

.message {
  max-width: 80%;
  margin-bottom: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  word-wrap: break-word;
}

.message.user {
  background: var(--primary);
  color: #fff;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.message.bot {
  background: #F3F4F6;
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.doc-item {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.doc-item .title { font-weight: 600; }
.doc-item .meta { font-size: 11px; color: var(--text-muted); }

/* =====================================================
   FUNNEL
   ===================================================== */
.funnel-stage {
  margin-bottom: 8px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  color: #fff;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* =====================================================
   HEATMAP
   ===================================================== */
.heatmap {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 4px;
}

.heatmap-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  background: #F3F4F6;
}

.heatmap-cell.l1 { background: #EDE9FE; }
.heatmap-cell.l2 { background: #C4B5FD; }
.heatmap-cell.l3 { background: #8B5CF6; }
.heatmap-cell.l4 { background: #6D28D9; }

/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.15); }
  .main, .main-wrapper { margin-left: 0; }
  .topbar .topbar-brand { display: flex; }
  .topbar .menu-toggle, .topbar .btn-menu { display: flex; }
  .chat-container { grid-template-columns: 1fr; }
  .chat-sidebar { display: none; }
}

@media (max-width: 640px) {
  .content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .page-header h1 { font-size: 20px; }
  .auth-card { padding: 28px 22px; }
  .kanban { grid-template-columns: 1fr; }
  .table-wrapper { overflow-x: auto; }
  .table { min-width: 700px; }
  .action-buttons { flex-direction: row; }
  .action-btn { padding: 4px 8px; }
}

/* Utilities */
.text-muted { color: var(--text-muted); }
.text-light { color: var(--text-light); }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.w-full { width: 100%; }
.hidden { display: none; }

/* === Text color utilities === */
.text-purple { color: var(--primary); }
.text-pink { color: var(--secondary); }
.text-blue { color: #3B82F6; }
.text-green { color: #10B981; }
.text-yellow { color: #F59E0B; }
.text-red { color: #EF4444; }
.text-orange { color: #F97316; }
.text-gray { color: #6B7280; }

/* === Profile detail header === */
.profile-header { display: flex; align-items: center; gap: 16px; }
.profile-avatar-lg {
    width: 64px; height: 64px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white; display: flex; align-items: center; justify-content: center;
    font-size: 24px; font-weight: 700;
}
.profile-meta { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 4px; color: var(--text-muted); font-size: 13px; }
.profile-meta i { margin-right: 4px; }
.header-actions { display: flex; gap: 8px; }

/* === Detail / definition lists === */
.detail-list { display: grid; grid-template-columns: 130px 1fr; gap: 8px 16px; margin: 0; }
.detail-list dt { color: var(--text-muted); font-size: 13px; }
.detail-list dd { margin: 0; font-weight: 500; }
.notes-block { margin-top: 16px; padding: 12px; background: #F9FAFB; border-radius: 8px; }
.notes-block p { margin: 8px 0 0; color: var(--text-muted); font-size: 14px; }

/* === Detail grid layout === */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

/* === Dashboard list items === */
.list-clean { list-style: none; padding: 0; margin: 0; }
.list-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #F3F4F6;
}
.list-item:last-child { border-bottom: none; }
.list-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white; display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.list-content { flex: 1; min-width: 0; }
.list-title { font-weight: 600; font-size: 14px; color: var(--text-strong); }
.list-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.list-notes { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-style: italic; }

.empty-state-sm {
    text-align: center; padding: 20px; color: var(--text-muted);
    font-size: 14px;
}
.empty-state-sm i { margin-right: 6px; }

/* === Dashboard grid === */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

/* === Sale items rows === */
.sale-item-row {
    display: grid;
    grid-template-columns: 2fr 80px 120px 40px;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}
.sale-item-row select, .sale-item-row input {
    margin: 0;
}
.btn-remove {
    background: #FEE2E2; color: #DC2626; border: none;
    width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.sale-total {
    margin-top: 16px; padding: 12px; background: #F9FAFB;
    border-radius: 8px; display: flex; justify-content: space-between;
    align-items: center; font-size: 16px;
}
.sale-total strong { color: var(--primary); font-size: 18px; }

/* === Inline forms in tables === */
.inline-form {
    display: inline-flex; align-items: center; gap: 8px; margin: 0;
}
.inline-form input, .inline-form select {
    margin: 0; padding: 6px 10px;
}
.select-sm {
    font-size: 12px; padding: 4px 8px;
}

/* === Filter tabs === */
.filter-tabs {
    display: flex; gap: 12px; margin: 16px 0;
    flex-wrap: wrap;
}
.filter-tab {
    background: white; padding: 8px 16px; border-radius: 999px;
    font-size: 13px; box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    display: flex; align-items: center; gap: 6px;
}
.filter-tab .dot {
    width: 8px; height: 8px; border-radius: 50%; display: inline-block;
}

/* === Form section === */
.form-section { margin-bottom: 24px; }
.form-section h3 {
    font-size: 15px; font-weight: 600; margin-bottom: 12px;
    color: var(--text-strong); padding-bottom: 8px;
    border-bottom: 1px solid #E5E7EB;
}
.form-hint { color: var(--text-muted); font-size: 12px; }

/* === MLM tree === */
.mlm-tree { padding: 16px; overflow-x: auto; }
.tree-node { margin-bottom: 12px; }
.tree-card {
    display: inline-flex; align-items: center; gap: 12px;
    padding: 10px 16px; border-radius: 12px; color: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    min-width: 200px;
}
.tree-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: rgba(255,255,255,0.25); display: flex;
    align-items: center; justify-content: center;
    font-size: 12px; font-weight: 600;
}
.tree-name { font-weight: 600; font-size: 14px; }
.tree-role { font-size: 12px; opacity: 0.9; text-transform: capitalize; }
.tree-children { padding-left: 32px; margin-top: 8px; border-left: 2px dashed #E5E7EB; }
.level-0 .tree-card { background: linear-gradient(135deg, var(--primary), var(--secondary)); }
.level-1 .tree-card { background: linear-gradient(135deg, var(--secondary), #F59E0B); }
.level-2 .tree-card { background: linear-gradient(135deg, #3B82F6, #06B6D4); }

/* === Heatmap === */
.heatmap {
    display: grid;
    grid-template-columns: repeat(15, 1fr);
    gap: 3px; padding: 8px 0;
}
.heat-cell {
    aspect-ratio: 1; border-radius: 3px; min-width: 14px;
}
.heat-0 { background: #F3F4F6; }
.heat-1 { background: #DDD6FE; }
.heat-2 { background: #A78BFA; }
.heat-3 { background: #7C3AED; }
.heat-4 { background: #5B21B6; }
.heatmap-legend {
    display: flex; align-items: center; gap: 4px; margin-top: 8px;
    font-size: 11px; color: var(--text-muted); justify-content: flex-end;
}
.heatmap-legend .heat-cell { width: 14px; height: 14px; }

/* === Funnel === */
.funnel { padding: 8px 0; }
.funnel-stage {
    display: grid; grid-template-columns: 100px 1fr;
    gap: 12px; align-items: center; margin-bottom: 8px;
}
.funnel-label { font-size: 13px; color: var(--text-strong); font-weight: 500; }
.funnel-bar-wrap {
    background: #F3F4F6; height: 28px; border-radius: 6px;
    position: relative; overflow: hidden;
}
.funnel-bar {
    height: 100%; border-radius: 6px;
    transition: width 0.6s ease;
}
.funnel-count {
    position: absolute; right: 12px; top: 50%;
    transform: translateY(-50%); font-weight: 600; font-size: 13px;
    color: var(--text-strong);
}
.close-rate {
    margin-top: 16px; padding: 12px; background: #F0FDF4;
    border-radius: 8px; display: flex; justify-content: space-between;
    align-items: center;
}
.close-rate strong { color: #10B981; font-size: 18px; }

/* === AI chat layout === */
.ai-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 16px;
    height: calc(100vh - 180px);
    min-height: 500px;
}
.ai-sidebar { overflow-y: auto; }
.ai-chat {
    background: white; border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    display: flex; flex-direction: column;
    overflow: hidden;
}
.chat-messages {
    flex: 1; overflow-y: auto; padding: 20px;
    display: flex; flex-direction: column; gap: 16px;
}
.chat-msg { display: flex; gap: 10px; max-width: 85%; }
.msg-bot { align-self: flex-start; }
.msg-user { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.msg-bubble {
    background: #F3F4F6; padding: 10px 14px; border-radius: 12px;
    font-size: 14px; line-height: 1.5;
}
.msg-user .msg-bubble {
    background: var(--primary); color: white;
}
.msg-bubble ul { margin: 8px 0; padding-left: 20px; }
.msg-bubble li { margin: 2px 0; }
.chat-input-form {
    display: flex; padding: 12px; border-top: 1px solid #E5E7EB;
    gap: 8px;
}
.chat-input-form input {
    flex: 1; margin: 0;
}
.chat-input-form button {
    background: var(--primary); color: white; border: none;
    width: 44px; height: 44px; border-radius: 8px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}

/* === Upload zone === */
.upload-tabs {
    display: flex; gap: 4px; margin-bottom: 12px;
    background: #F3F4F6; padding: 4px; border-radius: 8px;
}
.tab-btn {
    flex: 1; background: transparent; border: none;
    padding: 8px; font-size: 13px; cursor: pointer;
    border-radius: 6px; font-weight: 500;
}
.tab-btn.active { background: white; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.tab-content { display: none; }
.tab-content.active { display: block; }
.upload-zone {
    border: 2px dashed #D1D5DB; border-radius: 8px;
    padding: 24px; text-align: center; margin-bottom: 12px;
    cursor: pointer;
}
.upload-zone i { font-size: 32px; color: var(--text-muted); }
.upload-zone p { margin: 8px 0; color: var(--text-muted); font-size: 13px; }
.upload-zone input[type=file] {
    width: 100%; margin-top: 8px;
}
.docs-list { margin-top: 12px; }
.doc-item {
    display: flex; align-items: center; gap: 8px;
    padding: 8px; border-radius: 6px;
    background: #F9FAFB; margin-bottom: 6px;
}
.doc-item i { color: var(--primary); }
.doc-info { flex: 1; min-width: 0; }
.doc-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { font-size: 11px; color: var(--text-muted); }

/* === Auth pages === */
.auth-body {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    font-family: 'Inter', -apple-system, sans-serif;
}
.auth-container { width: 100%; max-width: 420px; padding: 16px; }
.auth-card {
    background: white; border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
    padding: 32px;
}
.auth-brand { text-align: center; margin-bottom: 24px; }
.brand-icon-lg {
    width: 64px; height: 64px; margin: 0 auto 12px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 16px; color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: 28px;
}
.auth-brand h1 {
    font-size: 28px; font-weight: 700; margin: 0;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.auth-brand p { color: var(--text-muted); font-size: 14px; margin: 4px 0 0; }
.auth-title { font-size: 20px; font-weight: 600; margin: 0 0 16px; text-align: center; }
.auth-subtitle { color: var(--text-muted); font-size: 13px; text-align: center; margin: 0 0 16px; }
.auth-form .form-group { margin-bottom: 14px; }
.auth-links { text-align: center; margin-top: 16px; font-size: 13px; }
.auth-links a { color: var(--primary); text-decoration: none; }
.auth-footer { text-align: center; color: rgba(255,255,255,0.8); font-size: 12px; margin-top: 16px; }

.input-icon { position: relative; }
.input-icon i {
    position: absolute; left: 12px; top: 50%;
    transform: translateY(-50%); color: var(--text-muted);
}
.input-icon input { padding-left: 36px; }
.btn-block { width: 100%; }

/* === Topbar adjustments === */
.topbar-brand {
    display: flex; align-items: center; gap: 8px;
    font-weight: 600; font-size: 16px;
}
.brand-icon-sm {
    width: 28px; height: 28px; border-radius: 6px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white; display: flex; align-items: center; justify-content: center;
}
.topbar-icon {
    width: 36px; height: 36px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); text-decoration: none;
}
.topbar-icon:hover { background: #F3F4F6; }
.topbar-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white; display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 13px; text-decoration: none;
}

/* === Kanban tweaks === */
.kanban-empty {
    padding: 24px; text-align: center; color: var(--text-muted);
    font-size: 13px;
}
.kanban-card-meta { font-size: 12px; color: var(--text-muted); margin: 4px 0; }
.kanban-card-notes { font-size: 12px; color: var(--text-muted); margin: 4px 0; font-style: italic; }
.kanban-card-actions { display: flex; gap: 4px; margin-top: 8px; align-items: center; }

/* === Search bar === */
.search-bar {
    position: relative; margin-bottom: 16px;
}
.search-bar i {
    position: absolute; left: 14px; top: 50%;
    transform: translateY(-50%); color: var(--text-muted);
}
.search-bar input {
    width: 100%; padding: 10px 14px 10px 40px;
    border: 1px solid #E5E7EB; border-radius: 10px;
    font-size: 14px; background: white;
}

/* === Status dot in user card === */
.status-dot {
    display: inline-block; width: 8px; height: 8px;
    border-radius: 50%; background: #10B981;
    margin-right: 4px;
}

/* === bg-gray for nav-icon === */
.bg-gray { background: linear-gradient(135deg, #6B7280, #4B5563); }

/* === Mobile === */
@media (max-width: 1024px) {
    .ai-layout { grid-template-columns: 1fr; height: auto; }
    .detail-list { grid-template-columns: 1fr; gap: 4px; }
    .detail-list dt { margin-top: 8px; }
    body.sidebar-open { overflow: hidden; }
}
@media (max-width: 640px) {
    .sale-item-row { grid-template-columns: 1fr; }
    .header-actions { flex-direction: column; align-items: stretch; }
    .stats-grid { grid-template-columns: 1fr; }
}

/* =====================================================
   FIXES: aliases for class names used by views
   ===================================================== */

/* data-table = table */
.data-card {
  background: var(--surface);
  border-radius: var(--radius, 12px);
  border: 1px solid var(--border, #E5E7EB);
  overflow: hidden;
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,0.05));
  margin-bottom: 16px;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}
.data-table thead th {
  background: #F9FAFB;
  padding: 14px 18px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  color: var(--text-light, #6B7280);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border-bottom: 1px solid var(--border, #E5E7EB);
  white-space: nowrap;
}
.data-table tbody td {
  padding: 16px 18px;
  border-bottom: 1px solid #F3F4F6;
  vertical-align: middle;
  font-size: 14px;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #FAFAFB; }
.data-table .text-right { text-align: right; }
.data-table .text-center { text-align: center; }

/* profile-cell aliases */
.profile-cell .profile-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary, #7C3AED), var(--secondary, #EC4899));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  text-transform: uppercase;
  flex-shrink: 0;
}
.profile-cell .profile-info .profile-name { font-weight: 600; color: var(--text, #111827); font-size: 14px; }
.profile-cell .profile-info .profile-phone { font-size: 13px; color: var(--text-light, #6B7280); margin-top: 2px; }
.profile-cell .profile-info .profile-ref { font-size: 12px; color: var(--text-muted, #9CA3AF); display: flex; align-items: center; gap: 4px; margin-top: 2px; }

/* action-buttons row layout (horizontal pills) */
.action-buttons {
  display: flex;
  flex-direction: row;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  text-decoration: none;
  border: 1px solid transparent;
  white-space: nowrap;
  transition: all 0.15s;
}
.btn-action i { font-size: 12px; }
.btn-action-edit {
  background: #EEF2FF;
  color: #4338CA;
  border-color: #C7D2FE;
}
.btn-action-edit:hover { background: #E0E7FF; }
.btn-action-invite {
  background: #FEF3C7;
  color: #92400E;
  border-color: #FDE68A;
}
.btn-action-invite:hover { background: #FDE68A; }
.btn-action-call {
  background: #DBEAFE;
  color: #1E40AF;
  border-color: #BFDBFE;
}
.btn-action-call:hover { background: #BFDBFE; }
.btn-action-wa {
  background: #25D366;
  color: white;
  border-color: #25D366;
  width: 30px;
  height: 30px;
  padding: 0;
  justify-content: center;
}
.btn-action-wa:hover { background: #1FB855; }

/* btn-icon for action icons in tables */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: transparent;
  color: var(--text-light, #6B7280);
  text-decoration: none;
  transition: all 0.15s;
  border: none;
  cursor: pointer;
}
.btn-icon:hover { background: #F3F4F6; color: var(--text, #111827); }
.btn-icon.text-red:hover { background: #FEE2E2; color: #DC2626; }

/* Empty state inside table */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-light, #6B7280);
  font-size: 14px;
}
.empty-state i {
  display: block;
  font-size: 36px;
  color: #D1D5DB;
  margin-bottom: 10px;
}
.empty-state a { color: var(--primary, #7C3AED); text-decoration: none; font-weight: 500; }

/* Page header tweaks */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
  color: var(--text, #111827);
}
.page-subtitle {
  font-size: 14px;
  color: var(--text-light, #6B7280);
  margin: 4px 0 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary, #7C3AED), var(--secondary, #EC4899));
  color: white;
}
.btn-primary:hover { opacity: 0.95; box-shadow: 0 4px 12px rgba(124, 58, 237, 0.25); }
.btn-light {
  background: white;
  color: var(--text, #111827);
  border-color: #E5E7EB;
}
.btn-light:hover { background: #F9FAFB; }
.btn-success {
  background: #10B981;
  color: white;
}
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* Badge sizes/colors used in tables */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 12px;
  white-space: nowrap;
}
.badge-purple { background: #EDE9FE; color: #6D28D9; }
.badge-pink { background: #FCE7F3; color: #BE185D; }
.badge-blue { background: #DBEAFE; color: #1E40AF; }
.badge-green { background: #D1FAE5; color: #047857; }
.badge-yellow { background: #FEF3C7; color: #92400E; }
.badge-red { background: #FEE2E2; color: #B91C1C; }
.badge-orange { background: #FFEDD5; color: #9A3412; }
.badge-gray { background: #F3F4F6; color: #4B5563; }

/* Search bar */
.search-bar {
  position: relative;
  margin-bottom: 16px;
  background: white;
  border-radius: 10px;
  border: 1px solid var(--border, #E5E7EB);
}
.search-bar i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light, #6B7280);
}
.search-bar input {
  width: 100%;
  padding: 12px 16px 12px 42px;
  border: none;
  background: transparent;
  font-size: 14px;
  border-radius: 10px;
  outline: none;
}
.search-bar input:focus { box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1); }

/* Next action urgency */
.next-action .action-date { font-size: 14px; font-weight: 500; }
.next-action .urgency-overdue { color: #DC2626; font-size: 12px; font-weight: 600; }
.next-action .urgency-today { color: #F59E0B; font-size: 12px; font-weight: 600; }
.next-action .urgency-soon { color: #3B82F6; font-size: 12px; }
.next-action .urgency-later { color: var(--text-light, #6B7280); font-size: 12px; }

/* Stack action buttons on mobile */
@media (max-width: 768px) {
  .action-buttons { flex-direction: column; align-items: stretch; }
  .btn-action { justify-content: center; }
  .data-table thead { display: none; }
  .data-table tbody td { display: block; padding: 8px 16px; }
  .data-table tbody td:first-child { padding-top: 14px; }
  .data-table tbody td:last-child { padding-bottom: 14px; }
  .data-table tbody tr { display: block; border-bottom: 1px solid #E5E7EB; }
}
