/* =========================================
   WHX Nairobi 2026 - Campaign Tracker
   ========================================= */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #0D47A1;
  --primary-light: #1565C0;
  --primary-dark: #002171;
  --accent: #FF6F00;
  --accent-light: #FFA040;
  --bg: #f0f2f5;
  --sidebar-bg: #0D1B2A;
  --sidebar-text: #8ba0b8;
  --sidebar-hover: #1B2838;
  --sidebar-active: #0D47A1;
  --card-bg: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

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

/* --- App Layout --- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  width: 250px;
  min-width: 250px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: white;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand svg { color: var(--accent); }

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: var(--sidebar-text);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
  border-left: 3px solid transparent;
  position: relative;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: white;
}

.nav-item.active {
  background: rgba(13, 71, 161, 0.2);
  color: white;
  border-left-color: var(--accent);
}

.nav-item svg { flex-shrink: 0; }

.badge-new {
  background: var(--accent);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 8px;
  margin-left: auto;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
}

.user-name { font-size: 13px; font-weight: 600; color: white; }
.user-role { font-size: 11px; color: var(--sidebar-text); }

.logout-btn {
  display: block;
  text-align: center;
  padding: 8px;
  background: rgba(255,255,255,0.06);
  border-radius: 6px;
  color: var(--sidebar-text);
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
}

.logout-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

/* --- Main Content --- */
.main-content {
  margin-left: 250px;
  flex: 1;
  padding: 24px 32px;
  min-height: 100vh;
  min-width: 0;
  overflow-x: hidden;
}

.main-content-full {
  flex: 1;
  min-height: 100vh;
}

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

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

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

/* --- Cards --- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

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

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

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

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.stat-card .stat-icon {
  position: absolute;
  right: 16px;
  top: 16px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.15;
}

.stat-card .stat-icon svg { width: 24px; height: 24px; }

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.stat-change {
  font-size: 12px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

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

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
}

/* --- Tables --- */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:hover { background: #f8fafc; }

/* --- Status Badges --- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-processing { background: #fef3c7; color: #b45309; }
.badge-pending { background: #f3f4f6; color: #6b7280; }
.badge-cancelled { background: #f3f4f6; color: #9ca3af; }
.badge-delivered { background: #dbeafe; color: #1d4ed8; }
.badge-not-contacted { background: #f3f4f6; color: #6b7280; }
.badge-sent { background: #dbeafe; color: #1d4ed8; }
.badge-opened { background: #e0f2fe; color: #0369a1; }
.badge-replied { background: #dcfce7; color: #15803d; }
.badge-meeting { background: #fef3c7; color: #b45309; }
.badge-quote { background: #ede9fe; color: #7c3aed; }
.badge-won { background: #10b981; color: white; }
.badge-lost { background: #fee2e2; color: #dc2626; }
.badge-unresponsive { background: #f3f4f6; color: #9ca3af; }

/* Priority badges */
.priority-very-high { color: var(--danger); font-weight: 700; }
.priority-high { color: var(--warning); font-weight: 600; }
.priority-medium { color: var(--primary); font-weight: 500; }
.priority-low { color: var(--text-muted); }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); color: white; }

.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: var(--accent-light); color: white; }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { opacity: 0.9; color: white; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; color: white; }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn:disabled, .btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

/* --- Filters --- */
.filters {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
}

.filters select, .filters input, .btn-filter {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: white;
  color: var(--text);
}

.filters select:focus, .filters input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13,71,161,0.1);
}

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

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

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: white;
  transition: border-color 0.15s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13,71,161,0.1);
}

textarea.form-control {
  min-height: 100px;
  resize: vertical;
  font-family: inherit;
}

select.form-control { cursor: pointer; }

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

@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
}

.form-help {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* --- Email Templates --- */
.template-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  max-height: 600px;
  overflow-y: auto;
  padding: 4px;
}

.template-card {
  border: 1.5px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  background: var(--card-bg);
  position: relative;
}

.template-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  opacity: 0;
  transition: opacity 0.25s;
}

.template-card:hover::before {
  opacity: 1;
}

.template-card:hover {
  border-color: var(--primary);
  box-shadow: 0 8px 25px rgba(13,71,161,0.12);
  transform: translateY(-3px);
}

.template-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13,71,161,0.15), 0 4px 12px rgba(13,71,161,0.1);
}

