/* ─── GPS Module Styles ─────────────────────────────────────────────────── */

/* 4-status color system. Single source of truth — used by fleet summary,
   sidebar groups, status chips, popup badges, and SVG map pins.          */
:root {
  --gps-moving:  #10b981;
  --gps-idle:    #f59e0b;
  --gps-parked:  #3b82f6;
  --gps-offline: #64748b;
}

/* ─── Fleet summary bar (top of live page) ─────────────────────────────── */

.gps-fleet-summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-md);
}

.gps-fleet-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  position: relative;
  overflow: hidden;
}

.gps-fleet-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--color-border);
}

.gps-fleet-card.total::before   { background: var(--color-primary); }
.gps-fleet-card.moving::before  { background: var(--gps-moving); }
.gps-fleet-card.idle::before    { background: var(--gps-idle); }
.gps-fleet-card.parked::before  { background: var(--gps-parked); }
.gps-fleet-card.offline::before { background: var(--gps-offline); }
.gps-fleet-card.km::before      { background: var(--color-primary); }

.gps-fleet-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.1;
}

.gps-fleet-value small {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-left: 3px;
}

.gps-fleet-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

@media (max-width: 1200px) {
  .gps-fleet-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .gps-fleet-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ─── Live Map ─────────────────────────────────────────────────────────── */

.gps-layout {
  display: flex;
  height: calc(100vh - var(--topbar-height) - 2 * var(--spacing-lg));
  gap: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.gps-sidebar {
  width: 340px;
  min-width: 340px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.gps-sidebar-header {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
}

.gps-sidebar-search {
  position: relative;
}

.gps-sidebar-search .material-icons {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  color: var(--color-text-muted);
}

.gps-sidebar-search input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  background: var(--color-bg);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s;
}

.gps-sidebar-search input:focus {
  border-color: var(--color-primary);
}

.gps-sidebar-stats {
  display: flex;
  gap: var(--spacing-xs);
  margin-top: var(--spacing-sm);
}

.gps-stat-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  background: var(--color-bg);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.gps-stat-chip.active {
  box-shadow: 0 0 0 2px var(--color-primary);
  background: rgba(var(--color-primary-rgb), 0.1);
}

.gps-stat-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.gps-stat-chip .dot {
  flex-shrink: 0;
}

.gps-stat-chip .dot.moving  { background: var(--gps-moving); }
.gps-stat-chip .dot.idle    { background: var(--gps-idle); }
.gps-stat-chip .dot.parked  { background: var(--gps-parked); }
.gps-stat-chip .dot.offline { background: var(--gps-offline); }

.gps-vehicle-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-xs);
}

/* Group headers in the vehicle sidebar — sticky, colored by status. */
.gps-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin: 10px 2px 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--color-text-secondary);
  position: sticky;
  top: 0;
  background: var(--color-surface);
  z-index: 2;
  border-radius: var(--radius-sm);
}

.gps-group-header:first-child { margin-top: 2px; }

.gps-group-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.gps-group-header.moving  .gps-group-dot { background: var(--gps-moving); }
.gps-group-header.idle    .gps-group-dot { background: var(--gps-idle); }
.gps-group-header.parked  .gps-group-dot { background: var(--gps-parked); }
.gps-group-header.offline .gps-group-dot { background: var(--gps-offline); }

.gps-group-label { flex: 1; }

.gps-group-count {
  background: var(--color-bg);
  color: var(--color-text-muted);
  padding: 1px 8px;
  border-radius: 100px;
  font-size: 10px;
  font-weight: 700;
}

.gps-vehicle-card {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  border: 1px solid transparent;
  border-left-width: 3px;
  border-left-color: transparent;
}

.gps-vehicle-card.moving  { border-left-color: var(--gps-moving); }
.gps-vehicle-card.idle    { border-left-color: var(--gps-idle); }
.gps-vehicle-card.parked  { border-left-color: var(--gps-parked); }
.gps-vehicle-card.offline { border-left-color: var(--gps-offline); }

