* {
  box-sizing: border-box;
}

/* Colour roles. The map colours (pins, lines, station dots) live in app.js and use the same values. */
:root {
  --brand: #c026d3; /* brand magenta: logo, bike route, pickup and return stations, focus */
  --brand-tint: #fae8ff;
  --error-tint: #fde8e8;
  --error-ink: #9b1c1c;
  --ink: #0f172a; /* text and primary action */
  --muted: #64748b; /* helper text */
  --start: #0f172a; /* "A" pin */
  --dest: var(--brand); /* "B" pin, also the logo accent */
}

::selection {
  background: var(--brand-tint);
  color: var(--ink);
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
  font-size: 15px;
  color: var(--ink);
}

#map {
  position: absolute;
  inset: 0;
}

/* Keep the map controls clear of the notch and the rounded screen corners (viewport-fit=cover). */
.leaflet-top {
  top: env(safe-area-inset-top);
}
.leaflet-left {
  left: env(safe-area-inset-left);
}
.leaflet-right {
  right: env(safe-area-inset-right);
}

#panel {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: calc(54px + env(safe-area-inset-left));
  z-index: 1000;
  width: 360px;
  max-height: calc(100% - 20px);
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

#panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid #eee;
}

#panel-header h1 {
  margin: 0;
  font-size: 17px;
}

#panel-header h1 span {
  color: var(--dest);
}

#panel-body {
  padding: 10px 12px;
  overflow-y: auto;
}

#panel.collapsed #panel-body {
  display: none;
}

label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 6px 0 3px;
  font-weight: 600;
  font-size: 13px;
}

input[type="text"] {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
  caret-color: var(--brand);
}

input[type="text"]::placeholder {
  color: var(--muted);
}

input[type="text"]:focus-visible {
  border-color: var(--brand);
  outline: 1px solid var(--brand);
  outline-offset: 0;
}

/* Matches the A and B pins on the map. */
.ab-badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--start);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

.ab-badge.dest {
  background: var(--dest);
}

.row {
  display: flex;
  gap: 6px;
}

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

button {
  padding: 7px 10px;
  border: 0;
  border-radius: 5px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

button.secondary,
#locate-button,
#toggle-panel {
  background: #f1f5f9;
  color: #334155;
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

#plan-button {
  flex: 1;
}

/* Square button with a Lucide icon instead of a text label. */
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px;
}

.icon-button svg {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The caret points where the panel goes: up to hide it at the top of the screen. */
#toggle-panel svg {
  transform: rotate(180deg);
}
#panel.collapsed #toggle-panel svg {
  transform: none;
}

.hint {
  margin: 6px 0 10px;
  font-size: 12px;
  color: var(--muted);
}

#message {
  margin-top: 10px;
}
#message:empty {
  display: none;
}

#message.error {
  padding: 8px;
  border-radius: 5px;
  background: var(--error-tint);
  color: var(--error-ink);
}

#message.info {
  padding: 8px;
  border-radius: 5px;
  background: #eef4ff;
  color: #1e3a8a;
}

#summary h2 {
  margin: 12px 0 6px;
  font-size: 15px;
}

.place {
  color: #555;
  font-size: 13px;
}

/* Key for the station dots on the map. */
.station-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 12px;
}

.station-legend li::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--dot);
  vertical-align: -1px;
}

.disclaimer {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.leg {
  margin-top: 8px;
  padding: 6px 8px;
  background: #fafafa;
  border-radius: 5px;
}

/* Swatch that matches the line on the map: dotted dark walk, solid magenta bike. */
.leg-title::before {
  content: "";
  display: inline-block;
  width: 18px;
  margin-right: 6px;
  vertical-align: middle;
  border-top: 4px dotted var(--ink);
}

.leg.bike .leg-title::before {
  border-top: 4px solid var(--brand);
}

.leg-title {
  font-weight: 600;
}
.leg-meta {
  color: #555;
  font-size: 13px;
}

.leg details {
  margin-top: 4px;
  font-size: 13px;
}
.leg ol {
  margin: 4px 0 0;
  padding-left: 20px;
}

.station-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding: 8px;
  border: 1px solid #e5e5e5;
  border-radius: 5px;
}

