/* Layout: full-bleed map, one floating tool panel (top-left on desktop, bottom sheet on phones). */
:root {
  --bg: #eef1ef;
  --surface: #ffffff;
  --fg: #1b1f1d;
  --muted: #5b6560;
  --line: #d7ddda;
  --accent: #f0a000;
  --accent-ink: #1b1f1d;
  --warn-bg: #fdecea;
  --warn-fg: #9b2016;
  --shadow: 0 6px 24px rgba(20, 30, 25, 0.18);

  --font-body: "Barlow", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-label: "Barlow Semi Condensed", "Barlow", "Arial Narrow", system-ui, sans-serif;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111413;
    --surface: #1a1e1c;
    --fg: #e6ebe8;
    --muted: #98a39e;
    --line: #2f3633;
    --accent: #f5a800;
    --accent-ink: #141716;
    --warn-bg: #3a1714;
    --warn-fg: #ffb4ab;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.4;
}

#map {
  position: fixed;
  inset: 0;
  background: var(--bg);
}

#map.is-drawing { cursor: crosshair; }
#map.is-drawing .leaflet-interactive { cursor: pointer; }

/* ---------- Dock: search on top, tools below (desktop) ---------- */
.dock {
  position: fixed;
  z-index: 1000;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: calc(12px + env(safe-area-inset-left, 0px));
  width: 300px;
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---------- Search ---------- */
.search {
  margin: 0;
  flex: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.search-row {
  display: flex;
  align-items: center;
}

.search input {
  flex: 1;
  min-width: 0;
  font: 400 15px/1.2 var(--font-body);
  color: var(--fg);
  background: transparent;
  border: 0;
  padding: 12px 14px;
}

.search input::placeholder { color: var(--muted); }
.search input:focus-visible { outline: none; }
.search:focus-within { border-color: var(--accent); }

.search-go {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: var(--muted);
  background: transparent;
  border: 0;
  cursor: pointer;
}

.search-go:hover { color: var(--fg); }

.search-out {
  border-top: 1px solid var(--line);
  max-height: 260px;
  overflow-y: auto;
}

.search-status {
  margin: 0;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 13.5px;
}

.search-status:empty { display: none; }

.search-results {
  list-style: none;
  margin: 0;
  padding: 0;
}

.search-results button {
  display: block;
  width: 100%;
  text-align: left;
  font: 400 14px/1.35 var(--font-body);
  color: var(--fg);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 9px 14px;
  cursor: pointer;
}

.search-results li:last-child button { border-bottom: 0; }
.search-results button:hover,
.search-results button:focus-visible { background: var(--bg); outline: none; }

.search-results .r-main { display: block; font-weight: 600; }
.search-results .r-sub { display: block; color: var(--muted); font-size: 12.5px; }

.search-credit {
  margin: 0;
  padding: 7px 14px 9px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
}

.search-credit a { color: inherit; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  z-index: 1100;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  max-width: min(420px, calc(100% - 32px));
  margin: 0;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--fg);
  color: var(--surface);
  font-size: 14px;
  box-shadow: var(--shadow);
}

/* ---------- Locate control ---------- */
.locate-btn {
  display: grid !important;
  place-items: center;
  color: #333;
  cursor: pointer;
}

.locate-btn svg { display: block; }
.locate-btn.is-busy svg { opacity: 0.4; }

/* ---------- Panel ---------- */
.panel {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.panel-head h1 {
  margin: 0;
  font-family: var(--font-label);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: 0.01em;
  text-wrap: balance;
}

.panel-head .sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

/* Segmented layer switch */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  gap: 3px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.seg button {
  font: 500 14px/1 var(--font-body);
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 9px 8px;
  cursor: pointer;
}

.seg button[aria-checked="true"] {
  color: var(--fg);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* Buttons */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  font: 500 14px/1 var(--font-body);
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 14px;
  cursor: pointer;
}

.btn:hover:not(:disabled) { border-color: var(--muted); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.06); border-color: var(--accent); }

.btn-quiet { background: transparent; }

.btn-wide { width: 100%; }

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
}

.hint kbd {
  font: 500 12px/1 var(--font-body);
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--fg);
}

/* Stats */
.stats {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.stats-label {
  margin: 0 0 8px;
  font-family: var(--font-label);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.stats dl {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}

.stats dt {
  font-size: 12.5px;
  color: var(--muted);
}

.stats dd {
  margin: 1px 0 0;
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.warn {
  margin: 0;
  padding: 9px 11px;
  border-radius: 7px;
  background: var(--warn-bg);
  color: var(--warn-fg);
  font-size: 13.5px;
}

/* Export */
.export {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.export label {
  font-size: 12.5px;
  color: var(--muted);
}

.export-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.export input {
  font: 400 15px/1.2 var(--font-body);
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  width: 100%;
  min-width: 0;
}

/* Import: choose one polygon from a file that holds several */
.pick {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.pick .stats-label { margin: 0; }

.pick-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.pick-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.pick-list button {
  display: block;
  width: 100%;
  text-align: left;
  font: 400 14px/1.35 var(--font-body);
  color: var(--fg);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 8px 11px;
  cursor: pointer;
}

.pick-list li:last-child button { border-bottom: 0; }
.pick-list button:hover,
.pick-list button:focus-visible { background: var(--bg); outline: none; }

.pick-list .r-main { display: block; font-weight: 600; overflow-wrap: anywhere; }
.pick-list .r-sub { display: block; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }

.pick .btn { align-self: flex-start; }

/* ---------- Map overlays ---------- */
.vtx {
  /* 22px hit area, 12px visible dot */
  background: transparent;
}

.vtx::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #f0a000;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
}

.vtx.vtx-first.can-close::after {
  inset: 2px;
  background: #f0a000;
  border-color: #ffffff;
}

.mid {
  background: transparent;
}

.mid::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  border: 1.5px solid #f0a000;
}

.edge-label {
  background: transparent;
  border: 0;
  pointer-events: none !important;
}

.edge-label span {
  position: absolute;
  left: 0;
  top: 0;
  white-space: nowrap;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(20, 24, 22, 0.82);
  color: #ffffff;
  font: 600 12px/1.2 var(--font-body);
  font-variant-numeric: tabular-nums;
}

.leaflet-container {
  font-family: var(--font-body);
}

/* ---------- Phones: bottom sheet ---------- */
@media (max-width: 640px) {
  .dock { display: contents; }

  .search {
    position: fixed;
    z-index: 1000;
    top: calc(10px + env(safe-area-inset-top, 0px));
    left: max(12px, env(safe-area-inset-left, 0px));
    right: calc(60px + env(safe-area-inset-right, 0px));
  }

  .search-out { max-height: 40vh; }

  .toast { bottom: calc(var(--sheet-h, 0px) + 12px); }

  .panel {
    position: fixed;
    z-index: 1000;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 55%;
    gap: 10px;
    padding-top: 12px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
    border-radius: 14px 14px 0 0;
    border-width: 1px 0 0;
  }

  .panel-head { display: none; }
  .hint { font-size: 13px; }

  .stats { padding-top: 8px; }
  .stats-label { margin-bottom: 4px; }
  .stats dl { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px 8px; }
  .stats dd { font-size: 14px; }

  .pick { padding-top: 8px; }
  .pick-list { max-height: 30vh; }

  .export { padding-top: 8px; }
  .export label { display: none; }
  .export-row { flex-direction: row; gap: 8px; }
  .export-row .btn { flex: none; }

  .leaflet-bottom { bottom: var(--sheet-h, 0px); }
}

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