:root {
  --navy: #1a2a44;
  --navy-deep: #121e33;
  --green: #3e6b26;
  --gold: #f0b429;
  --gold-hover: #e5a516;
  --page: #f7f4ec;
  --surface: #fffdf8;
  --rule: #dad3c3;
  --muted: #4a5670;
  --danger: #b3261e;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(18, 30, 51, 0.22);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--navy);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--page); }
body { overflow: hidden; -webkit-text-size-adjust: 100%; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 1000;
  padding: calc(8px + var(--safe-t)) 12px 8px;
  background: var(--navy); color: #fff;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
.brand { font-weight: 800; letter-spacing: .2px; white-space: nowrap; font-size: 15px; }
.brand b { color: var(--gold); }
.topbar .title { font-size: 13px; color: #c9d1de; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.topbar .title strong { color: #fff; font-weight: 600; }
.help-btn {
  flex: none; border: 1px solid rgba(255,255,255,.35); background: transparent; color: #fff;
  border-radius: 999px; padding: 5px 11px; font-size: 13px;
}

#map { position: fixed; inset: 0; z-index: 1; background: #dfe6ea; }
.leaflet-top { top: calc(52px + var(--safe-t)); }
.leaflet-control-attribution { font-size: 10px; }
body.drawing #map { cursor: crosshair; touch-action: none; }

/* ---------- floating map tools (right side) ---------- */
.maptools {
  position: fixed; right: 10px; top: calc(62px + var(--safe-t)); z-index: 900;
  display: flex; flex-direction: column; gap: 8px;
}
.round {
  width: 44px; height: 44px; border-radius: 12px; border: 0;
  background: var(--surface); box-shadow: var(--shadow);
  display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--navy);
}
.round svg { width: 22px; height: 22px; }

.searchbox {
  position: fixed; left: 56px; right: 64px; top: calc(62px + var(--safe-t)); z-index: 900;
  display: flex; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow);
  overflow: hidden; max-width: 420px;
}
.searchbox input { flex: 1; min-width: 0; border: 0; padding: 11px 12px; background: transparent; font-size: 16px; outline: none; }
.searchbox button { border: 0; background: transparent; padding: 0 12px; color: var(--muted); }
.search-results {
  position: fixed; left: 56px; right: 64px; max-width: 420px; top: calc(110px + var(--safe-t)); z-index: 950;
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden;
}
.search-results button {
  display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--rule);
  background: transparent; padding: 11px 12px; font-size: 14px;
}
.search-results button:last-child { border-bottom: 0; }

/* ---------- bottom action bar ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
  padding: 10px 10px calc(10px + var(--safe-b));
  display: flex; gap: 8px; justify-content: center;
  pointer-events: none;
}
.actionbar > * { pointer-events: auto; }
.btn {
  border: 0; border-radius: 999px; padding: 14px 18px; font-weight: 700; font-size: 15px;
  box-shadow: var(--shadow); display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn-primary { background: var(--gold); color: var(--navy-deep); }
.btn-primary:active, .btn-primary:hover { background: var(--gold-hover); }
.btn-dark { background: var(--navy); color: #fff; }
.btn-light { background: var(--surface); color: var(--navy); }
.btn-danger-text { background: transparent; color: var(--danger); box-shadow: none; padding-left: 4px; padding-right: 4px; }
.btn[disabled] { opacity: .5; }
.badge {
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--gold); color: var(--navy-deep);
  font-size: 12px; display: inline-grid; place-items: center;
}
.btn-dark .badge { background: var(--gold); }

/* draw-mode banner */
.drawbanner {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: calc(62px + var(--safe-t)); z-index: 960;
  background: var(--navy); color: #fff; border-radius: 12px; box-shadow: var(--shadow);
  padding: 10px 12px 10px 14px; display: flex; align-items: center; gap: 12px;
  width: min(92vw, 460px); font-size: 14px; line-height: 1.3;
}
.drawbanner .btn { padding: 9px 14px; font-size: 14px; box-shadow: none; }

