/* ==========================================================
   Map page (map.html) — a basic WebGIS on MapLibre GL JS.
   Floating panels sit on top of the map; MapLibre's own controls and
   popups are restyled with the template tokens so they follow the theme.
   ========================================================== */

.gis-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.gis-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.gis-stat {
  display: flex; flex-direction: column; gap: 1px; min-width: 104px;
  padding: 7px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.gis-stat small { font-size: 11px; color: var(--text-3); }
.gis-stat strong { font-size: 16px; font-weight: 600; letter-spacing: -.01em; }

/* The map card fills the rest of the viewport (header, topbar and top menu excluded) */
.gis {
  position: relative; padding: 0; overflow: hidden;
  height: calc(100dvh - 52px - var(--hnav-h) - 150px); min-height: 520px;
  background: var(--surface-2);
}
.gis-map { position: absolute; inset: 0; }
.gis:fullscreen { height: 100vh; border-radius: 0; }

/* ---------- floating chrome ---------- */
.gis-float {
  position: absolute; z-index: 3;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg);
}

.gis-search { top: 12px; left: 12px; width: min(320px, calc(100% - 24px)); }
.gis-search .search { height: 38px; border: 0; border-radius: 10px; }
.gis-search .search:focus-within { box-shadow: none; }
.gis-results { list-style: none; margin: 0; padding: 4px; border-top: 1px solid var(--border); max-height: 280px; overflow-y: auto; }
.gis-results[hidden] { display: none; }
.gis-results li button {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 6px; text-align: left;
}
.gis-results li button:hover, .gis-results li button.focus { background: var(--surface-2); }
.gis-results .lucide { width: 15px; height: 15px; color: var(--text-3); flex-shrink: 0; }
.gis-results span { flex: 1; min-width: 0; }
.gis-results b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gis-results small { color: var(--text-3); font-size: 11.5px; }
.gis-results .empty { padding: 10px; color: var(--text-3); font-size: 12px; }

.gis-tools { top: 62px; left: 12px; display: flex; flex-direction: column; padding: 4px; gap: 2px; }
.gis-tools .icon-btn { border: 0; }
.gis-tools .icon-btn.on { background: var(--primary); color: var(--primary-fg); }
.gis-tools hr { width: 20px; margin: 2px auto; border: 0; border-top: 1px solid var(--border); }

.gis-panel {
  top: 12px; right: 56px; bottom: 44px; width: 300px;
  display: flex; flex-direction: column; overflow: hidden;
  transition: transform .25s var(--ease), opacity .2s;
}
.gis-panel.closed { transform: translateX(calc(100% + 70px)); opacity: 0; pointer-events: none; }
.gis-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 0 14px; }
.gis-panel-head h3 { font-size: 13px; font-weight: 600; }
.gis-panel .tabs { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.gis-panel .tab-list { padding: 0 10px; }
.gis-panel .tab-panel { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 14px 14px; color: var(--text); }
.gis-panel .tab-panel.active { display: flex; flex-direction: column; gap: 12px; }

/* layers */
.layer { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.layer:last-child { border-bottom: 0; padding-bottom: 0; }
.layer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.layer-head .switch { font-weight: 500; }
.layer-head small { color: var(--text-3); font-size: 11.5px; }
.layer-opacity { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--text-3); }
.layer-opacity input { flex: 1; }
.layer.off .legend, .layer.off .layer-opacity { opacity: .4; pointer-events: none; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-2); }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend .sw { width: 12px; height: 12px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--border); }
.legend .sw.area { border-radius: 3px; background: color-mix(in srgb, var(--c) 18%, transparent); box-shadow: inset 0 0 0 1.5px var(--c); }
.legend .lucide { width: 13px; height: 13px; }
.legend .ramp { flex: 1; height: 8px; border-radius: 99px; background: linear-gradient(90deg, transparent, var(--seq-200), var(--seq-350), var(--seq-450), var(--seq-550), var(--seq-650)); }

/* basemaps */
.basemaps { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.basemap {
  display: flex; flex-direction: column; gap: 6px; padding: 5px;
  border: 1px solid var(--border); border-radius: 10px; font-size: 12px; font-weight: 500; color: var(--text-2); text-align: left;
  transition: border-color .15s, box-shadow .15s;
}
.basemap:hover { border-color: var(--border-hover); color: var(--text); }
.basemap.active { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); color: var(--text); }
.basemap img, .basemap .auto { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 6px; background: var(--surface-3); }
.basemap .auto { display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; }
.basemap .auto img { aspect-ratio: auto; height: 100%; border-radius: 0; }
.basemap span { padding: 0 3px 2px; }

