:root {
  color-scheme: light;
  --bg: #edf1ec;
  --surface: #ffffff;
  --surface-2: #f4f7f3;
  --ink: #16241c;
  --ink-2: #56665c;
  --line: #d8e0d9;
  --primary: #1e5e4e;
  --primary-ink: #ffffff;
  --primary-soft: #dcebe4;
  --sun: #d99a12;
  --sun-soft: #fbefd0;
  --sun-ink: #7a5200;
  --sky: #2f5e8c;
  --sky-soft: #dde8f3;
  --danger: #b3402a;
  --danger-soft: #f6e0db;
  --shadow: 0 1px 2px rgba(22, 36, 28, 0.06), 0 4px 16px rgba(22, 36, 28, 0.06);
  --radius-lg: 20px;
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', Ubuntu, sans-serif;
  --tabbar-h: 64px;
  --header-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1612;
    --surface: #17221c;
    --surface-2: #1e2b24;
    --ink: #e5eee8;
    --ink-2: #98a99f;
    --line: #29382f;
    --primary: #62b99e;
    --primary-ink: #0b1a14;
    --primary-soft: #1e382f;
    --sun: #f0bc45;
    --sun-soft: #3a3018;
    --sun-ink: #f3c560;
    --sky: #7fb0e0;
    --sky-soft: #1c2c3c;
    --danger: #e3735c;
    --danger-soft: #3d221c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 2px; }
svg.i { width: 22px; height: 22px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
#app { height: 100%; display: flex; flex-direction: column; max-width: 640px; margin: 0 auto; position: relative; }
.header {
  flex: none;
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 12px 0 16px;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg);
  position: relative; z-index: 5;
}
.header h1 { font-size: 22px; font-weight: 750; letter-spacing: -0.02em; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--ink); }
.icon-btn:active { background: var(--line); }

.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px calc(var(--tabbar-h) + 96px + env(safe-area-inset-bottom, 0px)); }

.tabbar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
}
.tab { text-decoration: none; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.tab .pill-bg { width: 56px; height: 30px; border-radius: 15px; display: grid; place-items: center; transition: background .2s; }
.tab[aria-current='page'] { color: var(--ink); }
.tab[aria-current='page'] .pill-bg { background: var(--primary-soft); color: var(--primary); }

.fab {
  position: absolute; right: 16px; z-index: 6;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom, 0px));
  height: 56px; padding: 0 20px 0 16px; border-radius: 18px;
  display: flex; align-items: center; gap: 8px;
  background: var(--primary); color: var(--primary-ink); font-weight: 650;
  box-shadow: 0 6px 20px rgba(30, 94, 78, 0.35);
}
.fab:active { transform: scale(0.97); }

/* ---------- sync status: the one loud element ---------- */
.sync {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 12px 0 10px; border-radius: 17px;
  font-size: 13px; font-weight: 650; white-space: nowrap;
  background: var(--primary-soft); color: var(--primary);
}
.sync .dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.sync.pending { background: var(--sun-soft); color: var(--sun); }
.sync.offline { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.sync.offline .dot { background: transparent; border: 2px solid currentColor; }
.sync.error { background: var(--danger-soft); color: var(--danger); }
.sync.busy .dot { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(0.5); opacity: 0.5; } }

