/* ============================================================
   B2P Teachers CRM — Modern Flat Design
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --navy:    #1B3A6B;
  --blue:    #1976D2;
  --green:   #2E7D32;
  --orange:  #E65100;
  --red:     #C62828;
  --purple:  #6A1B9A;
  --teal:    #00695C;
  --cyan:    #0277BD;

  --sidebar-w: 260px;
  --navbar-h:  58px;
  --bg:        #F4F6FA;
  --surface:   #ffffff;
  --radius:    10px;
  --radius-lg: 14px;
  --text:      #111827;
  --text-2:    #374151;
  --muted:     #6B7280;
  --border:    #E5E7EB;
  --border-2:  #F3F4F6;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:    0 4px 12px rgba(0,0,0,.07), 0 1px 3px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.10), 0 2px 6px rgba(0,0,0,.06);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: .875rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 9px; }
::-webkit-scrollbar-thumb:hover { background: #9CA3AF; }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  z-index: 1050;
  transition: transform .28s cubic-bezier(.4,0,.2,1), width .28s cubic-bezier(.4,0,.2,1);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 18px;
  height: var(--navbar-h);
  border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
  text-decoration: none;
}

.sidebar-logo { height: 36px; width: auto; object-fit: contain; }

.brand-text {
  color: #fff;
  font-weight: 700;
  font-size: .9rem;
  letter-spacing: -.01em;
  display: block;
  line-height: 1.3;
}

.brand-sub {
  color: rgba(255,255,255,.4);
  font-size: .65rem;
  display: block;
  letter-spacing: .25px;
  font-weight: 400;
}

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

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  color: rgba(255,255,255,.6);
  text-decoration: none;
  font-size: .82rem;
  font-weight: 500;
  border-radius: 7px;
  margin-bottom: 1px;
  transition: color .15s, background .15s;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-nav .nav-link:hover {
  color: #fff;
  background: rgba(255,255,255,.08);
}

.sidebar-nav .nav-link.active {
  color: #fff;
  background: rgba(255,255,255,.14);
  font-weight: 600;
}

.sidebar-nav .nav-link .bi {
  font-size: .95rem;
  width: 18px;
  flex-shrink: 0;
  text-align: center;
}

.nav-divider {
  height: 1px;
  background: rgba(255,255,255,.06);
  margin: 6px 2px;
}

.nav-logout { color: rgba(252,165,165,.65) !important; }
.nav-logout:hover { color: #fca5a5 !important; background: rgba(239,68,68,.1) !important; }

/* Mobile overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1040;
}
.sidebar-overlay.active { display: block; }

/* ── Main Content ─────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left .28s cubic-bezier(.4,0,.2,1);
}

/* ── Top Navbar ───────────────────────────────────────────── */
.top-navbar {
  height: var(--navbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 900;
  flex-shrink: 0;
  gap: 12px;
}

.sidebar-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--muted);
  padding: 5px 10px;
  line-height: 1;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.sidebar-toggle:hover {
  background: var(--border-2);
  color: var(--text);
}

.bg-primary-soft { background: #EFF6FF !important; }

/* ── Page Header ──────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0 18px;
  flex-wrap: wrap;
  gap: 12px;
}

/* ── Stat Cards ───────────────────────────────────────────── */
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: box-shadow .2s, transform .2s;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  border-radius: 3px 0 0 3px;
}

.stat-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

a.stat-card { color: inherit; }

.stat-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  letter-spacing: -.02em;
}

.stat-label {
  font-size: .68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
  margin-top: 3px;
}

.stat-sub { font-size: .72rem; color: var(--muted); margin-top: 2px; }

