/*
 * Lot-master stylesheet. Mobile first: everything is one column on a phone and
 * widens on a tablet/desktop. Touch targets are at least 44px high (Apple/
 * Google guidance) because people use this with gloves and dirty hands.
 * Served from /static so the Content-Security-Policy can forbid inline styles
 * and scripts entirely.
 */
/* Brand: concept B "the brand", a branding-iron LM in rust (see
   public/brand/). Wordmark face Alfa Slab One, self-hosted under /static/fonts
   because the CSP only allows fonts from this site. Neutrals lean warm toward
   the rust; semantic ok/warn/bad colours stay separate from the brand. */
@font-face {
  font-family: "Alfa Slab One";
  src: url("/static/fonts/alfa-slab-one.woff2") format("woff2");
  font-display: swap;
}
:root {
  --ink: #2a1d17; --muted: #6b5d55; --line: #e2dad3; --bg: #f6f3f0; --card: #fff;
  --brand: #9a3d20; --brand-dark: #7a2f17; --brand-ink: #fff; --ok: #1e7a34; --warn: #a35a00; --bad: #b3261e;
  --font-brand: "Alfa Slab One", Georgia, "Times New Roman", serif;
  --ok-bg: #e5f3e8; --warn-bg: #fdf1df; --bad-bg: #fbe7e5;
  --radius: 10px; --tap: 44px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); }
h1 { font-size: 1.35rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
p { margin: .4rem 0; }
small, .muted { color: var(--muted); }

/* ── Top bar + menu ─────────────────────────────────────────────────── */
.top { position: sticky; top: 0; z-index: 10; background: var(--brand); color: var(--brand-ink); display: flex; align-items: center; gap: .5rem; padding: .4rem .75rem; }
.top .brand { color: var(--brand-ink); text-decoration: none; margin-right: auto; padding: .4rem 0; display: flex; align-items: center; gap: .5rem; font: 1.2rem/1 var(--font-brand); letter-spacing: .01em; }
.top .brand img { width: 34px; height: auto; }
.top .brand .wordmark { white-space: nowrap; }
/* On a phone the search box needs the room: the mark alone carries the brand. */
@media (max-width: 520px) { .top .brand .wordmark { display: none; } }
.top form.search { display: flex; flex: 1 1 auto; max-width: 340px; }
.top form.search input { flex: 1; min-width: 0; border: 0; border-radius: var(--radius) 0 0 var(--radius); }
.top form.search button { border-radius: 0 var(--radius) var(--radius) 0; background: var(--brand-dark); }
details.menu { position: relative; }
details.menu summary { list-style: none; cursor: pointer; min-height: var(--tap); min-width: var(--tap); display: flex; align-items: center; justify-content: center; font-size: 1.4rem; }
details.menu summary::-webkit-details-marker { display: none; }
details.menu nav { position: absolute; right: 0; top: 100%; background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.15); min-width: 230px; padding: .4rem; }
details.menu nav a { display: block; padding: .7rem .8rem; border-radius: 8px; color: var(--ink); text-decoration: none; }
details.menu nav a:hover, details.menu nav a:focus { background: var(--bg); }
details.menu nav .who { border-top: 1px solid var(--line); margin-top: .3rem; padding: .6rem .8rem; font-size: .85rem; color: var(--muted); }

main { padding: .9rem; max-width: 1100px; margin: 0 auto; }

/* ── Cards, tiles, pills ─────────────────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem; margin-bottom: .9rem; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; margin-bottom: .9rem; }
.tile { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; text-decoration: none; color: var(--ink); min-height: 76px; }
.tile b { display: block; font-size: 1.6rem; line-height: 1.1; }
.tile span { color: var(--muted); font-size: .85rem; }
.tile.warn { border-color: #f0c98a; background: var(--warn-bg); }
.tile.bad { border-color: #efb3ad; background: var(--bad-bg); }
.pill { display: inline-block; padding: .05rem .55rem; border-radius: 999px; font-size: .8rem; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); border-color: #b8dcc0; }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: #f0c98a; }
.pill.bad { background: var(--bad-bg); color: var(--bad); border-color: #efb3ad; }
.flash { padding: .75rem .9rem; border-radius: var(--radius); margin-bottom: .9rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.bad { background: var(--bad-bg); color: var(--bad); }
.block { border: 2px solid var(--bad); background: var(--bad-bg); border-radius: var(--radius); padding: 1rem; margin-bottom: .9rem; }
.block h2 { color: var(--bad); margin-top: 0; }

/* ── Key/value list (animal card) ────────────────────────────────────── */
dl.kv { display: grid; grid-template-columns: 9.5rem 1fr; gap: .35rem .75rem; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-weight: 500; }

