/* ── Bus Tracking — full-bleed map-app layout ────────────────────
   The map is the base layer filling the whole panel; the toolbar, fleet
   list and fit/zoom controls all float over it. .bus-tracking-container
   sits inside .content-area's own padding (40px desktop / 14px-12px
   mobile sides, plus a large top/bottom reserve on mobile for the fixed
   header + bottom nav) — negative side margins matching that padding
   pull it out to the true width of the viewport; top/bottom padding is
   deliberately left alone since it's clearing real fixed chrome, not
   empty space. ── */

.bus-tracking-container {
  position: relative;
  height: 100%;
  padding: 0;
  overflow: hidden;
  background: var(--bg);
  margin: 0 -40px;
}
@media (max-width: 991px) { .bus-tracking-container { margin: 0 -14px; } }
@media (max-width: 575px) { .bus-tracking-container { margin: 0 -12px; } }

#bus-map-container { position: absolute; inset: 0; }

/* ── Toolbar ─────────────────────────────────────────────────── */

.bt-toolbar {
  position: absolute; top: 10px; left: 10px; right: 10px; z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.bt-toolbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }

.bt-icon {
  width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-l));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 0.9rem;
  box-shadow: var(--shadow-g);
}

.bt-title { font-weight: 800; font-size: 0.95rem; color: var(--text); letter-spacing: -0.01em; line-height: 1.2; }

.bt-sub { font-size: 0.72rem; color: var(--text-3); font-weight: 600; margin-top: 2px; display: flex; align-items: center; }

.bt-sub .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--primary); display: inline-block; margin-right: 6px;
  animation: btPulse 2s infinite;
}

@keyframes btPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.bt-watch-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--indigo); display: inline-block; margin-right: 4px;
  animation: btWatchPulse 1.6s ease-in-out infinite;
}
@keyframes btWatchPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(1.35); }
}
.bt-watch-count { color: var(--indigo); font-weight: 800; }

.btn-export {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
  padding: 9px 16px; border-radius: 50px;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text-2); font-weight: 700; font-size: 0.75rem;
  cursor: pointer; transition: all 0.18s;
}
.btn-export:hover { background: var(--primary); border-color: var(--primary); color: #fff; }

.leaflet-container {
  font-family: 'Geist', 'Inter', sans-serif;
  background: #eef2f5;
}

.leaflet-control { border-radius: var(--radius-md); box-shadow: var(--shadow); overflow: hidden; }
.leaflet-popup-content { margin: 12px; font-size: 0.85rem; }
.bus-marker { filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.25)); }

/* Subtle, cohesive tile tone — only the base map, never markers/circles */
.leaflet-tile-pane { filter: saturate(0.9) brightness(1.02); }

/* Zoom buttons: small, half-transparent pair instead of Leaflet's
   default solid squares (which looked out of place floating on the map). */
.leaflet-control-zoom {
  border: 1px solid rgba(226,232,240,0.6) !important;
  box-shadow: var(--shadow) !important;
}
.leaflet-control-zoom a {
  width: 22px !important; height: 22px !important; line-height: 22px !important;
  background: rgba(255,255,255,0.5) !important; color: var(--text-2) !important;
  font-weight: 700 !important; font-size: 13px !important; border: none !important;
}
.leaflet-control-zoom a:hover { background: rgba(255,255,255,0.75) !important; color: var(--primary) !important; }
.leaflet-control-zoom-in { border-radius: var(--radius-md) var(--radius-md) 0 0 !important; }
.leaflet-control-zoom-out { border-radius: 0 0 var(--radius-md) var(--radius-md) !important; }

/* Attribution: just a quiet pill in the corner, not a banner */
.leaflet-control-attribution {
  background: rgba(255,255,255,0.82) !important;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--border) !important; box-shadow: none !important;
  border-radius: 50px !important;
  padding: 2px 9px !important;
  font-size: 0.6rem !important; color: var(--text-3) !important;
  line-height: 1.6;
}
.leaflet-control-attribution a { color: var(--text-3) !important; }

