html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: #f0f0f0;
  color: #333;
  transition: background-color 0.3s, color 0.3s;
  overscroll-behavior: none;
}

#map {
  height: 100vh;
  width: 100vw;
  background-color: #ddd;
  touch-action: pan-x pan-y;
}

.top-right-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 401;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.top-right-controls>* {
  pointer-events: auto;
}

#last-updated,
.theme-switch-wrapper {
  background-color: rgba(255, 255, 255, 0.95);
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 14px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
  max-width: 90vw;
  word-break: break-word;
}

#last-updated .progress-info {
  display: block;
  font-size: 13px;
  color: #555;
  margin-top: 3px;
}

body.dark-mode #last-updated .progress-info {
  color: #ccc;
}

#analytics-link {
  background-color: rgba(0, 85, 166, 0.9);
  color: #fff;
  padding: 5px 12px;
  border-radius: 5px;
  font-size: 14px;
  font-weight: bold;
  text-decoration: none;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
  text-align: center;
  transition: background 0.2s;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

#analytics-link:hover {
  background-color: rgba(0, 68, 133, 1);
}

.theme-switch {
  display: inline-block;
  height: 20px;
  position: relative;
  width: 40px;
}

.theme-switch input {
  display: none;
}

.slider {
  background-color: #ccc;
  bottom: 0;
  left: 0;
  right: 0;
  top: 0;
  position: absolute;
  cursor: pointer;
  border-radius: 20px;
  transition: .4s;
}

.slider:before {
  background-color: #fff;
  content: "";
  position: absolute;
  left: 2px;
  bottom: 2px;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  transition: .4s;
}

input:checked+.slider {
  background-color: #0055A6;
}

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

.leaflet-tooltip.custom-tooltip {
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  border: none;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 0.9em;
  word-break: break-word;
  max-width: 90vw;
}

.custom-tooltip .tooltip-name {
  font-weight: bold;
  font-size: 1.1em;
  margin-bottom: 4px;
}

.custom-tooltip .tooltip-delay.late {
  color: #ff8a8a;
}

.custom-tooltip .tooltip-delay.minor-delay {
  color: #ffd93d;
}

.custom-tooltip .tooltip-delay.ontime,
.custom-tooltip .tooltip-delay.on-time {
  color: #9effb0;
}

.custom-tooltip .tooltip-delay.early {
  color: #8ecae6;
}

/* New: route chip in titles/tooltips */
.route-chip {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.85em;
  line-height: 1;
  vertical-align: baseline;
  background: #0055A6;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.05) inset;
  margin-right: 6px;
}

/* New: alert badges in details header */
.alert-badges {
  position: absolute;
  top: 15px;
  left: 34px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  max-width: calc(100% - 140px);
}

.alert-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.78em;
  font-weight: 600;
  background: #eee;
  color: #333;
  white-space: nowrap;
}

.alert-badge.info {
  background: #e3f2fd;
  color: #0b6bbf;
}
.alert-badge.warning {
  background: #fff3cd;
  color: #856404;
}
.alert-badge.severe {
  background: #fdecea;
  color: #a80d0d;
}
.alert-badge.more {
  background: #e0e0e0;
  color: #333;
}

#details-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 390px;
  max-width: 100vw;
  height: 100vh;
  background: #fff;
  z-index: 1000;
  box-shadow: -3px 0 15px rgba(0, 0, 0, 0.3);
  transform: translateX(100%);
  transition: transform 0.3s, background-color 0.3s, color 0.3s;
  display: flex;
  flex-direction: column;
  will-change: transform;
  overscroll-behavior: contain;
  touch-action: none;
}

#details-panel.open {
  transform: translateX(0);
}

.panel-header {
  padding: 15px 20px 15px 50px;
  background: #f7f7f7;
  border-bottom: 1px solid #ddd;
  flex-shrink: 0;
  position: relative;
  transition: background-color 0.3s, border-color 0.3s;
  min-height: 70px;
  word-break: break-word;
}

.panel-header h2 {
  margin: 0 0 8px 0;
  font-size: 1.2em;
}

.panel-header p {
  margin: 0;
  color: #555;
  line-height: 1.4;
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 24px;
  font-weight: bold;
  cursor: pointer;
  color: #999;
  transition: color 0.2s;
  z-index: 10;
}

.close-btn:active,
.close-btn:focus {
  color: #222;
}

.close-btn:hover {
  color: #333;
}

.delay-banner {
  position: absolute;
  top: 15px;
  left: 0;
  padding: 5px 10px 5px 10px;
  color: #fff;
  font-weight: bold;
  font-size: 0.9em;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
}

/* Keep both variants for compatibility */
.delay-banner.on-time,
.delay-banner.ontime {
  background: #28a745;
}

.delay-banner.minor-delay {
  background: #ffc107;
}

.delay-banner.late {
  background: #dc3545;
}

.delay-banner.early {
  background: #17a2b8;
}

.stops-container {
  overflow-y: auto;
  flex-grow: 1;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  background: inherit;
  min-height: 0;
  overscroll-behavior: contain;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 58px);
}

.stops-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.stops-list li {
  padding: 12px 20px;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: flex-start;
  transition: background-color 0.3s, border-color 0.3s, opacity 0.3s;
  font-size: 15px;
}

.stop-icon {
  margin-right: 15px;
  font-size: 1.5em;
  color: #ccc;
  width: 24px;
  text-align: center;
  padding-top: 5px;
  flex-shrink: 0;
}

.stop-info .name {
  font-weight: bold;
  margin-bottom: 8px;
}

.stop-info .times-grid {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 2px 8px;
  font-size: 0.9em;
  color: #666;
}

.times-grid .label {
  font-weight: bold;
  color: #333;
}