/* ── Forms ───────────────────────────────────────────────────────────── */
form.stack { display: grid; gap: .8rem; }
.field label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
.field .err { color: var(--bad); font-size: .85rem; margin-top: .2rem; }
.field.has-err input, .field.has-err select { border-color: var(--bad); }
input, select, textarea, button, .btn { font: inherit; min-height: var(--tap); }
input, select, textarea { width: 100%; padding: .55rem .65rem; border: 1px solid #cbbfb5; border-radius: 8px; background: #fff; color: var(--ink); }
textarea { min-height: 80px; }
input[type="checkbox"] { width: 1.4rem; height: 1.4rem; min-height: 0; vertical-align: middle; }
.check { display: flex; align-items: center; gap: .6rem; min-height: var(--tap); }
button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1.1rem; border: 0; border-radius: 8px; background: var(--brand); color: var(--brand-ink); cursor: pointer; text-decoration: none; font-weight: 600; }
button.secondary, .btn.secondary { background: #ece4dd; color: var(--ink); }
/* Danger is outlined so it never looks like the rust primary button. */
button.danger, .btn.danger { background: var(--card); color: var(--bad); box-shadow: inset 0 0 0 2px var(--bad); }
button.small, .btn.small { min-height: 36px; padding: .3rem .7rem; font-size: .9rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .6rem 0; }
.grid2, .grid3 { display: grid; gap: .8rem; grid-template-columns: 1fr; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem; margin: 0; }
legend { padding: 0 .3rem; color: var(--muted); font-size: .85rem; }

/* ── Tables: scroll inside their own box, never the page ─────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #f1ebe5; color: var(--muted); font-weight: 600; font-size: .8rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.voided td { color: var(--muted); text-decoration: line-through; }
tr:last-child td { border-bottom: 0; }

/* Lists of animals on a phone: tappable rows. */
ul.rows { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
ul.rows li { border-bottom: 1px solid var(--line); }
ul.rows li:last-child { border-bottom: 0; }
ul.rows a { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .7rem .8rem; min-height: var(--tap); color: var(--ink); text-decoration: none; }
ul.rows a .meta { color: var(--muted); font-size: .85rem; text-align: right; }

/* ── Wider screens ───────────────────────────────────────────────────── */
@media (min-width: 700px) {
  main { padding: 1.25rem; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .grid2 { grid-template-columns: 1fr 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr 1fr; }
  h1 { font-size: 1.55rem; }
}
@media print {
  .top, .actions, form.no-print { display: none !important; }
  body { background: #fff; }
  .card, .table-wrap { border: 0; }
}

/* Radio buttons (medicine dose rule) get the same touch size as checkboxes. */
input[type="radio"] { width: 1.4rem; height: 1.4rem; min-height: 0; vertical-align: middle; }

/* ── Sign-in brand block ─────────────────────────────────────────────── */
.login-brand { display: flex; align-items: center; gap: .7rem; margin-bottom: .4rem; }
.login-brand img { width: 64px; height: auto; }
.login-brand h1 { font: 2rem/1 var(--font-brand); color: var(--brand); margin: 0; letter-spacing: .01em; }

/* ── Platform admin working inside a farm ────────────────────────────── */
.acting { background: #2a1d17; color: #f6f3f0; font-size: .9rem; padding: .45rem max(16px, env(safe-area-inset-left, 0px)); }
.acting a { color: #f2b49b; }

/* ── Platform: feedlot cards ─────────────────────────────────────────── */
.farms { display: grid; gap: .7rem; grid-template-columns: 1fr; }
@media (min-width: 700px) { .farms { grid-template-columns: 1fr 1fr; } }
.farm { margin-bottom: 0; }
.farm-head { display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
.farm-head b { font-size: 1.05rem; }
.farm .actions { margin-bottom: 0; }

/* Home: "Getting started" checklist for a feedlot that isn't set up yet */
.setup { border-color: var(--brand); border-width: 2px; }
.setup-steps { list-style: none; padding: 0; margin: .6rem 0 .9rem; }
.setup-steps li { display: grid; grid-template-columns: 1.6rem 1fr; column-gap: .3rem; padding: .45rem 0; border-top: 1px solid var(--line); }
.setup-steps li:first-child { border-top: 0; }
.setup-steps .mark { grid-row: span 2; font-weight: 700; color: var(--muted); text-align: center; }
.setup-steps li.done .mark { color: var(--ok); }
.setup-steps li.done a { color: var(--muted); }
.setup-steps a { font-weight: 600; min-height: 1.6rem; }
.setup-steps small { grid-column: 2; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
