/* ============================================
   EV Market Dynamics – BI Dashboard
   Design System & Styles (Refined)
   ============================================ */

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

/* ── Light Theme ──────────────────────────── */
:root {
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --primary-soft: rgba(30, 64, 175, 0.07);
  --accent: #047857;
  --accent-light: #10b981;
  --accent-soft: rgba(4, 120, 87, 0.07);
  --warning: #b45309;
  --warning-soft: rgba(180, 83, 9, 0.07);
  --danger: #dc2626;
  --purple: #6d28d9;
  --purple-soft: rgba(109, 40, 217, 0.07);
  --teal: #0e7490;
  --teal-soft: rgba(14, 116, 144, 0.07);

  --bg-body: #f8f9fb;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-header: rgba(248, 249, 251, 0.92);
  --bg-hover: #f3f4f6;
  --bg-input: #ffffff;
  --bg-muted: #f3f4f6;

  --border: #e5e7eb;
  --border-light: #f3f4f6;

  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.07);

  --sidebar-width: 240px;
  --header-height: 56px;
  --radius: 8px;
  --radius-lg: 10px;
  --transition: 0.2s ease;
}

/* ── Dark Theme ───────────────────────────── */
[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-light: #60a5fa;
  --primary-soft: rgba(59, 130, 246, 0.1);
  --accent: #10b981;
  --accent-light: #34d399;
  --accent-soft: rgba(16, 185, 129, 0.1);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.08);
  --purple: #8b5cf6;
  --purple-soft: rgba(139, 92, 246, 0.1);
  --teal: #06b6d4;
  --teal-soft: rgba(6, 182, 212, 0.1);

  --bg-body: #0f1117;
  --bg-sidebar: #161822;
  --bg-card: #1c1e2a;
  --bg-header: rgba(15, 17, 23, 0.92);
  --bg-hover: rgba(255, 255, 255, 0.04);
  --bg-input: #1c1e2a;
  --bg-muted: rgba(255, 255, 255, 0.04);

  --border: rgba(255, 255, 255, 0.07);
  --border-light: rgba(255, 255, 255, 0.04);

  --text-primary: #e5e7eb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.35);
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.55;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 600;
  line-height: 1.3;
}

::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 3px;
}

/* ════════════════════════════════════════════
   LAYOUT
   ════════════════════════════════════════════ */

.app-container {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-brand h2 {
  font-size: 13px;
  font-weight: 600;
}

.sidebar-brand span {
  font-size: 10.5px;
  color: var(--text-muted);
  font-weight: 400;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 1px;
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 450;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  position: relative;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 550;
}

.nav-item .nav-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 13px;
  opacity: 0.7;
}

.nav-item.active .nav-icon {
  opacity: 1;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.sidebar-footer-text {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
}

/* ── Main ─────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  transition: margin-left 0.3s ease;
}

/* ── Header ───────────────────────────────── */
.header {
  height: var(--header-height);
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-header);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}

.header-title h1 {
  font-size: 15px;
  font-weight: 600;
}

.header-title span {
  font-size: 11px;
  color: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Theme Toggle */
.theme-toggle {
  width: 42px;
  height: 24px;
  background: var(--border);
  border-radius: 12px;
  cursor: pointer;
  border: none;
  position: relative;
  transition: background var(--transition);
}

.theme-toggle::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  width: 20px;
  height: 20px;
  background: var(--bg-card);
  border-radius: 50%;
  transition: left var(--transition);
  box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .theme-toggle {
  background: var(--primary);
}

[data-theme="dark"] .theme-toggle::after {
  left: 20px;
}

.theme-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-right: 2px;
  user-select: none;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-select {
  padding: 5px 10px;
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-input);
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
}

.filter-select:focus {
  border-color: var(--primary);
}

.btn-download {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: opacity var(--transition);
}

.btn-download:hover {
  opacity: 0.85;
}

/* ════════════════════════════════════════════
   PAGE
   ════════════════════════════════════════════ */

.page-content {
  padding: 24px;
}

.page-section {
  display: none;
}

.page-section.active {
  display: block;
  animation: fadeUp 0.3s ease;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.section-header {
  margin-bottom: 20px;
}

.section-header h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 2px;
}

.section-header p {
  font-size: 13px;
  color: var(--text-muted);
}

/* ════════════════════════════════════════════
   GRIDS
   ════════════════════════════════════════════ */

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.grid-5 {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
}

/* ════════════════════════════════════════════
   CARDS
   ════════════════════════════════════════════ */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

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

.card-header h3 {
  font-size: 13px;
  font-weight: 600;
}

/* ── KPI Cards ────────────────────────────── */
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: box-shadow var(--transition);
}

.kpi-card:hover {
  box-shadow: var(--shadow-md);
}

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.kpi-icon {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.kpi-icon.blue {
  background: var(--primary-soft);
  color: var(--primary);
}

.kpi-icon.green {
  background: var(--accent-soft);
  color: var(--accent);
}

.kpi-icon.amber {
  background: var(--warning-soft);
  color: var(--warning);
}

.kpi-icon.purple {
  background: var(--purple-soft);
  color: var(--purple);
}

.kpi-icon.teal {
  background: var(--teal-soft);
  color: var(--teal);
}

.kpi-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.kpi-change {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 500;
  margin-top: 6px;
  color: var(--accent);
}

/* ── Chart Card ───────────────────────────── */
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.chart-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}

