@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,300&display=swap');

/* ── Design Tokens ───────────────────────────────────────────────── */
:root {
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'SF Pro Display', sans-serif;

  /* Glass layers */
  --glass-bg: rgba(255, 255, 255, 0.52);
  --glass-bg-deep: rgba(255, 255, 255, 0.58);
  --glass-border: rgba(255, 255, 255, 0.6);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.10), 0 1px 0 rgba(255, 255, 255, 0.8) inset;
  --glass-shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.14), 0 1px 0 rgba(255, 255, 255, 0.9) inset;
  --blur: blur(24px) saturate(180%);

  /* Palette — Light */
  --bg: #e8edf5;
  --bg-gradient: radial-gradient(ellipse at 20% 0%, #dce8f8 0%, #e6ecf5 40%, #eceaf8 100%);
  --surface: rgba(255, 255, 255, 0.72);
  --surface-raised: rgba(255, 255, 255, 0.92);
  --on-surface: #0d0d0e;
  --on-surface-dim: rgba(13, 13, 14, 0.55);
  --on-surface-dimmer: rgba(13, 13, 14, 0.35);

  /* Accent colors */
  --accent: #0a84ff;
  --accent-green: #30d158;
  --accent-orange: #ff9f0a;
  --accent-red: #ff453a;
  --accent-purple: #bf5af2;

  /* Line colours */
  --lrt1: #1a8a4a;
  --mrt3: #d4aa00;
  --lrt2: #8c44c8;

  /* Radii */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-2xl: 36px;

  /* Motion */
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  /* MD3 tokens for compatibility */
  --md-sys-color-primary: #0a84ff;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: rgba(10, 132, 255, 0.15);
  --md-sys-color-on-primary-container: #0a84ff;
  --md-sys-color-surface: #fdfcff;
  --md-sys-color-surface-variant: rgba(0, 0, 0, 0.08);
  --md-sys-color-on-surface: #0d0d0e;
  --md-sys-color-on-surface-variant: rgba(13, 13, 14, 0.55);
  --md-sys-color-outline: rgba(13, 13, 14, 0.3);
  --md-sys-color-error: #ff453a;
  --md-sys-color-success: #30d158;

  --elevation-1: 0 2px 8px rgba(0, 0, 0, 0.08);
  --elevation-2: 0 4px 16px rgba(0, 0, 0, 0.10);
  --elevation-3: 0 8px 24px rgba(0, 0, 0, 0.12);
}

[data-theme="dark"] {
  /* Glass layers */
  --glass-bg: rgba(26, 26, 28, 0.60);
  --glass-bg-deep: rgba(32, 32, 36, 0.64);
  --glass-border: rgba(255, 255, 255, 0.085);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.50), 0 1px 0 rgba(255, 255, 255, 0.06) inset;
  --glass-shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.65), 0 1px 0 rgba(255, 255, 255, 0.05) inset;
  --blur: blur(28px) saturate(200%);

  /* Palette — Dark */
  --bg: #000000;
  --bg-gradient: radial-gradient(ellipse at 25% 5%, #071426 0%, #050507 55%, #08060e 100%);
  --surface: rgba(26, 26, 28, 0.80);
  --surface-raised: rgba(32, 32, 36, 0.94);
  --on-surface: #f0f0f2;
  --on-surface-dim: rgba(240, 240, 242, 0.52);
  --on-surface-dimmer: rgba(240, 240, 242, 0.28);

  --md-sys-color-primary: #0a84ff;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: rgba(10, 132, 255, 0.2);
  --md-sys-color-on-primary-container: #0a84ff;
  --md-sys-color-surface: #1a1c1e;
  --md-sys-color-surface-variant: rgba(255, 255, 255, 0.08);
  --md-sys-color-on-surface: #f0f0f2;
  --md-sys-color-on-surface-variant: rgba(240, 240, 242, 0.52);
  --md-sys-color-outline: rgba(240, 240, 242, 0.2);
  --md-sys-color-error: #ff453a;
  --md-sys-color-success: #30d158;

  --elevation-1: 0 2px 8px rgba(0, 0, 0, 0.3);
  --elevation-2: 0 4px 16px rgba(0, 0, 0, 0.4);
  --elevation-3: 0 8px 24px rgba(0, 0, 0, 0.5);
}

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

