:root {
  --color-sunny: #d97706;
  --color-mixed: #a8a29e;
  --color-shaded: #0369a1;
  --color-canopy: #16a34a;
  --color-bg: #faf7f2;
  --color-ink: #1c1917;
  --color-ink-muted: #57534e;
  --color-surface: #ffffff;
  --color-border: #e7e2d9;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-sans);
  color: var(--color-ink);
}

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

.top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.85rem;
  background: rgba(250, 247, 242, 0.92);
  backdrop-filter: blur(4px);
  border-bottom: 1px solid var(--color-border);
}

.top-bar__title {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  min-width: 0;
}

.top-bar__title a.back-link {
  font-size: 0.85rem;
  color: var(--color-ink-muted);
  text-decoration: none;
  white-space: nowrap;
}

.top-bar__title a.back-link:hover {
  text-decoration: underline;
}

.top-bar__title a.sources-link {
  font-size: 0.72rem;
  color: var(--color-ink-muted);
  text-decoration: underline dotted;
  white-space: nowrap;
}

.top-bar__city {
  font-weight: 700;
  font-size: 1.05rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-bar__controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

.weather-badge {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-ink-muted);
  white-space: nowrap;
}

.season-toggle,
.hour-toggle {
  display: flex;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--color-surface);
}

.season-toggle button,
.hour-toggle button {
  border: none;
  background: transparent;
  padding: 0.4rem 0.9rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-ink-muted);
  cursor: pointer;
}

.season-toggle button[aria-pressed="true"],
.hour-toggle button[aria-pressed="true"] {
  background: var(--color-ink);
  color: #fff;
}

.data-quality-banner {
  position: absolute;
  top: 3.1rem;
  left: 0.85rem;
  right: 0.85rem;
  z-index: 4;
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #7c2d12;
  font-size: 0.8rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  max-width: 32rem;
}

.legend {
  position: absolute;
  bottom: 1rem;
  left: 0.85rem;
  z-index: 5;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--color-border);
  border-radius: 0.6rem;
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  max-width: 15rem;
}

.legend__title {
  font-weight: 700;
  margin: 0 0 0.15rem;
}

.legend__subtitle {
  font-size: 0.7rem;
  color: var(--color-ink-muted);
  margin: 0 0 0.4rem;
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  line-height: 1.5;
}

.legend__swatch {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend__gradient {
  height: 0.6rem;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--color-shaded), var(--color-mixed), var(--color-sunny));
  margin: 0.3rem 0;
}

.legend__gradient-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--color-ink-muted);
}

/* ICU night-hazard levels -- fixed classes, not inline style (see the note
   above .contrib-bar__segment--sunny for why). */
.legend__swatch--icu-1 {
  background: #fef3c7;
}

.legend__swatch--icu-2 {
  background: #fdba74;
}

.legend__swatch--icu-3 {
  background: #f97316;
}

.legend__swatch--icu-4 {
  background: #b91c1c;
}

.layers-panel {
  position: absolute;
  bottom: 1rem;
  right: 0.85rem;
  z-index: 5;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--color-border);
  border-radius: 0.6rem;
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  max-width: 16rem;
  max-height: 60vh;
  overflow-y: auto;
}

.layers-panel__title {
  font-weight: 700;
  margin: 0 0 0.35rem;
}

.layers-panel__item {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  line-height: 1.4;
  cursor: pointer;
}

.layers-panel__item input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.layers-panel__desc {
  display: block;
  font-size: 0.7rem;
  color: var(--color-ink-muted);
  font-weight: 400;
}

.layers-panel__item:has(input:disabled) {
  color: var(--color-ink-muted);
  cursor: default;
}

.layers-panel__item + .layers-panel__item {
  margin-top: 0.3rem;
}

.sublegend {
  margin: 0.35rem 0 0.5rem 1.3rem;
  padding: 0.4rem 0.5rem;
  background: var(--color-bg);
  border-radius: 0.4rem;
  font-size: 0.72rem;
}

.sublegend .legend__item {
  font-size: 0.72rem;
  line-height: 1.35;
}

.sublegend__note {
  margin: 0 0 0.3rem;
  color: var(--color-ink-muted);
  font-style: italic;
}

.route-panel {
  position: absolute;
  top: 3.9rem;
  left: 0.85rem;
  z-index: 6;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--color-border);
  border-radius: 0.6rem;
  padding: 0.7rem 0.8rem;
  font-size: 0.8rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  width: 17rem;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
}

.panel-tabs {
  display: flex;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.6rem;
}

.panel-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0.4rem 0.5rem;
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--color-ink-muted);
  cursor: pointer;
}

.panel-tab[aria-pressed="true"] {
  background: var(--color-ink);
  color: #fff;
}

.route-panel__title {
  font-weight: 700;
  margin: 0 0 0.5rem;
}

.route-panel__hint--static {
  margin: 0 0 0.6rem;
  font-style: normal;
}

.iso-legend {
  margin-top: 0.6rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.iso-legend__row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.76rem;
  color: var(--color-ink-muted);
}

.iso-legend__swatch {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 3px;
  flex-shrink: 0;
}

.route-field {
  margin-bottom: 0.55rem;
  position: relative;
}

.route-field__label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-ink-muted);
  margin-bottom: 0.2rem;
}

.route-field__row {
  display: flex;
  gap: 0.35rem;
}

.route-field input[type="text"],
.route-field input[type="time"] {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 0.82rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 0.4rem;
  background: var(--color-surface);
  color: var(--color-ink);
}

.route-field input[type="text"]:focus,
.route-field input[type="time"]:focus {
  outline: 2px solid var(--color-shaded);
  outline-offset: 1px;
}