.gps-vehicle-card:hover {
  background: var(--color-bg);
}

.gps-vehicle-card.active {
  background: rgba(var(--color-primary-rgb), 0.06);
  border-color: var(--color-primary);
}

/* Colored dot on the left of each card (redundant with the left border, but helps scannability) */
.gps-vehicle-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.04);
}

.gps-vehicle-dot.moving  { background: var(--gps-moving); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15); animation: gpsPulse 1.8s ease-in-out infinite; }
.gps-vehicle-dot.idle    { background: var(--gps-idle); }
.gps-vehicle-dot.parked  { background: var(--gps-parked); }
.gps-vehicle-dot.offline { background: var(--gps-offline); opacity: 0.7; }

@keyframes gpsPulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15); }
  50%      { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.05); }
}

.gps-speed-pill {
  background: var(--gps-moving);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 100px;
  margin-left: auto;
}

.gps-vehicle-info {
  flex: 1;
  min-width: 0;
}

.gps-vehicle-plate {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}

.gps-vehicle-driver {
  font-weight: 400;
  font-size: 11px;
  color: var(--color-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
}

.gps-vehicle-detail {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gps-vehicle-speed {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
}

/* Hide vehicle button */
.gps-hide-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 4px;
  flex-shrink: 0;
  transition: color 0.15s;
  display: flex;
  align-items: center;
}

.gps-hide-btn:hover {
  color: var(--color-text);
}

.gps-hide-btn .material-icons {
  font-size: 18px;
}

/* Daily km display */
.gps-vehicle-km {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* ─── Map Container ────────────────────────────────────────────────────── */

.gps-map-container {
  flex: 1;
  position: relative;
  min-width: 0;
}

.gps-map {
  width: 100%;
  height: 100%;
}

/* Leaflet popup overrides */
.gps-popup {
  font-family: var(--font-family);
  min-width: 200px;
}

.gps-popup-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border-light);
}

.gps-popup-plate {
  font-size: var(--font-size-base);
  font-weight: 700;
  color: var(--color-text);
}

.gps-popup-driver {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  margin-bottom: 8px;
}

.gps-popup-driver .material-icons {
  font-size: 14px;
  opacity: 0.6;
}

.gps-popup-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  font-size: var(--font-size-xs);
}

.gps-popup-label {
  color: var(--color-text-muted);
}

.gps-popup-value {
  font-weight: 600;
  color: var(--color-text);
}

.gps-popup-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  color: var(--color-primary);
  background: rgba(var(--color-primary-rgb), 0.08);
  text-decoration: none;
  transition: background 0.15s;
}

.gps-popup-link:hover {
  background: rgba(var(--color-primary-rgb), 0.15);
}

/* Teardrop SVG pin (divicon wrapper). The SVG is drawn from JS with the
   correct status color + heading arrow. This element just positions it. */
.gps-pin-divicon {
  background: transparent !important;
  border: none !important;
}

/* Wrapper fits whatever SVG it holds — dimensions come from the divIcon's
   iconSize so the label can hang off the bottom without affecting anchoring. */
.gps-pin-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
}

.gps-pin-wrap svg {
  display: block;
  margin: 0 auto;
}

.gps-pin-label {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 3px;
  background: rgba(17, 24, 39, 0.92);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  font-family: var(--font-family);
  letter-spacing: 0.3px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.gps-pin-label::before {
  content: '';
  position: absolute;
  top: -3px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 6px;
  height: 6px;
  background: rgba(17, 24, 39, 0.92);
}

/* Trip endpoints on the history map */
.gps-trip-endpoint {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  border: 2px solid white;
}

.gps-trip-endpoint .material-icons {
  font-size: 16px;
}

.gps-trip-endpoint.start { background: var(--gps-moving); }
.gps-trip-endpoint.end   { background: #ef4444; }

/* Stop marker (yellow dot) on the history map */
.gps-stop-marker {
  background: transparent !important;
  border: none !important;
}

.gps-stop-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gps-idle);
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

/* ─── GPS Tabs (sub-navigation within GPS pages) ──────────────────────── */

.gps-tabs {
  display: flex;
  gap: 2px;
  background: var(--color-bg);
  padding: 3px;
  border-radius: var(--radius-md);
  margin-bottom: var(--spacing-md);
  width: fit-content;
}

.gps-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: none;
}