html {
  height: 100%;
  /* Prevent layout shift from dynamic browser UI on Android Chrome */
  height: -webkit-fill-available;
}

body {
  height: 100vh;
  height: 100dvh;
  /* dynamic viewport: shrinks/grows with Android browser chrome */
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  background: var(--bg);
  background-image: var(--bg-gradient);
  color: var(--on-surface);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Respect Android gesture nav bar and notches */
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* ── Layout ───────────────────────────────────────────────── */
.app-container {
  height: 100vh;
  height: 100dvh;
  /* dynamic viewport height for Android */
  display: flex;
  flex-direction: column;
  position: relative;
}

.map-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
}


.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--r-md);
  border: none;
  background: transparent;
  color: var(--on-surface-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.18s var(--ease);
}

.icon-btn:hover {
  background: var(--glass-bg-deep);
  color: var(--on-surface);
  box-shadow: var(--glass-shadow);
}

.actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Theme Pill */
.theme-pill {
  display: flex;
  align-items: center;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-xl);
  padding: 3px;
  gap: 2px;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--glass-shadow);
}

.theme-pill button {
  width: 26px;
  height: 26px;
  border-radius: var(--r-lg);
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--on-surface-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: all 0.2s var(--spring);
}

.theme-pill button.active {
  background: var(--glass-bg-deep);
  color: var(--on-surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

/* ── Fallback for Cached HTML Clients ───────────────── */
.header {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 200;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  pointer-events: none;
}

.header>* {
  pointer-events: auto;
}

.branding {
  display: none !important;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 100px;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--glass-shadow);
}

/* ── Glass Pill — vitals overlay ──────────────────────────── */
.overlay-vitals {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 7px;
  pointer-events: none;
}

.overlay-vitals>* {
  pointer-events: auto;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  background: var(--glass-bg);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  border-radius: 100px;
  box-shadow: var(--glass-shadow);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--on-surface);
  cursor: default;
  transition: all 0.2s var(--ease);
  white-space: nowrap;
}

.chip:hover {
  background: var(--glass-bg-deep);
  transform: translateY(-1px);
  box-shadow: var(--glass-shadow-lg);
}

.chip[onclick],
.chip[onclick] {
  cursor: pointer;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-red);
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(255, 69, 58, 0.25);
  transition: background 0.4s, box-shadow 0.4s;
}

.status-dot.connected {
  background: var(--accent-green);
  box-shadow: 0 0 0 2px rgba(48, 209, 88, 0.25);
  animation: pulse-dot 2.4s ease infinite;
}

@keyframes pulse-dot {

  0%,
  100% {
    box-shadow: 0 0 0 2px rgba(48, 209, 88, 0.25);
  }

  50% {
    box-shadow: 0 0 0 4px rgba(48, 209, 88, 0.12);
  }
}

/* ── FABs ─────────────────────────────────────────────────── */
.fab-container {
  position: absolute;
  right: 14px;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.fab {
  width: 50px;
  height: 50px;
  border-radius: var(--r-lg);
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--glass-shadow);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.22s var(--spring);
  outline: none;
}

.fab:hover {
  transform: scale(1.07);
  box-shadow: var(--glass-shadow-lg);
}

.fab:active {
  transform: scale(0.94);
}

.fab.small {
  width: 38px;
  height: 38px;
  border-radius: var(--r-md);
  background: transparent;
  border: none;
  box-shadow: none;
  backdrop-filter: none;
  color: var(--on-surface-dim);
}

.fab.small:hover {
  background: var(--glass-bg);
  box-shadow: var(--glass-shadow);
  color: var(--on-surface);
}

/* ── Bottom Sheet ─────────────────────────────────────────── */
.bottom-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 500;
  max-width: 460px;
  margin: 0 auto;
  max-height: 82vh;
  overflow-y: auto;
  overflow-x: hidden;

  background: var(--glass-bg-deep);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  border-bottom: none;
  border-radius: var(--r-2xl) var(--r-2xl) 0 0;
  box-shadow: var(--glass-shadow-lg);

  padding: 0;
  transform: translateY(105%);
  transition: transform 0.42s var(--spring);

  scrollbar-width: none;
  -ms-overflow-style: none;
  will-change: transform;
}

