/*
 * Survey tool — map-first layout.
 *
 * The map fills the viewport and every control floats above it. Placing the
 * two pins accurately is the part that genuinely needs screen space; a form
 * in a scrolling page pushed the map down to a strip you couldn't aim with.
 *
 * Constraints that drove the details:
 *   - Controls at least 48px: taps land while walking.
 *   - Bottom sheet in thumb reach, never covering the pins.
 *   - Strong contrast: used in direct Sydney sunlight.
 *   - 16px+ inputs, or iOS zooms on focus and wrecks the layout.
 */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden; /* the map pans; the page itself never scrolls */
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #e6e9ee;
  color: #16202b;
  -webkit-tap-highlight-color: transparent;
}

/* ------------------------------------------------------------------ map -- */
/*
 * Sized with explicit width/height rather than `inset: 0`.
 *
 * This page rendered a blank grey rectangle where the map should be, while
 * the consumer map (which sizes #map through flex) was fine. The difference
 * was that this one was sized ONLY by `inset: 0` — a shorthand added to CSS
 * relatively recently. Where it isn't understood, a position:fixed element
 * with automatic offsets shrink-wraps to its content, which for an empty div
 * is nothing at all; Google Maps then measures a zero-sized container and
 * draws nothing, with no error to explain itself.
 *
 * width/height against a fixed element resolve to the viewport and have done
 * for as long as CSS has existed, so this cannot fail the same way. The
 * survey tool has to work on whatever phone a surveyor happens to carry.
 */
#map {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* -------------------------------------------------------------- top bar -- */
#top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: calc(0.5rem + env(safe-area-inset-top)) 0.7rem 0.5rem;
  background: linear-gradient(to bottom, rgba(20, 30, 42, 0.86), rgba(20, 30, 42, 0));
  color: #fff;
  font-size: 0.82rem;
  pointer-events: none; /* let map drags pass through the gradient */
}
#gps-status {
  flex: 1;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  line-height: 1.3;
}
#top-bar a {
  pointer-events: auto;
  color: #fff;
  text-decoration: none;
  font-size: 1.2rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 50%;
}

/* Live length of the stretch, pinned under the top bar. */
#extent-badge {
  position: fixed;
  top: calc(3.1rem + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: #1565c0;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

/* ------------------------------------------------------ floating buttons -- */
.fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 11;
}
.fab:active { transform: scale(0.94); }

#photo-float {
  position: fixed;
  right: 0.7rem;
  top: calc(3.6rem + env(safe-area-inset-top));
  z-index: 11;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}
#photo-fab.done { background: #2e7d32; }
#photo-input { display: none; }
#photo-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#recentre {
  position: fixed;
  right: 0.7rem;
  bottom: calc(var(--sheet-height, 260px) + 0.7rem);
  font-size: 1.4rem;
  color: #1565c0;
  transition: bottom 0.2s ease;
}

#fullscreen-toggle {
  position: fixed;
  right: 0.7rem;
  bottom: calc(var(--sheet-height, 260px) + 4.4rem);
  font-size: 1.3rem;
  color: #1565c0;
  transition: bottom 0.2s ease;
}

/* Tells a first-time user the one thing they need to know: the map is the
   input. Disappears once there's a chain, so it never nags. */
#map-hint {
  position: fixed;
  top: 46px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  max-width: min(92vw, 460px);
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: rgba(27, 42, 58, 0.88);
  color: #fff;
  font-size: 0.78rem;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
}
#map-hint[hidden] { display: none; }

/* ------------------------------------------------------------- the walk -- */
/* One chip per stretch captured so far, newest on the right. Scrolls sideways
   rather than wrapping, so a long street doesn't push the buttons off screen. */
