/* Additions on top of the approved mockup styles (styles.css) for the working app. */
body.app-page { overflow: auto; height: auto; min-height: 100%; }
body.app-page .page { height: auto; min-height: calc(100vh - 60px - 48px); }
body.app-page .page-grid, body.app-page .memory-grid { height: auto; align-items: start; }
body.app-page .memory-main { min-height: 0; }
.page.narrow { max-width: 640px; margin: 0 auto; }
.msg-card { text-align: left; }
.msg-card h2 { margin-bottom: 10px; }
.msg-card p { margin-bottom: 12px; line-height: 1.5; }
.msg-card .btn { display: inline-flex; width: auto; padding: 0 18px; }
.big-icon { font-size: 34px; margin-bottom: 8px; }
.muted { color: var(--muted); font-size: 13px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
label.photo-drop { cursor: pointer; }
button.btn { border: none; cursor: pointer; font-family: inherit; width: 100%; }
button.btn-ghost { border: 1px solid #d9d3c8; }
.btn-ghost.danger { color: var(--red); border-color: #f0c9cb; width: auto; padding: 0 14px; margin-top: 14px; }
.counter { text-align: right; font-size: 11px; color: var(--muted); margin-top: 3px; }
.form-errors { background: #fdecec; border: 1px solid #f3c1c3; color: #8a1a1f; border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13px; }
.form-errors ul { margin-left: 16px; }
.form-ok, .banner-ok { background: #e8f5ec; border: 1px solid #bfe3ca; color: #1d5e33; border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13px; font-weight: 600; }
.banner-ok { max-width: 1100px; margin: 0 auto 12px; }
.field select { width: 100%; height: 42px; border: 1px solid #d9d3c8; border-radius: 8px; padding: 0 10px; font-family: inherit; background: #fff; color: var(--navy); }
.field input[type=file] { font-size: 13px; }
.edit-photo { max-height: 140px; border-radius: 8px; margin-bottom: 8px; }
.legal a, .context-copy a { color: var(--navy); font-weight: 600; }
.app-footer { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; padding: 14px; font-size: 11px; color: var(--muted); }
.app-footer a { color: var(--muted); }

/* minimap (real satellite) */
.minimap { position: relative; overflow: hidden; background: #2b3a2b; }
.minimap .addr-overlay { z-index: 3; }
.minimap .maplibregl-ctrl-attrib { font-size: 9px; }
.mini-pin { filter: drop-shadow(0 4px 6px rgba(15,35,64,.5)); }
.house-photo.minimap { background: #2b3a2b; }
.memory-hero.minimap { background: #2b3a2b; height: 260px; min-height: 260px; }

/* memory page */
.pin-entry .pin-photo { width: 100%; max-height: 320px; object-fit: cover; border-radius: 10px; margin-top: 10px; }
.pin-photo.small { max-height: 200px; }
.quote.small { font-size: 13px; }
.empty-pins { padding: 8px 0 10px; }
.empty-pins h2 { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 4px; }
.empty-pins p { color: var(--muted); font-size: 14px; }
.cta-row { display: flex; gap: 10px; margin: 14px 0 4px; }
.cta-row .btn { width: auto; padding: 0 18px; height: 42px; }
details.other-row-wrap summary { list-style: none; cursor: pointer; }
details.other-row-wrap summary::-webkit-details-marker { display: none; }
.other-body { padding: 4px 0 12px 44px; }
.mini-link { font-size: 12px; font-weight: 600; color: var(--navy); }
.disclaimer { margin-top: 16px; }
.share-img { width: 148px; border-radius: 10px; box-shadow: var(--shadow-soft); border: 1px solid var(--line); }
.share-actions .mini-link { display: inline-block; margin-top: 8px; }
.tip { cursor: pointer; font-family: inherit; border: 1px solid #d9d3c8; }
.tip-msg { font-size: 12px; margin-top: 8px; min-height: 0; }
.tip-msg.info { color: #1d5e33; } .tip-msg.err { color: #8a1a1f; }
.btn-support:disabled { opacity: .6; }
.ad-card { padding: 14px 16px; }
.ad-kicker { font-size: 10px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.ad-row { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.ad-photo { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; }
.ad-name { font-weight: 700; font-size: 14px; }
.ad-co { font-size: 12px; color: var(--muted); }
.ad-headline { font-size: 15px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 10px; }
.ad-headline.small { font-size: 13px; font-weight: 600; }
.ad-links { display: flex; gap: 12px; font-size: 12px; font-weight: 600; }
.ad-links a { color: var(--navy); }
.ad-card.small { padding: 12px 16px; }
.report-wrap { display: flex; justify-content: space-between; }
.report-wrap a.adv-link { font-weight: 600; }
.memory-side .btn-ghost { display: inline-flex; width: auto; padding: 0 14px; }

/* map page */
.map-stage.live { background: #1a1a1a; }
#map { position: absolute; inset: 0; }
.search-bar.live { padding: 0 14px; }
.search-bar.live input { flex: 1; border: none; outline: none; background: transparent; font-family: inherit; font-size: 14px; font-weight: 500; color: var(--navy); height: 100%; }
#results { position: absolute; top: 50px; left: 0; right: 0; list-style: none; background: var(--paper); border-radius: 12px; box-shadow: var(--shadow); max-height: 360px; overflow: auto; }
#results li { padding: 10px 14px; font-size: 14px; font-weight: 600; cursor: pointer; border-bottom: 1px solid var(--line); }
#results li small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
#results li:hover { background: var(--soft); }
#results li.none { cursor: default; color: var(--muted); font-weight: 400; }
.intro-card { position: absolute; left: 18px; bottom: 28px; width: 300px; background: var(--paper); border-radius: 16px; box-shadow: var(--shadow); padding: 16px 18px; z-index: 6; }
.intro-card h1, .intro-card h2 { font-size: 17px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 6px; }
.intro-card p { font-size: 13px; line-height: 1.45; color: var(--muted); margin-bottom: 6px; }
.intro-card .intro-stat { color: var(--navy); font-weight: 700; }
.intro-card .legal { font-size: 11px; margin: 0; }

/* Find my spot from a photo — compact control under the search bar */
.photo-locate-wrap {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 80px));
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  pointer-events: none;
}
.photo-locate-wrap > * { pointer-events: auto; }
.photo-locate-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(15, 35, 64, 0.12);
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 6px 16px rgba(15, 35, 64, 0.12);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--navy);
  cursor: pointer;
}
.photo-locate-btn:hover { background: #fff; }
.photo-locate-btn:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
}
.photo-locate-icon { flex: 0 0 auto; display: block; }
.photo-locate-hint {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--navy);
  background: rgba(255, 253, 248, 0.9);
  padding: 3px 8px;
  border-radius: 8px;
  max-width: 100%;
}
.photo-locate-msg {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
  background: rgba(255, 253, 248, 0.96);
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: 0 8px 20px rgba(15, 35, 64, 0.16);
  max-width: 100%;
}
.photo-locate-msg.err { border-left: 4px solid #e3242b; }
.photo-locate-msg.ok { border-left: 4px solid #2f9e57; }
.photo-locate-found { margin: 8px 0 6px; font-size: 13px; font-weight: 600; color: var(--navy); }
.map-status { position: absolute; left: 50%; transform: translateX(-50%); top: 114px; z-index: 6; font-size: 12px; font-weight: 600; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.8); }
.map-status:empty { display: none; }
.maplibregl-ctrl-top-right { top: 8px; }
.sap-popup .maplibregl-popup-content { background: var(--paper); border-radius: 16px; box-shadow: 0 18px 50px rgba(15,35,64,.28); padding: 18px 18px 16px; width: 320px; font-family: Inter, Helvetica, Arial, sans-serif; }
.sap-popup .maplibregl-popup-close-button { font-size: 20px; right: 8px; top: 6px; color: var(--muted); }
.sap-pop h1 { font-size: 21px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.15; color: var(--navy); }
.sap-pop .city { margin-top: 2px; font-size: 14px; font-weight: 500; color: var(--muted); }
.sap-pop .btn { width: 100%; text-decoration: none; }
.pop-more { display: block; text-align: center; margin-top: 10px; font-size: 13px; font-weight: 700; color: var(--navy); }
.pop-legal { margin-top: 8px; font-size: 11px; color: var(--muted); text-align: center; }
.btn-worth {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 40px; margin-top: 8px; box-sizing: border-box;
  background: #fff; color: var(--navy); border: 1px solid #d9d3c8;
  border-radius: 10px; font-weight: 700; font-size: 14px; text-decoration: none;
  cursor: pointer;
}
.sap-pop .btn-worth { width: 100%; }
.pop-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.pop-actions .btn-primary { margin-top: 0; }
.btn-add-photo {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 42px; box-sizing: border-box;
  background: var(--navy); color: #fff; border: none;
  border-radius: 12px; font-weight: 700; font-size: 15px;
  font-family: inherit; cursor: pointer;
}
.sap-pop .btn-add-photo { width: 100%; }
.photo-size-msg { color: #8a1a1f; font-size: 13px; font-weight: 600; margin-top: 8px; }
.remax-card .btn-worth, .ad-card .btn-worth { width: 100%; margin: 8px 0 0; }
.memory-side .btn-worth { margin-top: 8px; }
.rel-set { border: 0; padding: 0; margin: 0 0 12px; min-width: 0; }
.rel-set legend, .rel-set .label { padding: 0; }
.rel-set .rel { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; margin: 6px 0; cursor: pointer; }

/* Historic landmark card (map popup / memory page) */
.historic-landmark {
  margin: 10px 0 8px;
  padding: 10px 12px;
  background: #f7f1de;
  border: 1px solid #ead9a0;
  border-radius: 10px;
}
.landmark-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--navy);
}
.landmark-badge::before {
  content: "";
  width: 12px;
  height: 12px;
  background: #f6c21c;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.historic-landmark h2 { font-size: 17px; font-weight: 800; letter-spacing: -0.03em; color: var(--navy); margin: 4px 0 2px; }
.landmark-addr { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.landmark-note { font-size: 13px; line-height: 1.45; color: var(--navy); margin: 0 0 6px; }
.landmark-source { font-size: 12px; margin: 0; color: var(--muted); }
.landmark-source a { color: var(--navy); font-weight: 700; }

/* admin */
.admin-wrap { padding: 18px 22px 40px; max-width: 1400px; margin: 0 auto; }
.admin-wrap h1 { font-size: 22px; font-weight: 800; margin: 8px 0 12px; }
.admin-wrap h1 small { font-size: 14px; color: var(--muted); font-weight: 500; }
.admin-wrap h2 { font-size: 16px; font-weight: 800; margin: 22px 0 8px; }
.admin-nav { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; padding-bottom: 10px; border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 700; }
.admin-nav a { color: var(--navy); text-decoration: none; }
.inline { display: inline; }
.linkbtn { background: none; border: none; color: var(--red); font: inherit; font-weight: 700; cursor: pointer; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 12px; color: var(--muted); }
.stat b { display: block; font-size: 24px; color: var(--navy); }
.admin-table { width: 100%; border-collapse: collapse; background: var(--paper); font-size: 12px; border: 1px solid var(--line); }
.admin-table th, .admin-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.admin-table th { background: var(--soft); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.admin-table td.mem { max-width: 320px; }
.admin-table small { color: var(--muted); }
.tag { display: inline-block; padding: 2px 7px; border-radius: 999px; font-size: 10px; font-weight: 800; text-transform: uppercase; background: #e5e7eb; }
.tag.live { background: #d8eadc; } .tag.pending { background: #fdf0c8; } .tag.hidden { background: #f3d6d8; } .tag.removed { background: #ddd; }
.act { border: 1px solid #d9d3c8; background: #fff; border-radius: 6px; padding: 3px 8px; font: inherit; font-weight: 700; cursor: pointer; margin: 0 2px 2px 0; }
.act.remove, .act.hide { color: var(--red); }
.filters a { margin-right: 10px; font-size: 13px; color: var(--navy); }
.filters a.on { font-weight: 800; text-decoration: underline; }
.admin-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 14px; font-size: 12px; font-weight: 600; }
.admin-form label { display: flex; flex-direction: column; gap: 4px; }
.admin-form label.wide { grid-column: span 2; }
.admin-form label.chk { flex-direction: row; align-items: center; }
.admin-form input, .admin-form select { height: 34px; border: 1px solid #d9d3c8; border-radius: 6px; padding: 0 8px; font: inherit; font-weight: 400; }
.admin-form .btn { height: 40px; align-self: end; }
.legal-page p { font-size: 14px; line-height: 1.6; margin-bottom: 12px; }
.draft-flag { display: inline-block; background: var(--yellow); font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 999px; margin-bottom: 10px; }

/* Mobile bottom sheet for the selected parcel (map page) */
.parcel-sheet { display: none; }

@media (max-width: 760px) {
  body.app-page .page-grid, body.app-page .memory-grid { display: flex; flex-direction: column; }
  .form-row { grid-template-columns: 1fr; }

  /* Search: leave room for zoom, shorter results list */
  .search-bar {
    top: 10px;
    left: 12px;
    transform: none;
    width: calc(100% - 72px);
    height: 42px;
    padding: 0 12px;
  }
  .search-bar.live input { font-size: 13px; }
  #results { top: 46px; max-height: min(220px, 36vh); border-radius: 10px; }
  #results li { padding: 8px 12px; font-size: 13px; }
  #results li small { font-size: 11px; }

  .photo-locate-wrap {
    top: 56px;
    left: 12px;
    transform: none;
    width: calc(100% - 72px);
  }
  .photo-locate-btn { height: 28px; font-size: 11px; padding: 0 10px; }
  .photo-locate-icon { width: 14px; height: 14px; }
  .photo-locate-hint { font-size: 10px; padding: 2px 7px; }
  .photo-locate-msg { font-size: 12px; padding: 7px 9px; }
  .map-status { top: 100px; }
  body.sheet-open .photo-locate-wrap { display: none; }

  /* Intro card: compact bar, not a full-width slab */
  .intro-card {
    width: auto;
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom, 0px));
    padding: 10px 12px 9px;
    border-radius: 14px;
  }
  .intro-card h1, .intro-card h2 { font-size: 15px; margin-bottom: 2px; }
  .intro-card p { font-size: 12px; line-height: 1.4; margin-bottom: 3px; }
  .intro-card .legal { font-size: 10px; }
  body.sheet-open .intro-card { display: none; }

  /* Parcel / coming-soon bottom sheet: collapsed ≈ address + button, max ~45vh */
  .parcel-sheet:not([hidden]) {
    display: flex;
    flex-direction: column;
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom, 0px));
    z-index: 7;
    background: var(--paper);
    border-radius: 16px;
    box-shadow: 0 12px 36px rgba(15, 35, 64, 0.22);
    max-height: 45vh;
    overflow: hidden;
    padding: 4px 14px 12px;
  }
  .parcel-sheet.expanded { max-height: 45vh; }
  .sheet-grab {
    display: block;
    width: 40px;
    height: 4px;
    margin: 8px auto 6px;
    padding: 0;
    border: 0;
    border-radius: 99px;
    background: #b7b1a6;
    cursor: pointer;
    flex: 0 0 auto;
  }
  .parcel-sheet .sheet-grab { width: 44px; height: 20px; margin: 0 auto; background: transparent; position: relative; }
  .parcel-sheet .sheet-grab::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 8px;
    width: 40px;
    height: 4px;
    margin-left: -20px;
    border-radius: 99px;
    background: #b7b1a6;
  }
  .sheet-close {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 32px;
    height: 32px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
  }
  .parcel-sheet .sap-pop { padding: 0 4px 2px; }
  .parcel-sheet .sap-pop h1 { font-size: 17px; letter-spacing: -0.03em; padding-right: 24px; }
  .parcel-sheet .sap-pop .city { font-size: 12px; margin-top: 1px; }
  .parcel-sheet .popup-kicker { font-size: 10px; margin-bottom: 2px; }
  .parcel-sheet .popup-stat { margin: 8px 0 10px; padding: 7px 10px; font-size: 13px; }
  .parcel-sheet .pop-actions { margin-top: 10px; gap: 6px; }
  .parcel-sheet .btn-primary { height: 40px; font-size: 15px; border-radius: 10px; margin-top: 0; }
  .parcel-sheet .btn-add-photo { height: 38px; font-size: 14px; border-radius: 10px; }
  .parcel-sheet .btn-worth { height: 36px; font-size: 13px; margin-top: 8px; border-radius: 10px; }
  .parcel-sheet:not(.expanded) .pop-actions { margin-top: 8px; gap: 6px; }
  .parcel-sheet:not(.expanded) .btn-primary { height: 40px; }
  .parcel-sheet:not(.expanded) .btn-add-photo { height: 36px; }
  .parcel-sheet:not(.expanded) .btn-worth { height: 34px; margin-top: 6px; }
  .parcel-sheet .pop-more { margin-top: 8px; font-size: 12px; }
  .parcel-sheet .pop-legal { margin-top: 6px; font-size: 10px; }
  .parcel-sheet .historic-landmark { margin: 8px 0; padding: 8px 10px; }
  .parcel-sheet .landmark-note { font-size: 12px; }
  .parcel-sheet .landmark-source { font-size: 11px; }
  .parcel-sheet:not(.expanded) .popup-kicker,
  .parcel-sheet:not(.expanded) .popup-stat,
  .parcel-sheet:not(.expanded) .pop-more,
  .parcel-sheet:not(.expanded) .pop-legal,
  .parcel-sheet:not(.expanded) .landmark-note,
  .parcel-sheet:not(.expanded) .landmark-source { display: none; }
  .parcel-sheet:not(.expanded) .historic-landmark { margin: 6px 0 4px; padding: 5px 8px; }
  .parcel-sheet.expanded { overflow: auto; -webkit-overflow-scrolling: touch; }

  /* Fallback if a MapLibre popup is still used (cached JS, coming-soon, etc.) */
  .maplibregl-popup.sap-popup {
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    bottom: max(10px, env(safe-area-inset-bottom, 0px)) !important;
    top: auto !important;
    transform: none !important;
    max-width: none !important;
    width: auto !important;
  }
  .sap-popup .maplibregl-popup-tip { display: none; }
  .sap-popup .maplibregl-popup-content {
    width: auto !important;
    max-width: none;
    padding: 12px 14px 14px;
    border-radius: 16px;
  }
  .sap-popup .sap-pop h1 { font-size: 17px; }
  .sap-popup .btn-primary { height: 42px; font-size: 15px; }

  /* Pin / edit form: map stays visible; form is a compact, expandable sheet */
  body.form-page {
    overflow: hidden;
    height: 100dvh;
  }
  body.form-page .app-footer { display: none; }
  body.form-page .page:not(.narrow) {
    padding: 0;
    height: calc(100dvh - 52px);
    min-height: calc(100dvh - 52px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  body.form-page .page:not(.narrow) .page-grid {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0;
    height: 100%;
    min-height: 0;
    max-width: none;
    margin: 0;
  }
  body.form-page .page:not(.narrow) .context-panel {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    border-radius: 0;
    border: 0;
    box-shadow: none;
    position: relative;
    overflow: hidden;
  }
  body.form-page .page:not(.narrow) .house-photo,
  body.form-page .page:not(.narrow) .minimap.house-photo {
    flex: 1 1 auto;
    min-height: 140px;
    height: auto;
    width: 100%;
    border-radius: 0;
  }
  body.form-page .page:not(.narrow) .context-body {
    position: absolute;
    left: 10px;
    bottom: 18px;
    max-width: calc(100% - 20px);
    margin: 0;
    padding: 6px 10px 7px;
    background: rgba(255, 253, 248, 0.94);
    border-radius: 10px;
    box-shadow: 0 4px 14px rgba(15, 35, 64, 0.15);
    z-index: 3;
  }
  body.form-page .page:not(.narrow) .context-body h1 { font-size: 15px; }
  body.form-page .page:not(.narrow) .context-body .city { font-size: 11px; }
  body.form-page .page:not(.narrow) .context-body .kicker { font-size: 10px; margin-bottom: 1px; }
  body.form-page .page:not(.narrow) .context-copy { display: none; }
  body.form-page .page:not(.narrow) .context-copy:has(strong) {
    display: block;
    margin-top: 3px;
    font-size: 11px;
  }
  body.form-page .page:not(.narrow) .form-card {
    flex: 0 1 auto;
    max-height: 45vh;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 16px 16px 0 0;
    padding: 2px 14px 14px;
    margin: 0;
    box-shadow: 0 -10px 28px rgba(15, 35, 64, 0.16);
    position: relative;
    z-index: 2;
    padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
  }
  body.form-page .page:not(.narrow) .form-card.is-expanded,
  body.form-page .page:not(.narrow) .form-card:focus-within {
    max-height: 78vh;
  }
  body.form-page .page:not(.narrow) .form-card .sheet-grab {
    width: 44px;
    height: 20px;
    margin: 0 auto 2px;
    background: transparent;
    border: 0;
    padding: 0;
    position: relative;
    cursor: pointer;
  }
  body.form-page .page:not(.narrow) .form-card .sheet-grab::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 8px;
    width: 40px;
    height: 4px;
    margin-left: -20px;
    border-radius: 99px;
    background: #b7b1a6;
  }
  body.form-page .form-card h2 { font-size: 18px; }
  body.form-page .form-lead { font-size: 13px; margin-bottom: 10px; }
  body.form-page .pin-type-field { margin-bottom: 8px; }
  body.form-page .pin-types { gap: 5px; }
  body.form-page .pin-type { min-height: 32px; padding: 5px 6px; font-size: 12px; border-radius: 8px; }
  .parcel-sheet .photo-locate-found { font-size: 12px; margin: 6px 0 4px; }
  body.form-page .field { margin-bottom: 8px; }
  body.form-page .field label, body.form-page .field .label { margin-bottom: 4px; font-size: 11px; }
  body.form-page .field input[type="text"],
  body.form-page .field input[type="email"],
  body.form-page .field input[type="number"],
  body.form-page .field textarea {
    height: 38px;
    border-radius: 8px;
    font-size: 16px; /* keep 16px to avoid iOS zoom */
  }
  body.form-page .field textarea { height: 68px; padding: 8px 10px; }
  body.form-page .photo-drop { height: 48px; padding: 0 10px; gap: 8px; font-size: 12px; }
  body.form-page .photo-drop svg { width: 22px; height: 22px; flex: 0 0 auto; }
  body.form-page .edit-photo { max-height: 72px; }
  body.form-page .btn-primary { height: 42px; font-size: 15px; }
  body.form-page .optin { font-size: 12px; margin: 2px 0 10px; }
  body.form-page .legal, body.form-page .confirm-note { font-size: 11px; margin-top: 8px; }

  /* Standalone message / confirm cards: compact, not full-screen */
  .page.narrow { padding: 12px 12px 16px; }
  .page.narrow .form-card, .msg-card { padding: 16px 16px 14px; border-radius: 14px; }
  .msg-card h2 { font-size: 20px; }
  .app-footer { padding: 10px 12px 14px; }
}
/* Connection type chips — compact 2x2 on phones, one row on wide forms */
.pin-types {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.pin-type {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 13px;
  font-weight: 700;
  color: var(--navy);
  cursor: pointer;
  text-align: center;
  line-height: 1.2;
}
.pin-type input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.pin-type:has(input:focus-visible) { outline: 2px solid var(--navy); outline-offset: 2px; }
.pin-type:has(input:checked),
.pin-type.is-on {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}
.optional-flag { font-weight: 500; color: var(--muted); text-transform: none; letter-spacing: 0; }
@media (min-width: 761px) {
  .pin-types { grid-template-columns: repeat(4, 1fr); }
  .pin-type { min-height: 40px; }
}

.field label.photo-drop { display: flex; font-size: 13px; font-weight: 400; color: var(--muted); margin-bottom: 0; }
.field label.optin { display: flex; font-weight: 400; font-size: 13px; margin-bottom: 8px; }
.toggle-card { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 16px; border-radius: 12px; margin: 10px 0 14px; border: 1px solid var(--line); background: var(--paper); font-size: 13px; }
.toggle-card.off { border-left: 5px solid #8a93a6; } .toggle-card.on { border-left: 5px solid #2f9e57; }
.toggle-card .btn { width: auto; padding: 0 16px; height: 38px; }
.first-badge { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 999px; background: var(--yellow); color: var(--navy); font-size: 10px; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; vertical-align: middle; margin-left: 6px; white-space: nowrap; }
.first-badge.big { height: 24px; font-size: 11px; margin: 0 0 8px; }
.others.prominent { margin-top: 18px; padding: 14px 14px 6px; background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--yellow); border-radius: 12px; }
.others.prominent h3 { font-size: 16px; font-weight: 800; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.count-pill { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--navy); color: #fff; font-size: 12px; }
.others.prominent.empty p { padding-bottom: 8px; }
.others.prominent .other-body { padding-left: 44px; }
.empty-pins h2 { font-size: 22px; }


/* Map filters (top-left button + compact panel) */
.map-filters {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 11;
  width: 36px;
}
.map-filters-btn {
  position: relative;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(15, 35, 64, 0.12);
  border-radius: 10px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 6px 16px rgba(15, 35, 64, 0.14);
  color: var(--navy);
  cursor: pointer;
  padding: 0;
}
.map-filters-btn:hover { background: #fff; }
.map-filters-btn[aria-expanded="true"] {
  box-shadow: 0 0 0 2px var(--navy);
}
.map-filters-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
  box-sizing: border-box;
}
.map-filters-panel {
  position: absolute;
  top: 44px;
  left: 0;
  width: min(320px, calc(100vw - 28px));
  max-height: min(70vh, 540px);
  overflow: auto;
  background: var(--paper);
  border: 1px solid rgba(15, 35, 64, 0.1);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(15, 35, 64, 0.22);
  padding: 10px 12px 12px;
  color: var(--navy);
}
.map-filters-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.map-filters-head h2 {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
  flex: 1;
}
.map-filters-reset {
  border: none;
  background: none;
  color: var(--navy);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  padding: 4px 6px;
}
.map-filters-reset:hover { text-decoration: underline; }
.map-filters-close {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  border-radius: 8px;
}
.map-filters-close:hover { background: var(--soft); color: var(--navy); }
.map-filters-set {
  border: 0;
  margin: 8px 0 0;
  padding: 8px 0 0;
  border-top: 1px solid var(--line);
  min-width: 0;
}
.map-filters-set:first-child { border-top: 0; padding-top: 0; }
.map-filters-set legend {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0;
  margin-bottom: 4px;
}
.map-filters-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 8px;
}
.map-filters-opt {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
  cursor: pointer;
  min-height: 24px;
}
.map-filters-opt.wide { grid-column: 1 / -1; margin-top: 4px; }
.map-filters-opt input { width: 14px; height: 14px; accent-color: var(--navy); flex: 0 0 auto; }

@media (max-width: 760px) {
  .map-filters { top: 10px; left: 10px; }
  .search-bar, .search-bar.live {
    left: 54px;
    width: calc(100% - 54px - 72px);
  }
  .photo-locate-wrap {
    left: 54px;
    width: calc(100% - 54px - 72px);
  }
  .map-filters-panel {
    width: min(320px, calc(100vw - 20px));
    max-height: min(62vh, 480px);
  }
  body.sheet-open .map-filters-panel { max-height: min(42vh, 360px); }
}


/* Ham radio repeater popup (compact, mobile-first) */
.popup-kicker {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.repeater-pop .repeater-facts {
  list-style: none;
  margin: 8px 0 6px;
  padding: 0;
}
.repeater-pop .repeater-facts li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 3px 0;
  border-bottom: 1px solid #ece7dc;
  font-size: 13px;
}
.repeater-pop .repeater-facts li:last-child { border-bottom: 0; }
.repeater-pop .repeater-facts .k {
  color: var(--muted);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  flex: 0 0 auto;
}
.repeater-pop .repeater-facts .v { font-weight: 700; color: var(--navy); text-align: right; }
.repeater-pop .repeater-desc {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--navy);
}
.repeater-pop .repeater-approx,
.repeater-pop .repeater-attr {
  margin: 6px 0 0;
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
}
.repeater-pop .repeater-attr a { color: var(--navy); font-weight: 600; }
.sap-popup.repeater-popup .maplibregl-popup-content { width: 280px; padding: 14px 14px 12px; }
@media (max-width: 760px) {
  .parcel-sheet .repeater-pop .repeater-facts { margin: 6px 0 4px; }
  .parcel-sheet .repeater-pop .repeater-facts li { font-size: 12px; padding: 2px 0; }
  .parcel-sheet .repeater-pop .repeater-desc { font-size: 11px; }
  .parcel-sheet:not(.expanded) .repeater-desc { display: none; }
  .parcel-sheet:not(.expanded) .repeater-attr { margin-top: 4px; }
}


/* Historic events card (map popup / memory page). Distinct from gold landmark stars. */
.historic-event {
  margin: 10px 0 8px;
  padding: 10px 12px;
  background: #eef2f7;
  border: 1px solid #c5d0de;
  border-radius: 10px;
}
.historic-event.fun {
  background: #f8eee6;
  border-color: #e4c4ae;
}
.historic-event.solemn {
  background: #f2f1ef;
  border-color: #d0cdc7;
}
.event-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #1d3b66;
}
.historic-event.fun .event-badge { color: #8a3d16; }
.historic-event.solemn .event-badge { color: #5a5c5f; letter-spacing: .04em; }
.event-badge::before {
  content: "";
  width: 9px;
  height: 9px;
  background: #1d3b66;
  transform: rotate(45deg);
  flex: 0 0 auto;
}
.historic-event.fun .event-badge::before {
  transform: none;
  border-radius: 2px;
  background: #c45c26;
}
.historic-event.solemn .event-badge::before {
  transform: none;
  width: 7px;
  height: 10px;
  border-radius: 1px;
  background: #6a6d70;
}
.historic-event h2 { font-size: 16px; font-weight: 800; letter-spacing: -0.03em; color: var(--navy); margin: 4px 0 2px; }
.event-date { font-size: 12px; font-weight: 700; color: var(--muted); margin: 0 0 6px; }
.event-note { font-size: 13px; line-height: 1.45; color: var(--navy); margin: 0 0 6px; }
.event-source { font-size: 12px; margin: 0; color: var(--muted); }
.event-source a { color: var(--navy); font-weight: 700; }
.event-privacy {
  font-size: 13px;
  line-height: 1.4;
  color: var(--navy);
  background: #f3f1ea;
  border: 1px solid #e2ddd0;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 8px 0 6px;
}
.sap-popup.event-popup .maplibregl-popup-content { width: 300px; padding: 14px 14px 12px; }
.event-pop .historic-event { margin: 0; }
@media (max-width: 760px) {
  .parcel-sheet .historic-event { margin: 8px 0; padding: 8px 10px; }
  .parcel-sheet .historic-event h2 { font-size: 15px; }
  .parcel-sheet .event-note { font-size: 12px; margin-bottom: 4px; }
  .parcel-sheet .event-date { font-size: 11px; margin-bottom: 4px; }
  .parcel-sheet .event-privacy { font-size: 12px; padding: 6px 8px; margin: 6px 0 4px; }
  .parcel-sheet:not(.expanded) .historic-event { margin: 6px 0 4px; padding: 5px 8px; }
  .parcel-sheet:not(.expanded) .event-source { display: none; }
}

/* Place-layer popups (fishing, dog parks, drive-ins & diners) — compact, mobile-first */
.place-pop h1 { font-size: 18px; line-height: 1.2; margin: 2px 0 4px; }
.place-pop .popup-kicker { letter-spacing: .04em; }
.place-pop .city { font-size: 13px; margin: 0 0 6px; }
.place-pop .place-detail {
  font-size: 13px;
  line-height: 1.35;
  margin: 0 0 8px;
  color: var(--navy);
}
.place-pop .place-attr {
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
  margin: 0;
}
.place-pop .place-attr a { color: var(--navy); font-weight: 600; }
.sap-popup.place-popup .maplibregl-popup-content { width: 260px; padding: 12px 13px 11px; }
@media (max-width: 760px) {
  .parcel-sheet .place-pop h1 { font-size: 16px; }
  .parcel-sheet .place-pop .place-detail { font-size: 12px; margin-bottom: 6px; }
  .parcel-sheet:not(.expanded) .place-attr { margin-top: 2px; }
}

/* ---------- Parcel comments (popup + phone bottom sheet) ---------- */
.pop-comments { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.pop-comments > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; color: var(--navy); padding: 4px 0; user-select: none; }
.pop-comments > summary::-webkit-details-marker { display: none; }
.pop-comments > summary::after { content: ""; margin-left: auto; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform .15s; margin-right: 4px; }
.pop-comments[open] > summary::after { transform: rotate(-135deg); }
.pc-body { padding-top: 4px; }
.pc-list { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow-y: auto; }
.pc-item { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; line-height: 1.4; }
.pc-item:last-child { border-bottom: 0; }
.pc-meta { display: flex; align-items: baseline; gap: 4px; font-size: 12px; color: var(--muted); }
.pc-name { color: var(--ink); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.pc-del { margin-left: auto; border: 0; background: none; color: #a33; font-size: 11px; font-weight: 600; cursor: pointer; padding: 0 2px; }
.pc-text { margin-top: 2px; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.pc-text a { color: var(--navy); text-decoration: underline; }
.pc-note { font-size: 12px; color: var(--muted); margin: 4px 0; }
.pc-form { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.pc-form input[type=text], .pc-form textarea { width: 100%; box-sizing: border-box; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font: inherit; font-size: 14px; background: #fff; color: var(--ink); }
.pc-form textarea { resize: vertical; min-height: 54px; }
.pc-form .pc-hp { position: absolute !important; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.pc-row { display: flex; align-items: center; gap: 8px; }
.pc-hint { flex: 1; font-size: 10.5px; line-height: 1.3; color: var(--muted); }
.pc-form .pc-send { flex: 0 0 auto; width: auto; height: 34px; padding: 0 16px; font-size: 14px; margin: 0; border-radius: 9px; }
.pc-err { margin: 0; font-size: 12px; color: #a32020; background: #fdecea; border-radius: 6px; padding: 6px 8px; }
@media (max-width: 760px) {
  .parcel-sheet .pop-comments { margin-top: 8px; padding-top: 6px; }
  .parcel-sheet .pc-list { max-height: none; overflow: visible; }
  .parcel-sheet .pc-form input[type=text], .parcel-sheet .pc-form textarea { font-size: 16px; } /* no iOS zoom on focus */
}
@media (min-width: 761px) {
  /* a popup with comments open never grows past the map; it scrolls inside instead */
  .sap-popup .maplibregl-popup-content { max-height: calc(100vh - 160px); overflow-y: auto; overscroll-behavior: contain; }
}

/* Town info link: compact, top-right of the parcel card header (visible without scrolling). */
.pop-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.pop-head-main { min-width: 0; flex: 1; }
.pop-town {
  flex: 0 0 auto;
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-height: 40px;
  min-width: 40px;
  padding: 0 8px;
  margin: -6px -4px 0 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--navy);
  text-decoration: none;
  white-space: nowrap;
  border-radius: 8px;
  line-height: 1;
}
.pop-town:hover, .pop-town:focus-visible { background: rgba(15, 35, 64, 0.08); color: var(--navy); }
.pop-town-chevron { margin-left: 2px; font-weight: 800; }
@media (min-width: 761px) {
  /* leave room for MapLibre's close button at the top-right of the popup */
  .sap-popup .pop-head { padding-right: 22px; }
}
@media (max-width: 760px) {
  /* leave room for .sheet-close; keep the link visible on the collapsed sheet */
  .parcel-sheet .pop-head { padding-right: 28px; }
  .parcel-sheet .sap-pop h1 { padding-right: 0; }
  .parcel-sheet .pop-town { margin-top: -4px; }
}

/* Sticky "Back to the map" on every public page except the map and admin. */
.back-to-map {
  position: fixed;
  z-index: 25;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px 0 12px;
  background: var(--navy);
  color: #fff;
  border-radius: 999px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
  box-shadow: 0 8px 24px rgba(15, 35, 64, 0.28);
  box-sizing: border-box;
}
.back-to-map svg { display: block; flex: 0 0 auto; }
.back-to-map:hover, .back-to-map:focus-visible { color: #fff; filter: brightness(1.08); }
body.has-map-back .app-footer {
  padding-bottom: calc(44px + 24px + 24px + env(safe-area-inset-bottom, 0px));
}
body.has-map-back .page.narrow,
body.has-map-back .page.town-page,
body.has-map-back .page.narrow.town-page,
body.has-map-back .memory-grid,
body.has-map-back .page,
body.has-map-back.legal-body .page {
  /* keep last content / page footers clear of the floating button:
     button height + 24px gap + 16–24px of the button's offset from the edge + safe-area */
  padding-bottom: calc(44px + 24px + 24px + env(safe-area-inset-bottom, 0px));
}
body.form-page.has-map-back .page:not(.narrow) { padding-bottom: 0; }
@media (max-width: 760px) {
  .back-to-map {
    right: max(12px, env(safe-area-inset-right, 0px));
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }
  /* Pin/edit form is a bottom sheet: sit the button on the map, above the sheet. */
  body.form-page:has(.page:not(.narrow) .page-grid) .back-to-map {
    bottom: calc(45vh + 12px);
  }
  body.has-map-back .page.narrow.town-page,
  body.has-map-back .page.narrow,
  body.has-map-back.legal-body .page { padding-bottom: calc(44px + 24px + 24px + env(safe-area-inset-bottom, 0px)); }
}

/* admin campaigns */
.campaign-compose .field, .campaign-confirm .field { margin: 12px 0; }
.campaign-compose textarea, .campaign-preview { width: 100%; max-width: 720px; font: 14px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #fff; white-space: pre-wrap; }
.campaign-filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin: 10px 0; }
.campaign-filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; }
.campaign-filters select { height: 34px; min-width: 160px; border: 1px solid #d9d3c8; border-radius: 6px; padding: 0 8px; }
.campaign-count { font-size: 16px; margin: 14px 0; }
.campaign-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
#postalForm label.wide input { width: min(100%, 520px); }