.chart-card .chart-subtitle {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.chart-container {
  position: relative;
  width: 100%;
  height: 260px;
}

.chart-container.tall {
  height: 340px;
}

.chart-container.short {
  height: 200px;
}

/* ── Insight Box ──────────────────────────── */
.insight-box {
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-top: 16px;
  border-left: 3px solid var(--primary);
}

.insight-box h4 {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.insight-box p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.65;
}

/* Summary Panel */
.summary-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  border-left: 3px solid var(--primary);
}

.summary-panel p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}

/* ════════════════════════════════════════════
   METRIC BADGES
   ════════════════════════════════════════════ */

.metric-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-muted);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.metric-badge.blue {
  color: var(--primary);
}

.metric-badge.green {
  color: var(--accent);
}

.metric-badge.red {
  color: var(--danger);
}

/* ════════════════════════════════════════════
   SEGMENTS
   ════════════════════════════════════════════ */

.segment-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: box-shadow var(--transition);
}

.segment-card:hover {
  box-shadow: var(--shadow-md);
}

.segment-card .segment-number {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 12px;
}

.segment-card:nth-child(1) .segment-number {
  background: var(--primary);
}

.segment-card:nth-child(2) .segment-number {
  background: var(--accent);
}

.segment-card:nth-child(3) .segment-number {
  background: var(--warning);
}

.segment-card:nth-child(4) .segment-number {
  background: var(--purple);
}

.segment-card h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

.segment-card .segment-traits {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.55;
}

.segment-card .segment-strategy {
  font-size: 12px;
  background: var(--bg-muted);
  padding: 10px 12px;
  border-radius: 5px;
  color: var(--text-secondary);
  border-left: 2px solid var(--primary);
  line-height: 1.5;
}

/* ════════════════════════════════════════════
   MODEL METRICS
   ════════════════════════════════════════════ */

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.metric-card {
  text-align: center;
  padding: 16px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.metric-card .metric-val {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
}

.metric-card .metric-name {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 3px;
}

/* ════════════════════════════════════════════
   RECOMMENDATIONS
   ════════════════════════════════════════════ */

.rec-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  transition: box-shadow var(--transition);
}

.rec-card:hover {
  box-shadow: var(--shadow-md);
}

.rec-card .rec-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  margin-bottom: 14px;
}

.rec-card h4 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
}

.rec-card .rec-insight {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.6;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.rec-card .rec-action {
  font-size: 12.5px;
  color: var(--accent);
  font-weight: 500;
  line-height: 1.55;
}

[data-theme="dark"] .rec-card .rec-action {
  color: var(--accent-light);
}

/* ════════════════════════════════════════════
   ABOUT
   ════════════════════════════════════════════ */

.about-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
}

.about-card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.about-card p,
.about-card li {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.65;
}

.about-card ul {
  list-style: none;
  padding: 0;
}

.about-card ul li {
  padding: 4px 0 4px 16px;
  position: relative;
}

.about-card ul li::before {
  content: '›';
  position: absolute;
  left: 0;
  color: var(--primary);
  font-weight: 700;
}

.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.team-member {
  background: var(--bg-muted);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
}

.team-member .member-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  margin: 0 auto 8px;
}

.team-member h4 {
  font-size: 12.5px;
  font-weight: 600;
}

.team-member p {
  font-size: 11px;
  color: var(--text-muted);
}

/* ════════════════════════════════════════════
   DRIVER TAGS
   ════════════════════════════════════════════ */

.driver-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.driver-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border-radius: 5px;
  font-size: 12.5px;
  font-weight: 500;
  background: var(--primary-soft);
  color: var(--primary);
}

/* ════════════════════════════════════════════
   MAP (Leaflet)
   ════════════════════════════════════════════ */

.map-container {
  width: 100%;
  height: 380px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
}

/* ════════════════════════════════════════════
   HEATMAP TABLE
   ════════════════════════════════════════════ */

.heatmap-container {
  width: 100%;
  overflow-x: auto;
}

.heatmap-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 2px;
  font-size: 11px;
}

.heatmap-table th {
  padding: 6px 4px;
  font-weight: 600;
  font-size: 9.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.2px;
}

.heatmap-table td {
  padding: 6px;
  text-align: center;
  border-radius: 3px;
  font-weight: 500;
  font-size: 10.5px;
}

/* ════════════════════════════════════════════
   SPACING HELPERS
   ════════════════════════════════════════════ */

.mb-12 {
  margin-bottom: 12px;
}

.mb-16 {
  margin-bottom: 16px;
}

.mb-20 {
  margin-bottom: 20px;
}

.mb-24 {
  margin-bottom: 24px;
}

.mt-16 {
  margin-top: 16px;
}

.mt-20 {
  margin-top: 20px;
}

/* ════════════════════════════════════════════
   RESPONSIVE
   ════════════════════════════════════════════ */

@media (max-width: 1024px) {
  .grid-5 {
    grid-template-columns: repeat(3, 1fr);
  }

  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }

  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .main-content {
    margin-left: 0;
  }

  .menu-toggle {
    display: flex;
  }

  .page-content {
    padding: 16px;
  }

  .grid-5,
  .grid-4,
  .grid-3,
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .header {
    padding: 0 14px;
  }

  .filter-bar {
    display: none;
  }
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 99;
}

.sidebar-overlay.active {
  display: block;
}