/* data list */
.gis-filter { display: flex; gap: 4px; flex-wrap: wrap; }
.gis-list { list-style: none; margin: 0 -6px; padding: 0; }
.gis-list li button {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 8px 6px; border-radius: 8px; text-align: left; transition: background .12s;
}
.gis-list li button:hover { background: var(--surface-2); }
.gis-list .dotc { width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex-shrink: 0; }
.gis-list span { flex: 1; min-width: 0; }
.gis-list b { display: block; font-weight: 500; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gis-list small { color: var(--text-3); font-size: 11.5px; }
.gis-list strong { font-size: 12.5px; font-variant-numeric: tabular-nums; }
.gis-count { font-size: 11.5px; color: var(--text-3); }

.gis-status {
  bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; height: 28px; padding: 0 10px;
  font-size: 11.5px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.gis-status .sep { width: 1px; height: 12px; background: var(--border); }

.gis-measure {
  top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px;
  background: var(--ink); color: var(--ink-fg); border-color: var(--ink);
}
.gis-measure[hidden] { display: none; }
.gis-measure strong { font-size: 14px; font-variant-numeric: tabular-nums; }
.gis-measure small { color: rgba(255, 255, 255, .6); font-size: 11.5px; }
.gis-measure .icon-btn { background: transparent; color: rgba(255, 255, 255, .7); }
.gis-measure .icon-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }

/* ---------- MapLibre controls & popups, themed ---------- */
.gis .maplibregl-ctrl-group { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); overflow: hidden; }
.gis .maplibregl-ctrl-group button + button { border-top-color: var(--border); }
.gis .maplibregl-ctrl-group button:not(:disabled):hover { background: var(--surface-2); }
[data-theme="dark"] .gis .maplibregl-ctrl-icon { filter: invert(1) hue-rotate(180deg); }
.gis .maplibregl-ctrl-scale { background: color-mix(in srgb, var(--surface) 80%, transparent); border-color: var(--text-3); color: var(--text-2); font-size: 10.5px; }
.gis .maplibregl-ctrl-attrib { background: color-mix(in srgb, var(--surface) 80%, transparent); color: var(--text-3); font-size: 10.5px; }
.gis .maplibregl-ctrl-attrib a { color: var(--text-2); }
[data-theme="dark"] .gis .maplibregl-ctrl-attrib-button { filter: invert(1); }
.gis .maplibregl-ctrl-top-right { top: 2px; right: 2px; }

.gis .maplibregl-popup-content {
  padding: 12px 14px; min-width: 210px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-lg); font: 12.5px/1.45 var(--font);
}
.gis .maplibregl-popup-anchor-bottom .maplibregl-popup-tip, .gis .maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip, .gis .maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip { border-top-color: var(--surface); }
.gis .maplibregl-popup-anchor-top .maplibregl-popup-tip, .gis .maplibregl-popup-anchor-top-left .maplibregl-popup-tip, .gis .maplibregl-popup-anchor-top-right .maplibregl-popup-tip { border-bottom-color: var(--surface); }
.gis .maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--surface); }
.gis .maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--surface); }
.gis .maplibregl-popup-close-button { width: 24px; height: 24px; top: 6px; right: 6px; border-radius: 6px; font-size: 16px; color: var(--text-3); }
.gis .maplibregl-popup-close-button:hover { background: var(--surface-2); color: var(--text); }
.pop-title { padding-right: 20px; font-weight: 600; font-size: 13px; }
.pop-sub { color: var(--text-3); font-size: 11.5px; margin-bottom: 8px; }
.pop-rows { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; }
.pop-rows dt { color: var(--text-3); }
.pop-rows dd { margin: 0; text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; }
.pop-status { display: inline-flex; align-items: center; gap: 5px; }
.pop-status .lucide { width: 13px; height: 13px; }

@media (max-width: 760px) {
  .gis { height: calc(100dvh - 52px - 190px); min-height: 460px; }
  .gis-panel { top: auto; left: 12px; right: 12px; bottom: 50px; width: auto; height: 55%; }
  .gis-panel.closed { transform: translateY(calc(100% + 60px)); }
  .gis-status .coords { display: none; }
  .gis-stat { min-width: 0; flex: 1; }
}
