:root {
  --bg: #f7f6f2;
  --panel: #ffffff;
  --ink: #20242a;
  --muted: #667085;
  --line: #d7dbe0;
  --accent: #0b6b65;
  --focus: #005fcc;
  --shadow: 0 12px 36px rgba(20, 27, 36, 0.18);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 0 12px;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

button:hover,
button:focus {
  filter: brightness(0.94);
}

button:focus,
input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(0, 95, 204, 0.28);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  height: 100vh;
  min-height: 620px;
}

.map-wrap {
  position: relative;
  min-width: 0;
}

#map {
  height: 100%;
  width: 100%;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  overflow: auto;
  padding: 18px;
  background: var(--panel);
  border-left: 1px solid var(--line);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 2px;
  font-size: 1.45rem;
  line-height: 1.18;
}

h2 {
  margin-bottom: 8px;
  font-size: 1rem;
}

.panel-header p,
.muted,
.meta-row {
  color: var(--muted);
}

.panel-header p {
  margin-bottom: 0;
}

.disclaimer {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #edd391;
  border-radius: 6px;
  background: #fff7db;
  font-size: 0.92rem;
  line-height: 1.35;
}

.controls {
  display: grid;
  gap: 12px;
}

.secondary-button {
  border-color: var(--line);
  background: #fff;
  color: var(--accent);
}

.secondary-button:hover,
.secondary-button:focus {
  background: #e6f3f1;
  filter: none;
}

