:root {
  --accent: #c40f5f;
  --ink: #1a1a1a;
  --paper: #fff;
  --line: #c9c9c9;
  --ok: #1d6b2f;
  --warn: #8a5a00;
  --danger: #a11212;
  --tab-h: 72px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { font-size: 18px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 18px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
}
main {
  max-width: 34rem;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}
body.has-tabs main { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 1.5rem); }
h1 { font-size: 1.5rem; line-height: 1.25; margin: .5rem 0 1rem; }
h2 { font-size: 1.2rem; line-height: 1.3; margin: 2rem 0 .5rem; }
p { margin: 0 0 1rem; }
a { color: var(--accent); }
.meta { color: #4a4a4a; }

/* Forms */
label { display: block; font-weight: 700; margin: 1.25rem 0 .4rem; }
input[type=email], input[type=password], input[type=text], select {
  display: block; width: 100%; min-height: 56px; padding: .6rem .8rem;
  font: inherit; color: var(--ink); background: var(--paper);
  border: 2px solid var(--ink); border-radius: 10px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

/* Buttons: real buttons and links that look like them. At least 56 px tall. */
button, .button {
  display: flex; align-items: center; justify-content: center; text-align: center;
  width: 100%; min-height: 56px; margin-top: 1.25rem; padding: .6rem 1rem;
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  color: #fff; background: var(--accent); border: 2px solid var(--accent); border-radius: 10px;
}
button.secondary, .button.secondary { color: var(--accent); background: var(--paper); }
button.danger { color: var(--danger); background: var(--paper); border-color: var(--danger); }
.rows form button, .rows form .button { margin-top: .6rem; }

/* Messages */
.message { padding: .8rem 1rem; border-radius: 10px; border: 2px solid; margin: 0 0 1rem; }
.message.error { background: #fdeaea; border-color: var(--danger); color: #5a0a0a; }
.message.notice { background: #eaf5ec; border-color: var(--ok); color: #123a1e; }

/* Lists */
ul.rows { list-style: none; margin: 0; padding: 0; }
ul.rows li { padding: 1rem 0; border-top: 2px solid var(--line); }
ul.rows li:last-child { border-bottom: 2px solid var(--line); }
.rows p { margin: 0; }
.share { border: 2px solid var(--ok); border-radius: 10px; padding: 0 1rem 1rem; margin-bottom: 1rem; }

/* Badges and cards */
.badge {
  display: inline-block; padding: .1rem .7rem; font-weight: 700; font-size: 1rem;
  color: var(--ink); background: var(--paper); border: 2px solid var(--ink); border-radius: 999px;
}
.card { border: 2px solid var(--line); border-radius: 10px; padding: 1rem; margin-bottom: 1rem; }
.empty { border: 2px dashed var(--line); border-radius: 10px; padding: 1.5rem 1rem; }
.stack-links { list-style: none; margin: 0 0 1rem; padding: 0; }
.stack-links a.button { margin-top: .75rem; }
.error-page { padding-top: 1rem; }

/* Bottom tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; background: var(--paper); border-top: 3px solid var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1 1 0; min-width: 0; min-height: var(--tab-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--ink); text-decoration: none; font-weight: 700; font-size: 1rem; line-height: 1.2;
  border-right: 2px solid var(--line);
}
.tabs a:last-child { border-right: 0; }
.tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
/* The current tab is filled, bold and has a bar on top: not colour alone. */
.tabs a[aria-current="page"] { color: #fff; background: var(--accent); box-shadow: inset 0 5px 0 var(--ink); }

/* Install nudge (iOS Safari, not yet on the Home Screen) */
.nudge {
  padding: .8rem 1rem; padding-top: max(.8rem, env(safe-area-inset-top));
  color: var(--ink); background: #fff3d6; border-bottom: 3px solid var(--warn);
}
.nudge p { margin: 0 auto; max-width: 34rem; }
.nudge button { max-width: 34rem; margin: .6rem auto 0; color: var(--ink); background: var(--paper); border-color: var(--ink); }
.signout { margin-top: 2rem; padding-top: 1rem; border-top: 2px solid var(--line); }
.signout p { margin: 0; }
.signout button { margin-top: .5rem; }

/* ==========================================================================================
   M2 shared screen styles (ported from the prototype, practice banner and Reset left out).
   Screen builders use these class names and put anything screen-specific in their own
   template's <style> block. Do not add global rules after this section.

   Class index
   - Tokens:        --muted --soft --line-strong --toast-h (added to :root below)
   - Chips:         .chips (scroll row)  .chip  .chip[aria-pressed=true]  .chip .count
   - Herd rows:     .list  a.herd-row  .herd-tag (.num .col .dot .tc)  .herd-mid  .herd-l1  .herd-l2
                    .pill  .pill.why (trailing reason, dashed)  .chev  .list-summary  .empty
   - Cards:         .card (existing)  .card.strong  .panel-title  .facts (dl)  .sect
   - Sheets:        .sheet-scrim  .sheet  .sheet-title  .sheet-sub  .sheet-actions (pinned Save / Cancel)
   - Keypad:        .keypad  .kp-head  .kp-q (.ph .caret)  .kp-done  .kp-sub  .keys  .key  .key.fn  .key.wide
   - Toast:         #toast  .toast-msg  .toast-undo  (body.toast-on pushes the page down: never covers a button)
   - Save bar:      .savebar (sticky bottom, above the tab bar)  .savebar .hint
   - Fields:        .field  textarea.field  .field-label  .money  .hint  .linkbtn  .spacer
   - Choices:       .choice-row (2 up)  .choice-row.three  .choice  .choice[aria-pressed=true]  .choice.big
                    .choice.here (dashed)  .choice small
   ========================================================================================== */
:root {
  --muted: #4a4a4a;
  --soft: #f4f4f2;
  --line-strong: #6b6b6b;
  --toast-h: 56px;
}
.sect { font-size: 1.1rem; font-weight: 800; margin: 1.4rem 0 .5rem; }

/* Buttons that are not the full-width page button: undo the global `button` rule. */
.chip, .key, .choice, .toast-undo, .linkbtn, .kp-done {
  width: auto; margin: 0; font: inherit; cursor: pointer; touch-action: manipulation;
}

/* Filter chips */
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 1rem 10px; margin: 0 -1rem;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 56px; display: inline-flex; align-items: center; gap: 8px; padding: 0 20px;
  color: var(--ink); background: var(--paper); border: 2px solid var(--ink); border-radius: 28px;
  font-weight: 700; white-space: nowrap; text-decoration: none;
}
.chip[aria-pressed="true"], .chip[aria-current="true"] { color: #fff; background: var(--accent); border-color: var(--accent); }
.chip .count { font-weight: 800; }

/* Herd rows */
.list { margin: 0 -1rem; background: var(--paper); }
.list-summary {
  padding: 8px 1rem; font-size: .9rem; font-weight: 700; color: var(--muted); background: var(--soft);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.herd-row {
  display: grid; grid-template-columns: 96px 1fr 24px; align-items: center; gap: 6px; min-height: 80px;
  padding: 10px 12px 10px 1rem; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit;
}
.herd-row:active { background: var(--soft); }
.herd-tag { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; line-height: 1.1; }
.herd-tag .num { font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.herd-tag .col { font-size: 20px; font-weight: 800; }
.herd-tag .tc { flex: 0 0 100%; display: flex; align-items: center; gap: 6px; font-size: .9rem; font-weight: 700; line-height: 1.2; }
.dot { display: inline-block; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink); vertical-align: 2px; flex: none; }
.herd-mid { min-width: 0; }
.herd-l1 { font-weight: 700; line-height: 1.25; }
.herd-l1 span { font-weight: 500; color: var(--muted); }
.herd-l2 { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 4px; color: var(--muted); }
.pill {
  display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border: 1.5px solid var(--line-strong);
  border-radius: 14px; font-size: .9rem; font-weight: 600; color: var(--ink); background: var(--paper);
}
.pill.why { background: var(--soft); border-style: dashed; }
.chev { color: var(--line-strong); }
.empty { text-align: center; color: var(--muted); }

/* Cards and facts */
.card.strong { border-color: var(--ink); border-radius: 14px; }
.panel-title { font-size: 1.2rem; font-weight: 800; margin: 0 0 .5rem; }
.facts { margin: .8rem 0 0; padding: .7rem 0 0; border-top: 2px solid var(--line); display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; }
.facts dt { color: var(--muted); font-weight: 600; }
.facts dd { margin: 0; font-weight: 700; min-width: 0; }

/* Bottom sheets: a scrim and a panel pinned to the bottom edge; Save / Cancel stay on screen. */
.sheet-scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 80; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90; max-width: 34rem; margin: 0 auto; max-height: 92%; overflow-y: auto;
  background: var(--paper); border: 2px solid var(--ink); border-bottom: 0; border-radius: 18px 18px 0 0;
  padding: 14px 1rem calc(14px + env(safe-area-inset-bottom));
}
.sheet-title { margin: 0 0 10px; font-size: 1.25rem; }
.sheet-sub { margin: 0 0 12px; color: var(--muted); }
.sheet label { margin: 10px 0 6px; }
.sheet-actions {
  position: sticky; bottom: calc(-14px - env(safe-area-inset-bottom)); z-index: 2;
  margin: 12px -1rem calc(-14px - env(safe-area-inset-bottom)); padding: 10px 1rem calc(14px + env(safe-area-inset-bottom));
  background: var(--paper); border-top: 2px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.sheet-actions button, .sheet-actions .button { margin: 0; }

/* Custom keypad (no system keyboard for tag numbers) */
.keypad { z-index: 90; box-shadow: 0 -6px 18px rgba(0, 0, 0, .18); }
.kp-head { display: flex; gap: 10px; align-items: center; }
.kp-q {
  flex: 1; min-width: 0; min-height: 60px; display: flex; align-items: center; padding: 0 4px;
  font-size: 40px; font-weight: 800; letter-spacing: 2px; overflow: hidden; white-space: nowrap;
}
.kp-q .ph { font-size: 1.1rem; font-weight: 500; letter-spacing: 0; color: var(--muted); }
.kp-q .caret { display: inline-block; width: 3px; height: 36px; background: var(--accent); margin-left: 2px; }
.kp-done {
  flex: none; min-width: 92px; min-height: 56px; border: 2px solid var(--accent); border-radius: 14px;
  background: var(--accent); color: #fff; font-weight: 800; font-size: 1.1rem;
}
.kp-sub { font-size: .9rem; font-weight: 700; color: var(--muted); margin: 0 4px 8px; min-height: 22px; }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key { min-height: 60px; border: 2px solid var(--ink); border-radius: 12px; background: var(--paper); color: var(--ink); font-size: 28px; font-weight: 800; }
.key:active { background: var(--soft); }
.key.fn { font-size: 1.1rem; background: var(--soft); }
.key.wide { grid-column: 1 / -1; }
@media (max-height: 760px) {
  .keys { gap: 6px; }
  .key { min-height: 56px; }
  .kp-q { min-height: 52px; font-size: 36px; }
}
@media (max-height: 600px) { .key { font-size: 26px; } .kp-sub { display: none; } }  /* keys stay 56 px: the tap-target floor */

/* Toast strip: the one place every toast lives, at the very top of the screen. While it shows,
   body.toast-on pushes the page down by its height, so it never covers a page button. */
#toast {
  position: fixed; left: 0; right: 0; top: 0; z-index: 100; display: flex; align-items: stretch; justify-content: center;
  min-height: calc(var(--toast-h) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top);
  background: var(--ink); color: #fff; border-bottom: 2px solid var(--warn); font-weight: 700; line-height: 1.2;
}
#toast[hidden] { display: none; }
.toast-msg { flex: 1; max-width: 34rem; display: flex; align-items: center; padding: 4px 1rem; }
.toast-undo {
  flex: none; min-width: 92px; min-height: var(--toast-h); padding: 0 16px; border: 0; border-left: 2px solid var(--warn); border-radius: 0;
  background: #fff; color: var(--ink); font-weight: 800; text-decoration: underline; text-underline-offset: 3px;
}
.toast-undo[hidden] { display: none; }
body.toast-on { padding-top: calc(var(--toast-h) + env(safe-area-inset-top)); }

/* Sticky bottom Save bar (sits above the tab bar when there is one) */
.savebar {
  position: sticky; bottom: 0; z-index: 20; margin: 1.5rem -1rem 0; padding: 8px 1rem; background: var(--paper); border-top: 2px solid var(--line);
}
body.has-tabs .savebar { bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
.savebar .hint { margin: 0 0 6px; }
.savebar button { margin-top: 0; min-height: 64px; font-size: 1.25rem; }

/* Form fields */
.field {
  display: block; width: 100%; min-height: 56px; padding: 0 14px; border: 2px solid var(--ink); border-radius: 12px;
  background: var(--paper); font: inherit; font-size: 1.1rem; color: var(--ink);
}
textarea.field { padding: 12px 14px; min-height: 130px; resize: none; line-height: 1.35; }
.money { display: flex; align-items: center; gap: 8px; }
.money span { font-size: 1.3rem; font-weight: 800; }
.hint { margin: 8px 0 0; font-weight: 700; color: var(--accent); }
.spacer { height: 12px; }
.linkbtn {
  display: inline-flex; align-items: center; min-height: 56px; padding: 0 4px; border: 0; background: transparent;
  font-weight: 800; color: var(--accent); text-decoration: underline; text-underline-offset: 3px;
}

/* Big choice buttons (BULL / HEIFER, pens, yes / no) */
.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.choice-row.three { grid-template-columns: 1fr 1fr 1fr; }
.choice {
  display: flex; align-items: center; justify-content: center; text-align: center; width: 100%; min-height: 60px; padding: 0 12px;
  color: var(--ink); background: var(--paper); border: 2px solid var(--ink); border-radius: 14px; font-weight: 700;
}
.choice[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.choice.big { min-height: 72px; font-size: 1.4rem; letter-spacing: .5px; }
.choice.here { background: var(--soft); border-style: dashed; }
.choice small { font-weight: 600; font-size: .9rem; margin-left: 8px; color: var(--muted); }
.choice[aria-pressed="true"] small { color: #ddd; }
.choice[disabled] { opacity: .45; }
