/* ============================================================
   Omoda Jaecoo Dashboard — Main Stylesheet
   Design: Black + Red brand, clean professional UI
   ============================================================ */

:root {
  --black:       #0a0a0a;
  --red:         #d0021b;
  --red-dark:    #a80016;
  --red-light:   #ff1a35;
  --white:       #ffffff;
  --grey-100:    #f5f5f5;
  --grey-200:    #ebebeb;
  --grey-300:    #d6d6d6;
  --grey-400:    #b0b0b0;
  --grey-600:    #6b6b6b;
  --grey-800:    #2e2e2e;
  --pink-chart:  #e8547a;
  --pink-light:  #f4a0b5;
  --blue-chart:  #3b82f6;
  --blue-light:  #93c5fd;
  --sidebar-w:   220px;
  --header-h:    56px;
  --filter-w:    680px;
  --radius:      8px;
  --shadow:      0 2px 12px rgba(0,0,0,0.10);
  --shadow-lg:   0 4px 24px rgba(0,0,0,0.16);
  --transition:  0.22s ease;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--grey-100);
  color: var(--black);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--grey-200); }
::-webkit-scrollbar-thumb { background: var(--grey-400); border-radius: 3px; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
  min-height: 100vh;
  background: var(--grey-100);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 48px 40px 40px;
  width: 100%;
  max-width: 420px;
}
.login-logo {
  display: block;
  max-width: 260px;
  margin: 0 auto 32px;
}
.login-card h2 {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--grey-600);
  text-align: center;
  margin-bottom: 24px;
}
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--grey-600);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.form-control {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--grey-300);
  border-radius: var(--radius);
  font-size: 0.95rem;
  color: var(--black);
  background: var(--white);
  transition: border-color var(--transition);
  outline: none;
}
.form-control:focus { border-color: var(--black); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 20px; border-radius: var(--radius); font-size: 0.9rem; font-weight: 600; cursor: pointer; border: none; transition: all var(--transition); text-decoration: none; }
.btn-black { background: var(--black); color: var(--white); }
.btn-black:hover { background: var(--grey-800); }
.btn-red { background: var(--red); color: var(--white); }
.btn-red:hover { background: var(--red-dark); }
.btn-outline { background: transparent; color: var(--black); border: 1.5px solid var(--grey-300); }
.btn-outline:hover { border-color: var(--black); }
.btn-full { width: 100%; }
.btn-sm { padding: 7px 14px; font-size: 0.82rem; }
.login-error { background: #fff0f0; border: 1px solid #ffc0c0; color: var(--red); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 0.88rem; }

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  height: var(--header-h);
  background: var(--white);
  border-bottom: 1px solid var(--grey-200);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.header-logo { height: 28px; }
.header-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--grey-100);
  border-radius: 20px;
  padding: 4px 14px;
}
.toggle-label { font-size: 0.88rem; font-weight: 600; color: var(--grey-600); }
.toggle-label.active { color: var(--black); }
.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  cursor: pointer;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--grey-300);
  border-radius: 22px;
  transition: var(--transition);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; bottom: 3px;
  background: var(--white);
  border-radius: 50%;
  transition: var(--transition);
}
.toggle-switch input:checked + .toggle-slider { background: var(--black); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }

.header-nav { display: flex; align-items: center; gap: 4px; }
.header-nav a {
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--grey-600);
  text-decoration: none;
  transition: all var(--transition);
  border-bottom: 2px solid transparent;
}
.header-nav a:hover { color: var(--black); }
.header-nav a.active { color: var(--black); font-weight: 700; border-bottom-color: var(--black); }
.header-spacer { flex: 1; }
.header-upload .btn { padding: 7px 16px; font-size: 0.85rem; }
.header-user {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--black);
  color: var(--white);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  position: relative;
}
.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  display: none;
  z-index: 200;
}
.user-dropdown.open { display: block; }
.user-dropdown a, .user-dropdown button {
  display: block;
  width: 100%;
  padding: 10px 16px;
  text-align: left;
  font-size: 0.88rem;
  color: var(--black);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition);
}
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--grey-100); }
.user-dropdown .divider { height: 1px; background: var(--grey-200); margin: 4px 0; }

/* ============================================================
   FILTER LEGEND BAR
   ============================================================ */
