:root {
  --bg: #0f1419;
  --panel: #161c24;
  --panel-2: #1d2630;
  --line: #2a333f;
  --text: #e6edf3;
  --muted: #8a97a6;
  --accent: #4ea1ff;
  --idea: #8a97a6;
  --scouting: #f0a93b;
  --confirmed: #4ea1ff;
  --shot: #46c98b;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); overflow: hidden;
}
#app { display: flex; height: 100vh; position: relative; }

/* Sidebar */
#sidebar {
  width: 340px; flex: 0 0 340px; background: var(--panel);
  border-right: 1px solid var(--line); display: flex; flex-direction: column; z-index: 500;
}
.side-head { padding: 16px 16px 10px; border-bottom: 1px solid var(--line); }
.side-head h1 { font-size: 18px; margin: 0; letter-spacing: -0.2px; }
.side-head h1 span { color: var(--accent); font-weight: 600; }
.tagline { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.project-bar { display: flex; gap: 8px; margin-top: 10px; }
.project-bar select { flex: 1; font-weight: 600; }

.controls { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.controls .row { display: flex; gap: 8px; }
input, select, textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 13px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }

.stats { padding: 4px 14px 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.pill { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.pill b { color: var(--text); }

.list { flex: 1; overflow-y: auto; padding: 4px 10px 10px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 30px 16px; line-height: 1.5; }

.card {
  background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--idea);
  border-radius: 8px; padding: 9px 11px; margin: 7px 0; cursor: pointer; transition: border-color .15s, transform .05s;
}
.card:hover { border-color: var(--accent); }
.card:active { transform: scale(0.995); }
.card.s-scouting { border-left-color: var(--scouting); }
.card.s-confirmed { border-left-color: var(--confirmed); }
.card.s-shot { border-left-color: var(--shot); }
.card .t { font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card .meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card .chips { margin-top: 5px; display: flex; gap: 5px; flex-wrap: wrap; }
.chip { font-size: 10px; color: var(--muted); background: #131a22; border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; }
.badge { font-size: 10px; text-transform: uppercase; letter-spacing: .4px; padding: 2px 6px; border-radius: 5px; color: #0c1117; font-weight: 700; flex: 0 0 auto; }
.badge.idea { background: var(--idea); } .badge.scouting { background: var(--scouting); }
.badge.confirmed { background: var(--confirmed); } .badge.shot { background: var(--shot); }
.card .del { margin-left: auto; color: var(--muted); font-size: 12px; background: none; border: none;
  cursor: pointer; padding: 2px 6px; line-height: 1; border-radius: 5px; font-family: inherit; }
.card .del:hover { color: #ff6b6b; }

/* Visible keyboard focus (a11y) — keep outlines for keyboard users even though inputs drop them on mouse focus */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.card:focus-visible { outline-offset: -2px; }

.side-foot {
  border-top: 1px solid var(--line); padding: 10px 14px; display: flex;
  align-items: center; justify-content: space-between; gap: 8px;
}
.foot-actions { display: flex; gap: 6px; }
.foot-actions .btn { flex: 0 0 auto; }
.count { font-size: 12px; color: var(--muted); }

.btn { border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 7px; padding: 7px 11px; font-size: 12.5px; cursor: pointer; font-family: inherit; flex: 1; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0c1117; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger:hover { border-color: #ff6b6b; color: #ff6b6b; }
.icon-btn { width: 36px; flex: 0 0 36px; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); border-radius: 7px; cursor: pointer; font-size: 15px; }
.icon-btn:hover { border-color: var(--accent); }

#map { flex: 1; height: 100%; background: #0b0e12; }

/* Slide-over panels (detail + planner) */
.panel {
  position: absolute; top: 0; right: 0; height: 100%; width: 360px; max-width: 92vw;
  background: var(--panel); border-left: 1px solid var(--line); z-index: 1000;
  display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0,0,0,.45);
}
.panel[hidden] { display: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-head strong { font-size: 15px; }
.panel-body { flex: 1; overflow-y: auto; padding: 14px 16px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .4px; }
.field .row2 { display: flex; gap: 8px; }
.subhead { font-size: 12px; font-weight: 700; color: var(--text); margin: 16px 0 8px;
  display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 12px; }
.subhead button { font-size: 11px; padding: 3px 8px; flex: 0 0 auto; }
.subhead-btns { display: flex; gap: 6px; }
.photo-grid img { cursor: pointer; }
.photo-grid img:hover { border-color: var(--accent); }

.repeat-row { display: flex; gap: 6px; align-items: flex-start; margin-bottom: 6px; }
.repeat-row input, .repeat-row select { font-size: 12px; padding: 6px 8px; }
.repeat-row .rm { flex: 0 0 26px; width: 26px; background: transparent; border: 1px solid var(--line);
  color: var(--muted); border-radius: 6px; cursor: pointer; align-self: stretch; }
.repeat-row .rm:hover { color: #ff6b6b; border-color: #ff6b6b; }
.photo-grid { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.photo-grid img { width: 70px; height: 52px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.panel-actions { display: flex; gap: 8px; position: sticky; bottom: 0; z-index: 2;
  margin: 18px -16px 0; padding: 12px 16px; background: var(--panel); border-top: 1px solid var(--line); }

.ext-link { display: inline-block; font-size: 12.5px; color: var(--accent); text-decoration: none; margin: -6px 0 14px; }
.ext-link:hover { text-decoration: underline; }
.empty-mini { color: var(--muted); font-size: 12px; font-style: italic; margin-bottom: 6px; }
.dist { color: var(--accent); font-weight: 600; }
.plan-item { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.plan-item .pm { color: var(--muted); font-size: 11.5px; margin-top: 2px; }

/* Leaflet popup */
.leaflet-popup-content-wrapper { background: var(--panel); color: var(--text); border-radius: 10px; }
.leaflet-popup-tip { background: var(--panel); }
.pop { font-size: 13px; min-width: 170px; }
.pop h3 { margin: 0 0 4px; font-size: 15px; }
.pop .meta { color: var(--muted); font-size: 11.5px; margin-bottom: 6px; }
.pop .actions { display: flex; gap: 7px; margin-top: 8px; }
.hood-label { background: none; border: none; box-shadow: none; pointer-events: none; }
/* only the visible (translated) inner span is clickable, so empty map clicks pass through to drop pins */
.hood-label .hl-in { pointer-events: auto; display: inline-block; transform: translate(-50%, -50%); white-space: nowrap;
  color: #cdd9e5; font-size: 11px; font-weight: 600; text-shadow: 0 1px 3px #000, 0 0 2px #000;
  cursor: pointer; padding: 3px 5px; }
.hood-label .hl-in:hover { color: #4ea1ff; }
/* On satellite, a strong dark halo keeps labels legible over bright imagery (#15) */
.sat-on .hood-label .hl-in { color: #fff;
  text-shadow: -1px -1px 2px #000, 1px -1px 2px #000, -1px 1px 2px #000, 1px 1px 2px #000, 0 0 6px #000; }

.mobile-only { display: none; }

/* Map view toggles (explore + satellite) — stacked bottom-right */
#explore-toggle, #sat-toggle {
  position: absolute; right: 10px; z-index: 600;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 7px 12px; font-size: 13px; cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,.45); font-family: inherit;
}
#explore-toggle { bottom: 50px; }
#sat-toggle { bottom: 90px; }
#explore-toggle:hover, #sat-toggle:hover { border-color: var(--accent); }
#explore-toggle.active, #sat-toggle.active { background: var(--accent); border-color: var(--accent); color: #0c1117; font-weight: 600; }

/* #4 — on-map "Explore mode" pill: a visible mode signal that works on touch (no hover, no cursor) */
#mode-pill {
  position: absolute; right: 10px; bottom: 130px; z-index: 600;
  background: var(--accent); color: #0c1117; font-weight: 600; font-size: 12px;
  padding: 6px 12px; border-radius: 999px; box-shadow: 0 2px 10px rgba(0,0,0,.45);
  pointer-events: none; white-space: nowrap;
}
#mode-pill[hidden] { display: none; }

/* Place search — floating top-right over the map */
#place-search { position: absolute; top: 10px; right: 10px; z-index: 600; width: 270px; max-width: calc(100% - 20px); }
#place-search input { box-shadow: 0 2px 10px rgba(0,0,0,.45); }

/* Persistent scope labels above the two search boxes (so the scope stays clear once you type) */
.search-label { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 4px; }
#place-search .search-label { text-shadow: 0 1px 3px var(--bg), 0 0 2px var(--bg); } /* floats over the map */
#place-results { list-style: none; margin: 5px 0 0; padding: 4px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.5);
  max-height: 280px; overflow-y: auto; }
#place-results[hidden] { display: none; }
#place-results li { padding: 7px 9px; font-size: 12.5px; border-radius: 6px; cursor: pointer; color: var(--text); line-height: 1.3; }
#place-results li:hover { background: var(--panel-2); }
#place-results li small { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; }
#place-results .pr-empty { color: var(--muted); font-style: italic; cursor: default; }
#place-results .pr-empty:hover { background: none; }

/* Nearby quick-pick chips in the editor */
.nearby-chips { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin: -4px 0 12px; }
.nearby-chips:empty { display: none; }
.nearby-label, .nearby-loading { font-size: 11px; color: var(--muted); }
.nearby-loading { font-style: italic; }
.nearby-chip { font-size: 11.5px; padding: 3px 9px; background: var(--panel-2);
  border: 1px solid var(--line); color: var(--text); border-radius: 999px; cursor: pointer; }
.nearby-chip:hover { border-color: var(--accent); color: var(--accent); }

/* Wikipedia block inside the explore popup */
.info-pop-wiki-block { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }

/* Info popup content (neighbourhood blurb + Wikipedia) */
.info-pop { font-size: 13px; }
.info-pop-name { font-weight: 700; font-size: 15px; margin-bottom: 6px; }
.info-pop-text { color: var(--muted); line-height: 1.55; margin: 0 0 8px; }
.info-pop-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid var(--line); padding-top: 7px; flex-wrap: wrap; }
.info-pop-count { font-size: 11.5px; color: var(--muted); }
.info-pop-wiki { font-size: 12px; color: var(--accent); text-decoration: none; }
.info-pop-wiki:hover { text-decoration: underline; }
.info-pop-near { font-size: 11px; color: var(--muted); flex-basis: 100%; }
.info-pop-add { font-size: 11.5px !important; padding: 3px 9px !important; flex: none !important; }

/* Mobile / field layout */
@media (max-width: 720px) {
  #app { flex-direction: column; }
  #map { order: -1; height: 55vh; flex: none; }
  #sidebar { width: 100%; flex: 1; border-right: none; border-top: 1px solid var(--line); }
  #sidebar.collapsed { position: absolute; bottom: 0; left: 0; right: 0; height: 0; overflow: hidden; }
  .panel { width: 100%; max-width: 100%; }
  .mobile-only { display: block; position: absolute; right: 10px; bottom: 10px; z-index: 600;
    flex: none; width: auto; }

  /* #9 — touch targets ≥44px on mobile (Apple HIG) */
  .btn, .icon-btn, select, input, .nearby-chip,
  #sat-toggle, #explore-toggle, #sidebar-toggle { min-height: 44px; }
  .icon-btn { width: 44px; flex-basis: 44px; }
  .repeat-row .rm { min-height: 44px; min-width: 40px; }
  .card .del { min-width: 44px; min-height: 44px; padding: 0; margin: -8px -6px -8px auto;
    display: inline-flex; align-items: center; justify-content: center; font-size: 15px; }

  /* #1 — dock the map controls into the map band (map is the top 55vh; place them bottom-left, clear of zoom/search/attribution) */
  #explore-toggle, #sat-toggle { right: auto; left: 10px; }
  #explore-toggle { bottom: calc(45vh + 10px); }
  #sat-toggle { bottom: calc(45vh + 62px); }
  #mode-pill { right: auto; left: 10px; bottom: calc(45vh + 114px); }
}