/* Fit-all-buses button injected by JS */
.bt-fit-btn {
  position: absolute; bottom: 16px; right: 12px; z-index: 1000;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 50px; border: none;
  background: var(--surface); color: var(--text-2);
  font-weight: 700; font-size: 0.72rem; cursor: pointer;
  box-shadow: var(--shadow); transition: all 0.18s;
}
.bt-fit-btn:hover { background: var(--primary); color: #fff; }

/* ── Sidebar (floating overlay — positioned per-breakpoint below) ─── */

.bus-sidebar {
  position: absolute; z-index: 900;
  /* Semi-transparent + blurred rather than solid — the fleet list sits
     directly on top of the map, so a solid background hides whatever
     part of the map is underneath it the whole time it's open. */
  background: rgba(255,255,255,0.72); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 8px 30px rgba(15,23,42,0.18);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

/* Floating "follow" card — shown only while a single bus is selected
   (see selectBus/exitFollowMode in bus-tracking.js), pinned to the map's
   left edge (out of the way of the fleet sidebar, which floats on the
   right/bottom) instead of requiring that sidebar to be open. Very
   light (~15% opacity) — this sits directly over the map while
   following, so it needs to stay unobtrusive, not just translucent. */
#bt-follow-card {
  position: absolute; left: 10px; top: 68px; z-index: 980;
  width: 190px; max-width: 46vw;
  background: rgba(255,255,255,0.15); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(226,232,240,0.5); border-radius: 14px;
  box-shadow: 0 6px 20px rgba(15,23,42,0.10);
  padding: 8px 10px;
}

#bus-info-panel { flex-shrink: 0; }

/* This card fills nearly the whole sidebar's interior, so a solid
   background here would defeat the sidebar's own translucency almost
   entirely — kept semi-transparent instead of solid var(--surface). */
.bt-info-card {
  background: rgba(255,255,255,0.6); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.bt-info-empty {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; color: var(--text-3); font-size: 0.7rem; font-weight: 600;
}
.bt-info-empty i { font-size: 0.8rem; color: var(--border); }

.bt-info-head {
  padding: 8px 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: linear-gradient(135deg, rgba(5,150,105,0.08), rgba(16,185,129,0.03));
  border-bottom: 1px solid var(--border);
}
.bt-info-name { font-weight: 800; font-size: 0.8rem; color: var(--text); line-height: 1.2; }

.bt-badge {
  display: inline-flex; align-items: center; gap: 5px; flex-shrink: 0;
  padding: 3px 9px; border-radius: 50px;
  font-size: 0.56rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em;
}
.bt-badge.moving { background: rgba(5,150,105,0.12); color: var(--primary); }
.bt-badge.idle   { background: rgba(245,158,11,0.14); color: var(--warning); }

.bt-info-body { padding: 8px 12px 9px; display: flex; flex-direction: column; gap: 6px; }
.bt-stat-row { display: flex; gap: 6px; }
.bt-stat { flex: 1; background: var(--bg); border: 1px solid var(--border-g); border-radius: var(--radius-sm); padding: 5px 8px; }
.bt-stat-label { font-size: 0.53rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); }
.bt-stat-val { font-size: 0.78rem; font-weight: 800; color: var(--text); }

.bt-info-addr { display: flex; gap: 6px; font-size: 0.68rem; color: var(--text-2); font-weight: 600; line-height: 1.3; }
.bt-info-addr i { color: var(--primary); margin-top: 1px; flex-shrink: 0; }

.bt-eta {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: rgba(99,102,241,0.08); border: 1px solid rgba(99,102,241,0.18);
  border-radius: var(--radius-sm); padding: 5px 8px;
  font-size: 0.64rem; font-weight: 700; color: var(--indigo);
}

/* ── Fleet list header (All / None) ─────────────────────────── */

.bt-fleet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 2px 4px 4px;
}
.bt-fleet-title {
  font-size: 0.68rem; font-weight: 800; color: var(--text-2);
  display: flex; align-items: center; gap: 6px;
}
.bt-fleet-count {
  background: var(--bg); border: 1px solid var(--border-g); color: var(--primary);
  font-size: 0.6rem; font-weight: 800; padding: 1px 7px; border-radius: 50px;
}
.bt-fleet-actions { display: flex; gap: 5px; }
.bt-fleet-actions button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-3);
  font-size: 0.6rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 3px 9px; border-radius: 50px; cursor: pointer; transition: all 0.15s;
}
.bt-fleet-actions button:hover { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── Bus List ────────────────────────────────────────────────── */

#bus-list {
  flex: 1; min-height: 80px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
  padding: 2px 2px 4px;
}
#bus-list::-webkit-scrollbar { width: 5px; }
#bus-list::-webkit-scrollbar-track { background: transparent; }
#bus-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Same reasoning as .bt-info-card above — these rows fill the sidebar's
   interior, so a solid background here defeats the container's own
   translucency almost entirely. */
