/* ==========================================================================
   Calfmate V2 — Design System
   "A tool that gets out of the way." Google-Workspace-inspired: white surfaces,
   generous spacing, clear hierarchy, zero noise. Readable at 5am in a shed.
   One stylesheet. Inter only. Borders, not shadows. AA-legible status colours.
   ========================================================================== */

:root {
    /* ====================================================================
       Calfmate — Hunter Valley brand palette
       Deep pasture green, green-tinted neutrals, borders not shadows.
       ==================================================================== */

    /* Neutrals (green undertone, visibly distinct steps) */
    --neutral-950: #0F1412;
    --neutral-900: #1C2B22;
    --neutral-800: #243B2A;
    --neutral-700: #2F3D35;
    --neutral-400: #7A8F82;
    --neutral-200: #D4DDD8;
    --neutral-100: #EEF3F0;
    --neutral-50:  #F7FAF8;

    /* Surfaces */
    --bg: #FFFFFF;            /* cards / elevated surfaces */
    --surface: #F2F6F3;       /* sidebar, card headers, table headers */
    --surface-2: #EEF3F0;     /* subtle fills, progress tracks */
    --border: #D4DDD8;

    /* Brand / primary */
    --primary: #256F3A;
    --primary-light: #EDF7F0;
    --primary-dark: #1A5230;

    /* Text */
    --text-main: #1C2B22;
    --text-muted: #56685D;

    /* Status (full-strength) */
    --status-green: #256F3A;
    --status-amber: #C27803;
    --status-red: #A31616;
    --status-blue: #1D4ED8;
    --status-purple: #6D4AA8;   /* withdrawal / "Do not sell" */
    --status-grey: #7A8F82;

    /* Status tints (light bg + AA-legible text) */
    --green-bg: #EDF7F0;   --green-fg: #1E5C38;
    --amber-bg: #FBEFD9;   --amber-fg: #92580A;
    --red-bg: #FBE9E9;     --red-fg: #A31616;
    --blue-bg: #E6ECFB;    --blue-fg: #1D4ED8;
    --purple-bg: #EFE9F8;  --purple-fg: #56368C;
    --grey-bg: #EEF3F0;    --grey-fg: #56685D;

    /* ---- spec-named brand tokens (Part 2 of BRAND_PLAN) ---- */
    --color-primary: var(--primary);
    --color-primary-dark: var(--primary-dark);
    --color-primary-light: var(--primary-light);
    --color-accent-amber: var(--status-amber);
    --color-accent-red: var(--status-red);
    --color-accent-blue: var(--status-blue);
    --color-accent-teal: #0D7E7E;
    --color-amber-text: #92580A;
    --status-withdrawal: #6D4AA8;
    --status-withdrawal-text: #56368C;
    --color-text-primary: var(--text-main);
    --color-text-secondary: var(--neutral-700);
    --color-text-muted: var(--text-muted);
    --color-border: var(--border);
    --color-bg-page: var(--neutral-50);
    --color-bg-card: var(--bg);
    --color-danger: var(--status-red);
    --color-warning: var(--status-amber);
    --color-success: var(--primary);
    --color-info: var(--status-blue);

    /* Colostrum tiers — never reuse amber for these */
    --colostrum-gold: #B7860B;
    --colostrum-silver: #64748B;
    --colostrum-bronze: #92400E;

    /* Radius (buttons/inputs = 8px; pills reserved for badges & chips) */
    --radius-xs: 3px;
    --radius-sm: 4px;
    --radius-base: 8px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-pill: 9999px;

    /* Layout */
    --sidebar-w: 240px;
    --maxw: 1200px;
    --tap: 44px;

    /* Shadows — ONLY for modals, dropdowns, FABs, drag items */
    --shadow-sm: 0 1px 3px rgba(15,20,18,0.08), 0 1px 2px rgba(15,20,18,0.04);
    --shadow-md: 0 4px 12px rgba(15,20,18,0.10), 0 2px 4px rgba(15,20,18,0.06);

    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;

    /* Transitions */
    --transition-fast: 120ms ease;
    --transition-base: 200ms ease;

    /* ---- legacy token aliases (so existing inline styles keep working) ---- */
    --brand-primary: var(--primary);
    --brand-accent: var(--primary);
    --accent: var(--primary);
    --text: var(--text-main);
    --ok-fg: var(--green-fg);
    --warn-fg: var(--amber-fg);
    --sick-fg: var(--red-fg);
    --crit-fg: var(--red-fg);
    --success-green: var(--primary);
    --border-strong: #BFCcC4;
    --radius: var(--radius-md);
}

/* ----- reset ----- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    /* Flat page background — clean, calm, readable at 5am in a shed. */
    background-color: var(--neutral-50);
    color: var(--text-main);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

h1, h2, h3 { color: var(--text-main); margin: 0 0 0.5rem; }
h1 { font-size: 22px; font-weight: 500; line-height: 1.3; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }

.mono, .calf-id { font-family: var(--font-mono); font-size: 13px; }

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ==========================================================================
   App shell: light sidebar (desktop) + bottom tab bar (mobile)
   ========================================================================== */
.app { min-height: 100vh; }

.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 16px 0; z-index: 30;
}
.sidebar__brand {
    display: flex; align-items: center; gap: 8px;
    font-size: 20px; font-weight: 700; color: var(--text-main);
    padding: 8px 24px 16px; border-bottom: 1px solid var(--border); margin-bottom: 8px;
}
.sidebar__brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--primary); }
.sidebar__nav { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 2px; padding: 8px; overflow-y: auto; }
.sidebar__link {
    display: flex; align-items: center; gap: 10px; min-height: var(--tap);
    padding: 8px 16px; border-radius: var(--radius-base);
    color: var(--text-main); font-weight: 500; font-size: 14px;
}
.sidebar__link .ic {
    flex-shrink: 0; width: 24px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 17px; line-height: 1;
    font-family: "Segoe UI Symbol", "Apple Color Emoji", "Segoe UI Emoji", var(--font);
}
.sidebar__link:hover { background: var(--primary-light); text-decoration: none; }
.sidebar__link.is-active {
    background: var(--primary-light); color: var(--primary); font-weight: 600;
    box-shadow: inset 3px 0 0 var(--primary);
}
.sidebar__spacer { display: none; }
.sidebar__link--help {
    flex-shrink: 0; margin: 0 8px 4px; position: relative; z-index: 1;
}
.sidebar__footer { padding: 16px 24px 0; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-muted); }
.sidebar__footer a { color: var(--primary); }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 24px;
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: saturate(1.1) blur(8px);
    -webkit-backdrop-filter: saturate(1.1) blur(8px);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
}
.topbar__title { font-size: 16px; font-weight: 600; }
.topbar__end {
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: flex-end;
    margin-left: auto; min-width: 0;
}
.topbar__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex-shrink: 0; }
.topbar__user { display: flex; align-items: center; gap: 12px; color: var(--text-muted); font-size: 13px; white-space: nowrap; }
.topbar__end:has(.topbar__actions) .topbar__user {
    padding-left: 16px; border-left: 1px solid var(--border);
}

