:root {
  --navy: #111111;
  --navy-deep: #000000;
  --blue: #276ef1;
  --blue-soft: #eef3ff;
  --blue-line: #111111;
  --text: #1f1f1f;
  --muted: #6b6b6b;
  --border: #ebebeb;
  --bg: #f6f6f6;
  --panel: #ffffff;
  --danger: #ff5a5f;
  --sidebar-w: 64px;
  --header-h: 56px;
  --history-w: 380px;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --font: "Uber Move Text", "Uber Move", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

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

html,
body {
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 4px;
  z-index: 20;
}

.brand {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #276ef1;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
  margin-bottom: 10px;
  letter-spacing: -0.02em;
}

.nav-btn {
  width: 42px;
  height: 42px;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  border-radius: 10px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: 0.15s ease;
}

.nav-btn:hover,
.nav-btn.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.nav-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-spacer {
  flex: 1;
}

/* Main column */
.main {
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  min-width: 0;
}

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 15;
}

.filter-group,
.search-wrap {
  position: relative;
}

.filter-group select,
.search-wrap input,
.date-nav {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 0 12px;
  color: var(--text);
  outline: none;
}

.filter-group select {
  min-width: 160px;
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.search-wrap input {
  width: 220px;
  padding-left: 34px;
}

.search-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  stroke: var(--muted);
  fill: none;
  stroke-width: 2;
}

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

.tool-btn {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.tool-btn:hover,
.tool-btn.active {
  border-color: #111;
  background: #111;
  color: #fff;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-chip {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  display: grid;
  place-items: center;
  color: var(--muted);
  cursor: pointer;
  position: relative;
}

.icon-chip [data-icon] {
  display: grid;
  place-items: center;
}

.icon-chip svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-chip .badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  display: grid;
  place-items: center;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #276ef1;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}

.user-menu span {
  font-size: 13px;
  color: var(--text);
  padding-right: 4px;
}

/* Workspace */
.workspace {
  display: grid;
  grid-template-columns: var(--history-w) 1fr;
  min-height: 0;
}

.side-panel,
.history-panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-panel[hidden],
.history-panel[hidden] {
  display: none !important;
}

.panel-header,
.history-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.fleet-count {
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: #111;
  color: #fff;
  display: inline-grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}

.fleet-summary {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 12px;
}

.status-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.status-chip {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.status-chip:hover {
  border-color: #111;
  color: #111;
}

.status-chip.active {
  background: #111;
  border-color: #111;
  color: #fff;
}

.vehicle-list {
  flex: 1;
  overflow: auto;
  padding: 8px 8px 72px;
}

.fab-add {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: #111;
  color: #fff;
  font-size: 32px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.28);
  z-index: 6;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, background 0.15s ease;
}

.fab-add:hover {
  background: #276ef1;
  transform: scale(1.06);
}

#vehiclesPanel {
  position: relative;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-card {
  width: min(480px, 100%);
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  padding: 20px 20px 16px;
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h2 {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: #f3f3f3;
  font-size: 22px;
  cursor: pointer;
  color: #111;
}

.modal-sub {
  margin: 6px 0 16px;
  color: var(--muted);
  font-size: 13px;
}

.tracker-form .form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.tracker-form label {
  font-size: 12px;
  font-weight: 650;
  color: #444;
}

.tracker-form input,
.tracker-form select,
.tracker-form textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 40px;
  padding: 8px 12px;
  outline: none;
  background: #fff;
}

.tracker-form textarea {
  min-height: 72px;
  resize: vertical;
}

.tracker-form input:focus,
.tracker-form select:focus,
.tracker-form textarea:focus {
  border-color: #111;
}

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

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: #f3f3f3;
  padding: 4px;
  border-radius: 12px;
}

.mode-btn {
  border: 0;
  background: transparent;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--muted);
}

