:root {
  --accent: #1d5fd1;
  --accent-soft: #e8f0fd;
  --text: #1c1f24;
  --muted: #5f6672;
  --line: #dde1e7;
  --bg: #f6f7f9;
  --panel-w: 380px;
  --top-h: 56px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- Top bar ---------- */
.topbar {
  height: var(--top-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  z-index: 1001;
}
.topbar h1 { font-size: 17px; margin: 0; white-space: nowrap; }
.count { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { margin-left: auto; display: flex; gap: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:focus-visible, input:focus-visible, select:focus-visible, .item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Layout ---------- */
.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  min-height: 0;
}
.map { min-height: 0; height: 100%; }
.panel {
  background: #fff;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.sheet-handle { display: none; }

/* ---------- Filters ---------- */
.filters { border-bottom: 1px solid var(--line); }
.filters summary {
  cursor: pointer;
  padding: 12px;
  font-weight: 600;
  min-height: 44px;
}
.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 12px 14px;
}
.filter-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.filter-grid .wide { grid-column: 1 / -1; }
.filter-grid label.check, .list-head label.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
  min-height: 40px;
  cursor: pointer;
}
input[type=number], input[type=search], select {
  font: inherit;
  color: var(--text);
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  width: 100%;
}
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 6px !important;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--text) !important;
  font-size: 13px !important;
  cursor: pointer;
}
.chip:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- List ---------- */
.list-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.list-head > label:first-child { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); flex: 1; }
.note { margin: 0; padding: 10px 12px; font-size: 13px; color: var(--muted); background: var(--bg); border-bottom: 1px solid var(--line); }
.list { list-style: none; margin: 0; padding: 0; }
.item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
  cursor: pointer;
  min-height: 44px;
}
.item:hover { background: var(--bg); }
.item.fav { border-left-color: var(--accent); }
.item-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.item-price { font-weight: 700; font-size: 16px; }
.item.fav .item-price { color: var(--accent); }
.item-status { font-size: 12px; color: var(--muted); }
.item-addr { font-weight: 500; }
.item-city, .item-facts { font-size: 13px; color: var(--muted); }
.item-warn { font-size: 12px; color: #9a5b00; margin-top: 2px; }
.item-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
}
.item-link:hover { text-decoration: underline; }

/* ---------- Markers ---------- */
.pin-wrap { background: none; border: 0; }
.pin {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -100%);
  display: inline-block;
  padding: 3px 7px;
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  border: 1px solid #8a919c;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  cursor: pointer;
}
.pin::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  margin-left: -5px;
  border: 5px solid transparent;
  border-bottom: 0;
  border-top-color: inherit;
}
.pin.int { border-color: var(--accent); color: var(--accent); }
.pin.fav { background: var(--accent); border-color: var(--accent); color: #fff; font-size: 13px; }
.leaflet-marker-icon:hover .pin, .leaflet-marker-icon:focus .pin { transform: translate(-50%, -100%) scale(1.08); }

/* ---------- Popup ---------- */
.popup { min-width: 210px; font-size: 13px; }
.popup-price { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.popup-addr { font-weight: 600; margin-top: 2px; }
.popup-city { color: var(--muted); }
.popup dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 8px 0; }
.popup dt { color: var(--muted); }
.popup dd { margin: 0; }
.popup-link { width: 100%; color: #fff !important; }
.tag { font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 10px; border: 1px solid var(--accent); color: var(--accent); }
.tag.fav { background: var(--accent); color: #fff; }

/* ---------- Help dialog, drop overlay, toast ---------- */
.help {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 30, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 2000;
}
.help[hidden], .drop[hidden], .toast[hidden] { display: none; }
.help-card {
  background: #fff;
  border-radius: 12px;
  max-width: 480px;
  width: 100%;
  padding: 20px 22px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
  max-height: 90vh;
  overflow-y: auto;
}
.help-card h2 { margin: 0 0 10px; font-size: 19px; }
.help-card ol { padding-left: 20px; margin: 0 0 12px; }
.help-card li { margin-bottom: 6px; }
.help-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

.drop {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(29, 95, 209, .12);
  border: 3px dashed var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.drop div { background: #fff; padding: 16px 22px; border-radius: 10px; font-weight: 600; color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100% - 24px));
  background: #1c1f24;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 2500;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}

/* ---------- Phone ---------- */
@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 0 8px; }
  .topbar h1 { display: none; }
  .count { font-size: 12px; flex: 1; min-width: 0; }
  .actions { gap: 6px; }
  .actions .btn { padding: 0 10px; font-size: 14px; }

  .layout { display: block; position: relative; }
  .map { position: absolute; inset: 0; }
  .panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 56px;
    z-index: 1000;
    border-right: 0;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, .12);
    overflow: hidden;
    transition: height .2s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.sheet-open .panel { height: calc(100% - var(--top-h) - 24px); overflow-y: auto; }
  .sheet-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 56px;
    flex: 0 0 auto;
    border: 0;
    background: #fff;
    font: inherit;
    font-weight: 600;
    color: var(--accent);
    cursor: pointer;
    position: sticky;
    top: 0;
    z-index: 1;
    border-bottom: 1px solid var(--line);
  }
  .sheet-handle::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    width: 40px;
    height: 4px;
    margin-left: -20px;
    border-radius: 2px;
    background: var(--line);
  }
  .toast { bottom: 72px; }
  .leaflet-bottom { bottom: 56px; }
}
