:root {
  --bg: #0d0f13;
  --panel: #171a21;
  --panel-2: #1f242e;
  --text: #e8eaed;
  --muted: #9aa3b2;
  --line: #2a2f3a;
  --sheet-h: 42vh;
  --green: #00c875;
  --amber: #fdab3d;
  --red: #e2445c;
  --grey: #8a93a3;
  --accent: #579bfc;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 Helvetica, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}

#map {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  /* Explicit height: Google Maps overrides our `position` with `relative` on
     init, which kills any height derived from top/bottom edge-stretching. */
  height: calc(100% - var(--sheet-h));
  background: var(--bg);
}

/* Google Maps InfoWindow — drag it into the dark theme */
.gm-style .gm-style-iw-c { background: var(--panel-2) !important; box-shadow: 0 2px 12px rgba(0,0,0,0.5) !important; padding: 0 !important; border-radius: 12px !important; }
.gm-style .gm-style-iw-d { overflow: hidden !important; background: var(--panel-2); }
.gm-style .gm-style-iw-tc::after { background: var(--panel-2) !important; }
.gm-style .gm-ui-hover-effect span { background-color: var(--muted) !important; }
.iw { padding: 12px 14px; }

#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  padding: max(8px, env(safe-area-inset-top)) 14px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(var(--bg), transparent);
  z-index: 600;
  pointer-events: none;
}
.logo { height: 22px; width: auto; display: block; }
.status { font-size: 12px; color: var(--muted); }

#recenter {
  position: fixed;
  right: 14px;
  bottom: calc(var(--sheet-h) + 14px);
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--accent);
  font-size: 22px;
  z-index: 600;
}

#sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--sheet-h);
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  z-index: 600;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
#sheet-handle {
  position: relative;
  width: 100%;
  height: 24px;
  margin: 0;
  flex: none;
  cursor: grab;
  touch-action: none; /* let the drag handler own vertical gestures */
}
#sheet-handle::before {
  content: "";
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  width: 40px; height: 4px;
  background: var(--line);
  border-radius: 2px;
}
#sheet-handle:active { cursor: grabbing; }

#sheet { overflow: hidden; }
#sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 12px 10px;
  border-bottom: 1px solid var(--line);
  flex: none;
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
}
.search-wrap { position: relative; flex: 1 1 100%; }
.search-wrap input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 34px 10px 12px;
  font-size: 14px;
}
.search-wrap input::placeholder { color: var(--muted); }
#search-clear {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  width: 26px; height: 26px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

#use-location {
  flex: 1 1 100%;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--accent);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
}
#use-location:disabled { color: var(--muted); }

.controls select, .segmented {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  font-size: 13px;
}
.controls select { padding: 8px 10px; flex: 1 1 120px; }
.segmented { display: flex; overflow: hidden; flex: 1 1 100%; }
.segmented button {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 8px 6px;
  font-size: 13px;
}
.segmented button.active { background: var(--accent); color: #06223f; font-weight: 600; }

.radius { flex: 1 1 100%; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.radius input { flex: 1; accent-color: var(--accent); }

.layers { display: flex; gap: 16px; font-size: 13px; flex: 1 1 100%; }
.layers label { display: flex; align-items: center; gap: 6px; }
.layers .disabled { color: var(--muted); opacity: 0.6; }

/* Selected-account detail card — sits under the layer checkboxes. */
.detail {
  position: relative;
  margin: 0 12px 10px;
  padding: 12px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  flex: none;
}
#detail-close {
  position: absolute;
  top: 6px; right: 8px;
  width: 26px; height: 26px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}
.d-head { display: flex; align-items: center; gap: 8px; padding-right: 26px; }
.d-head .dot { margin-top: 0; }
.d-name { font-weight: 700; font-size: 15px; }
.detail .chip { margin: 6px 0 4px; }
.d-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 12px;
  margin: 6px 0 4px;
  font-size: 13px;
}
.d-k { color: var(--muted); }
.d-v { color: var(--text); }
.d-v a { color: var(--accent); text-decoration: none; }
.detail .dir { font-size: 13px; }

.meta { padding: 8px 12px; font-size: 11.5px; color: var(--muted); border-bottom: 1px solid var(--line); flex: none; }

.list { list-style: none; margin: 0; padding: 4px 0 12px; }
.row { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 4px; flex: none; }
.dot.green { background: var(--green); }
.dot.amber { background: var(--amber); }
.dot.red { background: var(--red); }
.dot.grey { background: var(--grey); }
.row-main { flex: 1; min-width: 0; }
.row-name { font-weight: 600; }
.row-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; margin-top: 5px; border: 1px solid var(--line); }
.chip.green { color: var(--green); }
.chip.amber { color: var(--amber); }
.chip.red { color: var(--red); }
.chip.grey { color: var(--grey); }
.row-dist { font-size: 12px; color: var(--muted); white-space: nowrap; }
.overdue { color: var(--red); font-weight: 600; }
.dir { display: inline-block; margin-top: 6px; color: var(--accent); font-size: 12px; text-decoration: none; }

.popup-name { font-weight: 700; margin-bottom: 4px; }
.popup-line { font-size: 12px; color: var(--muted); }
.popup .dir { font-size: 13px; }
