/* OpenSource Lithgow Hydrant Survey (v1.9) */

:root {
  color-scheme: light dark;

  --brand: #C8102E;
  --brand-ink: #7A0A1D;

  --paper: #F6F4EF;
  --paper-raised: #FFFFFF;
  --ink: #1C1E22;
  --ink-soft: #565C64;
  --line: #DCD8CC;

  --ok: #2E8B57;
  --attention: #C98A1E;
  --overdue: #C2410C;
  --unsurveyed: #64748B;
  --oos: #B91C1C;

  --focus: #1D4ED8;
  --radius: 14px;
  --shadow: 0 6px 20px rgba(20, 20, 20, 0.16);

  --font-display: "Oswald", "Arial Narrow", sans-serif;
  --font-body: "Public Sans", -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14171A;
    --paper-raised: #1E2226;
    --ink: #ECE9E2;
    --ink-soft: #ABB0B7;
    --line: #33383F;

    --ok: #3FAE71;
    --attention: #E0AC46;
    --overdue: #E2673F;
    --unsurveyed: #8C97A6;
    --oos: #F0574F;

    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

/* Bug fix: several elements below set their own `display`, which — unlike
   the browser's default stylesheet — beats the plain `hidden` attribute.
   Without this, anything toggled via `el.hidden = true/false` (the
   placement banner, the bottom sheet, its backdrop) stayed visible at all
   times regardless of that flag. This restores the attribute's authority. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, select, textarea { font-family: inherit; font-size: 1rem; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.85rem;
  background: var(--paper-raised);
  border-bottom: 1px solid var(--line);
  z-index: 20;
  flex-wrap: wrap;
}

.topbar-actions { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }

.search-wrap { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }

.search {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  background: var(--paper);
  color: var(--ink);
  min-width: 0;
  width: 12rem;
  max-width: 55vw;
  opacity: 1;
  transition: width 0.15s ease, opacity 0.1s ease, padding 0.15s ease, border-color 0.15s ease;
}
/* Collapsed to a sliver rather than `hidden` — keeps it in the tab order
   and avoids a layout jump when it expands back out. */
.search.is-collapsed {
  width: 0;
  min-width: 0;
  padding-left: 0;
  padding-right: 0;
  border-color: transparent;
  opacity: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem; /* ~44px minimum touch target */
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.88rem;
  white-space: nowrap;
}
.icon-btn[aria-expanded="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

/* Search/legend/admin toggles: same touch target, just square and centred
   on a single glyph instead of a text label — the minimal topbar Jerry
   asked for. */
.icon-btn.icon-only {
  justify-content: center;
  min-width: 2.75rem;
  padding: 0.4rem;
  font-size: 1.05rem;
  line-height: 1;
}

.auth-status { font-size: 0.82rem; color: var(--ink-soft); white-space: nowrap; }
.auth-status a { color: var(--focus); }

/* ---------- Filter chips ---------- */

.filter-row {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  overflow-x: auto;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  z-index: 19;
}

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: 2.5rem;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 0.32rem 0.9rem;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}
.chip.is-active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ---------- Map ---------- */

#map {
  flex: 1;
  min-height: 0;
  background: var(--paper);
  /* Bug fix: Leaflet gives its container `position: relative` but no
     z-index, so it never forms its own stacking context — its internal
     panes (tiles z-index:200, markers z-index:600…) leaked out and painted
     over sibling UI with a *lower* z-index than that, invisibly covering
     the "Add hydrant" button and the legend panel. Pinning z-index here
     seals the map's internal layers inside their own context so every
     sibling control (FAB, legend, sheet, toast) reliably paints above it. */
  position: relative;
  z-index: 0;
}

.leaflet-container { font-family: var(--font-body); }

/* Custom hydrant pin (built as an inline SVG divIcon in app.js) */
.hydrant-pin {
  position: relative;
  width: 30px;
  height: 38px;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.35));
}
.hydrant-pin svg { display: block; }
.hydrant-pin .pin-fill { fill: var(--pin-color, var(--unsurveyed)); }
.hydrant-pin .pin-type {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  fill: #fff;
  text-anchor: middle;
}
.hydrant-pin .status-badge {
  position: absolute;
  top: -4px;
  right: -6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--paper-raised);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 12px;
  text-align: center;
}
.hydrant-pin .status-badge-attention { background: var(--attention); }
.hydrant-pin .status-badge-oos { background: var(--oos); }
#map.placement-cursor { cursor: crosshair; }

/* ---------- Legend ---------- */