/* ---------- lists ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; scrollbar-width: none; }
.chip {
  flex: none; height: 36px; padding: 0 14px; border-radius: 18px; font-size: 14px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
}
.chip[aria-pressed='true'] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.group-title { font-size: 13px; font-weight: 700; color: var(--ink-2); margin: 18px 4px 8px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.list { display: flex; flex-direction: column; gap: 8px; }

.item { display: flex; gap: 10px; padding: 14px 10px 14px 16px; align-items: center; text-align: left; width: 100%; color: inherit; text-decoration: none; }
.item:active { background: var(--surface-2); }
.item > svg.i { color: var(--ink-2); flex: none; }
.item-body { flex: 1; min-width: 0; }
.item-title { font-weight: 650; font-size: 17px; overflow-wrap: anywhere; }
.item-title .sub, .detail-title .sub { font-weight: 500; font-size: 14px; color: var(--ink-2); }
.detail-title .sub { display: block; margin-top: 2px; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; font-size: 13px; color: var(--ink-2); align-items: center; }
.meta span { display: inline-flex; align-items: center; gap: 4px; }
.meta svg.i { width: 15px; height: 15px; }
.meta .late { color: var(--danger); font-weight: 600; }
.meta .warn { color: var(--sun-ink); font-weight: 600; }
.unsent { width: 8px; height: 8px; border-radius: 50%; background: var(--sun); flex: none; margin-top: 7px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--primary-soft); color: var(--primary); flex: none; }
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }

.empty { text-align: center; padding: 56px 24px; color: var(--ink-2); }
.empty svg.i { width: 40px; height: 40px; stroke-width: 1.5; margin-bottom: 8px; }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.empty .btn svg.i { width: 20px; height: 20px; stroke-width: 2; margin: 0; }

/* ---------- rows (settings-style) ---------- */
.rows { overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; min-height: 52px; width: 100%; text-align: left; }
.row + .row { border-top: 1px solid var(--line); }
button.row:active { background: var(--surface-2); }
.row .label { flex: 1; min-width: 0; }
.row .label small { display: block; color: var(--ink-2); font-size: 13px; }
.row .value { color: var(--ink-2); text-align: right; overflow-wrap: anywhere; max-width: 60%; }
.row .chev { color: var(--ink-2); width: 18px; height: 18px; }

/* ---------- detail ---------- */
.detail-title { font-size: 24px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.2; margin: 6px 0 14px; overflow-wrap: anywhere; text-align: left; width: 100%; }
.segmented { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 16px; }
.segmented button { flex: 1; height: 38px; border-radius: 9px; font-size: 14px; font-weight: 650; color: var(--ink-2); }
.segmented button[aria-pressed='true'] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; }

