* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { display: flex; }

#sidebar {
  width: 320px; min-width: 320px; height: 100vh; overflow-y: auto;
  background: #f7f9f5; border-right: 1px solid #d8e0d2; padding: 16px;
}
#map { flex: 1; height: 100vh; }

h1 { margin: 0 0 2px; font-size: 22px; color: #1d3520; }
.subtitle { margin: 0 0 14px; font-size: 12px; color: #6a7a66; }
.subtitle a { color: #2e5d31; text-decoration: none; font-weight: 600; }
.subtitle a:hover { text-decoration: underline; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: #41523e; margin: 0 0 8px; }

.controls { margin-bottom: 14px; position: relative; }
#search {
  width: 100%; padding: 9px 10px; border: 1px solid #c4d0bd; border-radius: 8px;
  font-size: 14px; background: #fff;
}
#search:focus { outline: 2px solid #5b8c5a; border-color: transparent; }
#suggestions {
  position: absolute; top: 40px; left: 0; right: 0; z-index: 10;
  background: #fff; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.15);
  max-height: 260px; overflow-y: auto;
}
#suggestions div { padding: 7px 10px; font-size: 13px; cursor: pointer; }
#suggestions div:hover { background: #eef4ea; }
#suggestions .count { color: #8b9b86; font-size: 11px; float: right; }

.filter-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
#active-filter {
  background: #2e5d31; color: #fff; font-size: 12px; padding: 3px 10px; border-radius: 99px;
}
button {
  border: 1px solid #c4d0bd; background: #fff; border-radius: 8px; padding: 7px 10px;
  font-size: 13px; cursor: pointer; color: #2c3e2a;
}
button:hover { background: #eef4ea; }
#rare-toggle { margin-top: 8px; width: 100%; }
#rare-toggle.arming { background: #6a3d9a; color: #fff; border-color: #6a3d9a; }
#locate-me { margin-top: 8px; width: 100%; }
#set-home { margin-top: 8px; width: 100%; }
#set-home.arming { background: #2e5d31; color: #fff; }
.locate-status { margin-top: 6px; font-size: 12px; color: #8b9b86; }
.locate-status.error { color: #b3541e; }

.panel { background: #fff; border: 1px solid #e0e7da; border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.hidden { display: none !important; }

#stats-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 12px; }
#stats-table th { text-align: left; color: #8b9b86; font-weight: 500; padding: 2px 4px; }
#stats-table td { padding: 3px 4px; border-top: 1px solid #f0f3ec; }
#stats-table td.num { text-align: right; white-space: nowrap; }
.over { color: #b3541e; font-weight: 600; }

ol { margin: 0; padding-left: 18px; font-size: 12.5px; }
ol li { margin-bottom: 5px; cursor: pointer; }
ol li:hover { text-decoration: underline; }
ol li.empty { color: #8b9b86; cursor: default; list-style: none; margin-left: -18px; }
ol li.empty:hover { text-decoration: none; }
.dist { color: #8b9b86; }

#legend-items { display: flex; flex-wrap: wrap; gap: 6px; }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: #41523e; }
.legend-dot { width: 11px; height: 11px; border-radius: 50%; border: 1px solid rgba(0,0,0,.2); }

.maplibregl-popup-content { font-family: inherit; font-size: 13px; line-height: 1.45; min-width: 200px; }
.popup-title { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.popup-latin { font-style: italic; color: #5b6e57; margin-bottom: 6px; }
.popup-row { color: #333; }
.popup-row b { color: #777; font-weight: 500; }

/* ---------- mobile: map fills the screen, sidebar becomes a bottom sheet ---------- */
@media (max-width: 760px) {
  html, body { height: 100%; }
  body { display: block; }

  #map {
    position: fixed; inset: 0; height: 100%; width: 100%;
  }

  #sidebar {
    position: fixed; left: 0; right: 0; bottom: 0;
    width: auto; min-width: 0; height: auto; max-height: 52vh;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    background: rgba(247, 249, 245, 0.97);
    backdrop-filter: blur(6px);
    border-right: none; border-top: 1px solid #d4ddcd;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.18);
    padding: 8px 16px 18px;
    z-index: 5;
  }
  /* grabber handle to signal the sheet scrolls */
  #sidebar::before {
    content: ""; display: block; width: 40px; height: 4px; border-radius: 2px;
    background: #c4d0bd; margin: 2px auto 10px;
  }

  h1 { font-size: 19px; }
  .subtitle { margin-bottom: 10px; }

  /* full-size tap targets on touch */
  button { padding: 11px 12px; font-size: 14px; }
  #search { padding: 12px; font-size: 16px; } /* 16px avoids iOS/Brave zoom-on-focus */
  #suggestions div { padding: 11px 12px; font-size: 14px; }

  /* keep MapLibre's zoom controls clear of the sheet */
  .maplibregl-ctrl-bottom-right { bottom: 54vh; }
}
