/* defib.je — one responsive codebase.
   Desktop weight to management, mobile weight to a guardian standing at a cabinet
   in the rain, one-handed, in sunlight. High contrast, large targets, no chrome
   the public does not need. Design tokens carried over from the May build. */

:root {
  --green: #1a9640;
  --green-dark: #157a33;
  --green-light: #edf9f1;
  --amber: #d97706;
  --amber-light: #fff8e6;
  --amber-ink: #92400e;
  --blue: #185fa5;
  --red: #e11d48;
  --red-light: #fff1f3;

  --ink: #111;
  --muted: #666;
  --faint: #999;
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.14);
  --bg: #fff;
  --bg-soft: #f7f7f7;
  --bg-panel: #fafafa;

  --radius: 12px;
  --radius-lg: 16px;
  --radius-sm: 8px;
  --touch: 46px;                 /* minimum comfortable target for an outdoor thumb */
  --nav-height: 56px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: var(--green-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- app frame ------------------------------------------------------------ */

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* The top bar. Sticky, thin, honest about who you are. */
.topbar {
  height: var(--nav-height);
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 1000;
}
.topbar-logo img { height: 28px; display: block; }
.topbar-nav { display: flex; gap: 2px; }
.topbar-nav a {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}
.topbar-nav a:hover { background: var(--bg-soft); color: var(--ink); text-decoration: none; }
.topbar-nav a.active { background: var(--green-light); color: var(--green-dark); font-weight: 600; }
.topbar-right { display: flex; gap: 8px; align-items: center; }

.who {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted);
}
.who-name { font-weight: 600; color: var(--ink); }
.who-cap {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--green-dark); background: var(--green-light);
  padding: 2px 8px; border-radius: 6px;
}

/* On a phone the nav collapses to the essentials; management links hide. */
@media (max-width: 720px) {
  .topbar-nav a.desktop-only { display: none; }
  .who-name { display: none; }
}

.view { flex: 1; min-height: 0; }

/* ---- buttons -------------------------------------------------------------- */

.btn {
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 10px 18px;
  min-height: var(--touch);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .12s, border-color .12s;
  text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--green-dark); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-soft); text-decoration: none; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(0.94); }
.btn-sm { min-height: 38px; padding: 6px 14px; font-size: 14px; }
.btn-block { width: 100%; }

/* ---- forms ---------------------------------------------------------------- */

.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 13px; font-weight: 600; color: var(--ink);
  margin-bottom: 6px;
}
.field .hint { font-size: 12px; color: var(--faint); font-weight: 400; margin-top: 4px; }
.field input, .field select, .field textarea {
  width: 100%;
  font-family: var(--font);
  font-size: 16px;                /* 16px keeps iOS from zooming on focus */
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  min-height: var(--touch);
}
.field textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(26, 150, 64, 0.12);
}
.field input:disabled { background: var(--bg-soft); color: var(--muted); }
.field.verified label::after {
  content: 'verified content';
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--amber-ink); background: var(--amber-light);
  padding: 2px 6px; border-radius: 5px; margin-left: 8px; vertical-align: middle;
}

.checkbox-row { display: flex; align-items: center; gap: 10px; min-height: var(--touch); }
.checkbox-row input { width: 22px; height: 22px; }
.checkbox-row label { margin: 0; }

/* ---- shared layout blocks ------------------------------------------------- */

.page { max-width: 860px; margin: 0 auto; padding: 24px 18px 64px; }
.page-wide { max-width: 1180px; }
.page h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 4px; }
.page h2 { font-size: 18px; font-weight: 700; margin: 28px 0 12px; }
.lede { color: var(--muted); font-size: 15px; margin-bottom: 24px; }

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 20px;
}
.pill-green { background: var(--green-light); color: var(--green-dark); }
.pill-amber { background: var(--amber-light); color: var(--amber-ink); }
.pill-red { background: var(--red-light); color: var(--red); }
.pill-grey { background: var(--bg-soft); color: var(--muted); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.banner {
  border-radius: var(--radius); padding: 12px 14px; font-size: 14px;
  display: flex; gap: 10px; align-items: flex-start; margin-bottom: 16px;
}
.banner-info { background: var(--green-light); color: var(--green-dark); }
.banner-warn { background: var(--amber-light); color: var(--amber-ink); }
.banner-error { background: var(--red-light); color: var(--red); }

.empty {
  text-align: center; padding: 56px 24px; color: var(--muted);
}
.empty svg { opacity: .35; margin-bottom: 14px; }
.empty h2 { border: none; margin: 0 0 6px; color: var(--ink); }

.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--green);
  animation: spin .7s linear infinite; margin: 48px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--muted); }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Toast — brief, non-blocking confirmations. Never an alert() (blocks the tab). */
