/* ============================================================
   DocDairy layout and component overrides, loaded after theme.css and rtl.css.
   The approved CSS refresh follows the layout helpers; phones share one block.
   ============================================================ */

/* Every colour here is a theme.css token. Pages that do not extend layout/base.html load
   theme.css through fragments/theme :: head before this file; there is no second copy of the
   palette anywhere. */

/* Sidebar brand: the round cow emblem (logo-mark.png) on a white rounded chip so it
   reads on the dark sidebar. The <img> IS the chip — fixed size so it never blows up. */
.sidebar-brand .brand-logo {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    object-fit: contain;
    background: #fff;
    padding: 3px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
    margin: 0 !important;
}

/* Login logo: a clean white badge with a soft green ring — professional and prominent. */
.auth-logo {
    background: #fff;
    padding: 16px;
    width: 180px;
    height: 180px;
    object-fit: contain;
    border-radius: 50%;
    border: 1px solid rgba(15, 40, 33, 0.06);
    box-shadow: 0 0 0 6px rgba(29, 111, 92, 0.06),
                0 18px 40px -16px rgba(15, 40, 33, 0.40);
}

/* Active sidebar item uses the green gradient */
.sidebar-menu .nav-link.active {
    background: var(--gradient-primary);
    color: #fff;
}

/* Profile header avatar */
.cow-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--gradient-primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    flex: 0 0 auto;
}

/* Cow profile picture (first photo, or the default cow image). */
.cow-avatar-img {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    flex: 0 0 auto;
    background: #fff;
    border: 1px solid var(--surface-border);
}

/* ---------- Professional polish ---------- */

/* Consistent control heights so buttons line up with the inputs beside them.
   theme.css gives .btn a fixed padding (0.55rem) that (a) ignores .btn-sm and
   (b) differs from the form-control padding (0.7rem), so a button always ended
   up a different height than the field next to it. app.css loads last, so here
   we re-align button padding/line-height to the inputs at BOTH sizes. Inputs and
   buttons that share a padding-y + line-height + border render the same height. */
.btn { padding: 0.7rem 1.1rem; line-height: 1.5; }
.btn-sm,
.form-control-sm,
.form-select-sm { padding: 0.4rem 0.7rem; font-size: 0.875rem; line-height: 1.5; }
.input-group .btn { line-height: 1.5; }

/* A button column that sits next to labelled fields: this spacer reserves the
   label's height so the button aligns with the inputs (not taller/shorter). */
.field-spacer { display: block; height: 1.5em; margin-bottom: .25rem; }
@media (max-width: 767.98px) { .field-spacer { display: none; } }

/* Text typed in a textarea (a vet's summary, recommendations) keeps its line breaks when shown. */
.text-pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Cards: cleaner, lighter, consistent */
.card { border-radius: 14px; }
.card-header { font-weight: 600; background: transparent; }

/* Tables: tidy header + comfortable rows */
.table > thead th {
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .02em;
    color: var(--text-secondary);
    border-bottom-width: 1px;
}
.table > tbody td { vertical-align: middle; }
.table-toolbar { margin-top: -0.25rem; }

/* Green focus ring on inputs/selects to match the brand */
.form-control:focus,
.form-select:focus {
    border-color: var(--focus-ring);
    box-shadow: 0 0 0 0.2rem rgba(29, 111, 92, 0.18);
}

/* Page content header spacing */
.app-content-header { padding-block: 0.5rem; }
.app-content-header h3 { font-weight: 700; }

/* ---------- Denser layout — save real estate ----------
   Bootstrap/AdminLTE default to generous 1.5rem gaps and card padding. We tighten the
   whole vertical rhythm to a compact ~8–12px scale (the industry norm for data-dense
   dashboards) so pages show more without feeling cramped. This is applied globally and
   should be the baseline for new components too — prefer these gaps over ad-hoc large
   margins. Scoped to the main content so login/auth screens are untouched. */
.app-content { padding-top: 0.25rem; padding-bottom: 1rem; }
.app-content > .container-fluid,
.app-content-header > .container-fluid { padding-left: 1.1rem; padding-right: 1.1rem; }
.app-content .card-body { padding: 0.85rem 1rem; }
.app-content .card-header { padding-top: 0.55rem; padding-bottom: 0.55rem; }
/* Collapse the oversized spacing utilities to the compact scale (0.75rem major gap). */
.app-content .mb-4, .app-content .mb-5 { margin-bottom: 0.75rem !important; }
.app-content .mt-4, .app-content .mt-5 { margin-top: 0.75rem !important; }
.app-content .my-4, .app-content .my-5 { margin-top: 0.75rem !important; margin-bottom: 0.75rem !important; }
.app-content .mb-3 { margin-bottom: 0.6rem !important; }
.app-content .mt-3 { margin-top: 0.6rem !important; }
.app-content .g-4 { --bs-gutter-y: 0.75rem; --bs-gutter-x: 0.75rem; }
.app-content .g-3 { --bs-gutter-y: 0.6rem; --bs-gutter-x: 0.6rem; }
/* Rein in large block padding (empty states / "not applicable" panels don't need 3rem). */
.app-content .py-5 { padding-top: 1.5rem !important; padding-bottom: 1.5rem !important; }
.app-content .py-4 { padding-top: 1rem !important; padding-bottom: 1rem !important; }
.app-content .p-5 { padding: 1.5rem !important; }
.app-content .p-4 { padding: 1rem !important; }
/* Tables: Bootstrap's default cell padding makes data rows ~50px tall; trim to the compact
   scale so an 8-row table (e.g. per-cow milk log) doesn't dominate its column. */
.app-content .table > :not(caption) > * > * { padding-top: 0.4rem; padding-bottom: 0.4rem; }
/* Forms: trim the label→field gap so multi-field cards (e.g. feeding plans) stay compact. */
.app-content .form-label { margin-bottom: 0.2rem; }
.app-content form .text-muted.small { margin-bottom: 0.5rem; }
/* Bootstrap gives .alert a 1rem bottom margin that the compact scale missed, so info/notice banners
   left a big gap above the first card. Bring alerts into the ~8-12px scale, and drop the trailing
   margin on a card body's last <p> so note text never pads the bottom of its card. */
.app-content .alert { margin-bottom: 0.6rem; }
.app-content .card-body > p:last-child { margin-bottom: 0; }

/* Status / attribute helpers */
.row-due { background: rgba(245, 158, 11, 0.10); }
.row-overdue { background: rgba(220, 53, 69, 0.12); }
.row-ready { background: rgba(29, 111, 92, 0.10); }

/* Photo gallery thumbnails */
.photo-thumb { aspect-ratio: 1; object-fit: cover; width: 100%; cursor: zoom-in; transition: transform .12s ease; }
.photo-thumb:hover { transform: scale(1.03); }

/* Meta line on records */
.record-meta { font-size: .75rem; color: var(--text-muted); }

/* Keep the sidebar always visible while a long page scrolls. Sticky inside the AdminLTE
   CSS grid proved unreliable, so on desktop we take the sidebar out of flow (position:fixed,
   full viewport height) and reserve its width as a fixed grid column so nothing shifts under it.
   inset-inline-start handles both LTR (left) and RTL (right) automatically. */
@media (min-width: 992px) {
    .app-wrapper { grid-template-columns: var(--lte-sidebar-width) 1fr !important; }
    .app-sidebar {
        position: fixed !important;
        top: 0;
        inset-inline-start: 0;
        height: 100vh !important;
        max-height: none !important;
        width: var(--lte-sidebar-width);
        z-index: 1035;
        overflow: hidden;
    }
    /* Collapsed via the hamburger: reclaim the space (AdminLTE's negative margin slides it away). */
    .sidebar-collapse .app-wrapper { grid-template-columns: 0 1fr !important; }

    /* Fixed app-shell: cap the wrapper at the viewport height so the header stays put and only
       .app-main scrolls. This is what actually lets the top bar pin — position:sticky only sticks
       relative to its own scroll container, and before this .app-main grew with its content (the
       whole window scrolled), so the sticky top bar had nothing to stick to. */
    html, body { height: 100%; overflow: hidden; }
    .app-wrapper { height: 100vh; min-height: 100vh; overflow: hidden; }
    .app-main { overflow-y: auto; overflow-x: hidden; min-height: 0; }
}
/* Turn the scroll area into a flex column so the Help item pins to the bottom. */
.app-sidebar .sidebar-wrapper { display: flex; flex-direction: column; }
.app-sidebar .sidebar-wrapper > nav { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.app-sidebar .sidebar-menu { flex: 1 1 auto; }

/* Line the sidebar brand bar up with the top header bar (same 3.5rem height + centred). */
.sidebar-brand {
    height: calc(3.5rem + 1px);
    padding-top: 0;
    padding-bottom: 0;
    display: flex;
    align-items: center;
}

/* Flag glyph in the language menu */
.lang-flag { display: inline-block; width: 20px; height: 15px; border-radius: 3px; object-fit: cover; vertical-align: -2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .08); }

/* Notification bell */
.app-header .nav-link { position: relative; }
.app-header .notif-badge-count { position: absolute; top: 0; inset-inline-end: -1px; font-size: .58rem; padding: .12rem .3rem; }
.notif-menu { width: 330px; max-height: 72vh; overflow-y: auto; }
.notif-item.notif-unread { background: rgba(29, 111, 92, 0.07); }
.notif-unread-row { background: rgba(29, 111, 92, 0.05); }