.content { padding: 24px; width: 100%; flex: 1; min-width: 0; }

.bottom-nav { display: none; }

@media (max-width: 820px) {
    .sidebar { display: none; }
    .main { margin-left: 0; }
    .content { padding: 16px 16px 88px; }
    .bottom-nav {
        display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
        background: var(--bg); border-top: 1px solid var(--border);
        padding: 4px; justify-content: space-around;
    }
    .bottom-nav a {
        flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
        gap: 2px; min-height: var(--tap); color: var(--text-muted);
        font-size: 11px; padding: 6px 2px; border-radius: var(--radius-sm);
    }
    .bottom-nav a .ic { font-size: 18px; line-height: 1; }
    .bottom-nav a.is-active { color: var(--primary); background: var(--primary-light); text-decoration: none; }

    .bottom-nav__more {
        flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
        gap: 2px; min-height: var(--tap); color: var(--text-muted);
        font-size: 11px; padding: 6px 2px; border-radius: var(--radius-sm);
        background: none; border: none; cursor: pointer; font-family: var(--font);
    }
    .bottom-nav__more .ic { font-size: 18px; line-height: 1; }
    .bottom-nav__more.is-active { color: var(--primary); background: var(--primary-light); }
}

/* Mobile "More" sheet — lists every module so nothing is unreachable on phones */
.nav-sheet { position: fixed; inset: 0; z-index: 50; }
.nav-sheet[hidden] { display: none; }
.nav-sheet__backdrop {
    position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45);
    animation: navFade 0.15s ease;
}
.nav-sheet__panel {
    position: absolute; left: 0; right: 0; bottom: 0;
    background: var(--bg); border-top: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
    box-shadow: var(--shadow-md); animation: navSlide 0.2s ease;
}
.nav-sheet__handle {
    width: 40px; height: 4px; border-radius: 999px; background: var(--border);
    margin: 4px auto 12px;
}
.nav-sheet__grid {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
}
.nav-sheet__item {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 4px; padding: 12px 4px; border-radius: var(--radius-md);
    color: var(--text-main); font-size: 12px; text-align: center; min-height: 64px;
}
.nav-sheet__item:hover { background: var(--primary-light); text-decoration: none; }
.nav-sheet__item .ic { font-size: 22px; line-height: 1; }
.nav-sheet__item.is-active { color: var(--primary); background: var(--primary-light); font-weight: 600; }
.nav-sheet__signout {
    display: block; text-align: center; margin-top: 12px; padding-top: 12px;
    border-top: 1px solid var(--border); color: var(--primary); font-weight: 600;
}
@keyframes navFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes navSlide { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (min-width: 821px) { .nav-sheet { display: none !important; } }

/* ==========================================================================
   Cards, stats, tables  (borders, not shadows)
   ========================================================================== */
.card {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 20px 24px;
}
.card + .card { margin-top: 16px; }
/* Grids space their children with `gap`; cancel the stacking margin so it can't
   offset sibling cards within a row (would break equal-height alignment). */
.grid > .card + .card { margin-top: 0; }
.card__title { font-size: 16px; font-weight: 600; margin: 0 0 16px; }

.grid { display: grid; gap: 16px; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid--cards { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* Selectable protocol/option cards (radio-driven). */
.pick-card { display: block; cursor: pointer; position: relative; }
.pick-card input { position: absolute; opacity: 0; pointer-events: none; }
.pick-card__body {
    border: 1.5px solid var(--border); border-radius: var(--radius-md);
    padding: 14px 16px; height: 100%; transition: border-color .12s, background .12s;
    display: flex; flex-direction: column; gap: 6px;
}
.pick-card:hover .pick-card__body { border-color: var(--text-muted); }
.pick-card input:checked + .pick-card__body {
    border-color: var(--success-green, #43A047);
    background: var(--green-bg, rgba(67,160,71,.08));
}

.stat {
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: 16px 20px;
}
.stat__label { color: var(--text-muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }
.stat__value { font-size: 36px; font-weight: 300; margin-top: 4px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat__value small { font-size: 14px; color: var(--text-muted); font-weight: 400; }
.stat--accent { border-left: 3px solid var(--primary); }
.stat--ok { border-left: 3px solid var(--status-green); }
.stat--warn { border-left: 3px solid var(--status-amber); }
.stat--crit { border-left: 3px solid var(--status-red); }
.stat--withdraw { border-left: 3px solid var(--status-purple); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }
table.data { width: 100%; border-collapse: collapse; background: var(--bg); }
table.data th, table.data td { padding: 0 16px; height: 48px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data thead th {
    position: sticky; top: 0; background: var(--surface);
    font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted);
}
table.data tbody tr:hover { background: var(--primary-light); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data td .calf-id { font-weight: 600; }
table.data tbody tr[hidden] { display: none; }

/* Enhanced table: column sort + filter */
.enh-table-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin-bottom: 8px; font-size: 13px; color: var(--text-muted);
}
.enh-table-bar [data-enh-clear][hidden] { display: none; }
table.data th.enh-th { height: auto; padding: 8px 10px; vertical-align: top; min-width: 88px; }
.enh-col { display: flex; flex-direction: column; gap: 6px; }
.enh-sort {
    display: inline-flex; align-items: center; gap: 4px; width: 100%;
    border: none; background: none; padding: 0; margin: 0; cursor: pointer;
    font: inherit; font-size: 12px; font-weight: 500; text-transform: uppercase;
    letter-spacing: 0.03em; color: var(--text-muted); text-align: left;
}
.enh-sort:hover, .enh-sort:focus-visible { color: var(--text); outline: none; }
.enh-sort-label { flex: 1; min-width: 0; }
.enh-sort-icon {
    flex-shrink: 0; width: 14px; height: 14px; opacity: 0.35;
    background: currentColor;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6h8L8 2 4 6zm0 4h8l-4 4-4-4z'/%3E%3C/svg%3E") center / contain no-repeat;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6h8L8 2 4 6zm0 4h8l-4 4-4-4z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.enh-sort-icon.is-asc { opacity: 1; mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 10h8L8 14 4 10z'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 10h8L8 14 4 10z'/%3E%3C/svg%3E"); }
.enh-sort-icon.is-desc { opacity: 1; mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6h8L8 2 4 6z'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6h8L8 2 4 6z'/%3E%3C/svg%3E"); }
.enh-filter-text, .enh-filter-select, .enh-filter-age {
    width: 100%; min-width: 0; box-sizing: border-box;
    font-size: 12px; font-weight: 400; text-transform: none; letter-spacing: normal;
}
.enh-filter-text, .enh-filter-age {
    height: 30px; padding: 4px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm, 6px);
    background: var(--bg); color: var(--text);
}
.enh-filter-select { height: 30px; padding: 2px 6px; }
.enh-age-filter { display: flex; align-items: center; gap: 4px; }
.enh-age-filter .enh-filter-age { flex: 1; min-width: 0; }
.enh-age-sep { color: var(--text-muted); font-size: 11px; flex-shrink: 0; }

/* ==========================================================================
   Badges / status chips
   ========================================================================== */
.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: var(--radius-pill);
    font-size: 12px; font-weight: 600; line-height: 1.5;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--ok       { background: var(--green-bg);  color: var(--green-fg); }
.badge--warn     { background: var(--amber-bg);  color: var(--amber-fg); }
.badge--sick     { background: var(--red-bg);    color: var(--red-fg); }
.badge--crit     { background: var(--red-bg);    color: var(--red-fg); }
.badge--info     { background: var(--blue-bg);   color: var(--blue-fg); }
.badge--withdraw { background: var(--purple-bg); color: var(--purple-fg); }
.badge--muted    { background: var(--grey-bg);   color: var(--grey-fg); }
/* Colostrum tiers — metallic tints, distinct from the health palette. */
.badge--gold     { background: #fbf2cf; color: #8a6d00; }
.badge--silver   { background: #e9edf1; color: #5b6b7a; }
.badge--bronze   { background: #f3e2d2; color: #8a5320; }

/* ==========================================================================
   Buttons (pill, no shadows, no gradients)
   ========================================================================== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 40px; padding: 0 20px; border-radius: var(--radius-base);
    font-family: var(--font); font-size: 14px; font-weight: 600;
    border: 1.5px solid var(--border); cursor: pointer; background: var(--bg); color: var(--text-main);
    transition: background-color var(--transition-fast, 120ms ease),
                border-color var(--transition-fast, 120ms ease),
                color var(--transition-fast, 120ms ease);
}
.btn:hover { text-decoration: none; background: var(--neutral-100); }
.btn:disabled, .btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn--primary { background: var(--primary); color: #fff; border-color: transparent; }
.btn--primary:hover { background: var(--primary-dark); }
.btn--accent { background: var(--primary); color: #fff; border-color: transparent; }
.btn--accent:hover { background: var(--primary-dark); }
.btn--ghost { background: var(--bg); border-color: var(--primary); color: var(--primary); }
.btn--ghost:hover { background: var(--primary-light); }
.btn--danger { background: var(--bg); border-color: var(--status-red); color: var(--status-red); }
.btn--danger:hover { background: var(--red-bg); }
.btn--ok { background: var(--status-green); color: #fff; border-color: transparent; }
.btn--ok:hover { filter: brightness(0.95); }
.btn--block { width: 100%; }
.btn--lg { min-height: 48px; font-size: 16px; padding: 0 28px; }
.btn--icon { min-height: 40px; padding: 0 12px; border-color: var(--border); color: var(--text-muted); }
.btn--icon:hover { background: var(--red-bg); color: var(--status-red); border-color: var(--red-bg); }
/* A compact (icon) button that also carries a colour variant must keep the
   variant's own colours — otherwise the muted icon text is unreadable on the
   coloured fill (only legible on hover). The two-class selectors out-rank the
   single-class .btn--icon rules regardless of source order. */
.btn--icon.btn--primary,
.btn--icon.btn--accent,
.btn--icon.btn--ok { color: #fff; border-color: transparent; }
.btn--icon.btn--primary:hover,
.btn--icon.btn--accent:hover { background: var(--primary-dark); color: #fff; border-color: transparent; }
.btn--icon.btn--ok:hover { background: var(--status-green); color: #fff; border-color: transparent; filter: brightness(0.95); }
.btn--icon.btn--ghost { color: var(--primary); border-color: var(--primary); }
.btn--icon.btn--ghost:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.btn--icon.btn--danger { color: var(--status-red); border-color: var(--status-red); }
.btn--icon.btn--danger:hover { background: var(--red-bg); color: var(--status-red); border-color: var(--status-red); }

/* Big primary action (e.g. "Start feeding") */
.action-hero {
    display: flex; align-items: center; justify-content: center; gap: 12px;
    width: 100%; min-height: 88px; border: none; border-radius: var(--radius-lg);
    background: var(--primary); color: #fff; font-size: 20px; font-weight: 700; cursor: pointer;
}
.action-hero:hover { background: var(--primary-dark); }

/* ==========================================================================
   Forms (labels above inputs; focus = 2px primary border, no shadow)
   ========================================================================== */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 500; font-size: 12px; color: var(--text-main); margin-bottom: 6px; }
.field .hint { color: var(--text-muted); font-size: 12px; margin-top: 6px; }
.input, .select, .textarea {
    width: 100%; min-height: 40px; padding: 8px 12px;
    border: 1px solid var(--border); border-radius: var(--radius-base);
    background: var(--bg); color: var(--text-main); font-size: 14px; font-family: var(--font);
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); border-width: 2px; padding: 7px 11px; outline: none; }
.textarea { min-height: 96px; resize: vertical; }
[hidden] { display: none !important; }
.form-row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.form-error { color: var(--status-red); font-size: 12px; margin-top: 6px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 400; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }

/* ==========================================================================
   Alerts
   ========================================================================== */
.alert {
    border-radius: var(--radius-md); padding: 12px 16px; margin-bottom: 16px;
    border: 1px solid var(--blue-bg); background: var(--blue-bg); color: var(--blue-fg); font-weight: 500; font-size: 14px;
}
.alert--success { background: var(--green-bg); color: var(--green-fg); border-color: var(--green-bg); }
.alert--error { background: var(--red-bg); color: var(--red-fg); border-color: var(--red-bg); }
.alert--warn { background: var(--amber-bg); color: var(--amber-fg); border-color: var(--amber-bg); }
.alert--info { background: var(--blue-bg); color: var(--blue-fg); border-color: var(--blue-bg); }

/* ==========================================================================
   Auth / onboarding cards
   ========================================================================== */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--surface); }
.auth-card { width: 100%; max-width: 400px; background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: 32px; }
.auth-brand { display: flex; align-items: center; gap: 8px; font-size: 24px; font-weight: 700; color: var(--text-main); margin-bottom: 4px; }
.auth-brand .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--primary); }
.auth-sub { color: var(--text-muted); margin: 0 0 24px; }
.auth-foot { text-align: center; margin-top: 16px; font-size: 0.9rem; color: var(--text-muted); }
.auth-foot a { color: var(--accent); text-decoration: none; }
.auth-foot a:hover { text-decoration: underline; }

/* Register — UX psychology layout (value panel + progressive form) */
.auth-register-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    width: 100%;
    max-width: 920px;
    align-items: start;
}
@media (min-width: 820px) {
    .auth-register-layout { grid-template-columns: 300px 1fr; gap: 24px; }
}
.auth-register-panel {
    background: linear-gradient(165deg, var(--primary-dark) 0%, var(--primary) 55%, #2d8a4e 100%);
    color: #fff;
    border-radius: var(--radius-lg);
    padding: 24px;
    border: 1px solid rgba(255,255,255,0.12);
}
.auth-register-panel__brand {
    display: flex; align-items: center; gap: 10px;
    font-size: 1.15rem; font-weight: 700; margin-bottom: 16px;
}
.auth-register-panel__brand img { border-radius: 7px; }
.auth-register-panel__trial {
    font-size: 1.05rem; font-weight: 600; line-height: 1.35; margin: 0 0 14px;
}
.auth-register-panel__list {
    list-style: none; margin: 0 0 18px; padding: 0;
    font-size: 0.9rem; line-height: 1.45;
}
.auth-register-panel__list li {
    display: flex; align-items: flex-start; gap: 8px; margin-bottom: 8px;
}
.auth-register-panel__list li::before {
    content: "✓"; flex-shrink: 0; font-weight: 700; opacity: 0.95;
}
.auth-register-panel__anchor {
    font-size: 0.82rem; line-height: 1.45; opacity: 0.92;
    padding-top: 14px; border-top: 1px solid rgba(255,255,255,0.2);
}
.auth-register-card { max-width: none; }
.auth-register-journey { margin-bottom: 20px; }
.auth-register-journey__label {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.82rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px;
}
.auth-register-journey__steps {
    display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 10px;
    font-size: 0.78rem; color: var(--text-muted);
}
.auth-register-journey__step { display: flex; align-items: center; gap: 4px; }
.auth-register-journey__step.is-done { color: var(--green-fg); font-weight: 600; }
.auth-register-journey__step.is-current { color: var(--text-main); font-weight: 600; }
.auth-register-farm-preview {
    background: var(--primary-light); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 12px 14px; margin-bottom: 20px;
}
.auth-register-farm-preview__label {
    font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 4px;
}
.auth-register-farm-preview__name {
    font-size: 1.1rem; font-weight: 700; color: var(--text-main);
    min-height: 1.35em;
}
.auth-register-farm-preview__name.is-empty {
    color: var(--text-muted); font-weight: 500; font-style: italic;
}
.auth-register-section {
    border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: 16px; margin-bottom: 16px; background: var(--neutral-50);
}
.auth-register-section__title {
    font-size: 0.82rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.03em; color: var(--text-muted); margin: 0 0 12px;
}
.auth-register-section .field:last-child { margin-bottom: 0; }
.auth-register-username-row { display: flex; gap: 8px; align-items: flex-start; }
.auth-register-username-row .input { flex: 1; }
.auth-register-suggest {
    flex-shrink: 0; margin-top: 2px; white-space: nowrap;
    font-size: 0.78rem; padding: 0 10px; min-height: 40px;
}
.auth-register-device .seg { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.auth-register-device .seg__opt span {
    width: 100%; border-radius: var(--radius-md); min-height: 44px;
    justify-content: flex-start; text-align: left; padding: 10px 14px;
    flex-direction: column; align-items: flex-start; gap: 2px;
}
.auth-register-device .seg__opt strong { font-size: 0.92rem; }
.auth-register-device .seg__opt .seg__desc {
    font-size: 0.82rem; font-weight: 400; opacity: 0.85;
}
.auth-register-device .seg__opt input:checked + span .seg__desc { opacity: 0.92; }
.auth-register-cta-note {
    font-size: 0.82rem; color: var(--text-muted); text-align: center; margin-top: 10px;
}

/* ==========================================================================
   Utilities
   ========================================================================== */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: 8px; } .gap { gap: 16px; }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; } .mt-lg { margin-top: 24px; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--text-muted); padding: 40px 16px; }
.empty .ic { font-size: 40px; }

/* Progress bar (e.g. treatment day X of N) */
.progress { height: 8px; background: var(--surface-2, var(--surface)); border-radius: 999px; overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; background: var(--primary); }

/* Urgent card (e.g. colostrum needed) + live countdown */
.card--urgent { border-left: 3px solid var(--status-red); }
.countdown { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--status-green); }
.countdown.is-over { color: var(--status-red); }

/* Segmented radio control (e.g. birth type, calving time) */
.seg { display: inline-flex; flex-wrap: wrap; gap: 8px; }
.seg__opt { position: relative; cursor: pointer; }
.seg__opt input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg__opt span {
    display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px;
    border: 1px solid var(--border); border-radius: var(--radius-pill);
    background: var(--bg); color: var(--text-main); font-size: 14px; font-weight: 500;
}
.seg__opt input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.seg__opt input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Dashboard panels — equal-height cards, balanced rows */
.grid--panels { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); align-items: stretch; }
.grid--panels > .card { display: flex; flex-direction: column; }

/* Dashboard "Today" rows: intentional, matched column tracks (not generic
   auto-fit) so widths read consistently and row 3 lines up under row 2 —
   Watch list (8) under Milk(5)+Tasks(3), Recent arrivals (4) under Treatments(4). */
.grid--panels-ops   { grid-template-columns: 5fr 3fr 4fr; }
.grid--panels-lists { grid-template-columns: 8fr 4fr; }
/* Min frame so short/empty panels still read as proper cards; `stretch` then
   equalizes the taller neighbours within each row. */
.grid--panels-ops > .card,
.grid--panels-lists > .card { min-height: 150px; }

@media (max-width: 820px) {
    .grid--panels-ops,
    .grid--panels-lists { grid-template-columns: 1fr; }
}
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card__head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.card__head .card__link { font-size: 13px; color: var(--primary); text-decoration: none; white-space: nowrap; }
.card__head .card__link:hover { text-decoration: underline; }
.dash-list { list-style: none; margin: 0; padding: 0; }
.dash-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-top: 1px solid var(--border); }
.dash-list li:first-child { border-top: 0; }
.dash-list a:not(.btn) { color: var(--text-main); text-decoration: none; font-weight: 500; }
.dash-list a:not(.btn):hover { color: var(--primary); }
.dash-metric { display: flex; align-items: baseline; gap: 6px; }
.dash-metric .n { font-size: 28px; font-weight: 300; line-height: 1; font-variant-numeric: tabular-nums; }
.dash-metric .u { color: var(--text-muted); font-size: 13px; }
.dash-sub { color: var(--text-muted); font-size: 13px; }
.dash-tasks__group + .dash-tasks__group { margin-top: 14px; }
.dash-tasks__head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.dash-tasks__section-label {
    font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--text-muted);
}
.dash-week-nav { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 12px; }
.dash-week-nav__label { font-weight: 600; font-size: 14px; min-width: 10rem; text-align: center; }

/* Dashboard tasks — urgency chips + protocol groups */
.dash-task-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.dash-task-chip {
    display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 120px;
    padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-md);
    background: var(--bg); color: var(--text-main); text-decoration: none;
    transition: border-color .12s, background .12s;
}
.dash-task-chip:hover { border-color: var(--primary); text-decoration: none; }
.dash-task-chip.is-active { border-color: var(--primary); background: var(--primary-light); }
.dash-task-chip--crit:not(.is-active) { border-left: 3px solid var(--status-red); }
.dash-task-chip.is-active.dash-task-chip--crit { background: var(--red-bg); border-color: var(--red-bg); border-left: 3px solid var(--status-red); }
.dash-task-chip__label { font-size: 12px; font-weight: 600; }
.dash-task-chip__meta { font-size: 12px; color: var(--text-muted); }
.dash-task-chip.is-active .dash-task-chip__meta { color: inherit; opacity: .85; }

