:root {
  --bg: #ffffff;
  --fg: #16191d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --shadow: 0 6px 24px rgba(0, 0, 0, .16);
  --panel-w: 380px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

/* ------------------------------------------------------------------ legend */

.legend {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  min-width: 190px;
  font-size: 13px;
}

.legend-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  border: 0;
  background: none;
  color: var(--fg);
  font-family: inherit;
  font-size: 12px;
  padding: 0;
  cursor: pointer;
}

.legend-icon { flex: none; }

/* No label between them now, so push the chevron to the far side. */
.legend-toggle > .legend-icon { margin-right: auto; }

.legend-chev {
  flex: none;
  color: var(--muted);
  transform: rotate(180deg);
  transition: transform .15s ease;
}

.legend-toggle:focus-visible { outline: 2px solid var(--fg); outline-offset: 3px; }

/* Collapsed: the card shrinks to just its header button. */
.legend.is-collapsed .legend-body { display: none; }

.legend.is-collapsed { min-width: 0; }

.legend.is-collapsed .legend-chev { transform: rotate(0deg); }

.legend-body { margin-top: 9px; }

@media (prefers-reduced-motion: reduce) {
  .legend-chev { transition: none; }
}

.legend-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 8px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
  user-select: none;
}

.legend-row input { margin: 0; cursor: pointer; }

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .18);
  flex: none;
}

.legend-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-section {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
}

.legend-body > :first-child.legend-section {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

#legend-accounts[hidden] + .legend-section {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.date-row {
  display: flex;
  gap: 6px;
}

.date-field {
  flex: 1;
  /* Without this the field inherits min-width:auto and refuses to shrink below
     the date control's intrinsic width. WebKit reserves a lot of room for a
     native date picker, so on iPhone the value overflows its box and pushes
     the whole legend card wide. */
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
}

.date-field input {
  font-family: inherit;
  font-size: 12px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px 6px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  cursor: pointer;
  /* Stops WebKit applying its own chrome and intrinsic sizing to the control. */
  -webkit-appearance: none;
  appearance: none;
  text-align: left;
}

.date-field input:focus-visible { outline: 2px solid var(--fg); outline-offset: 1px; }

.date-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 16px;
  margin-top: 6px;
}

.date-note {
  flex: 1;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.date-note.is-warn { color: #b45309; }

.date-clear {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  flex: none;
}

.date-clear[hidden] { display: none; }

.date-clear:hover { background: #f9fafb; color: var(--fg); }

.basemap-switch {
  display: flex;
  gap: 4px;
}

.basemap-btn {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.basemap-btn:hover { background: #f9fafb; color: var(--fg); }

.basemap-btn.is-active {
  background: var(--fg);
  border-color: var(--fg);
  color: #fff;
}

.basemap-btn:focus-visible { outline: 2px solid var(--fg); outline-offset: 1px; }

/* Aerial imagery is busy — thicken the white outlines so markers stay legible. */
.basemap-dark path.leaflet-interactive { stroke-width: 2.5; }

.basemap-dark .cluster { box-shadow: 0 1px 7px rgba(0, 0, 0, .65); }

.legend-count {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  flex: none;
}

/* ------------------------------------------------------- loading / banner */

.loading {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 7px 14px;
  font-size: 13px;
}

.loading[hidden] { display: none; }

.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid var(--line);
  border-top-color: var(--muted);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex: none;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}

.banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  max-width: min(560px, calc(100vw - 24px));
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #7c2d12;
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.4;
}

.banner[hidden] { display: none; }

.banner-close {
  background: none;
  border: 0;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  color: inherit;
  padding: 0 2px;
}

/* ----------------------------------------------------------- overlay card */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .72);
  padding: 24px;
}

.overlay[hidden] { display: none; }

.overlay-card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 20px 22px;
  max-width: 440px;
  text-align: center;
}

.overlay-card h2 { margin: 0 0 8px; font-size: 17px; }

.overlay-card p {
  margin: 0 0 14px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.btn {
  display: inline-block;
  background: var(--fg);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}

.btn[hidden] { display: none; }

.btn:hover { opacity: .88; }

/* ------------------------------------------------------------------ panel */

.panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--panel-w);
  z-index: 1100;
  background: var(--bg);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.panel[hidden] { display: none; }

.panel-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.panel-body { padding-bottom: 20px; }

.photo {
  position: relative;
  background: #f3f4f6;
  min-height: 180px;
  display: grid;
  place-items: center;
}

.photo img {
  display: block;
  width: 100%;
  height: auto;
  opacity: 0;
  transition: opacity .2s ease;
}

.photo img.loaded { opacity: 1; }

.photo img.loaded { cursor: zoom-in; }

.photo-zoom {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: rgba(0, 0, 0, .58);
  color: #fff;
  cursor: pointer;
  padding: 0;
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.photo-zoom[hidden] { display: none; }

.photo-zoom:hover { background: rgba(0, 0, 0, .78); }

.photo-zoom:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.photo-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  color: var(--muted);
  padding: 16px;
  text-align: center;
}

.badge-wrap { padding: 14px 16px 0; }

.badge {
  display: inline-block;
  color: #fff;
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12px;
  font-weight: 600;
}

.rows { padding: 12px 16px 4px; }

.row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  align-items: baseline;
}

.row-label { color: var(--muted); }

.row-value { overflow-wrap: anywhere; }

.seq { display: flex; align-items: center; gap: 8px; }

.seq code {
  font-family: var(--mono);
  font-size: 12px;
  background: #f3f4f6;
  border-radius: 5px;
  padding: 2px 6px;
}

.copy {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  flex: none;
}