.bottom-sheet::-webkit-scrollbar {
  display: none;
}



.bottom-sheet.visible {
  transform: translateY(0);
}

@media (max-width: 768px) {
  .bottom-sheet {
    max-height: 88dvh;
    overflow-y: scroll !important;
    padding-bottom: 80px;
    -webkit-overflow-scrolling: touch;
  }

  body.mode-native .bottom-sheet {
    padding-bottom: calc(16px + env(safe-area-inset-bottom)) !important;
  }
}

/* Drag handle */
.sheet-handle {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--on-surface-dimmer);
  margin: 0 auto;
}

/* ── Sheet Header ─────────────────────────────────────────── */
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 0;
  margin-bottom: 18px;
}

.title-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.title-group h2 {
  font-size: clamp(16px, 5vw, 19px);
  font-weight: 650;
  letter-spacing: -0.4px;
  white-space: nowrap;
}

.close-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--glass-bg);
  color: var(--on-surface-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--glass-shadow);
  transition: all 0.18s var(--ease);
}

.close-btn:hover {
  background: var(--glass-bg-deep);
  color: var(--accent-red);
}

/* Station header top */
.station-header-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.station-header-top h2 {
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.4px;
  flex: 1;
}

.station-card-arrivals-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--on-surface-dimmer);
  margin-bottom: 10px;
}

.station-view-more {
  padding: 10px 0 4px;
  display: flex;
  justify-content: center;
}

/* ── Badge Routes ─────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 10px;
  border-radius: var(--r-sm);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: #fff;
}

.badge-route {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: #fff;
  border-radius: var(--r-xs);
  white-space: nowrap;
}

.badge-route-sm {
  height: 22px;
  min-width: 50px;
  font-size: 10px;
  padding: 0 8px;
}

.badge-route-md {
  height: 26px;
  min-width: 56px;
  font-size: 11px;
  padding: 0 10px;
}

.badge-route-lg {
  height: 30px;
  min-width: 64px;
  font-size: 12px;
  padding: 0 12px;
}

.badge-lrt1 {
  background: var(--lrt1);
}

.badge-mrt3 {
  background: var(--mrt3);
  color: #111;
}

.badge-lrt2 {
  background: var(--lrt2);
}

.badge-mrt7 {
  background: #e51e24;
}

.badge-jeep {
  background: #d95a10;
}

.badge-carousel {
  background: #0068b5;
}

/* Density badges */
.badge-density {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  min-width: 60px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  border-radius: 100px;
  padding: 0 10px;
  border: 1.5px solid currentColor;
}

.badge-light {
  color: var(--accent-green);
  background: rgba(48, 209, 88, 0.10);
}

.badge-moderate {
  color: var(--accent-orange);
  background: rgba(255, 159, 10, 0.10);
}

.badge-heavy {
  color: var(--accent-red);
  background: rgba(255, 69, 58, 0.10);
}

.badge-unknown {
  color: var(--on-surface-dim);
  background: transparent;
}

/* ── Metric Cards ─────────────────────────────────────────── */
.grid-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 20px 18px;
}

.card-metric {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

.card-metric .label {
  font-size: 10px;
  font-weight: 600;
  color: var(--on-surface-dimmer);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.card-metric .value {
  font-size: clamp(17px, 5.5vw, 22px);
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--on-surface);
}

/* ── Station Card ─────────────────────────────────────────── */
.station-card-header {
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--on-surface-dimmer);
  padding: 0 20px;
  margin-bottom: 8px;
}

.arrival-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 20px;
  border-bottom: 1px solid var(--glass-border);
  transition: background 0.15s;
}

.arrival-row:hover {
  background: rgba(255, 255, 255, 0.025);
}

.arrival-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}

.arrival-dest {
  font-size: 15px;
  font-weight: 550;
  letter-spacing: -0.2px;
}

.arrival-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

.arrival-time {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.4px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.arrival-live {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent-green);
  display: flex;
  align-items: center;
  gap: 4px;
}

.arrival-live::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent-green);
  animation: pulse-dot 1.8s ease infinite;
}

.notify-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
}