.filter-legend {
  background: var(--white);
  border-bottom: 1px solid var(--grey-200);
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  font-size: 0.82rem;
  flex-wrap: wrap;
}
.filter-legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
}
.dot-primary { background: var(--red); }
.dot-secondary { background: var(--blue-chart); }
.filter-legend-item { color: var(--grey-600); }
.filter-legend-item strong { color: var(--black); }

/* ============================================================
   MAIN LAYOUT
   ============================================================ */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Left sidebar */
.app-sidebar {
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--grey-200);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 16px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--grey-200);
}
.sidebar-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--grey-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sidebar-export-btn {
  display: flex; align-items: center; gap: 4px;
  font-size: 0.75rem; font-weight: 700;
  color: var(--grey-600);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--grey-300);
  background: none;
  transition: all var(--transition);
  text-decoration: none;
}
.sidebar-export-btn:hover { background: var(--grey-100); color: var(--black); }
.sidebar-export-btn svg { width: 14px; height: 14px; }
.sidebar-nav { padding: 8px 0; flex: 1; }
.sidebar-nav a {
  display: block;
  padding: 10px 16px;
  font-size: 0.88rem;
  color: var(--grey-800);
  text-decoration: none;
  border-radius: 6px;
  margin: 2px 8px;
  transition: all var(--transition);
  line-height: 1.3;
}
.sidebar-nav a:hover { background: var(--grey-100); color: var(--black); }
.sidebar-nav a.active { background: var(--grey-100); color: var(--black); font-weight: 600; }

/* Main content */
.app-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  position: relative;
}
.content-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 20px;
}

/* ============================================================
   DASHBOARD — SPEEDOMETERS
   ============================================================ */
.speedometer-section { margin-bottom: 32px; }
.speedometer-groups {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}
.speedometer-group {
  flex: 1;
  min-width: 280px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 16px 16px;
}
.speedometer-group-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
  min-height: 32px;
}
.speedometer-group-logo img { max-height: 32px; max-width: 120px; object-fit: contain; }
.speedometer-group-label {
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--grey-600);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}
.speedometer-target {
  text-align: center;
  font-size: 0.88rem;
  font-weight: 700;
  color: #f5a623;
  margin-bottom: 12px;
}
.speedometer-pair {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.speedometer-item {
  flex: 1;
  max-width: 160px;
  text-align: center;
}
.speedometer-n {
  font-size: 0.75rem;
  color: var(--grey-600);
  margin-bottom: 2px;
}
.speedometer-canvas-wrap { position: relative; }
.speedometer-canvas-wrap canvas { width: 100% !important; }
.speedometer-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--black);
  margin-top: 2px;
}
.speedometer-sublabel {
  font-size: 0.75rem;
  color: var(--grey-600);
  margin-top: 2px;
}

/* ============================================================
   CHART CONTAINER
   ============================================================ */
.chart-container {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}
.chart-title {
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
  color: var(--black);
}
.chart-subtitle {
  font-size: 0.82rem;
  color: var(--grey-600);
  text-align: center;
  margin-bottom: 16px;
  line-height: 1.4;
}
.chart-wrap { position: relative; }
.chart-wrap canvas { max-height: 480px; }

/* ============================================================
   TABLES
   ============================================================ */
