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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f0f2f5;
  color: #1f2937;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* ── Login ─────────────────────────────────────────────── */

#login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.25);
  z-index: 1000;
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  width: 360px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  text-align: center;
}

.login-card h1 {
  font-size: 1.8rem;
  margin-bottom: 24px;
  color: #1f2937;
}

.login-card input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.2s;
}

.login-card input:focus {
  border-color: #3b82f6;
}

.login-card button {
  width: 100%;
  padding: 12px;
  background: #3b82f6;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.login-card button:hover {
  background: #2563eb;
}

#login-error {
  color: #ef4444;
  font-size: 0.875rem;
  margin-top: 12px;
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: #9ca3af;
  font-size: 0.875rem;
}

.login-divider::before,
.login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e5e7eb;
}

.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  background: #fff;
  color: #3c4043;
  border: 1px solid #dadce0;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}

.google-btn:hover {
  background: #f8f9fa;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* ── Header ────────────────────────────────────────────── */

header {
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

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

.header-left h1 {
  font-size: 1.2rem;
  font-weight: 700;
}

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

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

#btn-prev,
#btn-next {
  width: 36px;
  height: 36px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#btn-prev:hover,
#btn-next:hover {
  background: #f0f2f5;
}

.hd-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  position: relative;
  min-width: 60px;
  transition: opacity 0.2s, background 0.2s;
}

.hd-toggle.disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.hd-toggle input {
  margin: 0;
  cursor: inherit;
}

.hd-toggle:not(.disabled):hover {
  background: #f0f2f5;
}

.hd-toggle:not(.disabled).active {
  background: #eff6ff;
  border-color: #3b82f6;
  color: #3b82f6;
}

.lang-toggle {
  display: flex;
  gap: 0;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}

.lang-btn {
  padding: 6px 10px;
  border: none;
  background: #fff;
  color: #6b7280;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.lang-btn:not(:last-child) {
  border-right: 1px solid #e5e7eb;
}

.lang-btn:hover {
  background: #f0f2f5;
}

.lang-btn.active {
  background: #3b82f6;
  color: #fff;
}

#day-picker {
  width: 140px;
  padding: 8px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  text-align: center;
  font-size: 0.875rem;
  cursor: pointer;
  background: #fff;
  outline: none;
}

#btn-today {
  padding: 8px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 0.15s;
}

#btn-today:hover {
  background: #f0f2f5;
}

#vehicle-select {
  padding: 8px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  font-size: 0.875rem;
  cursor: pointer;
  outline: none;
}

.btn-logout {
  padding: 8px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  color: #6b7280;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 0.15s, color 0.15s;
}

.btn-logout:hover {
  background: #f0f2f5;
  color: #1f2937;
}

/* ── Back button ──────────────────────────────────────── */

.btn-back {
  width: 36px;
  height: 36px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.btn-back:hover {
  background: #f0f2f5;
}

/* ── Fleet Overview ───────────────────────────────────── */

.fleet-header {
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.fleet-main {
  max-width: 960px;
  margin: 32px auto;
  padding: 0 24px;
}

.fleet-main h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: #1f2937;
}

.fleet-table-wrap {
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
}

#fleet-table {
  width: 100%;
  border-collapse: collapse;
}

#fleet-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
}

#fleet-table td {
  padding: 14px 16px;
  font-size: 0.95rem;
  border-bottom: 1px solid #f3f4f6;
}

#fleet-table tbody tr {
  cursor: pointer;
  transition: background 0.15s;
}

#fleet-table tbody tr:hover {
  background: #f0f7ff;
}

#fleet-table tbody tr:last-child td {
  border-bottom: none;
}

.no-vehicles {
  text-align: center;
  padding: 60px 20px;
  color: #6b7280;
  font-size: 1.05rem;
  line-height: 1.6;
}

.fleet-loading {
  text-align: center;
  padding: 40px;
}

.fleet-loading.hidden {
  display: none;
}

