/* TrackHerd — "Pasture Calm" design system (approved 2026-07-02)
   Light minimal surfaces, forest-green accent, Manrope, bottom tabs. */
:root {
  --bg: #F7F6F3;
  --card: #FFFFFF;
  --ink: #17201B;
  --muted: #8B948D;
  --faint: #A7AFA9;
  --line: #ECEAE5;
  --chip: #F0EFEA;
  --green: #1F6B4A;
  --green-soft: #E4F0E9;
  --green-map: #2E9A6B;
  --red: #B4372A;
  --red-soft: #FBE5E2;
  --red-map: #D24A3A;
  --amber: #946E12;
  --amber-soft: #FBF0D9;
  --amber-map: #E3A81C;
  --shadow: 0 1px 3px rgba(20,30,24,.05);
  --shadow-up: 0 -4px 24px rgba(20,30,24,.10);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: 'Manrope', -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--ink);
  overscroll-behavior: none;
}
button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 15px; }

#app, #login-view { height: 100%; height: 100dvh; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ── login ── */
#login-view { align-items: center; justify-content: center; padding: 24px; gap: 0; }
.login-box { width: 100%; max-width: 360px; }
.logo { text-align: center; margin-bottom: 34px; }
.logo .mark { width: 64px; height: 64px; border-radius: 20px; background: var(--green);
  display: inline-flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.logo .mark svg { width: 36px; height: 36px; }
.logo h1 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.logo p { font-size: 13px; color: var(--muted); margin-top: 4px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 13px 14px; border: 1.5px solid var(--line); border-radius: 14px;
  background: var(--card); color: var(--ink); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green); }
.btn-primary {
  width: 100%; padding: 14px; border-radius: 14px; background: var(--green); color: #fff;
  font-size: 15px; font-weight: 800; margin-top: 6px;
}
.btn-primary:active { opacity: .85; }
.login-err { color: var(--red); font-size: 13px; font-weight: 600; margin-top: 12px; text-align: center; min-height: 18px; }

/* ── app frame ── */
.screen { flex: 1; display: none; flex-direction: column; overflow: hidden; }
.screen.active { display: flex; }
.scroll { flex: 1; overflow-y: auto; }
.hdr { padding: 18px 18px 8px; display: flex; align-items: flex-start; justify-content: space-between; }
.hdr .hi { font-size: 21px; font-weight: 800; letter-spacing: -.02em; }
.hdr .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.hdr .gear { padding: 6px; color: var(--faint); }
.hdr .gear svg { width: 22px; height: 22px; }

/* ── bottom tabs ── */
.tabbar {
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(10px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; font-weight: 600; color: var(--faint); padding: 4px 0;
}
.tabbar button.on { color: var(--green); }
.tabbar svg { width: 22px; height: 22px; }
.tabbar .tab-badge { position: relative; }
.tabbar .tab-badge[data-n]:not([data-n="0"])::after {
  content: attr(data-n); position: absolute; top: -4px; right: -10px;
  background: var(--red); color: #fff; font-size: 9px; font-weight: 800;
  border-radius: 10px; padding: 1px 5px; min-width: 15px;
}

/* ── dashboard ── */
.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px 14px 6px; }
.stat { background: var(--card); border-radius: 18px; padding: 14px 15px; box-shadow: var(--shadow); }
.stat .l { font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 5px; }
.stat .v { font-size: 27px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.stat .v small { font-size: 14px; color: var(--faint); font-weight: 700; }
.stat .s { font-size: 10.5px; margin-top: 5px; font-weight: 700; }
.stat.tappable:active { transform: scale(.98); }
.sect { padding: 12px 18px 6px; font-size: 11px; font-weight: 800; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em; display: flex; justify-content: space-between; align-items: baseline; }
.sect a { color: var(--green); font-size: 11px; text-decoration: none; letter-spacing: 0; text-transform: none; font-weight: 700; }
.minimap-wrap { margin: 2px 14px 14px; border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); position: relative; }
#minimap { height: 240px; z-index: 0; }
.minimap-cover { position: absolute; inset: 0; z-index: 400; }

