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

:root {
  --bg: hsl(210 33% 98%);
  --foreground: hsl(215 28% 17%);
  --card: hsl(0 0% 100%);
  --card-border: hsl(214 32% 91%);
  --primary: #04071D;
  --accent: #155eef;
  --accent-light: hsla(220 88% 52% / 0.08);
  --green: #10b981;
  --green-bg: hsla(160 64% 39% / 0.08);
  --red: #ef4444;
  --red-bg: hsla(0 84% 60% / 0.08);
  --amber: #f59e0b;
  --amber-bg: hsla(38 92% 50% / 0.08);
  --muted: hsl(210 20% 95%);
  --muted-foreground: hsl(215 16% 47%);
  --border: hsl(214 32% 91%);
  --radius: 8px;
  --radius-lg: 12px;
  --gold-gradient: linear-gradient(135deg, #1898ff, #155eef);
  --sidebar-background: #04071D;
  --sidebar-foreground: #e4ecff;
  --sidebar-border: #0C1327;
  --sidebar-accent: #0E162A;
}

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--foreground);
  min-height: 100vh;
}

/* ─── LOADING OVERLAY ─── */
.loading-overlay {
  position: fixed; inset: 0; background: var(--primary); z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: opacity 0.4s ease;
}
.loading-overlay.fade-out { opacity: 0; pointer-events: none; }
.loading-logo { font-size: 28px; font-weight: 700; color: #fff; margin-bottom: 24px; }
.loading-logo span { color: var(--accent); }
.loading-bar-wrap { width: 240px; height: 4px; background: #1a2040; border-radius: 4px; overflow: hidden; margin-bottom: 16px; }
.loading-bar-fill { height: 100%; width: 0%; background: var(--gold-gradient); border-radius: 4px; transition: width 0.3s ease; }
.loading-text { font-size: 13px; color: #8b8fa3; letter-spacing: 0.5px; }

/* ─── SIDEBAR ─── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 240px;
  background: var(--sidebar-background); color: var(--sidebar-foreground);
  display: flex; flex-direction: column; z-index: 50;
  border-right: 1px solid var(--sidebar-border);
}
.sidebar-brand { padding: 24px 20px 20px; border-bottom: 1px solid var(--sidebar-border); }
.sidebar-brand-row { display: flex; align-items: center; gap: 12px; }
.sidebar-logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--gold-gradient);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.sidebar-brand-text { display: flex; flex-direction: column; }
.sidebar-brand-name { font-size: 11px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: #fff; line-height: 1.3; }
.sidebar-brand-sub { font-size: 10px; font-weight: 500; letter-spacing: .8px; text-transform: uppercase; color: var(--accent); margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav .nav-label {
  font-size: 9px; font-weight: 700; letter-spacing: 1.5px;
  text-transform: uppercase; color: hsla(210 20% 78% / 0.4);
  padding: 14px 14px 6px; margin-top: 4px;
}
.sidebar-nav .tab-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 14px; border-radius: 8px; border: none;
  background: transparent; color: var(--sidebar-foreground);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all .15s; font-family: inherit; text-align: left;
  text-decoration: none;
}
.sidebar-nav .tab-btn:hover { background: var(--sidebar-accent); color: #fff; }
.sidebar-nav .tab-btn.active { background: var(--sidebar-accent); color: var(--accent); font-weight: 600; }
.sidebar-nav .tab-btn .nav-icon { width: 20px; text-align: center; font-size: 15px; flex-shrink: 0; opacity: .7; }
.sidebar-nav .tab-btn.active .nav-icon { opacity: 1; }

.sidebar-user {
  padding: 16px; border-top: 1px solid var(--sidebar-border);
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--gold-gradient);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: #fff; flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-info .user-display-name { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-info .user-role { font-size: 11px; color: var(--sidebar-foreground); opacity: 0.6; }

/* ─── LAYOUT ─── */
.app-page { display: flex; min-height: 100vh; }
.main-content-area { margin-left: 240px; flex: 1; min-height: 100vh; }

.top-bar {
  padding: 20px 28px; border-bottom: 1px solid var(--border);
  background: var(--card); display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.top-bar-title { font-size: 18px; font-weight: 700; color: var(--foreground); }
.top-bar-sub { font-size: 13px; color: var(--muted-foreground); margin-top: 2px; }
.top-bar-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.content { padding: 24px 28px; max-width: 1400px; width: 100%; }

/* ─── TOGGLE FILTER ─── */
.toggle-label {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 6px 14px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--card); transition: all 0.2s; user-select: none;
}
.toggle-label:hover { border-color: var(--accent); }
.toggle-label input[type="checkbox"] {
  width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer;
}
.toggle-text { font-size: 13px; color: var(--foreground); font-weight: 500; white-space: nowrap; }

/* ─── DATE CONTROLS ─── */
.date-controls { display: flex; gap: 8px; align-items: center; }
.date-controls label { font-size: 13px; color: var(--muted-foreground); }
.date-controls input[type="date"] {
  background: var(--card); border: 1px solid var(--border); color: var(--foreground);
  padding: 6px 10px; border-radius: 6px; font-size: 13px; font-family: inherit;
}
.date-controls select {
  background: var(--card); border: 1px solid var(--border); color: var(--foreground);
  padding: 8px 28px 8px 12px; border-radius: 6px; font-size: 13px; cursor: pointer;
  appearance: none; -webkit-appearance: none; font-family: inherit;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 6l3.5 3.5L11.5 6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}
.date-controls select:focus { outline: none; border-color: var(--accent); }
.custom-dates { display: none; }
.custom-dates.show { display: flex; gap: 8px; align-items: center; }

/* ─── BUTTONS ─── */
.btn {
  background: var(--accent); color: #fff; border: none;
  padding: 8px 16px; border-radius: 6px; cursor: pointer;
  font-size: 13px; font-weight: 600; transition: all 0.2s; font-family: inherit;
}
.btn:hover { opacity: 0.9; }
.btn-outline {
  background: transparent; border: 1px solid var(--border); color: var(--muted-foreground);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

/* ─── KPI CARDS ─── */
.funnel-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px; margin-bottom: 24px;
}
.kpi-card {
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--radius-lg); padding: 20px; text-align: center;
  position: relative; box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.kpi-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0;
  height: 2px; background: var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.kpi-card .kpi-label {
  font-size: 11px; color: var(--muted-foreground); text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: 8px; font-weight: 600;
}
.kpi-card .kpi-value { font-size: 30px; font-weight: 700; color: var(--foreground); }
.kpi-card .kpi-sub { font-size: 12px; color: var(--muted-foreground); margin-top: 4px; }

.kpi-card.highlight::before { background: var(--gold-gradient); height: 3px; }
.kpi-card.highlight { border-color: hsla(220 88% 52% / 0.2); }
.kpi-card.highlight .kpi-value { color: var(--accent); }

.kpi-card.green .kpi-value { color: var(--green); }
.kpi-card.green::before { background: var(--green); }
.kpi-card.red .kpi-value { color: var(--red); }
.kpi-card.red::before { background: var(--red); }
.kpi-card.gold .kpi-value { color: var(--amber); }
.kpi-card.gold::before { background: var(--amber); }

/* ─── INFO TOOLTIP ─── */
.kpi-info-btn {
  position: absolute; top: 10px; right: 10px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--muted); border: 1px solid var(--border);
  color: var(--muted-foreground); font-size: 11px; font-weight: 700;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; line-height: 1;
}
.kpi-info-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.kpi-info-tooltip {
  display: none; position: absolute; top: 36px; right: 6px;
  background: var(--card-solid, var(--card)); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
  font-size: 12px; color: var(--foreground); line-height: 1.5;
  z-index: 200; width: 240px; text-align: left;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
.kpi-info-tooltip.show { display: block; }
.kpi-info-tooltip .tip-title {
  font-weight: 700; color: var(--foreground); margin-bottom: 6px;
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.3px;
}
.kpi-info-tooltip ul { margin: 0; padding-left: 16px; }
.kpi-info-tooltip li { margin-bottom: 3px; }

/* ─── FUNNEL VISUAL ─── */
.funnel-visual {
  display: flex; align-items: center; justify-content: center; gap: 0;
  margin-bottom: 24px; padding: 20px;
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--radius-lg); box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  position: relative; overflow: hidden;
}
.funnel-visual::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0;
  height: 2px; background: var(--gold-gradient);
}
.funnel-step { text-align: center; flex: 1; padding: 12px 8px; }
.funnel-step .step-value { font-size: 24px; font-weight: 700; color: var(--foreground); }
.funnel-step .step-label {
  font-size: 11px; color: var(--muted-foreground); margin-top: 4px;
  text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;
}
.funnel-step .step-rate { font-size: 11px; color: var(--accent); margin-top: 2px; font-weight: 600; }
.funnel-arrow { color: var(--border); font-size: 20px; flex-shrink: 0; }
.funnel-bar { height: 4px; margin-top: 8px; border-radius: 2px; background: var(--muted); }
.funnel-bar-fill {
  height: 100%; border-radius: 2px;
  background: var(--gold-gradient);
  transition: width 0.6s ease;
}

/* ─── TABS (filter pills) ─── */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; flex-wrap: wrap; }
.tab {
  padding: 8px 18px; border-radius: 6px; font-size: 13px; font-weight: 500;
  cursor: pointer; background: transparent; border: 1px solid var(--border);
  color: var(--muted-foreground); transition: all 0.2s; font-family: inherit;
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tab:hover:not(.active) { border-color: var(--accent); color: var(--accent); }

/* ─── VIEW PANELS ─── */
.view-panel { display: none; }
.view-panel.active { display: block; }

/* ─── TABLE ─── */
.table-wrap {
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.table-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 8px;
}
.search-box {
  background: var(--bg); border: 1px solid var(--border); color: var(--foreground);
  padding: 8px 12px; border-radius: 6px; font-size: 13px; width: 280px; font-family: inherit;
}
.search-box::placeholder { color: #aaa; }
.search-box:focus { outline: none; border-color: var(--accent); }
.count-badge {
  background: var(--muted); color: var(--muted-foreground);
  padding: 4px 12px; border-radius: 12px; font-size: 12px; font-weight: 500;
}

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: 10px 14px; font-size: 11px; color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border);
  cursor: pointer; white-space: nowrap; user-select: none; font-weight: 600;
  background: var(--bg);
}
thead th:hover { color: var(--foreground); }
tbody td {
  padding: 10px 14px; font-size: 13px; border-bottom: 1px solid var(--muted);
  white-space: nowrap; color: var(--foreground);
}
tbody tr:hover { background: hsla(210 33% 98% / 0.6); }
tbody tr:last-child td { border-bottom: none; }

