:root {
  --navy: #0b1f3a;
  --navy-2: #12305a;
  --navy-3: #1d3d6b;
  --amber: #f59e0b;
  --amber-dark: #b45309;
  --teal: #0f8f7e;
  --ink: #12233b;
  --muted: #5b6b80;
  --line: #dde3ec;
  --bg: #f4f6fa;
  --panel: #ffffff;
  --radius: 10px;
  --shadow: 0 8px 28px rgba(11, 31, 58, .22);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  flex: none;
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 3px solid var(--amber);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; min-width: 0; }
.brand-mark { flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 17px; font-weight: 800; letter-spacing: .01em; }
.brand-text span { font-size: 12px; color: #aebbd0; font-weight: 500; }
.demo-badge {
  flex: none;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  color: var(--navy); background: var(--amber);
  padding: 4px 9px; border-radius: 99px;
}

/* ---------- layout ---------- */
.app {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "search map"
    "rest   map";
}
.search-panel { grid-area: search; }
.map-wrap { grid-area: map; }
.rest-panel { grid-area: rest; }

.search-panel {
  position: relative;
  z-index: 30;
  background: var(--panel);
  padding: 14px 14px 12px;
  border-right: 1px solid var(--line);
}
.field-label { display: block; font-size: 12px; font-weight: 700; color: var(--navy-2); margin-bottom: 6px; }
.search-box { position: relative; display: flex; align-items: center; }
.search-icon { position: absolute; left: 11px; color: var(--muted); pointer-events: none; }
.search-box input {
  width: 100%;
  padding: 10px 36px 10px 36px;
  border: 1.5px solid #c3ccd9;
  border-radius: var(--radius);
  background: #fff;
  font-size: 15px;
}
.search-box input::-webkit-search-cancel-button { display: none; }
.search-box input:focus { border-color: var(--navy-3); outline: 3px solid rgba(245, 158, 11, .55); outline-offset: 0; }
.icon-btn {
  position: absolute; right: 6px;
  width: 28px; height: 28px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted);
  display: grid; place-items: center;
}
.icon-btn:hover { background: #eef1f6; color: var(--ink); }

.search-results {
  position: absolute;
  left: 14px; right: 14px; top: calc(100% - 6px);
  margin: 0; padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 60vh;
  overflow-y: auto;
}
.sr-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 7px; cursor: pointer;
}
.sr-item:hover, .sr-item.active { background: #fff4de; }
.sr-main { min-width: 0; flex: 1; }
.sr-title { font-weight: 700; font-size: 14px; }
.sr-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-note { padding: 8px 10px; font-size: 12px; color: var(--muted); }
.sr-all {
  display: block; width: 100%; text-align: left;
  margin-top: 2px; padding: 9px 10px;
  border: 0; border-top: 1px solid var(--line); border-radius: 0 0 7px 7px;
  background: transparent; color: var(--navy-3); font-weight: 700; font-size: 13px;
}
.sr-all:hover, .sr-all.active { background: #fff4de; }

.rest-panel {
  display: flex; flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

/* ---------- filters ---------- */
.filters { flex: none; max-height: 44%; overflow-y: auto; border-top: 1px solid var(--line); }
.filters details { border-bottom: 1px solid var(--line); }
.filters summary {
  list-style: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 14px;
  font-weight: 700; font-size: 13.5px; color: var(--navy);
  cursor: pointer; user-select: none;
}
.filters summary::-webkit-details-marker { display: none; }
.filters summary::after {
  content: ""; width: 8px; height: 8px; margin-left: 10px; flex: none;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); transition: transform .15s;
}
.filters details[open] > summary::after { transform: rotate(-135deg); }
.filters summary span:first-child { flex: 1; }
.filters summary:hover { background: #f7f9fc; }
.badge {
  background: var(--amber); color: var(--navy);
  font-size: 11px; font-weight: 800; min-width: 20px; text-align: center;
  padding: 1px 6px; border-radius: 99px; margin-left: 8px;
}
.opts { padding: 2px 14px 12px; display: grid; gap: 2px; }
.opt {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 4px; border-radius: 7px; cursor: pointer;
}
.opt:hover { background: #f3f6fb; }
.opt input { width: 17px; height: 17px; accent-color: var(--navy-3); margin: 0; flex: none; }
.opt .opt-label { flex: 1; }
.opt .opt-n { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.opt svg { flex: none; }

.count-bar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px;
  background: var(--navy); color: #fff;
  font-weight: 700; font-size: 13px;
}
.link-btn {
  border: 0; background: transparent; color: var(--amber);
  font-weight: 700; font-size: 12.5px; text-decoration: underline; padding: 2px 4px; border-radius: 4px;
}

/* ---------- results list ---------- */
.result-list { flex: 1; min-height: 0; overflow-y: auto; margin: 0; padding: 0; list-style: none; }
.result-list li { border-bottom: 1px solid var(--line); }
.res-btn {
  display: flex; align-items: center; gap: 11px;
  width: 100%; text-align: left;
  padding: 10px 14px; border: 0; background: transparent;
}
.res-btn:hover { background: #fff8ea; }
.res-btn[aria-current="true"] { background: #fff1d1; box-shadow: inset 4px 0 0 var(--amber); }
.res-btn:focus-visible { outline-offset: -3px; }
.res-main { flex: 1; min-width: 0; }
.res-panel { font-weight: 800; font-size: 14px; color: var(--navy); }
.res-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.res-meta { font-size: 12px; color: var(--ink); text-align: right; flex: none; line-height: 1.3; }
.res-meta span { display: block; color: var(--muted); }
.more-btn {
  display: block; width: calc(100% - 28px); margin: 12px 14px;
  padding: 9px; border: 1.5px solid var(--navy-3); border-radius: var(--radius);
  background: #fff; color: var(--navy-3); font-weight: 700;
}
.more-btn:hover { background: #eef3fb; }
.empty { padding: 22px 16px; color: var(--muted); text-align: center; }

/* ---------- map ---------- */
.map-wrap { position: relative; min-width: 0; min-height: 0; background: #e9edf3; }
#map { position: absolute; inset: 0; }
.maplibregl-ctrl-attrib { font-size: 11px; }

.legend {
  position: absolute; left: 12px; bottom: 28px; z-index: 5;
  display: flex; gap: 14px; align-items: center;
  background: rgba(255, 255, 255, .96);
  border: 1px solid var(--line); border-radius: 99px;
  padding: 6px 14px;
  font-size: 12.5px; font-weight: 600; color: var(--navy);
  box-shadow: 0 2px 8px rgba(11, 31, 58, .15);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }

.map-message {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 6;
  background: var(--navy); color: #fff; padding: 8px 14px; border-radius: 8px;
  font-size: 13px; max-width: 90%; text-align: center;
}

/* ---------- card ---------- */
.card {
  position: absolute; z-index: 10;
  left: 14px; top: 14px;
  width: 372px; max-width: calc(100% - 28px);
  max-height: calc(100% - 84px);
  overflow-y: auto;
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.card-photo { position: relative; background: #cfe0f2; border-radius: 14px 14px 0 0; overflow: hidden; }
.card-photo svg { display: block; width: 100%; height: auto; }
.photo-tag {
  position: absolute; left: 10px; bottom: 8px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  background: rgba(11, 31, 58, .78); color: #fff; padding: 3px 8px; border-radius: 99px;
}
.card-close {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  width: 32px; height: 32px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .95); color: var(--navy);
  display: grid; place-items: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}
.card-close:hover { background: #fff; color: #000; }
.card-body { padding: 14px 16px 16px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.card-title { margin: 0; font-size: 20px; font-weight: 800; color: var(--navy); }
.card-id { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.card-loc { margin: 6px 0 12px; color: var(--ink); font-size: 13.5px; }
.card h3 { margin: 0 0 4px; font-size: 11.5px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.strengths { margin: 0 0 14px; padding-left: 18px; }
.strengths li { margin: 2px 0; }
.strengths li::marker { color: var(--amber); }
.impr {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  background: #fff7e6; border: 1px solid #f6d99a; border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 12px;
}
.impr b { font-size: 24px; font-weight: 800; color: var(--navy); font-variant-numeric: tabular-nums; }
.impr span { font-size: 12.5px; color: var(--amber-dark); font-weight: 600; }
.specs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 14px; }
.specs div { background: #f4f6fa; border-radius: 8px; padding: 8px 10px; min-width: 0; }
.specs dt { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.specs dd { margin: 1px 0 0; font-weight: 700; color: var(--navy); overflow-wrap: anywhere; }
.specs .wide { grid-column: 1 / -1; }
.btn-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.btn {
  border: 1.5px solid var(--navy-3); background: #fff; color: var(--navy-3);
  font-weight: 700; font-size: 13px; padding: 9px 6px; border-radius: 8px;
}
.btn:hover { background: #eef3fb; }
.btn.primary { background: var(--amber); border-color: var(--amber); color: var(--navy); }
.btn.primary:hover { background: #fbab1f; }
.demo-note {
  margin-top: 10px; padding: 9px 11px; border-radius: 8px;
  background: var(--navy); color: #fff; font-size: 12.5px;
}

/* ---------- footer ---------- */
.notice {
  flex: none;
  padding: 7px 18px;
  background: #e8edf5; color: #52627a;
  font-size: 11.5px; line-height: 1.4;
  border-top: 1px solid var(--line);
}

/* ---------- mobile ---------- */
@media (max-width: 759px) {
  body { height: auto; min-height: 100vh; display: block; }
  .topbar { padding: 9px 14px; }
  .brand-text strong { font-size: 15px; }
  .demo-badge { display: none; }
  .app {
    display: block;
  }
  .search-panel {
    position: sticky; top: 0;
    border-right: 0; border-bottom: 1px solid var(--line);
    padding: 10px 14px;
  }
  .search-results { left: 10px; right: 10px; max-height: 55vh; }
  .map-wrap { height: 62vh; min-height: 380px; }
  .rest-panel { border-right: 0; display: block; }
  .filters { max-height: none; overflow: visible; }
  .result-list { max-height: 60vh; }
  /* Leave room on the right for the zoom buttons (top-right control, ~29px wide + 10px margin). */
  .legend { left: 8px; right: 48px; bottom: auto; top: 8px; justify-content: center; gap: 10px; padding: 5px 10px; }
  .map-wrap { scroll-margin-top: 78px; }
  .card {
    position: fixed; z-index: 40;
    left: 0; right: 0; top: auto; bottom: 0;
    width: auto; max-width: none;
    max-height: 58vh; max-height: 58dvh;
    border-radius: 16px 16px 0 0;
  }
  .card-photo { border-radius: 16px 16px 0 0; }
  .card-photo svg { max-height: 130px; width: 100%; }
  .card-title { font-size: 18px; }
  .impr b { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