.gps-tab:hover {
  color: var(--color-text);
  background: var(--color-surface);
}

.gps-tab.active {
  color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  font-weight: 600;
}

.gps-tab .material-icons {
  font-size: 18px;
}

/* ─── Trip History ─────────────────────────────────────────────────────── */

.gps-history-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: calc(100vh - var(--topbar-height) - 2 * var(--spacing-lg) - 52px);
  gap: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.gps-history-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--color-border);
  overflow: hidden;
}

.gps-history-filters {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.gps-history-filters .form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-sm);
}

/* Row under the day label — "Arată toate rutele" + future actions */
.gps-history-actions {
  display: flex;
  gap: var(--spacing-xs);
}

.gps-history-actions .btn {
  flex: 1;
}

.gps-history-actions .btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Prev-day / date picker / next-day trio */
.gps-day-nav {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  gap: var(--spacing-xs);
  align-items: stretch;
}

.gps-day-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.gps-day-btn:hover {
  background: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-primary);
}

.gps-day-btn .material-icons {
  font-size: 20px;
}

.gps-day-input {
  width: 100%;
  text-align: center;
}

.gps-day-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-align: center;
  text-transform: capitalize;
  padding-top: 4px;
}

/* Day summary card (4 stats) */
.gps-day-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  padding: 0;
  background: var(--color-border);
  border-bottom: 1px solid var(--color-border);
}

.gps-day-summary:empty {
  display: none;
}

.gps-day-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 4px;
  background: var(--color-surface);
}

.gps-day-stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.1;
}

.gps-day-stat-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-top: 2px;
}

.gps-trip-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-xs);
}

.gps-trip-card {
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-light);
  margin-bottom: var(--spacing-xs);
  cursor: pointer;
  transition: all 0.15s;
}

.gps-trip-card:hover {
  border-color: var(--color-primary);
  background: rgba(var(--color-primary-rgb), 0.03);
}

.gps-trip-card.active {
  border-color: var(--color-primary);
  background: rgba(var(--color-primary-rgb), 0.06);
}

.gps-trip-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.gps-trip-time {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text);
}

.gps-trip-duration {
  font-size: 11px;
  color: var(--color-text-muted);
  background: var(--color-bg);
  padding: 2px 8px;
  border-radius: 100px;
}

.gps-trip-route {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin: 8px 0;
}

.gps-trip-dots {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 2px 0;
}

.gps-trip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.gps-trip-dot.start { background: var(--color-success); }
.gps-trip-dot.end { background: var(--color-danger); }

.gps-trip-line {
  width: 2px;
  flex: 1;
  background: var(--color-border);
  min-height: 16px;
}

.gps-trip-addresses {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 4px;
  min-width: 0;
}

.gps-trip-address {
  font-size: 12px;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gps-trip-stats {
  display: flex;
  gap: var(--spacing-md);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--color-border-light);
}

.gps-trip-stat {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--color-text-muted);
}

.gps-trip-stat .material-icons {
  font-size: 14px;
}

.gps-trip-stat strong {
  color: var(--color-text);
  font-weight: 600;
}

/* ─── Geofence styles ──────────────────────────────────────────────────── */

.gps-geofence-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--spacing-md);
}

.gps-geofence-card {
  padding: var(--spacing-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.gps-geofence-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-sm);
}

.gps-geofence-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.gps-geofence-name {
  font-weight: 600;
  font-size: var(--font-size-sm);
  color: var(--color-text);
  flex: 1;
}

.gps-geofence-meta {
  font-size: 11px;
  color: var(--color-text-muted);
  display: flex;
  gap: var(--spacing-sm);
}

/* ─── Map Controls ─────────────────────────────────────────────────────── */