.dash-task-protocol {
    border: 1px solid var(--border); border-radius: var(--radius-md);
    background: var(--surface, var(--bg)); overflow: hidden;
}
.dash-task-protocol + .dash-task-protocol { margin-top: 8px; }
.dash-task-protocol__head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 10px 12px; cursor: pointer; list-style: none;
}
.dash-task-protocol__head::-webkit-details-marker { display: none; }
.dash-task-protocol__head::before {
    content: '▸'; flex-shrink: 0; width: 14px; color: var(--text-muted); font-size: 12px;
    transition: transform .12s;
}
.dash-task-protocol[open] > .dash-task-protocol__head::before { transform: rotate(90deg); }
.dash-task-protocol__title { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.dash-task-inline-form { margin: 0; display: inline-flex; }

.dash-task-pens { list-style: none; margin: 0; padding: 0 12px 10px 26px; }
.dash-task-pen {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 8px 0; border-top: 1px solid var(--border);
}
.dash-task-pen:first-child { border-top: 0; }
.dash-task-pen__main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.dash-task-pen__name { font-weight: 600; font-size: 14px; }
.dash-task-more { display: inline-block; margin: 0 12px 10px 26px; }

/* ---- Dashboard "Today" v2: compact KPI strip + work/attention two-column ---- */

/* KPI band: side context panels + central stat strip use full content width. */
.dash-kpi-band {
    display: grid;
    grid-template-columns: minmax(148px, 1fr) minmax(0, 2.4fr) minmax(148px, 1fr);
    gap: 12px;
    align-items: stretch;
    margin-bottom: 24px;
}
.dash-kpi-side {
    display: flex; flex-direction: column; justify-content: center; gap: 2px; min-width: 0;
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: 12px 14px; color: inherit; text-decoration: none;
}
.dash-kpi-side:hover { border-color: var(--primary); background: var(--primary-light); text-decoration: none; }
.dash-kpi-side__label {
    color: var(--text-muted); font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.03em;
}
.dash-kpi-side__value { font-size: 18px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.dash-kpi-side__sub { color: var(--text-muted); font-size: 12px; line-height: 1.35; }

/* Compact KPI strip — uniform stat cards, value-led; urgency through colour not size. */
.dash-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; min-width: 0; }
.dash-kpi {
    display: flex; flex-direction: column; justify-content: center; gap: 6px;
    background: var(--bg); border: 1px solid var(--border); border-left: 3px solid var(--border);
    border-radius: var(--radius-md); padding: 12px 16px; min-width: 0;
}
.dash-kpi__value { font-size: 30px; font-weight: 300; line-height: 1; font-variant-numeric: tabular-nums; }
.dash-kpi__label {
    color: var(--text-muted); font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.dash-kpi--accent { border-left-color: var(--primary); }
.dash-kpi--warn   { border-left-color: var(--status-amber); }
.dash-kpi--crit   { border-left-color: var(--status-red); }
/* Only "shout" when the count is non-zero — quiet when there's nothing wrong. */
.dash-kpi--warn.is-active { background: var(--amber-bg); border-color: var(--amber-bg); border-left-color: var(--status-amber); }
.dash-kpi--warn.is-active .dash-kpi__value { color: var(--amber-fg); }
.dash-kpi--crit.is-active { background: var(--red-bg); border-color: var(--red-bg); border-left-color: var(--status-red); }
.dash-kpi--crit.is-active .dash-kpi__value { color: var(--red-fg); }

/* Two-column dashboard body: wide "work" column + narrow "attention" rail.
   Each column stacks its own cards; columns top-align so they don't stretch. */
.dash-cols { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.dash-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* Tasks = primary panel: a touch more presence than the reference cards. */
.card--feature { border-top: 3px solid var(--primary); }

/* Task rows get room for full label + due badge + inline action. */
.dash-list--tasks li { gap: 12px; }
.task-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex: 1; min-width: 0; }
.task-row__main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.task-row__main strong { line-height: 1.25; }
.task-row__cta { flex-shrink: 0; }
.btn--sm { min-height: 32px; padding: 0 14px; font-size: 13px; }

@media (max-width: 980px) {
    .dash-cols { grid-template-columns: 1fr; }
    .dash-kpi-band { grid-template-columns: 1fr 1fr; }
    .dash-kpi-band .dash-kpis { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
    .dash-kpis { grid-template-columns: repeat(2, 1fr); }
    .dash-kpi-band { grid-template-columns: 1fr; }
    .topbar__end { gap: 10px; }
    .topbar__actions .btn { min-height: 36px; padding: 0 12px; font-size: 12px; }
    .topbar__end:has(.topbar__actions) .topbar__user { padding-left: 0; border-left: 0; }
}

/* Simple CSS bar chart (e.g. daily milk litres) */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 8px; }
.bars__col { flex: 1 1 0; display: flex; align-items: flex-end; height: 100%; min-width: 4px; text-decoration: none; color: inherit; }
.bars__bar { width: 100%; background: var(--primary); border-radius: 3px 3px 0 0; transition: height .2s; }
.bars__col:hover .bars__bar,
.bars__col.is-active .bars__bar { background: var(--primary-dark); }
.bars__col.is-active { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

/* Reports — Performance Board KPI cards (DCHA traffic lights) */
.rpt-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}
.rpt-kpi {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    border-left-width: 4px;
    padding: 12px 14px;
    background: var(--bg);
    min-width: 0;
}
.rpt-kpi--green { border-left-color: var(--status-green); }
.rpt-kpi--amber { border-left-color: var(--status-amber); background: var(--amber-bg); }
.rpt-kpi--red   { border-left-color: var(--status-red); background: var(--red-bg); }
.rpt-kpi--none  { border-left-color: var(--border); }
.rpt-kpi__label {
    font-size: 12px; font-weight: 600; color: var(--text-muted);
    line-height: 1.3; margin-bottom: 6px;
}
.rpt-kpi__value {
    font-size: 26px; font-weight: 300; line-height: 1;
    font-variant-numeric: tabular-nums;
}
.rpt-kpi__unit { font-size: 13px; color: var(--text-muted); margin-left: 2px; }
.rpt-kpi__bench {
    margin-top: 8px; font-size: 11px; color: var(--text-muted); line-height: 1.35;
}
table.data tbody tr.is-warn { background: rgba(194, 120, 3, 0.08); }

/* Reports — season sparklines */
.rpt-spark-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}
.rpt-spark-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
}
.rpt-spark-card__label {
    font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 8px;
}
.rpt-spark { color: var(--primary); display: block; }