/* "soon" badge on a sidebar item (e.g. Accounting). AdminLTE pins .nav-badge to the end edge of
   the link (its RTL build puts it on the left), clear of the start-aligned label. */
.sidebar-menu .nav-link > .nav-badge { font-size: .62rem; text-transform: uppercase; }

/* "Get started" sidebar entry (layout/base.html, admins while setup steps are open): a soft brand
   tint and a dashed brand edge so a first-time owner spots it before anything else, without
   fighting the active gradient (which wins when the checklist page itself is open). */
.sidebar-menu .nav-link.nav-getstarted:not(.active) {
    background: var(--soft-primary);
    border: 1px dashed var(--brand-teal);
}
.sidebar-menu .nav-link.nav-getstarted:not(.active) .nav-icon { color: var(--ink-primary); }
.sidebar-menu .nav-link.nav-getstarted > .nav-badge { font-size: .62rem; }
/* Sidebar badges (the Get started "3/5" counter, "soon" markers) take a solid brand fill with the
   on-brand ink in BOTH themes. The sidebar carries data-bs-theme="dark" (AdminLTE), so without
   this the badge mixed the dark tint with the light theme's text (#8a5a00 on #3a3325, 2.1:1). */
.sidebar-menu .nav-link .nav-badge {
    background: var(--brand-teal) !important;
    color: var(--on-brand) !important;
    font-weight: 650;
}

/* Inline "record calving" disclosure inside the breeding table */
.calving-capture > summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: .3rem; }
.calving-capture > summary::-webkit-details-marker { display: none; }

/* Inline edit disclosure (e.g. correcting a milk record) — summary looks like a button, no marker */
.inline-edit > summary { cursor: pointer; list-style: none; }
.inline-edit > summary::-webkit-details-marker { display: none; }
.inline-edit[open] > summary { margin-bottom: .25rem; }

/* Brand: keep a clear gap between the logo and the name in both directions. */
.sidebar-brand .brand-link { gap: .5rem; }
/* Login password show/hide control reads as a clickable affordance. */
.input-group .pwd-toggle { cursor: pointer; }

/* Cow-profile collapsible sections (profile-collapse.js). Click the header to fold a section;
   the chevron shows state and sits at the trailing edge (RTL-aware). */
.card.dd-collapsible > .card-header {
    cursor: pointer;
    position: relative;
    padding-inline-end: 2.1rem;
}
.card.dd-collapsible > .card-header .dd-collapse-chevron {
    position: absolute;
    inset-inline-end: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    transition: transform 0.15s ease;
    opacity: 0.6;
}
.card.dd-collapsed > .card-header .dd-collapse-chevron {
    transform: translateY(-50%) rotate(-90deg);
}
/* RTL: the collapsed chevron must point the other way (toward the trailing edge, which is now the
   left) so it still reads as "expand". Without this it points the wrong direction in fa/ar. */
html[dir="rtl"] .card.dd-collapsed > .card-header .dd-collapse-chevron {
    transform: translateY(-50%) rotate(90deg);
}
.card.dd-collapsed > .card-body,
.card.dd-collapsed > .card-footer {
    display: none;
}

/* ---------- AI chat bubbles (ai/chat.html) ----------
   User turns hug the trailing edge, assistant turns the leading edge; logical
   properties (inline-start/end, margin-inline) flip automatically under RTL. */
.ai-chat-log { display: flex; flex-direction: column; gap: .5rem; max-height: 55vh; overflow-y: auto; }
.ai-bubble {
    max-width: 82%;
    padding: .5rem .8rem;
    border-radius: 14px;
    line-height: 1.35;
    font-size: .92rem;
    white-space: pre-wrap;
}
.ai-bubble.assistant {
    align-self: flex-start;
    background: var(--surface-muted, rgba(127, 127, 127, .12));
    border-end-start-radius: 4px;
}
.ai-bubble.user {
    align-self: flex-end;
    background: var(--bs-primary);
    color: #fff;
    border-end-end-radius: 4px;
}
/* Rendered Markdown replies (chat.html renderMd): tight paragraphs and lists inside a bubble. */
.ai-bubble.ai-rendered { white-space: normal; }
.ai-bubble.ai-rendered p { margin: 0 0 .4rem; }
.ai-bubble.ai-rendered p:last-child, .ai-bubble.ai-rendered li > p { margin-bottom: 0; }
.ai-bubble.ai-rendered .ai-h { font-weight: 600; margin-top: .55rem; }
.ai-bubble.ai-rendered ul, .ai-bubble.ai-rendered ol { margin: 0 0 .4rem; padding-inline-start: 1.35rem; }
.ai-bubble.ai-rendered li { margin: .12rem 0; }
.ai-bubble.ai-rendered li > ul, .ai-bubble.ai-rendered li > ol { margin-bottom: 0; }
.ai-bubble.ai-rendered code { font-size: .88em; }
html[lang="fa"] .ai-bubble.ai-rendered ol, html[lang="ur"] .ai-bubble.ai-rendered ol { list-style: persian; }
html[lang="ar"] .ai-bubble.ai-rendered ol { list-style: arabic-indic; }
/* Under Farsi every digit is Persian, list numbers included (they are generated by CSS, so the
   fa-digits.js text pass never sees them). :where() keeps the rule at zero specificity, so any
   class that removes markers (.list-unstyled, .breadcrumb, nav lists) still wins. */
:where(html[lang="fa"]) ol { list-style-type: persian; }
/* "Assistant is thinking…" indicator shown while the reply is in flight. */
.ai-bubble.ai-typing { display: inline-flex; align-items: center; gap: .4rem; opacity: .85; }
.ai-dots { display: inline-flex; gap: 3px; }
.ai-dots > span {
    width: 6px; height: 6px; border-radius: 50%;
    background: currentColor; opacity: .35;
    animation: aiDot 1s infinite ease-in-out;
}
.ai-dots > span:nth-child(2) { animation-delay: .15s; }
.ai-dots > span:nth-child(3) { animation-delay: .3s; }
@keyframes aiDot { 0%, 60%, 100% { transform: translateY(0); opacity: .3; } 30% { transform: translateY(-3px); opacity: .9; } }

/* Compact photo gallery: small fixed thumbnails with caption + date. */
.photo-grid { display: flex; flex-wrap: wrap; gap: .6rem; }
.photo-card { width: 104px; }
.photo-card .photo-thumb {
    width: 104px; height: 104px; object-fit: cover; border-radius: 10px;
    border: 1px solid var(--surface-border); cursor: zoom-in; transition: transform .12s ease;
}
.photo-card .photo-thumb:hover { transform: scale(1.04); }
.photo-card .photo-cap { font-size: .72rem; line-height: 1.2; margin-top: .25rem; }
.photo-card .photo-date { font-size: .68rem; color: var(--text-muted); }

/* ---------- Sidebar: fit full menu labels, never truncate ----------
   Widen the sidebar and let labels wrap instead of being clipped with an
   ellipsis (AdminLTE's default is nowrap + text-overflow:ellipsis). This keeps
   long items like "Welfare & hoof health" and RTL fa/ar labels fully readable. */
:root, [data-bs-theme] { --lte-sidebar-width: 14.5rem; }   /* beats AdminLTE's per-theme 250px */
.sidebar-menu .nav-link { align-items: flex-start; }
.sidebar-menu .nav-link > p {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.25;
    /* reserve room for the absolutely-positioned collapse arrow / "soon" badge */
    padding-inline-end: 1.25rem;
}