.gps-map-controls {
  position: absolute;
  top: var(--spacing-md);
  right: var(--spacing-md);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.gps-map-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--color-text-secondary);
  transition: all 0.15s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.gps-map-btn:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.gps-map-btn.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.gps-map-btn .material-icons {
  font-size: 20px;
}

/* ─── Empty / Loading states ───────────────────────────────────────────── */

.gps-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-2xl);
  text-align: center;
  color: var(--color-text-muted);
  gap: var(--spacing-sm);
}

.gps-empty .material-icons {
  font-size: 48px;
  opacity: 0.3;
}

.gps-empty p {
  font-size: var(--font-size-sm);
  max-width: 240px;
}

.gps-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-2xl);
}

/* ─── Responsive ───────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
  .gps-layout {
    flex-direction: column;
    height: calc(100vh - var(--topbar-height) - 2 * var(--spacing-lg));
  }

  .gps-sidebar {
    width: 100%;
    min-width: 0;
    max-height: 240px;
    min-height: 140px;
    flex-shrink: 0;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }

  .gps-map-container {
    flex: 1;
    min-height: 250px;
  }

  .gps-history-layout {
    grid-template-columns: 1fr;
    height: calc(100vh - var(--topbar-height) - 2 * var(--spacing-lg) - 52px);
  }

  .gps-history-panel {
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    max-height: 45vh;
  }
}

/* ─── Mobile bottom-sheet for GPS lists ───────────────────────────────────
   On phones the cramped strip above the map was unusable. Switch to a
   bottom-sheet overlay: peek shows fleet counts, tap expands to ~78vh.    */
