/* ══════════════════════════════════════════════════════════
   CRM SaaS — Main Stylesheet
   ══════════════════════════════════════════════════════════ */

:root {
  --primary:        #4F46E5;
  --primary-dark:   #3730A3;
  --primary-light:  #EEF2FF;
  --secondary:      #7C3AED;
  --sidebar-bg:     #1E1B4B;
  --sidebar-text:   #C7D2FE;
  --sidebar-active: #4F46E5;
  --header-bg:      #FFFFFF;
  --btn-color:      #4F46E5;
  --success:        #10B981;
  --warning:        #F59E0B;
  --danger:         #EF4444;
  --info:           #3B82F6;

  --bg:             #F8FAFC;
  --bg2:            #FFFFFF;
  --surface:        #FFFFFF;
  --border:         #E2E8F0;
  --text:           #0F172A;
  --text-2:         #64748B;
  --text-3:         #94A3B8;

  --radius:         0.75rem;
  --radius-sm:      0.5rem;
  --shadow:         0 1px 3px 0 rgb(0 0 0 / .1), 0 1px 2px -1px rgb(0 0 0 / .1);
  --shadow-md:      0 4px 6px -1px rgb(0 0 0 / .1), 0 2px 4px -2px rgb(0 0 0 / .1);
  --shadow-lg:      0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);
  --sidebar-w:      260px;
  --topbar-h:       64px;
  --transition:     .2s ease;
}

[data-theme="dark"] {
  --bg:       #0F172A;
  --bg2:      #1E293B;
  --surface:  #1E293B;
  --border:   #334155;
  --text:     #F1F5F9;
  --text-2:   #94A3B8;
  --text-3:   #64748B;
  --header-bg:#1E293B;
  --primary-light: #1E1B4B;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
}

a { text-decoration: none; color: inherit; }

/* ── SCROLLBAR ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── UTILITIES ─────────────────────────────────────────── */
.hidden { display: none !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 0.5rem; }
.gap-4 { gap: 1rem; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.font-bold { font-weight: 700; }
.text-muted { color: var(--text-2); }
.w-full { width: 100%; }
.text-center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── AUTH PAGE ─────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1E1B4B 0%, #312E81 50%, #4C1D95 100%);
  padding: 1rem;
  position: relative;
  overflow: hidden;
}
.auth-bg {
  position: absolute; inset: 0;
  background-image: radial-gradient(circle at 20% 50%, rgba(79,70,229,.3) 0%, transparent 50%),
                    radial-gradient(circle at 80% 20%, rgba(124,58,237,.2) 0%, transparent 50%);
}
.auth-card {
  background: rgba(255,255,255,.07);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 1.5rem;
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  position: relative;
  z-index: 1;
  box-shadow: 0 25px 50px rgba(0,0,0,.4);
}
.auth-logo {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.5rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
}
.auth-card h1 { font-size: 1.75rem; color: #fff; font-weight: 700; }
.auth-subtitle { color: rgba(255,255,255,.6); margin-bottom: 1.5rem; }

/* ── APP LAYOUT ────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ───────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: width var(--transition), transform var(--transition);
  overflow: hidden;
}
.sidebar.collapsed { width: 70px; }
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  min-height: 65px;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .65rem;
  color: #fff;
  font-weight: 700;
  font-size: .95rem;
  overflow: hidden;
  white-space: nowrap;
}
.sidebar.collapsed .sidebar-logo span,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .badge,
.sidebar.collapsed .user-mini-info,
.sidebar.collapsed .sidebar-name { display: none; }

.sidebar-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--sidebar-text); font-size: 1.25rem;
  padding: .25rem; border-radius: 6px;
  transition: background var(--transition);
}
.sidebar-toggle:hover { background: rgba(255,255,255,.1); }

.sidebar-nav { flex: 1; padding: 1rem .75rem; overflow-y: auto; }
.nav-section-label {
  font-size: .7rem; font-weight: 600; letter-spacing: .08em;
  color: rgba(199,210,254,.4); padding: .75rem .5rem .25rem;
  text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem .75rem; border-radius: var(--radius-sm);
  color: var(--sidebar-text); cursor: pointer;
  transition: background var(--transition), color var(--transition);
  margin-bottom: .15rem; position: relative;
  white-space: nowrap; overflow: hidden;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-icon { width: 20px; height: 20px; flex-shrink: 0; }

.badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: .7rem; font-weight: 700; padding: .1rem .45rem;
  border-radius: 999px; min-width: 20px; text-align: center;
}
.badge-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); margin-left: auto;
}

.sidebar-footer {
  padding: .75rem;
  border-top: 1px solid rgba(255,255,255,.08);
}
.user-mini {
  display: flex; align-items: center; gap: .65rem;
  padding: .5rem .75rem; border-radius: var(--radius-sm);
  overflow: hidden;
}
.user-mini-info { flex: 1; overflow: hidden; }
.user-mini-info span { display: block; font-size: .8rem; }
.user-mini-info .role-badge {
  font-size: .7rem; color: rgba(199,210,254,.5);
}

/* ── TOPBAR ────────────────────────────────────────────── */
.main-wrap {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--transition);
}
.sidebar.collapsed ~ .main-wrap { margin-left: 70px; }

