/* === MAPA AO VIVO - VIAÇÃO BOA ESPERANÇA VIRTUAL === */

/* Layout geral da página do mapa */
.destinos-main {
  height: 100vh;
  height: 100dvh;
  padding-top: 110px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--header-bg-custom); /* Blends perfectly with header if any padding is exposed */
}

@media (max-width: 768px) {
  .destinos-main {
    padding-top: 100px;
  }
}

@media (max-width: 480px) {
  .destinos-main {
    padding-top: 100px;
  }
}

/* ── LAYOUT MAPA + SIDEBAR ───────────────────────────── */
.map-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ── SIDEBAR ─────────────────────────────────────────── */
.map-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-light);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 500;
}

/* Garante que elementos com hidden dentro da sidebar fiquem invisíveis mesmo com display:flex/grid */
.map-sidebar [hidden] {
  display: none !important;
}

.sidebar-map-switcher {
  padding: 14px 12px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(0, 0, 0, 0.1);
}

.sidebar-map-switcher-header {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}

.sidebar-map-switcher-title {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-gray);
}

.sidebar-map-switcher-title i {
  color: #f59e0b;
  font-size: 0.78rem;
}

.sidebar-map-switcher-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 8px;
}

.map-option-btn {
  min-height: 38px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04);
  color: var(--text-dark);
  font-size: 0.78rem;
  font-weight: 700;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.2s;
}

.map-option-btn:hover {
  background: rgba(249,115,22,0.1);
  border-color: rgba(249,115,22,0.28);
  color: #f97316;
  transform: translateY(-1px);
}

.map-option-btn.active {
  background: rgba(249,115,22,0.16);
  border-color: rgba(249,115,22,0.38);
  color: #f97316;
  box-shadow: inset 0 0 0 1px rgba(249,115,22,0.12);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

/* ── CARDS DE ESTATÍSTICAS NA SIDEBAR ────────────────── */
.sidebar-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(0, 0, 0, 0.14);
}

.sidebar-stat-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 8px 10px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-stat-card:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.09);
  transform: translateY(-1px);
}

.stat-icon-wrapper {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.stat-icon-wrapper.online {
  background: rgba(74, 222, 128, 0.1);
  color: #4ade80;
}

.stat-icon-wrapper.viagem {
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
}

.stat-icon-wrapper.km {
  background: rgba(249, 115, 22, 0.1);
  color: #f97316;
}

.stat-icon-wrapper.vel {
  background: rgba(168, 85, 247, 0.1);
  color: #a855f7;
}

.sidebar-stat-card .stat-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-stat-card .stat-value {
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.2;
}

.sidebar-stat-card:nth-child(1) .stat-value { color: #4ade80; }
.sidebar-stat-card:nth-child(2) .stat-value { color: #3b82f6; }
.sidebar-stat-card:nth-child(3) .stat-value { color: #f97316; }
.sidebar-stat-card:nth-child(4) .stat-value { color: #a855f7; }

.sidebar-stat-card .stat-label {
  font-size: 0.65rem;
  color: #64748b;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.sidebar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #cbd5e1;
}

.sidebar-title i {
  color: #64748b;
}

.sidebar-count {
  background: rgba(249,115,22,0.15);
  border: 1px solid rgba(249,115,22,0.3);
  color: #f97316;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  min-width: 24px;
  text-align: center;
}

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 12px 6px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 8px 12px;
}

.sidebar-search i {
  color: #475569;
  font-size: 0.8rem;
}

.sidebar-search input {
  background: transparent;
  border: none;
  outline: none;
  color: #cbd5e1;
  font-size: 0.82rem;
  width: 100%;
  font-family: 'Inter', sans-serif;
}

.sidebar-search input::placeholder {
  color: #475569;
}

.sidebar-filters {
  display: flex;
  gap: 5px;
  padding: 6px 12px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.filter-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  color: #64748b;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Inter', sans-serif;
}

.filter-btn.active,
.filter-btn:hover {
  background: rgba(249,115,22,0.15);
  border-color: rgba(249,115,22,0.4);
  color: #f97316;
}

.sidebar-driver-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.map-sidebar.is-driver-detail .sidebar-driver-list {
  padding: 0;
  overflow-y: auto;
}

.sidebar-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 200px;
  color: #334155;
  font-size: 0.82rem;
}

/* Card do motorista na sidebar */
.driver-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.driver-card:hover {
  background: rgba(249,115,22,0.07);
}

.driver-card.highlight {
  background: rgba(249,115,22,0.12);
  border-left: 3px solid #f97316;
}

.driver-card.is-stale {
  background: rgba(148, 163, 184, 0.05);
}

.driver-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
  color: #fff;
  background: linear-gradient(135deg, #f97316, #ea580c);
}

.driver-avatar.has-image,
.driver-detail-avatar.has-image {
  background: rgba(15, 23, 42, 0.35);
  overflow: hidden;
}

.driver-avatar img,
.driver-detail-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.driver-info {
  flex: 1;
  min-width: 0;
}

.driver-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.driver-speed {
  font-size: 0.72rem;
  color: #64748b;
  margin-top: 2px;
}

.driver-map {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  font-size: 0.66rem;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.driver-map i {
  color: #f97316;
  font-size: 0.65rem;
}

.driver-card.highlight .driver-map {
  color: #fdba74;
}

.driver-route {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  font-size: 0.66rem;
  color: #cbd5e1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.driver-route i {
  color: #22c55e;
  font-size: 0.65rem;
}

.driver-last-seen {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  font-size: 0.64rem;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.driver-last-seen i {
  color: #f59e0b;
  font-size: 0.62rem;
}

.driver-detail-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 14px 18px;
  height: 100%;
  box-sizing: border-box;
  overflow-y: auto;
}

.driver-detail-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  border: 0;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  color: #e2e8f0;
  padding: 9px 14px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
  font-size: 0.82rem;
  font-weight: 600;
}

.driver-detail-back:hover {
  background: rgba(249, 115, 22, 0.16);
  color: #f97316;
  transform: translateX(-2px);
}

.driver-detail-profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.92), rgba(15, 23, 42, 0.92));
  border: 1px solid rgba(148, 163, 184, 0.14);
  text-align: center;
}