@media (max-width: 768px) {

  /* Live map page */
  .gps-layout {
    position: relative;
    overflow: visible;
    flex-direction: column;
    border-radius: var(--radius-lg);
  }

  .gps-map-container {
    width: 100%;
    min-height: calc(100vh - var(--topbar-height) - 2 * var(--spacing-lg) - 88px);
    border-radius: var(--radius-lg);
  }

  /* Proper bottom sheet:
     - flush to viewport edges (0 left/right/bottom)
     - rounded ONLY on top (not bottom)
     - z-index 1050 → above Leaflet (1000) but BELOW the slide-in sidebar nav (1100)
       so opening the hamburger menu covers the sheet instead of sitting under it
     - safe-area inset for iOS home indicator bar */
  .gps-sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    min-width: 0;
    max-height: calc(96px + env(safe-area-inset-bottom, 0px));
    min-height: calc(96px + env(safe-area-inset-bottom, 0px));
    border: none;
    border-top: 1px solid var(--color-border);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -8px 28px rgba(15, 23, 42, 0.18);
    background: var(--color-surface);
    /* Above Leaflet (1000), BELOW the sidebar scrim overlay (1080) so the
       nav drawer and its backdrop both cover this sheet when opened. */
    z-index: 1040;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transition: max-height 0.3s var(--ease-out-quart), min-height 0.3s var(--ease-out-quart);
  }

  /* Disable CSS transition while user is actively dragging (JS adds this class) */
  .gps-sidebar.is-dragging,
  .gps-history-panel.is-dragging {
    transition: none !important;
  }

  .gps-sidebar.sheet-expanded {
    max-height: calc(78vh + env(safe-area-inset-bottom, 0px));
    min-height: calc(78vh + env(safe-area-inset-bottom, 0px));
  }

  .gps-sidebar-header {
    position: relative;
    padding: 22px var(--spacing-md) var(--spacing-sm);
    cursor: grab;
    user-select: none;
    touch-action: none;
  }
  .gps-sidebar.is-dragging .gps-sidebar-header {
    cursor: grabbing;
  }

  .gps-sidebar-header::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--color-border);
  }

  .gps-sidebar:not(.sheet-expanded) .gps-sidebar-search {
    display: none;
  }

  .gps-sidebar:not(.sheet-expanded) .gps-sidebar-stats {
    margin-top: 2px;
    justify-content: center;
    flex-wrap: wrap;
  }

  .gps-sidebar.sheet-expanded .gps-sidebar-search {
    display: block;
    margin-bottom: var(--spacing-sm);
  }

  .gps-vehicle-list {
    overflow-y: auto;
  }

  /* Hide the fleet summary bar on mobile — the sheet handles all the counts */
  .gps-fleet-summary {
    display: none;
  }

  /* History page — same bottom sheet treatment */
  .gps-history-layout {
    position: relative;
    overflow: visible;
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - var(--topbar-height) - 2 * var(--spacing-lg) - 88px);
  }

  .gps-history-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: calc(108px + env(safe-area-inset-bottom, 0px));
    min-height: calc(108px + env(safe-area-inset-bottom, 0px));
    border: none;
    border-top: 1px solid var(--color-border);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -8px 28px rgba(15, 23, 42, 0.18);
    background: var(--color-surface);
    /* Above Leaflet (1000), BELOW the sidebar scrim overlay (1080) so the
       nav drawer and its backdrop both cover this sheet when opened. */
    z-index: 1040;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transition: max-height 0.3s var(--ease-out-quart), min-height 0.3s var(--ease-out-quart);
  }

  .gps-history-panel.sheet-expanded {
    max-height: calc(78vh + env(safe-area-inset-bottom, 0px));
    min-height: calc(78vh + env(safe-area-inset-bottom, 0px));
  }

  .gps-history-filters {
    position: relative;
    padding: 22px var(--spacing-md) var(--spacing-sm);
    cursor: grab;
    user-select: none;
    touch-action: none;
  }
  .gps-history-panel.is-dragging .gps-history-filters {
    cursor: grabbing;
  }

  .gps-history-filters::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--color-border);
  }

  .gps-history-panel:not(.sheet-expanded) .gps-trip-list,
  .gps-history-panel:not(.sheet-expanded) .gps-day-summary {
    display: none;
  }

  /* When the sheet is collapsed show just the vehicle dropdown + day nav */
  .gps-history-panel:not(.sheet-expanded) .gps-history-filters {
    padding-bottom: 8px;
  }

  /* Keep the map's in-corner UI clear of the sheet peek. Without this, the
     top-right custom controls (refresh/fit) were fine but the bottom-right
     Leaflet attribution sat under the sheet border and looked broken. */
  .gps-layout .leaflet-control-attribution,
  .gps-history-layout .leaflet-control-attribution {
    margin-bottom: 92px !important;
    font-size: 9px;
    max-width: 55vw;
  }

  /* When the sheet is fully expanded the bottom half of the map is obscured
     anyway, so the attribution is hidden to avoid double-showing behind it. */
  .gps-sidebar.sheet-expanded ~ .gps-map-container .leaflet-control-attribution,
  .gps-history-panel.sheet-expanded ~ .gps-map-container .leaflet-control-attribution {
    display: none;
  }

  .gps-history-map,
  #gps-history-map {
    min-height: calc(100vh - var(--topbar-height) - 2 * var(--spacing-lg) - 160px);
  }
}

/* ─── GPS Setup Guide Dialog ──────────────────────────────────────────── */

.gps-setup-guide {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

.gps-setup-section {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.gps-setup-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.gps-setup-section-header h3 {
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--color-text);
  margin: 0;
}

.gps-setup-step-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.gps-setup-section-body {
  padding: 16px;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  line-height: 1.7;
}

.gps-setup-section-body p {
  margin: 0 0 4px 0;
}

.gps-setup-section-body ol {
  margin: 4px 0;
  padding-left: 20px;
}

.gps-setup-section-body ol li {
  margin-bottom: 4px;
}

/* Specs grid */
.gps-setup-specs {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.gps-setup-spec {
  display: flex;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border-light);
}

.gps-setup-spec:last-child {
  border-bottom: none;
}

.gps-setup-spec-label {
  width: 140px;
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.gps-setup-spec-value {
  font-size: var(--font-size-sm);
  color: var(--color-text);
}

.gps-setup-spec-value code {
  font-size: 12px;
  background: var(--color-bg);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Wiring diagram */
.gps-setup-wiring {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
  padding: 12px;
  background: var(--color-bg);
  border-radius: var(--radius-md);
}

.gps-setup-wire {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--font-size-sm);
}

.gps-setup-wire-color {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* SMS commands */
.gps-setup-sms-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gps-setup-sms {
  padding: 12px;
  background: var(--color-bg);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--color-primary);
}

.gps-setup-sms-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.gps-setup-sms-num {
  font-size: 14px;
  color: var(--color-primary);
  font-weight: 700;
}

.gps-setup-sms-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text);
}

