:root {
  --bg: #fafaf8;
  --surface: #ffffff;
  --border: #d8d8d4;
  --text: #1f2328;
  --muted: #5c6168;
  --accent: #1f5f6b;
  --accent-soft: #e6f0f2;
  --radius: 6px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}
body {
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Top bar + search ---------- */
.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 600; white-space: nowrap; }
.brand p { margin: 0; font-size: 14px; color: var(--muted); }

.search { position: relative; flex: 1; max-width: 400px; }
#search-input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
#search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 340px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.result { padding: 8px 10px; border-radius: 4px; cursor: pointer; }
.result:hover, .result[aria-selected="true"] { background: var(--accent-soft); }
.result-name { display: block; font-size: 14px; font-weight: 600; }
.result-sub { display: block; font-size: 13px; color: var(--muted); }
.search-empty { padding: 10px; font-size: 14px; color: var(--muted); }

/* ---------- Layout + sidebar ---------- */
.layout { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  padding: 14px 10px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.sidebar h2 {
  margin: 0 8px 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
#category-list { list-style: none; margin: 0; padding: 0; }

.cat-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  font: inherit;
  color: var(--text);
  text-align: left;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
}
.cat-btn:hover { background: var(--bg); }
.cat-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  font-weight: 600;
}
.cat-dot { width: 10px; height: 10px; border-radius: 50%; border: 1px solid #fff; box-shadow: 0 0 0 1px var(--border); }
.cat-dot.none { background: var(--muted); }
.cat-label { flex: 1; }
.cat-num { font-size: 13px; color: var(--muted); }

/* ---------- Map + status ---------- */
.map-wrap { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; }

#map-status {
  position: absolute; left: 12px; top: 12px; margin: 0;
  padding: 6px 10px; font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
#map-status:empty { display: none; }

/* ---------- Place card ---------- */
.card {
  position: absolute;
  left: 12px;
  bottom: 12px;
  width: 310px;
  max-width: calc(100% - 24px);
  max-height: calc(100% - 24px);
  overflow-y: auto;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.card h2 { margin: 0 28px 2px 0; font-size: 16px; font-weight: 600; }
.card p { margin: 6px 0 0; font-size: 14px; }
.card .card-meta { margin-top: 0; color: var(--muted); }
.card .card-coords { font-size: 13px; color: var(--muted); }
.card a { color: var(--accent); overflow-wrap: anywhere; }
.card-close {
  position: absolute; top: 8px; right: 8px;
  width: 32px; height: 32px;
  font-size: 22px; line-height: 1;
  color: var(--muted);
  background: none; border: 0; border-radius: var(--radius);
  cursor: pointer;
}
.card-close:hover { background: var(--bg); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  margin-top: 12px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
}
.btn:hover { background: #184e58; }
.btn-secondary { color: var(--text); background: var(--surface); border-color: var(--border); font-weight: 500; }
.btn-secondary:hover { background: var(--bg); }
.btn-secondary[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; padding: 0 8px; }

.field-title {
  display: block;
  margin: 12px 0 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.card .origin-label { margin-top: 2px; font-weight: 600; }
#origin-input {
  width: 100%;
  min-height: 40px;
  margin-top: 6px;
  padding: 0 10px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.card .route-message { min-height: 1.2em; font-size: 13px; color: var(--muted); }
.card .route-result { padding: 8px 0 0; font-size: 15px; }
.route-result span { color: var(--muted); }

.mode-toggle {
  display: flex;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.mode-btn {
  flex: 1;
  min-height: 36px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 0;
  cursor: pointer;
}
.mode-btn + .mode-btn { border-left: 1px solid var(--border); }
.mode-btn:hover { background: var(--bg); }
.mode-btn[aria-pressed="true"] {
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- Footer ---------- */
.statusbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 16px;
  font-size: 13px;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* ---------- Tablet ---------- */
@media (min-width: 701px) and (max-width: 960px) {
  .sidebar { width: 180px; }
  .brand p { display: none; }
  .card { width: 280px; }
}

/* ---------- Mobile ---------- */
@media (max-width: 700px) {
  .topbar { padding: 8px 12px; gap: 10px; }
  .brand h1 { font-size: 16px; }
  .brand p { display: none; }
  .search { max-width: none; }
  #search-input { min-height: 44px; }
  #search-results { max-height: 45vh; }

  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    padding: 6px 8px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .sidebar h2 {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
  }
  #category-list { display: flex; gap: 6px; }
  .cat-btn {
    width: auto;
    min-height: 44px;
    padding: 0 12px;
    white-space: nowrap;
    border-color: var(--border);
  }
  .cat-num { display: none; }

  .card {
    left: 0; right: 0; bottom: 0;
    width: auto; max-width: none;
    max-height: 55%;
    padding: 12px 14px;
    border-left: 0; border-right: 0; border-bottom: 0;
    border-radius: 10px 10px 0 0;
  }
  .card h2 { font-size: 15px; }
  .btn { min-height: 44px; }
  .mode-btn { min-height: 44px; }

  .statusbar { padding: 6px 12px; }
  .statusbar span:last-child { display: none; }
}

/* ---------- Small phones ---------- */
@media (max-width: 380px) {
  .brand h1 { font-size: 15px; }
  .cat-btn { padding: 0 10px; font-size: 14px; }
}