/* ---------- sheets (bottom on phone, side panel on desktop) ---------- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1100;
  background: var(--surface); border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(18,30,51,.25);
  padding: 8px 16px calc(16px + var(--safe-b));
  max-height: 78vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--rule); margin: 4px auto 10px; }
.sheet h2 { margin: 2px 0 4px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.sheet .sub { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.sheet label { display: block; font-size: 13px; font-weight: 600; margin: 10px 0 5px; }
.sheet textarea, .sheet input[type=text], .sheet input[type=tel], .sheet input[type=email] {
  width: 100%; border: 1px solid var(--rule); border-radius: 10px; padding: 11px 12px;
  background: #fff; font-size: 16px; /* 16px stops iOS zoom-on-focus */
}
.sheet textarea { min-height: 110px; resize: vertical; line-height: 1.4; }
.sheet textarea:focus, .sheet input:focus { outline: 2px solid var(--gold); border-color: var(--gold); }
.sheet .row { display: flex; gap: 8px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.sheet .row .spacer { flex: 1; }
.sheet .close-x { margin-left: auto; border: 0; background: transparent; font-size: 22px; color: var(--muted); padding: 0 4px; line-height: 1; }
.swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  border: 1px solid var(--rule); background: #fff; border-radius: 999px; padding: 6px 10px; font-size: 13px; color: var(--navy);
}
.chip:active { background: var(--page); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.err { color: var(--danger); font-size: 14px; margin-top: 10px; }
.hp { position: absolute; left: -5000px; width: 1px; height: 1px; overflow: hidden; }

.arealist { list-style: none; margin: 6px 0 0; padding: 0; }
.arealist li {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 2px; border-bottom: 1px solid var(--rule);
}
.arealist li:last-child { border-bottom: 0; }
.arealist .num { width: 28px; height: 28px; border-radius: 8px; color: #fff; font-weight: 800; display: grid; place-items: center; flex: none; font-size: 14px; }
.arealist .body { flex: 1; min-width: 0; }
.arealist .meta { font-size: 12px; color: var(--muted); }
.arealist .note { font-size: 14px; margin-top: 2px; white-space: pre-wrap; word-wrap: break-word; }
.arealist .note.empty { color: var(--muted); font-style: italic; }
.arealist button.link { border: 0; background: transparent; color: var(--green); font-weight: 700; padding: 4px 0; font-size: 14px; }
.empty-state { color: var(--muted); font-size: 14px; padding: 6px 0 4px; }

.steps { margin: 4px 0 6px; padding: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; font-size: 15px; line-height: 1.35; }
.steps li::before {
  content: counter(s); flex: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--navy); color: #fff; font-weight: 800; font-size: 13px; display: grid; place-items: center;
}

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(118px + var(--safe-t)); z-index: 1200;
  background: var(--navy-deep); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px;
  box-shadow: var(--shadow); max-width: 92vw; text-align: center;
}

/* polygon number labels */
.area-label {
  background: transparent; border: 0; box-shadow: none;
}
.area-label span {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  color: #fff; font-weight: 800; font-size: 13px; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.zip-label { background: rgba(26,42,68,.85); color: #fff; border: 0; border-radius: 6px; font-weight: 700; font-size: 12px; padding: 3px 7px; box-shadow: none; }
.zip-label::before { display: none; }

/* desktop: sheets become a right-side panel, action bar sits bottom-left of map */
@media (min-width: 900px) {
  .sheet {
    left: auto; right: 12px; bottom: 12px; top: calc(62px + var(--safe-t));
    width: 380px; max-height: none; border-radius: 16px; padding: 14px 18px 18px;
  }
  .sheet .grab { display: none; }
  .maptools { right: 12px; }
  body.panel-open .maptools { right: 404px; }
  .actionbar { justify-content: flex-start; padding-left: 14px; }
  body.panel-open .actionbar { right: 400px; }
  .searchbox { right: auto; width: 380px; }
  .search-results { right: auto; width: 380px; }
}
.help-btn .short { display: none; }
@media (max-width: 599px) {
  .topbar .long { display: none; }
  .help-btn .short { display: inline; }
  /* the open sheet carries its own buttons; keep the bar from stacking under it */
  body.panel-open .actionbar { display: none; }
}
@media (max-width: 380px) {
  .btn { padding: 13px 14px; font-size: 14px; }
}