.toast-host { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 5000; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #111; color: #fff; padding: 11px 18px; border-radius: 10px;
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease;
}
.toast.err { background: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* View-specific styles are appended below by feature. */

/* ==== map view ============================================================= */

.view:has(.map-wrap) { display: flex; }        /* let the map fill the frame */
.map-wrap { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; z-index: 1; }
.leaflet-control-attribution { font-size: 10px; opacity: .7; }

.map-search {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  width: min(440px, calc(100vw - 24px)); background: #fff;
  border-radius: var(--radius); border: 1px solid var(--line);
  height: 46px; display: flex; align-items: center; padding: 0 14px; gap: 10px;
  z-index: 500; box-shadow: var(--shadow);
}
.map-search input { flex: 1; border: none; outline: none; font-size: 15px; background: transparent; font-family: var(--font); }
.map-count { background: var(--green-light); color: var(--green-dark); font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; flex-shrink: 0; }

.nearby-panel {
  position: absolute; top: 70px; left: 12px; bottom: 12px; width: 264px;
  display: flex; flex-direction: column; gap: 6px; z-index: 500; overflow-y: auto;
  scrollbar-width: none;
}
.nearby-panel::-webkit-scrollbar { display: none; }
.nearby-label { font-size: 10px; font-weight: 700; color: #555; letter-spacing: .07em; text-transform: uppercase; padding: 2px; }
.nearby-empty {
  background: #fff; border-radius: var(--radius); border: 1px solid var(--line); padding: 16px;
  display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow);
  font-size: 13px; color: var(--muted);
}
.nearby-empty strong { color: var(--ink); font-size: 14px; }

.nc { background: #fff; border-radius: var(--radius); border: 1px solid var(--line); cursor: pointer; overflow: hidden; display: flex; height: 76px; flex-shrink: 0; transition: border-color .15s; }
.nc:hover { border-color: var(--green); }
.nc.active { border-color: var(--blue); border-width: 1.5px; }
.nc-thumb { width: 76px; height: 76px; flex-shrink: 0; position: relative; overflow: hidden; }
.nc-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.nc-bar { position: absolute; bottom: 0; left: 0; right: 0; height: 3px; }
.nc-body { flex: 1; padding: 8px 10px; display: flex; flex-direction: column; justify-content: space-between; min-width: 0; }
.nc-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 4px; }
.nc-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.nc-dist { font-size: 12px; font-weight: 700; flex-shrink: 0; }
.nc-addr { font-size: 11.5px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nc-foot { display: flex; align-items: center; justify-content: space-between; }
.tag { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 5px; }
.tag-24 { background: var(--green); color: #fff; }
.tag-r { background: var(--amber); color: #fff; }
.nc-id { font-size: 10px; color: #ccc; }

.map-controls { position: absolute; right: 12px; top: 70px; display: flex; flex-direction: column; gap: 5px; z-index: 500; }
.map-ctrl { width: 40px; height: 40px; background: #fff; border-radius: var(--radius-sm); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 20px; color: #444; box-shadow: var(--shadow); }
.map-ctrl:hover { background: var(--bg-soft); }

.map-legend { position: absolute; right: 12px; bottom: 40px; background: #fff; border-radius: var(--radius-sm); border: 1px solid var(--line); padding: 10px 12px; z-index: 400; box-shadow: var(--shadow); }
.leg-row { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: #555; margin-bottom: 4px; }
.leg-row:last-child { margin-bottom: 0; }
.leg-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* Pins */
.lpin { cursor: pointer; position: relative; }
.lpin-body { width: 32px; height: 32px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); display: flex; align-items: center; justify-content: center; border: 2.5px solid rgba(0,0,0,0.25); box-shadow: 0 2px 6px rgba(0,0,0,0.3); }
.lpin-inner { transform: rotate(45deg); display: flex; }
.lpin-green .lpin-body { background: var(--green); }
.lpin-amber .lpin-body { background: var(--amber); }
.lpin-blue .lpin-body { background: var(--blue); border-color: #fff; }
.lpin-pulse { position: absolute; width: 48px; height: 48px; border-radius: 50%; border: 2px solid rgba(24,95,165,0.25); top: 50%; left: 50%; transform: translate(-50%, -65%); pointer-events: none; }
.lpin-nearest { position: absolute; top: -9px; right: -12px; background: var(--red); color: #fff; font-size: 8px; font-weight: 700; padding: 1px 5px; border-radius: 4px; white-space: nowrap; }

/* Bottom sheet — the primary detail surface on mobile, a floating card on desktop */
.bottom-sheet {
  position: absolute; bottom: 0; left: 0; right: 0; background: #fff;
  border-radius: 18px 18px 0 0; border-top: 1px solid var(--line);
  z-index: 600; transform: translateY(110%); transition: transform .28s cubic-bezier(.32,.72,0,1);
  box-shadow: 0 -6px 24px rgba(0,0,0,0.1);
}
.bottom-sheet.open { transform: translateY(0); }
.sheet-handle { width: 36px; height: 4px; background: #e0e0e0; border-radius: 2px; margin: 10px auto 0; }
.sheet-body { padding: 12px 18px 22px; }
.sheet-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.sheet-title { font-size: 19px; font-weight: 700; letter-spacing: -0.3px; }
.sheet-addr { font-size: 13px; color: var(--faint); margin-top: 2px; }
.sheet-photos { display: flex; gap: 6px; margin-bottom: 12px; }
.sheet-photo { flex: 1; height: 84px; border-radius: var(--radius-sm); background: #e8e8e8; overflow: hidden; }
.sheet-photo img { width: 100%; height: 100%; object-fit: cover; }
.sheet-meta { display: flex; gap: 6px; margin-bottom: 12px; }
.meta-item { flex: 1; background: var(--bg-soft); border-radius: var(--radius-sm); padding: 8px 10px; text-align: center; }
.meta-label { font-size: 10px; color: var(--faint); margin-bottom: 2px; }
.meta-val { font-size: 12.5px; font-weight: 600; }
.w3w-bar { display: flex; align-items: center; gap: 8px; background: var(--bg-soft); border-radius: var(--radius-sm); padding: 9px 11px; margin-bottom: 12px; }
.w3wm { color: var(--red); font-weight: 800; font-size: 12px; }
.w3wt { font-size: 13px; font-weight: 500; color: #444; flex: 1; }
.w3wc { font-size: 12px; color: var(--blue); cursor: pointer; background: none; border: none; padding: 6px; }
.sheet-desc { font-size: 13px; color: var(--muted); line-height: 1.55; margin-bottom: 14px; }
.sheet-actions { display: flex; gap: 8px; }

/* Desktop: float the sheet as a right-hand card, hide the phone affordances */
@media (min-width: 721px) {
  .sheet-handle { display: none; }
  .bottom-sheet {
    top: 70px; bottom: auto; left: auto; right: 12px; width: 340px;
    border-radius: var(--radius-lg); border: 1px solid var(--line);
    max-height: calc(100vh - var(--nav-height) - 94px); overflow-y: auto;
    transform: translateX(120%);
  }
  .bottom-sheet.open { transform: translateX(0); }
}

/* Phone: the side list would crowd the map; the sheet carries detail instead */
@media (max-width: 720px) {
  .nearby-panel { display: none; }
  .map-legend { display: none; }
  .map-controls { top: auto; bottom: 26px; }
}

/* ==== sign in =============================================================== */

.signin-wrap { max-width: 440px; margin: 48px auto; padding: 0 18px; }
.signin-card h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 6px; }
.signin-admin {
  margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line);
  font-size: 13px; color: var(--muted);
}
.banner-info strong { font-weight: 700; }

/* ==== tasks (guardian) ===================================================== */

.seg { display: inline-flex; background: var(--bg-soft); border-radius: var(--radius-sm); padding: 3px; margin-bottom: 20px; }
.seg button {
  border: none; background: transparent; font-family: var(--font); font-size: 14px; font-weight: 600;
  color: var(--muted); padding: 8px 18px; border-radius: 6px; cursor: pointer; min-height: 40px;
}
.seg button.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

.task-head { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); margin-bottom: 10px; }
.task-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.task-top { display: flex; justify-content: space-between; }
.task-id { cursor: pointer; min-width: 0; }
.task-name { font-size: 17px; font-weight: 700; display: flex; align-items: baseline; gap: 8px; }
.task-dist { font-size: 13px; font-weight: 700; color: var(--green-dark); }
.task-sub { font-size: 13px; color: var(--faint); margin-top: 2px; }
.task-need { font-size: 13.5px; color: var(--amber-ink); background: var(--amber-light); border-radius: var(--radius-sm); padding: 8px 11px; margin: 12px 0; }
.task-need.ok { color: var(--green-dark); background: var(--green-light); }
.task-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.task-last { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; }

/* the three-field visit */
.ok-choice { display: flex; gap: 10px; }
.ok-choice button {
  flex: 1; min-height: 56px; border-radius: var(--radius); border: 2px solid var(--line-strong);
  background: #fff; font-family: var(--font); font-size: 16px; font-weight: 600; color: var(--ink); cursor: pointer;
}
.ok-choice button[data-wrong="false"].active { border-color: var(--green); background: var(--green-light); color: var(--green-dark); }
.ok-choice button[data-wrong="true"].active { border-color: var(--amber); background: var(--amber-light); color: var(--amber-ink); }
.photo-drop {
  display: flex; align-items: center; justify-content: center; min-height: 88px;
  border: 2px dashed var(--line-strong); border-radius: var(--radius); cursor: pointer;
  color: var(--muted); font-size: 15px; font-weight: 600; overflow: hidden; position: relative; padding: 10px;
}
.photo-drop img { max-height: 220px; max-width: 100%; border-radius: var(--radius-sm); }

/* ==== site detail / edit =================================================== */

.site-readonly { display: flex; flex-wrap: wrap; gap: 8px 20px; font-size: 13px; color: var(--muted); margin: 4px 0 16px; }
.site-readonly strong { color: var(--ink); }

.verify-card { border-left: 3px solid var(--green); margin-bottom: 14px; }
.det-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); margin-bottom: 10px; }

.det-photos { display: flex; gap: 8px; flex-wrap: wrap; }
.det-photo { position: relative; width: 120px; height: 90px; border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-soft); display: block; }
.det-photo img { width: 100%; height: 100%; object-fit: cover; }
.det-photo span { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 10px; padding: 2px 6px; text-transform: capitalize; }

.det-device + .det-device { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.det-components { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.det-comp { font-size: 12px; background: var(--bg-soft); border-radius: 6px; padding: 3px 8px; color: var(--muted); }
.det-comp.expired { background: var(--red-light); color: var(--red); font-weight: 600; }

.det-concern + .det-concern { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }

.det-visits { display: flex; flex-direction: column; gap: 8px; }
.det-visit { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.det-visit span:first-child { font-variant-numeric: tabular-nums; }

/* ==== concerns ============================================================= */

.concern { margin-bottom: 12px; }
.concern-title { font-size: 16px; font-weight: 700; }
.concern-desc { font-size: 14px; color: var(--muted); margin: 10px 0; line-height: 1.5; }
.concern-actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.audit-note { margin-top: 24px; background: var(--bg-soft); box-shadow: none; }

@media (max-width: 560px) {
  .concern-actions .field { flex: 1 1 100% !important; }
}

/* ==== overview (signed-in home) =========================================== */

.ov-head { margin-bottom: 8px; }
.ov-scope { color: var(--green-dark); font-weight: 600; }
.ov-band { margin-top: 28px; }
.ov-band h2 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); margin-bottom: 12px; border: none; }

.ov-clear { background: var(--green-light); color: var(--green-dark); border-radius: var(--radius); padding: 16px; font-weight: 600; }

.ov-needs { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.ov-need {
  background: #fff; border: 1px solid var(--line); border-left: 3px solid var(--amber);
  border-radius: var(--radius); padding: 16px; position: relative; box-shadow: var(--shadow);
  display: block; text-decoration: none; color: inherit;
}
a.ov-need:hover { border-color: var(--amber); text-decoration: none; }
.ov-need-count { font-size: 30px; font-weight: 800; color: var(--ink); line-height: 1; }
.ov-need-label { font-size: 14px; color: var(--muted); margin-top: 6px; }
.ov-need-go { position: absolute; top: 16px; right: 16px; color: var(--amber); font-weight: 700; }

.ov-total { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow); }
.ov-bar { height: 8px; background: var(--bg-soft); border-radius: 5px; overflow: hidden; margin-top: 10px; }
.ov-bar.big { height: 12px; }
.ov-bar-fill { height: 100%; background: var(--green); border-radius: 5px; transition: width .4s; min-width: 2px; }

.ov-parishes { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.ov-parish { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-decoration: none; color: inherit; display: block; }
.ov-parish:hover { border-color: var(--green); text-decoration: none; }
.ov-parish-top { display: flex; align-items: baseline; justify-content: space-between; }
.ov-parish-name { font-size: 14.5px; font-weight: 600; }
.ov-parish-num { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

