/* FS Field Monitoring — 4DCS brand: forest #006838, lime #8DC63F, cyan #00a0dc,
   earth #8b7356, cream #f9f8f5, dark #2d3436. Poppins headings, Nunito Sans body. */

:root {
  --forest: #006838;
  --forest-dark: #00522c;
  --lime: #8DC63F;
  --cyan: #00a0dc;
  --earth: #8b7356;
  --cream: #f9f8f5;
  --dark: #2d3436;
  --grey: #6b7280;
  --line: #e5e2da;
  --card: #ffffff;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --radius: 14px;
  --nav-h: 62px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }
body {
  font-family: 'Nunito Sans', system-ui, -apple-system, sans-serif;
  background: var(--cream);
  color: var(--dark);
  font-size: 16px;
  line-height: 1.45;
}

h1, h2, h3, .brand-font { font-family: 'Poppins', system-ui, sans-serif; }

button { font: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font: inherit; color: inherit; }

/* ---- boot splash ---- */
.boot-splash {
  height: 100vh; display: flex; flex-direction: column; gap: 10px;
  align-items: center; justify-content: center; color: var(--forest);
  font-family: 'Poppins', sans-serif; font-weight: 600;
}
.boot-logo {
  width: 74px; height: 74px; border-radius: 20px; background: var(--forest);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 20px; letter-spacing: .5px;
}

/* ---- app frame ---- */
.app-header {
  position: sticky; top: 0; z-index: 500;
  background: var(--forest); color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.app-header .title { font-family: 'Poppins', sans-serif; font-weight: 600; font-size: 17px; }
.app-header .sub { font-size: 12.5px; opacity: .85; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.net-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 3px rgba(255,255,255,.18); }
.net-dot.off { background: #f59e0b; }
.icon-btn { color: #fff; font-size: 13px; font-weight: 700; padding: 7px 10px; border-radius: 9px; background: rgba(255,255,255,.14); }

main#view {
  padding: 14px 14px calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 18px);
  max-width: 680px; margin: 0 auto;
}

/* ---- bottom nav ---- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 500;
  background: #fff; border-top: 1px solid var(--line);
  display: flex; height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; text-decoration: none; color: var(--grey); font-size: 11.5px; font-weight: 700;
  position: relative;
}
.bottom-nav a.active { color: var(--forest); }
.bottom-nav svg { width: 23px; height: 23px; }
.nav-badge {
  position: absolute; top: 7px; right: calc(50% - 22px);
  background: var(--danger); color: #fff; border-radius: 99px;
  font-size: 10px; min-width: 17px; height: 17px; line-height: 17px; text-align: center;
  padding: 0 4px;
}

/* ---- cards & general ---- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.card h2 { font-size: 16px; margin-bottom: 10px; color: var(--forest-dark); }
.card h3 { font-size: 14px; margin-bottom: 6px; }
.muted { color: var(--grey); font-size: 13px; }
.small { font-size: 12.5px; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { justify-content: space-between; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px;
  font-weight: 700; font-size: 15.5px; text-decoration: none; text-align: center;
}
.btn-primary { background: var(--forest); color: #fff; }
.btn-primary:active { background: var(--forest-dark); }
.btn-secondary { background: #eef2ec; color: var(--forest-dark); }
.btn-outline { border: 1.5px solid var(--line); color: var(--dark); background: #fff; }
.btn-danger-outline { border: 1.5px solid #fecaca; color: var(--danger); background: #fff; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-sm { min-height: 38px; padding: 6px 12px; font-size: 13.5px; border-radius: 10px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 700; font-size: 13.5px; margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; border: 1.5px solid var(--line);
  border-radius: 12px; background: #fff; font-size: 16px;
}
.field textarea { min-height: 76px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--forest);
}

.error-box {
  background: #fef2f2; border: 1px solid #fecaca; color: #991b1b;
  border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px;
}
.info-box {
  background: #eef7e9; border: 1px solid #d3e8c2; color: #2d5016;
  border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px;
}

/* ---- chips / badges ---- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: 99px; padding: 3px 10px; font-size: 12px; font-weight: 700;
  background: #eef2ec; color: var(--forest-dark);
}
.chip.gold { background: #fdf3e0; color: #92600a; }
.chip.blue { background: #e5f4fb; color: #076286; }
.chip.red { background: #fee2e2; color: #991b1b; }
.chip.grey { background: #f1f0ec; color: var(--grey); }

.state-draft  { background: #f1f0ec; color: #57534e; }
.state-queued { background: #fdf3e0; color: #92600a; }
.state-synced { background: #e7f3e7; color: #166534; }
.state-failed { background: #fee2e2; color: #991b1b; }

/* ---- login ---- */
.login-wrap { max-width: 400px; margin: 0 auto; padding-top: 6vh; }
.login-logo {
  width: 82px; height: 82px; border-radius: 22px; background: var(--forest); color: #fff;
  display: flex; align-items: center; justify-content: center; margin: 0 auto 14px;
  font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 22px;
}
.login-wrap h1 { text-align: center; font-size: 21px; color: var(--forest-dark); }
.login-wrap .tagline { text-align: center; margin-bottom: 26px; }

/* ---- progress ---- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px;
}
.stat .num { font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 22px; color: var(--forest); }
.stat .lbl { font-size: 12px; color: var(--grey); font-weight: 700; }
.pbar { height: 8px; background: #eceae3; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.pbar > div { height: 100%; background: var(--lime); border-radius: 99px; min-width: 2px; }
.pbar.full > div { background: var(--ok); }

/* ---- site list ---- */
.site-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px;
  border-bottom: 1px solid var(--line); text-decoration: none; color: inherit;
}
.site-item:last-child { border-bottom: none; }
.site-dot { width: 13px; height: 13px; border-radius: 50%; flex: 0 0 13px; }
.site-main { flex: 1; min-width: 0; }
.site-name { font-weight: 700; font-size: 15px; }
.site-meta { font-size: 12.5px; color: var(--grey); }

