:root {
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --amber-50: #fffbeb;
  --amber-700: #b45309;
  --red-50: #fef2f2;
  --red-700: #b91c1c;
  /* Charging speed. Kept off the status hues so a chip never reads as a status. */
  --indigo-50: #eef2ff;
  --indigo-700: #4338ca;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  color: var(--gray-900);
  display: flex;
  flex-direction: column;
}

#notice {
  margin: 0;
  padding: 0.5rem 0.75rem;
  background: var(--amber-50);
  color: var(--amber-700);
  border-bottom: 1px solid var(--gray-200);
  font-size: 0.8125rem;
  flex: none;
}

#notice.error {
  background: var(--red-50);
  color: var(--red-700);
}

/* --- layout ------------------------------------------------------------- */

main {
  flex: 1;
  display: flex;
  /* Required for the map inside the flex layout. */
  min-height: 0;
}

#map-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
}

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

/* --- list --------------------------------------------------------------- */

#list {
  width: 320px;
  flex: none;
  overflow-y: auto;
  background: var(--gray-100);
  border-right: 1px solid var(--gray-300);
}

#station-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.loading {
  padding: 1rem;
  color: var(--gray-500);
  font-size: 0.8125rem;
}

.station {
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--gray-200);
  padding: 0.625rem 0.75rem;
  font: inherit;
  cursor: pointer;
  display: block;
}

.station:hover {
  background: var(--gray-200);
}

.station:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: -2px;
}

.station[aria-current="true"] {
  background: #fff;
  box-shadow: inset 3px 0 0 #2563eb;
}

/* Name and address stack on the left; the open-port count anchors the right. */
.station-row {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
}

/* min-width:0 lets a long name wrap instead of pushing the count off the edge. */
.station-main {
  flex: 1;
  min-width: 0;
}

.station-name {
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: capitalize;
  display: block;
}

.station-address {
  display: block;
  margin-top: 0.0625rem;
  font-size: 0.6875rem;
  color: var(--gray-500);
}

/* Specs run along the bottom, with the operator anchored to the opposite corner. */
.station-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.4375rem;
}

.station-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
}

.station-network {
  flex: none;
  align-self: flex-end;
  font-size: 0.625rem;
  color: var(--gray-500);
  white-space: nowrap;
}

.station-avail {
  flex: none;
  text-align: right;
  line-height: 1.15;
}

/* Tabular figures keep the counts aligned down the column. */
.avail-count {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--status);
  font-variant-numeric: tabular-nums;
}

/* Darker and larger than the operator below it, so availability wins the corner. */
.avail-label {
  display: block;
  margin-top: 0.0625rem;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--gray-700);
  white-space: nowrap;
}

.avail-none {
  display: block;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--gray-500);
  white-space: nowrap;
}

/* A planned site's stage is its headline fact, so it carries the legend color. */
.avail-status {
  color: var(--status);
}

.station-stale {
  display: block;
  margin-top: 0.375rem;
  font-size: 0.6875rem;
  color: var(--amber-700);
}

/* Status is carried by the count's color, which a screen reader cannot announce. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --- legend ------------------------------------------------------------- */

#legend {
  position: absolute;
  bottom: 1.5rem;
  left: 0.75rem;
  z-index: 1;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  padding: 0.5rem 0.625rem;
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.legend-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.legend-group strong {
  color: var(--gray-900);
  font-size: 0.6875rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.legend-planned {
  border-top: 1px solid var(--gray-300);
  padding-top: 0.5rem;
}

.legend-group span {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

#legend i,
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dot);
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
  flex: none;
  display: inline-block;
}

/* Type is carried by the marker glyph, so the legend shows shape, not color. */
#legend i.glyph {
  width: 15px;
  height: 15px;
  background: var(--gray-700);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#legend i.glyph svg {
  width: 9px;
  height: 9px;
  display: block;
}

/* --- charging speed chip ------------------------------------------------ */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.1875rem;
  padding: 0.0625rem 0.3125rem;
  border-radius: 999px;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
  vertical-align: middle;
}

/* The glyph repeats the map marker, so the chip and the point read as one thing. */
.chip svg {
  width: 0.6875rem;
  height: 0.6875rem;
  flex: none;
}

.chip-dcfc {
  background: var(--indigo-50);
  color: var(--indigo-700);
}

.chip-l2 {
  background: var(--gray-200);
  color: var(--gray-700);
}

/* Outlined, so the filled speed chip stays the one that leads the row. */
.chip-spec {
  background: none;
  color: var(--gray-700);
  box-shadow: inset 0 0 0 1px var(--gray-300);
}

/*
 * Speed and rating fused into one pill under a single shared border. A real border
 * is used rather than an inset shadow, which the filled head would paint over,
 * leaving the outline visible only around the tail. The segments inside go square
 * and borderless so the head's fill runs to the rounded edge.
 */
.chip-pair {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--gray-300);
  border-radius: 999px;
  overflow: hidden;
  flex: none;
}

.chip-pair .chip {
  border-radius: 0;
  box-shadow: none;
}

.station-chips .chip,
.station-chips .chip-pair,
.popup-chips .chip,
.popup-chips .chip-pair {
  flex: none;
}

/* --- popup -------------------------------------------------------------- */

.maplibregl-popup-content {
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  padding: 0.75rem 0.875rem;
  border-radius: 4px;
}

.hover-popup {
  pointer-events: none;
}

/* Same three bands as a sidebar card: head, chips, footer. */
.popup-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.popup-title {
  min-width: 0;
}

.popup h2 {
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  font-size: 0.9375rem;
  font-weight: 700;
  margin: 0;
  text-transform: capitalize;
}

.popup p {
  margin: 0.125rem 0 0;
  font-size: 0.8125rem;
}

.popup-address {
  color: var(--gray-500);
  font-size: 0.75rem !important;
}

.popup-avail {
  flex: none;
  text-align: right;
  line-height: 1.15;
}

.popup-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.5rem;
}

/* Labels the breakdown so the list does not read as a continuation of the chips. */
.popup-section {
  margin-top: 0.625rem !important;
  font-size: 0.625rem !important;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gray-500);
}

.popup-ports {
  margin: 0.1875rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.75rem;
  color: var(--gray-700);
}

.popup-ports li {
  display: flex;
  align-items: baseline;
  gap: 0.375rem;
  padding: 0.09375rem 0;
}

.popup-item-name {
  font-weight: 500;
  white-space: nowrap;
}

.popup-item-status {
  color: var(--gray-500);
  min-width: 0;
}

.popup-footer {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.625rem;
  padding-top: 0.4375rem;
  border-top: 1px solid var(--gray-200);
}

.popup-age {
  color: var(--gray-500);
  font-size: 0.6875rem;
}

.popup-age.stale {
  color: var(--amber-700);
}

.popup-network {
  flex: none;
  margin-left: auto;
  color: var(--gray-500);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

@media (max-width: 720px) {
  main {
    flex-direction: column;
  }
  #list {
    width: auto;
    border-right: 0;
    border-top: 1px solid var(--gray-300);
    flex: 1 1 45%;
  }
  #map-wrap {
    flex: 1 1 55%;
    /* Preserve list-first DOM order while showing the map first. */
    order: -1;
  }
}

@media (max-width: 480px) {
  #legend {
    bottom: 0.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