.table-container {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table-avg-row {
  display: flex;
  gap: 0;
  background: var(--grey-100);
  border-bottom: 2px solid var(--grey-300);
  padding: 10px 0;
  font-size: 0.82rem;
  font-weight: 700;
}
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
table.data-table th {
  background: var(--grey-100);
  padding: 10px 12px;
  text-align: center;
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--grey-600);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--grey-300);
  white-space: nowrap;
}
table.data-table th.left { text-align: left; }
table.data-table td {
  padding: 9px 12px;
  text-align: center;
  border-bottom: 1px solid var(--grey-200);
  color: var(--black);
}
table.data-table td.left { text-align: left; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: var(--grey-100); }
table.data-table .total-row td {
  font-weight: 700;
  background: var(--grey-100);
  border-top: 2px solid var(--grey-300);
}
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  border-radius: 50%;
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--grey-200);
  color: var(--grey-800);
}
.rank-badge.rank-1 { background: #ffd700; color: #7a5c00; }
.rank-badge.rank-2 { background: #c0c0c0; color: #4a4a4a; }
.rank-badge.rank-3 { background: #cd7f32; color: #fff; }

/* ============================================================
   FILTER PANEL (slide-in from right)
   ============================================================ */
.filter-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.filter-panel-overlay.open { opacity: 1; pointer-events: all; }
.filter-panel {
  position: fixed;
  top: var(--header-h);
  right: 0;
  bottom: 0;
  width: var(--filter-w);
  background: var(--white);
  box-shadow: var(--shadow-lg);
  z-index: 301;
  transform: translateX(100%);
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.filter-panel.open { transform: translateX(0); }
.filter-panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--grey-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--white);
  flex-shrink: 0;
}
.filter-panel-title {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.filter-compare-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--grey-600);
}
.filter-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  min-height: 0; /* critical: prevents flex child from overflowing */
}
.filter-panel-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--grey-200);
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}
.filter-panel-footer .btn { flex: 1; }

/* Dual filter columns */
.filter-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.filter-col-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.filter-group { margin-bottom: 10px; }
.filter-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--grey-600);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.filter-select {
  width: 100%;
  border: 1.5px solid var(--grey-300);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.82rem;
  color: var(--black);
  background: var(--white);
  outline: none;
  transition: border-color var(--transition);
}
.filter-select:focus { border-color: var(--black); }
.filter-select[multiple] { height: 80px; }

/* Filter trigger button (funnel icon in content area) */
.filter-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--black);
  color: var(--white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  transition: all var(--transition);
}
.filter-trigger:hover { background: var(--grey-800); transform: scale(1.05); }
.filter-trigger .compare-dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--blue-chart);
  border: 2px solid var(--white);
  display: none;
}
.filter-trigger .compare-dot.visible { display: block; }

/* ============================================================
   UPLOAD PAGE
   ============================================================ */
.upload-section {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  max-width: 640px;
}
.upload-section h3 { font-size: 1rem; font-weight: 700; margin-bottom: 16px; }
.upload-drop-zone {
  border: 2px dashed var(--grey-300);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 16px;
}
.upload-drop-zone:hover, .upload-drop-zone.drag-over {
  border-color: var(--black);
  background: var(--grey-100);
}
.upload-drop-zone svg { width: 40px; height: 40px; color: var(--grey-400); margin-bottom: 8px; }
.upload-drop-zone p { font-size: 0.88rem; color: var(--grey-600); }
.upload-drop-zone input[type=file] { display: none; }
.batch-list { margin-top: 24px; }
.batch-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid var(--grey-200);
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 0.85rem;
}
.batch-item-info { flex: 1; }
.batch-item-info strong { display: block; }
.batch-item-info span { color: var(--grey-600); font-size: 0.78rem; }
.total-records {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--grey-600);
  margin-bottom: 16px;
}

/* ============================================================
   USER MANAGEMENT
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 32px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(-20px);
  transition: transform var(--transition);
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--grey-100);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  color: var(--grey-600);
  transition: all var(--transition);
}
.modal-close:hover { background: var(--grey-200); color: var(--black); }

/* ============================================================
   FOOTER
   ============================================================ */
.app-footer {
  background: var(--white);
  border-top: 1px solid var(--grey-200);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--grey-600);
  flex-shrink: 0;
}
.app-footer img { height: 22px; }

/* ============================================================
   ALERTS / TOASTS
   ============================================================ */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 10px;
}
.alert-success { background: #f0fdf4; border: 1px solid #86efac; color: #166534; }
.alert-error   { background: #fff0f0; border: 1px solid #fca5a5; color: #991b1b; }
.alert-info    { background: #eff6ff; border: 1px solid #93c5fd; color: #1e40af; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; --filter-w: 100vw; }
  .app-sidebar { display: none; }
  .app-content { padding: 16px; }
  .speedometer-groups { flex-direction: column; }
  .filter-cols { grid-template-columns: 1fr; }
}

/* ============================================================
   UTILITIES
   ============================================================ */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-red    { color: var(--red); }
.text-muted  { color: var(--grey-600); }
.fw-bold     { font-weight: 700; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-2 { gap: 16px; }
.flex-1 { flex: 1; }
