:root {
  color-scheme: light;
  --ink: #172126;
  --muted: #5a6870;
  --panel: #fbfbf8;
  --panel-strong: #ffffff;
  --line: #d8ded9;
  --field: #eef2ee;
  --accent: #146c5c;
  --accent-strong: #0d4e42;
  --heat: #c2412d;
  --gold: #b27717;
  --blue: #1f6fb2;
  --shadow: 0 18px 50px rgba(23, 33, 38, 0.16);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: #e6ebe6;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  min-height: 100vh;
}

.map-stage {
  position: relative;
  min-height: 100vh;
}

.map {
  position: absolute;
  inset: 0;
  z-index: 0;
  min-height: 100%;
  background: #dfe6e0;
}

.map-notice {
  position: absolute;
  z-index: 650;
  top: 50%;
  left: 50%;
  display: none;
  max-width: min(340px, calc(100% - 40px));
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  font-size: 0.86rem;
  font-weight: 800;
  text-align: center;
  transform: translate(-50%, -50%);
}

.map-notice.visible {
  display: block;
}

.map-notice.error {
  border-color: rgba(194, 65, 45, 0.4);
  color: #852d20;
}

.map-controls {
  position: absolute;
  z-index: 600;
  right: 18px;
  bottom: 24px;
  display: grid;
  grid-template-columns: 48px;
  gap: 7px;
}

.map-controls button,
.zoom-level {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(23, 33, 38, 0.18);
  border-radius: 7px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 7px 20px rgba(23, 33, 38, 0.18);
}

.map-controls button {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
}

.map-controls button:hover {
  color: #fff;
  background: var(--accent);
}

.map-controls button:focus-visible {
  outline: 3px solid rgba(31, 111, 178, 0.4);
  outline-offset: 2px;
}

.map-controls button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.zoom-level {
  height: 30px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
}

.map-controls .uk-view-button {
  font-size: 0.78rem;
  letter-spacing: 0;
}

.search-panel {
  position: absolute;
  z-index: 500;
  top: 18px;
  left: 18px;
  width: min(620px, calc(100% - 36px));
  padding: 18px;
  border: 1px solid rgba(216, 222, 217, 0.86);
  border-radius: 8px;
  background: rgba(251, 251, 248, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.brand-row,
.panel-header,
.input-row,
.metric-row,
.filter-grid {
  display: flex;
  gap: 12px;
}

.brand-row,
.panel-header {
  align-items: flex-start;
  justify-content: space-between;
}

.brand-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-toggle {
  display: none;
}

.compact {
  margin-top: 6px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  font-size: clamp(1.55rem, 2.3vw, 2.3rem);
}

h2 {
  font-size: 1.08rem;
}

.status-badge {
  min-width: 98px;
  padding: 7px 10px;
  border-radius: 999px;
  color: #fff;
  background: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.status-badge.warning {
  background: var(--gold);
}

.status-badge.error {
  background: var(--heat);
}

.postcode-form {
  margin-top: 18px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.input-row {
  align-items: stretch;
}

input,
select {
  min-width: 0;
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--field);
}

input {
  padding: 0 12px;
  text-transform: uppercase;
}

select {
  padding: 0 10px;
}

.input-row button,
#refreshButton {
  height: 42px;
  padding: 0 16px;
  border-radius: 6px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
}

.input-row button:hover,
#refreshButton:hover {
  background: var(--accent-strong);
}

.filter-grid {
  display: grid;
  grid-template-columns: 160px minmax(180px, 1fr);
  margin-top: 12px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 14px;
}

.metric-row article {
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.metric-row strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 1.32rem;
}

.metric-row span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
}

.message {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.details-panel {
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(220px, 1fr) auto auto;
  gap: 14px;
  max-height: 100vh;
  padding: 18px;
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow: auto;
}

#refreshButton {
  height: 36px;
  padding: 0 12px;
}

.street-list,
.crime-list {
  display: grid;
  gap: 8px;
}

.street-list {
  align-content: start;
  overflow: auto;
  padding-right: 2px;
}

.street-button,
.crime-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  text-align: left;
}

.street-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 11px;
  color: var(--ink);
}

.street-button:hover,
.street-button.active {
  border-color: rgba(20, 108, 92, 0.45);
  background: #edf6f2;
}

.street-button strong,
.crime-card strong {
  overflow-wrap: anywhere;
  font-size: 0.92rem;
}