.template-card-wave {
  padding: 7px 16px;
  font-size: 11px;
  font-weight: 700;
  color: white;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.template-card-wave::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255,255,255,0.2);
}

.template-card-body {
  padding: 16px 18px 18px;
}

.template-card-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  margin: 8px 0 5px;
  line-height: 1.3;
}

.template-card-subject {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 12px;
  padding: 6px 8px;
  background: #f8fafc;
  border-radius: 6px;
  border-left: 3px solid var(--border);
}

.template-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.template-tag {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Placeholder warning inline styles */
.placeholder-warning {
  animation: warnSlideIn 0.3s ease;
}

@keyframes warnSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Pipeline (Kanban-ish) --- */
.pipeline {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.pipeline-item {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: center;
  border-top: 3px solid var(--border);
}

.pipeline-item.very-high { border-top-color: var(--danger); }
.pipeline-item.high { border-top-color: var(--warning); }
.pipeline-item.medium { border-top-color: var(--primary); }
.pipeline-item.completed { border-top-color: var(--success); }

.pipeline-item .pipeline-value {
  font-size: 28px;
  font-weight: 700;
}

.pipeline-item .pipeline-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* --- Login Page --- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0D1B2A 0%, #0D47A1 100%);
}

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

.login-card h1 {
  font-size: 24px;
  margin-bottom: 4px;
  text-align: center;
}

.login-card .login-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 14px;
}

.login-error {
  background: #fef2f2;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
  text-align: center;
}

/* --- Alerts --- */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}

.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.alert-error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.alert-info { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* --- Toast Notification --- */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: 10px;
  color: white;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }

/* --- Pipeline (engagement stages) --- */
.stage-pipeline {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.stage-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
  background: var(--border);
}

.stage-dot.active { background: var(--primary); }
.stage-dot.done { background: var(--success); }
.stage-dot.lost { background: var(--danger); }
.stage-dot.current { background: var(--warning); animation: pulse 2s infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(245, 158, 11, 0); }
}

.stage-connector {
  width: 16px;
  height: 2px;
  background: var(--border);
}

.stage-connector.done { background: var(--success); }

/* --- Engagement Timeline --- */
.timeline {
  position: relative;
  padding-left: 30px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  margin-bottom: 20px;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -24px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid white;
  box-shadow: 0 0 0 2px var(--primary);
}

.timeline-item.inbound::before { background: var(--success); box-shadow: 0 0 0 2px var(--success); }

.timeline-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.timeline-title {
  font-weight: 600;
  font-size: 14px;
}

.timeline-body {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* --- Modal --- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

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

.modal {
  background: white;
  border-radius: 16px;
  padding: 28px;
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h2 { font-size: 18px; }
.modal-close {
  width: 32px; height: 32px;
  border: none;
  background: var(--bg);
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* --- Loading Spinner --- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Responsive --- */
@media (max-width: 768px) {
  .sidebar {
    width: 60px;
    min-width: 60px;
  }
  .sidebar-brand span, .sidebar-nav .nav-item span, .sidebar-user .user-info, .sidebar-footer .logout-btn {
    display: none;
  }
  .sidebar-nav .nav-item { justify-content: center; padding: 14px; }
  .main-content { margin-left: 60px; padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .pipeline { grid-template-columns: repeat(2, 1fr); }
}

/* --- Lead detail header --- */
.lead-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
}

.lead-header-info h1 { font-size: 24px; margin-bottom: 4px; }
.lead-header-info .lead-meta { font-size: 14px; color: var(--text-muted); }

.lead-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.lead-actions .btn { white-space: nowrap; }

/* --- Email page compose / template grid --- */
.email-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 900px) {
  .email-layout { grid-template-columns: 1fr; }
}



/* --- Inbox --- */
.email-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.email-item {
  padding: 14px 16px;
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.1s;
}

.email-item:hover { border-color: var(--primary); }
.email-item.unread { border-left: 3px solid var(--primary); background: #f8faff; }

.email-item .email-subject { font-weight: 600; font-size: 14px; }
.email-item .email-from { font-size: 13px; color: var(--text-muted); }
.email-item .email-preview { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.email-item .email-date { font-size: 11px; color: var(--text-muted); }
.email-item .email-lead { font-size: 11px; font-weight: 600; color: var(--primary); }

/* --- Country badge --- */
.country-flag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: #f3f4f6;
  color: var(--text-muted);
}