.notify-row .label-text {
  font-size: 13.5px;
  font-weight: 500;
}

.station-card-body {
  padding: 14px 20px 20px;
}

.station-arrival-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px solid var(--glass-border);
  transition: background 0.15s;
}

.station-arrival-row:hover {
  background: rgba(255, 255, 255, 0.025);
}

.station-arrival-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}

.station-arrival-destination {
  font-size: 15px;
  font-weight: 550;
  letter-spacing: -0.2px;
}

.station-arrival-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

.station-arrival-time {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--accent);
}

.station-arrival-status {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent-green);
}

/* ── Notify Row ───────────────────────────────────────────── */
.station-notify-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 0;
  margin-top: 6px;
  border-top: 1px solid var(--glass-border);
}

.notify-label {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--on-surface);
}

/* ── Toggle Switch (iOS style) ────────────────────────────── */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 30px;
  flex-shrink: 0;
}

.toggle-switch input {
  display: none;
}

.slider {
  position: absolute;
  inset: 0;
  background: var(--on-surface-dimmer);
  border-radius: 100px;
  cursor: pointer;
  transition: background 0.24s var(--ease);
}

.slider::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 24px;
  height: 24px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.28);
  transition: transform 0.26s var(--spring);
}

.toggle-switch input:checked+.slider {
  background: var(--accent-green);
}

.toggle-switch input:checked+.slider::before {
  transform: translateX(20px);
}

/* ── Train Details Card ───────────────────────────────────── */
.train-details-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 0;
  margin-bottom: 16px;
}

.train-details-header h2 {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.5px;
}

.train-details-body {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0 20px 20px;
}

.train-details-row {
  padding: 11px 0;
  border-bottom: 1px solid var(--glass-border);
}

.train-details-row:last-child {
  border-bottom: none;
}

.train-details-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.train-details-value {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.3px;
  color: var(--on-surface);
}

.train-details-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--on-surface-dimmer);
}

/* ── PIDS Board ───────────────────────────────────────────── */
.pids-container {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 20px 20px 16px;
}

.pids-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.pids-station-name {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pids-station-name h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.pids-transfer-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--on-surface-dim);
  margin-top: 5px;
}

.pids-datetime {
  text-align: right;
  flex-shrink: 0;
}

.pids-date {
  font-size: 11px;
  font-weight: 500;
  color: var(--on-surface-dimmer);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.pids-time {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  color: var(--on-surface);
}

.pids-trains {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.pids-direction-section {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  overflow: hidden;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

.pids-direction-title {
  padding: 10px 14px;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.03);
}

[data-theme="dark"] .pids-direction-title {
  background: rgba(255, 255, 255, 0.04);
}

.pids-direction-title h2 {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--on-surface-dimmer);
}

.pids-train-row {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  gap: 10px;
  font-size: 14px;
}

.pids-footer {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--glass-border);
}

.pids-footer h3 {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--on-surface-dimmer);
  margin-bottom: 10px;
}

.pids-connections {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ── Train Markers ────────────────────────────────────────── */
.train-marker-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s var(--ease);
  /* Android / Mali-G57 optimization: promote to own compositor layer.
     Prevents paint storms when many markers move simultaneously. */
  will-change: transform;
  transform: translateZ(0);
}

.train-circle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  /* GPU layer promotion — avoids forcing a repaint on the parent stacking context */
  transform: translateZ(0);
}

.direction-arrow {
  position: absolute;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 10px solid rgba(255, 255, 255, 0.9);
  z-index: 3;
  top: -13px;
  left: 50%;
  transform-origin: 50% 28px;
  /* Use translate3d in JS; keep transition here for < 50 markers.
     If marker count > 50, JS switches to canvas (see trainsight.js). */
  transition: transform 0.4s var(--spring);
  will-change: transform;
}

.station-marker {
  width: 9px;
  height: 9px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  border: 2.5px solid;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
  /* Expand tap target to 44px minimum without changing visual size */
  /* padding: 10px;
  margin: -10px; */
  box-sizing: content-box;
}

/* ── Selection Ring ───────────────────────────────────────── */
.selection-ring {
  position: absolute;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2.5px solid var(--accent);
  animation: pulse-ring 1.8s ease infinite;
  pointer-events: none;
  z-index: 1;
  box-sizing: border-box;
}

