/* Survey Tool — one stylesheet, phone and tablet first.
   Every interactive element is at least 44px tall so it can be hit with a pen. */

:root {
  --ink:        #16232b;
  --ink-soft:   #5d707c;
  --line:       #d6dfe4;
  --bg:         #f3f6f8;
  --card:       #ffffff;
  --brand:      #12303f;
  --brand-ink:  #ffffff;
  --yes:        #1c7c4a;
  --yes-bg:     #e4f4ea;
  --no:         #a8322c;
  --no-bg:      #fbe8e7;
  --warn-bg:    #fff5da;
  --warn-line:  #e3c565;
  --tap:        48px;
  --radius:     10px;
}

* { box-sizing: border-box; }

/* A `display` rule beats the hidden attribute, and several elements here are
   hidden that way (the photo preview, the new-category box). Without this they
   stay on screen no matter what the markup says. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, "Noto Sans Arabic", sans-serif;
  padding-bottom: 3rem;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 52px;
  padding: .4rem .75rem;
  padding-top: max(.4rem, env(safe-area-inset-top));
  background: var(--brand);
  color: var(--brand-ink);
}

.topbar-title {
  flex: 1;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-back,
.topbar-user {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 .5rem;
  color: var(--brand-ink);
  font-size: 1.1rem;
  text-decoration: none;
}

.topbar-user { font-size: .85rem; opacity: .85; }

/* ---------- layout ---------- */

.wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: .75rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 0 0 .85rem;
}

.card-title {
  margin: 1.25rem 0 .6rem;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.card-title:first-child { margin-top: 0; }

.crumb { margin: 0 0 .6rem; color: var(--ink-soft); font-size: .9rem; }
.muted { color: var(--ink-soft); font-size: .87rem; }
.empty { text-align: center; }
.plain { list-style: none; margin: 0; padding: 0; }
.signout { text-align: center; margin: 1.5rem 0; }
.signout a { color: var(--ink-soft); }

/* ---------- fields ---------- */

.field { display: block; margin: 0 0 1rem; }

.field-label {
  display: block;
  margin-bottom: .35rem;
  font-size: .9rem;
  font-weight: 600;
}

.input {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: .6rem .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: inherit;
  font: inherit;
}

.input:focus {
  outline: 3px solid rgba(18, 48, 63, .25);
  border-color: var(--brand);
}

textarea.input { min-height: 3.2rem; resize: vertical; }
.input-num { text-align: center; font-size: 1.25rem; font-weight: 600; }
.field-narrow { margin-bottom: 0; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
}

.sub-field { display: block; }
.sub-label { display: block; margin-bottom: .2rem; font-size: .78rem; color: var(--ink-soft); }

.count-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .5rem;
  margin-bottom: .6rem;
}
.count-grid .input { min-width: 0; }

/* ---------- radio pills: the whole point of this tool ---------- */

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}

/* The real radio stays in the DOM (keyboard + screen readers) but is invisible. */
.pill-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: .5rem .85rem;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  font-size: .95rem;
  line-height: 1.15;
  text-align: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.pill-input:checked + .pill {
  border-color: var(--brand);
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 600;
}

.pill-input:focus-visible + .pill {
  outline: 3px solid rgba(18, 48, 63, .35);
  outline-offset: 2px;
}

/* Y / N get their own colours so a filled row is readable at a glance. */
.yn-field .pills { gap: .5rem; }
.pill-yes, .pill-no { min-width: 5.5rem; font-size: 1.1rem; font-weight: 700; }
.pill-input:checked + .pill-yes { border-color: var(--yes); background: var(--yes); }
.pill-input:checked + .pill-no  { border-color: var(--no);  background: var(--no); }

.pill-clear {
  min-height: var(--tap);
  border-style: dashed;
  color: var(--ink-soft);
  font-size: .8rem;
}
.pill-input:checked + .pill-clear {
  background: #fff;
  border-color: var(--ink-soft);
  color: var(--ink-soft);
  font-weight: 600;
}

.pill-vacant { border-style: dashed; }
.pill-input:checked + .pill-vacant { background: var(--no); border-color: var(--no); }

.tier-group { margin-bottom: .75rem; }
.tier-head {
  display: block;
  margin-bottom: .3rem;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: .55rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn-danger  { background: #fff; border-color: var(--no); color: var(--no); }
.btn-block   { width: 100%; }
.btn-big     { min-height: 56px; font-size: 1.05rem; }
.btn-camera  { border: 2px dashed var(--brand); color: var(--brand); font-weight: 600; }

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin: 0 0 .85rem;
}
.row-actions .btn { flex: 1 1 auto; }

.btn-icon {
  min-width: var(--tap);
  min-height: var(--tap);
  border: none;
  background: none;
  color: var(--ink-soft);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

/* The save buttons ride along the bottom so they are always in thumb reach. */
.sticky-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: .5rem;
  margin: 1rem -1rem -1rem;
  padding: .7rem 1rem;
  padding-bottom: max(.7rem, env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.sticky-actions .btn { flex: 1; }

/* ---------- flashes ---------- */

.flash {
  margin: 0 0 .75rem;
  padding: .7rem .85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  font-size: .92rem;
}
.flash-ok   { background: var(--yes-bg); border-color: var(--yes); }
.flash-err  { background: var(--no-bg);  border-color: var(--no); }
.flash-warn { background: var(--warn-bg); border-color: var(--warn-line); }

/* ---------- zones / areas ---------- */

.area-block {
  margin-top: .85rem;
  padding-top: .85rem;
  border-top: 1px solid var(--line);
}

.area-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .5rem;
}

.area-name { font-weight: 600; }

.badge {
  padding: .15rem .5rem;
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink-soft);
  font-size: .78rem;
  white-space: nowrap;
}

.area-links { display: flex; flex-wrap: wrap; gap: .5rem; }
.area-links .btn { flex: 1 1 8rem; }

/* ---------- merchant list ---------- */

.mlist { list-style: none; margin: 0; padding: 0; }

.mrow {
  display: flex;
  align-items: stretch;
  margin-bottom: .5rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.mrow-vacant { background: #faf3f2; }

.mrow-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: .6rem;
  min-height: 60px;
  padding: .5rem .6rem;
  color: inherit;
  text-decoration: none;
}

.mseq {
  flex: none;
  width: 2rem;
  color: var(--ink-soft);
  font-size: .85rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.mthumb {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--bg);
  object-fit: cover;
}

.mthumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--line);
}