.station-icon {
  flex: none;
  width: 36px;
  height: 36px;
  padding: 6px;
  box-sizing: border-box;
  border-radius: 50%;
  background: var(--brand-tint);
  color: var(--brand);
}

.station-icon svg,
.pin-icon svg,
.popup-stat svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Station popups on the map. */
.station-popup .leaflet-popup-content {
  margin: 12px 14px;
  font-size: 13px;
  line-height: 1.3;
}

.popup-role {
  margin-bottom: 4px;
  color: var(--brand);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.popup-title {
  font-size: 14px;
  font-weight: 600;
}

.popup-sub,
.popup-status {
  color: #555;
  font-size: 12px;
}

.popup-stats {
  display: flex;
  gap: 8px;
  margin: 10px 0 8px;
}

.popup-stat {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 5px;
  background: #f3f4f6;
  color: #111827;
}

.popup-stat svg {
  flex: none;
  width: 20px;
  height: 20px;
}

.popup-stat strong {
  display: block;
  font-size: 18px;
  line-height: 1.1;
}

.popup-stat span {
  color: #555;
  font-size: 11px;
}

/* Fewer than 3 bikes or docks: not usable for pickup or return. */
.popup-stat.low {
  background: var(--error-tint);
  color: var(--error-ink);
}

.popup-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* Big enough to tap. */
.popup-actions button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
}

/* White ring keeps the badge apart from the dark button. */
.popup-actions .ab-badge {
  box-shadow: 0 0 0 1.5px #fff;
}

.popup-stats.stale .popup-stat {
  background: #f3f4f6;
  color: #6b7280;
}

/* Icon inside the round map pin of the pickup and return stations. */
.pin-icon {
  display: block;
  width: 18px;
  height: 18px;
}

.station-text {
  flex: 1;
  min-width: 0;
}
.station-action {
  color: #555;
  font-size: 12px;
}
.station-address {
  font-weight: 600;
}
.station-name {
  color: #555;
  font-size: 12px;
}

.station-count {
  flex: none;
  font-weight: 600;
  font-size: 13px;
  text-align: right;
}

.total {
  margin-top: 8px;
  font-weight: 600;
}

/* Legend for the "City bike network" map layer. */
.network-legend {
  padding: 6px 8px;
  border-radius: 5px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  font-size: 12px;
  line-height: 1.6;
}

.network-legend span {
  display: inline-block;
  width: 18px;
  margin-right: 6px;
  vertical-align: middle;
}

@media (max-width: 600px) {
  #panel {
    top: auto;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 55%;
    /* White continues below the home indicator; the content stays above it. */
    padding-bottom: env(safe-area-inset-bottom);
    border-radius: 10px 10px 0 0;
  }

  /* The sheet sits at the bottom: down to hide, up to show. */
  #toggle-panel svg {
    transform: none;
  }
  #panel.collapsed #toggle-panel svg {
    transform: rotate(180deg);
  }

  /* The attribution sits top right (see app.js); keep it clear of the zoom buttons. */
  .leaflet-control-attribution {
    max-width: calc(100vw - 54px);
  }
}

/* Touch screens: 44px targets for a thumb on the street, and 16px input text
   so that iOS Safari does not zoom in when a field gets focus. */
@media (pointer: coarse) {
  button,
  input[type="text"] {
    min-height: 44px;
  }

  .icon-button {
    min-width: 44px;
  }

  input[type="text"] {
    font-size: 16px;
  }

  .leg summary {
    padding: 10px 0;
  }
}

/* Live location: dark blue dot with a pulsing light blue halo. */
.live-location span {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.live-location .dot {
  background: #1a73e8;
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.live-location .pulse {
  background: #8ab4f8;
  animation: live-pulse 2s ease-out infinite;
}

@keyframes live-pulse {
  from {
    transform: scale(1);
    opacity: 0.8;
  }
  to {
    transform: scale(3);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .live-location .pulse {
    animation: none;
    transform: scale(2);
    opacity: 0.4;
  }
}