.sc-navy   { } .sc-navy::before   { background: var(--navy);   } .sc-navy   .stat-icon-wrap { background: #EBF0FA; color: var(--navy);   }
.sc-blue   { } .sc-blue::before   { background: var(--blue);   } .sc-blue   .stat-icon-wrap { background: #EFF6FF; color: var(--blue);   }
.sc-green  { } .sc-green::before  { background: var(--green);  } .sc-green  .stat-icon-wrap { background: #F0FDF4; color: var(--green);  }
.sc-orange { } .sc-orange::before { background: var(--orange); } .sc-orange .stat-icon-wrap { background: #FFF7ED; color: var(--orange); }
.sc-red    { } .sc-red::before    { background: var(--red);    } .sc-red    .stat-icon-wrap { background: #FFF1F2; color: var(--red);    }
.sc-purple { } .sc-purple::before { background: var(--purple); } .sc-purple .stat-icon-wrap { background: #FAF5FF; color: var(--purple); }
.sc-teal   { } .sc-teal::before   { background: var(--teal);   } .sc-teal   .stat-icon-wrap { background: #F0FDFA; color: var(--teal);   }
.sc-cyan   { } .sc-cyan::before   { background: var(--cyan);   } .sc-cyan   .stat-icon-wrap { background: #F0F9FF; color: var(--cyan);   }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-sm);
  background: var(--surface);
}

.card-header {
  background: var(--surface) !important;
  border-bottom: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
  padding: 14px 20px;
  font-weight: 600;
  font-size: .82rem;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .4px;
}

.card-body { padding: 20px; }
.card-body.p-0 { padding: 0 !important; }

.card-footer {
  border-top: 1px solid var(--border) !important;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg) !important;
  background: var(--surface) !important;
  padding: 12px 20px;
}

/* ── Tables ───────────────────────────────────────────────── */
.table {
  font-size: .82rem;
  --bs-table-hover-bg: #F9FAFB;
}

.table th {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  background: #FAFAFA;
  border-bottom: 1px solid var(--border) !important;
  padding: 10px 16px;
  white-space: nowrap;
}

.table td {
  padding: 11px 16px;
  border-color: var(--border-2) !important;
  vertical-align: middle;
  color: var(--text-2);
}

.table-hover tbody tr:hover td { background: #F9FAFB; }
.clickable-row { cursor: pointer; }

/* ── Forms ────────────────────────────────────────────────── */
.form-control, .form-select {
  border-color: var(--border);
  border-radius: 8px;
  font-size: .85rem;
  color: var(--text);
  box-shadow: none !important;
  transition: border-color .15s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--blue);
  background: #fff;
}
.form-label { font-size: .78rem; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.input-group-text {
  background: var(--border-2);
  border-color: var(--border);
  color: var(--muted);
  font-size: .85rem;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  font-size: .82rem;
  font-weight: 600;
  border-radius: 8px;
  letter-spacing: .01em;
  transition: all .15s;
}

.btn-primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.btn-primary:hover, .btn-primary:focus {
  background: #1565C0;
  border-color: #1565C0;
  color: #fff;
}

.btn-success {
  background: var(--green);
  border-color: var(--green);
}
.btn-success:hover { background: #256427; border-color: #256427; }

.btn-outline-primary { color: var(--blue); border-color: var(--blue); }
.btn-outline-primary:hover { background: var(--blue); color: #fff; }

.btn-outline-secondary { color: var(--muted); border-color: var(--border); }
.btn-outline-secondary:hover { background: var(--border-2); color: var(--text); border-color: var(--border); }

.btn-outline-danger { color: var(--red); border-color: #FECACA; }
.btn-outline-danger:hover { background: #FFF1F2; border-color: var(--red); color: var(--red); }

/* ── Badges ───────────────────────────────────────────────── */
.badge { font-weight: 600; letter-spacing: .2px; border-radius: 6px; }

.category-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.cat-high   { background: #DCFCE7; color: #166534; }
.cat-medium { background: #FEF3C7; color: #92400E; }
.cat-low    { background: #FEE2E2; color: #991B1B; }
.cat-new    { background: #DBEAFE; color: #1E40AF; }

.source-badge-meta     { background: #1877F2 !important; font-size: .68rem; }
.source-badge-manual   { background: #6B7280 !important; font-size: .68rem; }
.source-badge-excel    { background: #166534 !important; font-size: .68rem; }
.source-badge-whatsapp { background: #16A34A !important; color: #fff !important; font-size: .68rem; }

.status-badge { font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; border-radius: 6px; }
.status-new            { background: #DBEAFE !important; color: #1E40AF !important; }
.status-contacted      { background: #CFFAFE !important; color: #155E75 !important; }
.status-qualified      { background: #EDE9FE !important; color: #5B21B6 !important; }
.status-demo_scheduled { background: #E0E7FF !important; color: #3730A3 !important; }
.status-interested     { background: #DCFCE7 !important; color: #166534 !important; }
.status-not_interested { background: #FEE2E2 !important; color: #991B1B !important; }
.status-converted      { background: #CCFBF1 !important; color: #134E4A !important; }

/* ── Lead Avatar ──────────────────────────────────────────── */
.lead-avatar {
  width: 68px; height: 68px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--blue) 0%, var(--navy) 100%);
  color: #fff;
  font-size: 1.8rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -.02em;
}

/* ── Score Ring ───────────────────────────────────────────── */
.score-ring {
  width: 88px; height: 88px;
  border-radius: 50%;
  border: 5px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.score-ring.score-high   { border-color: #16A34A; }
.score-ring.score-medium { border-color: #D97706; }
.score-ring.score-low    { border-color: var(--red); }
.score-ring.score-new    { border-color: var(--blue); }
.score-fill-high   { background: #16A34A; }
.score-fill-medium { background: #D97706; }
.score-fill-low    { background: var(--red); }
.score-fill-new    { background: var(--blue); }
.score-number { font-size: 1.5rem; font-weight: 800; line-height: 1; letter-spacing: -.03em; }

/* ── Progress ─────────────────────────────────────────────── */
.progress { border-radius: 99px; background: var(--border-2); }
.progress-bar { border-radius: 99px; }

/* ── Alerts ───────────────────────────────────────────────── */
.alert {
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: .83rem;
}
.alert-success { background: #F0FDF4; border-color: #BBF7D0; color: #166534; }
.alert-danger  { background: #FFF1F2; border-color: #FECDD3; color: #9F1239; }
.alert-warning { background: #FFFBEB; border-color: #FDE68A; color: #92400E; }
.alert-info    { background: #F0F9FF; border-color: #BAE6FD; color: #075985; }

/* ── Conversation ─────────────────────────────────────────── */
.conversation-container {
  max-height: 400px;
  overflow-y: auto;
  padding: 16px;
  background: #FAFAFA;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.chat-message { display: flex; flex-direction: column; margin-bottom: 12px; }
.chat-message.outbound { align-items: flex-end; }
.chat-message.inbound  { align-items: flex-start; }
.chat-bubble {
  max-width: 70%;
  padding: 9px 14px;
  font-size: .83rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.outbound .chat-bubble {
  background: var(--navy);
  color: #fff;
  border-radius: 12px 12px 3px 12px;
}
.inbound .chat-bubble {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px 12px 12px 3px;
  color: var(--text);
}
.chat-time { font-size: .65rem; color: #9CA3AF; margin-top: 4px; }

/* ── Follow-up ────────────────────────────────────────────── */
.followup-list { padding-left: 14px; border-left: 2px solid var(--border); }
.followup-item { padding: 10px 0; border-bottom: 1px solid var(--border-2); }
.followup-item:last-child { border-bottom: none; }

/* ── Search Dropdown ──────────────────────────────────────── */
.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  overflow: hidden;
}
.search-result-item {
  display: block;
  padding: 10px 16px;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border-2);
  transition: background .12s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--border-2); color: var(--text); }
.search-result-footer { padding: 9px 16px; background: var(--border-2); border-top: 1px solid var(--border); }

/* ── Score mini-bar ───────────────────────────────────────── */
.score-mini-bar { display: inline-block; vertical-align: middle; }

/* ── Login ────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.login-logo-img { height: 72px; width: auto; object-fit: contain; }

/* ── Animations ───────────────────────────────────────────── */
@keyframes statFlash { 0%{background:#EFF6FF} 100%{background:transparent} }
.stat-updated { animation: statFlash .8s ease; }

/* ── Pagination ───────────────────────────────────────────── */
.page-link {
  border-color: var(--border);
  color: var(--text-2);
  font-size: .8rem;
  font-weight: 500;
  border-radius: 7px !important;
  margin: 0 2px;
  padding: 5px 10px;
}
.page-item.active .page-link {
  background: var(--blue);
  border-color: var(--blue);
}
.page-link:hover { background: var(--border-2); color: var(--text); border-color: var(--border); }

/* ── Misc utilities ───────────────────────────────────────── */
.font-monospace { font-family: 'SFMono-Regular', Consolas, monospace !important; }
.text-navy { color: var(--navy) !important; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 6px 0 24px rgba(0,0,0,.2);
  }
  .main-content { margin-left: 0 !important; }
  .page-header { padding: 16px 0 12px; }
  .stat-value { font-size: 1.45rem; }
  .stat-icon-wrap { width: 42px; height: 42px; font-size: 1.05rem; }
  .login-card { padding: 28px 22px; }
  .card-body { padding: 14px; }
  .table th, .table td { padding: 9px 12px; }
}

/* ── Collapsed sidebar (desktop) ─────────────────────────── */
.sidebar.collapsed { width: 60px; }
.sidebar.collapsed .brand-text,
.sidebar.collapsed .brand-sub,
.sidebar.collapsed .nav-link span { display: none; }
.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 0; }
.sidebar.collapsed .sidebar-logo { height: 26px; }
.sidebar.collapsed .nav-link { justify-content: center; padding: 10px 0; gap: 0; }
.main-content.expanded { margin-left: 60px; }