/* ─── BADGES ─── */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 10px;
  font-size: 11px; font-weight: 600;
}
.badge-lead { background: var(--muted); color: var(--muted-foreground); }
.badge-booked { background: var(--accent-light); color: var(--accent); }
.badge-qualified { background: var(--green-bg); color: var(--green); }
.badge-review { background: #fef3c7; color: #d97706; }
.badge-score { background: #ede9fe; color: #7c3aed; font-weight: 700; }
.badge-dq { background: var(--red-bg); color: var(--red); }
.badge-nosub { background: var(--muted); color: var(--muted-foreground); }
.badge-sold { background: var(--amber-bg); color: var(--amber); }
.badge-yes { background: var(--green-bg); color: var(--green); }
.badge-no { background: var(--muted); color: #ccc; }

/* ─── SPINNER ─── */
.loading { text-align: center; padding: 60px; color: var(--muted-foreground); }
.spinner {
  display: inline-block; width: 32px; height: 32px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── BREAKDOWN CHARTS ─── */
.breakdown-section {
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--radius-lg); padding: 24px; margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04); position: relative; overflow: hidden;
}
.breakdown-section::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0;
  height: 2px; background: var(--gold-gradient);
}
.breakdown-title { font-size: 16px; font-weight: 700; color: var(--foreground); margin-bottom: 20px; }
.bar-chart { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: flex; align-items: center; gap: 12px; }
.bar-label {
  width: 180px; font-size: 13px; color: var(--foreground); flex-shrink: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500;
}
.bar-track {
  flex: 1; height: 28px; background: var(--muted); border-radius: 6px;
  overflow: hidden; position: relative; cursor: pointer;
}
.bar-fill {
  height: 100%; border-radius: 6px; transition: width 0.5s ease;
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 8px; min-width: 36px;
}
.bar-fill span { font-size: 12px; font-weight: 700; color: #fff; }
.bar-pct { width: 50px; text-align: right; font-size: 13px; color: var(--muted-foreground); flex-shrink: 0; }

.breakdown-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px; margin-top: 16px;
}
.summary-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; text-align: center;
}
.summary-card .sc-val { font-size: 24px; font-weight: 700; color: var(--foreground); }
.summary-card .sc-label {
  font-size: 11px; color: var(--muted-foreground); margin-top: 4px;
  text-transform: uppercase; font-weight: 600;
}

/* ─── FILTER ROW ─── */
.filter-row { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.filter-row label { font-size: 13px; color: var(--muted-foreground); font-weight: 500; }
.filter-select {
  background: var(--bg); border: 1px solid var(--border); color: var(--foreground);
  padding: 8px 12px; border-radius: 6px; font-size: 13px; cursor: pointer;
  min-width: 200px; font-family: inherit;
}
.filter-select:focus { outline: none; border-color: var(--accent); }

/* ─── RESPONSIVE ─── */
@media (max-width: 1100px) {
  .funnel-row { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 900px) {
  .sidebar { display: none; }
  .main-content-area { margin-left: 0; }
}
@media (max-width: 700px) {
  .funnel-row { grid-template-columns: repeat(2, 1fr); }
  .top-bar { flex-direction: column; gap: 12px; align-items: flex-start; }
  .content { padding: 16px; }
}