:root {
  --primary: #0F172A;
  --accent: #2563EB;
  --success: #16A34A;
  --sidebar-width: 260px;
}

* { box-sizing: border-box; }

/* Prevent white flash on page load */
html { background: #0F172A; }

body {
  font-family: 'Segoe UI', sans-serif;
  background: #F1F5F9;
  margin: 0; padding: 0;
  overflow-x: hidden;
  /* Smooth fade in on load */
  animation: pageFadeIn 0.25s ease;
}

@keyframes pageFadeIn {
  from { opacity: 0.4; }
  to   { opacity: 1; }
}

.wrapper { display: flex; width: 100%; min-height: 100vh; }

/* ===================== SIDEBAR ===================== */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--primary);
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 999;
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 20px rgba(0,0,0,0.25);
  /* NO transition on sidebar itself — prevents blink */
}

#sidebar.active {
  transform: translateX(calc(-1 * var(--sidebar-width)));
  transition: transform 0.3s ease;
}

/* Logo */
#sidebar .sidebar-header {
  padding: 18px 20px 14px;
  background: #1E293B;
  flex-shrink: 0;
  border-bottom: 2px solid #2563EB;
}
#sidebar .sidebar-header h3 {
  color: #fff;
  font-size: 1.05rem;
  margin: 0 0 2px;
  font-weight: 700;
}
#sidebar .sidebar-header small { color: #64748B; font-size: 0.72rem; }

/* Scrollable menu */
#sidebar .sidebar-menu {
  flex: 1 1 auto;
  overflow-y: scroll;
  overflow-x: hidden;
  height: calc(100vh - 72px);
  padding-bottom: 20px;
  scrollbar-width: thin;
  scrollbar-color: #3B82F6 #1E293B;
}
#sidebar .sidebar-menu::-webkit-scrollbar { width: 6px; }
#sidebar .sidebar-menu::-webkit-scrollbar-track { background: #1E293B; }
#sidebar .sidebar-menu::-webkit-scrollbar-thumb {
  background: #3B82F6;
  border-radius: 6px;
  min-height: 40px;
}
#sidebar .sidebar-menu::-webkit-scrollbar-thumb:hover { background: #60A5FA; }

#sidebar ul.components { list-style: none; padding: 8px 0; margin: 0; }

.sidebar-section {
  display: block;
  padding: 12px 16px 4px;
  color: #475569;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 700;
}

/* Menu links - smooth hover, NO blink */
#sidebar ul li a {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  color: #94A3B8;
  text-decoration: none;
  font-size: 0.86rem;
  gap: 10px;
  border-left: 3px solid transparent;
  /* Smooth transition ONLY on color/bg, not layout */
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, padding-left 0.18s ease;
  will-change: background, color;
}
#sidebar ul li a i {
  width: 18px;
  font-size: 0.85rem;
  flex-shrink: 0;
  text-align: center;
  transition: color 0.18s ease;
}
#sidebar ul li a span { flex: 1; }

/* Hover - smooth, no flash */
#sidebar ul li a:hover {
  background: rgba(37,99,235,0.18);
  color: #E2E8F0;
  border-left-color: #3B82F6;
  padding-left: 22px;
}

/* Active - bold highlight */
#sidebar ul li a.active {
  background: linear-gradient(90deg, rgba(37,99,235,0.35) 0%, rgba(37,99,235,0.15) 100%);
  color: #fff;
  border-left-color: #3B82F6;
  font-weight: 600;
}
#sidebar ul li a.active i { color: #60A5FA; }

/* ===================== CONTENT ===================== */
#content {
  margin-left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
  min-height: 100vh;
}
#content.full { margin-left: 0; width: 100%; }

/* NAVBAR */
.navbar {
  box-shadow: 0 2px 10px rgba(0,0,0,0.12);
  position: sticky;
  top: 0;
  z-index: 100;
}

/* ===================== STAT CARDS ===================== */
.stat-card {
  border: none;
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  background: #fff;
}
.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.1);
}
.stat-card .icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; color: #fff; flex-shrink: 0;
}
.stat-card .value {
  font-size: 1.5rem; font-weight: 700;
  color: var(--primary); line-height: 1.2;
}
.stat-card .label { color: #64748B; font-size: 0.8rem; margin-top: 2px; }

/* ===================== TABLE CARDS ===================== */
.table-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  overflow: hidden;
}
.table-card .card-header {
  background: var(--primary);
  color: #fff;
  padding: 12px 18px;
  font-weight: 600;
  font-size: 0.88rem;
}
.table thead th {
  background: #F8FAFC;
  color: #475569;
  font-size: 0.77rem;
  text-transform: uppercase;
  border: none;
  padding: 10px 14px;
}
.table tbody td {
  padding: 10px 14px;
  vertical-align: middle;
  border-color: #F1F5F9;
  font-size: 0.86rem;
}
.table tbody tr {
  transition: background 0.12s ease;
}
.table tbody tr:hover { background: #F8FAFC; }

/* ===================== BADGES ===================== */
.badge-new      { background: #DBEAFE; color: #1D4ED8; }
.badge-contacted{ background: #FEF3C7; color: #92400E; }
.badge-converted{ background: #DCFCE7; color: #166534; }
.badge-lost     { background: #FEE2E2; color: #991B1B; }
.badge-followup { background: #EDE9FE; color: #5B21B6; }

/* ===================== FORMS ===================== */
.form-card {
  background: #fff;
  border-radius: 12px;
  padding: 22px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
.form-label { font-weight: 600; font-size: 0.82rem; color: #374151; }
.form-control, .form-select {
  border-radius: 8px;
  border: 1.5px solid #E2E8F0;
  font-size: 0.87rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
.btn { transition: all 0.18s ease; }
.btn-primary { background: var(--accent); border-color: var(--accent); border-radius: 8px; }
.btn-primary:hover { background: #1D4ED8; border-color: #1D4ED8; transform: translateY(-1px); }
.btn-xs { padding: 3px 8px; font-size: 0.74rem; border-radius: 5px; }

/* ===================== LOGIN ===================== */
.login-wrapper {
  min-height: 100vh;
  background: linear-gradient(135deg, #0F172A 0%, #1E3A5F 100%);
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 40px;
  width: 100%; max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: slideUp 0.35s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.login-logo {
  font-size: 2rem; font-weight: 800;
  color: var(--accent); text-align: center; margin-bottom: 8px;
}

/* Page transition overlay - prevents white flash */
#page-loader {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #0F172A;
  z-index: 9999;
  pointer-events: none;
  animation: loaderFade 0.3s ease 0.05s forwards;
  opacity: 1;
}
@keyframes loaderFade {
  from { opacity: 1; }
  to   { opacity: 0; visibility: hidden; }
}

/* ===================== MOBILE ===================== */
@media (max-width: 768px) {
  #sidebar {
    transform: translateX(calc(-1 * var(--sidebar-width)));
    transition: transform 0.3s ease;
  }
  #sidebar.active { transform: translateX(0); }
  #content { margin-left: 0; width: 100%; }
  .stat-card .value { font-size: 1.2rem; }
  .container-fluid { padding: 12px !important; }
}

/* ===================== ALERTS - No flash on close ===================== */
.alert {
  transition: opacity 0.5s ease, max-height 0.5s ease, padding 0.5s ease, margin 0.5s ease;
  max-height: 200px;
  overflow: hidden;
}
.alert-dismissible .btn-close {
  transition: opacity 0.2s ease;
}
