/* ==========================================================================
   Halifax Transit Live — Mobile First Design System
   Aesthetic: Snapchat Map / iOS Transit Dark Mode with Glassmorphism
   ========================================================================== */

:root {
  --bg-base: #080c14;
  --bg-surface: rgba(15, 23, 42, 0.88);
  --bg-surface-solid: #0f172a;
  --bg-card: rgba(30, 41, 59, 0.7);
  --bg-input: rgba(15, 23, 42, 0.95);
  --border: rgba(255, 255, 255, 0.1);
  --border-glow: rgba(56, 189, 248, 0.35);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-cyan: #38bdf8;
  --accent-blue: #3b82f6;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-purple: #8b5cf6;
  --accent-pink: #ec4899;
  --accent-red: #ef4444;

  --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", Menlo, Monaco, Consolas, monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-system);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: pan-x pan-y;
  user-select: none;
  -webkit-user-select: none;
}

#app-container {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Map Container
   ========================================================================== */
#map {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* MapLibre Controls Customization */
.maplibregl-ctrl-top-right,
.maplibregl-ctrl-bottom-right {
  margin-right: max(14px, var(--safe-right)) !important;
}

.maplibregl-ctrl-group {
  background: var(--bg-surface) !important;
  backdrop-filter: blur(16px) !important;
  -webkit-backdrop-filter: blur(16px) !important;
  border: 1px solid var(--border) !important;
  border-radius: 16px !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4) !important;
  overflow: hidden !important;
}

.maplibregl-ctrl-group button {
  width: 44px !important;
  height: 44px !important;
  border-bottom: 1px solid var(--border) !important;
}

.maplibregl-ctrl-group button:last-child {
  border-bottom: none !important;
}

.maplibregl-ctrl-icon {
  filter: invert(1) brightness(1.8) !important;
}

/* ==========================================================================
   Floating Top Header & Search Bar (Snapchat Style)
   ========================================================================== */
#top-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: max(10px, var(--safe-top)) max(12px, var(--safe-right)) 8px max(12px, var(--safe-left));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(8, 12, 20, 0.85) 0%, rgba(8, 12, 20, 0.4) 75%, transparent 100%);
}

#top-overlay > * {
  pointer-events: auto;
}

.header-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-container {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.search-input {
  width: 100%;
  height: 40px;
  padding: 0 36px 0 38px;
  background: var(--bg-surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  outline: none;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  transition: border-color 0.15s ease;
}

.search-input:focus {
  border-color: var(--accent-cyan);
}

.search-input::placeholder {
  color: var(--text-muted);
  font-size: 14px;
}

.search-icon {
  position: absolute;
  left: 14px;
  font-size: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-clear-btn {
  position: absolute;
  right: 10px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: pointer;
  visibility: hidden;
}

.search-clear-btn.visible {
  visibility: visible;
}

/* Status Indicator Pill */
.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 12px;
  background: var(--bg-surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
  transition: background-color 0.3s;
}

.pulse-dot.live {
  animation: pulseLive 2s infinite ease-in-out;
}

.pulse-dot.stale {
  background: var(--accent-amber);
  box-shadow: 0 0 8px var(--accent-amber);
}

.pulse-dot.error {
  background: var(--accent-red);
  box-shadow: 0 0 8px var(--accent-red);
}

@keyframes pulseLive {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

/* Route Filter Chips */
.route-chips-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 2px 6px 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.route-chips-scroll::-webkit-scrollbar {
  display: none;
}

.chip-btn {
  flex-shrink: 0;
  height: 30px;
  padding: 0 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.12s ease;
}

.chip-btn:active {
  transform: scale(0.95);
}

.chip-btn.active {
  background: var(--accent-cyan);
  color: #030712;
  border-color: var(--accent-cyan);
}

/* ==========================================================================
   Bus markers are rendered as WebGL symbol layers — no DOM marker CSS needed.
   ========================================================================== */

/* ==========================================================================
   Bottom Sheet (Retractable Drawer)
   ========================================================================== */
#bottom-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--bg-surface-solid);
  border-top: 1px solid var(--border);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  max-height: 75dvh;
  transform: translateY(105%);
  transition: transform 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
  padding-bottom: max(12px, var(--safe-bottom));
  touch-action: pan-y;
  user-select: none;
}

#bottom-sheet.open {
  visibility: visible;
}

/* Drag Handle */
.sheet-drag-handle {
  width: 100%;
  padding: 10px 0 4px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: grab;
  touch-action: none;
}

.sheet-drag-handle:active {
  cursor: grabbing;
}

.drag-pill {
  width: 38px;
  height: 4px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
}

/* Close Sheet Button */
.sheet-close-btn {
  position: absolute;
  top: 8px;
  right: 12px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  z-index: 10;
  transition: background 0.15s;
}

.sheet-close-btn:active {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

/* Peek Content (always visible in peek & full) */
.sheet-peek-content {
  padding: 4px 16px 10px;
  flex-shrink: 0;
  cursor: pointer;
}

.sheet-top-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sheet-title-stack {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.route-pill-large {
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 800;
  color: #ffffff;
  background: var(--accent-blue);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

.bus-num-large {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.destination-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Compact Action Buttons */
.bus-actions-compact {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.action-btn-compact {
  height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(30, 41, 59, 0.7);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.action-btn-compact:active {
  transform: scale(0.95);
}

.action-btn-compact.active {
  background: var(--accent-cyan);
  color: #030712;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.4);
}

/* Expanded Content (scrollable below peek) */
.sheet-expanded-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Telemetry Grid (Speed, Heading, Freshness) */
.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.telemetry-card {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
}

.telemetry-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.telemetry-val-group {
  display: flex;
  align-items: baseline;
  gap: 3px;
  margin-top: 3px;
}

.telemetry-val {
  font-size: 17px;
  font-weight: 800;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.telemetry-unit {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
}

/* Upcoming Stops Section */
.stops-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stops-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stops-title {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.stops-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stop-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 13px;
}

.stop-row.next-stop {
  border-color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.08);
}

.stop-seq {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  width: 18px;
}

.stop-name {
  flex: 1;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stop-eta-badge {
  font-weight: 800;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  white-space: nowrap;
}

.stop-delay {
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.delay-ontime { color: var(--text-muted); }
.delay-early { color: var(--accent-green); }
.delay-late { color: var(--accent-red); }

/* ==========================================================================
   iOS "Add to Home Screen" Banner
   ========================================================================== */
#ios-install-banner {
  position: absolute;
  bottom: max(16px, var(--safe-bottom));
  left: max(14px, var(--safe-left));
  right: max(14px, var(--safe-right));
  z-index: 15;
  background: var(--bg-surface-solid);
  border: 1px solid var(--border-glow);
  border-radius: 20px;
  padding: 14px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  gap: 12px;
  animation: slideUpBanner 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#ios-install-banner.visible {
  display: flex;
}

@keyframes slideUpBanner {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.install-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.install-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.install-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-primary);
}

.install-subtitle {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.3;
}

.install-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}
