:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #14212b;
  --muted: #5b6b78;
  --line: #d9e0e6;
  --brand: #0b3d5c;
  --brand-ink: #ffffff;
  --active: #1e8e3e;
  --obs: #d98c00;
  --plugged: #8a949c;
  --sheet-h: 70vh;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { display: flex; flex-direction: column; min-height: 100dvh; }

.topbar { display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; z-index: 20; }
.topbar h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn { background: transparent; border: 0; color: inherit; font-size: 22px; width: 44px; height: 44px; border-radius: 22px; cursor: pointer; }
.iconbtn:active { background: rgba(255,255,255,.15); }

.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.view[hidden] { display: none; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px 14px; min-height: 110px;
  display: flex; flex-direction: column; justify-content: space-between; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.tile { border-top: 4px solid var(--fc, transparent); }
.tile-all { grid-column: 1 / -1; border-top-color: var(--brand); background: linear-gradient(180deg, #eef3f6, var(--card)); }
.tile-all .name { font-size: 18px; }
.tile:active { background: #e9eef2; }
.tile .name { font-weight: 700; font-size: 17px; }
.tile .sub { color: var(--muted); font-size: 13px; }
.meta { color: var(--muted); font-size: 12px; text-align: center; margin: 4px 16px 20px; }

.toolbar { display: flex; gap: 8px; padding: 10px 12px 6px; background: var(--bg); }
.toolbar input { flex: 1; font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.filters { display: flex; align-items: center; gap: 8px; padding: 0 12px 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); font-size: 14px; cursor: pointer; user-select: none; font-family: inherit; color: inherit; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip input { margin: 0; }
.count { margin-left: auto; color: var(--muted); font-size: 13px; }

.wells { list-style: none; margin: 0; padding: 0 12px 24px; overflow-y: auto; flex: 1; }
.wells li { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px;
  padding: 12px 14px; display: flex; align-items: center; gap: 12px; cursor: pointer; }
.wells li:active { background: #e9eef2; }
.wells .dot { flex: 0 0 12px; }
.wells .body { flex: 1; min-width: 0; }
.wells .n { font-weight: 600; font-size: 16px; }
.wells .s { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wells .d { color: var(--muted); font-size: 13px; text-align: right; white-space: nowrap; }
.wells li.plugged .n { color: var(--plugged); text-decoration: line-through; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.active { background: var(--active); } .dot.obs { background: var(--obs); } .dot.plugged { background: var(--plugged); }

#map { flex: 1; min-height: 0; }
.legend { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 12px); left: 12px; z-index: 10;
  background: rgba(255,255,255,.95); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
  font-size: 13px; display: flex; gap: 12px; }
#viewMap { position: relative; }
.pin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.pin.active { background: var(--active); } .pin.obs { background: var(--obs); } .pin.plugged { background: var(--plugged); }
.pin.me { background: #1a73e8; width: 18px; height: 18px; box-shadow: 0 0 0 6px rgba(26,115,232,.25); }
.pin.focused { box-shadow: 0 0 0 3px #fff, 0 0 0 6px #ffcc00; animation: pin-pulse 1.6s ease-out 2; }
@keyframes pin-pulse { 0% { box-shadow: 0 0 0 3px #fff, 0 0 0 6px #ffcc00; } 70% { box-shadow: 0 0 0 3px #fff, 0 0 0 14px rgba(255,204,0,0); } 100% { box-shadow: 0 0 0 3px #fff, 0 0 0 6px #ffcc00; } }
.well-label { background: #14212b; color: #fff; border: 0; border-radius: 6px; padding: 3px 8px; font-size: 12px; font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.well-label::before { border-top-color: #14212b; }
.well-label.focused { background: #14212b; font-size: 13px; padding: 4px 10px; }
.leaflet-container { font: inherit; }

.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; }
.sheet[hidden] { display: none; }
.sheet-inner { width: 100%; max-width: 640px; margin: 0 auto; background: var(--card); border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px); max-height: var(--sheet-h); overflow-y: auto; }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; }
.sheet-head > div { flex: 1; min-width: 0; }
.dname { font-size: 22px; font-weight: 700; }
.dfield { color: var(--muted); font-size: 14px; }
.badge { padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; margin-top: 4px; }
.badge.active { background: var(--active); } .badge.obs { background: var(--obs); } .badge.plugged { background: var(--plugged); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 14px 0 16px; font-size: 15px; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; font-variant-numeric: tabular-nums; word-break: break-all; }
.primary, .secondary { display: block; width: 100%; text-align: center; padding: 14px; border-radius: 12px; font-size: 17px; font-weight: 600;
  text-decoration: none; margin-top: 10px; border: 0; cursor: pointer; font-family: inherit; }
.primary { background: var(--brand); color: var(--brand-ink); }
.secondary { background: #e9eef2; color: var(--ink); }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 40; max-width: 90vw; }
.toast[hidden] { display: none; }

@media (min-width: 700px) {
  .tiles { grid-template-columns: repeat(4, 1fr); max-width: 1000px; margin: 0 auto; width: 100%; }
  .toolbar, .filters, .wells { max-width: 800px; margin-left: auto; margin-right: auto; width: 100%; }
}