.copy:hover { background: #f9fafb; }

.link { margin: 14px 16px 0; }

/* ---------------------------------------------------------------- markers */

.cluster-wrap { background: none; border: 0; }

.cluster {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  border: 2px solid #fff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, .35);
}

/* ------------------------------------------------------------- full screen */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, .93);
}

.lightbox[hidden] { display: none; }

/* Scroll container: at fit size nothing scrolls, but zoomed in this is what
   lets you pan around a 4032px photo on a phone. */
.lightbox-stage {
  position: absolute;
  inset: 0;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Fit mode: whole photo visible.
   Viewport units, not percentages: a percentage max-height against an
   auto-sized grid track is circular, so the browser ignores it and tall
   photos overflow a short window. The 32px matches .lightbox-stage's padding. */
.lightbox img {
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  width: auto;
  height: auto;
  object-fit: contain;
  cursor: zoom-in;
}

@supports (height: 100dvh) {
  /* dvh tracks the mobile URL bar showing and hiding. */
  .lightbox img { max-height: calc(100dvh - 32px); }
}

/* Zoomed: actual pixels, panned by scrolling the stage. Fitting a landscape
   photo to a portrait phone can render it smaller than the sidebar did, so
   this is what actually delivers "more detail" on mobile. */
.lightbox.zoomed .lightbox-stage { place-items: start; }

.lightbox.zoomed img {
  max-width: none;
  max-height: none;
  cursor: zoom-out;
}

.lightbox-close {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  z-index: 1;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.lightbox-close:hover { background: rgba(255, 255, 255, .28); }

.lightbox-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.lightbox-hint {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  color: rgba(255, 255, 255, .72);
  font-size: 12px;
  pointer-events: none;
}

.lightbox-hint:empty { display: none; }

/* Stop the page behind the photo from scrolling on touch devices. */
body.lightbox-open { overflow: hidden; }

/* ----------------------------------------------------------- small screens */

@media (max-width: 767px) {
  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 70vh;
    height: 70dvh;
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
  }

  .legend {
    top: 8px;
    right: 8px;
    padding: 8px 10px;
    min-width: 0;
    font-size: 12px;
  }

  .row { grid-template-columns: 84px 1fr; }
}

@media (max-width: 520px) {
  /* Two native date controls side by side don't fit a phone-width legend card
     once WebKit has had its say, so stack them and let each have the full
     width. Costs ~30px of height and removes the overflow entirely. */
  .date-row { flex-direction: column; gap: 5px; }

  .legend { max-width: calc(100vw - 16px); }
}

/* ============================================================== report page */

.report-page {
  background: #f7f7f8;
  min-height: 100%;
}

.report-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  max-width: 620px;
  margin: 0 auto;
  padding: 18px 16px 0;
}

.report-header h1 {
  margin: 0;
  font-size: 20px;
}

.report-back {
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
}

.report-back:hover { color: var(--fg); }

.report-main {
  max-width: 620px;
  margin: 0 auto;
  padding: 14px 16px 40px;
}

.field {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}

.field-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 8px;
}

.field-input {
  width: 100%;
  min-width: 0;
  font-family: inherit;
  /* 16px keeps iOS from zooming the page when a control takes focus. */
  font-size: 16px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
}

select.field-input { -webkit-appearance: none; appearance: none; cursor: pointer; }

.field-hint {
  margin: 8px 0 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
}

/* Honeypot: off-screen rather than display:none, which some bots skip. */
.hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.mini-map {
  height: 220px;
  border-radius: 9px;
  border: 1px solid var(--line);
  overflow: hidden;
}

.file-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.file-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-status {
  flex: none;
  color: var(--muted);
  font-size: 12px;
}

.file-row.is-sent .file-status { color: #15803d; }

.file-row.is-failed .file-status,
.file-row.is-too-big .file-status { color: #b91c1c; }

.file-retry {
  flex: none;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
}

.btn-primary {
  width: 100%;
  padding: 13px;
  font-size: 15px;
  border-radius: 10px;
}

.btn-primary:disabled {
  background: #d1d5db;
  cursor: not-allowed;
}

.btn-secondary {
  margin-top: 10px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
}

.btn-secondary:hover { background: #f9fafb; }

.notice {
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 12px;
}

.notice.is-warn {
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #7c2d12;
}

.notice[hidden] { display: none; }

.result {
  border-radius: 12px;
  padding: 16px;
  margin-top: 14px;
  font-size: 14px;
}

.result p { margin: 6px 0 0; line-height: 1.5; }

.result.is-ok { background: #f0fdf4; border: 1px solid #86efac; color: #14532d; }

.result.is-warn { background: #fff7ed; border: 1px solid #fdba74; color: #7c2d12; }

.result[hidden] { display: none; }

.report-link {
  display: block;
  text-align: center;
  background: var(--fg);
  color: #fff;
  text-decoration: none;
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
}

.report-link:hover { opacity: .88; }

.field-required {
  font-style: normal;
  color: #b45309;
  letter-spacing: 0;
  text-transform: none;
  font-size: 11px;
}

.notice { margin-top: 10px; margin-bottom: 0; }

/* Report form on a phone: keep "Send photo" above the fold.
 *
 * Must live at the end of the file. The base .mini-map rule is declared later
 * than the earlier @media block, and at equal specificity the last declaration
 * wins — so an override placed further up is silently ignored.
 *
 * Shortening every line of microcopy to one line was not enough on its own;
 * the map is the single biggest consumer of vertical space here, and 150px is
 * still ample for confirming or dragging a pin. */
@media (max-width: 520px) {
  .mini-map { height: 150px; }

  .report-header { padding-top: 12px; }

  .field { padding: 12px; margin-bottom: 10px; }

  .report-main { padding-top: 10px; }
}