.topbar {
  height: var(--topbar-h);
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
  transition: background var(--transition);
}
.topbar-left { display: flex; align-items: center; gap: 1rem; }
.topbar-right { display: flex; align-items: center; gap: .75rem; }
.page-title { font-size: 1.15rem; font-weight: 600; color: var(--text); }
.topbar-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem; cursor: pointer;
  flex-shrink: 0;
}

/* ── PAGE CONTENT ──────────────────────────────────────── */
.page-content { flex: 1; padding: 1.5rem; overflow-y: auto; }

/* ── AVATAR ────────────────────────────────────────────── */
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem; flex-shrink: 0;
}
.avatar.sm { width: 28px; height: 28px; font-size: .75rem; }

/* ── CARDS ─────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  transition: background var(--transition), border-color var(--transition);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; padding-bottom: .75rem;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 1rem; font-weight: 600; }

/* ── STATS GRID ────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex; align-items: center; gap: 1rem;
  box-shadow: var(--shadow);
  transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon {
  width: 48px; height: 48px; border-radius: .75rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; flex-shrink: 0;
}
.stat-icon.blue   { background: #EFF6FF; }
.stat-icon.green  { background: #ECFDF5; }
.stat-icon.purple { background: #F5F3FF; }
.stat-icon.orange { background: #FFF7ED; }
.stat-icon.red    { background: #FEF2F2; }
[data-theme="dark"] .stat-icon.blue   { background: #1E3A5F; }
[data-theme="dark"] .stat-icon.green  { background: #064E3B; }
[data-theme="dark"] .stat-icon.purple { background: #2E1065; }
[data-theme="dark"] .stat-icon.orange { background: #431407; }
[data-theme="dark"] .stat-icon.red    { background: #450A0A; }

.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .8rem; color: var(--text-2); margin-top: .25rem; }

/* ── GRID ──────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
@media (max-width: 1024px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ── TABLE ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%; border-collapse: collapse;
  font-size: .875rem;
}
thead th {
  text-align: left; padding: .75rem 1rem;
  font-size: .75rem; font-weight: 600; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .05em;
  background: var(--bg); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: .875rem 1rem; border-bottom: 1px solid var(--border);
  color: var(--text); vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg); }

/* ── BADGES / CHIPS ────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center;
  padding: .2rem .65rem; border-radius: 999px;
  font-size: .75rem; font-weight: 600; white-space: nowrap;
}
.chip-success { background: #DCFCE7; color: #166534; }
.chip-warning { background: #FEF9C3; color: #854D0E; }
.chip-danger  { background: #FEE2E2; color: #991B1B; }
.chip-info    { background: #DBEAFE; color: #1E40AF; }
.chip-purple  { background: #F3E8FF; color: #6B21A8; }
.chip-gray    { background: #F1F5F9; color: #475569; }
[data-theme="dark"] .chip-success { background: #14532D; color: #86EFAC; }
[data-theme="dark"] .chip-warning { background: #422006; color: #FDE68A; }
[data-theme="dark"] .chip-danger  { background: #450A0A; color: #FCA5A5; }
[data-theme="dark"] .chip-info    { background: #1E3A5F; color: #93C5FD; }
[data-theme="dark"] .chip-gray    { background: #1E293B; color: #94A3B8; }

/* ── BUTTONS ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1.1rem; border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 600; cursor: pointer;
  border: none; transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary {
  background: var(--primary); color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #DC2626; }
.btn-success { background: var(--success); color: #fff; }
.btn-full { width: 100%; justify-content: center; padding: .75rem; }
.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-icon {
  background: none; border: none; cursor: pointer;
  color: var(--text-2); padding: .4rem; border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
  display: inline-flex; align-items: center;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

.btn-spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── FORMS ─────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block; margin-bottom: .4rem;
  font-size: .85rem; font-weight: 500; color: var(--text);
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%; padding: .6rem .875rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg2); color: var(--text);
  font-size: .875rem; transition: border-color var(--transition);
  outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}
.form-group textarea { resize: vertical; min-height: 100px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.input-icon-wrap { position: relative; }
.input-icon-wrap input { padding-right: 2.5rem; }
.toggle-pass {
  position: absolute; right: .75rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: var(--text-3);
  font-size: 1rem;
}

/* ── ALERTS ────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem; border-radius: var(--radius-sm);
  font-size: .875rem; margin-bottom: 1rem;
}
.alert-error { background: #FEE2E2; color: #991B1B; border: 1px solid #FCA5A5; }
.alert-success { background: #DCFCE7; color: #166534; border: 1px solid #86EFAC; }
.alert-info { background: #DBEAFE; color: #1E40AF; border: 1px solid #93C5FD; }
[data-theme="dark"] .alert-error { background: #450A0A; color: #FCA5A5; border-color: #7F1D1D; }
[data-theme="dark"] .alert-success { background: #14532D; color: #86EFAC; border-color: #166534; }

/* ── MODAL ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5); backdrop-filter: blur(4px);
  z-index: 200; display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%; max-width: 560px;
  max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity:0; transform: scale(.95); } to { opacity:1; transform: scale(1); } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.modal-body { padding: 1.5rem; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex; gap: .75rem; justify-content: flex-end;
  padding: 1rem 1.5rem; border-top: 1px solid var(--border);
}

/* ── TOAST ─────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  z-index: 300; display: flex; flex-direction: column; gap: .5rem;
}
.toast {
  display: flex; align-items: center; gap: .75rem;
  padding: .875rem 1.25rem; border-radius: var(--radius-sm);
  min-width: 280px; max-width: 380px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .25s ease;
  font-size: .875rem; font-weight: 500;
}
@keyframes toastIn { from { opacity:0; transform: translateX(100%); } to { opacity:1; transform: translateX(0); } }
.toast-success { background: #DCFCE7; color: #166534; border-left: 4px solid var(--success); }
.toast-error   { background: #FEE2E2; color: #991B1B; border-left: 4px solid var(--danger); }
.toast-info    { background: #DBEAFE; color: #1E40AF; border-left: 4px solid var(--info); }

/* ── PAGINATION ────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem; font-size: .875rem; color: var(--text-2);
  border-top: 1px solid var(--border);
}
.pagination-pages { display: flex; gap: .25rem; }
.page-btn {
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); cursor: pointer; font-size: .875rem;
  background: none; border: 1px solid var(--border); color: var(--text);
  transition: all var(--transition);
}
.page-btn:hover, .page-btn.active {
  background: var(--primary); border-color: var(--primary); color: #fff;
}

/* ── SEARCH BAR ────────────────────────────────────────── */
.search-bar {
  display: flex; gap: .75rem; flex-wrap: wrap;
  margin-bottom: 1rem; align-items: center;
}
.search-input-wrap { position: relative; flex: 1; min-width: 200px; }
.search-input-wrap input { padding-left: 2.25rem; }
.search-icon {
  position: absolute; left: .75rem; top: 50%; transform: translateY(-50%);
  color: var(--text-3); font-size: .9rem; pointer-events: none;
}

