:root {
  color: #202f3e;
  background: #fff;
  font: 16px/1.4 Inter, system-ui, sans-serif;
  --line: #dce5ed;
  --muted: #596b7c;
  --primary: #0865bc;
  --blue-soft: #eef6ff;
  --panel-padding: 18px;
  --surface-shadow: 0 2px 8px #283e5620;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.layout {
  display: grid;
  grid-template-columns: clamp(320px, 29vw, 450px) minmax(0, 1fr);
  height: 100dvh;
}
.panel, .map-panel { min-width: 0; min-height: 0; }
.panel {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-right: 1px solid var(--line);
  box-shadow: 2px 0 8px #19344f0e;
}
.panel-collapsed { grid-template-columns: minmax(0, 1fr); }
.panel-collapsed .panel { display: none; }

.header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  min-height: 60px;
  gap: 10px;
  padding: 10px var(--panel-padding);
  border-bottom: 1px solid var(--line);
}
h1 { margin: 0; font-size: 1.06rem; font-weight: 650; letter-spacing: -.015em; }
.home-link { margin-left: auto; color: var(--primary); font-size: .875rem; white-space: nowrap; text-underline-offset: 3px; }
.brand-icon {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--blue-soft);
}
.brand-icon span, .place::before {
  width: 13px;
  height: 13px;
  border: 2px solid var(--primary);
  border-radius: 50% 50% 50% 0;
  transform: translateY(-1px) rotate(-45deg);
}
.brand-icon span::before, .place::after {
  content: '';
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--primary);
}
.brand-icon span::before { top: 3px; left: 3px; }