.times-grid .actual {
  font-weight: bold;
}

.times-grid .actual.late {
  color: #dc3545;
}

.times-grid .actual.minor-delay {
  color: #ffc107;
}

.times-grid .actual.early {
  color: #17a2b8;
}

.stop-passed {
  opacity: 0.6;
  background: #f8f9fa;
}

.stop-passed .stop-icon {
  color: #28a745;
  font-weight: bold;
}

.stop-passed .name {
  color: #6c757d;
}

.stop-current {
  background: #fff3cd;
  border-left: 4px solid #ffc107;
}

.stop-current .stop-icon {
  color: #ffc107;
  font-weight: bold;
}

.platform {
  font-size: 0.88em;
  color: #888;
  font-weight: normal;
  background: #f4f4f4;
  border-radius: 3px;
  padding: 0 6px;
  margin-left: 8px;
}

.locate-me-btn {
  display: none;
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 410;
  background: #fff;
  color: #0055A6;
  border: none;
  outline: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
  font-size: 22px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
  padding: 0;
}

.locate-me-btn:active {
  background: #e4e4e4;
}

.locate-me-btn svg {
  width: 26px;
  height: 26px;
  display: block;
  margin: auto;
}

@media (max-width: 900px) {
  .locate-me-btn {
    display: flex;
  }
}

@media (max-width: 600px) {
  #details-panel {
    width: 100vw;
    min-width: 0;
    max-width: 100vw;
    font-size: 15px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.25);
  }

  .panel-header {
    padding: 12px 8vw 12px 40px;
    font-size: 1em;
    min-height: 58px;
  }

  .close-btn {
    top: 6px;
    right: 11px;
    font-size: 28px;
  }

  .delay-banner {
    top: 12px;
    font-size: 0.9em;
  }

  .alert-badges {
    top: 12px;
  }

  .stops-list li {
    padding: 11px 6vw 11px 6vw;
    font-size: 15px;
  }

  .stop-info .times-grid {
    grid-template-columns: 68px 1fr;
    font-size: 0.93em;
  }

  .stop-icon {
    margin-right: 10px;
    font-size: 1.3em;
    width: 20px;
    padding-top: 4px;
  }

  #last-updated,
  .theme-switch-wrapper,
  #analytics-link {
    font-size: 13px;
    padding: 6px 8px;
  }
}

@media (max-width: 400px) {
  .panel-header,
  .stops-list li {
    padding-left: 18px;
    padding-right: 6vw;
  }

  .stop-info .times-grid {
    grid-template-columns: 56px 1fr;
  }
}

body.dark-mode {
  background: #1a1a1a;
  color: #f1f1f1;
}

body.dark-mode #last-updated,
body.dark-mode .theme-switch-wrapper {
  background: rgba(40, 40, 40, 0.95);
  color: #f1f1f1;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.6);
}

body.dark-mode #analytics-link {
  background: rgba(66, 135, 245, 0.9);
}

body.dark-mode #analytics-link:hover {
  background: rgba(86, 155, 255, 1);
}

body.dark-mode #details-panel {
  background: #2c2c2c;
  box-shadow: -3px 0 15px rgba(0, 0, 0, 0.5);
}

body.dark-mode .panel-header {
  background: #333;
  border-bottom-color: #444;
}

body.dark-mode .panel-header p {
  color: #ccc;
}

body.dark-mode .close-btn {
  color: #aaa;
}

body.dark-mode .close-btn:hover {
  color: #fff;
}

body.dark-mode .stops-list li {
  border-bottom-color: #444;
}

body.dark-mode .stop-icon {
  color: #555;
}

body.dark-mode .stop-info .times-grid {
  color: #bbb;
}

body.dark-mode .times-grid .label {
  color: #f1f1f1;
}

body.dark-mode .stop-passed {
  opacity: 0.5;
  background: #222;
}

body.dark-mode .stop-passed .name {
  color: #888;
}

body.dark-mode .stop-passed .stop-icon {
  color: #28a745;
}

body.dark-mode .stop-current {
  background: #4d442a;
  border-left: 4px solid #ffc107;
}

body.dark-mode .stop-current .stop-icon {
  color: #ffc107;
}

body.dark-mode .platform {
  background: #333;
  color: #ccc;
}

body.dark-mode .locate-me-btn {
  background: #222;
  color: #86b6f5;
}

body.dark-mode .locate-me-btn:active {
  background: #333;
}

/* ...existing styles above... */

/* New: subtle separator for inline meta (prevents odd glyphs when fonts lack bullet) */
.sep {
  color: #999;
}

/* New: route chip in titles/tooltips */
.route-chip {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.85em;
  line-height: 1;
  vertical-align: baseline;
  background: #0055A6;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.05) inset;
  margin-right: 6px;
}

/* New: alert badges in details header */
.alert-badges {
  position: absolute;
  top: 15px;
  left: 34px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  max-width: calc(100% - 140px);
}

.alert-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.78em;
  font-weight: 600;
  background: #eee;
  color: #333;
  white-space: nowrap;
}

.alert-badge.info {
  background: #e3f2fd;
  color: #0b6bbf;
}
.alert-badge.warning {
  background: #fff3cd;
  color: #856404;
}
.alert-badge.severe {
  background: #fdecea;
  color: #a80d0d;
}
.alert-badge.more {
  background: #e0e0e0;
  color: #333;
}

/* Keep both variants for compatibility */
.custom-tooltip .tooltip-delay.ontime,
.custom-tooltip .tooltip-delay.on-time {
  color: #9effb0;
}
.delay-banner.on-time,
.delay-banner.ontime {
  background: #28a745;
}

/* ...keep the rest of your existing CSS unchanged... */