#chain-strip {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  padding-bottom: 0.4rem;
  margin-bottom: 0.5rem;
  scrollbar-width: thin;
}
.chain-chip {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-height: 44px;
  padding: 0.3rem 0.6rem;
  border: 2px solid var(--chip-colour, #455a64);
  border-radius: 10px;
  background: color-mix(in srgb, var(--chip-colour, #455a64) 10%, #fff);
  color: #1b2a3a;
  font-family: inherit;
  font-size: 0.7rem;
  line-height: 1.15;
  cursor: pointer;
}
.chain-chip .chip-span { color: #5a6b7b; font-size: 0.62rem; letter-spacing: 0.03em; }
.chain-chip .chip-rule { font-weight: 700; font-size: 0.8rem; }
/* A stretch with no rule yet is the one thing standing between the surveyor
   and the next point, so it has to be unmissable. */
.chain-chip.pending {
  border-style: dashed;
  animation: chip-pulse 1.4s ease-in-out infinite;
}
.chain-chip.editing { box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.28); }
/* On the server, no longer this device's to change. Dimmed so the walk still
   reads as one run, rather than hidden as if it never happened. */
.chain-chip.submitted { opacity: 0.62; }
@keyframes chip-pulse {
  50% { background: #fff3cd; }
}
@media (prefers-reduced-motion: reduce) {
  .chain-chip.pending { animation: none; background: #fff3cd; }
}

/* --------------------------------------------------------- rule picker -- */
#rule-picker { margin-bottom: 0.6rem; }
#rule-prompt {
  margin: 0 0 0.45rem;
  font-size: 0.85rem;
  color: #33475b;
}
/* Photographing the sign is the point of standing there, so it leads and it
   looks like the main action rather than an optional extra in the corner. */
.shoot-sign {
  display: block;
  width: 100%;
  min-height: 54px;
  margin-bottom: 0.5rem;
  padding: 0.9rem 0.6rem;
  border: none;
  border-radius: 11px;
  background: #4a3b8c;
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
}

/* What the reader made of the photo, with one button to accept it. */
#reading-confirm {
  background: #f3f0fa;
  border: 1px solid #ded5ee;
  border-radius: 11px;
  padding: 0.6rem 0.7rem;
  margin-bottom: 0.5rem;
}
#reading-confirm-headline { font-size: 1rem; font-weight: 700; line-height: 1.3; }
#reading-confirm-sub {
  font-size: 0.8rem;
  color: #5b5170;
  margin-top: 0.2rem;
  line-height: 1.35;
}
#reading-accept {
  width: 100%;
  min-height: 50px;
  margin-top: 0.55rem;
  border: none;
  border-radius: 10px;
  background: #2e7d32;
  color: #fff;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
}
#reading-accept[hidden] { display: none; }

/* Which kerb the rule applies to, sitting with the rule rather than in a
   panel. Only two answers are meaningful: the side that was marked out, or
   both. WHICH side that is comes from where the points were placed, so
   there's nothing to choose there and no dropdown pretending otherwise. */
.side-row {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.55rem;
}
.side-row button {
  flex: 1;
  min-height: 44px;
  border: 1.5px solid #c9d3dd;
  border-radius: 9px;
  background: #fff;
  color: #33475b;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.side-row button[aria-pressed="true"] {
  background: #1565c0;
  border-color: #1565c0;
  color: #fff;
  font-weight: 600;
}

/* A quiet divider, so the grid reads as the fallback rather than the task. */
.or-line {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.7rem 0 0.5rem;
  color: #93a1ae;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.or-line::before,
.or-line::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e3e8ed;
}

/* The most-pressed button on the page, so it gets the full width and sits
   above the grid rather than hiding inside it. */
#repeat-rule {
  width: 100%;
  min-height: 50px;
  margin-bottom: 0.45rem;
  border: 2px solid #1565c0;
  border-radius: 10px;
  background: #eaf2fb;
  color: #1565c0;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}
#repeat-rule[hidden] { display: none; }

/* Four across on a phone: big enough for a thumb at walking pace, and the
   ten rules that cover almost every Sydney kerb fit without scrolling. */
.rule-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}
.rule-grid button {
  min-height: 52px;
  padding: 0.4rem 0.2rem;
  border: 1px solid #c7d2dd;
  border-radius: 10px;
  background: #f6f8fa;
  color: #1b2a3a;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.rule-grid button[aria-pressed="true"] {
  background: #1565c0;
  border-color: #1565c0;
  color: #fff;
}
/* What the photo reader thinks it says -- an offer, not a decision, so it
   reads as "check this" rather than as already chosen. */
