/* ═══════════════════════════════════════════
   Car Analytics Dashboard — CSS Design System
   Color Palette: Yellow → Cream → Pink
   ═══════════════════════════════════════════ */

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

/* ── CSS Variables ─────────────────────────── */
:root {
  --yellow:       #FFD93D;
  --yellow-light: #FFE78A;
  --cream:        #FFF4B8;
  --cream-light:  #FFFCE8;
  --pink:         #E84393;
  --pink-light:   #FF6B8A;
  --pink-soft:    #FFB8C9;

  --bg-main:      #FFF9E6;
  --bg-sidebar:   #FFF4B8;
  --bg-card:      #FFFFFF;
  --bg-input:     #FFFDF0;
  --bg-hover:     #FFF0C0;

  --text-primary:   #2D2D2D;
  --text-secondary: #6B6B6B;
  --text-muted:     #A0A0A0;
  --text-on-pink:   #FFFFFF;
  --text-on-yellow: #5A4800;

  --border:       #F0E6B8;
  --border-light: #F5EDCC;

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.06);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg:  0 8px 30px rgba(0,0,0,0.10);
  --shadow-card: 0 2px 16px rgba(232,67,147,0.06);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --sidebar-w: 260px;
  --header-h:  64px;
  --transition: 0.25s cubic-bezier(.4,0,.2,1);
}

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

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; font-family: inherit; }
input, select { font-family: inherit; }

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

/* ── Sidebar ───────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: linear-gradient(180deg, var(--cream) 0%, var(--bg-sidebar) 100%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  box-shadow: 2px 0 20px rgba(0,0,0,0.04);
}

.sidebar-logo {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo .logo-icon {
  width: 46px; height: 46px;
  background: linear-gradient(135deg, var(--pink), var(--pink-light));
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(232,67,147,0.25);
}

.sidebar-logo .logo-text h1 {
  font-size: 15px; font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

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

.sidebar-section-label {
  padding: 20px 20px 8px;
  font-size: 9px; font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
}

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

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 4px;
  position: relative;
}

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

.nav-item.active {
  background: linear-gradient(135deg, var(--pink), var(--pink-light));
  box-shadow: 0 4px 16px rgba(232,67,147,0.3);
}

.nav-item.active .nav-icon,
.nav-item.active .nav-label,
.nav-item.active .nav-sub {
  color: #FFF !important;
}

.nav-item::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 0;
  background: var(--pink);
  border-radius: 0 3px 3px 0;
  transition: height var(--transition);
}

.nav-item.active::before { height: 60%; background: #FFF; }

.nav-icon {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 16px;
  background: rgba(255,255,255,0.5);
  flex-shrink: 0;
}

.nav-item.active .nav-icon { background: rgba(255,255,255,0.2); }

.nav-label {
  font-size: 12px; font-weight: 600;
  color: var(--text-primary);
}

.nav-sub {
  font-size: 9px; color: var(--text-muted);
  margin-top: 1px;
}

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

.db-status {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 10px; font-weight: 600;
}

.db-status.connected {
  background: rgba(42,157,143,0.1);
  color: #2A9D8F;
}

.db-status .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #2A9D8F;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Font Awesome Icon Overrides ───────────── */
.logo-icon i { color: #FFF; font-size: 20px; }
.nav-icon i { font-size: 14px; color: var(--text-secondary); }
.nav-item.active .nav-icon i { color: #FFF; }
.kpi-icon i { font-size: 20px; }
.kpi-card:nth-child(1) .kpi-icon i { color: var(--pink); }
.kpi-card:nth-child(2) .kpi-icon i { color: #E9A820; }
.kpi-card:nth-child(3) .kpi-icon i { color: var(--pink-light); }
.kpi-card:nth-child(4) .kpi-icon i { color: #D4A017; }
.db-status i.dot { font-size: 7px; }
.btn i { font-size: 12px; }
.tab-btn i { margin-right: 4px; }
.modal-icon i { color: #FFF; font-size: 16px; }
.search-icon i { font-size: 13px; color: var(--text-muted); }

/* ── Main Content ──────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Page Header ───────────────────────────── */
.page-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow-sm);
  position: relative;
}

.page-header::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--pink), var(--yellow));
}

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

.page-header .header-badge {
  padding: 6px 14px;
  background: linear-gradient(135deg, var(--pink), var(--pink-light));
  color: #FFF;
  border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.5px;
}

.page-header h2 {
  font-size: 18px; font-weight: 700;
  letter-spacing: -0.3px;
}

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

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

/* ── Page Content ──────────────────────────── */
.page-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

.page { display: none; }
.page.active { display: block; animation: fadeIn 0.35s ease; }

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

/* ── KPI Cards ─────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  transition: all var(--transition);
}

.kpi-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--pink-soft);
}

.kpi-card::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 80px; height: 80px;
  border-radius: 0 0 0 80px;
  opacity: 0.08;
}

.kpi-card:nth-child(1)::after { background: var(--pink); }
.kpi-card:nth-child(2)::after { background: var(--yellow); }
.kpi-card:nth-child(3)::after { background: var(--pink-light); }
.kpi-card:nth-child(4)::after { background: var(--yellow); }

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

.kpi-card .kpi-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}

.kpi-card:nth-child(1) .kpi-icon { background: rgba(232,67,147,0.12); }
.kpi-card:nth-child(2) .kpi-icon { background: rgba(255,217,61,0.2); }
.kpi-card:nth-child(3) .kpi-icon { background: rgba(255,107,138,0.12); }
.kpi-card:nth-child(4) .kpi-icon { background: rgba(255,217,61,0.2); }

.kpi-card .kpi-bar {
  width: 3px; height: 20px;
  border-radius: 2px;
}

.kpi-card:nth-child(1) .kpi-bar { background: var(--pink); }
.kpi-card:nth-child(2) .kpi-bar { background: var(--yellow); }
.kpi-card:nth-child(3) .kpi-bar { background: var(--pink-light); }
.kpi-card:nth-child(4) .kpi-bar { background: var(--yellow); }

.kpi-card .kpi-label {
  font-size: 11px; color: var(--text-muted); font-weight: 500;
  margin-bottom: 4px;
}

.kpi-card .kpi-value {
  font-size: 26px; font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.kpi-card .kpi-subtitle {
  font-size: 10px; color: var(--text-muted); margin-top: 4px;
}

/* ── Chart Cards ───────────────────────────── */
.chart-row {
  display: grid;
  gap: 16px;
  margin-bottom: 24px;
}