/* ---------- Animal flag colours ---------- */
.flag-RED { background: #dc3545 !important; color: #fff !important; }
.flag-ORANGE { background: #fd7e14 !important; color: #fff !important; }
.flag-YELLOW { background: #ffc107 !important; color: #000 !important; }
.flag-GREEN { background: #198754 !important; color: #fff !important; }
.flag-BLUE { background: #0d6efd !important; color: #fff !important; }
.flag-PURPLE { background: #6f42c1 !important; color: #fff !important; }
.flag-GRAY { background: #6c757d !important; color: #fff !important; }

/* ---------- Top category menu bar ---------- */
.app-topmenu {
    /* Opaque raised surface: it sits sticky over scrolling content, so a translucent --surface
       let text bleed through. --bg-elevated is fully opaque in both themes. A stronger border +
       shadow make the strip read as a distinct navigation bar rather than blending into content. */
    background: var(--bg-elevated);
    border-bottom: 2px solid var(--surface-border-strong);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
    position: sticky;
    top: 0;
    z-index: 1030;
}
.app-topmenu .container-fluid { padding-top: .45rem; padding-bottom: .45rem; }
/* Hide the horizontal scrollbar but keep it scrollable on small screens. */
.app-topmenu .container-fluid::-webkit-scrollbar { height: 0; }
/* Tablet and desktop: a long section bar (Health has 15 pages) wraps onto a second line instead of
   running off the right edge, where the last links were cut off with no hint to scroll (Saeed,
   v0.9.229). The bar is sticky, not fixed, so its height simply grows. Phones keep the swipeable
   single row with the fade hint (see the max-width: 767.98px block): 15 links would be 5-6 rows. */
@media (min-width: 768px) {
    .app-topmenu .container-fluid {
        flex-wrap: wrap !important;     /* beats Bootstrap's .flex-nowrap utility on the element */
        overflow: visible !important;
    }
    /* Wave 3: slightly narrower links so the Health bar (17 links after wave 3) stays on TWO rows at 1280px,
       as Saeed asked; the later screen-block padding (13px 14px) is overridden by the higher specificity. */
    .app-topmenu .topmenu-link { padding-inline: 10px; }
}
.topmenu-link {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    white-space: nowrap;
    padding: .4rem .9rem;
    border-radius: 10px;
    /* High-contrast, semibold labels so the bar is clearly legible in both light and dark themes. */
    color: var(--text-primary);
    text-decoration: none;
    font-size: .92rem;
    font-weight: 600;
    transition: background .15s ease, color .15s ease;
}
.topmenu-link i { color: var(--text-secondary); }
.topmenu-link:hover {
    background: var(--surface-2, rgba(0, 0, 0, .06));
    color: var(--text-primary);
}
.topmenu-link:hover i { color: var(--text-primary); }
/* Active category: filled brand pill, clearly dominant over the (now bolder) inactive items. */
.topmenu-link.active {
    background: var(--gradient-primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(59, 91, 219, 0.35);
}
.topmenu-link.active i { color: #fff !important; }

/* KPI target editor: keep the numeric bound inputs compact. */
.kpi-target-input { width: 8.5rem; }

/* Target-goal settings list (/kpi/targets).
   Dividers run the full width of the card, so they must not sit on a Bootstrap .row — its
   negative side margins pushed every line past the card padding. Rows carry their own padding
   instead, and flex-end keeps the Save/Reset buttons on the same baseline as the inputs whether
   a metric shows one bound or two. */
.kpi-target-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: .5rem 1rem;
    padding: .75rem 1rem;
    border-top: 1px solid var(--bs-border-color);
}
/* The name block is prose, so centre it against the control block rather than baseline-aligning
   two things of different heights. */
.kpi-target-name { flex: 1 1 15rem; min-width: 0; align-self: center; }
.kpi-target-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: .5rem;
}
.kpi-target-field { display: flex; flex-direction: column; }
.kpi-target-field .form-label { line-height: 1.3; }

/* ---------- Print / PDF ----------
   Turn any page into a clean printable document: drop the app chrome (sidebar, header, top bar,
   buttons, toolbars) and lay the content out full-width in black-on-white, so a printed report is
   a proper document — not a screenshot of the screen. The .print-only document header (farm name,
   title, date) is revealed; .no-print elements are removed. */
.print-only { display: none; }
@media print {
    /* Table headers keep their case on paper too: theme.css uppercases thead cells, which turns unit symbols
       into wrong ones (mg/dL -> MG/DL, lb DM/head/day -> LB DM/HEAD/DAY) on every printed table. */
    .table thead th, .table > thead th { text-transform: none !important; letter-spacing: normal !important; }

    .app-sidebar, .app-header, .app-topmenu, .app-footer, .app-content-header,
    .no-print, .table-toolbar, .table-pagination,
    /* the accessibility skip-link is parked above the viewport; a printed page has no
       viewport, so without this it leaks onto page one as an empty bordered box */
    .skip-link,
    .btn, .navbar { display: none !important; }

    /* Undo the fixed app-shell so content flows and paginates across pages. */
    html, body, .app-wrapper, .app-main {
        display: block !important;
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        background: #fff !important;
    }
    .app-wrapper { grid-template-columns: 1fr !important; }
    .app-content, .app-content > .container-fluid { padding: 0 !important; margin: 0 !important; }

    /* Force readable black-on-white (the app's default theme is dark). */
    body, .card, .card-body, .card-header, table, th, td, p, span, div, h1, h2, h3, h4, small {
        color: #000 !important;
        background-color: transparent !important;
    }

    /* Cards become clean bordered blocks that don't split across a page break. */
    .card {
        border: 1px solid #999 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        margin-bottom: 12pt !important;
        break-inside: avoid;
        page-break-inside: avoid;
    }
    .card-header { border-bottom: 1px solid #999 !important; font-weight: 700; }

    /* Report tables: full width, ruled, with the header repeated on every printed page. */
    .report-table-wrap { max-height: none !important; overflow: visible !important; }
    /* A scroll box clips on paper: let every wrapped table (and its long cells) flow to the page width. */
    .table-responsive, .table-scroll { overflow: visible !important; }
    .book-table td { white-space: normal !important; }
    table { width: 100% !important; border-collapse: collapse !important; }
    thead { display: table-header-group; }
    tr { page-break-inside: avoid; }
    th, td { border: 1px solid #bbb !important; padding: 3pt 5pt !important; }
    .badge { border: 1px solid #999 !important; padding: 0 2pt !important; font-weight: 600; }

    /* Document header shown only on the printout. */
    .print-only { display: block !important; }
    .report-doc-header {
        border-bottom: 2px solid #000;
        margin-bottom: 12pt;
        padding-bottom: 6pt;
    }
    .report-doc-header .rdh-farm { font-size: 15pt; font-weight: 700; }
    .report-doc-header .rdh-title { font-size: 11pt; }
    .report-doc-header .rdh-meta { font-size: 9pt; }

    /* A collapsed card prints as an empty header — data loss on paper. Expand them all. */
    .card.dd-collapsed > .card-body,
    .card.dd-collapsed > .card-footer { display: block !important; }

    /* Safety net for charts: chart-theme.js resizes each canvas for the print layout, but if a
       page loads Chart.js without it the raster at least scales instead of overflowing. */
    canvas { max-width: 100% !important; }

    @page { margin: 14mm; }
}

/* ============================================================
   Small screens: action-button clusters (a .btn next to an inline form in
   table cells and toolbars) separate with whitespace only, so when they wrap
   on a phone the rows touch. Give every clustered button a consistent 2px
   vertical breather and a small inline gap; flex parents with gap-* utilities
   are unaffected (their gap already covers both axes).
   ============================================================ */
td > .btn, td > form.d-inline, td > .d-inline > .btn,
.card-body > .btn + .btn, .card-body > form.d-inline {
    margin-block: 2px;
}
td > form.d-inline { display: inline-block; }
td > .btn + .btn, td > .btn + form.d-inline, td > form.d-inline + .btn,
td > form.d-inline + form.d-inline {
    margin-inline-start: 4px;
}

/* Dashboard KPI cards (.kpi-accent) are styled once, in the refresh block below: a plain
   bordered card, no accent bar and no hover lift. */

/* Stat tiles everywhere: the h3-number pattern steps down to the compact scale
   (matches the dashboard); labels and hierarchy untouched. */
.card-body .h3.mb-0{font-size:1.5rem}

/* ============================================================
   Desktop density: business tools run tighter type than Bootstrap's 16px default
   (the portal's Tabler base is 14px). Reduce the base to 15px on desktop only —
   phones keep 16px for barn readability and to avoid iOS auto-zoom on <16px
   inputs. Barn mode is untouched by design — it is a standalone page with its
   own styles and never loads this stylesheet. rem-based sizes (headings, .h3
   stats) scale down with the root automatically.
   ============================================================ */
@media (min-width: 768px) {
    html { font-size: 15px; }
    .table { font-size: .95rem; }
    .text-muted.small, .form-hint, .card .small { font-size: .82rem; }
}

/* ---------- Dashboard figures ----------
   The front page is mostly numbers, and numbers in a proportional face jitter as they change:
   columns stop lining up and a rising figure looks like it is also moving sideways. Tabular
   figures fix the width of every digit, which is what makes a dashboard feel settled rather than
   restless. Kept to a class so it applies where digits are compared, not to running text. */
.dash-figure {
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}


/* Bounds the dashboard milk chart. Chart.js with maintainAspectRatio:false measures its parent, so
   without a height here the canvas grows to fill whatever space it is given and then some. */
.dash-chart { position: relative; height: 220px; }
@media (min-width: 992px) { .dash-chart { height: 260px; } }

/* Herd composition doughnut beside its legend. Fixed square so the ring never grows with the
   card; the dots use the same brand tokens the slices read, so they match in both themes. */
.dash-pie { position: relative; width: 120px; height: 120px; flex: 0 0 auto; }
/* The legend counts are small labels, not KPI figures: the refresh block below sizes every
   .dash-figure at 29px for the stat tiles, which swamped this list. */
.dash-pie-legend li { line-height: 1.3; padding: 2px 0; }
.dash-pie-legend .dash-figure { font-size: 13px; font-weight: 600; letter-spacing: normal; line-height: 1.3; }
.dash-pie-dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%;
                margin-inline-end: .35rem; vertical-align: -1px; opacity: .85; }
.dash-pie-milking    { background: var(--brand-teal); }
.dash-pie-dry        { background: var(--brand-blue); }
.dash-pie-youngstock { background: var(--brand-orange); }
.dash-pie-bulls      { background: var(--brand-violet); }
/* Calendar grid, light theme: the month sits inside a white card, so white day cells need a
   border that is actually visible and out-of-month days a tint that reads as "not this month";
   the hairline + near-white tertiary used to leave the whole grid a single white sheet. */
[data-bs-theme="light"] .calendar-grid { --bs-table-border-color: var(--surface-border-strong); }
[data-bs-theme="light"] .calendar-grid thead th { background: var(--surface-strong); color: var(--text-secondary); }
[data-bs-theme="light"] .calendar-grid td.bg-body-tertiary { background: var(--bg-deep) !important; }
.calendar-grid .badge { font-size: 11px; }

/* reveal-section.js: a card scrolled to from a remote button stops below the sticky top bar,
   and flashes once so the eye lands on it. */
.app-content .card { scroll-margin-top: 4rem; }
@keyframes dd-reveal-flash {
    0%   { box-shadow: 0 0 0 0 rgba(var(--bs-primary-rgb), .55); }
    100% { box-shadow: 0 0 0 10px rgba(var(--bs-primary-rgb), 0); }
}
.dd-reveal-flash { animation: dd-reveal-flash 1.1s ease-out 1; }

/* Help shortcut pinned to the sidebar foot (layout/base.html). The soft brand tint makes it a
   noticeable panel without competing with the active nav item; RTL flips via flex + the
   global icon mirroring in rtl.css. */
.sidebar-help {
    display: flex; align-items: center; gap: .6rem;
    margin: .5rem .75rem .75rem; padding: .55rem .7rem;
    border-radius: 10px; text-decoration: none;
    background: var(--soft-primary); color: var(--text-primary);
    border: 1px solid transparent;
}
/* AdminLTE paints every sidebar anchor its own grey (#c2c7d0) at higher specificity, which left
   the title fainter than its subtitle; the ink has to be pinned. */
.app-sidebar .sidebar-help, .app-sidebar .sidebar-help .sidebar-help-title { color: var(--text-primary) !important; }
.sidebar-help:hover, .sidebar-help.active { border-color: var(--brand-teal); }
.sidebar-help > .bi-question-circle { font-size: 1.25rem; color: var(--brand-teal); }
.sidebar-help-text { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; line-height: 1.2; }
.sidebar-help-title { font-weight: 600; font-size: 13px; }
.sidebar-help-sub { font-size: 11px; color: var(--text-secondary); }
.sidebar-help-arrow { font-size: .8rem; color: var(--text-muted); }

/* Simple menu (menu/setup.html, menu/features.html). Setup tiles are btn-check toggles: the tick shows only
   on a chosen tile, and the description keeps the tile's text colour instead of turning grey on the blue. */
.dd-setup-tile {
    padding: .7rem .8rem; white-space: normal;
    /* house teal, not Bootstrap's stock blue (btn-outline-primary is not re-themed like .btn-primary) */
    --bs-btn-color: var(--brand-teal); --bs-btn-border-color: var(--brand-teal);
    --bs-btn-hover-bg: var(--soft-primary); --bs-btn-hover-color: var(--text-primary); --bs-btn-hover-border-color: var(--brand-teal);
    --bs-btn-active-bg: var(--brand-teal); --bs-btn-active-color: var(--on-brand); --bs-btn-active-border-color: var(--brand-teal);
}
.dd-setup-tile .dd-setup-desc { opacity: .8; }
.dd-setup-tile .dd-setup-tick { visibility: hidden; }
.btn-check:checked + .dd-setup-tile .dd-setup-tick { visibility: visible; }
/* A short side column beside ONE long list (a form beside its history, an upload beside the templates) stays in
   view while the list scrolls, so the space under it is not a dead hole (2026-11-13). Below the pinned top bar
   (.app-topmenu, ~3.1rem). js/side-sticky.js turns it off for a column taller than the screen. scripts/ui-checks/
   alignment.js accepts a tall gap only beside such a column — anything else must be rebalanced. */
@media (min-width: 992px) {
    .dd-side-sticky:not(.dd-sticky-off) { position: sticky; top: 3.6rem; align-self: flex-start; }
}

/* Alert-type groups (notifications/settings.html) flow in columns across a full-width card: one long
   column beside a short card left a screen-high empty gap. A group never splits across columns. */
.dd-kind-columns { column-gap: .5rem; }
@media (min-width: 992px) { .dd-kind-columns { columns: 2; } }
@media (min-width: 1600px) { .dd-kind-columns { columns: 3; } }
.dd-kind-columns > .dd-kind-group { break-inside: avoid; margin-bottom: .25rem; }

/* Full menu chosen: the page ticks are kept (for a later switch back) but greyed out and inert. */
.dd-menu-form:has(#menuModeFull:checked) .dd-menu-pages { opacity: .45; pointer-events: none; }

/* ============================================================
   Approved CSS refresh — Bootstrap/AdminLTE, using the reviewed preview.
   Screen-only: printed reports keep the existing house document layout.
   Theme tokens live in theme.css; phone overrides share the single block.
   ============================================================ */
@media screen {
  /* :where() keeps this at plain `body` weight so a standalone page's own body rule
     (the sign-in photo) still wins; theme.css's html,body loads earlier and loses. */
  :where(html) body {
    font-size: 14px;
    letter-spacing: normal;
    background: var(--bg-base);
    color: var(--text-primary);
  }
  .app-wrapper {
    background: var(--bg-base);
  }
  html .app-sidebar[data-bs-theme] {
    --bg-deep: inherit;
    --bg-base: inherit;
    --bg-elevated: inherit;
    --sidebar-top: inherit;
    --sidebar-bottom: inherit;
    --surface: inherit;
    --surface-strong: inherit;
    --surface-border: inherit;
    --surface-border-strong: inherit;
    --text-primary: inherit;
    --text-secondary: inherit;
    --text-muted: inherit;
    --bs-body-bg: inherit;
    --bs-body-color: inherit;
    --bs-body-secondary-bg: inherit;
    --bs-tertiary-bg: inherit;
    --bs-border-color: inherit;
    --bs-link-color: inherit;
    --bs-link-hover-color: inherit;
    --brand-teal: inherit;
    --brand-cyan: inherit;
    --brand-blue: inherit;
    --brand-orange: inherit;
    --soft-primary: inherit;
    --soft-warning: inherit;
    --soft-danger: inherit;
    --soft-info: inherit;
    --on-brand: inherit;
    --ink-primary: inherit;
    --ink-warning: inherit;
    --ink-danger: inherit;
    --ink-info: inherit;
    --control-bg: inherit;
    --control-border: inherit;
    --bs-primary-rgb: inherit;
    --bs-success-rgb: inherit;
    --bs-info-rgb: inherit;
    --bs-warning-rgb: inherit;
  }
  /* Links use the ink teal: the brand fill colour is 4.3:1 on the grey page background in light
     mode (the onboarding "Undo" links sit straight on it), the ink is 5.4:1 there. */
  .app-content a:not(.btn):not(.card) {
    color: var(--ink-primary);
  }
  .card-body > .small.text-uppercase {
    font-size: 11px;
    letter-spacing: normal;
    text-transform: none !important;
    font-weight: 600;
  }
  .d-flex.justify-content-between.small .dash-figure {
    font-size: 13px;
    letter-spacing: normal;
    line-height: 1.5;
  }
  .kpi-accent .bi {
    color: var(--brand-teal);
  }
  .kpi-accent.border-warning .bi {
    color: var(--brand-orange);
  }
  .app-content .badge.flag-GREEN {
    background: var(--soft-primary) !important;
    color: var(--ink-primary) !important;
  }
  .app-content .badge.flag-RED {
    background: var(--soft-danger) !important;
    color: var(--ink-danger) !important;
  }
  .app-content .badge.flag-YELLOW {
    background: var(--soft-warning) !important;
    color: var(--ink-warning) !important;
  }
  .app-header.navbar {
    background: var(--navbar-bg) !important;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-bottom: 1px solid var(--surface-border);
    box-shadow: none;
    min-height: 60px;
  }
  .app-header .nav-link {
    font-size: 13px;
    color: var(--text-secondary) !important;
  }
  .app-header .badge.text-bg-success {
    background: var(--soft-primary) !important;
    color: var(--ink-primary) !important;
    font-size: 12px;
    font-weight: 600;
    border-radius: 5px;
    padding: 5px 8px;
  }
  /* Sign-in flow: the toggle floats in the top end corner over the farm photo. */
  .auth-theme-toggle {
    position: fixed;
    top: 1rem;
    inset-inline-end: 1rem;
    z-index: 10;
    background: var(--bg-elevated) !important;
    box-shadow: 0 4px 14px -6px rgba(0, 0, 0, 0.45) !important;
  }
  .theme-toggle {
    border: 1px solid var(--surface-border);
    border-radius: 6px;
    box-shadow: none !important;
    background: transparent;
    color: var(--text-secondary);
    width: 34px;
    height: 34px;
  }
  .app-sidebar {
    background: var(--bg-elevated) !important;
    border-inline-end: 1px solid var(--surface-border);
    box-shadow: none !important;
  }
  .sidebar-brand {
    height: 61px;
    border-bottom: 1px solid var(--surface-border);
    padding-inline: 18px;
  }
  .sidebar-brand .brand-logo {
    width: 34px;
    height: 34px;
    box-shadow: none;
    border: 0;
    border-radius: 7px;
    padding: 0;
  }
  .sidebar-brand .brand-text {
    color: var(--text-primary);
    background: none;
    -webkit-text-fill-color: var(--text-primary);
    font-size: 20px;
    font-weight: 650;
    letter-spacing: -0.5px;
  }
  .sidebar-menu .nav-link {
    font-size: 13px;
    border-radius: 6px;
    margin: 3px 10px;
    padding: 10px 12px;
    font-weight: 500;
    transition: background 0.15s;
  }
  .sidebar-menu .nav-link:hover {
    transform: none;
    background: var(--surface-strong);
  }
  .sidebar-menu .nav-link .nav-icon {
    font-size: 17px;
    color: var(--text-muted);
  }
  .sidebar-menu .nav-link.active,
  .sidebar-menu .nav-link.active:hover {
    background: var(--soft-primary) !important;
    box-shadow: none !important;
    color: var(--ink-primary) !important;
    font-weight: 650;
  }
  .sidebar-menu .nav-link.active .nav-icon {
    color: var(--ink-primary) !important;
  }
  .sidebar-menu .nav-link p {
    line-height: 1.5;
  }
  .nav-header {
    color: var(--text-muted) !important;
    font-size: 10px;
    letter-spacing: 0.9px;
  }
  .sidebar-wrapper {
    padding-top: 12px;
  }
  .app-topmenu {
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--surface-border);
    box-shadow: none;
  }
  .app-topmenu .container-fluid {
    padding-block: 0;
    gap: 2px !important;
    min-height: 45px;
  }
  .topmenu-link {
    background: transparent;
    padding: 13px 14px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: 0;
    min-height: 45px;
    border-bottom: 2px solid transparent;
    box-shadow: none;
  }
  .topmenu-link i {
    font-size: 13px;
    color: var(--text-muted);
  }
  .topmenu-link.active,
  .topmenu-link.active:hover {
    background: transparent !important;
    color: var(--brand-teal) !important;
    border-bottom-color: var(--brand-teal);
    box-shadow: none;
    font-weight: 600;
  }
  .topmenu-link.active i {
    color: var(--brand-teal) !important;
  }
  .topmenu-link:hover {
    background: var(--surface-strong);
    color: var(--text-primary);
  }
  .app-content-header {
    padding-top: 20px;
    padding-bottom: 12px;
  }
  .app-content-header h3 {
    font-size: 26px;
    font-weight: 650;
    letter-spacing: -0.6px;
  }
  .app-content > .container-fluid,
  .app-content-header > .container-fluid {
    padding-inline: 24px;
  }
  .app-content {
    padding-top: 0;
    padding-bottom: 16px;
  }
  .app-content .row {
    --bs-gutter-x: 10px;
    --bs-gutter-y: 10px;
  }
  .app-content .mb-4,
  .app-content .mb-5 {
    margin-bottom: 10px !important;
  }
  .app-content .mb-3 {
    margin-bottom: 10px !important;
  }
  .app-content .mt-3 {
    margin-top: 14px !important;
  }
  .card {
    background: var(--bg-elevated) !important;
    border: 1px solid var(--surface-border) !important;
    border-radius: 8px;
    box-shadow: 0 1px 2px #14283e08 !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
  .card:hover {
    box-shadow: 0 1px 2px #14283e08 !important;
  }
  .app-content .card-body {
    padding: 14px 16px;
  }
  .app-content .card-header {
    padding: 12px 16px;
    background: transparent;
    border-bottom: 1px solid var(--surface-border);
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 600;
  }
  .card-footer {
    background: transparent;
    border-top: 1px solid var(--surface-border);
    padding: 10px 16px;
  }
  .app-content .card.h-100 {
    height: auto !important;
  }
  .card h2.h4 {
    font-size: 23px;
    font-weight: 650;
    letter-spacing: -0.4px;
  }
  .kpi-accent {
    border-top: 1px solid var(--surface-border) !important;
  }
  .kpi-accent .card-body.py-2 {
    padding: 14px 16px !important;
  }
  .kpi-accent .small.text-uppercase {
    text-transform: none !important;
    color: var(--text-secondary) !important;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: normal;
  }
  .dash-figure {
    font-size: 29px;
    font-weight: 650;
    letter-spacing: -0.7px;
    line-height: 1.35;
  }
  .kpi-accent small {
    font-size: 11px;
  }
  .kpi-accent .text-success {
    color: var(--brand-teal) !important;
  }
  .app-content a.card:hover {
    border-color: var(--brand-teal) !important;
  }
  .dash-chart {
    height: 238px;
  }
  .progress {
    background: var(--surface-strong);
    height: 5px !important;
    border-radius: 4px;
  }
  /* Plain progress bars (Get started card, onboarding page) follow the brand, not Bootstrap blue. */
  .progress-bar:not([class*="bg-"]) {
    background-color: var(--brand-teal);
  }
  .progress-bar.bg-info {
    background: var(--brand-teal) !important;
  }
  .progress-bar.bg-success {
    background: var(--brand-blue) !important;
  }
  .progress-bar.bg-warning {
    background: var(--brand-orange) !important;
  }
  .btn {
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    padding: 8px 12px;
    line-height: 1.35;
    box-shadow: none !important;
    background-image: none !important;
    transition:
      background 0.15s,
      border-color 0.15s;
  }
  .btn-sm {
    font-size: 12px;
    padding: 7px 10px;
    min-height: 31px;
  }
  /* A small button inside a one-line banner (trial countdown, payment due) must fit the strip. */
  .alert .btn-sm {
    min-height: 0;
    padding-top: 2px;
    padding-bottom: 2px;
  }
  .btn-primary {
    --bs-btn-bg: var(--brand-teal);
    --bs-btn-border-color: var(--brand-teal);
    --bs-btn-hover-bg: var(--brand-teal-hover);
    --bs-btn-hover-border-color: var(--brand-teal-hover);
    --bs-btn-color: var(--on-brand);
    --bs-btn-hover-color: var(--on-brand);
    background: var(--brand-teal) !important;
    border-color: var(--brand-teal) !important;
    color: var(--on-brand) !important;
  }
  /* Contextual solid buttons: ONE flat brand colour in both themes. theme.css paints
     .btn-success with a gradient token that the `background-image: none` above strips, which
     left "Upgrade & pay now" as white text on a white card in light mode. .btn-info (trial
     banner "Choose a plan") is Bootstrap's cyan otherwise — off palette. */
  .btn-success,
  .btn-info {
    --bs-btn-bg: var(--brand-teal);
    --bs-btn-border-color: var(--brand-teal);
    background: var(--brand-teal) !important;
    border-color: var(--brand-teal) !important;
    color: var(--on-brand) !important;
  }
  .btn-success:hover, .btn-success:focus, .btn-success:active,
  .btn-info:hover, .btn-info:focus, .btn-info:active {
    background: var(--brand-teal-hover) !important;
    border-color: var(--brand-teal-hover) !important;
    color: var(--on-brand) !important;
  }
  html[data-bs-theme="dark"] .btn-success:hover, html[data-bs-theme="dark"] .btn-success:focus,
  html[data-bs-theme="dark"] .btn-info:hover, html[data-bs-theme="dark"] .btn-info:focus {
    background: var(--brand-teal-hover-dark) !important;
    border-color: var(--brand-teal-hover-dark) !important;
  }
  /* Outline variants (plan picker, "Continue on the free plan"): readable teal text on the card,
     and the chosen plan (.btn-check:checked) fills solid in the same colour — not Bootstrap's green. */
  .btn-outline-success,
  .btn-outline-info {
    color: var(--brand-teal) !important;
    border-color: var(--brand-teal) !important;
    background: transparent !important;
    transition: none;   /* state swaps atomically: the fade showed white text on a half-painted teal */
  }
  .btn-outline-success:hover, .btn-outline-info:hover,
  .btn-check:checked + .btn-outline-success, .btn-check:checked + .btn-outline-info,
  .btn-outline-success.active, .btn-outline-info.active {
    background: var(--brand-teal) !important;
    border-color: var(--brand-teal) !important;
    color: var(--on-brand) !important;
  }
  .btn-outline-primary {
    color: var(--ink-primary);
    border-color: var(--surface-border-strong);
    background: var(--soft-primary);
  }
  .btn-outline-secondary {
    color: var(--text-secondary);
    border-color: var(--surface-border);
    background: var(--surface-strong);
  }
  .btn-outline-warning {
    color: var(--ink-warning);
    border-color: var(--surface-border);
    background: var(--soft-warning);
  }
  .btn-outline-danger {
    color: var(--ink-danger);
    border-color: var(--surface-border);
    background: var(--soft-danger);
  }
  .btn-outline-primary:hover,
  .btn-outline-secondary:hover {
    color: var(--text-primary);
    background: var(--surface-strong);
    border-color: var(--surface-border-strong);
  }
  .btn-link {
    color: var(--ink-primary);
  }
  .badge {
    font-weight: 550;
    letter-spacing: normal;
    border-radius: 4px;
    padding: 4px 7px;
    font-size: 10px;
    line-height: 1.2;
  }
  .badge.text-bg-success,
  .badge.bg-success {
    background: var(--soft-primary) !important;
    color: var(--ink-primary) !important;
  }
  .badge.text-bg-warning {
    background: var(--soft-warning) !important;
    color: var(--ink-warning) !important;
  }
  .badge.text-bg-info {
    background: var(--soft-info) !important;
    color: var(--ink-info) !important;
  }
  /* Solid brand badges/tiles: Bootstrap paints white text, which is 2.1:1 on the dark theme's
     lighter teal (#50c5b3) — the on-brand ink flips to dark there, as the buttons already do. */
  .badge.text-bg-primary,
  .small-box.text-bg-primary,
  .small-box.text-bg-success {
    color: var(--on-brand) !important;
  }
  .badge.text-bg-secondary,
  .badge.text-bg-light {
    background: var(--surface-strong) !important;
    color: var(--text-secondary) !important;
  }
  .rounded-pill.badge {
    border-radius: 5px !important;
  }
  .badge.text-bg-danger {
    background: var(--soft-danger) !important;
    color: var(--ink-danger) !important;
  }
  .form-control,
  .input-group-text {
    background: var(--control-bg) !important;
  }
  /* A select sets only the colour: the `background` shorthand also wiped Bootstrap's arrow image, so every
     select looked like a text box (v0.9.190 – 0.9.235). The arrow sits at the end side (the RTL build puts it
     on the left) and the end padding keeps the text clear of it. */
  .form-select {
    background-color: var(--control-bg) !important;
  }
  .form-control,
  .form-select,
  .input-group-text {
    border: 1px solid var(--control-border) !important;
    border-radius: 6px !important;
    color: var(--text-primary);
    font-size: 13px;
    padding: 8px 10px;
    line-height: 1.4;
    box-shadow: none;
  }
  .form-control-sm,
  .form-select-sm,
  .input-group-sm > .form-control,
  .input-group-sm > .input-group-text {
    font-size: 12px;
    padding: 7px 10px;
  }
  .form-select,
  .form-select-sm {
    padding-inline-end: 2.25rem;
  }
  .form-control:focus {
    background: var(--bg-elevated) !important;
  }
  .form-select:focus {
    background-color: var(--bg-elevated) !important;
  }
  .form-control:focus,
  .form-select:focus {
    border-color: var(--brand-teal) !important;
    box-shadow: 0 0 0 2px var(--soft-primary) !important;
  }
  .form-control::placeholder {
    color: var(--text-muted);
  }
  .input-group-text {
    color: var(--text-secondary);
    border-inline-end: 0 !important;
  }
  /* A trailing addon (the password eye, a unit) closes the group: it keeps its end border, or the
     outlined light field ends in an open box past the field's edge. */
  .input-group > .input-group-text:last-child {
    border-inline-end: 1px solid var(--control-border) !important;
  }
  /* One rounded pill per group: only the outer corners are rounded, whichever piece sits at
     either end (icon addon, field, eye button, select). Logical sides so RTL flips for free. */
  .input-group > :not(:first-child):not(.dropdown-menu) {
    border-start-start-radius: 0 !important;
    border-end-start-radius: 0 !important;
  }
  .input-group > :not(:last-child):not(.dropdown-toggle):not(.dropdown-menu) {
    border-start-end-radius: 0 !important;
    border-end-end-radius: 0 !important;
  }
  /* The RTL build keeps number / email / tel / url fields direction:ltr (Bootstrap's rtl:raw rule), and the
     logical corners above resolve against the field's OWN direction: inside a group under dir=rtl the number
     box of /kpi/targets squared its outer (right) corners and rounded the seam. Inside a group the field takes
     the group's direction, so its corners follow the row (0.9.236 review). */
  .input-group > .form-control:is([type=number], [type=email], [type=tel], [type=url]) {
    direction: inherit;
  }
  .input-group > .form-control:focus {
    position: relative;
    z-index: 3;
  }
  .form-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 5px;
  }
  .form-text {
    font-size: 11px;
  }
  .form-check-input:checked {
    background-color: var(--brand-teal);
    border-color: var(--brand-teal);
  }
  .table {
    --bs-table-color: var(--text-primary);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--surface-border);
    --bs-table-striped-bg: var(--surface-strong);
    --bs-table-hover-bg: var(--soft-primary);
    color: var(--text-primary);
    font-size: 12px;
    margin-bottom: 8px;
  }
  /* Contextual rows (cull candidates, off-track growth, underperforming lactations, statement
     subtotals): Bootstrap paints them with its own light pastel and black text, which on the
     dark theme is a pink slab with unreadable grey text. Use the theme's soft tints instead,
     keep the body text colour, and mark the row with a thin colour bar at its start. */
  .table > tbody > tr.table-danger,
  .table > tbody > tr.table-warning,
  .table > tbody > tr.table-success,
  .table > tbody > tr.table-info,
  .table > tbody > tr.table-light,
  .table > tbody > tr.table-secondary {
    --bs-table-color: var(--text-primary);
    --bs-table-striped-color: var(--text-primary);
    --bs-table-hover-color: var(--text-primary);
    --bs-table-border-color: var(--surface-border);
    color: var(--text-primary);
  }
  .table > tbody > tr.table-danger {
    --bs-table-bg: var(--soft-danger);
    --bs-table-striped-bg: var(--soft-danger);
    --bs-table-hover-bg: var(--soft-danger);
  }
  .table > tbody > tr.table-warning {
    --bs-table-bg: var(--soft-warning);
    --bs-table-striped-bg: var(--soft-warning);
    --bs-table-hover-bg: var(--soft-warning);
  }
  .table > tbody > tr.table-success {
    --bs-table-bg: var(--soft-primary);
    --bs-table-striped-bg: var(--soft-primary);
    --bs-table-hover-bg: var(--soft-primary);
  }
  .table > tbody > tr.table-info {
    --bs-table-bg: var(--soft-info);
    --bs-table-striped-bg: var(--soft-info);
    --bs-table-hover-bg: var(--soft-info);
  }
  .table > tbody > tr.table-light,
  .table > tbody > tr.table-secondary {
    --bs-table-bg: var(--surface-strong);
    --bs-table-striped-bg: var(--surface-strong);
    --bs-table-hover-bg: var(--surface-strong);
  }
  .table > tbody > tr.table-danger > :first-child { box-shadow: inset 3px 0 0 var(--ink-danger); }
  .table > tbody > tr.table-warning > :first-child { box-shadow: inset 3px 0 0 var(--brand-orange); }
  html[dir="rtl"] .table > tbody > tr.table-danger > :first-child { box-shadow: inset -3px 0 0 var(--ink-danger); }
  html[dir="rtl"] .table > tbody > tr.table-warning > :first-child { box-shadow: inset -3px 0 0 var(--brand-orange); }
  .table > thead th {
    background: var(--surface-strong) !important;
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 550;
    text-transform: none;
    letter-spacing: normal;
    border-bottom: 1px solid var(--surface-border);
    padding-block: 10px !important;
  }
  .table > tbody td {
    padding-block: 8px !important;
    border-bottom: 1px solid var(--surface-border);
    line-height: 1.4;
  }
  .table tbody tr:last-child td {
    border-bottom: 0;
  }
  .table tbody a {
    color: var(--ink-primary) !important;
  }
  .table-toolbar {
    margin-bottom: 10px !important;
    margin-top: 0;
  }
  .table-pagination {
    font-size: 11px;
    border-top: 1px solid var(--surface-border);
    padding-top: 10px;
    margin-top: 8px;
  }
  .tp-btn {
    background: var(--surface-strong) !important;
    border: 1px solid var(--surface-border) !important;
    color: var(--text-secondary) !important;
    border-radius: 5px !important;
    box-shadow: none !important;
    font-size: 11px;
  }
  .table-pagination .tp-num.active {
    background: var(--brand-teal) !important;
    color: var(--on-brand) !important;
    border-color: var(--brand-teal) !important;
  }
  .tp-size-select {
    background: var(--control-bg) !important;
    border: 1px solid var(--control-border) !important;
    border-radius: 5px;
    color: var(--text-primary);
  }
  .table-search {
    border-radius: 6px;
  }
  .text-muted,
  .text-body-secondary {
    color: var(--text-secondary) !important;
  }
  .text-primary {
    color: var(--brand-teal) !important;
  }
  .text-success {
    color: var(--brand-teal) !important;
  }
  .small,
  small {
    font-size: 12px;
  }
  .alert {
    border-radius: 7px;
    font-size: 12px;
    box-shadow: none !important;
  }
  .alert-warning {
    background: var(--soft-warning) !important;
    border: 1px solid var(--surface-border) !important;
    color: var(--text-secondary) !important;
  }
  .alert-info {
    background: var(--soft-info);
    border-color: var(--surface-border);
    color: var(--text-secondary);
  }
  .dropdown-menu {
    background: var(--bg-elevated);
    border-color: var(--surface-border);
    border-radius: 7px;
    box-shadow: 0 6px 20px #14283e18;
  }
  .dropdown-item {
    color: var(--text-primary);
    font-size: 12px;
  }
  .dropdown-item.active {
    background: var(--soft-primary);
    color: var(--ink-primary);
  }
  .dropdown-item:hover {
    background: var(--surface-strong);
  }
  .app-footer {
    background: var(--bg-elevated);
    border-top: 1px solid var(--surface-border);
    padding: 12px 24px;
    font-size: 11px;
    color: var(--text-muted);
  }
  .app-footer strong {
    font-weight: 500;
  }
  .app-footer .small {
    font-size: 10px;
  }
  .cow-avatar-img {
    border-radius: 8px;
    width: 66px;
    height: 66px;
  }
  .record-meta {
    font-size: 10px;
    color: var(--text-muted);
  }
  code {
    font-size: 12px;
    color: var(--ink-primary);
    background: var(--soft-primary);
    border-radius: 3px;
    padding: 2px 5px;
  }
  .accordion-button {
    background: var(--bg-elevated);
    color: var(--text-primary);
  }
  .profile-collapse-toggle {
    color: var(--text-secondary);
  }

  /* Soft controls still expose validation errors and keyboard focus. */
  .form-control.is-invalid,
  .form-select.is-invalid,
  .was-validated .form-control:invalid,
  .was-validated .form-select:invalid {
    border-color: var(--bs-danger) !important;
  }
  .form-control.is-valid,
  .form-select.is-valid,
  .was-validated .form-control:valid,
  .was-validated .form-select:valid {
    border-color: var(--brand-teal) !important;
  }
  .form-control.is-invalid:focus,
  .form-select.is-invalid:focus,
  .was-validated .form-control:invalid:focus,
  .was-validated .form-select:invalid:focus {
    box-shadow: 0 0 0 2px var(--soft-danger) !important;
  }
  .btn:focus-visible,
  .theme-toggle:focus-visible,
  .sidebar-menu .nav-link:focus-visible,
  .topmenu-link:focus-visible {
    outline: 2px solid var(--brand-teal);
    outline-offset: 2px;
  }
  .btn:disabled,
  .btn.disabled {
    opacity: 0.55;
  }
}

/* Health pages: a farm wall-clock moment is a date field plus a narrow time field side by side
   (fragments/health :: dateTime). The date takes the room; the time keeps just enough for HH:mm. */
.hx-datetime > input { min-width: 0; }
.hx-datetime > input:first-child { flex: 1 1 auto; }
.hx-datetime > .hx-time { flex: 0 0 7.5rem; }

/* ============================================================
   Operator text (portal announcement banner, a portal message in the bell/inbox, a support
   reply): rendered with the direction the operator chose — th:dir="${x.dir().attr()}".
   AUTO = dir="auto" + plaintext: every paragraph (line) follows its own first strong letter,
   so a Farsi message reads right to left in the English UI and an English one left to right
   in the Farsi UI. An explicit rtl/ltr (the composer toggle, for "DocDairy …" Farsi lines)
   applies to the whole text. Right-to-left text gets the RTL face in every UI language
   (css/vazirmatn.css is loaded by every page; --font-rtl exists only under html[dir=rtl]).
   ============================================================ */
.dd-bidi { unicode-bidi: plaintext; text-align: start; }
.dd-bidi[dir="rtl"], .dd-bidi[dir="ltr"] { unicode-bidi: isolate; }
.dd-bidi:dir(rtl) { font-family: var(--font-rtl, "Vazirmatn", "Vazir", "Tahoma", system-ui, sans-serif); letter-spacing: 0; }
.dd-bidi-pre { white-space: pre-line; overflow-wrap: anywhere; }
/* ============================================================
   Phones (< 768px). The customer opened the demo on an iPhone and called it "messy":
   the sidebar is off-canvas there, so the header has to carry the brand; the header
   overflowed in RTL and hid the user menu; the top bar clipped its last link with no
   hint that it scrolls; four full-width KPI cards pushed the chart below the fold;
   tables wrapped dates over three lines; small inputs made iOS zoom the whole page
   on focus; and the blurred background orbs made scrolling stutter. All of that is
   fixed here, in one place, so every page (demo and production alike) gets it.
   ============================================================ */
/* On-farm residue test: the NEG/POS/SUSPECT choices are a gloved-hand target (48px). */
.lab-residue-choices .btn { min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: .35rem; }
@media (max-width: 767.98px) {
    /* Tables marked .table-cards: one card per row on a phone instead of a sideways scroll. The
       column's header text is each cell's label (data-label, set by mobile-layout.js); the first cell
       is the card's title. The flex row follows dir, so the label sits on the right in RTL. */
    table.table-cards[data-cards-ready] thead { display: none; }
    table.table-cards[data-cards-ready],
    table.table-cards[data-cards-ready] > tbody { display: block; width: 100%; }
    table.table-cards[data-cards-ready] > tbody > tr {
        display: block; padding: .4rem .6rem; border-bottom: 1px solid var(--surface-border);
    }
    table.table-cards[data-cards-ready] > tbody > tr > td {
        display: grid; grid-template-columns: minmax(5.5rem, 38%) minmax(0, 1fr); column-gap: .75rem;
        align-items: baseline; padding: .1rem 0; border: 0; white-space: normal; background: transparent;
        text-align: start !important; /* beats .text-end: label and value line up on the start side */
    }
    table.table-cards[data-cards-ready] > tbody > tr > td > * { grid-column: 2; }
    table.table-cards[data-cards-ready] > tbody > tr > td::before {
        content: attr(data-label); grid-column: 1; grid-row: 1; color: var(--text-muted); font-size: .8rem;
    }
    table.table-cards[data-cards-ready] > tbody > tr > td:first-child,
    table.table-cards[data-cards-ready] > tbody > tr > td[data-label=""] { display: block; padding-bottom: .2rem; }
    /* page-level first/last cell paddings would indent the card title */
    table.table-cards[data-cards-ready] > tbody > tr > td { padding-left: 0 !important; padding-right: 0 !important; }
    table.table-cards[data-cards-ready] > tbody > tr > td:first-child::before,
    table.table-cards[data-cards-ready] > tbody > tr > td[data-label=""]::before { content: none; }
    table.table-cards[data-cards-ready] > tbody > tr > td:empty { display: none; }
    /* On-farm residue test: one full-width result button per line on a phone (beats .flex-fill). */
    .lab-residue-choices .btn { flex: 1 1 100% !important; }
    /* Health date + time fields: 16px controls need room for "03:56 PM" and the picker icon. */
    .hx-datetime > .hx-time { flex-basis: 9.5rem; }
    /* --- Header: one row, never wraps, everything reachable --- */
    .app-header .container-fluid {
        flex-wrap: nowrap;
        padding-left: .5rem;
        padding-right: .5rem;
        gap: .25rem;
    }
    .app-header .navbar-nav { flex-wrap: nowrap; align-items: center; }
    .app-header .navbar-nav:first-child { min-width: 0; flex: 1 1 auto; }
    .app-header .navbar-nav.ms-auto { flex: 0 0 auto; gap: 0; }
    .app-header .nav-link { padding: .4rem .4rem; }
    .app-header .theme-toggle { width: 32px; height: 32px; }
    /* The icon buttons on the right are the fixed cost; the dropdown carets add ~12px each
       for nothing a phone user needs — the icon itself is the affordance. */
    .app-header .navbar-nav.ms-auto .dropdown-toggle::after { display: none; }
    .app-header .navbar-nav.ms-auto .nav-link .ms-1 { margin: 0 !important; }
    /* Farm name: takes whatever is left of the row, one line, ellipsised — never pushes
       the icons off the edge on a long farm name (that hid the user menu in fa). */
    .app-header .nav-item[data-tour="farm"] { min-width: 0; flex: 1 1 auto; }
    .app-header .nav-item[data-tour="farm"] .badge {
        display: inline-flex;
        align-items: center;
        gap: .3rem;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .app-header .nav-item[data-tour="farm"] .badge > span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    /* The brand lives in the sidebar, which is hidden on phones. Show the mark in the
       header instead so a phone user still sees whose app this is. */
    .app-header .mobile-brand { display: inline-flex; align-items: center; padding: .25rem .35rem; }
    .app-header .mobile-brand img { width: 30px; height: 30px; border-radius: 8px; background: #fff; padding: 2px; }
    /* Dropdowns must not run past the screen edge. */
    .app-header .dropdown-menu { max-width: calc(100vw - 1rem); }
    .notif-menu { width: min(330px, calc(100vw - 1rem)); }

    /* --- Top bar: denser, and a fade at the trailing edge says "there is more" --- */
    .app-topmenu { position: sticky; top: 0; }
    .app-topmenu .container-fluid {
        padding: .35rem .5rem;
        gap: .15rem;
        scroll-padding-inline: .5rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        /* Fade the clipped edge so a cut-off link reads as "scroll me", not as a bug. */
        -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 2.25rem), transparent 100%);
        mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 2.25rem), transparent 100%);
    }
    html[dir="rtl"] .app-topmenu .container-fluid {
        -webkit-mask-image: linear-gradient(to left, #000 0, #000 calc(100% - 2.25rem), transparent 100%);
        mask-image: linear-gradient(to left, #000 0, #000 calc(100% - 2.25rem), transparent 100%);
    }
    .app-topmenu .container-fluid.at-end,
    .app-topmenu .container-fluid.no-overflow {
        -webkit-mask-image: none;
        mask-image: none;
    }
    .topmenu-link { padding: .35rem .7rem; font-size: .88rem; }

    /* --- Content: more of the 390px go to data --- */
    .app-content-header { padding-block: .35rem; }
    .app-content-header h3 { font-size: 1.25rem; }
    .app-content > .container-fluid,
    .app-content-header > .container-fluid { padding-left: .75rem; padding-right: .75rem; }
    .app-content .card-body { padding: .7rem .8rem; }
    .app-content .card-header { padding-left: .8rem; padding-right: .8rem; }
    .card { border-radius: 12px; }
    /* Card headers that hold a title and a button cluster: let the cluster drop to its
       own line instead of squeezing the title into a vertical stack of words. */
    .app-content .card-header.d-flex { flex-wrap: wrap; row-gap: .35rem; }
    .app-content .card-header.d-flex > .btn-toolbar,
    .app-content .card-header.d-flex > .card-actions { flex-wrap: wrap; gap: .3rem; }
    /* Page-level toolbars (title + buttons) follow the same rule. */
    .app-content .d-flex.justify-content-between:not(.flex-nowrap) { flex-wrap: wrap; row-gap: .35rem; }

    /* --- Tables: scroll sideways inside the card, never wrap a date over three lines --- */
    .app-content .table-responsive,
    .app-content .table-scroll { -webkit-overflow-scrolling: touch; }
    /* Same edge fade as the top bar: a clipped last column reads as "pan me". */
    .app-content .table-scroll:not(.at-end):not(.no-overflow) {
        -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 2rem), rgba(0,0,0,.15) 100%);
        mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 2rem), rgba(0,0,0,.15) 100%);
    }
    html[dir="rtl"] .app-content .table-scroll:not(.at-end):not(.no-overflow) {
        -webkit-mask-image: linear-gradient(to left, #000 0, #000 calc(100% - 2rem), rgba(0,0,0,.15) 100%);
        mask-image: linear-gradient(to left, #000 0, #000 calc(100% - 2rem), rgba(0,0,0,.15) 100%);
    }
    .app-content .table td.cell-nowrap,
    .app-content .table th { white-space: nowrap; }
    .app-content .table > :not(caption) > * > * { padding-left: .5rem; padding-right: .5rem; }
    .app-content .table { margin-bottom: 0; }

    /* --- Stat tiles / KPI cards --- */
    .app-content .card-body .h4.dash-figure { font-size: 1.3rem; }
    .app-content .kpi-accent .card-body .d-flex.align-items-baseline { flex-wrap: wrap; row-gap: 0; }

    /* --- iOS zooms into any field under 16px on focus and stays zoomed: the single
       biggest "the page went weird" complaint on phones. Keep every control at 16px. --- */
    .form-control, .form-select, .form-control-sm, .form-select-sm,
    .input-group-sm > .form-control, .input-group-sm > .form-select,
    .tp-size-select, textarea { font-size: 16px !important; }

    /* --- Footer --- */
    .app-footer { padding: .6rem .75rem; font-size: .8rem; justify-content: center; text-align: center; }

    /* --- Performance: the glass cards each ask for a backdrop blur, and iOS Safari repaints
       it on every scroll frame. Phones get flat surfaces; the desktop look is unchanged. --- */
    .card, .stat-card, .alert, .app-header.navbar {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
    .card, .stat-card { box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06); }

    /* --- Auth pages (login, 2FA, reset, chooser): breathing room at the edges, a logo
       that leaves the form above the fold. --- */
    body > .auth-card { width: calc(100% - 2rem); margin: 1rem auto; }
    .auth-logo { width: 116px; height: 116px; padding: 10px; }
    .auth-card .card-body.p-4 { padding: 1.25rem !important; }

    /* Approved CSS refresh: compact phone surfaces and controls. */
  .app-header.navbar {
    min-height: 56px;
  }
  .app-content-header {
    padding-top: 14px;
    padding-bottom: 10px;
  }
  .app-content-header h3 {
    font-size: 23px;
  }
  .app-content > .container-fluid,
  .app-content-header > .container-fluid {
    padding-inline: 12px;
  }
  .app-content .card-body {
    padding: 12px;
  }
  .app-content .card-header {
    padding: 10px 12px;
  }
  .card {
    border-radius: 8px;
  }
  .kpi-accent .card-body.py-2 {
    padding: 12px !important;
  }
  .app-content .card-body .h4.dash-figure {
    font-size: 23px;
  }
  .kpi-accent .small.text-uppercase {
    font-size: 10px;
  }
  .kpi-accent .text-muted.small,
  .kpi-accent small {
    font-size: 10px;
  }
  .dash-chart {
    height: 205px;
  }
  .topmenu-link {
    font-size: 12px;
    padding: 12px 10px;
    min-height: 44px;
  }
  .app-topmenu .container-fluid {
    padding-block: 0;
    min-height: 44px;
  }
  .btn-sm {
    font-size: 12px;
    min-height: 34px;
  }
  .form-control,
  .form-select,
  .form-control-sm,
  .form-select-sm,
  .tp-size-select,
  .input-group-sm > .form-control,
  .input-group-sm > .form-select,
  textarea {
    font-size: 16px !important;
  }
  .app-content .table > thead th {
    font-size: 10px;
  }
  .app-content .table > tbody td {
    font-size: 12px;
    padding-block: 8px !important;
  }
  .table-pagination {
    gap: 6px !important;
  }
  .app-footer {
    padding: 10px 12px;
    font-size: 10px;
  }
  .card h2.h4 {
    font-size: 22px;
  }
  .app-content .small {
    font-size: 11px;
  }
  .app-content .row {
    --bs-gutter-x: 8px;
    --bs-gutter-y: 8px;
  }
  .card,
  .app-header.navbar {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
  /* barn screens (e.g. the water round): gloved tap targets, never below 48px */
  .app-content .hx-tap {
    min-height: 48px;
    font-size: 16px;
  }
  /* Vet visit (H20): the vet records cow by cow in the barn, often with gloves on — every
     control on a visit line (and the By pen / By reason toggle) is a 48px target. */
  .vet-item .btn,
  .vet-item .form-select,
  .vet-item .form-control,
  .vet-toggle .btn {
    min-height: 48px;
  }
  .vet-item .btn,
  .vet-toggle .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .25rem;
    min-width: 48px;
  }
  .vet-item .form-check {
    min-height: 48px;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding-inline-start: 0;
  }
  .vet-item .form-check-input {
    float: none;
    width: 1.5rem;
    height: 1.5rem;
    margin: 0;
  }
}


/* Pagination: the light-theme .tp-btn override tied with .tp-num.active and won, leaving the
   current page number white on white. Re-assert the brand fill at higher specificity. */
[data-bs-theme="light"] .table-pagination .tp-num.active { background: var(--gradient-primary); color: var(--on-brand); border-color: transparent; }

/* Tap targets on any touch device, regardless of width (tablets included). */
@media (hover: none) and (pointer: coarse) {
    .topmenu-link { min-height: 2.5rem; }
    .app-header .nav-link, .theme-toggle { min-width: 2.5rem; min-height: 2.5rem; }
    .btn-sm { min-height: 2.25rem; }
    .app-content .hx-tap { min-height: 48px; }
}

/* Theme toggle: both icons are rendered, the theme picks one — no swap after the first paint. */
[data-bs-theme="dark"] .theme-toggle .dd-if-light,
[data-bs-theme="light"] .theme-toggle .dd-if-dark { display: none; }

/* Lab samples (H05): the animal picker of a herd-test batch scrolls inside its box and packs into
   columns; a sensitivity panel hangs under its organism on the reading side (logical properties,
   so it flips in RTL). */
.lab-pick { max-height: 16rem; overflow-y: auto; columns: 11rem; column-gap: 1rem; }
.lab-pick .form-check { break-inside: avoid; }
.lab-panel { padding-inline-start: .5rem; border-inline-start: 2px solid var(--bs-border-color); }
.lab-grid td.lab-cell { min-width: 7.5rem; }
/* ---------- Balanced card grid (js/card-balance.js, .row[data-dd-balance]) ----------
   Wide screens: two stacked columns, cards keep the grid's vertical gap; a card's own col-lg-6
   no longer sizes it (its column does). */
.dd-balance-col { display: flex; flex-direction: column; gap: var(--bs-gutter-y, .5rem); }
.dd-balance-col > [class*="col-"] { width: 100%; max-width: 100%; flex: none; padding: 0; margin: 0; }

/* ---------- Sidebar page search (js/sidebar-search.js) ----------
   A compact box above the sections; while it has text the results replace the section list. The
   icon and the "/" hint sit inside the field on its logical edges, so they flip in RTL. */
.sidebar-search { padding: .5rem .75rem 0; flex: none; }
.sidebar-search-box { position: relative; }
.sidebar-search-box > .bi-search {
    position: absolute; inset-inline-start: .6rem; top: 50%; transform: translateY(-50%);
    font-size: .8rem; color: var(--text-muted); pointer-events: none;
}
.sidebar-search-box > .form-control { padding-inline-start: 1.85rem; padding-inline-end: 1.9rem; font-size: 13px; }
.sidebar-search-box > .form-control::-webkit-search-cancel-button { display: none; }
.sidebar-search-key {
    position: absolute; inset-inline-end: .45rem; top: 50%; transform: translateY(-50%);
    padding: 0 .35rem; font-size: 11px; line-height: 1.35; border-radius: 4px;
    background: var(--surface); color: var(--text-muted); border: 1px solid var(--control-border);
    pointer-events: none;
}
.sidebar-search-box > .form-control:focus ~ .sidebar-search-key,
.sidebar-search-box > .form-control:not(:placeholder-shown) ~ .sidebar-search-key { display: none !important; }
.sidebar-search-results { flex: none !important; }
.sidebar-search-results .nav-link p { display: flex; flex-direction: column; line-height: 1.2; }
.sidebar-search-section { font-size: 11px; color: var(--text-muted); }
.sidebar-search-results .nav-link.active .sidebar-search-section { color: rgba(255, 255, 255, .8); }
.sidebar-search-none { margin: .25rem 1.25rem 0; font-size: 12px; color: var(--text-muted); }

/* Demo deployment: the DEMO label sits in the middle of the top bar, big enough to notice at a glance
   (Saeed, 2026-11-10). It sits in the flow between the two menus (margin-inline:auto keeps it centred
   there, and the farm-name chip shrinks rather than being covered); on wide screens, where the middle
   of the bar is free, it is pinned to the exact centre without moving the menus. */
.app-header .dd-demo-badge {
    margin-inline: auto; flex-shrink: 0;
    font-size: 1.15rem; letter-spacing: .12em; padding: .4em .9em;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .18);
}
@media (max-width: 1199.98px) {
    /* in the flow, the right-hand menu's own auto margin would take a share of the space and pull the label off-centre */
    .app-header .dd-demo-badge + .navbar-nav { margin-inline-start: 0 !important; }
}
@media (min-width: 1200px) {
    .app-header .dd-demo-badge { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 2; }
}
@media (max-width: 575.98px) {
    .app-header .dd-demo-badge { font-size: .9rem; padding: .3em .55em; letter-spacing: .06em; }
    .app-header .dd-demo-badge .bi { display: none; }
}
/* The header logo shows below lg (sidebar hidden) — size it at every such width, not only on phones
   (768–991 px used to show it at full size). */
.app-header .mobile-brand img { width: 30px; height: 30px; }