.mbody { flex: 1; min-width: 0; }

/* dir="auto" gives Arabic names correct bidi ordering, but it also flips the
   alignment to the right, which breaks the left edge you scan down. Force the
   alignment back; the character ordering is unaffected. */
.mname, .mmeta, .area-name {
  text-align: left;
  unicode-bidi: plaintext;
}

.mname { display: block; font-weight: 600; }
.mmeta { display: block; color: var(--ink-soft); font-size: .8rem; }
.mflags { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .2rem; }

.tag {
  padding: .05rem .4rem;
  border-radius: 4px;
  font-size: .7rem;
  font-weight: 600;
}
.tag-y { background: var(--yes-bg); color: var(--yes); }
.tag-n { background: var(--bg);     color: var(--ink-soft); }

.mrow-del { display: flex; align-items: center; border-left: 1px solid var(--line); }

/* ---------- photos ---------- */

.photo-field { text-align: center; }

.photo-current,
.photo-preview {
  display: block;
  width: 100%;
  max-height: 220px;
  margin: 0 auto .6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  object-fit: contain;
  background: var(--bg);
}

.rename-row {
  padding: .85rem 0;
  border-top: 1px solid var(--line);
}

.rename-photo {
  display: block;
  width: 100%;
  max-height: 320px;
  margin: .4rem 0 .6rem;
  border-radius: var(--radius);
  object-fit: contain;
  background: var(--bg);
}

/* ---------- checkboxes, social rows, new-category box ---------- */

.check-line {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: var(--tap);
  font-size: .92rem;
  cursor: pointer;
}
.check-line input[type="checkbox"] { width: 22px; height: 22px; flex: none; }

.social-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .5rem;
}

.check-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  flex: none;
  min-width: 7.5rem;
  min-height: var(--tap);
  padding: .5rem .7rem;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  font-size: .95rem;
  cursor: pointer;
  user-select: none;
}
.check::before {
  content: "";
  width: 20px;
  height: 20px;
  border: 2px solid var(--line);
  border-radius: 5px;
  flex: none;
}
.check-input:checked + .check {
  border-color: var(--brand);
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 600;
}
.check-input:checked + .check::before {
  border-color: #fff;
  background: #fff;
  /* the tick */
  box-shadow: inset 0 0 0 2px var(--brand), inset 0 0 0 20px var(--brand-ink);
}
.check-input:focus-visible + .check {
  outline: 3px solid rgba(18, 48, 63, .35);
  outline-offset: 2px;
}

.social-handle { flex: 1; min-width: 0; }

.new-category {
  margin: .6rem 0 0;
  padding: .7rem;
  border: 2px dashed var(--brand);
  border-radius: var(--radius);
  background: #f7fafc;
}

.pill-other { border-style: dashed; }

/* ---------- location ---------- */

.gps-current {
  margin: 0 0 .4rem;
  font-size: .95rem;
  font-variant-numeric: tabular-nums;
}
.gps-current a { margin-left: .4rem; font-size: .85rem; }

.stamp { margin: 0 0 .5rem; font-size: .8rem; }

.map {
  height: 60vh;
  min-height: 320px;
  margin-bottom: .85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* Numbered pins, so the map matches the numbers in the census list. */
.pin span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: .8rem;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.pin-vacant span { background: var(--no); }

.card-flagged { border-color: var(--warn-line); background: #fffdf5; }
.danger-card { border-color: var(--no); }

/* ---------- calculated block ---------- */

.calc-card { background: #fbfcfd; }

/* Grid, not flex: the hint needs its own full-width row underneath without
   squeezing the label into a one-word-per-line column. */
.calc-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  column-gap: .75rem;
  padding: .45rem 0;
  border-bottom: 1px solid var(--line);
}
.calc-row:last-child { border-bottom: none; }

.calc-label { font-size: .9rem; }

.calc-value {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.calc-hint {
  grid-column: 1 / -1;
  color: var(--ink-soft);
  font-size: .76rem;
}

/* ---------- tablet ---------- */

@media (min-width: 700px) {
  .wrap { padding: 1.25rem; }
  .card { padding: 1.25rem; }
  .pill { min-width: 7rem; }
  .login-card { max-width: 420px; margin-inline: auto; }
}