.fleet-spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid #e5e7eb;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.soc-high { color: #22c55e; font-weight: 600; }
.soc-mid  { color: #f59e0b; font-weight: 600; }
.soc-low  { color: #ef4444; font-weight: 600; }

.vehicle-name { font-weight: 600; }

.no-data { color: #9ca3af; }


/* ── Mileage ─────────────────────────────────────────── */

.mileage-main {
  max-width: 1100px;
  margin: 32px auto;
  padding: 0 24px;
}

.mileage-main h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: #1f2937;
}

.mileage-chart-wrap {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  height: 450px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
}

.mileage-table-wrap {
  margin-top: 24px;
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
}

.mileage-table-wrap h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: #1f2937;
}

.mileage-table-scroll {
  overflow-x: auto;
}

.mileage-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.mileage-table-wrap th,
.mileage-table-wrap td {
  padding: 6px 12px;
  text-align: right;
  border-bottom: 1px solid #e5e7eb;
  white-space: nowrap;
}

.mileage-table-wrap th {
  background: #f9fafb;
  font-weight: 600;
  color: #374151;
  position: sticky;
  top: 0;
}

.mileage-table-wrap th:first-child,
.mileage-table-wrap td:first-child {
  text-align: left;
}

.mileage-table-wrap tr:last-child td {
  font-weight: 700;
  border-top: 2px solid #d1d5db;
}

.mileage-link {
  display: inline-block;
  margin-top: 20px;
  padding: 8px 16px;
  background: #3b82f6;
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.15s;
}

.mileage-link:hover {
  background: #2563eb;
}


/* ── Grid ──────────────────────────────────────────────── */

main.grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 2fr;
  grid-template-rows: 1fr 1.2fr;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 65px);
  max-height: calc(100vw / 1.5);
}

.card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  padding: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.card h2 {
  font-size: 0.8rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.card canvas {
  flex: 1;
  min-height: 0;
}

.card.map-card {
  grid-column: 4;
  grid-row: 1 / 3;
}

.card.speed-card {
  grid-column: 1 / 4;
  grid-row: 2;
}

#map {
  flex: 1;
  border-radius: 8px;
  min-height: 0;
}

/* ── Loading ───────────────────────────────────────────── */

.card.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 12px;
  z-index: 10;
}

.card.loading::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border: 3px solid #e5e7eb;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  z-index: 11;
}

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

/* HD button loading state */
.hd-toggle.loading span {
  visibility: hidden;
}

.hd-toggle.loading::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid #e5e7eb;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Flatpickr: days with data ─────────────────────────── */

.flatpickr-day.has-data {
  background: #dcfce7;
  border-color: #bbf7d0;
}

.flatpickr-day.has-data:hover {
  background: #bbf7d0;
}

.flatpickr-day.has-data.selected {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #fff;
}

/* ── Export button ─────────────────────────────────────── */

.btn-export {
  padding: 6px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  color: #6b7280;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-export:hover {
  background: #eff6ff;
  border-color: #3b82f6;
  color: #3b82f6;
}

/* ── Export modal ──────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.25);
  z-index: 1000;
}

.export-card {
  background: #fff;
  border-radius: 16px;
  padding: 32px;
  width: 420px;
  max-width: 90vw;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

.export-card h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: #1f2937;
}

.export-range {
  font-size: 0.9rem;
  color: #6b7280;
  margin-bottom: 20px;
}

.export-seats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 12px;
  margin-bottom: 24px;
  min-height: 60px;
}

.export-no-seats {
  font-size: 0.9rem;
  color: #6b7280;
  text-align: center;
  padding: 16px 0;
}

.export-seat label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.export-seat input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.export-seat input:focus {
  border-color: #3b82f6;
}

.export-seat input:disabled {
  background: #f9fafb;
  color: #9ca3af;
}

.export-seat label.seat-inactive {
  color: #d1d5db;
}

.export-seat label.seat-loading {
  color: #9ca3af;
}

.export-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.btn-secondary {
  padding: 10px 20px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  color: #6b7280;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background 0.15s;
}

.btn-secondary:hover {
  background: #f0f2f5;
}

.btn-primary {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  background: #3b82f6;
  color: #fff;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: #2563eb;
}

.btn-primary:disabled {
  background: #93c5fd;
  cursor: not-allowed;
}

/* ── Responsive ────────────────────────────────────────── */

@media (max-width: 1024px) {
  main.grid {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(5, auto);
    height: auto;
    max-height: none;
  }

  .card {
    height: 250px;
  }

  .card.map-card {
    grid-column: 1;
    grid-row: 1;
    height: 50vw;
    min-height: 300px;
    max-height: 600px;
  }

  .card.speed-card {
    grid-column: 1;
    grid-row: auto;
  }
}