label span,
legend {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
  font-size: 0.86rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

fieldset {
  margin: 0;
  padding: 10px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

fieldset label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.92rem;
}

fieldset input[type="checkbox"] {
  width: auto;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px 12px;
}

.nearby {
  display: grid;
  gap: 8px;
}

.nearby form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.nearby .muted {
  margin-bottom: 0;
  font-size: 0.82rem;
}

.filters {
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.filters summary {
  cursor: pointer;
  font-weight: 800;
}

.filters > label,
.filters > fieldset {
  margin-top: 12px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.84rem;
}

.map-toggle {
  display: none;
}

.results {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.result-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.result-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  line-height: 1.25;
}

.result-title h3 {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.22;
}

.result-address {
  display: -webkit-box;
  overflow: hidden;
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.result-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.result-chips,
.popup-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 9px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.76rem;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.distance-chip {
  border: 1px solid #0b6b65;
  background: #0b6b65;
  color: #fff;
}

.status-chip {
  flex: 0 0 auto;
}

.status-likely {
  border-color: #a7f3d0;
  background: #d8f5e7;
  color: #065f46;
}

.status-possible {
  border-color: #f6d66b;
  background: #fff3c4;
  color: #7a4d00;
}

.status-unknown {
  border-color: #d7dbe0;
  background: #f2f4f7;
  color: #344054;
}

.category-chip {
  border-color: rgba(32, 36, 42, 0.12);
  background: #f2f4f7;
  color: #344054;
}

.category-restaurant {
  background: #fde7e5;
  color: #9f2f2a;
}

.category-hotel {
  background: #ece8ff;
  color: #563bd1;
}

.category-entertainment {
  background: #f9e2ef;
  color: #8b3c70;
}

.category-leisure {
  background: #dcf4eb;
  color: #17664d;
}

.category-culture {
  background: #f6ead5;
  color: #805315;
}

.category-public_building {
  background: #e9edf2;
  color: #344054;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.result-actions button {
  min-height: 34px;
  padding: 0 10px;
}

.result-overflow {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.legend {
  position: absolute;
  left: 12px;
  bottom: 24px;
  z-index: 500;
  min-width: 180px;
  max-width: calc(100% - 24px);
  padding: 9px 11px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 8px 24px rgba(20, 27, 36, 0.14);
  font-size: 0.78rem;
  transition: all 0.2s ease-in-out;
}

.legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.legend-toggle {
  display: none; /* hidden on desktop */
  background: none;
  border: none;
  color: var(--muted);
  padding: 4px;
  min-height: auto;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.legend-toggle:hover {
  color: var(--ink);
}

.legend-toggle .chevron {
  transition: transform 0.2s;
}

.legend.is-collapsed .legend-toggle .chevron {
  transform: rotate(180deg);
}

.legend-content {
  display: grid;
  gap: 5px;
  margin-top: 8px;
}

.legend.is-collapsed .legend-content {
  display: none;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot,
.marker-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.22);
}

.restaurant {
  background: #d94841;
}

.retail {
  background: #277da1;
}

.hotel {
  background: #7d5fff;
}

.entertainment {
  background: #c05a98;
}

.leisure {
  background: #2d9d78;
}

.culture {
  background: #b7791f;
}

.public_building {
  background: #4a5568;
}

.other {
  background: #718096;
}

.custom-marker {
  background: transparent;
  border: 0;
}

.custom-marker .marker-dot {
  width: 11px;
  height: 11px;
}

.map-notice {
  position: absolute;
  top: 16px;
  left: 50%;
  z-index: 500;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  border: 1px solid rgba(32, 36, 42, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: #344054;
  box-shadow: 0 8px 24px rgba(20, 27, 36, 0.14);
  padding: 8px 11px;
  font-size: 0.86rem;
  font-weight: 700;
  text-align: center;
}

.map-notice[hidden] {
  display: none;
}

.cluster-marker {
  background: transparent;
  border: 0;
}

.cluster-marker.marker-cluster {
  border-radius: 20px;
  background-clip: padding-box;
}

.cluster-marker.marker-cluster div {
  width: 30px;
  height: 30px;
  margin-top: 5px;
  margin-left: 5px;
  border-radius: 15px;
  color: #20242a;
  font: 12px "Helvetica Neue", Arial, Helvetica, sans-serif;
  line-height: 30px;
  text-align: center;
}

.cluster-marker.marker-cluster span {
  line-height: 30px;
}

.cluster-marker.marker-cluster-small {
  background-color: rgba(181, 226, 140, 0.6);
}

.cluster-marker.marker-cluster-small div {
  background-color: rgba(110, 204, 57, 0.6);
}

.cluster-marker.marker-cluster-medium {
  background-color: rgba(241, 211, 87, 0.6);
}

.cluster-marker.marker-cluster-medium div {
  background-color: rgba(240, 194, 12, 0.6);
}

.cluster-marker.marker-cluster-large {
  background-color: rgba(253, 156, 115, 0.6);
}

.cluster-marker.marker-cluster-large div {
  background-color: rgba(241, 128, 23, 0.6);
}

dialog {
  width: min(640px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.44);
}

dialog article {
  padding: 18px;
}

dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

dialog h2 {
  margin: 0;
  font-size: 1.25rem;
}

dialog p {
  line-height: 1.5;
}

.leaflet-popup-content {
  min-width: 220px;
}

.popup-title {
  margin-bottom: 6px;
  font-weight: 800;
}

.popup-chips {
  margin-bottom: 10px;
}

.leaflet-popup-content .chip {
  min-height: 24px;
  font-size: 0.72rem;
}

.popup-meta {
  margin: 4px 0;
  color: #4b5563;
}

.popup-section {
  display: grid;
  gap: 2px;
  margin: 8px 0;
  color: #374151;
}

.popup-section strong {
  color: #20242a;
}

.popup-section span {
  font-size: 0.9rem;
  line-height: 1.35;
}

.sheet-handle {
  display: none;
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    position: relative;
  }

  .map-wrap {
    height: 100vh;
    height: 100dvh;
  }

  .panel {
    --sheet-peek: 214px;
    position: absolute;
    top: 16vh;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1000;
    height: auto;
    max-height: none;
    border-left: 0;
    border-top: 1px solid var(--line);
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.16);
    background: #fff;
    transition: height 0.2s ease, top 0.2s ease;
    transform: none;
    overflow-y: auto;
    overscroll-behavior-y: contain;
  }

  .panel.is-collapsed {
    top: auto;
    height: var(--sheet-peek);
    max-height: var(--sheet-peek);
    overflow: hidden;
  }

  .panel.is-collapsed .disclaimer,
  .panel.is-collapsed .controls,
  .panel.is-collapsed .meta-row,
  .panel.is-collapsed .map-toggle,
  .panel.is-collapsed .results,
  .panel.is-collapsed .nearby > .secondary-button,
  .panel.is-collapsed .nearby > #clearLocationBtn,
  .panel.is-collapsed .nearby > .muted {
    display: none;
  }

  .panel.is-collapsed .panel-header {
    display: flex;
  }

  .panel.is-collapsed .nearby form {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .sheet-handle {
    display: block;
    width: 40px;
    height: 5px;
    background: #d7dbe0;
    border-radius: 3px;
    margin: 0 auto 12px;
    cursor: grab;
    flex-shrink: 0;
  }

  .map-toggle {
    display: none;
  }

  .legend {
    bottom: 214px;
    min-width: auto;
  }

  body.sheet-open .legend {
    display: none;
  }

  .legend-toggle {
    display: flex;
  }
}

@media (max-width: 560px) {
  .panel {
    padding: 14px;
  }

  .panel-header {
    align-items: stretch;
  }

  .nearby form,
  .filter-grid {
    grid-template-columns: 1fr;
  }

  .meta-row {
    display: grid;
  }
}
