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

body { height: 100vh; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #111; }

#map { height: 100vh; width: 100%; }

/* ── Control Panel ── */
#panel {
  position: absolute;
  top: 16px; left: 16px;
  z-index: 1000;
  background: rgba(16,18,27,0.93);
  color: #e8eaf0;
  border-radius: 14px;
  padding: 16px 18px;
  min-width: 210px;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.07);
}

#panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

#panel-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #fff;
}

#panel-toggle {
  display: none; /* shown only on mobile via media query */
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}

.section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: rgba(255,255,255,0.35);
  margin-bottom: 10px;
}

/* Toggle rows */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  cursor: pointer;
  user-select: none;
}

.toggle-row input[type="checkbox"] { display: none; }

.toggle-track {
  position: relative;
  width: 34px; height: 18px;
  background: rgba(255,255,255,0.15);
  border-radius: 9px;
  flex-shrink: 0;
  transition: background 0.2s;
}

.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #888;
  transition: transform 0.2s, background 0.2s;
}

.toggle-row input:checked + .toggle-track { background: rgba(99,179,237,0.35); }
.toggle-row input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); background: #63b3ed; }

.toggle-aux-divider {
  height: 1px;
  background: rgba(255,255,255,0.1);
  margin: 6px 0;
}

.toggle-row-linked {
  padding-left: 14px;
  border-left: 2px solid rgba(255,199,44,0.22);
  margin-left: 2px;
}
.toggle-row-linked .toggle-label { color: #9aa0b0; }
.toggle-row-linked input:checked + .toggle-track { background: rgba(255,199,44,0.28); }
.toggle-row-linked input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); background: #FFC72C; }

.swatch {
  width: 11px; height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

.toggle-label { font-size: 13px; color: #d0d4e0; }

/* Bus progress */
#bus-progress { margin-top: 8px; }
.progress-bar-wrap { height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; overflow: hidden; }
.progress-bar-fill { height: 100%; width: 0%; background: #FFC72C; border-radius: 2px; transition: width 0.3s; }
.progress-label { font-size: 11px; color: rgba(255,255,255,0.4); margin-top: 4px; }

.divider { border: none; border-top: 1px solid rgba(255,255,255,0.08); margin: 12px 0; }

#status-line { font-size: 11px; color: rgba(255,255,255,0.4); }
#vehicle-count { font-size: 11px; color: rgba(255,255,255,0.3); margin-top: 2px; }

/* ── Stop Predictions Panel ── */
#stop-panel {
  position: absolute;
  bottom: 20px; right: 20px;
  z-index: 1000;
  background: rgba(16,18,27,0.95);
  color: #e8eaf0;
  border-radius: 14px;
  width: 330px;
  max-height: 520px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 28px rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(12px);
  transition: opacity 0.2s, transform 0.2s;
}

#stop-panel.hidden { opacity: 0; pointer-events: none; transform: translateY(10px); }

#stop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  background: rgba(255,255,255,0.06);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}

#stop-name-text { font-size: 14px; font-weight: 600; }

#stop-close {
  background: none; border: none;
  color: rgba(255,255,255,0.5);
  font-size: 18px; cursor: pointer; line-height: 1;
  padding: 0 2px;
}
#stop-close:hover { color: #fff; }

#predictions-body { overflow-y: auto; flex: 1; }

.pred-loading { padding: 20px; text-align: center; font-size: 13px; color: rgba(255,255,255,0.4); }

.pred-dir-header {
  padding: 8px 16px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.35);
  text-transform: uppercase;
}

.pred-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.pred-row:last-child { border-bottom: none; }

.pred-badge {
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 800;
  min-width: 42px;
  text-align: center;
  white-space: nowrap;
  flex-shrink: 0;
}

.pred-headsign { flex: 1; font-size: 12px; color: #c8ccd8; }

.pred-time {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}
.pred-time.arriving  { color: #fc8181; }
.pred-time.soon      { color: #f6c90e; }
.pred-time.later     { color: #68d391; }
.pred-time.scheduled { color: #a0aec0; }

.pred-status { font-size: 10px; color: rgba(255,255,255,0.35); margin-top: 1px; }

.pred-no-service { padding: 16px; font-size: 12px; color: rgba(255,255,255,0.35); text-align: center; }

/* ── Prediction filter toggle ── */
#pred-filter-row {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(0,0,0,0.2);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}

.filter-btn {
  flex: 1;
  padding: 5px 0;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,0.12);
  background: transparent;
  color: rgba(255,255,255,0.45);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.filter-btn:hover { color: rgba(255,255,255,0.75); }

.filter-btn.active {
  background: rgba(255,255,255,0.13);
  color: #fff;
  border-color: rgba(255,255,255,0.28);
}

/* ── Type section headers (Subway / Commuter Rail / Bus) in "All services" view ── */
.pred-type-header {
  padding: 7px 16px 3px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.55);
  background: rgba(255,255,255,0.04);
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* ── Loading Overlay ── */
#loading {
  position: absolute;
  inset: 0; z-index: 2000;
  background: rgba(10,12,20,0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.loading-box { text-align: center; }

.spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: #63b3ed;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

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

#loading-msg { font-size: 14px; color: rgba(255,255,255,0.6); }

.d-none { display: none !important; }

/* ── Terminus labels (subway / CR route end markers) ── */
.terminus-label {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
  opacity: 0.92;
  transform: translate(-50%, -50%);
  display: inline-block;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

/* ── Service alert rows (shown when no predictions exist) ── */
.alert-header {
  padding: 8px 16px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #f6ad55;
  text-transform: uppercase;
}

.alert-row {
  padding: 8px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.alert-row:last-child { border-bottom: none; }

.alert-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 5px;
}

.alert-effect {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #f6ad55;
  text-transform: capitalize;
  margin-bottom: 3px;
}

.alert-text {
  font-size: 12px;
  color: #c8ccd8;
  line-height: 1.4;
}

/* ── Leaflet overrides ── */
.leaflet-control-attribution { font-size: 9px !important; }
.leaflet-popup-content-wrapper { display: none; }

/* ── Mobile layout (≤ 600px) ── */
@media (max-width: 600px) {
  /* Use full viewport height including areas behind notch/home indicator */
  body { height: 100dvh; }
  #map  { height: 100dvh; }

  /* Control panel: tighter, toggle button visible */
  #panel {
    top: calc(12px + env(safe-area-inset-top));
    left: 12px;
    min-width: 0;
    padding: 12px 14px;
    max-width: calc(100vw - 24px);
  }

  #panel-toggle { display: block; }

  /* Collapsed state hides the layer controls but keeps bus progress visible */
  #panel.collapsed .panel-collapsible { display: none; }
  #panel.collapsed { padding-bottom: 12px; }
  #panel.collapsed #panel-header { margin-bottom: 0; }

  /* Predictions panel: full-width bottom sheet */
  #stop-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    border-radius: 14px 14px 0 0;
    max-height: 55vh;
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Slide up from bottom on mobile instead of fading up slightly */
  #stop-panel.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(100%);
  }

  /* Larger touch targets for filter buttons */
  .filter-btn { padding: 8px 0; font-size: 12px; }

  /* Prediction rows: taller for fat-finger tapping */
  .pred-row { padding: 10px 16px; min-height: 48px; }
}
