/* Nova Blood Gas Reporting — styled after veriprime.com:
   deep purple (#32005B) brand bar, the logo's violet as the accent, dark
   #292929 headings, Raleway for headings/navigation (uppercase, tracked),
   Open Sans for body copy, Noticia Text for the occasional serif line. */

:root {
  --vp-purple: #32005b;
  --vp-purple-deep: #24003f;
  --vp-violet: #5e2590;
  --vp-violet-dark: #4a1c73;
  --vp-lavender: #f1eaf7;
  --vp-lavender-line: #e0d3ec;
  --ink: #292929;
  --muted: #5f5f66;
  --line: #dddddd;
  --page: #f6f4f9;
  --surface: #ffffff;
  --link: #3579b7;

  --low: #1f5b9a;
  --low-bg: #e7f0fa;
  --high: #b3261e;
  --high-bg: #fcebeb;
  --ok: #3f6b12;
  --ok-bg: #eef6e3;
  --mild: #8a5a00;
  --mild-bg: #fef3e5;

  --font-head: "Raleway", "Helvetica Neue", Arial, sans-serif;
  --font-body: "Open Sans", "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Noticia Text", Georgia, serif;

  --radius: 4px;
  --shadow: 0 1px 2px rgba(41, 41, 41, 0.06), 0 2px 8px rgba(50, 0, 91, 0.05);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--page);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 {
  font-family: var(--font-head);
  font-weight: 600;
  color: var(--ink);
  line-height: 1.25;
  margin: 0 0 0.5em;
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.2rem; text-transform: uppercase; letter-spacing: 0.06em; }
h3 { font-size: 1rem; text-transform: uppercase; letter-spacing: 0.06em; }

p { margin: 0 0 1em; }

/* ---------- Site header ---------- */

.site-header {
  background: var(--vp-purple);
  color: #fff;
  border-bottom: 4px solid var(--vp-violet);
}
.site-header__inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 76px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  color: #fff;
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; }
.brand img { height: 56px; width: auto; display: block; }
/* Full-width line under the logo and menu. */
.site-header__tagline {
  max-width: 1600px;
  margin: 0 auto;
  padding: 7px 24px 9px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.85);
}

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
  flex-wrap: wrap;
  min-width: 0;
}
.nav a {
  font-family: var(--font-head);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.85);
  padding: 8px 9px;
  white-space: nowrap;
  border-radius: var(--radius);
}
.nav a:hover { color: #fff; background: rgba(255, 255, 255, 0.08); text-decoration: none; }
.nav a.is-active { color: #fff; background: var(--vp-violet); }

.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.user-menu__who { text-align: right; line-height: 1.3; }
.user-menu__who strong { display: block; font-weight: 600; }
.user-menu__who span { opacity: 0.7; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; }
.user-menu a, .user-menu button {
  color: rgba(255, 255, 255, 0.85);
  font: inherit;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: var(--radius);
  padding: 5px 10px;
  cursor: pointer;
}
.user-menu a:hover, .user-menu button:hover { color: #fff; border-color: #fff; text-decoration: none; }
.user-menu form { margin: 0; }

/* ---------- Page layout ---------- */

main {
  flex: 1;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 32px 24px 56px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.page-head h1 { margin: 0; }
.kicker {
  font-family: var(--font-head);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--vp-violet);
  margin-bottom: 4px;
}
.lede {
  font-family: var(--font-serif);
  color: var(--muted);
  margin: 6px 0 0;
  max-width: 70ch;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

.site-footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8rem;
}
.site-footer__inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* ---------- Cards, grids ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 24px;
}
.card > h2:first-child, .card__head h2 { margin-bottom: 14px; }
.card__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.card--flush { padding: 0; }
.card--flush > .card__head { padding: 20px 24px 0; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.grid-2 > .card { margin-bottom: 0; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--vp-violet);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat__label {
  font-family: var(--font-head);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat__value {
  font-family: var(--font-head);
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--vp-purple);
  line-height: 1.2;
  margin-top: 4px;
}
.stat__value--small { font-size: 1.1rem; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-head);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  line-height: 1;
  padding: 11px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { text-decoration: none; }
.btn:focus-visible, .nav a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--vp-violet);
  outline-offset: 2px;
}
.btn-primary { background: var(--vp-violet); color: #fff; }
.btn-primary:hover { background: var(--vp-violet-dark); }
.btn-secondary { background: var(--surface); color: var(--vp-violet); border-color: var(--vp-violet); }
.btn-secondary:hover { background: var(--vp-lavender); }
.btn-danger { background: var(--surface); color: var(--high); border-color: #e3b6b3; }
.btn-danger:hover { background: var(--high-bg); border-color: var(--high); }
.btn-sm { padding: 7px 11px; font-size: 0.7rem; }
.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--link);
  font: inherit;
  cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--high); }