@keyframes pulse-ring {
  0% {
    transform: scale(0.65);
    opacity: 1;
  }

  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}

/* ── Modal & Dialogs ──────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s var(--ease);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.md-dialog {
  background: var(--glass-bg-deep);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-2xl);
  padding: 28px;
  width: 90%;
  max-width: 380px;
  box-shadow: var(--glass-shadow-lg);
  animation: slideUp 0.32s var(--spring);
}

@keyframes slideUp {
  from {
    transform: translateY(24px) scale(0.97);
    opacity: 0;
  }

  to {
    transform: none;
    opacity: 1;
  }
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn-text {
  padding: 10px 16px;
  border-radius: var(--r-xl);
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--accent);
  transition: background 0.18s;
}

.btn-text:hover {
  background: rgba(10, 132, 255, 0.08);
}

.btn-filled {
  padding: 11px 24px;
  border-radius: var(--r-xl);
  border: none;
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(10, 132, 255, 0.35);
  transition: all 0.2s var(--ease);
}

.btn-filled:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-filled:active {
  transform: scale(0.97);
}

/* ── Settings Items ───────────────────────────────────────── */
.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 16px;
  background: var(--glass-bg);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  margin-bottom: 8px;
  transition: background 0.18s;
}

.setting-item:hover {
  background: var(--glass-bg-deep);
}

.setting-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.setting-label span {
  font-size: 14px;
  font-weight: 550;
}

.setting-label small {
  font-size: 11.5px;
  color: var(--on-surface-dim);
}

/* ── Alerts List ──────────────────────────────────────────── */
.alerts-modal-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 55vh;
}

.alerts-list {
  overflow-y: auto;
  scrollbar-width: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.alert-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  padding: 11px 14px;
  border-radius: var(--r-md);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

.alert-info {
  display: flex;
  flex-direction: column;
}

.alert-name {
  font-weight: 600;
  font-size: 14px;
}

.alert-line {
  font-size: 11px;
  color: var(--on-surface-dim);
}

.remove-alert-btn {
  background: none;
  border: none;
  color: var(--accent-red);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  transition: background 0.18s;
}

.remove-alert-btn:hover {
  background: rgba(255, 69, 58, 0.1);
}

/* ── Station List ──────────────────────────────────────────── */
.station-list-container {
  padding: 0 20px 20px;
  overflow-y: auto;
  scrollbar-width: none;
  max-height: 60vh;
}

.station-list-search {
  position: relative;
  margin-bottom: 14px;
}

.station-list-search input {
  width: 100%;
  padding: 10px 14px 10px 36px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-xl);
  font-family: var(--font);
  font-size: 14px;
  color: var(--on-surface);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.station-list-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.15);
}

.station-list-search input::placeholder {
  color: var(--on-surface-dimmer);
}

.station-list-search .search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--on-surface-dimmer);
  pointer-events: none;
}

.station-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  cursor: pointer;
  margin-bottom: 7px;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  transition: all 0.18s var(--ease);
}

.station-item:hover {
  background: var(--glass-bg-deep);
  transform: translateX(2px);
}

.station-name-text {
  font-size: 14px;
  font-weight: 550;
}

/* ── Privacy Card (Welcome Modal) ──────────────────────────── */
.privacy-card {
  background: rgba(10, 132, 255, 0.08);
  border: 1px solid rgba(10, 132, 255, 0.18);
  border-radius: var(--r-md);
  padding: 16px;
  margin-bottom: 22px;
  text-align: left;
}

.privacy-card h3 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 7px;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--accent);
}

.privacy-card p {
  font-size: 12px;
  line-height: 1.65;
  color: var(--on-surface-dim);
}

/* ── MapLibre attribution ─────────────────────────────────── */
.maplibregl-ctrl-attrib {
  background: rgba(0, 0, 0, 0.45) !important;
  color: rgba(255, 255, 255, 0.55) !important;
  backdrop-filter: blur(8px);
  border-radius: var(--r-sm) !important;
}

.maplibregl-ctrl-attrib a {
  color: rgba(255, 255, 255, 0.55) !important;
}