.driver-detail-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 1.6rem;
  background: linear-gradient(135deg, #f97316, #ea580c);
  flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(249,115,22,0.25), 0 4px 20px rgba(0,0,0,0.4);
  overflow: hidden;
}

.driver-detail-avatar.has-image {
  background: rgba(15, 23, 42, 0.35);
  box-shadow: 0 0 0 3px rgba(249,115,22,0.25), 0 4px 20px rgba(0,0,0,0.4);
}

.driver-detail-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.driver-detail-headline {
  min-width: 0;
  width: 100%;
}

.driver-detail-name {
  color: #f8fafc;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

.driver-detail-subline {
  color: #94a3b8;
  font-size: 0.78rem;
  margin-top: 4px;
}

.driver-detail-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #e2e8f0;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(0,0,0,0.25);
  border-radius: 999px;
  padding: 4px 12px;
}

.driver-detail-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-color, #4ade80);
  box-shadow: 0 0 6px var(--status-color, #4ade80);
}

.driver-detail-trip {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.driver-detail-section-title {
  color: #f8fafc;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.driver-detail-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.driver-detail-row .label {
  color: #94a3b8;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.driver-detail-row .value {
  color: #e2e8f0;
  font-size: 0.86rem;
  line-height: 1.4;
  word-break: break-word;
}

.driver-detail-actions {
  display: flex;
}

.driver-detail-route-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 14px;
  padding: 12px 14px;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #f8fafc;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  box-shadow: 0 12px 30px rgba(34, 197, 94, 0.22);
}

.driver-detail-route-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.driver-detail-route-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  box-shadow: none;
}

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

/* ── MAPA ─────────────────────────────────────────────── */
#map-container {
  background-color: var(--map-bg, #070a13);
  background-image:
    radial-gradient(rgba(249,115,22,0.06) 1px, transparent 0),
    radial-gradient(rgba(34,197,94,0.03) 1.5px, transparent 0);
  background-size: 32px 32px;
  background-position: 0 0, 16px 16px;
}

#map-container .leaflet-container,
#map-container .leaflet-pane,
#map-container .leaflet-tile-pane {
  background-color: var(--map-bg, #070a13);
}


/* ── CONTROLES DE ZOOM ───────────────────────────────── */
.map-layout {
  --map-control-height: 44px;
}

.custom-zoom-controls {
  position: absolute;
  bottom: 40px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: row;
  gap: 5px;
  align-items: center;
  padding: 0 6px;
  height: var(--map-control-height) !important;
  background: var(--bg-light);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  backdrop-filter: blur(10px);
  pointer-events: auto;
  box-sizing: border-box;
}

.custom-zoom-controls button {
  width: 30px;
  height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.12);
  border: 1px solid var(--border-color);
  border-radius: 7px;
  color: var(--text-dark);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.custom-zoom-controls button:hover {
  color: #f97316;
  background: rgba(249,115,22,0.15);
  border-color: rgba(249,115,22,0.3);
}

/* ── LEGENDA ──────────────────────────────────────────── */
.map-legend {
  position: absolute;
  top: auto;
  bottom: 40px;
  right: 100px;
  z-index: 1000;
  background: var(--bg-light);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0 12px;
  height: var(--map-control-height) !important;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  max-width: min(760px, calc(100% - 32px));
  backdrop-filter: blur(10px);
  pointer-events: none;
  box-sizing: border-box;
}

.legend-title {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-gray);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0;
  white-space: nowrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.75rem;
  color: var(--text-dark);
  margin-bottom: 0;
  white-space: nowrap;
}