/* ---------- Flash messages ---------- */

.flashes { margin-bottom: 20px; display: grid; gap: 8px; }
.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  border-left: 4px solid;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}
.flash-success { border-color: var(--ok); background: var(--ok-bg); }
.flash-error { border-color: var(--high); background: var(--high-bg); }
.flash-warning { border-color: #d98a00; background: var(--mild-bg); }
.flash-info { border-color: var(--vp-violet); background: var(--vp-lavender); }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
.table th, .table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table thead th {
  font-family: var(--font-head);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  background: #faf8fc;
  border-bottom: 2px solid var(--vp-lavender-line);
  white-space: nowrap;
}
.table tbody tr:hover td { background: #fcfbfd; }
.table .num, .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions-col { text-align: right; white-space: nowrap; }
.table .actions-col form { display: inline; }
.table .actions-col > * + * { margin-left: 12px; }
.empty { color: var(--muted); padding: 24px; text-align: center; font-family: var(--font-serif); }

.category-row th {
  background: var(--vp-lavender);
  color: var(--vp-purple);
  font-family: var(--font-head);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--vp-lavender-line);
}

/* ---------- Badges & statuses ---------- */

.badge {
  display: inline-block;
  font-family: var(--font-head);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--vp-lavender);
  color: var(--vp-purple);
  white-space: nowrap;
}
.badge-admin { background: var(--vp-purple); color: #fff; }
.badge-lab_tech { background: var(--vp-lavender); color: var(--vp-violet); }
.badge-viewer { background: #eceff3; color: #44505e; }
.badge-muted { background: #f0f0f0; color: var(--muted); }
.badge-warn { background: var(--mild-bg); color: var(--mild); }

.is-low { color: var(--low); background: var(--low-bg); font-weight: 600; }
.is-high { color: var(--high); background: var(--high-bg); font-weight: 600; }
.is-ok { color: var(--ok); background: var(--ok-bg); font-weight: 600; }
.is-mild { color: var(--mild); background: var(--mild-bg); font-weight: 600; }
.is-severe { color: var(--high); background: var(--high-bg); font-weight: 600; }
.excluded-count { color: var(--mild); font-weight: 700; }
.complete-true { color: var(--ok); font-weight: 700; }
.complete-false { color: var(--high); font-weight: 700; cursor: help; }
.index-pill {
  display: inline-block;
  min-width: 3.4em;
  padding: 2px 8px;
  border-radius: 999px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.comment { font-weight: 700; font-family: var(--font-head); letter-spacing: 0.04em; }
.comment.is-low, .comment.is-high { background: none; }

.legend-inline { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); }
.legend-inline span::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 2px;
  vertical-align: -1px;
}
.legend-inline .lg-low::before { background: var(--low-bg); border: 1px solid var(--low); }
.legend-inline .lg-high::before { background: var(--high-bg); border: 1px solid var(--high); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }

/* ---------- Forms ---------- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px 20px;
}
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-4 { grid-column: 1 / -1; }
.form-narrow { max-width: 460px; }
fieldset {
  border: none;
  padding: 0;
  margin: 0 0 24px;
}
legend {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--vp-violet);
  padding: 0;
  margin-bottom: 12px;
  width: 100%;
  border-bottom: 1px solid var(--vp-lavender-line);
  padding-bottom: 6px;
}
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 0; }
.form-narrow .field { margin-bottom: 16px; }
.field label {
  font-family: var(--font-head);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink);
}
.field .code { font-weight: 400; color: var(--muted); font-size: 0.72rem; margin-left: 4px; }
.field input[type="text"], .field input[type="password"], .field input[type="email"],
.field input[type="number"], .field input[type="date"], .field input[type="file"], .field input[type="search"], .field select,
.search input {
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cfcad6;
  border-radius: var(--radius);
  padding: 9px 11px;
  width: 100%;
}
.field input[type="file"] { padding: 8px; background: #fbfafc; }
.field input:focus, .field select:focus, .search input:focus {
  border-color: var(--vp-violet);
  box-shadow: 0 0 0 3px rgba(94, 37, 144, 0.15);
  outline: none;
}
.field .help { font-size: 0.78rem; color: var(--muted); }
tr.is-optional td { color: var(--muted); }
.field-note { font-size: 0.82rem; color: var(--muted); margin: 0; align-self: end; padding-bottom: 8px; }
.field .error { font-size: 0.8rem; color: var(--high); font-weight: 600; }
.field.has-error input, .field.has-error select { border-color: var(--high); }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; margin-bottom: 16px; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; flex-wrap: wrap; }

.search { display: flex; gap: 8px; max-width: 420px; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 16px;
  padding: 16px 20px;
  margin-bottom: 16px;
}
.filter-bar .field { flex: 0 1 180px; min-width: 150px; }
.filter-bar .filter-bar__search { flex: 1 1 240px; }
.filter-bar__actions { display: flex; align-items: center; gap: 14px; padding-bottom: 2px; }
.filter-summary { margin: -4px 0 12px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.feedyard-grid, .api-grid { align-items: start; }
.new-key { border-left: 4px solid var(--ok); background: var(--ok-bg); }
.key-box {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 8px 0 4px;
}
.key-box code, .api-help code, .api-ref code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.85rem;
}
.key-box code {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px; overflow-wrap: anywhere; flex: 1 1 320px;
}
.api-help h3 { margin-top: 22px; color: var(--vp-purple); }
.api-help ol { padding-left: 20px; }
.api-help li { margin-bottom: 8px; }
.code-block { position: relative; }
.code-block pre {
  background: #1e1b24; color: #f1eaf7; border-radius: var(--radius);
  padding: 14px 16px; overflow-x: auto; font-size: 0.8rem; line-height: 1.5; margin: 8px 0;
}
.code-block button { position: absolute; top: 8px; right: 8px; }
.api-ref td { vertical-align: top; }

/* Lots page: many narrow columns; keep the actions visible while scrolling. */
.lot-entries { font-size: 0.85rem; }
.lot-entries th, .lot-entries td { padding: 8px 7px; white-space: nowrap; }
.lot-entries .actions-col {
  position: sticky; right: 0; z-index: 1;
  background: var(--surface); box-shadow: -1px 0 0 var(--line);
  padding-left: 12px; padding-right: 14px;
}
.lot-entries thead .actions-col { background: #faf8fc; }
.lot-entries tbody tr:hover .actions-col { background: #fcfbfd; }
.access-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  padding: 4px 24px 16px; border-bottom: 1px solid var(--line);
}
.access-actions form { margin: 0; }
.add-user-form { display: flex; gap: 8px; flex: 1 1 320px; }
.add-user-form select, .filter-bar select {
  font: inherit; font-size: 0.95rem; color: var(--ink); background: #fff;
  border: 1px solid #cfcad6; border-radius: var(--radius); padding: 8px 10px; min-width: 0; flex: 1;
}

.sampling-summary { max-width: 620px; }
.sampling-summary .card__head { padding: 14px 20px 0; }
.sampling-summary .card__head h2 { margin-bottom: 10px; }
.pivot-table th, .pivot-table td { padding: 8px 14px; }
.pivot-table tbody th { font-weight: 600; text-align: left; }
.pivot-table .total-col { font-weight: 700; border-left: 1px solid var(--vp-lavender-line); }
.pivot-table tfoot th, .pivot-table tfoot td {
  font-weight: 700;
  border-top: 2px solid var(--vp-purple);
  border-bottom: none;
  background: var(--vp-lavender);
  color: var(--vp-purple);
}

/* ---------- Login ---------- */

.login-shell {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 48px 16px;
  background:
    linear-gradient(160deg, rgba(50, 0, 91, 0.94), rgba(36, 0, 63, 0.97)),
    var(--vp-purple);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 6px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.login-card__brand {
  background: var(--vp-purple-deep);
  padding: 28px 24px 22px;
  text-align: center;
  border-bottom: 4px solid var(--vp-violet);
}
.login-card__brand img { height: 92px; width: auto; }
.login-card__body { padding: 28px 32px 32px; }
.login-card__body h1 { font-size: 1.3rem; text-align: center; margin-bottom: 4px; }
.login-card__body .lede { text-align: center; margin: 0 auto 22px; font-size: 0.9rem; }
.login-card .btn { width: 100%; justify-content: center; padding: 13px; }
.login-shell .flashes { width: 100%; max-width: 420px; }

/* ---------- Report ---------- */

.report-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.report-meta div {
  padding: 10px 14px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.report-meta dt {
  font-family: var(--font-head);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.report-meta dd {
  margin: 2px 0 0;
  font-weight: 600;
  font-size: 1rem;
  overflow-wrap: anywhere;
}
.report-meta dd .muted { font-weight: 400; font-size: 0.8rem; }

.index-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 20px 0 24px;
}
.index-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 16px;
  align-items: center;
  box-shadow: var(--shadow);
}
.index-card h3 { margin: 0; font-size: 0.8rem; grid-column: 1 / -1; color: var(--vp-purple); }
.index-card__score {
  font-family: var(--font-head);
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--ink);
}
.index-card__score small { font-size: 0.8rem; font-weight: 400; color: var(--muted); margin-left: 6px; }
.index-card .band { font-size: 0.8rem; padding: 6px 10px; border-radius: var(--radius); }
.index-card__legend { grid-column: 1 / -1; font-size: 0.78rem; color: var(--muted); }

.summary-table td.comment-cell { min-width: 110px; }

.detail-table { font-size: 0.82rem; }
.detail-table th, .detail-table td { padding: 6px 9px; border-bottom: 1px solid #ececec; white-space: nowrap; }
.detail-table thead th { position: sticky; top: 0; }
.detail-table .sticky-col {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
  box-shadow: 1px 0 0 var(--line);
}
.detail-table thead .sticky-col { background: #faf8fc; z-index: 2; }
.detail-table .category-row th { position: sticky; left: 0; }
.detail-table .stat-col { background: #faf8fc; font-weight: 600; }
.detail-table .index-row th, .detail-table .index-row td { border-top: 2px solid var(--vp-lavender-line); }

/* Results by animal, pivoted: animals down, parameters across with rotated
   headers. A fixed layout shares the width evenly so every column fits the
   page; below the min-width (phones) the table scrolls instead. */
.detail-table.pivoted { table-layout: fixed; width: 100%; min-width: 980px; font-size: 0.8rem; }
.pivoted col.tag-col { width: 64px; }
.pivoted col.vt-col { width: 104px; }
.pivoted td.vt-cell { text-overflow: ellipsis; padding-left: 6px; }
.pivoted th, .pivoted td { padding: 5px 3px; white-space: nowrap; overflow: hidden; }
.pivoted thead th { position: static; }
.pivoted thead th.rot {
  height: 116px; vertical-align: bottom; text-align: center;
  padding: 8px 0; text-transform: none; letter-spacing: 0.02em;
  font-size: 0.74rem; color: var(--ink);
}
.pivoted th.rot span { display: inline-block; writing-mode: vertical-rl; transform: rotate(180deg); }
.pivoted th.rot small { font-weight: 400; color: var(--muted); font-size: 0.66rem; margin-top: 4px; }
.pivoted thead .corner { vertical-align: bottom; }
.pivoted tbody th { font-weight: 600; }
.pivoted .grp-start { border-left: 2px solid var(--vp-lavender-line); }
.pivoted .range-row th, .pivoted .range-row td { color: var(--muted); background: #faf8fc; font-size: 0.74rem; font-weight: 400; }
.pivoted .first-animal th, .pivoted .first-animal td { border-top: 2px solid var(--vp-lavender-line); }
.pivoted td.is-flagged, .flag-key {
  color: #8a2a2a; font-weight: 700; text-align: center;
  background: repeating-linear-gradient(135deg, #f6e9e9, #f6e9e9 4px, #fbf4f4 4px, #fbf4f4 8px);
}
.flag-key { display: inline-block; padding: 0 5px; border-radius: 2px; }
.pivoted tfoot th, .pivoted tfoot td { background: #faf8fc; font-weight: 700; }
.pivoted tfoot tr:first-child th, .pivoted tfoot tr:first-child td { border-top: 2px solid var(--vp-purple); }

.notes { font-size: 0.82rem; color: var(--muted); margin-top: 12px; }
.print-only { display: none; }

/* ---------- Responsive ---------- */

@media (max-width: 1560px) {
  .user-menu__who { display: none; }
}

/* Keep the admin menu on one line until it moves to its own row (1100px). */
@media (max-width: 1300px) {
  .site-header__inner { gap: 12px; }
  .nav { gap: 2px; }
  .nav a { padding: 8px 6px; font-size: 0.74rem; letter-spacing: 0.04em; }
  .user-menu { gap: 6px; }
  .user-menu a, .user-menu button { padding: 5px 8px; }
}

@media (max-width: 1100px) {
  .site-header__inner { flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; gap: 12px 20px; }
  .nav { order: 3; flex-basis: 100%; }
  .user-menu { margin-left: auto; }
}

@media (max-width: 900px) {
  .grid-2, .index-cards { grid-template-columns: minmax(0, 1fr); }
  .report-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  main { padding: 20px 16px 40px; }
  .site-header__inner { padding-left: 16px; padding-right: 16px; }
  .brand img { height: 44px; }
  .user-menu__who { display: none; }
  .site-header__tagline { padding-left: 16px; padding-right: 16px; font-size: 0.66rem; letter-spacing: 0.08em; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .filter-bar .field { flex: 1 1 100%; }
  h1 { font-size: 1.4rem; }
  .card { padding: 16px; }
}

/* ---------- Print (Save as PDF) ---------- */

@media print {
  @page { size: letter landscape; margin: 0.4in; }
  body { background: #fff; font-size: 11px; display: block; }
  .site-header, .site-footer, .no-print, .flashes { display: none !important; }
  .print-only { display: block; }
  main { max-width: none; padding: 0; }
  .card { box-shadow: none; border: none; padding: 0; margin-bottom: 14px; }
  .index-card, .stat { box-shadow: none; }
  .table-wrap { overflow: visible; }
  .chart-box { height: 260px; }
  .detail-table { font-size: 8.5px; }
  .detail-table th, .detail-table td { padding: 2px 4px; }
  .detail-table.pivoted { min-width: 0; font-size: 8px; }
  .pivoted col.tag-col { width: 44px; }
  .pivoted th, .pivoted td { padding: 2px 1px; }
  .pivoted thead th.rot { height: 84px; font-size: 7.5px; }
  .pivoted th.rot small { font-size: 6.5px; }
  .pivoted .range-row th, .pivoted .range-row td { font-size: 7px; }
  .detail-card { break-before: page; }
  .category-row th, .is-low, .is-high, .is-ok, .is-mild, .is-severe, .stat-col, .is-flagged {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .print-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--vp-purple);
    color: #fff;
    padding: 8px 12px;
    margin-bottom: 12px;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .print-brand img { height: 40px; }
  .print-brand span { font-family: var(--font-head); font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; font-size: 10px; }
}

/* ---------- Visual tag entry (lot -> Link PatientID to Visual Tag) ---------- */
.vt-table { max-width: 640px; }
.vt-table th[scope="row"] { font-variant-numeric: tabular-nums; font-weight: 600; width: 120px; }
.vt-table th[scope="row"] label { cursor: pointer; }
.vt-table td.field { padding-top: 6px; padding-bottom: 6px; }
.vt-table .field input.vt-input { padding: 6px 9px; max-width: 240px; }
.vt-table tr.vt-outside th, .vt-table tr.vt-outside td { background: var(--mild-bg); }
.vt-table .badge + .badge { margin-left: 4px; }
.vt-actions { padding: 14px 24px 20px; }

/* ---------- Tag Lookup: search by tag number or visual tag ---------- */
.filter-bar .search-by { border: 0; padding: 0; margin: 0; min-width: 0; flex: 0 0 auto; }
.search-by legend {
  font-family: var(--font-head); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: none; color: var(--ink); padding: 0; margin-bottom: 5px; border: 0; width: auto;
}
.segmented { display: inline-flex; border: 1px solid #cfcad6; border-radius: var(--radius); overflow: hidden; background: #fff; }
.segmented label {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px;
  font-family: var(--font-body); font-size: 0.9rem; font-weight: 400; letter-spacing: 0;
  cursor: pointer; color: var(--muted); white-space: nowrap;
}
.segmented label + label { border-left: 1px solid #cfcad6; }
.segmented input { accent-color: var(--vp-violet); margin: 0; }
.segmented label:has(input:checked) { background: var(--vp-lavender); color: var(--vp-violet); font-weight: 600; }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--vp-violet); outline-offset: -2px; }

/* ---------- Collection-day weather ---------- */
.wx-link {
  display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; white-space: nowrap;
  font-size: 0.85rem; font-weight: 600; color: var(--vp-violet); text-decoration: none;
  border: 1px solid var(--vp-lavender-line); border-radius: 999px; padding: 1px 9px; background: var(--surface);
}
.wx-link:hover { background: var(--vp-lavender); }
td .wx-link { margin: 4px 0 0; }
.wx-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px 24px; margin: 0; }
.wx-stats dt { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.wx-stats dd { margin: 2px 0 0; font-family: var(--font-head); font-weight: 700; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.wx-stats dd small { font-family: var(--font-body); font-weight: 600; font-size: 0.85rem; color: var(--muted); }
.wx-table td, .wx-table th { font-variant-numeric: tabular-nums; }
.wx-table tr.wx-collection th, .wx-table tr.wx-collection td { background: var(--vp-lavender); font-weight: 700; }
.wx-credit { margin: 4px 0 0; }
.wx-table th, .wx-table td { padding-left: 10px; padding-right: 10px; }
.wx-table thead th { white-space: normal; vertical-align: bottom; line-height: 1.3; }

/* Upload edit page */
.edit-dups { margin-bottom: 0; align-self: flex-end; padding-bottom: 10px; }
.edit-table td.field { padding-top: 6px; padding-bottom: 6px; }
.edit-table .field input { padding: 6px 9px; max-width: 220px; }
.edit-table tr.row-dup td { background: var(--mild-bg); }
.edit-actions { padding: 14px 24px 20px; }

/* ---- Statistics (admin) ---- */
.stats-scope { display: grid; grid-template-columns: minmax(220px, 360px) 1fr; gap: 8px 24px; align-items: end; margin-bottom: 24px; }
.stats-scope p { margin: 0 0 8px; }
.stats-reports { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 24px; margin-bottom: 24px; }
.stats-report { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.stats-report h2 { margin: 0; }
.stats-report p { margin: 0; color: var(--muted); flex: 1; }
.stats-report .btn { align-self: flex-start; }
.stats-error { max-width: 42ch; margin-top: 4px; }
.stats-refresh { padding: 0 24px 16px; margin: 0; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-failed { background: var(--high-bg); color: var(--high); }
@media (max-width: 640px) { .stats-scope { grid-template-columns: 1fr; } }
.stats-report--wide { grid-column: 1 / -1; }
.stats-report--wide > p { flex: none; }
.stats-params { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(160px, 220px); gap: 12px 20px; align-items: end; }
@media (max-width: 760px) { .stats-params { grid-template-columns: 1fr; } }
.table .tags-cell { min-width: 9ch; max-width: 16ch; }