.bus-list-item {
  display: flex; flex-direction: column; gap: 1px;
  padding: 6px 9px;
  background: rgba(255,255,255,0.55); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: all 0.15s;
}
.bus-list-item:hover { border-color: var(--primary-l); background: rgba(255,255,255,0.75); }
.bus-list-item.active { border-color: var(--primary); background: rgba(5,150,105,0.05); box-shadow: 0 0 0 2px rgba(16,185,129,0.12); }
.bus-list-item.dimmed { opacity: 0.45; }

.bli-check {
  width: 14px; height: 14px; flex-shrink: 0; cursor: pointer;
  accent-color: var(--primary); border-radius: 3px;
}

.bus-empty { text-align: center; color: var(--text-3); padding: 18px 12px; font-size: 0.76rem; font-weight: 600; }
.bus-empty i { font-size: 1.3rem; display: block; margin-bottom: 6px; color: var(--border); }

/* ── Map Markers ─────────────────────────────────────────────── */

.bt-marker-wrap { position: relative; display: flex; flex-direction: column; align-items: center; }
.bt-marker-pulse {
  position: absolute; inset: -6px; border-radius: 50%;
  border: 2px solid var(--primary);
  animation: btMarkerRing 2s ease-out infinite; pointer-events: none;
}
@keyframes btMarkerRing { 0% { transform: scale(0.9); opacity: 0.7; } 100% { transform: scale(1.6); opacity: 0; } }
.bt-marker-circle {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.28);
  position: relative; z-index: 1; color: #fff; font-size: 1rem;
  border: 2px solid #fff;
}
.bt-marker-label {
  background: rgba(15,23,42,0.92); color: #fff;
  font-family: 'Geist', 'Inter', sans-serif; font-weight: 700; font-size: 0.65rem;
  padding: 3px 9px; border-radius: 8px; white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}
.bt-marker-label::before { display: none; }

/* ── Geofence Alerts ─────────────────────────────────────────── */

#geofence-alerts {
  position: absolute; top: 68px; left: 10px; right: 10px; z-index: 999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