.mode-btn.active {
  background: #fff;
  color: #111;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.form-error {
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12.5px;
  margin-bottom: 10px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.primary-btn {
  height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: #111;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.primary-btn:hover {
  background: #276ef1;
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.vehicle-row {
  width: 100%;
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  align-items: center;
  text-align: left;
  border: 1px solid transparent;
  background: #fff;
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  margin-bottom: 6px;
  transition: 0.12s ease;
}

.vehicle-row:hover {
  background: #f7f7f7;
}

.vehicle-row.selected {
  background: #f3f3f3;
  border-color: #111;
  box-shadow: inset 3px 0 0 #111;
}

.vehicle-row-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  color: #fff;
  display: grid;
  place-items: center;
}

.vehicle-row-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
}

.vehicle-row-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.vehicle-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.vehicle-row-top strong {
  font-size: 14px;
}

.vehicle-row-meta,
.vehicle-row-loc {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #9ca3af;
  flex-shrink: 0;
}

.status-dot.driving {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

.status-dot.stopped {
  background: #276ef1;
}

.status-dot.idling {
  background: #f59e0b;
}

.status-dot.offline {
  background: #9ca3af;
}

.fleet-car-marker {
  position: relative;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.fleet-car-pulse {
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--car, #111) 28%, transparent);
  animation: pulse 1.8s ease-out infinite;
}

.fleet-car-marker.status-offline .fleet-car-pulse,
.fleet-car-marker.status-stopped .fleet-car-pulse {
  animation: none;
  opacity: 0.25;
}

.fleet-car-core {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--car, #111);
  color: #fff;
  border: 3px solid #fff;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
  display: grid;
  place-items: center;
  z-index: 1;
}

.fleet-car-marker.selected .fleet-car-core {
  transform: scale(1.12);
  box-shadow: 0 0 0 3px #111, 0 10px 22px rgba(0, 0, 0, 0.35);
}

.fleet-car-label {
  position: absolute;
  top: -26px;
  left: 50%;
  transform: translateX(-50%);
  background: #111;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.fleet-car-marker:hover .fleet-car-label,
.fleet-car-marker.selected .fleet-car-label {
  opacity: 1;
}

@keyframes pulse {
  0% {
    transform: scale(0.75);
    opacity: 0.85;
  }
  70% {
    transform: scale(1.45);
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}

.history-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.history-title-row h1 {
  font-size: 18px;
  font-weight: 650;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px;
  font-size: 13px;
  color: var(--muted);
}

.date-nav button {
  width: 24px;
  height: 24px;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  border-radius: 6px;
}

.date-nav button:hover {
  background: var(--bg);
  color: var(--text);
}

.vehicle-select {
  width: 100%;
  margin-bottom: 12px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.stat label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 2px;
}

.stat strong {
  font-size: 14px;
  color: #111;
}

.timeline {
  flex: 1;
  overflow: auto;
  padding: 8px 0 24px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  padding: 10px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s ease;
}

.timeline-item:hover,
.timeline-item.active {
  background: #f7f7f7;
  border-left-color: #111;
}

.rail {
  position: relative;
  display: flex;
  justify-content: center;
}

.rail::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: -20px;
  width: 2px;
  background: #e5e5e5;
}

.timeline-item:last-child .rail::before {
  display: none;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #111;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px #d4d4d4;
  z-index: 1;
  margin-top: 4px;
}

.dot.drive {
  background: #276ef1;
  box-shadow: 0 0 0 2px #c9daff;
}

.seg-body {
  min-width: 0;
}

.seg-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.seg-status {
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
}

.seg-duration {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.seg-address {
  font-size: 12.5px;
  color: var(--text);
  line-height: 1.35;
  margin-bottom: 4px;
}

.seg-time {
  font-size: 12px;
  color: var(--muted);
}

.seg-meta {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.pill {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #111;
  color: #fff;
}

/* Map */
.map-panel {
  position: relative;
  min-width: 0;
  background: #edeae4;
}

#map {
  width: 100%;
  height: 100%;
}

.maplibregl-map {
  font-family: var(--font);
}

.maplibregl-ctrl-attrib {
  font-size: 10px !important;
  background: rgba(255, 255, 255, 0.72) !important;
}

.maplibregl-popup-content {
  border-radius: 10px !important;
  box-shadow: var(--shadow) !important;
  padding: 10px 12px !important;
  font-size: 12.5px;
  line-height: 1.4;
}

.maplibregl-popup-tip {
  border-top-color: #fff !important;
}

.map-toolbar {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 5;
  display: flex;
  gap: 8px;
  align-items: center;
}

.map-toolbar .tool-btn {
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.94);
}

.map-type-switch {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.map-type-btn {
  border: 0;
  background: transparent;
  height: 36px;
  padding: 0 14px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  border-right: 1px solid var(--border);
}

.map-type-btn:last-child {
  border-right: 0;
}

.map-type-btn:hover {
  background: #f8fafc;
  color: var(--text);
}

.map-type-btn.active {
  background: #111;
  color: #fff;
}

.map-zoom-stack {
  position: absolute;
  top: 64px;
  right: 14px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.map-zoom-stack button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.map-zoom-stack button:hover {
  background: #fff;
  color: #111;
}

.map-zoom-stack #btn3d.is-3d-on {
  background: #111;
  border-color: #111;
  color: #fff;
}

.maplibregl-ctrl-group {
  border: 0 !important;
  border-radius: 12px !important;
  box-shadow: var(--shadow) !important;
  overflow: hidden;
}

.maplibregl-ctrl-compass {
  background: #fff !important;
}

.maplibregl-canvas {
  outline: none;
}

.map-marker {
  pointer-events: auto;
}

.marker-label {
  pointer-events: none;
}

.stop-chip {
  background: #111;
  color: #fff;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  margin-bottom: 10px;
}

.uber-endpoint {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid #111;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
  display: grid;
  place-items: center;
}

.uber-endpoint.end {
  border-color: #276ef1;
}

.uber-endpoint span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #111;
}

.uber-endpoint.end span {
  background: #276ef1;
}

.alert-pin {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #ff5a5f;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 14px;
  box-shadow: 0 8px 18px rgba(255, 90, 95, 0.4);
  border: 2px solid #fff;
}

.uber-car {
  position: relative;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  transform: rotate(var(--rot, 0deg));
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.28));
}

.uber-car-shadow {
  position: absolute;
  width: 28px;
  height: 10px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.22);
  bottom: 4px;
  filter: blur(2px);
}

