* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: #222;
}

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

#panel {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  padding: 16px 18px;
  width: 260px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
}

#year-display {
  font-size: 34px;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}

#year-slider {
  width: 100%;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #888;
  margin-top: -2px;
}

/* Reads out the zoom level and the stroke width it maps to, so the ZOOM_WEIGHTS
   thresholds in app.js can be seen taking effect rather than guessed at. Those two
   readouts are development-only (see DEV in app.js); the trolley-floor note below is
   shown to everyone. */
#zoom-display {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #e6e6e6;
  font-size: 11px;
  color: #888;
  font-variant-numeric: tabular-nums;
  display: flex;
  justify-content: space-between;
}

#zoom-display .zoom-level {
  font-weight: 700;
  color: #444;
}

/* The trolley-floor note is a third, full-width row rather than a third column:
   the two existing readouts already fill the panel width at 11px. */
#zoom-display {
  flex-wrap: wrap;
}

#zoom-display .zoom-note {
  flex-basis: 100%;
  margin-top: 4px;
  color: #a06a3a;
}

/* Off localhost and with no trolley note to show, the container is empty -- without this
   it would still draw its top border as a stray rule under the year slider. */
#zoom-display:empty {
  display: none;
}

.line-tooltip {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
}

#legend[hidden] {
  display: none;
}

#legend {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  width: 260px;
  max-height: calc(100% - 32px);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
}

.legend-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 8px;
  border-bottom: 1px solid #eee;
}

#legend.is-collapsed .legend-head {
  border-bottom: 0;
  padding-bottom: 12px;
}

#legend-toggle {
  display: flex;
  align-items: baseline;
  gap: 6px;
  border: 0;
  background: none;
  padding: 0;
  margin: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
  min-width: 0;
}

.legend-chevron {
  flex: none;
  width: 10px;
  height: 10px;
  margin-bottom: 1px;
  border-right: 1.5px solid #888;
  border-bottom: 1.5px solid #888;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

#legend.is-collapsed .legend-chevron {
  transform: rotate(-45deg);
  margin-bottom: -2px;
}

.legend-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #555;
}

#legend-count {
  color: #999;
  font-weight: 400;
}

#legend-reset {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 11px;
  color: #2a6f97;
  cursor: pointer;
  text-decoration: underline;
  flex: none;
}

#legend-list {
  overflow-y: auto;
  padding: 6px 6px 8px;
}

#legend.is-collapsed #legend-list {
  display: none;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.3;
}

.legend-row:hover {
  background: #f2f4f7;
}

.legend-row.is-solo {
  background: #eef2fb;
}

.legend-label {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.legend-row input {
  margin: 0;
  flex: none;
  cursor: pointer;
}

.legend-swatch {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  flex: none;
}

.legend-name {
  flex: 1;
  min-width: 0;
}

/* Mileage and the "only" button share one right-hand slot, the button laid over
   the mileage, so revealing it on hover cannot reflow the row. */
.legend-tail {
  position: relative;
  flex: none;
  min-width: 46px;
  text-align: right;
}

.legend-miles {
  font-size: 11px;
  color: #999;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.legend-row.is-off .legend-miles {
  color: #c3c7cc;
}

.legend-only {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 11px;
  color: #2a6f97;
  cursor: pointer;
  text-decoration: underline;
  white-space: nowrap;
}

.legend-row:hover .legend-only,
.legend-row.is-solo .legend-only {
  display: inline;
}

.legend-row:hover .legend-miles,
.legend-row.is-solo .legend-miles {
  visibility: hidden;
}

.legend-row.is-solo .legend-only {
  color: #1a1a1a;
  font-weight: 700;
  text-decoration: none;
}

/* No hover on touch, so give the button its own space rather than overlaying. */
@media (hover: none) {
  .legend-tail {
    min-width: 0;
  }

  .legend-only {
    position: static;
    display: inline;
    transform: none;
    margin-left: 8px;
  }

  .legend-row:hover .legend-miles,
  .legend-row.is-solo .legend-miles {
    visibility: visible;
  }
}

.legend-row.is-off .legend-name {
  color: #9aa0a6;
}

.legend-row.is-off .legend-swatch {
  opacity: 0.35;
}

.legend-empty {
  padding: 10px 14px;
  font-size: 12px;
  color: #888;
}

@media (max-width: 720px) {
  #legend {
    width: 200px;
    max-height: 45%;
  }
}

/* Too narrow for the year panel and the legend to share the top row, so drop the
   legend to the bottom right, clear of the Leaflet attribution. */
@media (max-width: 560px) {
  #legend {
    top: auto;
    bottom: 30px;
    /* wider than the desktop breakpoint because touch devices show the mileage
       and the "only" button side by side rather than overlaid on hover */
    width: 232px;
    max-height: 42%;
  }
}

/* Clicking a line focuses its SVG <path>, and the browser's default focus ring
   on a path is drawn around the path's whole bounding box -- a big rectangle
   sprawled across the map. Drop it for pointer focus; :focus-visible does not
   match on click, so keyboard focus rings are left intact. */
.leaflet-container path.leaflet-interactive:focus {
  outline: none;
}

.leaflet-container path.leaflet-interactive:focus-visible {
  outline: auto;
}