.rule-grid button.suggested {
  border-color: #f9a825;
  border-width: 2px;
  background: #fff8e1;
}
.linkish {
  margin-top: 0.5rem;
  padding: 0.4rem 0;
  min-height: 44px;
  border: none;
  background: none;
  color: #1565c0;
  font-family: inherit;
  font-size: 0.85rem;
  text-decoration: underline;
  cursor: pointer;
}

/* Shown when an already-saved stretch is picked up off the map. Amber so it
   reads as "you are changing existing data", not building something new. */
#saved-actions {
  border: 1px solid #ffe082;
  background: #fff8e1;
  border-radius: 10px;
  padding: 0.5rem 0.6rem;
  margin-bottom: 0.6rem;
}
#saved-label { margin: 0 0 0.45rem; font-size: 0.82rem; color: #6b4b00; font-weight: 600; }
.saved-buttons { display: flex; gap: 0.5rem; }
.saved-buttons button {
  flex: 1;
  min-height: 44px;
  border-radius: 9px;
  border: 1px solid #e0b76a;
  background: #fff;
  color: #6b4b00;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

#walk-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
#walk-actions button {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  padding: 0 0.35rem;
  border-radius: 10px;
  border: 1px solid #c7d2dd;
  background: #f6f8fa;
  color: #1b2a3a;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
#walk-actions #finish-btn { background: #2e7d32; border-color: #2e7d32; color: #fff; }
#walk-actions button { font-size: 0.8rem; }
#walk-actions button:disabled { opacity: 0.45; cursor: default; }

#resume-btn {
  width: 100%;
  margin-top: 0.5rem;
  min-height: 46px;
  border-radius: 10px;
  border: 1px dashed #1565c0;
  background: #eaf2fb;
  color: #1565c0;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

#apply-details {
  width: 100%;
  margin-top: 0.7rem;
  min-height: 46px;
  border-radius: 10px;
  border: none;
  background: #1565c0;
  color: #fff;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

/* --------------------------------------------------------- bottom sheet -- */
#sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  background: #fff;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -3px 18px rgba(0, 0, 0, 0.18);
  padding: 0.5rem 0.9rem calc(0.7rem + env(safe-area-inset-bottom));
  /* Grows with content but never swallows the map. */
  max-height: 62vh;
  overflow-y: auto;
}
#sheet-grip {
  width: 60px;
  height: 5px;
  border-radius: 3px;
  background: #d0d7de;
  margin: 0.15rem auto 0.6rem;
  cursor: pointer;
  /* Generous invisible hit area: a 5px bar is impossible to tap. */
  position: relative;
}
#sheet-grip::after {
  content: "";
  position: absolute;
  inset: -14px -60px;
}

/* Collapsed: the grip, the walk strip, the rule buttons and the big button
   remain. Those four ARE the walk -- dropping a point and saying what applies
   is the entire loop -- so collapsing gives the map almost the whole screen
   without costing a single tap. */
#sheet.collapsed
  > *:not(#sheet-grip):not(#primary-btn):not(#status):not(#chain-strip):not(#rule-picker) {
  display: none;
}
#sheet.collapsed #chain-strip { margin-bottom: 0.4rem; }
#sheet.collapsed {
  padding-bottom: calc(0.6rem + env(safe-area-inset-bottom));
}
#sheet.collapsed #status:empty { display: none; }

