/* ============================================================
   Field Visits — officer app
   A field instrument, not a website: built to be read in
   sunlight, tapped with one thumb, and trusted as a record.
   System fonts only — nothing to download, works fully offline.
   ============================================================ */

:root {
  /* Palette — cool paper + Prottyashi forest, never warm cream */
  --ink:          #10201A;   /* primary text */
  --ink-soft:     #56635C;   /* secondary text */
  --paper:        #F1F4F1;   /* app background */
  --card:         #FFFFFF;
  --forest:       #0B5A40;   /* primary action, brand */
  --forest-deep:  #063827;   /* pressed */
  --forest-wash:  #E4F0E9;   /* success surface */
  --amber:        #8F5200;   /* waiting to send */
  --amber-wash:   #FBEEDA;
  --clay:         #A32E22;   /* errors only */
  --clay-wash:    #F8E2DF;
  --rule:         #D9E0DB;

  /* Spacing scale */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px;

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px;
  --shadow: 0 1px 2px rgba(16,32,26,.05), 0 4px 14px rgba(16,32,26,.05);
  --bar-h: 84px;             /* bottom action bar */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* THE FIX: `hidden` must beat every display rule below. */
[hidden] { display: none !important; }

/* ---------- view scaffold ----------
   Each screen fills the viewport; inner content is capped at
   phone width and centred, so desktop never sprawls. */
.view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.login-box,
.visit-list,
.form,
.topbar > *,
.bottombar { max-width: 520px; }
.login-box, .visit-list, .form { width: 100%; margin-inline: auto; }

/* ---------- typography helpers ---------- */
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.center { text-align: center; }
.error {
  color: var(--clay);
  background: var(--clay-wash);
  font-weight: 600;
  font-size: 14px;
  padding: var(--s3);
  border-radius: var(--r-sm);
  margin: 0 0 var(--s4);
}
/* Micro-labels: the utility voice of the interface */
.eyebrow {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
/* Numbers line up like a ledger */
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-weight: 700;
  border: 1.5px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color .12s ease, border-color .12s ease;
}
.btn.big {
  width: 100%;
  min-height: 56px;
  padding: var(--s4);
  font-size: 17px;
  letter-spacing: .01em;
}
.btn.primary { background: var(--forest); color: #fff; }
.btn.primary:active { background: var(--forest-deep); }
.btn.ghost {
  background: var(--card);
  color: var(--forest);
  border-color: var(--rule);
}
.btn.ghost:active { background: var(--forest-wash); }
.btn.send { background: var(--amber); color: #fff; }
.btn.send:active { filter: brightness(.9); }
.btn.send:disabled {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--rule);
  cursor: default;
}
.small-btn {
  padding: 9px var(--s3);
  font-size: 14px;
  min-height: 40px;
}

:where(button, input, textarea, a, label.btn):focus-visible {
  outline: 3px solid #2E7DD1;
  outline-offset: 2px;
}

/* ---------- form fields ---------- */
label {
  display: block;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: var(--s4);
}
input, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 13px var(--s3);
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--rule);
  border-radius: var(--r-md);
}
input:focus, textarea:focus { border-color: var(--forest); }
textarea { resize: vertical; min-height: 96px; }
::placeholder { color: #9AA7A0; }

/* ============================================================
   SIGN IN
   ============================================================ */
#view-login { justify-content: center; padding: var(--s5); }
.login-box { max-width: 380px; }
.brand { text-align: center; margin-bottom: var(--s6); }
.brand-mark {
  width: 56px; height: 56px;
  margin: 0 auto var(--s3);
  border-radius: var(--r-lg);
  background: var(--forest);
  color: #fff;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: .02em;
  display: flex; align-items: center; justify-content: center;
}
.brand h1 {
  margin: 0 0 var(--s2);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -.01em;
}
.brand p { margin: 0; font-size: 14px; }

/* ============================================================
   TOP BAR
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--card);
  border-bottom: 1px solid var(--rule);
  padding: var(--s3) var(--s4);
}
/* inner row, capped to phone width and centred */
.topbar {
  display: flex;
  justify-content: center;
}
.topbar-inner {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
}
.topbar strong { font-size: 16px; font-weight: 700; }
.topbar .sub { font-size: 12px; color: var(--ink-soft); }

/* connection dot — quiet, never alarming */
.net-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ink-soft);
  margin-left: var(--s2);
  vertical-align: middle;
}
.net-dot.online { background: var(--forest); }

