:root {
  color-scheme: light;
  --bg: #f4f2ec;
  --panel: #fffdf8;
  --panel-strong: #fff8ea;
  --ink: #1e2528;
  --muted: #6d7579;
  --line: #ded6c8;
  --accent: #0f766e;
  --accent-dark: #0a5b55;
  --pin: #db4a39;
  --shadow: 0 18px 55px rgba(31, 39, 41, 0.14);
  --radius: 20px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.12), transparent 28rem),
    var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button,
.file-button {
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 750;
  padding: 0.72rem 1rem;
  transition:
    transform 160ms ease,
    background 160ms ease,
    opacity 160ms ease;
}

button:hover,
.file-button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

input {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--ink);
  padding: 0.72rem 1rem;
  width: 100%;
}

input:focus-visible,
button:focus-visible,
.file-button:focus-within {
  outline: 3px solid rgba(15, 118, 110, 0.25);
  outline-offset: 2px;
}

.app-header {
  align-items: end;
  display: grid;
  gap: 1.25rem;
  grid-template-columns: minmax(18rem, 1fr) minmax(20rem, 30rem);
  padding: 1.4rem clamp(1rem, 3vw, 2.5rem) 1.1rem;
}

.eyebrow {
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  margin: 0 0 0.35rem;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.6rem);
  letter-spacing: -0.06em;
  line-height: 0.96;
  margin-bottom: 0.65rem;
}

.lede {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
  margin-bottom: 0;
  max-width: 62rem;
}

