:root {
  --background: #f5f6f8;
  --surface: #ffffff;
  --foreground: #22252b;
  --muted: #68707c;
  --border: #d9dde3;
  --border-strong: #bec4cd;
  --purple: #a72bc4;
  --purple-dark: #7e1998;
  --purple-soft: #f3e6f6;
  --pink: #d95db8;
  --pink-dark: #a32f82;
  --pink-soft: #f9e8f4;
  --selected: #f0f1f4;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-width: 320px; height: 100%; margin: 0; }
body { overflow: hidden; background: var(--background); color: var(--foreground); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input { font: inherit; }

.map-app { display: grid; grid-template-rows: 82px minmax(0, 1fr); height: 100dvh; }
.map-header { display: flex; align-items: center; justify-content: space-between; gap: 22px; padding: 0 24px; border-bottom: 1px solid var(--border); background: var(--surface); z-index: 500; }
.map-heading { display: flex; align-items: center; gap: 12px; min-width: 0; }
.back-link { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; width: 38px; height: 38px; border: 1px solid var(--border-strong); border-radius: 5px; background: var(--surface); color: var(--foreground); font-size: 21px; font-weight: 650; line-height: 1; text-decoration: none; }
.back-link:hover { border-color: var(--purple); color: var(--purple-dark); }
.back-link:focus-visible { outline: 3px solid rgb(167 43 196 / 18%); outline-offset: 2px; }
.map-title { min-width: 0; }
.map-title h1 { margin: 0; font-size: 21px; font-weight: 750; letter-spacing: 0; }
.map-title p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.header-summary { display: flex; align-items: center; gap: 24px; flex: 0 0 auto; }
.zone-legend { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.zone-legend span { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.zone-legend i { display: block; width: 10px; height: 10px; border-radius: 50%; }
.zone-legend i.is-purple { background: var(--purple); }
.zone-legend i.is-pink { background: var(--pink); }
.map-stats { display: flex; align-items: center; gap: 18px; }
.map-stat { display: grid; gap: 2px; min-width: 66px; }
.map-stat strong { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.map-stat span { color: var(--muted); font-size: 12px; }

.map-workspace { display: grid; grid-template-columns: minmax(320px, 380px) minmax(0, 1fr); min-height: 0; }
.premises-panel { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; border-right: 1px solid var(--border); background: var(--surface); z-index: 400; }
.panel-search { padding: 16px; border-bottom: 1px solid var(--border); }
.panel-search label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
.panel-search input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 5px; outline: none; background: var(--surface); color: var(--foreground); }
.panel-search input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgb(167 43 196 / 14%); }
.building-list { min-height: 0; margin: 0; padding: 0; overflow-y: auto; list-style: none; }
.building-item { border-bottom: 1px solid var(--border); }
.building-button { display: block; width: 100%; padding: 15px 16px; border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.building-button:hover { background: #f7f7f9; }
.building-button.is-selected { background: var(--selected); box-shadow: inset 3px 0 0 var(--zone-color); }
.building-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.building-address { margin: 0; font-size: 14px; font-weight: 700; line-height: 1.35; }
.building-zone { flex: 0 0 auto; padding: 4px 7px; border-radius: 4px; background: var(--zone-soft); color: var(--zone-dark); font-size: 11px; font-weight: 750; }
.is-purple-zone { --zone-color: var(--purple); --zone-dark: var(--purple-dark); --zone-soft: var(--purple-soft); }
.is-pink-zone { --zone-color: var(--pink); --zone-dark: var(--pink-dark); --zone-soft: var(--pink-soft); }
.premise-lines { display: grid; gap: 8px; margin-top: 11px; }
.premise-line { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: baseline; }
.premise-line code { overflow: hidden; color: var(--foreground); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.premise-area { color: var(--zone-dark); font-size: 12px; font-weight: 750; white-space: nowrap; }
.empty-list { padding: 24px 16px; color: var(--muted); font-size: 14px; }

.map-stage, .leaflet-map { min-width: 0; min-height: 0; width: 100%; height: 100%; }
.leaflet-container { background: #e8ecef; font-family: inherit; }
.leaflet-control-zoom a { color: var(--foreground); }
.premises-marker { display: flex; align-items: center; justify-content: center; width: 38px; height: 38px; border: 3px solid #fff; border-radius: 50% 50% 50% 8px; background: var(--zone-color); box-shadow: 0 3px 10px rgb(34 37 43 / 28%); color: #fff; font-size: 13px; font-weight: 800; transform: rotate(-45deg); }
.premises-marker span { transform: rotate(45deg); }
.premises-marker.is-selected { box-shadow: 0 0 0 3px #22252b, 0 4px 12px rgb(34 37 43 / 34%); }
.leaflet-popup-content-wrapper { border-radius: 6px; box-shadow: 0 8px 28px rgb(34 37 43 / 22%); }
.leaflet-popup-content { width: 320px !important; margin: 16px; }
.popup-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.popup-title { margin: 0; font-size: 15px; font-weight: 750; line-height: 1.35; }
.popup-zone { flex: 0 0 auto; padding: 4px 7px; border-radius: 4px; background: var(--zone-soft); color: var(--zone-dark); font-size: 11px; font-weight: 750; }
.popup-coordinates { margin: 5px 0 0; color: var(--muted); font: 11px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.popup-premises { display: grid; gap: 10px; max-height: min(320px, 55vh); margin-top: 13px; padding-top: 12px; padding-right: 4px; overflow-y: auto; border-top: 1px solid var(--border); }
.popup-premise { display: grid; gap: 4px; }
.popup-premise-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.popup-premise code { font-size: 12px; }
.popup-premise-area { color: var(--zone-dark); font-size: 12px; font-weight: 750; white-space: nowrap; }
.popup-premise-meta { color: var(--muted); font-size: 11px; }

@media (max-width: 900px) {
  .zone-legend { display: none; }
}

@media (max-width: 760px) {
  .map-app { grid-template-rows: auto minmax(0, 1fr); }
  .map-header { align-items: flex-start; padding: 12px 14px; }
  .map-heading { align-items: flex-start; gap: 9px; }
  .back-link { width: 34px; height: 34px; }
  .map-title h1 { font-size: 17px; }
  .map-title p { max-width: 230px; font-size: 12px; }
  .header-summary { gap: 10px; }
  .map-stats { gap: 9px; }
  .map-stat { min-width: 43px; }
  .map-stat strong { font-size: 16px; }
  .map-stat span { font-size: 10px; }
  .map-workspace { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 224px; }
  .map-stage { grid-row: 1; }
  .premises-panel { grid-row: 2; border-top: 1px solid var(--border); border-right: 0; }
  .panel-search { display: none; }
  .building-list { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(290px, 88vw); overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; }
  .building-item { border-right: 1px solid var(--border); border-bottom: 0; scroll-snap-align: start; }
  .building-button { height: 100%; overflow-y: auto; }
  .leaflet-popup-content { width: min(270px, 70vw) !important; }
}