.chart-row.two-cols { grid-template-columns: 3fr 2fr; }
.chart-row.equal    { grid-template-columns: 1fr 1fr; }

.chart-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.chart-card .chart-header {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
}

.chart-card .chart-header .accent-bar {
  width: 3px; height: 16px;
  border-radius: 2px;
  background: var(--pink);
}

.chart-card .chart-header h3 {
  font-size: 12px; font-weight: 700;
  color: var(--text-secondary);
}

.chart-card .chart-body {
  padding: 16px;
  position: relative;
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-card .chart-body canvas {
  max-width: 100%;
  max-height: 320px;
}

/* ── Buttons ───────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600;
  transition: all var(--transition);
  border: 1px solid transparent;
}

.btn-primary {
  background: linear-gradient(135deg, var(--pink), var(--pink-light));
  color: #FFF;
  box-shadow: 0 2px 8px rgba(232,67,147,0.25);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(232,67,147,0.35);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-secondary:hover { background: var(--bg-hover); }

.btn-danger {
  background: #E63946;
  color: #FFF;
}

.btn-danger:hover { background: #C1121F; }

.btn-success {
  background: #2A9D8F;
  color: #FFF;
}

.btn-info {
  background: #457B9D;
  color: #FFF;
}

/* ── Toolbar ───────────────────────────────── */
.toolbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  padding: 12px 24px;
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
}

.search-box {
  display: flex; align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  gap: 8px;
  transition: border-color var(--transition);
}

.search-box:focus-within { border-color: var(--pink); }

.search-box .search-icon { color: var(--text-muted); font-size: 14px; }

.search-box input {
  border: none; outline: none;
  background: transparent;
  padding: 9px 0;
  width: 200px;
  font-size: 12px;
  color: var(--text-primary);
}

.search-box input::placeholder { color: var(--text-muted); }

.filter-select {
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}

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

.toolbar-right {
  margin-left: auto;
  display: flex; gap: 8px;
}

/* ── Data Table ────────────────────────────── */
.table-container {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  margin-bottom: 16px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table thead th {
  background: var(--cream-light);
  padding: 12px 14px;
  text-align: left;
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
  white-space: nowrap;
}

.data-table thead th:hover { background: var(--bg-hover); }
.data-table thead th.sorted { color: var(--pink); }

.data-table tbody tr {
  transition: background var(--transition);
  cursor: pointer;
}

.data-table tbody tr:nth-child(even) { background: var(--cream-light); }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr.selected { background: rgba(232,67,147,0.08); }

.data-table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Pagination ────────────────────────────── */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-card);
  border-top: 1px solid var(--border-light);
  font-size: 11px;
}

.pagination .page-info { color: var(--text-muted); font-weight: 500; }

.pagination .page-controls {
  display: flex; align-items: center; gap: 8px;
}

.pagination .page-btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11px; font-weight: 600;
  transition: all var(--transition);
}

.pagination .page-btn:hover { background: var(--bg-hover); }
.pagination .page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.pagination .page-current {
  font-weight: 700;
  color: var(--pink);
}

/* ── Tab Bar ───────────────────────────────── */
.tab-bar {
  display: flex; gap: 6px;
  padding: 12px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
}

.tab-btn {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.tab-btn:hover { background: var(--bg-hover); }

.tab-btn.active {
  background: linear-gradient(135deg, var(--pink), var(--pink-light));
  color: #FFF;
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(232,67,147,0.25);
}

/* ── Modal ─────────────────────────────────── */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

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

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  width: 520px;
  max-height: 85vh;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; gap: 12px;
  position: relative;
}

.modal-header::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--pink);
}

.modal-header .modal-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--pink), var(--pink-light));
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}

.modal-header h3 { font-size: 15px; font-weight: 700; }

.modal-header .close-btn {
  margin-left: auto;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--bg-input);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  color: var(--text-muted);
  transition: all var(--transition);
}

.modal-header .close-btn:hover {
  background: #FCE4E6; color: #E63946;
}

.modal-body {
  padding: 20px 24px;
  max-height: 60vh;
  overflow-y: auto;
}

.form-group { margin-bottom: 14px; }

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

.form-group input, .form-group select {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  font-size: 12px;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition);
}

.form-group input:focus, .form-group select:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(232,67,147,0.1);
}

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

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-light);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ── Insights Cards ────────────────────────── */
.insights-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Loading Spinner ───────────────────────── */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--pink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 10px;
}

/* ── Scrollbar ─────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ────────────────────────────── */
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-row.two-cols, .chart-row.equal { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform var(--transition); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .kpi-grid { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-right { margin-left: 0; }
}

/* ── Table overflow ────────────────────────── */
.table-scroll { overflow-x: auto; }

/* ── Empty State ───────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 13px; }