.route-pin-btn {
  flex-shrink: 0;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 0.4rem;
  width: 2rem;
  font-size: 0.95rem;
  cursor: pointer;
  line-height: 1;
}

.route-pin-btn:hover {
  background: var(--color-bg);
}

.route-pin-btn--active {
  background: var(--color-ink);
  border-color: var(--color-ink);
}

.route-suggestions {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
  position: absolute;
  left: 0;
  right: 0;
  z-index: 7;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.4rem;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
  max-height: 10rem;
  overflow-y: auto;
}

.route-suggestions li {
  padding: 0.4rem 0.55rem;
  font-size: 0.78rem;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border);
}

.route-suggestions li:last-child {
  border-bottom: none;
}

.route-suggestions li:hover {
  background: var(--color-bg);
}

.route-panel__actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.route-btn {
  flex: 1;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.45rem 0.6rem;
  border-radius: 0.4rem;
  border: 1px solid var(--color-border);
  cursor: pointer;
}

.route-btn--primary {
  background: var(--color-ink);
  color: #fff;
  border-color: var(--color-ink);
}

.route-btn--primary:disabled {
  background: var(--color-mixed);
  border-color: var(--color-mixed);
  cursor: not-allowed;
}

.route-btn--reset {
  background: var(--color-surface);
  color: var(--color-ink);
}

.route-btn--reset:hover {
  background: var(--color-bg);
}

.route-panel__hint {
  margin: 0.5rem 0 0;
  font-size: 0.74rem;
  color: var(--color-ink-muted);
  font-style: italic;
}

.route-alternatives {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.6rem;
}

.route-pill {
  font-family: inherit;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  padding: 0.3rem 0.65rem;
  cursor: pointer;
  text-align: left;
  line-height: 1.3;
}

.route-pill--active {
  background: var(--color-ink);
  border-color: var(--color-ink);
  color: #fff;
}

.route-pill__label {
  display: block;
  font-weight: 700;
  font-size: 0.74rem;
}

.route-pill__meta {
  display: block;
  font-size: 0.68rem;
  color: inherit;
  opacity: 0.8;
}

.route-summary {
  margin-top: 0.6rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--color-border);
}

.route-summary__label {
  font-weight: 700;
  margin: 0 0 0.35rem;
}

.route-summary__stats {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.78rem;
  color: var(--color-ink-muted);
}

.route-summary__stats strong {
  color: var(--color-ink);
}

@media (max-width: 640px) {
  .route-panel {
    left: 0.6rem;
    right: 0.6rem;
    width: auto;
    top: 3.6rem;
    max-height: 45vh;
  }
}

.terrace-popup {
  font-family: var(--font-sans);
  min-width: 200px;
  max-width: 260px;
}

.terrace-popup__name {
  font-weight: 700;
  font-size: 0.95rem;
  margin: 0 0 0.15rem;
}

.terrace-popup__address {
  color: var(--color-ink-muted);
  font-size: 0.8rem;
  margin: 0 0 0.4rem;
}

.terrace-popup__typology {
  font-size: 0.78rem;
  color: var(--color-ink-muted);
  margin: 0 0 0.5rem;
}

.terrace-popup__breakdown {
  margin-bottom: 0.4rem;
}

.contrib-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
}

.contrib-row__label {
  width: 2.6rem;
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--color-ink-muted);
}

.contrib-bar {
  flex: 1;
  display: flex;
  height: 0.6rem;
  border-radius: 999px;
  overflow: hidden;
  background: var(--color-bg);
}

/* Colour is a fixed CSS class (not an inline style attribute): the CSP here
   has no 'unsafe-inline' for style-src, so style="..." strings built in JS
   are silently dropped by the browser -- confirmed by testing, not assumed.
   Width still varies per popup, so it's set via element.style.width in JS
   (a CSSOM property assignment, which -- unlike a style attribute -- CSP
   does not restrict). */
.contrib-bar__segment--sunny {
  background: var(--color-sunny);
}

.contrib-bar__segment--building {
  background: var(--color-shaded);
}

.contrib-bar__segment--canopy {
  background: var(--color-canopy);
}

.contrib-legend__swatch--sunny {
  background: var(--color-sunny);
}

.contrib-legend__swatch--building {
  background: var(--color-shaded);
}

.contrib-legend__swatch--canopy {
  background: var(--color-canopy);
}

.contrib-row__pct {
  width: 2.4rem;
  flex-shrink: 0;
  text-align: right;
  font-weight: 700;
  font-size: 0.8rem;
}

.contrib-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.3rem;
  font-size: 0.68rem;
  color: var(--color-ink-muted);
}

.contrib-legend span {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.contrib-legend i {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 2px;
}

.terrace-popup__approx {
  font-size: 0.72rem;
  color: var(--color-ink-muted);
  font-style: italic;
  margin: 0;
}

.maplibregl-popup-content {
  border-radius: 0.6rem;
  padding: 0.85rem 0.9rem;
}

@media (max-width: 640px) {
  .top-bar {
    padding: 0.5rem 0.6rem;
    flex-wrap: wrap;
    row-gap: 0.4rem;
  }

  .top-bar__city {
    font-size: 0.95rem;
  }

  .top-bar__controls {
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .season-toggle button,
  .hour-toggle button {
    padding: 0.35rem 0.6rem;
    font-size: 0.8rem;
  }

  .weather-badge {
    font-size: 0.8rem;
  }

  .legend {
    left: 0.6rem;
    right: 0.6rem;
    bottom: 0.6rem;
  }

  .layers-panel {
    right: 0.6rem;
    bottom: 4.5rem;
    max-width: 11rem;
    font-size: 0.75rem;
  }

  .maplibregl-popup {
    max-width: 90vw !important;
  }
}
