/* =============================================
   Rivera Bus Tracker - Styles
   ============================================= */

:root {
  --bg-base: #0A0A0A;
  --bg-s1: #121212;
  --bg-s2: #1E1E1E;
  --text-1: #FFFFFF;
  --text-2: #A0A0A0;
  --text-3: #666666;
  --border: rgba(255, 255, 255, 0.1);
  --border-faint: rgba(255, 255, 255, 0.05);
}

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

body {
  font-family: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg-base);
  color: var(--text-1);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  height: 100dvh;
  width: 100vw;
  touch-action: manipulation;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: 'Outfit', system-ui, sans-serif;
}

/* ---- Loading Overlay ---- */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-base);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease;
}

#loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loader-content {
  text-align: center;
}

.loader-icon {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: #FFCC00;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.loader-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 12px;
}

.loader-spinner {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-3);
  font-size: 14px;
  justify-content: center;
}

.spin {
  animation: spin 1s linear infinite;
}

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

/* ---- Map ---- */
#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

/* ---- Header ---- */
#app-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(10, 10, 10, 0.7);
  border-bottom: 1px solid var(--border-faint);
}

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

.header-logo {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: #FFCC00;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

@media (min-width: 640px) {
  .header-title {
    font-size: 18px;
  }
}

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

.header-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
}

.update-time-text {
  color: var(--text-3);
}

@media (max-width: 480px) {
  .update-time-text {
    display: none;
  }
}

.signal-pulse {
  animation: pulse 1s ease-in-out;
  color: #34C759;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.3;
  }
}

/* ---- Filter Panel ---- */
#filter-panel {
  position: absolute;
  right: 8px;
  top: 68px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 40;
  max-height: calc(100dvh - 140px);
  overflow-y: auto;
  padding-bottom: 8px;
}

#filter-panel::-webkit-scrollbar {
  width: 0;
}

.filter-btn {
  min-width: 48px;
  padding: 4px 8px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0px;
  font-weight: 700;
  cursor: pointer;
  border: 1.5px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(30, 30, 30, 0.9);
  color: var(--text-2);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
  font-size: 11px;
  line-height: 1.1;
}

.filter-btn:active {
  transform: scale(0.92);
}

.filter-num {
  font-size: 12px;
  font-weight: 800;
  font-family: 'Outfit', system-ui;
  line-height: 1.2;
}

.filter-name {
  font-size: 7px;
  font-weight: 600;
  opacity: 0.85;
  white-space: nowrap;
  max-width: 52px;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

/* ---- Bus List Toggle ---- */
#bus-list-toggle {
  position: absolute;
  bottom: 24px;
  left: 16px;
  z-index: 40;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(30, 30, 30, 0.9);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  -webkit-tap-highlight-color: transparent;
}

#bus-list-toggle:active {
  transform: scale(0.92);
}

/* ---- Bus List Panel ---- */
#bus-list-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  max-height: 55vh;
  border-radius: 24px 24px 0 0;
  backdrop-filter: blur(32px);
  -webkit-backdrop-filter: blur(32px);
  background: rgba(30, 30, 30, 0.95);
  border-top: 1px solid var(--border);
  transition: transform 0.3s ease;
}

#bus-list-panel.hidden {
  transform: translateY(100%);
  pointer-events: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
}

.panel-header h3 {
  font-size: 15px;
  font-weight: 700;
}

.panel-close {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  cursor: pointer;
}

#bus-list-content {
  overflow-y: auto;
  padding: 0 16px 24px;
  max-height: calc(55vh - 56px);
}

.bus-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  margin-bottom: 2px;
  cursor: pointer;
  background: transparent;
  border: none;
  text-align: left;
  color: var(--text-1);
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

.bus-row:hover {
  background: rgba(255, 255, 255, 0.05);
}

.bus-row:active {
  background: rgba(255, 255, 255, 0.08);
}

.bus-row-badge {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  flex-shrink: 0;
  font-family: 'Outfit', system-ui;
}

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

.bus-row-name {
  font-size: 14px;
  font-weight: 600;
  font-family: 'Outfit', system-ui;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bus-row-stop {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bus-row-time {
  font-size: 12px;
  color: var(--text-2);
  flex-shrink: 0;
}

.cached-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-weight: 500;
  color: #B5B35C;
  margin: 16px 0 8px 4px;
}

/* ---- Bottom Sheet ---- */
#sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(0, 0, 0, 0.3);
  transition: opacity 0.3s;
}

#sheet-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 60;
  max-height: 85vh;
  border-radius: 32px 32px 0 0;
  backdrop-filter: blur(32px);
  -webkit-backdrop-filter: blur(32px);
  background: rgba(30, 30, 30, 0.92);
  border-top: 1px solid var(--border);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  overflow-y: auto;
}

#bottom-sheet.hidden {
  transform: translateY(100%);
  pointer-events: none;
}

.sheet-handle {
  display: flex;
  justify-content: center;
  padding: 12px 0 4px;
  cursor: pointer;
}

.handle-bar {
  width: 40px;
  height: 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.2);
}

.sheet-bus-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 4px 20px 8px;
}

.sheet-bus-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sheet-bus-badge {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 900;
  font-family: 'Outfit', system-ui;
}

.sheet-bus-title {
  font-size: 20px;
  font-weight: 700;
  font-family: 'Outfit', system-ui;
}

.sheet-bus-route {
  font-size: 14px;
  color: var(--text-2);
  margin-top: 2px;
}

.sheet-line-badge {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
}

.sheet-cached-warning {
  margin: 12px 20px 0;
  padding: 10px 14px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  background: rgba(181, 179, 92, 0.15);
  border: 1px solid rgba(181, 179, 92, 0.3);
  color: #B5B35C;
}

.sheet-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px 20px 0;
}

.sheet-widget {
  padding: 16px;
  border-radius: 16px;
  background: rgba(42, 42, 42, 0.4);
  border: 1px solid var(--border-faint);
}

.sheet-widget-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 500;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 6px;
}

.sheet-widget-value {
  font-size: 16px;
  font-weight: 600;
  margin-top: 6px;
  font-family: 'Outfit', system-ui;
}

.sheet-route-row {
  margin: 16px 20px 24px;
  padding: 16px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(42, 42, 42, 0.4);
  border: 1px solid var(--border-faint);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
}

/* ---- MapLibre overrides ---- */
.maplibregl-ctrl-group {
  background: rgba(30, 30, 30, 0.9) !important;
  border: 1px solid var(--border) !important;
  border-radius: 12px !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4) !important;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  overflow: hidden;
}

.maplibregl-ctrl-group button {
  width: 36px !important;
  height: 36px !important;
  border: none !important;
}

.maplibregl-ctrl-group button+button {
  border-top: 1px solid rgba(255, 255, 255, 0.06) !important;
}

.maplibregl-ctrl-group button:hover {
  background: rgba(255, 255, 255, 0.08) !important;
}

.maplibregl-ctrl-group button .maplibregl-ctrl-icon {
  filter: invert(1) brightness(0.8);
}

.maplibregl-ctrl-geolocate {
  background: rgba(30, 30, 30, 0.9) !important;
  border: 1px solid var(--border) !important;
  border-radius: 12px !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4) !important;
}

/* Bus markers - NO transform/filter to avoid MapLibre conflicts */
.bus-marker-wrapper {
  animation: markerFadeIn 0.3s ease-out;
}

.bus-marker-wrapper:hover svg path {
  stroke: rgba(255, 255, 255, 0.8);
  stroke-width: 2.5;
}

@keyframes markerFadeIn {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

/* Utility */
.hidden {
  pointer-events: none;
}