.street-button span,
.crime-card span,
.empty-state,
.data-note {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.count-pill {
  min-width: 34px;
  height: 30px;
  padding: 5px 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--heat);
  font-weight: 900;
  text-align: center;
}

.crime-detail {
  display: grid;
  gap: 10px;
  padding-top: 2px;
}

.crime-card {
  padding: 12px;
}

.crime-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.crime-meta span {
  padding: 4px 7px;
  border-radius: 999px;
  background: var(--field);
}

.data-note {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff7e8;
}

.crime-marker {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid #fff;
  border-radius: 50%;
  color: #fff;
  background: var(--heat);
  box-shadow: 0 8px 18px rgba(23, 33, 38, 0.24);
  font-size: 0.78rem;
  font-weight: 900;
}

.crime-marker.medium {
  background: var(--gold);
}

.crime-marker.low {
  background: var(--blue);
}

.crime-cluster {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 4px solid rgba(255, 255, 255, 0.86);
  border-radius: 50%;
  color: #fff;
  background: var(--blue);
  box-shadow: 0 8px 20px rgba(23, 33, 38, 0.3);
  font-size: 0.78rem;
  font-weight: 900;
}

.crime-cluster.medium {
  background: var(--gold);
}

.crime-cluster.high {
  background: var(--heat);
}

.postcode-marker {
  width: 24px;
  height: 24px;
  border: 5px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow:
    0 0 0 3px var(--accent),
    0 8px 18px rgba(23, 33, 38, 0.3);
}

.leaflet-popup-content {
  margin: 10px 12px;
  min-width: 210px;
}

.popup-title {
  margin: 0 0 6px;
  font-weight: 900;
}

.popup-text {
  margin: 0;
  color: #4d5b62;
}

.popup-breakdown {
  display: grid;
  gap: 5px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
}

.popup-breakdown-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: baseline;
  color: var(--ink);
  font-size: 0.8rem;
}

.popup-breakdown-row span {
  overflow-wrap: anywhere;
}

.popup-breakdown-row strong {
  min-width: 24px;
  color: var(--heat);
  text-align: right;
}

.popup-details-button {
  width: 100%;
  height: 36px;
  margin-top: 11px;
  border-radius: 6px;
  color: #fff;
  background: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
}

.popup-details-button:hover {
  background: var(--accent-strong);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(68vh, 720px) auto;
  }

  .map-stage {
    min-height: 68vh;
  }

  .details-panel {
    max-height: none;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .map-controls {
    right: 14px;
    bottom: 18px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    grid-template-rows: 100svh auto;
  }

  .map-stage {
    min-height: 100svh;
  }

  .search-panel {
    top: 10px;
    left: 10px;
    width: calc(100% - 20px);
    max-height: calc(100svh - 84px);
    padding: 10px;
    overflow: auto;
  }

  .brand-row,
  .panel-header {
    gap: 8px;
  }

  .brand-row {
    align-items: center;
  }

  .brand-row .eyebrow {
    display: none;
  }

  h1 {
    font-size: 1.22rem;
  }

  .brand-actions {
    gap: 6px;
  }

  .status-badge {
    min-width: 62px;
    padding: 6px 8px;
    font-size: 0.68rem;
  }

  .panel-toggle {
    display: block;
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--ink);
    background: var(--panel-strong);
    font-size: 0.72rem;
    font-weight: 900;
  }

  .postcode-form {
    margin-top: 9px;
  }

  .postcode-form > label {
    display: none;
  }

  input,
  select {
    height: 40px;
  }

  .filter-grid,
  .metric-row {
    grid-template-columns: 1fr;
  }

  .filter-controls {
    padding-top: 1px;
  }

  .mobile-collapsed .filter-controls {
    display: none;
  }

  .input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 58px;
    gap: 7px;
  }

  .input-row button {
    height: 40px;
    padding: 0 10px;
  }

  .metric-row article {
    min-height: 58px;
  }

  .map-controls {
    right: 10px;
    bottom: 12px;
    grid-template-columns: repeat(4, 44px);
  }

  .map-controls button,
  .zoom-level {
    width: 44px;
  }

  .leaflet-control-attribution {
    max-width: calc(100vw - 12px);
    overflow: hidden;
    white-space: nowrap;
  }

  .leaflet-popup-content-wrapper {
    max-width: calc(100vw - 34px);
  }

  .leaflet-popup-content {
    margin: 10px;
  }
}