/* Reports — pen morbidity heat map */
.rpt-heat {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}
.rpt-heat--compact { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
.rpt-heat__tile {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    background: var(--bg);
}
.rpt-heat__tile--ok    { background: var(--green-bg); border-color: transparent; }
.rpt-heat__tile--watch { background: var(--amber-bg); border-color: transparent; }
.rpt-heat__tile--high  { background: #fde8d0; border-color: transparent; }
.rpt-heat__tile--hot   { background: var(--red-bg); border-color: transparent; }
.rpt-heat__name { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.rpt-heat__rate { font-size: 22px; font-weight: 300; font-variant-numeric: tabular-nums; }
.rpt-heat__sub  { font-size: 11px; color: var(--text-muted); margin-top: 4px; line-height: 1.35; }

.rpt-heat-legend {
    display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center;
    font-size: 12px; color: var(--text-muted);
}
.rpt-heat-legend__item { display: inline-flex; align-items: center; gap: 6px; }
.rpt-heat-legend__swatch {
    display: inline-block; width: 14px; height: 14px; border-radius: 3px;
    border: 1px solid var(--border); vertical-align: middle;
}

/* Growth sparkline */
.growth-chart {
    width: 100%; height: 160px; display: block;
    background: var(--surface-2, #f8f9fb); border: 1px solid var(--border); border-radius: var(--radius);
}

/* Quick-jump chips (e.g. Settings section nav) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    display: inline-flex; align-items: center; min-height: 32px; padding: 0 14px;
    border: 1px solid var(--border); border-radius: var(--radius-pill);
    background: var(--bg); color: var(--text-main); font-size: 13px; font-weight: 500; text-decoration: none;
}
.chip:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.chip.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Tasks page horizon filter */
.filter-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip__count {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 18px; margin-left: 7px; padding: 0 5px;
    border-radius: var(--radius-pill); font-size: 11px; font-weight: 700;
    background: var(--grey-bg); color: var(--grey-fg);
}
.chip.is-active .chip__count { background: rgba(255,255,255,.22); color: #fff; }

/* Protocol component chips on a task card */
.task-items { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.task-item {
    display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px;
    border: 1px solid var(--border); border-radius: var(--radius-pill);
    background: var(--surface); font-size: 12px; font-weight: 500;
}

/* Guided feeding run */
.feed-step {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; flex: 0 0 36px; border-radius: 50%;
    background: var(--primary-light); color: var(--primary); font-weight: 700; font-size: 16px;
}
.card.is-fed .feed-step { background: var(--green-bg); color: var(--green-fg); }
.feed-prep { display: flex; flex-wrap: wrap; gap: 8px; }
.prep-pill {
    display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
    border: 1px solid var(--border); border-radius: var(--radius-pill);
    background: var(--surface); font-size: 13px;
}

/* Milk mix grouping in the feeding run */
.mix__head { border-left: 3px solid var(--primary); background: var(--surface); }
.mix__head--vat { border-left-color: var(--border); background: var(--grey-bg, #f6f7f8); }
.mix__pen { margin-left: 16px; }
.mix__pen--next {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}
.mix__pen--next .feed-step { background: var(--primary); color: #fff; }
.mix__pen--done { opacity: 0.7; }
.badge--next {
    background: var(--primary-light, #eaf4ee);
    color: var(--primary);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.feed-calves-details { border-top: 1px solid var(--border); padding-top: 8px; }
.feed-calves-summary {
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    list-style: none;
    user-select: none;
}
.feed-calves-summary::-webkit-details-marker { display: none; }
.feed-calves-summary::before {
    content: '▸';
    display: inline-block;
    margin-right: 6px;
    transition: transform 0.15s ease;
}
.feed-calves-details[open] > .feed-calves-summary::before { transform: rotate(90deg); }
.feed-calf__actions { display: flex; align-items: center; gap: 4px; flex: none; }
.feed-calf__main { flex: 1 1 auto; }
.mix-summary-grid {
  display: grid;
  gap: 12px;
  align-items: stretch;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.mix-summary-grid > .card + .card { margin-top: 0; }
.mix-summary-grid--1 { grid-template-columns: 1fr; }
.mix-summary-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mix-summary-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 900px) {
  .mix-summary-grid--2,
  .mix-summary-grid--3 { grid-template-columns: 1fr; }
}
.mix-summary-card {
  margin: 0;
  border-left: 3px solid var(--primary);
  height: 100%;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}
.mix-summary-card__top { flex: 0 0 auto; }
.mix-summary-card__prep {
  margin-top: auto;
  flex: 1 1 auto;
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}
.mix-summary-recipe + .mix-summary-recipe { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.mix-summary-steps { margin: 8px 0 0; padding-left: 1.1rem; line-height: 1.75; font-size: 13px; }
@media (max-width: 640px) { .mix__pen { margin-left: 0; } }
.text-right { text-align: right; }

/* Per-calf rows inside a feeding pen */
.feed-calves { display: flex; flex-direction: column; gap: 6px; }
.feed-calf {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 8px 12px; border: 1px solid var(--border); border-left: 3px solid var(--border);
    border-radius: var(--radius-sm); background: var(--bg);
}
.feed-calf__main { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; min-width: 0; flex: 1 1 auto; }
.feed-calf.is-treat  { border-left-color: var(--red-fg);    background: var(--red-bg); }
.feed-calf.is-health { border-left-color: var(--purple-fg); background: var(--purple-bg); }
.feed-calf.is-elyte  { border-left-color: var(--blue-fg);   background: var(--blue-bg); }
.feed-calf.is-watch  { border-left-color: var(--amber-fg);  background: var(--amber-bg); }

/* Native tap-friendly dropdown (no JS) */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu__pop {
    position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 200px;
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md);
    box-shadow: var(--shadow-md); padding: 6px; display: flex; flex-direction: column; gap: 2px;
}
.menu__item {
    width: 100%; text-align: left; background: none; border: none; cursor: pointer;
    padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px; color: var(--text-main); font-family: var(--font);
}
.menu__item:hover { background: var(--primary-light); }
.menu__item--clear { color: var(--text-muted); }
.menu__item--ok { color: var(--green-fg); font-weight: 600; }
.menu__head { padding: 8px 12px 4px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.menu__sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ==========================================================================
   Brand components (BRAND_PLAN Part 5)
   ========================================================================== */

/* Alert card — left status border, tinted background (5.2) */
.alert-card {
    position: relative; border: 1px solid var(--border); border-left: 4px solid var(--status-grey);
    border-radius: var(--radius-md); padding: 14px 16px; background: var(--bg);
}
.alert-card + .alert-card { margin-top: 12px; }
.alert-card__title { font-size: 14px; font-weight: 600; margin: 0 0 2px; }
.alert-card__body  { font-size: 13px; color: var(--text-muted); margin: 0; }
.alert-card--success { border-left-color: var(--status-green); background: var(--green-bg); }
.alert-card--success .alert-card__title { color: var(--green-fg); }
.alert-card--warn    { border-left-color: var(--status-amber); background: var(--amber-bg); }
.alert-card--warn .alert-card__title { color: var(--amber-fg); }
.alert-card--crit    { border-left-color: var(--status-red); background: var(--red-bg); }
.alert-card--crit .alert-card__title { color: var(--red-fg); }
.alert-card--withdraw { border-left-color: var(--status-withdrawal); background: var(--purple-bg); }
.alert-card--withdraw .alert-card__title { color: var(--purple-fg); }

/* Status badge — pill, tinted bg + AA-legible text (5.5) */
.status-badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: var(--radius-pill);
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
    line-height: 1.5;
}
.status-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-badge--active   { background: var(--green-bg);  color: var(--green-fg); }
.status-badge--watch    { background: var(--amber-bg);  color: var(--color-amber-text); }
.status-badge--sick     { background: var(--red-bg);    color: var(--red-fg); }
.status-badge--withdraw { background: var(--purple-bg); color: var(--status-withdrawal-text); }
.status-badge--weaning  { background: #D6ECEC;          color: #0A5A5A; }
.status-badge--exited   { background: var(--grey-bg);   color: var(--grey-fg); }

/* Dashboard stat number — tabular figures (Part 3) */
.stat-number {
    font-size: var(--font-size-2xl, 32px); font-weight: 700; line-height: 1.1;
    color: var(--text-main); font-variant-numeric: tabular-nums;
}

/* Status-tinted table rows (5.2) */
table.data tbody tr.table-row--sick     { background: rgba(163, 22, 22, 0.06); }
table.data tbody tr.table-row--sick:hover { background: rgba(163, 22, 22, 0.10); }
table.data tbody tr.table-row--watch    { background: rgba(194, 120, 3, 0.06); }
table.data tbody tr.table-row--watch:hover { background: rgba(194, 120, 3, 0.10); }
table.data tbody tr.table-row--withdraw { background: rgba(109, 74, 168, 0.06); }
table.data tbody tr.table-row--withdraw:hover { background: rgba(109, 74, 168, 0.10); }

/* Designed empty state (5.9) */
.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 48px 24px; gap: 8px;
}
.empty-state__icon { color: var(--neutral-400); width: 40px; height: 40px; }
.empty-state__icon svg { width: 100%; height: 100%; }
.empty-state__title { font-size: 17px; font-weight: 600; color: var(--neutral-700); margin: 0; }
.empty-state__text  { font-size: 14px; color: var(--text-muted); margin: 0; max-width: 36ch; }
.empty-state .btn { margin-top: 8px; }

/* Font-size scale tokens (Part 3) — available for new components */
:root {
    --font-size-xs: 11px;  --font-size-sm: 13px;  --font-size-base: 15px;
    --font-size-md: 17px;  --font-size-lg: 20px;  --font-size-xl: 24px;
    --font-size-2xl: 32px; --font-size-3xl: 48px;
}

/* ==========================================================================
   In-app help guide dialog
   ========================================================================== */
.help-guide {
    border: none; padding: 0; margin: 0;
    width: 100%; max-width: 100%; height: 100%; max-height: 100%;
    background: var(--bg); color: var(--text-main);
}
.help-guide:not([open]) {
    display: none !important;
    pointer-events: none;
}
.help-guide::backdrop { background: rgba(0, 0, 0, 0.45); }
.help-guide__frame {
    display: flex; flex-direction: column;
    height: 100%; max-height: 100dvh;
}
.help-guide__head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky; top: 0; z-index: 2;
    padding-top: max(16px, env(safe-area-inset-top));
}
.help-guide__title { margin: 0; font-size: var(--font-size-md); font-weight: 600; }
.help-guide__close { flex-shrink: 0; }
.help-guide__body {
    flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: 16px 16px max(24px, env(safe-area-inset-bottom));
    display: flex; flex-direction: column; gap: 16px;
}
.help-guide__toc { padding: 16px 20px; margin: 0; }
.help-guide__toc-lead { margin: 0 0 8px; font-size: var(--font-size-sm); color: var(--text-muted); font-weight: 500; }
.help-guide__toc-list {
    margin: 0; padding-left: 1.25rem;
    font-size: var(--font-size-sm); line-height: 1.6;
}
.help-guide__toc-list a { font-weight: 500; }
.help-guide__section { margin: 0; }
.help-guide__section h3 {
    margin: 0 0 12px; font-size: var(--font-size-md); font-weight: 600;
    scroll-margin-top: 72px;
}
.help-guide__section h4 {
    margin: 16px 0 8px; font-size: var(--font-size-base); font-weight: 600;
}
.help-guide__section p { margin: 0 0 12px; font-size: var(--font-size-sm); line-height: 1.55; color: var(--text-main); }
.help-guide__section ul,
.help-guide__section ol {
    margin: 0 0 12px; padding-left: 1.35rem;
    font-size: var(--font-size-sm); line-height: 1.55;
}
.help-guide__section li + li { margin-top: 6px; }
.help-guide__section li ul { margin-top: 6px; margin-bottom: 0; }

button.sidebar__link,
button.nav-sheet__item {
    border: none; background: transparent;
    cursor: pointer; font-family: inherit; text-align: inherit;
    pointer-events: auto;
}
button.sidebar__link { width: auto; text-align: left; }
button.nav-sheet__item { width: 100%; }
button.sidebar__link:hover,
button.nav-sheet__item:hover { background: var(--primary-light); }
button.nav-sheet__item { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

@media (min-width: 821px) {
    .help-guide {
        width: min(720px, 92vw); height: auto; max-height: 95vh;
        border: 1px solid var(--border); border-radius: var(--radius-lg);
        box-shadow: var(--shadow-md);
    }
    .help-guide__frame { max-height: 95vh; }
    .help-guide__body { padding: 20px 24px 24px; }
}

/* Pens / calf-move screens — refined picker checkboxes (DOC-003 §8.4) */
.pick-check,
[data-calf-picker] input[type="checkbox"][data-check],
[data-calf-picker] input[type="checkbox"][data-check-all],
.pen-screen input[type="checkbox"][data-check],
.pen-screen input[type="checkbox"][data-check-all] {
    appearance: none;
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    margin: 0 auto;
    display: block;
    border: 2px solid var(--border-strong, #BFCcC4);
    border-radius: 7px;
    background: var(--bg);
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
    flex-shrink: 0;
}
.pick-check:hover,
[data-calf-picker] input[type="checkbox"][data-check]:hover,
[data-calf-picker] input[type="checkbox"][data-check-all]:hover,
.pen-screen input[type="checkbox"][data-check]:hover,
.pen-screen input[type="checkbox"][data-check-all]:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}
.pick-check:checked,
[data-calf-picker] input[type="checkbox"][data-check]:checked,
[data-calf-picker] input[type="checkbox"][data-check-all]:checked,
.pen-screen input[type="checkbox"][data-check]:checked,
.pen-screen input[type="checkbox"][data-check-all]:checked {
    background-color: var(--primary);
    border-color: var(--primary);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M3.2 8.4L6.6 11.8L12.8 4.6' stroke='%23fff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-size: 15px 15px;
    background-position: center;
    background-repeat: no-repeat;
}
.pick-check:indeterminate,
[data-calf-picker] input[type="checkbox"][data-check-all]:indeterminate,
.pen-screen input[type="checkbox"][data-check-all]:indeterminate {
    background-color: var(--primary);
    border-color: var(--primary);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 8h8' stroke='%23fff' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E");
    background-size: 15px 15px;
    background-position: center;
    background-repeat: no-repeat;
}
.pick-check:focus-visible,
[data-calf-picker] input[type="checkbox"][data-check]:focus-visible,
[data-calf-picker] input[type="checkbox"][data-check-all]:focus-visible,
.pen-screen input[type="checkbox"]:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
.pick-check__cell,
.pen-screen__check {
    width: 52px;
    min-width: 52px;
    padding: 0 10px;
    text-align: center;
    vertical-align: middle;
}
[data-calf-picker] tbody tr,
.pen-screen table.data tbody tr:has(input[data-check]) {
    cursor: pointer;
}
[data-calf-picker] tbody tr:has(input[data-check]:checked),
.pen-screen table.data tbody tr:has(input[data-check]:checked) {
    background: var(--primary-light);
    box-shadow: inset 3px 0 0 var(--primary);
}
[data-calf-picker] tbody tr:has(input[data-check]:checked):hover,
.pen-screen table.data tbody tr:has(input[data-check]:checked):hover {
    background: #dff0e4;
}
[data-calf-picker] .enh-filter-text,
[data-calf-picker] .enh-filter-age,
[data-calf-picker] .enh-filter-select {
    border-radius: var(--radius-base);
    border-color: var(--border);
    background: var(--bg);
}
[data-calf-picker] .enh-filter-text:focus,
[data-calf-picker] .enh-filter-age:focus,
[data-calf-picker] .enh-filter-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
    outline: none;
}
.pen-quick-setup--hero {
    border: 1px solid var(--primary-light);
    background: linear-gradient(180deg, var(--primary-light) 0%, var(--surface) 48px);
}

/* View toggle: Cards vs List (pill segment — matches chip / filter patterns) */
.view-toggle {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border-radius: var(--radius-pill);
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.view-toggle__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    padding: 0 14px;
    border: none;
    border-radius: var(--radius-pill);
    background: transparent;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.view-toggle__ic {
    font-size: 14px;
    line-height: 1;
    opacity: 0.85;
}
.view-toggle__btn.is-active {
    background: var(--bg);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}
.view-toggle__btn.is-active .view-toggle__ic { opacity: 1; }
.view-toggle__btn:hover:not(.is-active) {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.72);
}
.view-toggle__btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
.pens-view-panel[hidden] { display: none !important; }
.pens-list-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    justify-content: flex-end;
    white-space: nowrap;
    text-align: right;
    min-width: 11rem;
}
.pens-list-actions .btn { margin: 0; flex-shrink: 0; }
.pens-list-fill-pct--over { color: var(--crit-fg); font-weight: 600; }
#pens-list-table th.enh-th { min-width: 4.5rem; padding: 6px 8px; }
#pens-list-table th.enh-th:first-child { min-width: 5rem; }
#pens-list-table .enh-filter-age { height: 28px; padding: 2px 6px; }
#pens-list-table .enh-filter-text,
#pens-list-table .enh-filter-select { height: 28px; }
.pens-list-fill {
    display: inline-block;
    min-width: 48px;
    height: 6px;
    background: var(--surface-2);
    border-radius: 999px;
    vertical-align: middle;
    margin-right: 6px;
    overflow: hidden;
}
.pens-list-fill > span {
    display: block;
    height: 100%;
    border-radius: 999px;
}