/* What the reader made of the sign */
#reading {
  background: #f3f0fa;
  border: 1px solid #ded5ee;
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.6rem;
}
#reading-headline { font-size: 1rem; font-weight: 700; line-height: 1.3; }
#reading-sub { font-size: 0.8rem; color: #5b5170; margin-top: 0.2rem; line-height: 1.35; }
#reading-status {
  font-size: 0.83rem;
  color: #4a3b8c;
  margin: 0 0 0.6rem;
  line-height: 1.35;
}

.sheet-row { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.6rem; }
.sheet-label { font-size: 0.78rem; color: #6b7885; font-weight: 600; flex: none; }

.side-picker { display: flex; gap: 0.35rem; flex: 1; }
.side-picker button {
  flex: 1;
  min-height: 48px;
  border: 1.5px solid #c9d3dd;
  border-radius: 9px;
  background: #fff;
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
}
.side-picker button[aria-pressed="true"] {
  background: #1565c0;
  border-color: #1565c0;
  color: #fff;
  font-weight: 600;
}

/* The one button that always means "the next thing": start the walk, then
   drop the next point. Kept large and in the same place throughout, because
   it gets pressed while walking, one-handed, without looking. */
#primary-btn {
  width: 100%;
  min-height: 56px;
  border: none;
  border-radius: 12px;
  background: #1565c0;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
#primary-btn:disabled { background: #b0c4d8; }

#status { margin: 0 0 0.5rem; font-size: 0.88rem; min-height: 1.1em; text-align: center; }
#status.ok { color: #2e7d32; font-weight: 600; }
#status.err { color: #c62828; font-weight: 600; }
#status.busy { color: #4a3b8c; }
#counter { margin: 0.45rem 0 0; font-size: 0.75rem; color: #6b7885; text-align: center; }

/* ------------------------------------------------------- details panel --- */
#details-panel { margin-top: 0.6rem; border-top: 1px solid #eceff2; padding-top: 0.5rem; }
#details-panel > summary {
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.35rem 0;
  list-style-position: inside;
}
#details-summary { font-weight: 400; color: #6b7885; font-size: 0.82rem; }

.field { display: block; margin-top: 0.7rem; }
.field > span {
  display: block;
  font-size: 0.8rem;
  color: #5c6b7a;
  margin-bottom: 0.25rem;
  font-weight: 600;
}
select, input[type="text"], input[type="number"], textarea {
  width: 100%;
  font-size: 16px; /* smaller triggers iOS zoom-on-focus */
  font-family: inherit;
  padding: 0.7rem;
  border: 1.5px solid #c9d3dd;
  border-radius: 9px;
  background: #fff;
  color: #16202b;
}
textarea { resize: vertical; line-height: 1.4; }

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.7rem; }
.chips button {
  flex: 1 0 auto;
  min-width: 62px;
  min-height: 44px;
  border: 1.5px solid #c9d3dd;
  border-radius: 999px;
  background: #fff;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
}
.chips button[aria-pressed="true"] {
  background: #1565c0;
  border-color: #1565c0;
  color: #fff;
  font-weight: 600;
}

.gps-helpers { display: flex; gap: 0.5rem; margin-top: 0.8rem; }
.gps-helpers button {
  flex: 1;
  min-height: 48px;
  border: 1.5px solid #c9d3dd;
  border-radius: 9px;
  background: #fff;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}

.hint { font-size: 0.8rem; color: #6b7885; margin: 0.5rem 0 0; line-height: 1.4; }
.hint a { color: #1565c0; }

/* Wider screens: keep the sheet a readable column rather than stretching it. */
@media (min-width: 700px) {
  #sheet {
    left: auto;
    right: 1rem;
    bottom: 1rem;
    width: 380px;
    border-radius: 14px;
    max-height: 82vh;
  }
  #recentre { right: calc(380px + 2rem); bottom: 1rem; }
  #extent-badge { left: 30%; }
}