/* ── Responsive tweaks ──────────────────────────────────────── */
@media (max-width: 600px) {

  .train-details-row:nth-child(5),
  .train-details-row:nth-child(6) {
    display: none !important;
  }
}

@media (max-width: 420px) {

  /* Ultra-compact mode for small vertical screens */
  .sheet-header {
    padding: 12px 14px 0 !important;
    margin-bottom: 10px !important;
  }

  .title-group h2 {
    font-size: 15px !important;
  }

  .title-group {
    gap: 4px !important;
    flex-direction: column !important;
    align-items: flex-start !important;
  }

  .badge-route-sm {
    padding: 0 4px !important;
    font-size: 9px !important;
    height: 18px !important;
    min-width: 36px !important;
  }

  .btn-text {
    font-size: 11px !important;
    padding: 4px 6px !important;
  }

  .grid-metrics {
    padding: 0 14px 12px !important;
    gap: 6px !important;
  }

  .card-metric {
    padding: 8px 10px !important;
    border-radius: 12px !important;
  }

  .card-metric .label {
    font-size: 9px !important;
  }

  .card-metric .value {
    font-size: 14px !important;
  }

  .train-details-body {
    padding: 0 14px 12px !important;
  }

  .section-title {
    margin-bottom: 2px !important;
    font-size: 9px !important;
  }

  .arrival-row,
  .train-details-row {
    padding: 6px 0 !important;
  }

  .train-details-row .train-details-item {
    gap: 1px !important;
  }

  .train-details-value,
  .arrival-row>div:nth-child(2) {
    font-size: 13px !important;
  }

  .train-details-label,
  .arrival-dest {
    font-size: 10px !important;
  }

  .station-card-header {
    padding: 12px 14px 10px !important;
    gap: 4px !important;
  }

  .station-card-body {
    padding: 10px 14px 14px !important;
  }

  .station-card-arrivals-title {
    margin-bottom: 6px !important;
    font-size: 9px !important;
  }

  #pids-arrivals-list {
    gap: 8px !important;
  }

  .bottom-sheet {
    border-radius: var(--r-xl) var(--r-xl) 0 0 !important;
  }
}

/* ── Toast notification ────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--glass-bg-deep);
  border: 1px solid var(--glass-border);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-radius: 100px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--on-surface);
  box-shadow: var(--glass-shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: all 0.28s var(--ease);
  z-index: 4000;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

@keyframes wiggle {

  0%,
  100% {
    transform: rotate(0deg);
  }

  25% {
    transform: rotate(-10deg);
  }

  75% {
    transform: rotate(10deg);
  }
}

.wiggle-icon {
  animation: wiggle 0.6s ease-in-out infinite;
}

/* ── Station Favorite Button ──────────────────────────────── */
#station-fav-btn {
  transition: color 0.2s var(--ease), transform 0.15s var(--spring);
}

#station-fav-btn:active {
  transform: scale(0.85);
}

/* ── Low Graphics Mode ────────────────────────────────────── */
/*
 * When enabled, all backdrop-filter/blur effects are replaced with
 * solid opaque surfaces, and all non-essential animations are halted.
 * This greatly improves performance on low-end devices.
 */

body.low-graphics *,
body.low-graphics *::before,
body.low-graphics *::after {
  /* Kill all animations and transitions except critical visibility ones */
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}

/* Exempt sheet slide-in/out transitions so sheets still open */
body.low-graphics .bottom-sheet {
  transition: transform 0.2s ease !important;
}

/* Exempt overlay fade */
body.low-graphics .sheet-overlay {
  transition: opacity 0.15s ease !important;
}

/* Exempt toast */
body.low-graphics .toast {
  transition: opacity 0.2s ease, transform 0.2s ease !important;
}