#geofence-alerts .alert {
  margin: 0; pointer-events: auto; border: none;
  border-radius: 50px; padding: 8px 14px 8px 12px;
  font-size: 0.74rem; font-weight: 700;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 6px;
  animation: btSlideIn 0.3s ease;
}
@keyframes btSlideIn { from { transform: translateX(-16px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Fleet list row — row 1: checkbox + name (never truncated; the panel's
   own width grows to fit, see .bus-sidebar). Row 2: status badge +
   location. Mobile media query below just shrinks these. */
.bli-row1 { display: flex; align-items: center; gap: 8px; }
.bli-row1-name { font-size: 0.76rem; font-weight: 800; color: var(--text); white-space: nowrap; }
/* Animated moving/idle indicator right after the name — quick at-a-
   glance state without having to read the row 2 badge text. */
.bli-status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; animation: btStatusPulse 1.8s ease-in-out infinite; }
.bli-status-dot.moving { background: #22c55e; }
.bli-status-dot.idle   { background: #f97316; }
@keyframes btStatusPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(1.3); }
}
.bli-row2 { display: flex; align-items: center; gap: 6px; margin-top: 4px; white-space: nowrap; }
.bli-badge-mini {
  padding: 2px 8px; border-radius: 999px; font-size: 0.6rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.03em; flex-shrink: 0;
}
.bli-badge-mini.moving { background: rgba(5,150,105,0.12); color: var(--primary); }
.bli-badge-mini.idle   { background: rgba(217,119,6,0.12); color: var(--warning); }
.bli-row2 .bli-addr { font-size: 0.65rem; color: var(--text-3); font-weight: 600; }

/* Desktop/tablet (≥992px, matching the app's own sidebar breakpoint):
   sidebar floats as a card on the right; always open, no toggle needed —
   there's room for both map and list at once. The merged header
   (Fit-all + list-toggle icons, mobile-only) stays hidden here since
   desktop already has its own persistent bottom-left fit button and
   never collapses the sidebar at all. */
@media (min-width: 992px) {
  .bus-sidebar {
    top: 68px; right: 10px; bottom: 10px; width: 300px;
    border-radius: var(--radius-lg); padding: 8px;
  }
  .bt-fit-btn { bottom: 16px; left: 56px; right: auto; }
  .bt-sheet-handle { display: none; }
  #bt-panel-header { display: none; }
}

/* Below 992px: Fit-all + the list-toggle live inside the sidebar's own
   header instead of as separate floating buttons — collapsing now just
   hides the list body (#bt-panel-body), leaving that two-icon header as
   the only thing on screen, rather than sliding the whole panel away.
   Width is content-driven so a bus's full name never truncates, capped
   so a very long name can't take over the screen. */
@media (max-width: 991px) {
  #geofence-alerts { right: 100px; }
  #bus-map-container .bt-fit-btn { display: none; }

  #bt-panel-header { padding: 2px; }
  .bt-fit-btn-inline {
    width: 30px; height: 30px; border-radius: 999px; border: none;
    background: rgba(15,23,42,0.06); color: var(--text-2);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: background 0.15s;
  }
  .bt-fit-btn-inline:hover { background: rgba(5,150,105,0.15); color: var(--primary); }

  /* Chrome on Android auto-inflates any text it judges "too small to
     read" (a11y font-boosting) — silently overriding every small
     font-size below unless disabled here. */
  .bus-sidebar, .bus-sidebar * { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

  .bus-sidebar {
    top: 68px; right: 10px; bottom: 10px; left: auto;
    /* Name still isn't truncated (row 1), but the address (row 2) now
       is — an address line was often far longer than any bus name, so
       sizing the whole panel to fit it made "dynamic width" useless. */
    width: auto; max-width: 148px; min-width: 60px;
    /* Lighter than the desktop sidebar (0.72) — this close to the map
       edge it needs to stay unobtrusive, not just translucent. */
    background: rgba(255,255,255,0.18);
    border-radius: 16px; padding: 3px;
  }
  .bus-sidebar.bt-collapsed { bottom: auto; }
  .bus-sidebar.bt-collapsed #bt-panel-body { display: none; }

  .bt-sheet-handle { display: none; }

  .bus-list-item { padding: 4px 6px; }
  .bli-row1, .bli-row1-name { line-height: 1; }
  .bli-row1-name { font-size: 0.62rem; }
  .bli-status-dot { width: 5px; height: 5px; }
  .bli-row2 { gap: 4px; margin-top: 0; line-height: 1; }
  .bli-badge-mini { padding: 1px 5px; font-size: 0.45rem; }
  .bli-row2 .bli-addr { font-size: 0.45rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

  /* "Fleet N" + All/None buttons — stacked and shrunk to a minimum so
     they don't force the panel wider just to fit this one row. */
  .bt-fleet-head { flex-direction: column; align-items: stretch; gap: 2px; padding: 2px; }
  .bt-fleet-title { font-size: 0.5rem; justify-content: center; }
  .bt-fleet-actions { gap: 2px; }
  .bt-fleet-actions button { flex: 1; padding: 1.5px 0; font-size: 0.45rem; }
}
