:root {
  --primary: #7c3aed;
  --primary-dark: #6d28d9;
  --purple: #8B5CF6;
  --green: #84CC16;
  --red: #EF4444;
  --orange: #F97316;
  --danger: #dc3545;
  --success: #28a745;
  --bg: #f5f6fa;
  --card: #ffffff;
  --border: #e0e3e8;
  --text: #1f2430;
  --muted: #6b7280;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* Login */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(135deg, #1e1b2e 0%, #2d1b3d 100%);
}
.login-box {
  background: var(--card); padding: 40px; border-radius: 12px;
  width: 100%; max-width: 380px; box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.logo-area { text-align: center; margin-bottom: 24px; }
.login-logo { width: 90px; height: 90px; object-fit: contain; margin-bottom: 12px; }
.logo-area h1 { font-size: 2.4rem; letter-spacing: 4px; display: inline-flex; }
.tagline { color: var(--muted); margin-top: 4px; }
.login-box form { display: flex; flex-direction: column; gap: 12px; }
.login-box input {
  padding: 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 1rem;
}
.login-box input:focus { outline: none; border-color: var(--primary); }
.login-box button {
  padding: 12px; background: var(--primary); color: #fff; border: none;
  border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.login-box button:hover { background: var(--primary-dark); }
.error-msg { color: var(--danger); text-align: center; min-height: 20px; font-size: 0.9rem; }

/* Topbar */
.topbar {
  background: #fff; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 60px; position: sticky; top: 0; z-index: 100;
}
.topbar-brand { display: flex; align-items: center; gap: 12px; }
.brand-link { display: flex; align-items: center; gap: 8px; text-decoration: none; color: inherit; }
.topbar-logo { width: 40px; height: 40px; object-fit: contain; }
.brand-text { font-weight: 800; font-size: 1.4rem; letter-spacing: 2px; display: flex; }
.letter-s { color: var(--purple); }
.letter-y { color: var(--green); }
.letter-x { color: var(--red); }
.letter-l { color: var(--orange); }
.brand-sub { color: var(--muted); font-size: 0.85rem; }
.topbar-links { display: flex; align-items: center; gap: 6px; }
.topbar-links a {
  text-decoration: none; font-size: 0.95rem; padding: 6px 12px;
  border-radius: 6px; font-weight: 600; color: var(--text);
}
.topbar-links a:hover { background: var(--bg); }
.topbar-links a.active { color: #fff; background: var(--primary); }
.btn-link { background: none; border: none; color: var(--text); cursor: pointer; font-size: 0.95rem; padding: 6px 10px; }
.btn-link:hover { background: var(--bg); }
.btn-link.active { color: #fff; background: var(--primary); }

/* Container */
.container { max-width: 1100px; margin: 0 auto; padding: 24px 20px; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card {
  background: var(--card); border-radius: 10px; padding: 20px; box-shadow: var(--shadow);
  border-top: 3px solid var(--primary);
}
.stat-value { font-size: 2rem; font-weight: 800; color: var(--text); }
.stat-label { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }
.progress-card { border-top-color: var(--success); }
.stat-label { display: inline-flex; align-items: center; gap: 6px; }
.edit-target-btn {
  background: none; border: none; cursor: pointer; color: var(--primary);
  font-size: 0.85rem; padding: 0 4px; border-radius: 4px;
}
.edit-target-btn:hover { background: rgba(26,115,232,0.1); }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }
.data-table thead { background: #f8f9fb; }
.data-table th { text-align: left; padding: 12px 14px; font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafbfc; }
.data-table a { color: var(--primary); text-decoration: none; font-weight: 500; }
.data-table .empty { text-align: center; color: var(--muted); padding: 30px; }

/* WhatsApp button */
.phone { font-weight: 600; color: var(--text); }
.call-link { text-decoration: none; }
.call-link:hover { color: var(--primary); text-decoration: underline; }
.email-link { color: var(--primary); text-decoration: none; }
.email-link:hover { text-decoration: underline; }
.wa-icon {
  display: inline-flex; align-items: center; justify-content: center;
  vertical-align: middle; margin-left: 4px; width: 26px; height: 26px;
  background: #25d366; color: #fff; border-radius: 50%; font-size: 0.85rem;
  text-decoration: none;
}
.wa-icon:hover { background: #1ebe57; }
.wa-btn {
  display: inline-block; background: #25d366; color: #fff !important;
  padding: 6px 12px; border-radius: 6px; font-size: 0.82rem;
  font-weight: 600; text-decoration: none; white-space: nowrap;
}
.wa-btn:hover { background: #1ebe57; }

/* Badges */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
.stage-new-lead { background: #eef2ff; color: #4338ca; }
.stage-contacted { background: #f0f9ff; color: #0369a1; }
.stage-interested { background: #ecfeff; color: #0e7490; }
.stage-interview-scheduled { background: #fef3c7; color: #92400e; }
.stage-interview-complete { background: #fef9c3; color: #a16207; }
.stage-onboarding { background: #ede9fe; color: #6d28d9; }
.stage-ride-along, .stage-on-road { background: #dcfce7; color: #15803d; }
.stage-rejected, .stage-withdrawn { background: #fee2e2; color: #b91c1c; }

/* Source */
.src-facebook, .src-instagram, .src-tiktok, .src-linkedin, .src-referral,
.src-whatsapp, .src-phone, .src-indeed, .src-walk-in, .src-other {
  display: inline-block; padding: 2px 10px; border-radius: 6px; font-size: 0.85rem; font-weight: 600;
}
.src-facebook { background: #e7f3ff; color: #1877f2; }
.src-tiktok { background: #1c1c1e; color: #fff; }
.src-instagram { background: #ffe5f0; color: #c13584; }
.src-linkedin { background: #e8f4fd; color: #0a66c2; }
.src-referral { background: #dcfce7; color: #15803d; }
.src-whatsapp { background: #dcf8c6; color: #075e54; }
.src-phone { background: #f3e8ff; color: #7c3aed; }
.src-indeed { background: #eef2ff; color: #4338ca; }
.src-walk-in { background: #fef3c7; color: #92400e; }
.src-other { background: #f3f4f6; color: #374151; }

/* Toolbar */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar h2 { margin-right: auto; }
.toolbar input, .toolbar select {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.95rem;
}
.toolbar input { flex: 1; min-width: 180px; }

/* Buttons */
.btn {
  display: inline-block; padding: 10px 16px; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  font-size: 0.95rem; cursor: pointer; text-decoration: none; font-weight: 500;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #b02a37; }
.btn-sm { padding: 4px 9px; font-size: 0.85rem; border-radius: 6px; line-height: 1.2; }
.row-actions { display: flex; gap: 6px; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-weight: 600; font-size: 0.9rem; }
.form-group input, .form-group select, .form-group textarea {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.95rem; font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--primary); }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.success-msg { background: #dcfce7; color: #15803d; padding: 12px; border-radius: 8px; margin-top: 16px; }

/* Two col */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 28px; }
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }
.two-col h2 { font-size: 1.1rem; margin-bottom: 12px; }
.mini-list { background: var(--card); border-radius: 10px; box-shadow: var(--shadow); padding: 16px; }
.mini-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.mini-row:last-child { border-bottom: none; font-weight: 600; }

/* Cards */
.card { background: var(--card); border-radius: 10px; box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card h3 { margin-bottom: 14px; font-size: 1.05rem; }
.card textarea { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 8px; font-family: inherit; margin-bottom: 10px; }

/* Candidate header */
.candidate-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; background: var(--card); border-radius: 10px; box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px; }
.candidate-header h2 { margin-bottom: 6px; }
.muted { color: var(--muted); margin: 4px 0; }
.current-stage { text-align: right; }
.big-badge { font-size: 1rem; padding: 6px 14px; }
.stage-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* Stage selector */
.stage-selector { display: flex; flex-wrap: wrap; gap: 8px; }
.sg-btn {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 20px;
  background: #fff; font-size: 0.85rem; cursor: pointer; font-weight: 500;
}
.sg-btn:hover { border-color: var(--primary); }
.sg-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.sg-btn.selected { background: var(--success); color: #fff; border-color: var(--success); }

/* History */
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item { padding: 10px; border: 1px solid var(--border); border-radius: 8px; }
.history-item small { color: var(--muted); margin-left: 8px; }
.note { margin-top: 6px; color: var(--text); }

/* Hamburger menu */
.nav-toggle {
  display: none; background: none; border: none; cursor: pointer;
  flex-direction: column; justify-content: center; gap: 5px;
  width: 40px; height: 40px; padding: 8px; border-radius: 8px;
}
.nav-toggle span { display: block; width: 24px; height: 3px; background: var(--text); border-radius: 3px; transition: 0.2s; }
.nav-toggle:hover { background: var(--bg); }

/* Table wrapper for horizontal scroll */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; }

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  .container { padding: 16px 12px; }

  /* Topbar / menu */
  .topbar { padding: 0 12px; height: 56px; }
  .topbar-logo { width: 34px; height: 34px; }
  .brand-text { font-size: 1.15rem; }
  .brand-sub { display: none; }
  .nav-toggle { display: flex; }
  .topbar-links {
    position: fixed; top: 56px; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    background: #fff; box-shadow: 0 8px 16px rgba(0,0,0,0.12);
    padding: 8px 12px; display: none; z-index: 200;
  }
  .topbar-links.open { display: flex; }
  .topbar-links a, .topbar-links .btn-link {
    font-size: 1rem; padding: 12px 14px; border-radius: 8px;
  }

  /* Stats */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 1.5rem; }
  .stat-label { font-size: 0.75rem; }

  /* Tables */
  .data-table th, .data-table td { padding: 10px 10px; font-size: 0.85rem; white-space: nowrap; }
  .data-table td { white-space: nowrap; }
  .data-table .cell-wrap { white-space: normal; }

  /* Toolbar / filters */
  .toolbar { gap: 8px; }
  .toolbar h2 { flex: 1 1 100%; }
  .toolbar input, .toolbar select { width: 100%; min-width: 0; font-size: 1rem; padding: 12px; }
  .toolbar .btn { flex: 1; text-align: center; }

  /* Buttons */
  .btn { padding: 12px 16px; font-size: 1rem; }
  .btn-danger, .btn-primary { width: auto; }

  /* Forms */
  .form-grid { grid-template-columns: 1fr; gap: 14px; }
  .form-actions .btn { flex: 1; text-align: center; }

  /* Cards */
  .card { padding: 16px; }
  .candidate-header { flex-direction: column; padding: 18px; }
  .current-stage { text-align: left; }
  .stage-actions { justify-content: flex-start; }
  .stage-actions .btn { flex: 1 1 45%; text-align: center; }

  /* Stage selector */
  .sg-btn { padding: 12px 14px; font-size: 0.9rem; flex: 1 1 45%; text-align: center; }

  /* Login */
  .login-box { padding: 28px 24px; margin: 0 16px; }

  /* WhatsApp */
  .wa-btn { padding: 10px 14px; font-size: 0.9rem; }
}

@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 1.3rem; }
  .brand-text { font-size: 1.05rem; }
}

/* ===== THEME TOGGLE ===== */
#themeToggle {
  background: none; border: 1px solid var(--border); cursor: pointer;
  width: 38px; height: 38px; border-radius: 50%; font-size: 1.05rem;
  display: inline-flex; align-items: center; justify-content: center;
}
#themeToggle:hover { background: var(--bg); }

/* ===== DARK MODE ===== */
body.dark {
  --bg: #0f1117;
  --card: #1a1d27;
  --border: #2d2f3a;
  --text: #e4e6eb;
  --muted: #8b8fa3;
  --shadow: 0 1px 3px rgba(0,0,0,0.5);
}
body.dark .login-body { background: linear-gradient(135deg, #0a0a10 0%, #161121 100%); }
body.dark .login-box input { background: #232632; }
body.dark .topbar { background: #14161e; }
body.dark .data-table thead { background: #1f222d; }
body.dark .data-table tr:hover td { background: #20232f; }
body.dark .mini-list, body.dark .card, body.dark .candidate-header,
body.dark .data-table, body.dark .stat-card, body.dark .mini-row,
body.dark .history-item { background: var(--card); }
body.dark .toolbar input, body.dark .toolbar select,
body.dark .form-group input, body.dark .form-group select, body.dark .form-group textarea,
body.dark .card textarea, body.dark .login-box input, body.dark .search-input,
body.dark .note-input, body.dark .add-note textarea,
body.dark .modal-box input, body.dark .modal-box select, body.dark .modal-box textarea {
  background: #232632; border-color: #343743; color: var(--text);
}
body.dark .btn { background: #232632; border-color: #343743; color: var(--text); }
body.dark .btn:hover { background: #2b2f3d; }
body.dark .btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
body.dark .btn-primary:hover { background: var(--primary-dark); }
body.dark .sg-btn { background: #232632; border-color: #343743; color: var(--text); }
body.dark .sg-btn.active, body.dark .sg-btn.selected { color: #fff; }
body.dark .nav-toggle span { background: var(--text); }
body.dark .wa-btn { color: #fff !important; }
body.dark .src-tiktok { background: #3a3a3e; }
body.dark .src-other { background: #343743; color: #cfd2da; }
body.dark .topbar-links a:hover { background: #20232f; }
body.dark select option { background: #1a1d27; color: var(--text); }
@media (max-width: 768px) {
  body.dark .topbar-links { background: #14161e; }
}

/* ===== FLOATING ACTION BUTTON + QUICK ADD MODAL ===== */
.fab-btn {
  position: fixed; bottom: 24px; right: 24px; z-index: 500;
  width: 58px; height: 58px; border-radius: 50%; border: none;
  background: var(--primary); color: #fff; font-size: 2rem; font-weight: 700;
  cursor: pointer; box-shadow: 0 4px 14px rgba(124,58,237,0.45);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s;
}
.fab-btn:hover { transform: scale(1.08); background: var(--primary-dark); }
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 600;
  background: rgba(0,0,0,0.5); align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.show { display: flex; }
.quick-add {
  background: var(--card); border-radius: 12px; width: 100%; max-width: 440px;
  padding: 24px; box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.qa-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.qa-head strong { font-size: 1.1rem; }
.qa-close { background: none; border: none; font-size: 1.6rem; cursor: pointer; color: var(--muted); line-height: 1; }
.quick-add form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.quick-add form .qa-full { grid-column: 1 / -1; }
.quick-add label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 0.9rem; }
.quick-add input, .quick-add select, .quick-add textarea {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.95rem; font-family: inherit;
}
.qa-actions { display: flex; gap: 10px; margin-top: 8px; }
.qa-actions .btn-secondary, .qa-actions .btn-primary { flex: 1; text-align: center; }
.btn-secondary { background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 10px 16px; border-radius: 8px; cursor: pointer; font-weight: 500; }
.btn-secondary:hover { background: var(--border); }
@media (max-width: 420px) {
  .quick-add form { grid-template-columns: 1fr; }
}

/* ===== TOAST ===== */
#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1f2937; color: #fff; padding: 12px 22px; border-radius: 8px;
  font-size: 0.95rem; box-shadow: 0 6px 16px rgba(0,0,0,0.3);
  opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s; z-index: 700;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== DASHBOARD SEARCH ===== */
.search-wrap { position: relative; max-width: 620px; margin: 0 auto 28px; }
.search-input {
  width: 100%; padding: 14px 18px; font-size: 1rem;
  border: 2px solid var(--border); border-radius: 12px; background: var(--card);
}
.search-input:focus { outline: none; border-color: var(--primary); }
.search-results {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 300;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.15); margin-top: 6px; overflow: hidden;
}
.search-result-item {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border-bottom: 1px solid var(--border); cursor: pointer; text-decoration: none; color: var(--text);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg); }
.sr-name { font-weight: 600; }
.sr-phone { color: var(--muted); font-size: 0.85rem; margin-left: auto; }

/* ===== STUCK / WARNING ===== */
.stuck-badge {
  display: inline-flex; align-items: center; gap: 3px; cursor: help;
  color: #b45309; background: #fef3c7; border-radius: 6px;
  padding: 2px 7px; font-size: 0.78rem; font-weight: 600;
}
body.dark .stuck-badge { background: #3b3a22; color: #fcd34d; }
.followup-section { margin-bottom: 28px; }
.followup-list { display: flex; flex-direction: column; gap: 8px; }
.followup-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: var(--card); border: 1px solid #fcd34d; border-left: 4px solid #f59e0b;
  border-radius: 8px; text-decoration: none; color: var(--text);
}
.followup-item:hover { background: var(--bg); }

/* ===== NOTES ===== */
.notes-list { display: flex; flex-direction: column; gap: 10px; }
.note-item { padding: 10px 14px; border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 8px; }
.note-text { margin-top: 2px; }
.note-meta { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 0.8rem; }
.note-del { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 1rem; }
.add-note { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.add-note textarea { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 8px; font-family: inherit; }

/* ===== INTERVIEW ===== */
.interview-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.interview-row input[type="datetime-local"] {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.95rem; font-family: inherit;
}
.interview-indicator {
  display: inline-flex; align-items: center; gap: 4px; background: #ede9fe; color: #6d28d9;
  border-radius: 6px; padding: 2px 8px; font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
body.dark .interview-indicator { background: #33264d; color: #c4b5fd; }
body.dark .interview-row input[type="datetime-local"] { background: #232632; border-color: #343743; color: var(--text); }

/* ===== PRINT ===== */
@media print {
  .topbar, .fab-btn, .no-print, .stage-actions, .btn, .stage-selector, .notes-list, .add-note, #toast, .theme-wrap { display: none !important; }
  body { background: #fff; }
  .candidate-header, .card, .print-section { box-shadow: none; border: 1px solid #ddd; }
  .container { max-width: 100%; padding: 0; }
  * { color: #000 !important; }
  a { text-decoration: none; }
  @page { margin: 16mm; }
}