.legend-panel {
  position: absolute;
  left: 0.85rem;
  bottom: 0.85rem;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.85rem 1rem;
  max-width: 20rem;
  z-index: 25;
}
.legend-panel h2 {
  font-family: var(--font-display);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin: 0.6rem 0 0.35rem;
}
.legend-panel h2:first-child { margin-top: 0; }
.legend-panel ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.legend-panel li { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.swatch { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.swatch-green { background: var(--ok); }
.swatch-yellow { background: var(--attention); }
.swatch-red { background: var(--overdue); }
.swatch-unsurveyed { background: var(--unsurveyed); }
.badge-sample {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%; background: var(--oos); color: #fff;
  font-size: 10px; font-weight: 700; flex: none;
}
.badge-sample-attention { background: var(--attention); }

/* ---------- FAB ---------- */

.fab {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.75rem 1.15rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.fab span:first-child { font-size: 1.2rem; line-height: 1; }
.fab.is-active { background: var(--ink); }

.locate-fab {
  position: absolute;
  right: 1rem;
  bottom: 4.75rem;
  z-index: 25;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.locate-fab.is-active { color: var(--focus); border-color: var(--focus); }

.you-are-here {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--focus);
  border: 3px solid var(--paper-raised);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.35);
}

.placement-banner {
  position: absolute;
  top: 0.6rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 26;
  background: var(--ink);
  color: var(--paper);
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  box-shadow: var(--shadow);
}
.placement-banner button {
  background: transparent;
  border: 1px solid currentColor;
  color: inherit;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  cursor: pointer;
  font-size: 0.78rem;
}

/* ---------- Bottom sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.35);
  z-index: 30;
}

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 31;
  background: var(--paper-raised);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.sheet-grabber {
  width: 40px; height: 4px;
  background: var(--line);
  border-radius: 999px;
  margin: 0.6rem auto 0.2rem;
  flex: none;
}

.sheet-body {
  overflow-y: auto;
  padding: 0.5rem 1.1rem 1.2rem;
}

.sheet-body h3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  margin: 0.3rem 0 0.1rem;
}
.sheet-body .meta-line {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-bottom: 0.9rem;
}

.field { margin-bottom: 0.9rem; }
.field label { display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 0.3rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }
/* Bug fix: this used to only match input[type="text"], so a password field
   in the same .field wrapper (login.php, setup-first-user.php) fell back to
   the browser's unstyled default — no border-radius, no theme colours.
   Covers every text-like input type the app actually uses (plus a couple
   for future-proofing), not just text. */
.field input[type="text"],
.field input[type="password"],
.field input[type="email"],
.field input[type="search"],
.field input[type="tel"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: var(--paper);
  color: var(--ink);
}
.field textarea { resize: vertical; min-height: 4.5em; }

.type-toggle { display: flex; gap: 0.5rem; }
.type-toggle button {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.6rem;
  font-weight: 700;
  font-family: var(--font-mono);
  cursor: pointer;
}
.type-toggle button.is-selected { background: var(--brand); border-color: var(--brand); color: #fff; }

.status-grid { display: flex; flex-direction: column; gap: 0.4rem; }
.status-option {
  display: flex; align-items: center; gap: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
}
.status-option input { flex: none; }
.status-option .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.status-option.cat-ok .dot { background: var(--ok); }
.status-option.cat-attention .dot { background: var(--attention); }
.status-option.cat-out_of_service .dot { background: var(--oos); }
.status-option.is-selected { border-color: var(--ink); }

.tag-grid { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tag-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.32rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  background: var(--paper);
  color: var(--ink);
}
.tag-chip.is-selected { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1.1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-secondary { background: var(--paper); color: var(--ink); border: 1px solid var(--line); }
.btn-danger-outline { background: transparent; color: var(--oos); border: 1px solid var(--oos); }
.btn-row { display: flex; gap: 0.6rem; margin-top: 1rem; }
.btn-row .btn { width: auto; flex: 1; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* Revealed under the "Log a check" button — kept out of the way until
   someone actually wants to start a survey, not just view a hydrant. */
.check-form { margin-top: 0.75rem; }

.locked-note {
  font-size: 0.82rem;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
  margin-top: 0.5rem;
}

.history-list { list-style: none; margin: 0.2rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.55rem; }
.history-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font-size: 0.86rem;
}
.history-item .h-top { display: flex; justify-content: space-between; gap: 0.5rem; font-weight: 600; }
.history-item .h-date { font-family: var(--font-mono); font-size: 0.78rem; color: var(--ink-soft); font-weight: 400; }
.history-item .h-tags { margin-top: 0.25rem; color: var(--ink-soft); }
.history-item .h-notes { margin-top: 0.25rem; }

.section-divider { border: none; border-top: 1px solid var(--line); margin: 1.1rem 0; }

/* ---------- Loading overlay ---------- */

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 0.92rem;
}
.loading-spinner {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  animation: hydrant-spin 0.8s linear infinite;
}
@keyframes hydrant-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .loading-spinner { animation-duration: 2.4s; }
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-size: 0.88rem;
  z-index: 60;
  box-shadow: var(--shadow);
}

/* ---------- Small screens ---------- */

@media (max-width: 480px) {
  .search:not(.is-collapsed) { width: 9.5rem; }
  .fab-label { display: none; }
  /* Bug fix: padding alone left the button's width and height at the mercy
     of the "+" glyph's own metrics, which aren't perfectly square in this
     font — it rendered as a very slightly wide oval. Fixed, equal
     width/height (matching .locate-fab's approach) guarantees a true circle. */
  .fab {
    width: 3.25rem;
    height: 3.25rem;
    padding: 0;
    border-radius: 50%;
    justify-content: center;
  }
}