.files { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile {
  aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden; position: relative;
  background: var(--surface-2); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 12px; color: var(--ink-2); text-align: center; padding: 6px;
}
.tile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile .badge { position: absolute; right: 6px; bottom: 6px; background: var(--sun); color: #1c1404; border-radius: 10px; padding: 2px 7px; font-size: 11px; font-weight: 700; }
.tile .fname { overflow-wrap: anywhere; max-height: 3em; overflow: hidden; }
.tile.add { border-style: dashed; color: var(--primary); font-weight: 650; background: transparent; }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.input { width: 100%; height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); }
textarea.input { height: auto; min-height: 96px; padding: 12px 14px; resize: vertical; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.btn { height: 50px; border-radius: 14px; padding: 0 20px; font-weight: 650; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.quiet { background: var(--surface-2); border: 1px solid var(--line); }
.btn.danger { color: var(--danger); background: var(--danger-soft); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; }
.form-error { color: var(--danger); font-size: 14px; margin: -4px 0 12px; }
.hint { font-size: 13px; color: var(--ink-2); }

.switch { width: 52px; height: 32px; border-radius: 16px; background: var(--line); position: relative; flex: none; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch[aria-checked='true'] { background: var(--sun); }
.switch[aria-checked='true']::after { transform: translateX(20px); }

/* ---------- sign-in ---------- */
.auth { min-height: 100%; display: flex; flex-direction: column; justify-content: center; padding: 32px 24px calc(32px + env(safe-area-inset-bottom, 0px)); max-width: 420px; margin: 0 auto; }
.auth .mark { width: 56px; height: 56px; border-radius: 16px; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; margin-bottom: 20px; }
.auth .mark svg.i { width: 30px; height: 30px; }
.auth h2 { font-size: 28px; letter-spacing: -0.02em; margin: 0 0 6px; line-height: 1.15; }
.auth p.lead { color: var(--ink-2); margin: 0 0 28px; }

/* ---------- sheets ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(8, 14, 11, 0.45); z-index: 20; opacity: 0; transition: opacity .22s; }
.backdrop.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 640px; margin: 0 auto;
  max-height: 92%; overflow-y: auto; background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 8px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1);
}
.sheet.open { transform: none; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { font-size: 20px; margin: 0 0 16px; letter-spacing: -0.01em; }

.toast {
  position: fixed; left: 50%; z-index: 40; bottom: calc(var(--tabbar-h) + 88px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 20px); opacity: 0; transition: all .25s;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-size: 14px; font-weight: 550;
  max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.25); pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }

.viewer { position: fixed; inset: 0; z-index: 30; background: #000; display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: 100%; }
.viewer .icon-btn { position: absolute; top: calc(8px + env(safe-area-inset-top, 0px)); right: 8px; color: #fff; }

.slide-in { animation: slideIn .24s cubic-bezier(.2, .8, .2, 1); }
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } }

.stat { display: flex; gap: 8px; margin: 4px 0 16px; }
.stat > div, .stat > a { flex: 1; min-width: 0; padding: 12px 14px; }
.stat > a { color: inherit; text-decoration: none; }
.stat b { overflow-wrap: anywhere; }
.stat b { display: block; font-size: 22px; letter-spacing: -0.02em; }
.stat small { color: var(--ink-2); font-size: 13px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Amounts in F CFA never break across lines ("125 000 F"). */
.money { white-space: nowrap; font-variant-numeric: tabular-nums; }
.segmented button:disabled { opacity: .6; cursor: default; }
/* Visible keyboard focus everywhere. */
:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }
/* Sheets that are closing (or not open yet) never capture taps. */
.backdrop:not(.open), .sheet:not(.open) { pointer-events: none; }

/* ---------- settings, error reports, history ---------- */
.block-btn { display: block; width: 100%; text-align: left; padding: 0; }
.block-btn:active { background: var(--surface-2); }
a.row { color: inherit; text-decoration: none; }
.callout { background: var(--sun-soft); color: var(--ink); border-radius: var(--radius-sm); padding: 10px 14px; margin: 4px 0 8px; }
.optional { font-style: normal; font-weight: 500; color: var(--ink-2); font-size: 13px; }
.status { flex: none; font-size: 12px; font-weight: 700; border-radius: 10px; padding: 3px 9px; background: var(--surface-2); color: var(--ink-2); }
.status.pending { background: var(--sun-soft); color: var(--sun-ink); }
.status.done { background: var(--primary-soft); color: var(--primary); }
.status.refused { background: var(--danger-soft); color: var(--danger); }
.flag-note { display: flex; align-items: center; gap: 8px; background: var(--sun-soft); color: var(--sun-ink); border-radius: var(--radius-sm); padding: 8px 12px; margin: 4px 0 8px; font-size: 14px; font-weight: 600; }
.flag-note svg.i { width: 16px; height: 16px; flex: none; }
.row.todo { border-top: 1px solid var(--line); color: var(--sun-ink); font-weight: 600; min-height: 44px; }
.row.todo svg.i { width: 18px; height: 18px; }
.btn svg.i { width: 18px; height: 18px; }
fieldset[disabled] .input { opacity: .75; }
.hist { padding: 12px 0; }
.hist + .hist { border-top: 1px solid var(--line); }
.hist .who { font-size: 13px; color: var(--ink-2); }
.hist .who b { color: var(--ink); font-weight: 650; }
.hist p { margin: 2px 0 0; overflow-wrap: anywhere; }

/* ---------- livestock ---------- */
h2.section { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--primary); margin: 22px 4px 0; font-weight: 750; }
h2.section:first-of-type { margin-top: 8px; }
.stat b.small { font-size: 16px; line-height: 1.25; overflow-wrap: anywhere; }
.row .value small { display: block; font-size: 12px; }
.row .value small.late, .row .label small.late, small.late { color: var(--danger); font-weight: 600; }
.row .btn.small { height: 34px; padding: 0 12px; font-size: 13px; flex: none; }
.btn.big { height: 56px; font-size: 17px; }
.btn svg.i { width: 20px; height: 20px; }
.actions { display: grid; gap: 8px; margin: 4px 0 8px; }
.callout.bad { background: var(--danger-soft); }
.clock-warn { flex: none; margin: 0 16px 8px; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--ink); font-weight: 600; }
.verdict { display: flex; gap: 10px; align-items: center; border-radius: var(--radius-sm); padding: 12px 14px; margin: 4px 0 14px; font-weight: 650; }
.verdict.ok { background: var(--primary-soft); color: var(--primary); }
.verdict.bad { background: var(--danger-soft); color: var(--danger); }
.verdict svg.i { flex: none; width: 22px; height: 22px; stroke-width: 2.6; }
.young .row { gap: 8px; padding: 8px 10px; }
.young .input { margin: 0; }
.young .input.tag { flex: 1.2; min-width: 0; font-variant-numeric: tabular-nums; }
.young select.input { flex: 1; min-width: 0; }
.chip svg.i { width: 15px; height: 15px; vertical-align: -2px; margin-right: 4px; }

/* ---------- stock and feed ---------- */
.row a.label { color: inherit; text-decoration: none; }
.status svg.i { width: 13px; height: 13px; vertical-align: -2px; margin-right: 3px; stroke-width: 3; }
small.warn { color: var(--sun-ink); font-weight: 600; }
.photo-pair { grid-template-columns: 1fr 1fr; }
.photo-slot span { position: relative; }
.photo-slot svg.i { position: relative; }
.photo-slot.done { border-style: solid; color: #fff; }
.photo-slot.done span { background: rgba(0, 0, 0, .6); border-radius: 8px; padding: 2px 8px; }
.photo-slot.done svg.i { display: none; }
.handover .row { gap: 10px; padding: 10px 12px; }
.handover .input { margin: 0; }
.handover .input.bags-n { width: 72px; flex: none; text-align: center; }
.handover select.input { flex: 1; min-width: 0; }
.bag-state { flex-wrap: wrap; }
.bag-state button { flex: 1 1 40%; }

/* Money */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 16px; }
.tile-btn { display: flex; align-items: center; gap: 10px; padding: 14px; min-height: 56px; font: inherit; font-weight: 600; color: var(--ink); text-align: left; }
.tile-btn .i { color: var(--primary); flex: none; }
.stat b.neg, .row .value.neg { color: var(--danger); }
.row .value.pos { color: var(--primary); }
.total { margin: 0 4px 14px; font-weight: 600; }
.total b.late { color: var(--danger); }

/* Field work: the roll call */
.row.roll { gap: 10px; }
.row.roll .segmented { margin: 0; flex: none; }
.segmented.small button { height: 34px; padding: 0 10px; font-size: 13px; }

/* The weekly report as it will be sent: plain text, wrapped, selectable. */
.report-text { margin: 0; padding: 14px; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink); user-select: text; -webkit-user-select: text; }