.map-legend .legend-title[style] {
  margin-top: 0 !important;
  margin-left: 6px;
  padding-left: 10px;
  border-left: 1px solid var(--border-color);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── TOOLTIP DOS MARCADORES ──────────────────────────── */
.truck-tooltip {
  background: rgba(10,14,26,0.95) !important;
  border: 1px solid rgba(249,115,22,0.4) !important;
  border-radius: 8px !important;
  color: #e2e8f0 !important;
  font-size: 0.78rem !important;
  padding: 6px 10px !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5) !important;
  font-family: 'Inter', sans-serif !important;
}

.truck-tooltip::before {
  border-top-color: rgba(249,115,22,0.4) !important;
}

/* Animação suave para os marcadores do mapa (movimento real-time) */
.leaflet-container:not(.leaflet-zoom-anim) .leaflet-marker-pane .leaflet-marker-icon {
  transition: transform 1.2s linear !important;
}

/* ── MARCADORES DE MOTORISTAS PREMIUM (ROTACIONADOS) ── */
.custom-marker-container {
  background: transparent !important;
  border: none !important;
}

.custom-truck-marker {
  width: 32px;
  height: 32px;
  background: rgba(10, 14, 26, 0.95);
  border: 2px solid #f59e0b;
  color: #f59e0b;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.3s ease, box-shadow 0.3s ease;
  position: relative;
}

.custom-truck-marker.em-viagem {
  border-color: #4ade80;
  box-shadow: 0 0 10px rgba(74, 222, 128, 0.4);
}

.custom-truck-marker.pausado {
  border-color: #ef4444; /* Vermelho */
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
}

.custom-truck-marker.parado {
  border-color: #f59e0b; /* Amarelo Escuro */
}

.custom-truck-marker.is-stale {
  border-style: dashed;
  opacity: 0.82;
}

.custom-truck-marker i {
  /* Alinha a frente do ônibus/caminhão com o topo do círculo (0 graus = Norte) */
  transform: rotate(-90deg);
  transition: color 0.3s ease;
}

/* ── CORES DO ÍCONE INTERNO (ÔNIBUS/CAMINHÃO) ── */
.custom-truck-marker.com-carga i {
  color: #3b82f6; /* Azul */
}

.custom-truck-marker.sem-trabalho i {
  color: #8b5cf6; /* Violeta */
}
/* ── SIDEBAR COLLAPSE & MOBILE OVERRIDES ──────────────────────────── */

/* Toggle Button Styling */
.sidebar-toggle-btn {
  position: absolute;
  top: 50%;
  left: 260px; /* Width of sidebar */
  transform: translateY(-50%);
  z-index: 1001;
  width: 24px;
  height: 48px;
  background: var(--bg-light);
  border: 1px solid var(--border-color);
  border-left: none;
  border-radius: 0 8px 8px 0;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 4px 0 12px rgba(0,0,0,0.3);
  transition: all 0.3s ease;
}

.map-sidebar {
  transition: width 0.3s ease, transform 0.3s ease;
}

.map-sidebar.collapsed {
  width: 0 !important;
  border-right: none;
}

.map-sidebar.collapsed + .sidebar-toggle-btn {
  left: 0;
}

.map-sidebar.collapsed + .sidebar-toggle-btn i {
  transform: rotate(180deg);
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .map-sidebar {
    width: 260px;
    position: absolute;
    top: 0;
    height: 100%;
    transform: translateX(0);
    z-index: 990;
  }
  
  .map-sidebar.collapsed {
    transform: translateX(-100%);
    width: 260px !important;
  }

  .sidebar-toggle-btn {
    position: absolute;
    top: 50%;
    left: 260px;
  }
  
  .map-sidebar.collapsed + .sidebar-toggle-btn {
    left: 0;
  }

  .map-stats-bar {
    padding: 0 10px;
  }

  .map-legend {
    left: 10px;
    right: auto;
    bottom: 15px;
    width: calc(100% - 66px); /* 10px left + 46px zoom box + 10px gap */
    max-width: none;
    height: 130px !important;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px 10px;
    padding: 10px 12px;
  }

  .map-legend .legend-title,
  .map-legend .legend-title[style] {
    grid-column: 1 / -1;
    border-left: none !important;
    padding-left: 0 !important;
    margin-left: 0 !important;
    margin-top: 6px !important;
    font-size: 0.7rem;
    color: #94a3b8;
  }

  .map-legend .legend-title:first-child {
    margin-top: 0 !important;
  }

  .legend-item {
    font-size: 0.75rem;
    white-space: normal;
    line-height: 1.2;
  }

  .custom-zoom-controls {
    bottom: 15px;
    right: 10px;
    flex-direction: column;
    height: 130px !important;
    width: 46px;
    padding: 6px;
    gap: 8px;
    justify-content: space-between;
  }

  .custom-zoom-controls button {
    width: 100%;
    flex: 1;
    height: auto;
    border-radius: 6px;
  }
}
