:root {
  /* Savanna daylight palette */
  --bg: #faf6ec;
  --bg-2: #f1e8d6;
  --panel: #fffdf8;          /* cards, inputs */
  --panel-2: #f6efdf;        /* soft surface */
  --line: #ddd0b0;           /* warm borders */
  --line-strong: #c6b892;    /* input outlines — visible in sun */
  --text: #23302a;           /* deep green-brown */
  --muted: #6f6547;          /* warm taupe — ~5.4:1 on cream, sun-readable */
  --placeholder: #8a7a54;    /* darker than before so it survives glare */
  --green: #2e7d4f;          /* acacia */
  --green-d: #226340;
  --green-tint: #e4f1e8;
  --amber: #e2942f;          /* sunset */
  --amber-d: #c97c1c;
  --amber-tint: #fbeecd;
  --terra: #c85a3c;          /* terracotta (offline / warnings) */
  --ink: #3d2600;            /* dark text on amber */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg), var(--bg-2)) fixed;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  padding-top: max(env(safe-area-inset-top), 12px);
  background: linear-gradient(135deg, var(--green), var(--green-d));
  color: #fff;
  box-shadow: 0 2px 10px rgba(34, 60, 40, .18);
  position: sticky;
  top: 0;
  z-index: 1100; /* above Leaflet's panes and controls (up to 1000) */
}
.brand { font-weight: 800; font-size: 19px; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.brand-leaf { font-size: 22px; }
.brand .bi .en { font-size: 11px; font-weight: 600; opacity: .8; letter-spacing: .3px; }
.login-brand { display: flex; align-items: center; gap: 8px; }
.login-brand .bi .en { font-size: 12px; font-weight: 600; color: var(--muted); opacity: 1; }
.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: rgba(255, 255, 255, .9); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--terra); display: inline-block; box-shadow: 0 0 0 3px rgba(255,255,255,.18); }
.dot.online { background: #7fe0a0; }

nav {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: var(--header-h, 54px); /* measured in app.js: the bilingual header is taller */
  z-index: 1050;
}
nav button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  transition: background .15s, color .15s;
}
nav button.active { background: var(--green); color: #fff; box-shadow: 0 2px 6px rgba(46,125,79,.35); }

main { padding: 16px; max-width: 720px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

label { display: block; margin: 14px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  border-radius: 10px;
  border: 1.5px solid var(--line-strong);
  background: var(--panel);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--placeholder); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(46, 125, 79, .16);
}
textarea { resize: vertical; }

fieldset.loc {
  border: 1px solid var(--line);
  border-radius: 14px;
  margin: 16px 0;
  padding: 14px;
  background: var(--panel);
}
legend { color: var(--green-d); font-size: 12px; font-weight: 700; padding: 0 6px; text-transform: uppercase; letter-spacing: .4px; }
.row { display: flex; gap: 10px; }
.row label { flex: 1; }

button.primary, button.secondary, button.ghost {
  border: none;
  border-radius: 12px;
  font-weight: 700;
  font-size: 15px;
  padding: 14px 16px;
  cursor: pointer;
}
button.primary {
  width: 100%;
  background: linear-gradient(135deg, var(--amber), var(--amber-d));
  color: var(--ink);
  margin-top: 18px;
  box-shadow: 0 4px 12px rgba(201, 124, 28, .3);
}
button.primary:active { transform: translateY(1px); }
button.secondary { background: var(--panel); color: var(--green-d); border: 1.5px solid var(--green); }
button.ghost { background: rgba(255, 255, 255, .16); color: #fff; border: 1px solid rgba(255,255,255,.35); padding: 7px 11px; font-size: 13px; }

.badge {
  display: inline-block;
  min-width: 18px;
  text-align: center;
  background: var(--amber);
  color: var(--ink);
  border-radius: 10px;
  font-size: 12px;
  padding: 0 6px;
  font-weight: 800;
}
.badge.zero { background: rgba(255,255,255,.22); color: #fff; }

.hint { color: var(--muted); font-size: 13px; margin: 8px 0; }
.hint.warn { color: var(--terra); font-weight: 600; }

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }

.cards { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 2px 8px rgba(34, 60, 40, .06);
}
.card.clickable { cursor: pointer; position: relative; transition: box-shadow .15s, transform .05s; }
.card.clickable:hover { box-shadow: 0 4px 14px rgba(34, 60, 40, .12); }
.card.clickable:active { transform: translateY(1px); }
.card .chev {
  position: absolute;
  top: 12px; right: 14px;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  font-weight: 700;
}
.card h4 { margin: 0 0 4px; font-size: 16px; padding-right: 22px; }
.card .meta { color: var(--muted); font-size: 12px; }
.card .photos { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.card .photos img { width: 62px; height: 62px; object-fit: cover; border-radius: 8px; }
.pill { display: inline-block; font-size: 11px; padding: 2px 9px; border-radius: 10px; margin-left: 6px; font-weight: 700; }
.pill.synced { background: var(--green-tint); color: var(--green-d); }
.pill.pending { background: var(--amber-tint); color: var(--amber-d); }

/* custom file picker (replaces the browser's localized native button) */
.filerow { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.filebtn {
  display: inline-block;
  background: var(--panel);
  color: var(--green-d);
  border: 1.5px solid var(--green);
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin: 0;
}
.filebtn:active { transform: translateY(1px); }
.filename { color: var(--muted); font-size: 14px; }

.linkbtn {
  background: none;
  border: none;
  color: var(--green-d);
  font-weight: 700;
  font-size: 13px;
  padding: 8px 0;
  cursor: pointer;
}
.subpanel {
  border: 1.5px solid var(--line-strong);
  border-radius: 12px;
  padding: 12px 14px 14px;
  margin: 4px 0 6px;
  background: var(--panel-2);
}
.subpanel label { margin-top: 8px; }
.subpanel .secondary { margin-top: 12px; }
.subpanel .hint { margin-bottom: 0; }

button.del {
  background: none;
  border: 1.5px solid var(--line-strong);
  color: var(--terra);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 11px;
  margin-top: 12px;
  cursor: pointer;
}
button.del:active { transform: translateY(1px); }

form.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
form.inline input, form.inline select { flex: 1; min-width: 140px; }
form.inline button { flex: 0 0 auto; }
h3 { margin: 22px 0 8px; font-size: 15px; color: var(--green-d); }

/* map */
#map {
  height: 68vh;
  min-height: 360px;
  border-radius: 14px;
  border: 1px solid var(--line);
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(34, 60, 40, .08);
}
.leaflet-div-icon { background: transparent; border: none; }
.mrk {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  font-size: 18px;
  line-height: 1;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.legend .leg { display: inline-flex; align-items: center; gap: 6px; }
.mrk.sm { width: 22px; height: 22px; font-size: 12px; border-width: 1px; }
.leaflet-popup-content { font-size: 13px; }
.leaflet-popup-content b { color: var(--green-d); }

/* detail sheet */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 33, 26, .45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 2000; /* above header, nav and Leaflet */
}
.modal[hidden] { display: none; }
.sheet {
  background: var(--panel);
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 14px 18px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 24px rgba(0, 0, 0, .25);
}
#detail-body h2 { margin: 6px 0 12px; font-size: 22px; }
.detail-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin-bottom: 14px; }
.detail-meta > div { font-size: 15px; color: var(--text); }
.detail-meta .dm-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 2px;
}
.detail-desc {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin: 4px 0 14px;
}
.detail-photos { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.detail-photo {
  width: 100%;
  max-width: 300px;
  border-radius: 12px;
  border: 1px solid var(--line);
}
.detail-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.detail-actions .del { margin-top: 0; }

/* signed-in user in the header */
header { position: sticky; }
.userbtn { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usermenu {
  position: absolute;
  right: 12px;
  top: calc(100% + 6px);
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(34, 60, 40, .22);
  padding: 12px 16px 6px;
  min-width: 200px;
  z-index: 20;
}
.usermenu[hidden] { display: none; }
.usermenu-who b { display: block; font-size: 15px; }
.usermenu-who span { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.usermenu .linkbtn { color: var(--terra); }

/* sign-in screen */
.login {
  position: fixed;
  inset: 0;
  z-index: 3000; /* above everything, including open sheets */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(circle at 20% 15%, rgba(226, 148, 47, .28), transparent 45%),
    linear-gradient(160deg, var(--green) 0%, var(--green-d) 55%, #1a4a30 100%);
}
.login[hidden] { display: none; }
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border-radius: 20px;
  padding: 28px 24px 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
}
.login-greeting { margin-bottom: 14px; }
.login-greeting .bi .sw { font-size: 40px; font-weight: 800; color: var(--amber-d); letter-spacing: -.5px; line-height: 1; }
.login-greeting .bi .en { font-size: 17px; font-weight: 600; color: var(--muted); opacity: 1; margin-top: 4px; }
.login-brand { font-size: 22px; font-weight: 800; color: var(--green-d); }
.login-sub { color: var(--muted); margin: 6px 0 8px; font-size: 14px; }
.login-note {
  background: var(--amber-tint);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin: 10px 0 4px;
}
.login-error { color: var(--terra); font-weight: 700; font-size: 14px; margin: 10px 0 0; }
.login-card .primary { margin-top: 18px; }
.login-card .primary:disabled { opacity: .6; }

/* users (admin) */
.pill.role-field { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.user-card.inactive { opacity: .6; }
.user-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
button.small { padding: 7px 11px; font-size: 13px; }
.pwrow { display: flex; gap: 8px; }
.pwrow input { flex: 1; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.pwrow .secondary { flex: 0 0 auto; padding: 0 14px; }
#u-msg { word-break: break-word; }

/* "Record saved" confirmation */
.modal.centered { align-items: center; padding: 20px; }
.confirm-card {
  background: var(--panel);
  width: 100%;
  max-width: 400px;
  border-radius: 20px;
  padding: 26px 22px 20px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .28);
  animation: pop .22s ease-out;
}
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.tick {
  width: 64px;
  height: 64px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 34px;
  font-weight: 800;
  line-height: 64px;
  box-shadow: 0 0 0 8px var(--green-tint);
}
.confirm-card h2 { margin: 4px 0 12px; font-size: 21px; }
.saved-summary {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.saved-species { font-size: 18px; font-weight: 700; }
.saved-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.saved-status { font-size: 13px; font-weight: 700; color: var(--muted); margin: 12px 0 0; }
.saved-status.ok { color: var(--green-d); }
.saved-status.wait { color: var(--amber-d); }

/* Two languages: Swahili is the main text, English small underneath */
.bi { display: inline-flex; flex-direction: column; line-height: 1.15; vertical-align: middle; }
.bi .en { font-size: .72em; font-weight: 500; opacity: .72; margin-top: 2px; letter-spacing: 0; text-transform: none; }
button .bi, .filebtn .bi { align-items: center; text-align: center; }
.linkbtn .bi, nav button .bi { align-items: flex-start; text-align: left; }
nav button .bi { align-items: center; text-align: center; }
.pill .bi { line-height: 1.05; }
.pill .bi .en { font-size: .8em; margin-top: 0; }
.status .bi .en { opacity: .8; }
.sync-error .bi .en, .saved-status .bi .en, .login-note .bi .en, .login-error .bi .en { opacity: .8; }
.saved-status .bi { align-items: center; }
.saved-status .bi + .bi { margin-top: 6px; }
.detail-meta .dm-label .bi .en { font-size: .85em; }

/* editing an existing record */
.edit-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--amber-tint);
  border: 1.5px solid var(--amber);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 6px;
  color: var(--ink);
}
.edit-banner[hidden] { display: none; }
.edit-label { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; color: var(--amber-d); }
.edit-banner .linkbtn { color: var(--terra); }
.edit-photos { display: flex; flex-wrap: wrap; gap: 10px; margin: 4px 0 10px; }
.edit-photos[hidden] { display: none; }
.ephoto { position: relative; }
.ephoto img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; }
.ephoto .ex {
  position: absolute; top: -8px; right: -8px;
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid #fff; background: var(--terra); color: #fff;
  font-weight: 800; font-size: 13px; line-height: 1; cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.ephoto.removed img { opacity: .3; filter: grayscale(1); }
.ephoto.removed .ex { background: var(--green); }

/* areas (parcels) */
.area-info { margin-top: 4px; font-weight: 600; color: var(--green-d); }
.areas-map {
  height: 55vh;
  min-height: 320px;
  border-radius: 14px;
  border: 1px solid var(--line);
  overflow: hidden;
  margin: 10px 0 14px;
  box-shadow: 0 2px 10px rgba(34, 60, 40, .08);
}
.vtx {
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 3px solid var(--amber-d);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
.ae-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0; }
.ae-count { font-weight: 700; color: var(--amber-d); margin-right: 4px; }
#ae-paste textarea { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 14px; }
#ae-paste .secondary { margin-top: 8px; }
#area-editor .primary { margin-top: 10px; }
.areas-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 6px 0; }
.areas-actions[hidden] { display: none; }
.import-msg { margin-top: 8px; }
.import-skipped { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
.leaflet-tooltip.area-tip { font-weight: 700; color: var(--green-d); }

/* entry type: three big choices, readable in the sun */
.field-label { margin: 14px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.entry-types { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.etype { margin: 0; position: relative; }
/* hidden radio: without the size reset it inherits input { width: 100% } and, being absolute,
   stretches past the screen edge — the page then scrolls sideways and tabs vanish (29 sept 2026) */
.etype input { position: absolute; top: 0; left: 0; width: 1px; height: 1px; margin: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.etype > span {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 58px; padding: 8px 6px; border-radius: 12px;
  border: 1.5px solid var(--line-strong); background: var(--panel);
  color: var(--text); font-weight: 700; font-size: 15px; cursor: pointer;
}
.etype > span .bi { align-items: center; }
.etype input:checked + span { background: var(--green); border-color: var(--green-d); color: #fff; }
.etype input:focus-visible + span { box-shadow: 0 0 0 3px rgba(46, 125, 79, .3); }
.type-tag { display: inline-block; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .4px; color: var(--green-d); background: var(--green-tint); border-radius: 6px; padding: 1px 6px; margin-right: 4px; }
.el-name { color: var(--amber-d); font-weight: 800; }

/* map: individual elements get a ring, whole-area records a small dot */
.mrk.el { border: 3px solid var(--amber-d); box-shadow: 0 0 0 2px #fff, 0 2px 6px rgba(0, 0, 0, .35); }
.mrk.dot { width: 14px; height: 14px; font-size: 0; border-width: 2px; }
.leaflet-tooltip.el-tip { font-weight: 800; color: var(--amber-d); padding: 1px 6px; }
.leaflet-tooltip.area-count { font-weight: 800; color: var(--green-d); background: rgba(255, 253, 248, .92); }
.area-pop ul { margin: 6px 0 0; padding-left: 16px; }
.area-pop a { color: var(--green-d); font-weight: 700; }
.leg-area { width: 22px; height: 16px; border: 2px solid #226340; background: rgba(63, 157, 84, .25); border-radius: 3px; display: inline-block; }

/* upload problems stay visible until they are solved */
.badge.error { background: var(--terra); color: #fff; }
.pill.failed { background: #f7dcd3; color: var(--terra); }
.sync-error { color: var(--terra); font-size: 12px; font-weight: 700; margin: 6px 0 0; }
.detail-meta .wide { grid-column: 1 / -1; }

/* Phones: six bilingual tabs and the header do not fit side by side. The tabs scroll within
   the bar and the header wraps, so the page itself never scrolls sideways. */
@media (max-width: 600px) {
  nav { overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  nav::-webkit-scrollbar { display: none; }
  nav button { flex: 0 0 auto; }
  header { flex-wrap: wrap; row-gap: 6px; }
  .status { flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
  .userbtn { max-width: 120px; }
}

/* Honour iOS/macOS "Increase Contrast" — push the weak spots harder still */
@media (prefers-contrast: more) {
  :root {
    --muted: #574d33;
    --placeholder: #6f6142;
    --line-strong: #a79769;
    --line: #c6b892;
  }
  nav button.active { box-shadow: 0 0 0 2px rgba(0,0,0,.15); }
}