.gps-setup-sms-cmd {
  display: block;
  font-size: 13px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  background: var(--color-surface);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  margin: 4px 0 6px 0;
  color: var(--color-primary);
  font-weight: 600;
  letter-spacing: 0.5px;
  user-select: all;
}

.gps-setup-sms-desc {
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* Callouts */
.gps-setup-callout {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  line-height: 1.6;
  align-items: flex-start;
}

.gps-setup-callout .material-icons {
  font-size: 20px;
  flex-shrink: 0;
  margin-top: 1px;
}

.gps-setup-callout.info {
  background: rgba(72, 149, 239, 0.08);
  border: 1px solid rgba(72, 149, 239, 0.2);
  color: var(--color-text);
}

.gps-setup-callout.info .material-icons {
  color: var(--color-info);
}

.gps-setup-callout.warning {
  background: rgba(255, 159, 28, 0.08);
  border: 1px solid rgba(255, 159, 28, 0.2);
  color: var(--color-text);
}

.gps-setup-callout.warning .material-icons {
  color: var(--color-warning);
}

.gps-setup-callout.danger {
  background: rgba(231, 29, 54, 0.08);
  border: 1px solid rgba(231, 29, 54, 0.2);
  color: var(--color-text);
}

.gps-setup-callout.danger .material-icons {
  color: var(--color-danger);
}

.gps-setup-callout ul {
  margin: 4px 0;
  padding-left: 16px;
}

.gps-setup-callout ul li {
  margin-bottom: 2px;
}

.gps-setup-callout code {
  font-size: 11px;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 3px;
}

/* Checklist */
.gps-setup-checklist {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gps-setup-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--font-size-sm);
  color: var(--color-text);
}

/* Data flow diagram */
.gps-setup-flow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  flex-wrap: wrap;
  padding: 8px 0;
}

.gps-setup-flow-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  background: var(--color-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  min-width: 110px;
}

.gps-setup-flow-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(var(--color-primary-rgb), 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gps-setup-flow-icon .material-icons {
  font-size: 20px;
  color: var(--color-primary);
}

.gps-setup-flow-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text);
  text-align: center;
  line-height: 1.4;
}

.gps-setup-flow-text small {
  font-weight: 400;
  color: var(--color-text-muted);
  font-size: 11px;
}

.gps-setup-flow-arrow {
  padding: 0 6px;
  color: var(--color-text-muted);
}

.gps-setup-flow-arrow .material-icons {
  font-size: 20px;
}

@media (max-width: 768px) {
  .gps-setup-flow {
    flex-direction: column;
    gap: 4px;
  }

  .gps-setup-flow-arrow .material-icons {
    transform: rotate(90deg);
  }

  .gps-setup-spec {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .gps-setup-spec-label {
    width: auto;
  }
}

/* ─── Leaflet overrides ───────────────────────────────────────────────── */

.leaflet-control-zoom a {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-border) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--color-bg) !important;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius-md) !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15) !important;
  padding: 4px 0 !important;
}

.leaflet-popup-content {
  margin: 10px 14px !important;
  font-family: var(--font-family) !important;
  font-size: var(--font-size-sm) !important;
}

.leaflet-popup-tip {
  box-shadow: 0 4px 16px rgba(0,0,0,0.15) !important;
}

.leaflet-control-attribution {
  font-size: 9px !important;
  background: rgba(255,255,255,0.7) !important;
}