/* Replace all glass/blur surfaces with solid equivalents */
body.low-graphics .chip,
body.low-graphics .fab,
body.low-graphics .bottom-sheet,
body.low-graphics .md-dialog,
body.low-graphics .setting-item,
body.low-graphics .alert-item,
body.low-graphics .station-item,
body.low-graphics .theme-pill,
body.low-graphics .header-right,
body.low-graphics .card-metric,
body.low-graphics .grid-metrics,
body.low-graphics .toast,
body.low-graphics .station-list-search input,
body.low-graphics .privacy-card {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* Dark theme solid surfaces */
[data-theme="dark"] body.low-graphics .chip,
[data-theme="dark"] body.low-graphics .fab,
[data-theme="dark"] body.low-graphics .theme-pill,
[data-theme="dark"] body.low-graphics .header-right,
[data-theme="dark"] body.low-graphics .setting-item,
[data-theme="dark"] body.low-graphics .alert-item,
[data-theme="dark"] body.low-graphics .station-item {
  background: #1c1c1e !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
}

[data-theme="dark"] body.low-graphics .bottom-sheet,
[data-theme="dark"] body.low-graphics .md-dialog {
  background: #1c1c1e !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
}

[data-theme="dark"] body.low-graphics .toast {
  background: #2c2c2e !important;
}

[data-theme="dark"] body.low-graphics .station-list-search input {
  background: #2c2c2e !important;
}

/* Light theme solid surfaces */
body:not([data-theme="dark"]) body.low-graphics .chip,
body:not([data-theme="dark"]) body.low-graphics .fab,
body:not([data-theme="dark"]) body.low-graphics .theme-pill,
body:not([data-theme="dark"]) body.low-graphics .header-right,
body:not([data-theme="dark"]) body.low-graphics .setting-item,
body:not([data-theme="dark"]) body.low-graphics .alert-item,
body:not([data-theme="dark"]) body.low-graphics .station-item {
  background: #ffffff !important;
  border-color: rgba(0, 0, 0, 0.1) !important;
}

body:not([data-theme="dark"]) body.low-graphics .bottom-sheet,
body:not([data-theme="dark"]) body.low-graphics .md-dialog {
  background: #f2f2f7 !important;
}

/* Simpler selector for body itself carrying the theme */
body[data-theme="dark"].low-graphics .chip,
body[data-theme="dark"].low-graphics .fab,
body[data-theme="dark"].low-graphics .theme-pill,
body[data-theme="dark"].low-graphics .header-right,
body[data-theme="dark"].low-graphics .setting-item,
body[data-theme="dark"].low-graphics .alert-item,
body[data-theme="dark"].low-graphics .station-item {
  background: #1c1c1e !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
}

body[data-theme="dark"].low-graphics .bottom-sheet,
body[data-theme="dark"].low-graphics .md-dialog {
  background: #1c1c1e !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
}

body[data-theme="dark"].low-graphics .toast,
body[data-theme="dark"].low-graphics .card-metric,
body[data-theme="dark"].low-graphics .grid-metrics {
  background: #2c2c2e !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

body[data-theme="dark"].low-graphics .station-list-search input {
  background: #2c2c2e !important;
}

body:not([data-theme="dark"]).low-graphics .chip,
body:not([data-theme="dark"]).low-graphics .fab,
body:not([data-theme="dark"]).low-graphics .theme-pill,
body:not([data-theme="dark"]).low-graphics .header-right,
body:not([data-theme="dark"]).low-graphics .setting-item,
body:not([data-theme="dark"]).low-graphics .alert-item,
body:not([data-theme="dark"]).low-graphics .station-item {
  background: #ffffff !important;
  border-color: rgba(0, 0, 0, 0.1) !important;
}

body:not([data-theme="dark"]).low-graphics .bottom-sheet,
body:not([data-theme="dark"]).low-graphics .md-dialog {
  background: #f2f2f7 !important;
}

body:not([data-theme="dark"]).low-graphics .toast,
body:not([data-theme="dark"]).low-graphics .card-metric {
  background: #ffffff !important;
}

/* Disable pulsing dots and selection rings in low-graphics */
body.low-graphics .status-dot.connected {
  animation: none !important;
  box-shadow: 0 0 0 2px rgba(48, 209, 88, 0.25) !important;
}

body.low-graphics .selection-ring,
body.low-graphics .station-selection-ring {
  display: none !important;
}

body.low-graphics .chip:hover {
  transform: none !important;
}

body.low-graphics .fab:hover,
body.low-graphics .fab:active {
  transform: none !important;
}

body.low-graphics .station-item:hover {
  transform: none !important;
}

body.low-graphics .btn-filled:active {
  transform: none !important;
}