/* ── map screen ── */
.map-wrap { flex: 1; position: relative; }
#bigmap { position: absolute; inset: 0; z-index: 0; }
.map-controls { position: absolute; top: 12px; right: 12px; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.map-btn {
  background: var(--card); border-radius: 14px; box-shadow: 0 2px 8px rgba(20,30,24,.18);
  padding: 10px; display: flex; align-items: center; justify-content: center; color: var(--ink);
}
.map-btn svg { width: 20px; height: 20px; }
.map-btn.on { background: var(--green); color: #fff; }
.draw-banner {
  position: absolute; top: 12px; left: 12px; right: 64px; z-index: 500;
  background: var(--green); color: #fff; border-radius: 14px; padding: 10px 14px;
  font-size: 12.5px; font-weight: 700; box-shadow: 0 2px 8px rgba(20,30,24,.25);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.draw-banner button { color: #fff; font-weight: 800; font-size: 12.5px; padding: 4px 8px;
  background: rgba(255,255,255,.18); border-radius: 8px; }

/* bottom sheet */
.sheet {
  background: var(--card); border-radius: 24px 24px 0 0; padding: 12px 18px 16px;
  box-shadow: var(--shadow-up); z-index: 600; position: relative;
}
.sheet .handle { width: 36px; height: 4px; background: var(--line); border-radius: 4px; margin: 0 auto 12px; }
.sheet .row1 { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet .nm { font-size: 17px; font-weight: 800; letter-spacing: -.02em; }
.sheet .meta { display: flex; gap: 15px; font-size: 11.5px; color: var(--muted); font-weight: 600; margin-bottom: 12px; flex-wrap: wrap; }
.sheet .meta b { color: var(--ink); }
.pills { display: flex; gap: 8px; }
.pill { background: var(--chip); border-radius: 12px; padding: 8px 0; font-size: 11px; flex: 1;
  text-align: center; color: var(--muted); font-weight: 700; }
.pill.on { background: var(--green); color: #fff; }
.sheet .hint { text-align: center; font-size: 12px; color: var(--faint); padding: 6px 0 10px; }

/* ── badges ── */
.badge { font-size: 10.5px; padding: 3px 10px; border-radius: 20px; font-weight: 800; display: inline-block; white-space: nowrap; }
.b-ok   { background: var(--green-soft); color: var(--green); }
.b-bad  { background: var(--red-soft);   color: var(--red); }
.b-warn { background: var(--amber-soft); color: var(--amber); }
.b-off  { background: var(--chip); color: #5B665E; }

/* ── alerts ── */
.ftabs { display: flex; background: var(--card); border-bottom: 1px solid var(--line); }
.ftab { flex: 1; text-align: center; padding: 11px 0 9px; font-size: 12px; color: var(--faint);
  font-weight: 700; border-bottom: 2.5px solid transparent; }
.ftab.on { color: var(--green); border-color: var(--green); }
.alitem { display: flex; gap: 12px; padding: 12px 16px; align-items: flex-start; border-bottom: 1px solid var(--line); background: var(--bg); }
.alitem .ic { width: 38px; height: 38px; border-radius: 14px; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; font-size: 17px; }
.alitem .t { font-size: 13.5px; font-weight: 800; }
.alitem .d { font-size: 11.5px; color: var(--muted); margin-top: 2px; font-weight: 500; }
.alitem .w { font-size: 10.5px; color: var(--faint); margin-top: 3px; }
.ack-btn { margin-left: auto; align-self: center; font-size: 11px; background: var(--chip);
  border-radius: 12px; padding: 7px 14px; color: #5B665E; font-weight: 800; flex-shrink: 0; }
.empty { text-align: center; color: var(--faint); font-size: 13px; padding: 44px 20px; font-weight: 600; }

/* ── animals ── */
.srchwrap { padding: 10px 14px 4px; }
.srchwrap input { width: 100%; padding: 11px 14px; border: none; border-radius: 16px;
  background: var(--card); box-shadow: var(--shadow); outline: none; font-size: 14px; color: var(--ink); }
.anrow { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--line); width: 100%; text-align: left; }
.anrow .av { width: 38px; height: 38px; border-radius: 14px; display: flex; align-items: center;
  justify-content: center; font-size: 11.5px; font-weight: 800; flex-shrink: 0; }
.anrow .nm { font-size: 13.5px; font-weight: 800; }
.anrow .zn { font-size: 11.5px; color: var(--muted); font-weight: 500; margin-top: 1px; }
.anrow .right { margin-left: auto; text-align: right; }
.anrow .batt { font-size: 11px; color: var(--muted); margin-top: 4px; font-weight: 600; }
.fab { position: absolute; right: 16px; bottom: 16px; width: 54px; height: 54px; border-radius: 18px;
  background: var(--green); color: #fff; font-size: 28px; font-weight: 400; box-shadow: 0 6px 18px rgba(31,107,74,.4);
  display: flex; align-items: center; justify-content: center; z-index: 50; }

/* ── modal ── */
.modal-bg { position: fixed; inset: 0; background: rgba(23,32,27,.45); z-index: 900;
  display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--card); border-radius: 24px 24px 0 0; padding: 18px 18px calc(20px + env(safe-area-inset-bottom));
  width: 100%; max-width: 520px; max-height: 86dvh; overflow-y: auto; }
.modal h3 { font-size: 17px; font-weight: 800; margin-bottom: 14px; letter-spacing: -.02em; }
.modal .btnrow { display: flex; gap: 10px; margin-top: 14px; }
.btn-secondary { flex: 1; padding: 13px; border-radius: 14px; background: var(--chip); color: #5B665E; font-size: 14px; font-weight: 800; }
.btn-primary.inrow { flex: 2; width: auto; margin: 0; }
.btn-danger { width: 100%; padding: 12px; border-radius: 14px; color: var(--red); background: var(--red-soft);
  font-size: 13px; font-weight: 800; margin-top: 10px; }
.modal .note { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.5; }
.err { color: var(--red); font-size: 12.5px; font-weight: 700; min-height: 16px; margin-top: 8px; }

/* history list inside detail modal */
.hist-row { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line);
  width: 100%; text-align: left; font-size: 13px; }
.hist-row .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green-map); flex-shrink: 0; }
.hist-row .when { font-weight: 700; }
.hist-row .coords { color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.hist-row .go { margin-left: auto; color: var(--green); font-weight: 800; font-size: 11.5px; }

/* fences list */
.fence-row { display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--line); }
.fence-row .sw { width: 16px; height: 16px; border-radius: 5px; flex-shrink: 0; }
.fence-row .nm { font-weight: 800; font-size: 13.5px; flex: 1; }
.fence-row button { font-size: 11.5px; font-weight: 800; padding: 6px 10px; border-radius: 10px; background: var(--chip); color: #5B665E; }
.fence-row button.del { color: var(--red); background: var(--red-soft); }

/* leaflet marker tweaks */
.animal-marker { border-radius: 50%; border: 2.5px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.45); }
.animal-marker.selected { outline: 3px solid rgba(31,107,74,.5); }
.gw-icon { background: var(--ink); border-radius: 6px; display: flex; align-items: center; justify-content: center;
  color: #fff; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); font-size: 10px; }
.hist-flag { border-radius: 50%; border: 3px solid #fff; background: #7C3AED; box-shadow: 0 1px 6px rgba(0,0,0,.5); }
.leaflet-container { font-family: inherit; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; background: var(--ink); color: #fff;
  border-radius: 14px; padding: 10px 18px; font-size: 13px; font-weight: 700; z-index: 999;
  box-shadow: 0 6px 20px rgba(0,0,0,.3); opacity: 0; transition: opacity .25s; pointer-events: none; }
.toast.show { opacity: 1; }

@media (min-width: 700px) {
  /* gentle desktop treatment: center a phone-width column */
  #app { max-width: 520px; margin: 0 auto; box-shadow: 0 0 40px rgba(20,30,24,.12); }
}