/* ---- map ---- */
#map { height: calc(100vh - 235px); min-height: 340px; border-radius: var(--radius); border: 1px solid var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 10px; font-size: 12.5px; }
.legend .row { gap: 6px; }

/* ---- visit form ---- */
.farm-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.farm-chip {
  border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 16px;
  font-weight: 700; background: #fff; min-height: 48px;
}
.farm-chip.sel { border-color: var(--forest); background: #eef7e9; color: var(--forest-dark); }

.gps-box { display: flex; align-items: center; gap: 10px; }
.gps-status { flex: 1; font-size: 13.5px; }

.readings-table { width: 100%; border-collapse: collapse; }
.readings-table th {
  text-align: left; font-size: 12px; color: var(--grey); padding: 4px 4px;
  font-weight: 700;
}
.readings-table td { padding: 3px 3px; }
.readings-table td:first-child { font-weight: 700; font-size: 13.5px; white-space: nowrap; padding-right: 6px; }
.readings-table .unit { display: block; font-weight: 400; font-size: 11px; color: var(--grey); }
.readings-table input {
  width: 100%; min-height: 44px; padding: 6px 8px; border: 1.5px solid var(--line);
  border-radius: 10px; font-size: 15px; text-align: center; background: #fff;
}
.readings-table input:focus { outline: none; border-color: var(--forest); }

.photo-strip { display: flex; gap: 10px; flex-wrap: wrap; }
.photo-thumb { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb button {
  position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,.6); color: #fff;
  width: 24px; height: 24px; border-radius: 50%; font-size: 13px; line-height: 1;
}
.photo-add {
  width: 84px; height: 84px; border: 1.5px dashed var(--earth); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; color: var(--earth);
  font-size: 26px; background: #fff;
}

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 48px; }
.switch { position: relative; width: 52px; height: 30px; flex: 0 0 52px; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; z-index: 2; margin: 0; }
.switch .track {
  position: absolute; inset: 0; background: #d6d3cb; border-radius: 99px; transition: background .15s;
}
.switch .track::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  background: #fff; border-radius: 50%; transition: left .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--forest); }
.switch input:checked + .track::after { left: 25px; }

/* ---- queue ---- */
.queue-item { border-bottom: 1px solid var(--line); padding: 12px 2px; }
.queue-item:last-child { border-bottom: none; }

/* ---- dashboard ---- */
.dash-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.dash-table th { text-align: left; color: var(--grey); font-size: 11.5px; padding: 6px 6px; border-bottom: 1px solid var(--line); }
.dash-table td { padding: 8px 6px; border-bottom: 1px solid #f0eee8; vertical-align: top; }
.scroll-x { overflow-x: auto; }
.flag { color: var(--danger); font-weight: 700; }

.team-item { display: flex; align-items: center; gap: 10px; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.team-item:last-child { border-bottom: none; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: #eef2ec; color: var(--forest-dark);
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex: 0 0 40px;
  font-family: 'Poppins', sans-serif;
}

/* toast */
#toast {
  position: fixed; bottom: calc(var(--nav-h) + 20px); left: 50%; transform: translateX(-50%);
  background: var(--dark); color: #fff; padding: 10px 18px; border-radius: 99px;
  font-size: 14px; font-weight: 700; z-index: 900; opacity: 0; pointer-events: none;
  transition: opacity .2s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; }

@media (min-width: 700px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