/* ============================================================
   VISIT LIST
   ============================================================ */
.visit-list {
  flex: 1;
  padding: var(--s4) var(--s4) calc(var(--bar-h) + var(--s5));
}

/* SIGNATURE: each record carries a status spine on its left
   edge — a ledger tab you can read at a glance from arm's length. */
.visit-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  padding: var(--s3) var(--s4) var(--s3) var(--s5);
  margin-bottom: var(--s3);
  overflow: hidden;
}
.visit-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 5px;
  background: var(--amber);
}
.visit-card:has(.chip.synced)::before { background: var(--forest); }
.visit-card:has(.chip.failed)::before { background: var(--clay); }

.visit-card .row1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s2);
  margin-bottom: 2px;
}
.visit-card .place {
  font-weight: 700;
  font-size: 16px;
  line-height: 1.3;
}
.visit-card .meta-line {
  font-size: 13px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.chip {
  flex: none;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.chip.pending { background: var(--amber-wash); color: var(--amber); }
.chip.synced  { background: var(--forest-wash); color: var(--forest); }
.chip.failed  { background: var(--clay-wash); color: var(--clay); }

/* empty state: an invitation, not an apology */
.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  text-align: center;
  color: var(--ink-soft);
  padding: var(--s6) var(--s5) calc(var(--bar-h) + var(--s6));
  font-size: 15px;
  line-height: 1.6;
}
.empty b { color: var(--ink); }

/* ============================================================
   BOTTOM ACTION BAR — the dispatch rail
   ============================================================ */
.bottombar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--rule);
  max-width: none;
}
.bottombar-inner {
  width: 100%;
  max-width: 520px;
  display: flex;
  gap: var(--s3);
}
.bottombar .btn { flex: 1; }

/* ============================================================
   NEW VISIT FORM
   ============================================================ */
.form {
  flex: 1;
  padding: var(--s5) var(--s4) calc(var(--bar-h) + var(--s6));
  max-width: 520px;
}

.capture-box {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: var(--s3) var(--s4);
  margin-bottom: var(--s4);
  box-shadow: var(--shadow);
  transition: border-color .15s ease, background-color .15s ease;
}
/* captured state reads as confirmed, not decorated */
.capture-box.captured {
  border-color: var(--forest);
  background: var(--forest-wash);
}
.capture-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s3);
  font-weight: 700;
  font-size: 15px;
}
.capture-row > span:first-child { min-width: 0; }
#gps-detail {
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.photo-strip {
  display: flex;
  gap: var(--s2);
  margin-top: var(--s3);
  flex-wrap: wrap;
}
.photo-strip:empty { margin-top: 0; }
.thumb { position: relative; }
.thumb img {
  width: 76px; height: 76px;
  object-fit: cover;
  border-radius: var(--r-sm);
  border: 1px solid var(--rule);
  display: block;
}
.thumb button {
  position: absolute;
  top: -7px; right: -7px;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--card);
  background: var(--clay);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: calc(var(--bar-h) + var(--s3));
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: var(--ink);
  color: #fff;
  padding: var(--s3) var(--s5);
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  max-width: min(90vw, 480px);
  text-align: center;
  box-shadow: 0 6px 24px rgba(16,32,26,.22);
}

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise .18s ease-out; }
  @keyframes rise {
    from { opacity: 0; transform: translate(-50%, 10px); }
  }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