/* Collar labels: a grid on screen, about 6 x 3 cm each on paper. */
.qr-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.qr-label { display: flex; align-items: center; gap: 8px; padding: 8px; background: #fff; color: #111; border: 1px dashed #9aa; border-radius: 8px; break-inside: avoid; }
.qr-label svg.qr { width: 72px; height: 72px; flex: none; }
.qr-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.qr-text b { font-size: 20px; letter-spacing: -0.01em; line-height: 1.1; }
.qr-text small { font-size: 12px; color: #444; }
.qr-colour { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; }
.qr-colour i { width: 22px; height: 12px; border-radius: 3px; border: 1px solid #555; }
.scan-box { position: relative; border-radius: 14px; overflow: hidden; background: #000; aspect-ratio: 1; }
.scan-box video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 18%; border: 3px solid #fff; border-radius: 12px; box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.35); pointer-events: none; }
@media print {
  @page { margin: 10mm; }
  body { background: #fff !important; }
  .header, .tabbar, .fab, .no-print, #toast, .backdrop, .sheet { display: none !important; }
  #app, .content { display: block !important; height: auto !important; overflow: visible !important; max-width: none !important; padding: 0 !important; }
  .qr-sheet { grid-template-columns: repeat(3, 60mm); gap: 4mm; }
  .qr-label { height: 28mm; box-sizing: border-box; border-color: #999; }
  .qr-label svg.qr { width: 24mm; height: 24mm; }
}