.key-form {
  background: rgba(255, 253, 248, 0.82);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.key-form label,
.controls label {
  display: block;
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
}

.key-row {
  display: grid;
  gap: 0.55rem;
  grid-template-columns: minmax(0, 1fr) auto;
}

.key-form small {
  color: var(--muted);
  display: block;
  line-height: 1.4;
  margin-top: 0.55rem;
}

.app-shell {
  align-items: start;
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(19rem, 25rem) minmax(0, 1fr);
  min-height: 0;
  padding: 0 clamp(1rem, 3vw, 2.5rem) 1.5rem;
}

.sidebar {
  display: grid;
  gap: 1rem;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
}

.panel {
  background: rgba(255, 253, 248, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.status {
  background: #edf8f4;
  border: 1px solid #cbe7dd;
  border-radius: 14px;
  color: #17463f;
  font-size: 0.9rem;
  line-height: 1.45;
  padding: 0.65rem 0.75rem;
}

.controls {
  display: grid;
  gap: 0.8rem;
}

.button-grid {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented-control {
  border: 0;
  display: grid;
  gap: 0.45rem;
  margin: 0;
  padding: 0;
}

.segmented-control legend {
  color: var(--ink);
  display: block;
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  margin-bottom: 0.05rem;
  padding: 0;
  text-transform: uppercase;
}

.segmented-control label {
  margin: 0;
  position: relative;
}

.segmented-control {
  grid-template-columns: repeat(auto-fit, minmax(7.8rem, 1fr));
}

.segmented-control legend {
  grid-column: 1 / -1;
}

.segmented-control input {
  opacity: 0;
  position: absolute;
  width: 1px;
}

.segmented-control span {
  align-items: center;
  background: white;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  font-size: 0.82rem;
  font-weight: 800;
  justify-content: center;
  min-height: 2.45rem;
  padding: 0.55rem 0.7rem;
  text-align: center;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.segmented-control input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.segmented-control label:hover span {
  border-color: rgba(15, 118, 110, 0.35);
  transform: translateY(-1px);
}

.segmented-control input:focus-visible + span {
  outline: 3px solid rgba(15, 118, 110, 0.25);
  outline-offset: 2px;
}

.button-grid button,
.file-button {
  font-size: 0.86rem;
  text-align: center;
}

.file-button input {
  display: none;
}

.list-heading {
  align-items: baseline;
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

.list-heading h2 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.list-heading span {
  color: var(--muted);
  font-size: 0.85rem;
}

.group-list {
  display: grid;
  gap: 0.55rem;
  max-height: calc(100vh - 30rem);
  min-height: 12rem;
  overflow: auto;
  padding-right: 0.25rem;
}

.group-button {
  appearance: none;
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--ink);
  cursor: pointer;
  display: block;
  padding: 0.82rem;
  text-align: left;
  width: 100%;
}

.group-button:hover {
  border-color: rgba(15, 118, 110, 0.35);
  transform: translateY(-1px);
}

.group-button strong {
  display: block;
  font-size: 0.95rem;
}

.group-button span {
  color: var(--muted);
  display: block;
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.map-panel {
  min-height: 0;
}

#map {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  height: clamp(24rem, 42vh, 30rem);
  min-height: 0;
  overflow: hidden;
}

.static-map {
  background: #f8fbf7;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(18rem, 24rem);
  height: 100%;
  min-height: 0;
  position: relative;
}

.static-map-surface {
  background:
    linear-gradient(rgba(16, 54, 49, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16, 54, 49, 0.08) 1px, transparent 1px),
    #dce7e2;
  background-size: 12.5% 12.5%, 12.5% 12.5%, auto;
  min-height: 0;
  overflow: hidden;
  position: relative;
  touch-action: none;
}

.static-map-surface:not(.static-map-dragging) {
  cursor: grab;
}

.static-map-dragging {
  cursor: grabbing;
}

.static-tile-layer {
  inset: 0;
  position: absolute;
}

.osm-tile {
  border: 0;
  display: block;
  image-rendering: auto;
  position: absolute;
  user-select: none;
}

.static-map-label {
  background: rgba(255, 253, 248, 0.9);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  left: 1rem;
  padding: 0.45rem 0.6rem;
  position: absolute;
  top: 1rem;
  z-index: 3;
}

.osm-attribution {
  background: rgba(255, 253, 248, 0.92);
  border-left: 1px solid rgba(31, 39, 41, 0.14);
  border-top: 1px solid rgba(31, 39, 41, 0.14);
  bottom: 0;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.2;
  padding: 0.28rem 0.42rem;
  position: absolute;
  right: 0;
  z-index: 9;
}

.osm-attribution a {
  color: #17463f;
  font-weight: 750;
  text-decoration: none;
}

.osm-attribution a:hover {
  text-decoration: underline;
}

.static-map-controls {
  align-items: center;
  background: rgba(255, 253, 248, 0.94);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(31, 39, 41, 0.16);
  display: flex;
  gap: 0.35rem;
  padding: 0.35rem;
  position: absolute;
  right: 1rem;
  top: 1rem;
  z-index: 8;
}

.static-map-controls button {
  align-items: center;
  border-radius: 8px;
  display: inline-flex;
  font-size: 0.9rem;
  height: 2rem;
  justify-content: center;
  min-width: 2rem;
  padding: 0 0.55rem;
}

.static-map-reset {
  font-size: 0.78rem;
  min-width: 3.4rem;
}

.static-map-zoom-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  min-width: 2rem;
  text-align: center;
}

.static-map-empty {
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  left: 50%;
  line-height: 1.4;
  margin: 0;
  padding: 0.75rem 0.9rem;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
}

.static-pin {
  align-items: center;
  background: var(--static-pin-color, var(--pin));
  border: 2px solid white;
  border-radius: 999px;
  box-shadow: 0 5px 14px rgba(31, 39, 41, 0.28);
  color: white;
  display: flex;
  font-size: 0.62rem;
  font-weight: 900;
  height: 1.55rem;
  justify-content: center;
  min-width: 1.55rem;
  padding: 0 0.28rem;
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 4;
}

.static-pin:hover {
  background: var(--static-pin-hover-color, #b93327);
  transform: translate(-50%, -50%) scale(1.08);
  z-index: 6;
}

.static-pin-warning {
  --static-pin-color: #b87514;
  --static-pin-hover-color: #925b0f;
}

.static-pin-deprivation {
  border-color: rgba(255, 255, 255, 0.96);
}

.static-pin-outside {
  outline: 2px dashed rgba(184, 117, 20, 0.65);
  outline-offset: 2px;
}

.static-pin-selected {
  background: #1b5f9e;
  box-shadow: 0 0 0 4px rgba(27, 95, 158, 0.18), 0 7px 18px rgba(31, 39, 41, 0.28);
  z-index: 7;
}

.static-pin-selected:hover {
  background: #164f82;
}

.static-map-legend {
  align-items: center;
  background: rgba(255, 253, 248, 0.94);
  border: 1px solid var(--line);
  border-radius: 10px;
  bottom: 1rem;
  box-shadow: 0 8px 24px rgba(31, 39, 41, 0.14);
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 0.72rem;
  font-weight: 800;
  gap: 0.42rem 0.55rem;
  left: 1rem;
  line-height: 1;
  max-width: calc(100% - 8rem);
  padding: 0.5rem 0.6rem;
  position: absolute;
  z-index: 8;
}

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

.static-map-legend i {
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  display: inline-block;
  height: 0.72rem;
  width: 0.72rem;
}

.static-details {
  background: rgba(255, 253, 248, 0.98);
  border-left: 1px solid var(--line);
  min-height: 0;
  overflow: auto;
  padding: 1rem;
  position: relative;
}

.static-details > h2 {
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}

.static-details > p {
  color: var(--muted);
  line-height: 1.45;
}

.static-details-close {
  float: right;
  font-size: 0.78rem;
  margin: 0 0 0.7rem 0.7rem;
  padding: 0.48rem 0.7rem;
}

.map-placeholder {
  align-items: center;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.12), rgba(219, 74, 57, 0.1)),
    var(--panel);
  display: grid;
  padding: 2rem;
  place-items: center;
  text-align: center;
}

.map-placeholder > div {
  max-width: 33rem;
}

.map-placeholder h2 {
  font-size: clamp(1.6rem, 3vw, 2.6rem);
  letter-spacing: -0.045em;
}

.map-placeholder p {
  color: var(--muted);
  line-height: 1.55;
}

.info-window {
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  max-width: min(720px, 72vw);
}

.info-window h2 {
  font-size: 1.25rem;
  letter-spacing: -0.03em;
  margin-bottom: 0.25rem;
}

.info-window .meta {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
  margin-bottom: 0.8rem;
}

.warning-meta {
  background: #fff7df;
  border: 1px solid #ead79e;
  border-radius: 10px;
  color: #674c0c;
  padding: 0.55rem 0.65rem;
}

.deprivation-meta {
  background: #eef7f5;
  border: 1px solid #c8e2dc;
  border-radius: 10px;
  color: #17463f;
  padding: 0.55rem 0.65rem;
}

.street-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  max-height: min(62vh, 640px);
  overflow: auto;
  padding-right: 0.25rem;
}

.street-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}

.street-card h3 {
  background: var(--panel-strong);
  border-bottom: 1px solid var(--line);
  font-size: 1rem;
  letter-spacing: -0.015em;
  margin: 0;
  padding: 0.65rem 0.75rem;
}

.street-card img {
  aspect-ratio: 16 / 9;
  background: #e9e5da;
  display: block;
  object-fit: cover;
  width: 100%;
}

.street-card .card-body {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
  padding: 0.65rem 0.75rem 0.75rem;
}

.street-card a {
  color: var(--accent-dark);
  display: inline-block;
  font-weight: 800;
  margin-top: 0.5rem;
  text-decoration: none;
}

.street-card a:hover {
  text-decoration: underline;
}

.empty {
  color: var(--muted);
  line-height: 1.45;
  padding: 0.5rem 0;
}

@media (max-width: 980px) {
  .app-header,
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-shell {
    min-height: auto;
  }

  .sidebar {
    grid-template-rows: none;
  }

  .group-list {
    max-height: 18rem;
  }
}

@media (max-width: 560px) {
  .key-row,
  .button-grid,
  .segmented-control {
    grid-template-columns: 1fr;
  }

  .app-header {
    padding-top: 1rem;
  }

  .static-map {
    grid-template-columns: 1fr;
    height: auto;
  }

  #map {
    height: auto;
  }

  .static-map-surface {
    height: 22rem;
  }

  .static-details {
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: 18rem;
    min-height: 0;
  }

  .info-window {
    max-width: 86vw;
  }
}