/* ── EMPTY STATE ───────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 3rem 1rem;
  color: var(--text-2);
}
.empty-state .icon { font-size: 3rem; margin-bottom: .75rem; }
.empty-state p { font-size: .9rem; }

/* ── LOADING ───────────────────────────────────────────── */
.loading {
  display: flex; align-items: center; justify-content: center;
  padding: 3rem; color: var(--text-2);
}
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin-right: .75rem;
}

/* ── STATUS CHIPS ──────────────────────────────────────── */
.status-new        { @extend .chip; background:#EFF6FF; color:#1D4ED8; }
.status-verifying  { background:#FEF9C3; color:#854D0E; }
.status-qualified  { background:#F0FDF4; color:#166534; }
.status-processing { background:#F5F3FF; color:#6B21A8; }
.status-shipped    { background:#DBEAFE; color:#1E40AF; }
.status-delivered  { background:#DCFCE7; color:#166534; }
.status-received   { background:#F0FDF4; color:#15803D; }
.status-refund     { background:#FFF7ED; color:#C2410C; }
.status-cancelled  { background:#FEE2E2; color:#991B1B; }

/* ── RESPONSIVE ────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .main-wrap { margin-left: 0 !important; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .page-content { padding: 1rem; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .auth-card { padding: 1.75rem 1.25rem; }
}

/* ── CHART CONTAINER ───────────────────────────────────── */
.chart-container { position: relative; height: 280px; width: 100%; }

/* ── TABS ──────────────────────────────────────────────── */
.tabs { display: flex; gap: .25rem; border-bottom: 2px solid var(--border); margin-bottom: 1.5rem; }
.tab {
  padding: .65rem 1.1rem; font-size: .875rem; font-weight: 500;
  cursor: pointer; border-bottom: 2px solid transparent;
  color: var(--text-2); margin-bottom: -2px; transition: color var(--transition);
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── COLOR PICKER ──────────────────────────────────────── */
.color-input-wrap { display: flex; align-items: center; gap: .75rem; }
.color-input-wrap input[type="color"] {
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); padding: 2px; cursor: pointer;
}