.filters { padding: 15px var(--panel-padding) 17px; display: grid; gap: 12px; }
.place-search { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.place-search button { padding: 0 12px; border: 0; border-radius: 4px; background: var(--primary); color: #fff; font-size: .875rem; }
.place-search button:hover { background: #0759a5; }
.reset-filters {
  justify-self: end;
  padding: 3px 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: .875rem;
}
.reset-filters:hover:not(:disabled) { text-decoration: underline; text-underline-offset: 3px; }
.filter-field { display: grid; gap: 5px; min-width: 0; }
.filter-field label { font-size: .875rem; font-weight: 600; }
.filter-control { position: relative; }
.filter-control::after {
  content: '';
  position: absolute;
  top: 16px;
  right: 14px;
  width: 7px;
  height: 7px;
  border: solid #516a82;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  pointer-events: none;
}
.filter-field input, .place-search input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 8px 32px 8px 11px;
  border: 1px solid #c7d4e0;
  border-radius: 4px;
  background: #fff;
  color: inherit;
}
.place-search input { padding-right: 10px; }
.filter-field input:disabled { background: #f5f7fa; }
.filter-hint { margin: 0; color: var(--muted); font-size: .875rem; }
.filter-options {
  position: absolute;
  z-index: 4;
  inset: calc(100% + 4px) 0 auto;
  max-height: min(282px, 45dvh);
  overflow: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  border: 1px solid #c7d4e0;
  border-radius: 4px;
  background: #fff;
  box-shadow: var(--surface-shadow);
}
.filter-options li { padding: 8px 10px; border-radius: 3px; cursor: pointer; overflow-wrap: anywhere; }
.filter-options li:hover, .filter-options [aria-selected="true"] { background: var(--blue-soft); }
.error { color: #982920; margin: 0; font-size: .875rem; }

.results { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.results-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  padding: 0 var(--panel-padding);
  background: #f1f6fc;
  border-block: 1px solid var(--line);
}
h2 { margin: 0; padding: 10px 0 8px; font-size: .94rem; border-bottom: 2px solid var(--primary); }
#status { margin: 0; padding-bottom: 3px; color: var(--muted); font-size: .875rem; }
#results { overflow: auto; padding: 0; margin: 0; list-style: none; scrollbar-color: #bac8d4 transparent; }
#results li + li { border-top: 1px solid #ebf0f5; }
.place {
  position: relative;
  width: 100%;
  display: grid;
  gap: 3px;
  padding: 10px var(--panel-padding) 10px calc(var(--panel-padding) + 23px);
  border: 0;
  background: #fff;
  color: inherit;
  text-align: left;
}
.place::before, .place::after { position: absolute; content: ''; }
.place::before { top: 14px; left: var(--panel-padding); }
.place::after { top: 18px; left: calc(var(--panel-padding) + 5px); }
.place:hover, .place[aria-current] { background: var(--blue-soft); }
.place:focus-visible { outline-offset: -2px; }
.place strong { font-size: .94rem; font-weight: 620; }
.place span { color: var(--muted); font-size: .875rem; }
#pagination { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: auto; padding: 10px var(--panel-padding); border-top: 1px solid var(--line); }
#page, .secondary { font-size: .875rem; }
.secondary { min-height: 36px; padding: 5px 10px; border: 1px solid #c7d4e0; border-radius: 4px; background: #fff; color: var(--primary); }
.secondary:hover:not(:disabled) { background: var(--blue-soft); }
#retry-results { align-self: flex-start; margin: 8px var(--panel-padding); }

.map-panel { position: relative; background: #edf0e7; overflow: hidden; }
#map { position: absolute; inset: 0; }
.map-toggle, .map-state, .selection {
  position: absolute;
  top: 12px;
  border: 1px solid #cdd9e5;
  border-radius: 5px;
  background: #fff;
  box-shadow: var(--surface-shadow);
}
.map-toggle { left: 12px; display: grid; place-items: center; width: 42px; height: 42px; color: var(--primary); }
.map-toggle:hover { background: var(--blue-soft); }
.map-toggle span { position: relative; width: 11px; height: 11px; transform: translateX(2px); }
.map-toggle span::before, .map-toggle span::after {
  position: absolute;
  top: 2px;
  left: 0;
  width: 8px;
  height: 8px;
  content: '';
  border: solid currentColor;
  border-width: 0 0 2px 2px;
  transform: rotate(45deg);
}
.map-toggle span::after { left: 5px; }
.panel-collapsed .map-toggle span { transform: translateX(-2px) rotate(180deg); }
.map-state, .selection { left: 64px; max-width: calc(100% - 120px); padding: 10px 12px; }
.selection { display: flex; align-items: start; gap: 12px; }
.selection p { margin: 3px 0 0; color: var(--muted); }
.selection p:empty { display: none; }
.selection button { border: 0; min-width: 30px; min-height: 30px; border-radius: 4px; color: var(--primary); background: var(--blue-soft); font-size: 1.25rem; }

.map-hint {
  position: absolute;
  left: 12px;
  bottom: 16px;
  max-width: calc(100% - 110px);
  margin: 0;
  padding: 6px 9px;
  border: 1px solid #cdd9e5;
  border-radius: 4px;
  background: #fff;
  color: var(--muted);
  box-shadow: var(--surface-shadow);
  font-size: .875rem;
  pointer-events: none;
}
.building-card {
  position: absolute;
  top: 12px;
  left: 64px;
  display: flex;
  flex-direction: column;
  width: min(390px, calc(100% - 120px));
  max-height: calc(100% - 60px);
  border: 1px solid #cdd9e5;
  border-radius: 5px;
  background: #fff;
  box-shadow: var(--surface-shadow);
}
.building-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.building-header h2 { padding: 3px 0; border: 0; font-size: 1rem; overflow-wrap: anywhere; }
.card-close { flex: 0 0 30px; min-height: 30px; padding: 0; border: 0; border-radius: 4px; background: var(--blue-soft); color: var(--primary); font-size: 1.25rem; }
.card-close:hover { background: #dcecff; }
.building-content { min-height: 0; overflow: auto; padding: 12px 14px; }
.building-content p { margin: 0 0 9px; }
.building-content p:empty { display: none; }
.building-address { color: var(--muted); }
.building-details summary { color: var(--primary); cursor: pointer; font-size: .875rem; }
.building-details[open] summary { margin-bottom: 8px; }
.building-facts { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 5px 10px; margin: 0; font-size: .875rem; }
.building-facts dt { color: var(--muted); }
.building-facts dd { margin: 0; overflow-wrap: anywhere; }
.building-content h3 { margin: 16px 0 4px; font-size: .96rem; }
.building-branches-status { color: var(--muted); font-size: .875rem; }
.building-branches { margin: 0 0 8px; padding: 0; list-style: none; }
.building-branches li { display: grid; gap: 3px; padding: 7px 0; border-top: 1px solid var(--line); font-size: .875rem; }
.building-branches li span { color: var(--muted); }

@media (max-width: 660px) {
  :root { --panel-padding: 12px; }
  .layout { height: auto; grid-template-columns: minmax(0, 1fr); }
  .panel { display: contents; }
  .header { grid-row: 1; min-height: 52px; }
  .filters { position: relative; z-index: 2; grid-row: 2; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 6px 10px; padding: 10px var(--panel-padding) 12px; }
  .filters .error, .filters > button, .place-search { grid-column: 1 / -1; }
  .map-panel { grid-row: 3; height: 54dvh; min-height: 270px; }
  .results { grid-row: 4; max-height: 320px; }
  .panel-collapsed .map-panel { grid-row: 1; height: 100dvh; }
  .map-toggle span { transform: rotate(90deg); }
  .panel-collapsed .map-toggle span { transform: rotate(-90deg); }
  .building-card { top: 63px; left: 12px; width: min(390px, calc(100% - 24px)); max-height: calc(100% - 112px); }
}