.uber-car-body {
  z-index: 1;
  display: grid;
  place-items: center;
}

.uber-popup .maplibregl-popup-content {
  border-radius: 14px !important;
  padding: 12px 14px !important;
  font-size: 13px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18) !important;
}

.vehicle-card {
  position: absolute;
  left: 16px;
  bottom: 28px;
  z-index: 5;
  width: min(360px, calc(100% - 32px));
  background: #fff;
  border: 0;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
  padding: 16px;
  display: none;
}

.vehicle-card.visible {
  display: block;
  animation: rise 0.25s ease;
}

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

.vehicle-card-top {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.vehicle-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #111;
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.vehicle-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
}

.vehicle-card h2 {
  font-size: 14px;
  font-weight: 650;
  margin-bottom: 2px;
}

.vehicle-card p {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.4;
}

.vehicle-card .group {
  margin-top: 8px;
  font-size: 12px;
  color: #276ef1;
  font-weight: 700;
}

.loading-overlay,
.error-banner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(243, 245, 248, 0.78);
  z-index: 20;
  font-size: 14px;
  color: var(--muted);
}

.error-banner {
  background: #fff1f2;
  color: #9f1239;
  inset: auto 16px 16px 16px;
  height: auto;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid #fecdd3;
}

.empty-state {
  padding: 32px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 980px) {
  :root {
    --history-w: 300px;
  }

  .toolbar {
    display: none;
  }

  .search-wrap input {
    width: 150px;
  }
}

@media (max-width: 760px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 45% 55%;
  }

  .history-panel {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}
