/*
 * Farm Manager on Tabler: brand and shell.
 * Primary is the navy on the PDFs farmers already receive; the sidebar is a deeper
 * navy from the same hue. Status colours (green/amber/red) are left to mean status.
 */
:root {
    --fm-navy: #1a4f7a;
    --fm-navy-deep: #0f2f4a;
    --fm-navy-ink: #0a2236;
    --fm-logo-green: #5aa832;

    /* Colours are light-dark(on light, on dark). Tabler 1.6 works the same way: the browser picks
       the half that matches the colour scheme where the colour is used, so data-bs-theme="dark"
       (on <html> for dark mode, and always on the navy sidebar) takes the second, and printing,
       which Tabler forces to the light scheme, always takes the first. The dark halves pass
       WCAG AA (4.5:1) as text on Tabler's dark cards and page, and on their own -lt tints. */

    /* Navy on light. On dark, navy is too dark to read, so the primary turns a light blue and
       text on a primary fill (buttons, the current page number) turns navy ink */
    --tblr-primary: light-dark(#1a4f7a, #7ab3e6);
    --tblr-primary-rgb: 26, 79, 122;
    --tblr-primary-fg: light-dark(var(--tblr-light), var(--fm-navy-ink));
    --tblr-link-color: var(--tblr-primary);
    --tblr-font-sans-serif: "Source Sans 3", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --tblr-body-font-size: 1rem;

    /* Tabler's own green, red and grey fail WCAG AA as text (green is 2.7:1 on white).
       These darker shades pass 4.5:1 on white and on their own -lt tints, and the tints
       (badges, alerts) follow automatically because Tabler mixes them from these. */
    --tblr-success: light-dark(#1f7a2e, #62c472);
    --tblr-success-rgb: 31, 122, 46;
    --tblr-success-fg: light-dark(var(--tblr-light), #0b2410);
    --tblr-danger: light-dark(#c92a2a, #ff8a8a);
    --tblr-danger-rgb: 201, 42, 42;
    --tblr-danger-fg: light-dark(var(--tblr-light), #2b0909);
    --tblr-secondary: light-dark(#5f6670, #a1a9b3);
    --tblr-secondary-rgb: 95, 102, 112;
    --tblr-muted: light-dark(#5f6670, #a1a9b3);
    --tblr-muted-rgb: 95, 102, 112;

    /* Amber stays bright as a fill; text in amber uses this instead */
    --fm-warning-text: light-dark(#7a4a00, #f2b340);
    --fm-info-text: light-dark(#1d5f91, #7cbcee);
    /* Red and green text in alerts, and red badges on the grey page, need a stronger shade */
    --fm-danger-strong: light-dark(#a61d1d, #ff9c9c);
    --fm-success-strong: light-dark(#18692a, #6ccb7b);

    --fm-sidebar-width: 15rem;
    --fm-rail-width: 4.5rem;

    /* Farm management sections: a navy-tinted header, and a tint and edge for each status */
    --fm-section-head: light-dark(#e4edf6, #1a2a3b);
    --fm-section-head-hover: light-dark(#d5e3f1, #213549);
    --fm-section-head-text: light-dark(#14405f, #d3e5f7);
    --fm-section-ok-head: light-dark(#e1f1e4, #15301d);
    --fm-section-ok-hover: light-dark(#d0e9d5, #1b3c25);
    --fm-section-warn-head: light-dark(#fcefd6, #3a2b0e);
    --fm-section-warn-hover: light-dark(#f8e4bb, #463513);
    --fm-section-bad-head: light-dark(#fae2e2, #3e1a1a);
    --fm-section-bad-hover: light-dark(#f4cfcf, #4b2020);
    --fm-warning-fill: #f59f00;
    --fm-warning-fill-text: #2b1d00;
    /* Fields the system fills in (calculated, or copied from elsewhere), and form panels */
    --fm-calculated-bg: light-dark(#e9edf2, #262d36);
    --fm-calculated-text: light-dark(#3b4350, #c3cad3);
    --fm-panel-bg: light-dark(#f7f9fb, #1d232b);
    --fm-unit-bg: light-dark(#eef4fa, #1a2533);
    --fm-unit-border: light-dark(#b9cfe4, #34506d);
}

/* Amber and blue text on white or on their tints fail contrast, so they read darker */
.text-warning,
.bg-warning-lt {
    color: var(--fm-warning-text) !important;
}

/* Red on its own tint passes on a white card but not on the grey page (a status beside a page
   title), so red badges use a darker red everywhere */
.bg-danger-lt {
    color: #a61d1d !important;
}

.text-info,
.bg-info-lt {
    color: var(--fm-info-text) !important;
}

.alert-warning {
    --tblr-alert-color: var(--fm-warning-text);
}

.alert-info {
    --tblr-alert-color: var(--fm-info-text);
}

.alert-success {
    --tblr-alert-color: #18692a;
}

.alert-danger {
    --tblr-alert-color: #a61d1d;
}

/* Skip link: first thing a keyboard user reaches on every page */
.fm-skip-link:focus {
    position: fixed !important;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 2000;
    padding: 0.5rem 1rem;
    background: #fff;
    color: var(--fm-navy);
    border-radius: var(--tblr-border-radius);
    box-shadow: 0 0 0 3px rgba(26, 79, 122, 0.5);
    font-weight: 600;
}

main:focus {
    outline: none;
}

/* Sidebar */
.navbar-vertical.fm-sidebar {
    --tblr-navbar-bg: var(--fm-navy-deep);
    background-color: var(--fm-navy-deep);
    border-right: 0;
}

.fm-sidebar .navbar-brand {
    gap: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.fm-sidebar .navbar-brand img {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: #fff;
}

.fm-sidebar .navbar-brand .fm-brand-name b {
    font-weight: 700;
}

.fm-sidebar .nav-link-icon {
    width: 1.25rem;
    text-align: center;
    opacity: 0.85;
}

.fm-sidebar .nav-item.active > .nav-link,
.fm-sidebar .nav-link.active {
    background-color: var(--fm-navy-ink);
    color: #fff;
}

.fm-sidebar .dropdown-menu .dropdown-item.active {
    background-color: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-weight: 600;
}

.fm-sidebar .dropdown-menu .dropdown-header {
    font-size: 0.6875rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.7);
    padding-top: 0.75rem;
}

/* Top bar */
.fm-topbar .fm-herd-search {
    max-width: 22rem;
}

/* Page header: pages still render their own <h1> inside content_header */
.page-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.4;
    margin: 0;
}

.page-header {
    margin-top: 0;
    padding-top: 1.25rem;
}

/* Numbers that line up in tables and figures */
.table td,
.fm-figure {
    font-variant-numeric: tabular-nums;
}

@media print {
    .fm-sidebar,
    .fm-topbar {
        display: none !important;
    }
}

/* Farmer portal top bar */
.fm-farmer-bar {
    background-color: var(--fm-navy-deep);
    color: #fff;
}

/* Bootstrap 5 buttons, tabs and badges are flex boxes, which drop the space between a
   Font Awesome icon and its label; a gap restores it, and icon margins are cleared so
   older markup that also set me-1 doesn't double up */
.btn,
.dropdown-item,
.nav-link,
.badge {
    column-gap: 0.4rem;
}

.btn > i[class*="fa-"],
.dropdown-item > i[class*="fa-"],
.nav-link > i[class*="fa-"],
.badge > i[class*="fa-"] {
    margin-inline: 0 !important;
}

/* Shared components (resources/views/components/ui) */
.fm-stat .subheader {
    letter-spacing: 0.04em;
}

.fm-attention-icon {
    width: 1.25rem;
    flex-shrink: 0;
    text-align: center;
}

.fm-section-tabs .nav-link {
    white-space: nowrap;
}

@media (max-width: 767.98px) {
    /* Section tabs scroll sideways on phones rather than wrapping into a stack */
    .fm-section-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
    }
}

/* Detail lists: narrower columns than Tabler's default so three or four fit across a card */
.datagrid {
    --tblr-datagrid-item-width: 11rem;
}

/* ---------- Collapsible sidebar ----------
   The rail keeps only icons. Hovering it, or tabbing into it, opens it over the page
   (the page doesn't move), so labels and groups are always there when they're used. */
.fm-sidebar-toggle {
    color: var(--tblr-secondary);
}

@media (min-width: 992px) {
    .navbar-vertical.fm-sidebar {
        transition: width 0.15s ease;
    }

    .fm-sidebar-collapsed .navbar-vertical.navbar-expand-lg.fm-sidebar {
        width: var(--fm-rail-width);
        overflow-x: hidden;
    }

    .fm-sidebar-collapsed .navbar-vertical.navbar-expand-lg ~ .page-wrapper {
        margin-left: var(--fm-rail-width);
    }

    .fm-sidebar-collapsed .fm-sidebar:not(:hover):not(:focus-within) .fm-brand-name,
    .fm-sidebar-collapsed .fm-sidebar:not(:hover):not(:focus-within) .nav-link-title {
        opacity: 0;
        width: 0;
        overflow: hidden;
        white-space: nowrap;
    }

    .fm-sidebar-collapsed .fm-sidebar:not(:hover):not(:focus-within) .dropdown-menu,
    .fm-sidebar-collapsed .fm-sidebar:not(:hover):not(:focus-within) .dropdown-toggle::after {
        display: none !important;
    }

    .fm-sidebar-collapsed .fm-sidebar:not(:hover):not(:focus-within) .nav-link {
        justify-content: center;
    }

    .fm-sidebar-collapsed .fm-sidebar:not(:hover):not(:focus-within) .nav-link-icon {
        margin-right: 0;
        font-size: 1.05rem;
    }

    .fm-sidebar-collapsed .fm-sidebar:not(:hover):not(:focus-within) .navbar-brand {
        justify-content: center;
    }

    /* Open over the page rather than pushing it */
    .fm-sidebar-collapsed .navbar-vertical.navbar-expand-lg.fm-sidebar:hover,
    .fm-sidebar-collapsed .navbar-vertical.navbar-expand-lg.fm-sidebar:focus-within {
        width: var(--fm-sidebar-width);
        z-index: 1035;
        box-shadow: 0 0 2rem rgba(10, 34, 54, 0.35);
    }
}

@media (prefers-reduced-motion: reduce) {
    .navbar-vertical.fm-sidebar {
        transition: none;
    }
}

/* ---------- Collapsible section cards (x-ui.collapse-card) ---------- */
.fm-collapsible > .card-header {
    position: relative;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.fm-collapsible > .card-header:hover {
    background-color: var(--tblr-bg-surface-secondary);
}

.fm-collapse-button {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
}

/* The whole header is the target, not just the words */
.fm-collapse-button::after {
    content: "";
    position: absolute;
    inset: 0;
}

.fm-collapse-button:focus-visible {
    outline: none;
}

.fm-collapsible > .card-header:has(.fm-collapse-button:focus-visible) {
    box-shadow: inset 0 0 0 3px rgba(26, 79, 122, 0.45);
}

.fm-collapse-chevron {
    color: var(--tblr-secondary);
    transition: transform 0.15s ease;
}

.fm-collapse-button[aria-expanded="true"] .fm-collapse-chevron {
    transform: rotate(180deg);
}

.fm-collapse-totals {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-left: auto;
}

@media (prefers-reduced-motion: reduce) {
    .fm-collapse-chevron {
        transition: none;
    }
}

/* Totals in section headers. Scripts colour some of them with solid bg-success / bg-danger /
   bg-warning; they read as tints here, and hide until a script has filled them in. */
.fm-total:empty {
    display: none;
}

.badge.fm-total.bg-success {
    background-color: var(--tblr-success-lt) !important;
    color: var(--tblr-success) !important;
}

.badge.fm-total.bg-danger {
    background-color: var(--tblr-danger-lt) !important;
    color: var(--tblr-danger) !important;
}

.badge.fm-total.bg-warning {
    background-color: var(--tblr-warning-lt) !important;
    color: var(--fm-warning-text) !important;
}

/* ---------- Farm management sections: colour that says how each one stands ----------
   Every section header is navy-tinted so the list reads as separate blocks; a status
   (js/section-status.js, soils from the server) turns the header green, amber or red, gives
   the card a coloured edge and shows a pill with the reason in words. */
.fm-sections > .fm-collapsible {
    --fm-head: var(--fm-section-head);
    --fm-head-hover: var(--fm-section-head-hover);
}

/* A closed section is all header: round its lower corners to the card's */
.fm-sections > .fm-collapsible:has(> .card-body[hidden]) > .card-header {
    border-bottom: 0;
    border-end-start-radius: var(--tblr-card-inner-border-radius);
    border-end-end-radius: var(--tblr-card-inner-border-radius);
}

.fm-sections > .fm-collapsible[data-status="success"] {
    --fm-head: var(--fm-section-ok-head);
    --fm-head-hover: var(--fm-section-ok-hover);
    border-inline-start: 6px solid var(--tblr-success);
}

.fm-sections > .fm-collapsible[data-status="warning"] {
    --fm-head: var(--fm-section-warn-head);
    --fm-head-hover: var(--fm-section-warn-hover);
    border-inline-start: 6px solid var(--fm-warning-fill);
}

.fm-sections > .fm-collapsible[data-status="danger"] {
    --fm-head: var(--fm-section-bad-head);
    --fm-head-hover: var(--fm-section-bad-hover);
    border-inline-start: 6px solid var(--tblr-danger);
}

.fm-sections > .fm-collapsible > .card-header {
    background-color: var(--fm-head);
    color: var(--fm-section-head-text);
    padding-block: 0.9rem;
}

.fm-sections > .fm-collapsible > .card-header:hover {
    background-color: var(--fm-head-hover);
}

.fm-sections > .fm-collapsible > .card-header .card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: inherit;
}

.fm-sections > .fm-collapsible > .card-header .fm-collapse-chevron {
    color: inherit;
}

/* The badge carries the section's figures, so the separate totals on the right would only
   repeat them; they stay in the page for the scripts that fill them in */
.fm-sections > .fm-collapsible > .card-header > .fm-collapse-totals {
    display: none;
}

.fm-section-status {
    border: 1px solid transparent;
    background-color: var(--tblr-bg-surface);
    color: var(--fm-section-head-text);
    font-variant-numeric: tabular-nums;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
}

[data-status="success"] > .card-header > .fm-section-status {
    background-color: var(--tblr-success);
    color: var(--tblr-success-fg);
}

[data-status="warning"] > .card-header > .fm-section-status {
    background-color: var(--fm-warning-fill);
    color: var(--fm-warning-fill-text);
}

[data-status="danger"] > .card-header > .fm-section-status {
    background-color: var(--tblr-danger);
    color: var(--tblr-danger-fg);
}

/* Totals on a tinted header: solid enough to read against it */
.fm-sections > .fm-collapsible > .card-header .badge.fm-total.bg-secondary-lt:not(.bg-success, .bg-danger, .bg-warning) {
    background-color: var(--tblr-bg-surface) !important;
    color: var(--tblr-body-color) !important;
}

/* The year's data forms: each group of fields its own panel, so the form reads in parts */
.fm-farm-form .fm-fieldset {
    padding: 1rem 1.25rem 1.25rem;
    border: 1px solid var(--tblr-border-color);
    border-radius: var(--tblr-border-radius-lg, 8px);
    background-color: var(--fm-panel-bg);
}

.fm-farm-form .fm-fieldset + .fm-fieldset,
.fm-farm-form .fm-unit + .fm-fieldset,
.fm-farm-form .fm-fieldset + .fm-unit {
    margin-top: 1rem;
}

.fm-farm-form .fm-fieldset > legend {
    float: left;
    width: 100%;
    font-size: 0.8125rem;
    color: var(--fm-section-head-text);
}

.fm-farm-form .fm-fieldset > legend + * {
    clear: left;
}

/* What can't be typed in is shaded and marked "auto", so the eye goes to what can */
.fm-farm-form .form-control:disabled,
.fm-farm-form .form-control[readonly],
.fm-farm-form .form-select:disabled {
    background-color: var(--fm-calculated-bg);
    border-style: dashed;
    color: var(--fm-calculated-text);
    opacity: 1;
    cursor: default;
}

.fm-farm-form [class*="col-"]:has(> .form-control:disabled, > .form-control[readonly], > .form-select:disabled) > .form-label::after {
    content: "auto";
    margin-inline-start: 0.4rem;
    padding: 0.05rem 0.4rem;
    border-radius: 4px;
    background-color: var(--fm-calculated-bg);
    color: var(--fm-calculated-text);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    vertical-align: 0.1em;
}

/* The dairy unit: banding, milk platform and its N limits, apart from the rest */
.fm-unit {
    margin-top: 1rem;
    padding: 1rem;
    border: 2px solid var(--fm-unit-border);
    border-radius: var(--tblr-border-radius-lg, 8px);
    background-color: var(--fm-unit-bg);
}

.fm-unit-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.75rem;
    margin-bottom: 0.75rem;
}

.fm-unit-title {
    margin: 0;
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--fm-section-head-text);
}

.fm-unit-hint {
    color: var(--tblr-secondary);
    font-size: 0.875rem;
}

.fm-unit .fm-fieldset {
    background-color: var(--tblr-bg-surface);
}

/* ---------- Farm section building blocks (components/farms) ---------- */

/* A titled block inside a section card: heading and actions on one line, content below */
/* Any later subsection in the same card gets the divider, even with a modal or hidden
   element in between */
.fm-subsection ~ .fm-subsection {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--tblr-border-color);
}

.fm-subsection-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    margin-bottom: 0.75rem;
}

.fm-subsection-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.fm-subsection-header .btn-list {
    margin-left: auto;
}

/* Grouped form fields */
.fm-fieldset {
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 0;
}

.fm-fieldset + .fm-fieldset {
    margin-top: 1.25rem;
}

.fm-fieldset > legend {
    float: none;
    width: auto;
    margin-bottom: 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--tblr-secondary);
}

/* Keeps visually hidden text in a scrolling table inside the scroller; without it that text
   is positioned against the page and widens it on phones */
.table-responsive {
    position: relative;
    /* Only sideways scrolling; a 1px border overhang otherwise made every table a vertical
       scroller. Tables meant to scroll down set overflow-y inline, which still wins. */
    overflow-y: hidden;
}

/* Tables of inputs: fields fill their cell, numbers line up */
.fm-input-table td {
    vertical-align: middle;
}

.fm-input-table .form-control,
.fm-input-table .form-select {
    min-width: 6rem;
}

.fm-input-table input[type="number"],
.fm-input-table .fm-number {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Save / add buttons under a table or form */
.fm-form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* ---------- Farm pages ---------- */
/* The farm's tabs, each in a colour of its own (navy, green, soil brown, plum for reports), the
   page you're on filled in it */
.fm-farm-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.5rem 1rem;
    border-bottom: 3px solid var(--fm-farm-tab-rule, var(--tblr-border-color));
}

.fm-farm-nav .nav-tabs {
    border-bottom: 0;
    gap: 0.35rem;
}

.fm-farm-tab-overview { --fm-tab: light-dark(#1a4f7a, #7ab3e6); --fm-tab-tint: light-dark(#e2ecf6, #1a2a3b); }
.fm-farm-tab-npk { --fm-tab: light-dark(#2b7a3b, #6ccb7b); --fm-tab-tint: light-dark(#e1f1e4, #15301d); }
.fm-farm-tab-soils { --fm-tab: light-dark(#8a5a2b, #e0b07a); --fm-tab-tint: light-dark(#f5ebdf, #33261a); }
.fm-farm-tab-reports { --fm-tab: light-dark(#6a3d8f, #c9a6e8); --fm-tab-tint: light-dark(#efe6f6, #2a1f35); }

.fm-farm-nav:has(.fm-farm-tab-overview .active) { --fm-farm-tab-rule: light-dark(#1a4f7a, #7ab3e6); }
.fm-farm-nav:has(.fm-farm-tab-npk .active) { --fm-farm-tab-rule: light-dark(#2b7a3b, #6ccb7b); }
.fm-farm-nav:has(.fm-farm-tab-soils .active) { --fm-farm-tab-rule: light-dark(#8a5a2b, #e0b07a); }

.fm-farm-tab .nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    margin-bottom: 0;
    padding: 0.6rem 1rem;
    border: 1px solid transparent;
    border-top: 3px solid var(--fm-tab);
    border-radius: var(--tblr-border-radius) var(--tblr-border-radius) 0 0;
    background-color: var(--fm-tab-tint);
    color: var(--fm-tab);
    font-weight: 600;
}

.fm-farm-tab .nav-link:hover,
.fm-farm-tab .nav-link:focus-visible {
    color: var(--fm-tab);
    filter: brightness(0.96);
}

.fm-farm-tab .nav-link.active,
.fm-farm-tab .nav-link.active:hover {
    background-color: var(--fm-tab);
    border-color: var(--fm-tab);
    color: light-dark(#ffffff, #0b1a12);
    filter: none;
}

/* On a phone the tabs share the width, icon over label, so they stay on one row */
@media (max-width: 575.98px) {
    .fm-farm-nav .nav-tabs {
        flex-wrap: nowrap;
        width: 100%;
        gap: 0.25rem;
    }

    .fm-farm-tab {
        flex: 1 1 0;
        min-width: 0;
    }

    .fm-farm-tab .nav-link {
        flex-direction: column;
        justify-content: center;
        gap: 0.2rem;
        width: 100%;
        height: 100%;
        padding: 0.45rem 0.25rem;
        font-size: 0.8125rem;
        line-height: 1.2;
        text-align: center;
        white-space: normal;
    }
}

/* The predicted year end in the overview's stocking rate figure */
.fm-stat-projection {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    font-size: 1.0625rem;
    color: var(--tblr-body-color);
}

.fm-stat-projection strong {
    font-size: 1.25rem;
}

.fm-stat-projection i {
    color: var(--tblr-success);
}

.fm-stat-projection.is-over strong,
.fm-stat-projection.is-over i {
    color: var(--tblr-danger);
}

/* The predicted year end under the overview's stocking rate */
.fm-projection-line {
    padding: 0.6rem 0.85rem;
    border-left: 4px solid var(--tblr-success);
    border-radius: var(--tblr-border-radius);
    background-color: var(--fm-section-ok-head);
}

.fm-projection-line.is-over {
    border-left-color: var(--tblr-danger);
    background-color: var(--fm-section-bad-head);
}

.fm-projection-line-figure {
    color: var(--tblr-body-color);
}

.fm-projection-line-figure i {
    color: var(--tblr-success);
}

.fm-projection-line.is-over .fm-projection-line-figure i {
    color: var(--tblr-danger);
}

/* Nutrient balance summary (components/farms/summary-section) */
.fm-npk-summary-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.75rem 1.5rem;
    margin-bottom: 1rem;
}

.fm-npk-summary-title {
    margin: 0 0 0.5rem;
    font-size: 1rem;
    font-weight: 600;
}

.fm-npk-facts {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.5rem;
    margin: 0;
}

.fm-npk-facts > div {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.4rem;
}

.fm-npk-facts dt {
    font-weight: 400;
    color: var(--tblr-secondary);
}

.fm-npk-facts dd {
    margin: 0;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.fm-npk-facts .badge {
    font-weight: 500;
}

.fm-npk-group {
    height: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid var(--tblr-border-color);
    border-radius: var(--tblr-border-radius-lg, 0.5rem);
}

.fm-npk-group-title {
    margin: 0 0 0.625rem;
    font-size: 0.875rem;
    font-weight: 600;
}

.fm-npk-figures {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
}

.fm-npk-label {
    font-size: 0.8125rem;
    color: var(--tblr-body-color);
}

.fm-npk-value {
    font-size: 1.375rem;
    font-weight: 600;
    line-height: 1.3;
    font-variant-numeric: tabular-nums;
}

.fm-npk-note {
    font-size: 0.8125rem;
    font-weight: 600;
    min-height: 1.2em;
}

.fm-npk-balance {
    padding-left: 0.75rem;
    border-left: 3px solid var(--tblr-border-color);
}

.fm-npk-balance.is-within {
    border-left-color: var(--tblr-success);
}

.fm-npk-balance.is-within .fm-npk-value,
.fm-npk-balance.is-within .fm-npk-note {
    color: var(--tblr-success);
}

.fm-npk-balance.is-over {
    border-left-color: var(--tblr-danger);
}

.fm-npk-balance.is-over .fm-npk-value,
.fm-npk-balance.is-over .fm-npk-note {
    color: var(--tblr-danger);
}

/* Kept on screen while scrolling, on screens big enough to spare the room */
@media (min-width: 768px) {
    #npk-summary.sticky {
        position: sticky;
        top: 0.75rem;
        z-index: 1020;
        box-shadow: 0 0.25rem 1rem rgba(10, 34, 54, 0.08);
    }

    /* farm-data.js adds .shrink once the page has scrolled: only the figures stay */
    #npk-summary.sticky.shrink .card-body {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
    }

    #npk-summary.sticky.shrink .fm-npk-summary-head {
        margin-bottom: 0.5rem;
    }

    #npk-summary.sticky.shrink .fm-npk-facts,
    #npk-summary.sticky.shrink .fm-npk-note {
        display: none;
    }

    #npk-summary.sticky.shrink .fm-npk-summary-title {
        margin: 0;
    }

    #npk-summary.sticky.shrink .fm-npk-group {
        padding: 0.5rem 0.75rem;
    }

    #npk-summary.sticky.shrink .fm-npk-value {
        font-size: 1.125rem;
    }
}

@media (max-width: 575.98px) {
    .fm-npk-value {
        font-size: 1.125rem;
    }
}

/* How it's calculated */
.fm-help-terms {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.25rem 1rem;
}

.fm-help-terms dt {
    font-weight: 600;
}

.fm-help-terms dd {
    margin: 0;
}

.fm-help-subhead {
    margin: 0.75rem 0 0.25rem;
    font-size: 0.875rem;
    font-weight: 600;
}

.fm-help code {
    color: var(--tblr-body-color);
    background: var(--tblr-bg-surface-secondary);
    padding: 0.125rem 0.375rem;
    border-radius: var(--tblr-border-radius-sm, 0.25rem);
    white-space: normal;
}

/* Reports dialog: the email choices as an even grid of equal buttons */
.fm-report-send {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: 0.5rem;
}

.fm-report-send .btn {
    justify-content: flex-start;
}

/* White on amber is 2:1; amber buttons and badges take dark text */
.btn-warning,
.badge.bg-warning {
    --tblr-btn-variant-fg: #1d1d1d;
    color: #1d1d1d;
}

/* Fields the BISS import has just filled in: the import script marks them bg-success text-white,
   which is unreadable on an input; shown as a green tint with an edge instead */
.form-control.bg-success,
.form-select.bg-success {
    background-color: var(--tblr-success-lt) !important;
    color: var(--tblr-body-color) !important;
    border-color: var(--tblr-success);
}

/* The projection panel sits between two subsections but is wrapped for refreshing */
#nitrogen_projection_panel + .fm-subsection {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--tblr-border-color);
}

/* Minimum widths for selects in tables of inputs, so their values aren't cut off */
.fm-input-table .fm-minw-8, .fm-minw-8 { min-width: 8rem; }
.fm-input-table .fm-minw-9, .fm-minw-9 { min-width: 9rem; }
.fm-input-table .fm-minw-10, .fm-minw-10 { min-width: 10rem; }
.fm-input-table .fm-minw-11, .fm-minw-11 { min-width: 11rem; }
.fm-input-table .fm-minw-12, .fm-minw-12 { min-width: 12rem; }
.fm-input-table .fm-minw-14, .fm-minw-14 { min-width: 14rem; }

/* ---------- Lists ---------- */
.fm-avatar {
    flex-shrink: 0;
    background-color: var(--tblr-primary-lt);
    color: var(--tblr-primary);
    font-weight: 600;
}

.fm-filter-pills {
    flex-wrap: wrap;
    gap: 0.25rem;
}

.fm-filter-pills .nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.fm-list-search {
    width: 100%;
    max-width: 24rem;
}

.fm-progress-col {
    min-width: 9rem;
}

.fm-role-picker .form-selectgroup-label {
    text-align: left;
}

/* Cards stacked one under another in the same column get the page's gap. Containers that
   already space their children with a gap (.space-y, flex/grid, rows) are left alone. */
.card + .card:not(.space-y > *, .vstack > *, .d-flex > *, .d-grid > *, .row > *) {
    margin-top: 1rem;
}

/* ---------- Guest pages (sign in, pay a bill, errors) ---------- */
/* A page taller than the screen (the pay page on a phone) must grow and scroll, not shrink and
   push its logo and title above the top of the window */
.fm-guest > main.page {
    flex-shrink: 0;
}

/* ---------- Forms (x-ui.form-actions, x-ui.error-summary) ---------- */
/* A long error message (an email address, a URL) wraps instead of pushing the page sideways */
.alert-link,
.alert li {
    overflow-wrap: anywhere;
}

/* Each error in the summary is a link to its field: big enough to hit (WCAG 2.5.8) */
.alert li + li {
    margin-top: 0.25rem;
}

.alert li > .alert-link {
    display: inline-block;
    max-width: 100%;
    min-height: 1.5rem;
    padding-block: 0.125rem;
}

/* ---------- Messages after an action (layouts/partials/alerts) ---------- */
.fm-alerts {
    margin-bottom: 1rem;
}

.fm-alerts .alert:last-child {
    margin-bottom: 0;
}

/* ---------- Kit: comms log, steps, filter bar ---------- */
.fm-comms-log-text {
    min-width: 0;
}

.fm-steps {
    padding-left: 0;
    list-style: none;
}

/* Steps still to come are information, not disabled controls: Tabler's disabled grey is too
   faint to read (WCAG 1.4.3), the secondary grey isn't */
.fm-steps .step-item.active ~ .step-item {
    color: var(--tblr-secondary);
}

/* Removable filter chips: big enough to hit (WCAG 2.5.8) */
.fm-filter-chip {
    display: inline-flex;
    align-items: center;
    min-height: 1.75rem;
    padding: 0.3rem 0.65rem;
    font-size: 0.8125rem;
}

/* ---------- Tables ---------- */
/* Message logs: fixed column shares, so long subjects, addresses and farm names truncate
   instead of widening the table; on a phone the table scrolls inside its card */
.fm-log-table {
    table-layout: fixed;
    min-width: 44rem;
}

/* Tabler drops the rule under the last row's cells but not under a row header (th scope=row),
   which left a stub of line under the first cell of every list */
.card-table > tbody:last-child > tr:last-child > th {
    border-bottom-width: 0;
}

.fm-form-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

/* ---------- Charts (x-ui.chart, x-ui.sparkline) ---------- */
.fm-chart-data {
    margin-top: 0.5rem;
    font-size: 0.8125rem;
}

.fm-chart-data > summary {
    width: fit-content;
    padding-block: 0.375rem;
    color: var(--tblr-secondary);
    cursor: pointer;
}

.fm-chart-data[open] > summary {
    margin-bottom: 0.5rem;
}

.fm-sparkline {
    margin: 0 -1px -1px;
}

.fm-legend li + li {
    margin-top: 0.25rem;
}

.fm-legend-swatch {
    display: inline-block;
    width: 0.625rem;
    height: 0.625rem;
    border-radius: 50%;
    flex-shrink: 0;
}

.progress-separated {
    gap: 2px;
    background: transparent;
}

.fm-mini-figures {
    display: flex;
    gap: 1.5rem;
    font-size: 0.8125rem;
}

.fm-mini-figures dt {
    font-weight: 400;
    color: var(--tblr-secondary);
}

.fm-mini-figures dd {
    margin: 0;
    font-weight: 600;
}

/* A select sizes itself to its longest option; long scheme names pushed filters off phones */
.form-select {
    max-width: 100%;
    text-overflow: ellipsis;
}

/* Links inside a sentence must be told apart by more than colour (WCAG 1.4.1); plain links
   in running text are underlined. Buttons, menus and links with their own classes are not. */
p a:not([class]),
li > a:not([class]),
.form-hint a:not([class]),
.text-secondary a:not([class]),
.text-muted a:not([class]),
.alert a:not([class]) {
    text-decoration: underline;
    text-underline-offset: 0.15em;
}

/* ==========================================================================
   Area styles. Each area keeps its own rules between its markers.
   ========================================================================== */

/* == area: bills == */
/* Long farm names, types and owners keep to one line in the bill lists (full text in title) */
.fm-bills-farm { max-width: 16rem; }
.fm-bills-type { max-width: 12rem; }
.fm-bills-owner { max-width: 14rem; }

/* Tabler drops the line under a card table's last row, but only for td cells. Tables with a
   total row or several groups keep it; elsewhere the row's header cell loses it too. */
.card-table.fm-bills-foot > tbody > tr:last-child > td,
.card-table.fm-bills-grouped > tbody:not(:last-child) > tr:last-child > td {
    border-bottom: var(--tblr-border-width) solid var(--tblr-table-border-color, var(--tblr-border-color));
}
.card-table.fm-bills-table:not(.fm-bills-foot) > tbody:last-child > tr:last-child > th { border-bottom-width: 0; }

/* Card headers with several buttons let them drop under the title on phones */
.fm-bills-wrap-header > .card-header { flex-wrap: wrap; gap: 0.75rem; }

/* A paid bill's items are read only; they shouldn't look like fields waiting for input */
.fm-bills-items .form-control[readonly] { background-color: var(--tblr-bg-surface-secondary); }

/* Internal notes keep the line breaks they were typed with */
.fm-bill-notes { white-space: pre-line; }

/* Quill's editor in the email window */
#emailBillModal .fm-bill-email-editor { height: 12.5rem; }
/* Quill's colour swatches are 16px; made 24px so each is big enough to hit (WCAG 2.5.8) */
#emailBillModal .ql-snow .ql-color-picker .ql-picker-options { width: 13.25rem; }
#emailBillModal .ql-snow .ql-color-picker .ql-picker-item { width: 24px; height: 24px; margin: 2px; }

/* Email and letter previews on the annual review scroll inside their box */
.fm-bill-preview { max-height: 20rem; overflow-y: auto; }
/* == end area: bills == */

/* == area: payments == */
/* Long farm names, items and error messages in list cells stop at a width and show in full on hover */
.fm-cell-truncate { max-width: 16rem; }
.fm-cell-truncate-sm { max-width: 12rem; }
.fm-cell-truncate-xs { max-width: 10rem; }

/* The email and text statuses keep their buttons beside them rather than wrapping underneath */
.fm-messages-cell { min-width: 17rem; }

/* Kit: x-ui.tom-select. Tom Select's Bootstrap 5 theme reads --bs-* colours, which Tabler names
   --tblr-*; these hand them over, so the picker looks and focuses like the other fields on every
   page that uses it (payments, farm edit, training records, missing TAMS IDs). Could move to the
   kit section of this file. */
.ts-wrapper,
.ts-dropdown {
    --bs-border-color: var(--tblr-border-color);
    --bs-border-color-translucent: var(--tblr-border-color);
    --bs-border-width: 1px;
    --bs-border-radius: var(--tblr-border-radius);
    --bs-body-bg: var(--tblr-bg-forms);
    --bs-body-color: var(--tblr-body-color);
    --bs-secondary-bg: var(--tblr-bg-surface-secondary);
    --bs-form-invalid-color: var(--tblr-danger);
}

.ts-wrapper.form-select.focus {
    border-color: var(--tblr-primary);
    box-shadow: 0 0 0 0.25rem rgba(var(--tblr-primary-rgb), 0.25);
}

.ts-wrapper.form-select.is-invalid { border-color: var(--tblr-danger); }
.ts-wrapper .focus .ts-control,
.ts-wrapper.focus .ts-control { box-shadow: none; }

.ts-control,
.ts-control input { color: var(--tblr-body-color); }
.ts-control input::placeholder { color: var(--tblr-secondary); opacity: 1; }

/* The option the arrow keys are on: navy like a native list, so it can't be missed */
.ts-dropdown .option.active {
    background-color: var(--tblr-primary);
    color: #fff;
}

.ts-dropdown .no-results { color: var(--tblr-secondary); }

/* The letters that matched: bold and underlined rather than Tom Select's yellow wash, which has
   no contrast on the navy row */
.ts-wrapper .ts-dropdown [data-selectable] .highlight,
.ts-dropdown.ts-dropdown [data-selectable] .highlight {
    background: none;
    color: inherit;
    font-weight: 700;
    text-decoration: underline;
}

/* While typing a search, the old choice steps aside so the text doesn't wrap under it */
.ts-wrapper.single.fm-ts-typing .ts-control > .item { display: none; }

/* The bill picker on "Record payment": the balance line under each bill, readable on the
   highlighted (navy) row too */
.fm-bill-option-owes { color: var(--tblr-secondary); }
.ts-dropdown .option.active .fm-bill-option-owes { color: inherit; }

/* Small links in a busy cell get a 24px-high target (WCAG 2.5.8) */
.fm-link-target {
    display: inline-block;
    min-height: 1.5rem;
    line-height: 1.5rem;
}

/* "Email" / "Text" in front of each message status on the bulk import list, so the badges line up */
.fm-channel-label {
    min-width: 2.25rem;
    font-size: 0.8125rem;
    color: var(--tblr-secondary);
}

.fm-pre-line { white-space: pre-line; }
.fm-pre-wrap { white-space: pre-wrap; }

/* Error lists that can run to hundreds of rows scroll inside their card */
.table-responsive.fm-scroll-y { max-height: 20rem; overflow-y: auto; }

/* A heading row inside a table body ("The farmer", "Schemes") */
.fm-table-group {
    background-color: var(--tblr-bg-surface-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--tblr-secondary);
}

/* Page titles that are file names can be one long word */
.fm-break-title .page-title { overflow-wrap: anywhere; }

/* The amount being charged, at the top of the card payment forms */
.fm-pay-amount {
    padding: 1rem 1.25rem;
    border-radius: var(--tblr-border-radius);
    background-color: var(--tblr-bg-surface-secondary);
}

.fm-pay-amount-center { text-align: center; }

.fm-pay-amount-figure {
    font-size: 2.25rem;
    font-weight: 700;
    line-height: 1.15;
    color: var(--tblr-body-color);
}

/* The box Stripe mounts its card input in, looking and focusing like the other fields */
.fm-card-field {
    min-height: 2.75rem;
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
}

.fm-card-field.StripeElement--focus {
    border-color: var(--tblr-primary);
    box-shadow: 0 0 0 0.25rem rgba(var(--tblr-primary-rgb), 0.25);
}

.fm-card-field.StripeElement--invalid { border-color: var(--tblr-danger); }

/* The farmer's pay-a-bill pages: a little wider than the sign-in card */
.fm-container-pay { max-width: 36rem; }

/* The guest layout centres its card in a box one screen high; a pay page is taller than a
   phone screen, and the centred box then pushed the logo and title above the top of the
   page, out of reach. Letting the box grow keeps the top in view. */
.fm-guest > main.page-center:has(.fm-container-pay) { flex-shrink: 0; }

.fm-result-icon {
    font-size: 3rem;
    line-height: 1;
}

/* A red status badge beside a page title sits on the grey page, where Tabler's red tint
   drops under 4.5:1; these headers use the darker red the alerts use */
.fm-status-header .badge.bg-danger-lt { color: #a61d1d !important; }

/* The error summary's links, one per line, are too close together to tap (WCAG 2.5.8) */
#paymentForm #error-summary li + li { margin-top: 0.375rem; }
/* == end area: payments == */

/* == area: quickbooks-settings == */
.fm-link-card {
    color: inherit;
}

.fm-link-card:focus-visible {
    outline: 2px solid var(--tblr-primary);
    outline-offset: 2px;
}

/* Numbered how-to steps (the Chrome plugin page). Its own class: .fm-steps belongs to x-ui.steps */
.fm-howto-steps {
    counter-reset: fm-howto-step;
    list-style: none;
    margin: 0;
    padding: 0;
}

.fm-howto-steps > li {
    counter-increment: fm-howto-step;
    position: relative;
    padding-left: 2.75rem;
}

.fm-howto-steps > li + li {
    margin-top: 1rem;
}

.fm-howto-steps > li::before {
    content: counter(fm-howto-step);
    position: absolute;
    left: 0;
    top: 0;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    background: var(--tblr-primary-lt, #e8eef4);
    color: var(--tblr-primary);
}

/* Import cards in a row line up: equal heights, buttons along the bottom */
.fm-settings-imports .row-cards > [class*="col"] > .fm-import-card {
    height: 100%;
}

.fm-settings-imports .fm-import-card > form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
}

.fm-settings-imports .fm-import-card > form > .card-body {
    flex: 1 1 auto;
}

/* The words to type to confirm a clean-up */
.fm-phrase {
    font-family: var(--tblr-font-monospace);
    font-weight: 600;
    padding: 0.05rem 0.35rem;
    border-radius: var(--tblr-border-radius-sm);
    background: var(--tblr-bg-surface-secondary);
    white-space: nowrap;
}

/* Placeholders to insert into a message: big enough to hit (WCAG 2.5.8) */
.fm-placeholder-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.fm-placeholder-chips .btn {
    min-height: 1.75rem;
}

/* Quill editors: a fixed-height writing area that scrolls, matched to the form controls.
   body-prefixed to win over quill.snow.css, which loads after this file */
body .ql-toolbar.ql-snow {
    border-color: var(--tblr-border-color);
    border-radius: var(--tblr-border-radius) var(--tblr-border-radius) 0 0;
    font-family: inherit;
}

.fm-quill.ql-container.ql-snow {
    height: 15rem;
    border-color: var(--tblr-border-color);
    border-radius: 0 0 var(--tblr-border-radius) var(--tblr-border-radius);
    font-family: inherit;
    font-size: 0.875rem;
}

.fm-quill.fm-quill-tall.ql-container.ql-snow {
    height: 20rem;
}

/* Colour swatches big enough to hit (24px, WCAG 2.5.8) */
body .ql-snow .ql-color-picker .ql-picker-options {
    width: 214px;
}

body .ql-snow .ql-color-picker .ql-picker-item {
    width: 24px;
    height: 24px;
}

.fm-quill .ql-editor:focus-visible {
    outline: 2px solid var(--tblr-primary);
    outline-offset: -2px;
}

/* Old and new values side by side in the activity log */
.fm-diff-value {
    max-width: 28rem;
    word-break: break-word;
}

.fm-preserve-lines {
    white-space: pre-wrap;
}

/* An email as it was sent, in a frame */
.fm-email-frame {
    display: block;
    width: 100%;
    min-height: 30rem;
    border: 0;
    background: #fff;
}

.fm-message-text {
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
    font-size: 0.9375rem;
    margin: 0;
    background: none;
    padding: 0;
    color: inherit;
}

.fm-code-block {
    max-height: 30rem;
    overflow: auto;
    margin: 0;
    font-size: 0.8125rem;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Saved email or letter wording, framed so its headings stay out of the page */
.fm-wording-frame {
    display: block;
    width: 100%;
    min-height: 3rem;
    background: #fff;
}

/* What happened to a message, in order */
.fm-timeline {
    list-style: none;
    margin: 0;
    padding: 0;
}

.fm-timeline-item {
    position: relative;
    display: flex;
    gap: 0.75rem;
    padding-bottom: 1rem;
}

.fm-timeline-item:last-child {
    padding-bottom: 0;
}

.fm-timeline-item > div {
    min-width: 0;
}

.fm-timeline-item:not(:last-child)::before {
    content: "";
    position: absolute;
    left: calc(1rem - 1px);
    top: 2.25rem;
    bottom: 0.25rem;
    width: 2px;
    background: var(--tblr-border-color);
}

.fm-cell-truncate {
    max-width: 20rem;
}

/* A red status badge beside a page title sits on the grey page, not a white card, which takes
   Tabler's red text just under 4.5:1; a darker red keeps it readable */
.fm-header-status .badge.bg-danger-lt {
    color: #a61d1d !important;
}

/* A long list in a card that scrolls inside the card rather than stretching the page */
.fm-scroll-tall {
    max-height: 30rem;
    overflow-y: auto;
}
/* == end area: quickbooks-settings == */

/* == area: tams == */
/* Steps still to come stay readable: Tabler greys them below AA. Covers the status-file steps
   and the portal imports' x-ui.steps (kit-wide; the kit could take this over) */
.fm-tams-steps .step-item.active ~ .step-item,
.steps.fm-steps .step-item.active ~ .step-item {
    color: var(--tblr-secondary);
}

/* Portal imports (components/import-status): several messages in the one box */
.fm-import-status-message + .fm-import-status-message {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--tblr-border-color-translucent);
}

/* Investment names keep a readable width when the table scrolls on a phone */
.fm-tams-investment {
    min-width: 14rem;
}

/* A farm's heading row inside a grouped report table */
.fm-tams-group > th {
    background: var(--tblr-bg-surface-secondary);
}

.fm-tams-comment {
    max-width: 12rem;
}

/* A single picker that shouldn't stretch across a wide card */
.fm-tams-narrow {
    max-width: 32rem;
}

/* Investment rows on the application forms: figures take what they need, the description the rest */
.fm-tams-col-cost {
    width: 10rem;
}
.fm-tams-col-money {
    width: 9rem;
}
/* No rows yet: a sentence instead of an empty table heading */
.fm-tams-invest:not(:has(tbody tr)) table,
.fm-tams-invest:has(tbody tr) .fm-tams-invest-empty {
    display: none;
}

/* Tabler drops the rule under a card table's last row, but only for td cells. Tables with a
   total row, or a group per farm, keep it on every cell; elsewhere the row header loses it too. */
.card-table.fm-tams-foot > tbody > tr:last-child > td,
.card-table.fm-tams-grouped > tbody:not(:last-child) > tr:last-child > td {
    border-bottom: var(--tblr-border-width) solid var(--tblr-table-border-color);
}
.card-table.fm-tams-table:not(.fm-tams-foot) > tbody:last-child > tr:last-child > th {
    border-bottom-width: 0;
}
/* == end area: tams == */

/* == area: tams-reference == */
/* Quill editors (scheme letter, TAMS terms): match the form controls around them */
.fm-rich-editor.ql-container {
    font-family: inherit;
    font-size: 0.875rem;
    border-color: var(--tblr-border-color);
    border-radius: 0 0 var(--tblr-border-radius) var(--tblr-border-radius);
    background: var(--tblr-bg-forms);
}

.fm-rich-editor .ql-editor {
    min-height: 13rem;
}

.fm-rich-editor .ql-editor code {
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.9em;
}

.ql-toolbar.ql-snow {
    border-color: var(--tblr-border-color);
    border-radius: var(--tblr-border-radius) var(--tblr-border-radius) 0 0;
}

.fm-rich-editor:focus-within {
    border-color: var(--tblr-primary);
    box-shadow: 0 0 0 0.25rem rgba(var(--tblr-primary-rgb), 0.25);
}

/* Census year + count + remove, on one line */
.fm-census-row {
    max-width: 24rem;
}

/* Short codes and orders in the scheme actions table */
.fm-input-table .fm-scheme-short {
    min-width: 4rem;
    max-width: 5rem;
}

/* A category of actions inside the enrolment form */
.fm-enrol-category {
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 0;
}

.fm-enrol-category + .fm-enrol-category {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--tblr-border-color);
}

/* Quill colour swatches big enough to tap (WCAG 2.5.8: 24px) */
.ql-toolbar.ql-snow .ql-color-picker .ql-picker-options {
    width: 206px;
}

.ql-toolbar.ql-snow .ql-color-picker .ql-picker-item {
    width: 24px;
    height: 24px;
}
/* == end area: tams-reference == */

/* == area: farm-reference == */
/* A description under a name in a list stays on one line */
.fm-ref-truncate {
    max-width: 28rem;
}

/* The name column of a list keeps a readable width on phones; the table scrolls sideways
   instead of squeezing a product name onto five lines */
.fm-ref-namecol {
    min-width: 11rem;
}

/* The upload, check, import steps (x-ui.steps). The quickbooks-settings area styles .fm-steps
   as a numbered how-to list, which also lands on the kit's steps and staggers them; this puts
   Tabler's steps back for this page, and darkens the steps still to come to readable grey. */
.fm-ref-steps.steps > .step-item {
    counter-increment: steps;
    margin-top: 0;
    padding-left: 0;
    padding-top: calc(var(--tblr-steps-dot-size) + 0.25rem);
}

.fm-ref-steps.steps > .step-item::before {
    content: counter(steps);
    left: 50%;
    width: var(--tblr-steps-dot-size);
    height: var(--tblr-steps-dot-size);
    border-radius: var(--tblr-border-radius-pill);
    font-size: 0.75rem;
    background: var(--tblr-steps-color);
    color: var(--tblr-white);
}

.fm-ref-steps.steps > .step-item.active ~ .step-item {
    color: var(--tblr-secondary);
}

.fm-ref-steps.steps > .step-item.active ~ .step-item::before {
    background: var(--tblr-steps-inactive-color);
    color: var(--tblr-body-color);
}

/* Master soil samples: the three step cards (upload, check, import) line up, buttons at the foot */
.fm-ref-flow .fm-import-card {
    height: 100%;
}

.fm-ref-flow .fm-import-card > form {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
}

.fm-ref-flow .fm-import-card > form > .card-body {
    flex: 1 1 auto;
}

/* The client's name under a sample ID, and plot names, in the master soil sample list */
.fm-ref-name {
    max-width: 9rem;
}

.fm-ref-plot {
    min-width: 6.5rem;
}

/* Tables split into groups with a heading row each (several tbody): Tabler drops the rule
   under each tbody's last row, which left a half-drawn line between groups */
.fm-ref-grouped > tbody:not(:last-child) > tr:last-child > td {
    border-bottom: var(--tblr-border-width) var(--tblr-border-style) var(--tblr-table-border-color);
}

.fm-ref-grouped > tbody:last-child > tr:last-child > th {
    border-bottom: 0;
}

.fm-ref-group > th {
    background-color: var(--tblr-bg-surface-secondary);
    font-weight: 600;
}

/* The crop limits table: narrower fields so all eight columns fit beside the menu, with room
   for the row's "Same as the row below" note */
.fm-input-table .fm-minw-7 {
    min-width: 7rem;
}

.fm-ref-limits .form-control {
    min-width: 5.5rem;
    padding-inline: 0.5rem;
}

.fm-ref-limits .fm-ref-narrow {
    min-width: 3.5rem;
}

.fm-ref-limits .invalid-feedback-cell {
    min-width: 7rem;
}

/* The sample details panel: two short facts a row instead of one long column */
.fm-sample-panel .datagrid {
    --tblr-datagrid-padding: 1rem;
    --tblr-datagrid-item-width: 9rem;
}
/* == end area: farm-reference == */

/* == area: reports == */
/* Reminder and text screens: the list of farms to tick scrolls inside the card, so the send
   button under it stays close however long the list is; the header row stays in view */
.fm-report-picker {
    max-height: 36rem;
}

.fm-report-picker thead.sticky-top {
    z-index: 1;
}

/* The hidden caption sits at the top, so it can't poke a pixel below the table and make the
   list scroll when it is short */
.fm-report-picker caption {
    caption-side: top;
}

.fm-report-picker thead th {
    background: var(--tblr-bg-surface-tertiary, var(--tblr-gray-50));
}

/* An amount box that only needs a few digits */
.fm-report-amount {
    max-width: 10rem;
}

/* The row header in a list's last row keeps no bottom rule, like the other cells */
.fm-report-picker .card-table tbody tr:last-child > th,
.fm-report-dt .card-table tbody tr:last-child > th {
    border-bottom: 0;
}

/* Notes in a report table wrap in a readable column rather than stretching the table */
.fm-report-notes {
    min-width: 10rem;
    max-width: 20rem;
}

/* DataTables reports (reports/partials/datatable): the table runs edge to edge in the card
   like every other list; DataTables' own spacing around it is dropped */
.fm-report-dt .dt-container > .table-responsive {
    margin: 0;
}

.fm-report-dt table.dataTable {
    margin: 0 !important;
}

/* The page buttons (first, previous, up to seven numbers, next, last) wrap onto a second line
   rather than pushing a phone-width page sideways when a report runs to many pages */
.fm-report-dt .dt-paging {
    min-width: 0;
    max-width: 100%;
}

.fm-report-dt .dt-paging .pagination {
    flex-wrap: wrap;
    justify-content: flex-end;
    margin: 0;
}

/* Wide reports: headings may wrap ("Phosphorus (kg)") so the figures fit without scrolling */
.fm-report-dt thead th {
    white-space: normal;
}

/* DataTables right-aligns anything it reads as a date; dates read left like the rest */
.fm-report-dt table.dataTable th.dt-type-date,
.fm-report-dt table.dataTable td.dt-type-date {
    text-align: start;
}

/* Headline figures that filter the report (reports/partials/filter-stat): the whole card is
   the link; the one in use has a navy edge and says "Showing" */
.fm-stat-filter,
.fm-stat-link {
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.fm-stat-filter:hover,
.fm-stat-link:hover {
    border-color: var(--tblr-primary);
}

.fm-stat-filter:has(.stretched-link:focus-visible),
.fm-stat-link:has(.stretched-link:focus-visible) {
    outline: 2px solid var(--tblr-primary);
    outline-offset: 2px;
}

.fm-stat-filter .stretched-link:focus-visible,
.fm-stat-link .stretched-link:focus-visible {
    outline: none;
}

.fm-stat-current {
    border-color: var(--tblr-primary);
    box-shadow: inset 0 0 0 1px var(--tblr-primary);
}

.fm-stat-showing {
    display: none;
    margin-inline-start: 0.5rem;
    font-size: 0.6875rem;
    vertical-align: middle;
}

.fm-stat-current .fm-stat-showing {
    display: inline-block;
}

@media (prefers-reduced-motion: reduce) {
    .fm-stat-filter,
    .fm-stat-link {
        transition: none;
    }
}

/* Bulk sends (x-ui.recipient-picker): the message as the first ticked client gets it, with
   its line breaks */
.fm-picker-preview-text {
    white-space: pre-line;
    max-width: 48rem;
}
/* == end area: reports == */

/* == area: farms == */
/* Farm list: long names and owners are cut short (the full text is in a title) */
.fm-farm-cell {
    max-width: 16rem;
}

/* Farm add/edit: the save buttons stay in view down the long form */
.fm-farm-form .fm-form-footer {
    position: sticky;
    bottom: 0;
    z-index: 3;
    background: var(--tblr-bg-surface);
    border-bottom-left-radius: inherit;
    border-bottom-right-radius: inherit;
    box-shadow: 0 -1px 0 var(--tblr-border-color), 0 -0.5rem 1rem rgba(var(--tblr-body-color-rgb), 0.04);
}

/* ...and a field reached with Tab scrolls clear of them */
html:has(.fm-farm-form) {
    scroll-padding-bottom: 5rem;
}

/* The farmer's email and phone links on the edit form are full 24px targets */
.fm-farmer-contacts > * {
    display: inline-block;
    line-height: 1.5rem;
}

.fm-farm-panel {
    padding: 1rem;
    border: 1px solid var(--tblr-border-color);
    border-radius: var(--tblr-border-radius);
    background: var(--tblr-bg-surface-secondary);
}

/* Farmer dashboard: this year's checklist on each farm card */
.fm-farmer-checklist li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0;
    border-top: 1px solid var(--tblr-border-color);
}

.fm-farmer-checklist li:last-child {
    border-bottom: 1px solid var(--tblr-border-color);
}

.fm-farmer-bill {
    background: var(--tblr-bg-surface-secondary);
}

.fm-min-w-0 {
    min-width: 0;
}

/* Portal imports: the numbered steps */
.fm-import-steps {
    padding-left: 1.25rem;
}

.fm-import-steps li + li {
    margin-top: 0.5rem;
}

/* Error summary on the farm forms: long messages wrap on phones (alert links don't wrap by
   default) and each link is a full 24px target */
.fm-farm-form #error-summary .alert-link {
    display: inline-block;
    min-height: 1.5rem;
    white-space: normal;
}
/* == end area: farms == */

/* == area: theme == */
/* Dark mode. <html data-bs-theme="dark"> comes from the head script (the theme menu's choice, or
   the device's setting). Most colours follow by themselves: Tabler's and ours (the light-dark()
   tokens in :root at the top of this file). These are the places that set a colour of their own.
   Every value is a token, so printing (forced to the light scheme) still comes out light. */

/* The theme menu (layouts/partials/theme-menu): the button shows the choice; the menu ticks it */
.fm-theme-menu [data-fm-theme-toggle] > i {
    display: none;
}

:root[data-fm-theme-choice="light"] .fm-theme-menu .fm-theme-when-light,
:root[data-fm-theme-choice="dark"] .fm-theme-menu .fm-theme-when-dark,
:root:not([data-fm-theme-choice="light"]):not([data-fm-theme-choice="dark"]) .fm-theme-menu .fm-theme-when-auto {
    display: inline-block;
}

.fm-theme-menu .dropdown-item[aria-checked="true"] {
    font-weight: 600;
}

.fm-theme-check {
    visibility: hidden;
}

.fm-theme-menu .dropdown-item[aria-checked="true"] .fm-theme-check {
    visibility: visible;
}

/* A white chip (the farmer bar's badge and initials, a current filter pill's count) keeps navy
   text in either theme; the primary turns light blue on dark, which can't be read on white */
.bg-white.text-primary {
    color: var(--fm-navy) !important;
}

/* The farmer bar is navy in both themes; its menus are light on light pages and dark on dark */
:root[data-bs-theme="dark"] .fm-farmer-bar .dropdown-menu[data-bs-theme="light"] {
    color-scheme: dark;
}

/* Shades set as fixed colours above and in the areas, given their dark counterparts */
[data-bs-theme="dark"] .bg-danger-lt,
[data-bs-theme="dark"] .fm-status-header .badge.bg-danger-lt {
    color: var(--fm-danger-strong) !important;
}

[data-bs-theme="dark"] .alert-success {
    --tblr-alert-color: var(--fm-success-strong);
}

[data-bs-theme="dark"] .alert-danger {
    --tblr-alert-color: var(--fm-danger-strong);
}

/* Focus rings and tints written as rgba(var(--x-rgb), a) */
@media screen {
    :root[data-bs-theme="dark"] {
        --tblr-primary-rgb: 122, 179, 230;
        --tblr-success-rgb: 98, 196, 114;
        --tblr-danger-rgb: 255, 138, 138;
        --tblr-secondary-rgb: 161, 169, 179;
        --tblr-muted-rgb: 161, 169, 179;
    }
}

/* Text on a primary fill is navy ink on dark (white can't be read on the light-blue primary) */
[data-bs-theme="dark"] .pagination {
    --tblr-pagination-active-color: var(--tblr-primary-fg);
}

[data-bs-theme="dark"] .bg-primary.text-white,
[data-bs-theme="dark"] .text-bg-primary,
[data-bs-theme="dark"] .ts-dropdown .option.active {
    color: var(--tblr-primary-fg) !important;
}

/* Tabler's fixed mid grey (4.7:1 on white, 3.2:1 on a dark card) where it is used for text */
[data-bs-theme="dark"] .nav {
    --tblr-nav-link-color: var(--tblr-secondary);
}

[data-bs-theme="dark"] .input-group-text,
[data-bs-theme="dark"] .footer,
[data-bs-theme="dark"] .list-group-header {
    color: var(--tblr-secondary);
}

[data-bs-theme="dark"] .toast {
    --tblr-toast-header-color: var(--tblr-secondary);
}

[data-bs-theme="dark"] .breadcrumb {
    --tblr-breadcrumb-divider-color: var(--tblr-secondary);
}

/* Bootstrap's fixed light utilities */
[data-bs-theme="dark"] .bg-light {
    background-color: var(--tblr-bg-surface-secondary) !important;
}

[data-bs-theme="dark"] .table-light {
    --tblr-table-color: var(--tblr-body-color);
    --tblr-table-bg: var(--tblr-bg-surface-tertiary);
    --tblr-table-border-color: var(--tblr-border-color);
    --tblr-table-striped-bg: var(--tblr-bg-surface-secondary);
    --tblr-table-hover-bg: var(--tblr-hover-bg);
    color: var(--tblr-body-color);
    border-color: var(--tblr-border-color);
}

/* Saved emails and letters stay as they were sent: white paper inside a dark page */
[data-bs-theme="dark"] .fm-email-frame,
[data-bs-theme="dark"] .fm-wording-frame {
    color-scheme: light;
}

/* ---------- SweetAlert dialogs ---------- */
:root[data-bs-theme="dark"] {
    --swal2-background: var(--tblr-bg-surface);
    --swal2-color: var(--tblr-body-color);
    --swal2-backdrop: rgba(0, 0, 0, 0.6);
    --swal2-input-background: var(--tblr-bg-forms);
    --swal2-input-border: 1px solid var(--tblr-border-color);
    --swal2-validation-message-background: var(--tblr-bg-surface-secondary);
    --swal2-validation-message-color: var(--tblr-body-color);
    --swal2-footer-border-color: var(--tblr-border-color);
    --swal2-close-button-color: var(--tblr-secondary);
}

[data-bs-theme="dark"] .swal2-popup .swal2-input,
[data-bs-theme="dark"] .swal2-popup .swal2-textarea,
[data-bs-theme="dark"] .swal2-popup .swal2-select {
    color: var(--tblr-body-color);
}

/* ---------- DataTables (Bootstrap 5 styling reads --bs-* colours, which Tabler calls --tblr-*) ---------- */
[data-bs-theme="dark"] .dt-container,
[data-bs-theme="dark"] .dt-button-collection,
[data-bs-theme="dark"] .dtsb-searchBuilder,
[data-bs-theme="dark"] .dtsp-panesContainer {
    --bs-body-color: var(--tblr-body-color);
    --bs-body-bg: var(--tblr-bg-surface);
    --bs-border-color: var(--tblr-border-color);
    --bs-secondary-color: var(--tblr-secondary);
    --bs-tertiary-bg: var(--tblr-bg-surface-secondary);
    --bs-emphasis-color-rgb: 229, 229, 229;
    --dt-row-selected: 122, 179, 230;
    --dt-row-selected-text: 10, 34, 54;
    --dt-row-selected-link: 10, 34, 54;
    --dt-row-stripe: 255, 255, 255;
    --dt-row-hover: 255, 255, 255;
    --dt-column-ordering: 255, 255, 255;
    --dt-html-background: var(--tblr-body-bg);
}

[data-bs-theme="dark"] div.dt-container div.dt-processing > div:last-child > div {
    background: var(--tblr-primary);
}

[data-bs-theme="dark"] .dt-button-collection .dropdown-menu,
[data-bs-theme="dark"] div.dt-button-collection {
    background-color: var(--tblr-bg-surface);
    color: var(--tblr-body-color);
}

/* ---------- Quill editors ---------- */
[data-bs-theme="dark"] .ql-snow .ql-stroke {
    stroke: var(--tblr-body-color);
}

[data-bs-theme="dark"] .ql-snow .ql-fill,
[data-bs-theme="dark"] .ql-snow .ql-stroke.ql-fill {
    fill: var(--tblr-body-color);
}

[data-bs-theme="dark"] .ql-snow .ql-picker {
    color: var(--tblr-body-color);
}

[data-bs-theme="dark"] .ql-snow.ql-toolbar button:hover .ql-stroke,
[data-bs-theme="dark"] .ql-snow.ql-toolbar button:focus .ql-stroke,
[data-bs-theme="dark"] .ql-snow.ql-toolbar button.ql-active .ql-stroke,
[data-bs-theme="dark"] .ql-snow.ql-toolbar .ql-picker-label:hover .ql-stroke,
[data-bs-theme="dark"] .ql-snow.ql-toolbar .ql-picker-label.ql-active .ql-stroke {
    stroke: var(--tblr-primary);
}

[data-bs-theme="dark"] .ql-snow.ql-toolbar button:hover .ql-fill,
[data-bs-theme="dark"] .ql-snow.ql-toolbar button:focus .ql-fill,
[data-bs-theme="dark"] .ql-snow.ql-toolbar button.ql-active .ql-fill {
    fill: var(--tblr-primary);
}

[data-bs-theme="dark"] .ql-snow.ql-toolbar button:hover,
[data-bs-theme="dark"] .ql-snow.ql-toolbar button.ql-active,
[data-bs-theme="dark"] .ql-snow.ql-toolbar .ql-picker-label:hover,
[data-bs-theme="dark"] .ql-snow.ql-toolbar .ql-picker-label.ql-active,
[data-bs-theme="dark"] .ql-snow.ql-toolbar .ql-picker-item:hover,
[data-bs-theme="dark"] .ql-snow.ql-toolbar .ql-picker-item.ql-selected {
    color: var(--tblr-primary);
}

[data-bs-theme="dark"] .ql-snow .ql-picker-options,
[data-bs-theme="dark"] .ql-snow .ql-tooltip {
    background-color: var(--tblr-bg-surface);
    color: var(--tblr-body-color);
    border-color: var(--tblr-border-color);
    box-shadow: var(--tblr-shadow-dropdown);
}

[data-bs-theme="dark"] .ql-snow .ql-picker.ql-expanded .ql-picker-label,
[data-bs-theme="dark"] .ql-snow .ql-picker.ql-expanded .ql-picker-options {
    border-color: var(--tblr-border-color);
}

[data-bs-theme="dark"] .ql-snow .ql-tooltip input[type="text"] {
    background-color: var(--tblr-bg-forms);
    color: var(--tblr-body-color);
    border-color: var(--tblr-border-color);
}

[data-bs-theme="dark"] .ql-snow .ql-tooltip a {
    color: var(--tblr-link-color);
}

[data-bs-theme="dark"] .ql-editor.ql-blank::before {
    color: var(--tblr-secondary);
}

/* ---------- Select pickers: Select2, Chosen ---------- */
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection,
[data-bs-theme="dark"] .select2-container--default .select2-selection,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown,
[data-bs-theme="dark"] .select2-container--default .select2-dropdown,
[data-bs-theme="dark"] .select2-container .select2-search__field {
    background-color: var(--tblr-bg-forms);
    color: var(--tblr-body-color);
    border-color: var(--tblr-border-color);
}

[data-bs-theme="dark"] .select2-container .select2-selection__rendered {
    color: var(--tblr-body-color);
}

[data-bs-theme="dark"] .select2-container .select2-selection__placeholder,
[data-bs-theme="dark"] .select2-container .select2-results__message,
[data-bs-theme="dark"] .select2-container .select2-results__group,
[data-bs-theme="dark"] .select2-container .select2-results__option--disabled {
    color: var(--tblr-secondary);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option.select2-results__option--highlighted,
[data-bs-theme="dark"] .select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
    background-color: var(--tblr-primary);
    color: var(--tblr-primary-fg);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option.select2-results__option--selected,
[data-bs-theme="dark"] .select2-container--default .select2-results__option--selected {
    background-color: var(--tblr-active-bg);
    color: var(--tblr-body-color);
}

[data-bs-theme="dark"] .select2-container .select2-selection--multiple .select2-selection__choice {
    background-color: var(--tblr-bg-surface-secondary);
    color: var(--tblr-body-color);
    border-color: var(--tblr-border-color);
}

[data-bs-theme="dark"] .chosen-container-single .chosen-single,
[data-bs-theme="dark"] .chosen-container-multi .chosen-choices,
[data-bs-theme="dark"] .chosen-container-active.chosen-with-drop .chosen-single {
    background: var(--tblr-bg-forms);
    color: var(--tblr-body-color);
    border-color: var(--tblr-border-color);
    box-shadow: none;
}

[data-bs-theme="dark"] .chosen-container .chosen-drop {
    background: var(--tblr-bg-surface);
    border-color: var(--tblr-border-color);
}

[data-bs-theme="dark"] .chosen-container .chosen-results,
[data-bs-theme="dark"] .chosen-container-single .chosen-search input[type="text"],
[data-bs-theme="dark"] .chosen-container-multi .chosen-choices li.search-field input[type="text"] {
    color: var(--tblr-body-color);
}

[data-bs-theme="dark"] .chosen-container-single .chosen-search input[type="text"] {
    background-color: var(--tblr-bg-forms);
    border-color: var(--tblr-border-color);
}

[data-bs-theme="dark"] .chosen-container-single .chosen-default,
[data-bs-theme="dark"] .chosen-container .chosen-results li.disabled-result,
[data-bs-theme="dark"] .chosen-container-multi .chosen-drop .result-selected {
    color: var(--tblr-secondary);
}

[data-bs-theme="dark"] .chosen-container .chosen-results li.highlighted {
    background: var(--tblr-primary);
    color: var(--tblr-primary-fg);
}

[data-bs-theme="dark"] .chosen-container .chosen-results li.no-results {
    background: var(--tblr-bg-surface-secondary);
    color: var(--tblr-secondary);
}

[data-bs-theme="dark"] .chosen-container-multi .chosen-choices li.search-choice {
    background: var(--tblr-bg-surface-secondary);
    color: var(--tblr-body-color);
    border-color: var(--tblr-border-color);
    box-shadow: none;
}

/* Chosen's arrow and remove icons are dark pictures; lightened for the dark field */
[data-bs-theme="dark"] .chosen-container-single .chosen-single div b,
[data-bs-theme="dark"] .chosen-container-multi .chosen-choices li.search-choice .search-choice-close {
    filter: invert(0.85);
}
/* == end area: theme == */

/* == area: npk-save-bar == */
/* The save bar on the farm workspace pages (components/farms/save-bar, js/save-bar.js). It is the
   last thing in the page content and sticks to the bottom of the window while there is more page
   below, so it stays inside the content column (never over the menu) and, being in the flow,
   never covers the end of the page. */
.fm-save-bar {
    position: sticky;
    bottom: 0;
    /* Over the page, under menus, pickers, dialogs and SweetAlert */
    z-index: 990;
    margin-top: 1.5rem;
    padding-bottom: 0.75rem;
    /* The strip under the bar is page, so content scrolling behind doesn't show through the gap */
    background: linear-gradient(to bottom, transparent calc(100% - 0.75rem), var(--tblr-body-bg) 0);
}

.fm-save-bar[hidden] {
    display: none;
}

.fm-save-bar-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1rem;
    padding: 0.75rem 1rem;
    background: var(--tblr-bg-surface, #fff);
    border: 1px solid var(--tblr-border-color);
    border-radius: var(--tblr-border-radius-lg, 0.5rem);
    box-shadow: 0 -0.25rem 1.25rem rgba(10, 34, 54, 0.14);
}

.fm-save-bar-message {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    flex: 1 1 18rem;
    min-width: 0;
    border-radius: var(--tblr-border-radius);
}

.fm-save-bar-message:focus {
    outline: none;
}

.fm-save-bar-message:focus-visible {
    outline: 2px solid var(--tblr-primary);
    outline-offset: 2px;
}

.fm-save-bar-icon {
    flex: none;
    width: 1.25rem;
    padding-top: 0.125rem;
    font-size: 1.125rem;
    line-height: 1;
    text-align: center;
}

.fm-save-bar-text {
    min-width: 0;
    overflow-wrap: anywhere;
}

.fm-save-bar-actions {
    flex: none;
    margin-left: auto;
}

.fm-save-bar-actions .btn[aria-disabled="true"] {
    pointer-events: none;
}

.fm-save-bar-actions .btn .spinner-border {
    margin-right: 0.375rem;
}

/* While the bar is up, anything scrolled to by keyboard stops above it rather than under it */
html.fm-save-bar-shown {
    scroll-padding-bottom: var(--fm-save-bar-space, 7rem);
}

@media (max-width: 575.98px) {
    .fm-save-bar {
        padding-bottom: 0.5rem;
        background: linear-gradient(to bottom, transparent calc(100% - 0.5rem), var(--tblr-body-bg) 0);
    }

    .fm-save-bar-inner {
        padding: 0.75rem;
    }

    /* Two equal buttons across the bar */
    .fm-save-bar-actions {
        width: 100%;
        margin-left: 0;
    }

    .fm-save-bar-actions .btn {
        flex: 1 1 0;
    }
}
/* == end area: npk-save-bar == */

/* == area: farm-overview == */
/* Long lists on the farm overview's tabs scroll inside their card, headings kept in view */
.table-responsive.fm-overview-scroll {
    max-height: 28rem;
    overflow-y: auto;
}

.fm-overview-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--tblr-bg-surface-tertiary);
}

/* Bill types and the like are cut short (the full text is in a title) */
.fm-overview-cell {
    max-width: 14rem;
}

/* The farm files list: long file names are cut short by CSS, so a screen reader still hears them whole */
.fm-file-name {
    max-width: 20rem;
}
/* == end area: farm-overview == */

/* Farm assistant: the chat window from the Ask button (resources/views/assistant/panel.blade.php) */
.fm-assistant.offcanvas-end {
    width: min(100vw, 30rem);
}
.fm-assistant .offcanvas-header {
    align-items: flex-start;
    border-bottom: 1px solid var(--tblr-border-color);
    gap: .75rem;
}
.fm-assistant .offcanvas-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0;
}
.fm-assistant .offcanvas-title .fa-wand-magic-sparkles,
.fm-assistant-fab .fa-wand-magic-sparkles {
    color: var(--tblr-primary);
}
.fm-assistant-scope {
    color: var(--tblr-secondary);
    font-size: .875rem;
    margin: .125rem 0 0;
}
.fm-assistant .offcanvas-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.fm-assistant-intro {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}
.fm-assistant-intro p {
    margin: 0;
}
.fm-assistant-label {
    color: var(--tblr-secondary);
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .04em;
    margin: .5rem 0 0;
    text-transform: uppercase;
}
.fm-assistant-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}
.fm-assistant-chip {
    background: var(--tblr-bg-surface);
    border: 1px solid var(--tblr-border-color);
    border-radius: 1rem;
    color: var(--tblr-body-color);
    font-size: .9375rem;
    line-height: 1.3;
    padding: .375rem .75rem;
    text-align: left;
}
.fm-assistant-chip:hover,
.fm-assistant-chip:focus-visible {
    border-color: var(--tblr-primary);
    color: var(--tblr-primary);
}
.fm-assistant-recent {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    list-style: none;
    margin: .25rem 0 0;
    padding: 0;
}
.fm-assistant-recent-item {
    align-items: baseline;
    background: none;
    border: 0;
    border-radius: var(--tblr-border-radius);
    color: var(--tblr-body-color);
    display: flex;
    gap: .75rem;
    justify-content: space-between;
    padding: .375rem .5rem;
    text-align: left;
    width: 100%;
}
.fm-assistant-recent-item span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.fm-assistant-recent-item small {
    color: var(--tblr-secondary);
    flex-shrink: 0;
}
.fm-assistant-recent-item:hover,
.fm-assistant-recent-item:focus-visible {
    background: var(--tblr-bg-surface-secondary);
}
.fm-assistant-log {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    list-style: none;
    margin: 0;
    padding: 0;
}
.fm-assistant-log:empty {
    display: none;
}
.fm-assistant-q {
    align-self: flex-end;
    background: var(--tblr-primary-lt);
    border-radius: 1rem 1rem .25rem 1rem;
    max-width: 85%;
    overflow-wrap: anywhere;
    padding: .5rem .875rem;
    white-space: pre-wrap;
}
.fm-assistant-a {
    min-width: 0;
}
.fm-assistant-text {
    overflow-wrap: anywhere;
}
.fm-assistant-text.is-streaming {
    white-space: pre-wrap;
}
.fm-assistant-text > :first-child {
    margin-top: 0;
}
.fm-assistant-text > :last-child {
    margin-bottom: 0;
}
.fm-assistant-text p,
.fm-assistant-text ul,
.fm-assistant-text ol {
    margin: 0 0 .625rem;
}
.fm-assistant-text ul,
.fm-assistant-text ol {
    padding-left: 1.25rem;
}
.fm-assistant-text h1,
.fm-assistant-text h2,
.fm-assistant-text h3,
.fm-assistant-text h4 {
    font-size: 1rem;
    font-weight: 600;
    margin: .875rem 0 .375rem;
}
.fm-assistant-text table {
    border-collapse: collapse;
    display: block;
    font-size: .875rem;
    font-variant-numeric: tabular-nums;
    margin: 0 0 .625rem;
    max-width: 100%;
    overflow-x: auto;
}
.fm-assistant-text th,
.fm-assistant-text td {
    border-bottom: 1px solid var(--tblr-border-color);
    padding: .3rem .5rem;
    text-align: left;
    vertical-align: top;
}
.fm-assistant-text th {
    color: var(--tblr-secondary);
    font-weight: 600;
    white-space: nowrap;
}
.fm-assistant-status {
    align-items: center;
    color: var(--tblr-secondary);
    display: flex;
    font-size: .875rem;
    gap: .5rem;
    margin-top: .25rem;
}
.fm-assistant-error {
    color: var(--fm-danger-strong);
    margin: .25rem 0 0;
}
.fm-assistant-compose {
    border-top: 1px solid var(--tblr-border-color);
    padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom, 0px));
}
.fm-assistant-compose form {
    align-items: flex-end;
    display: flex;
    gap: .5rem;
}
.fm-assistant-compose textarea {
    max-height: 10rem;
    min-width: 0;
    resize: vertical;
}
.fm-assistant-note {
    color: var(--tblr-secondary);
    font-size: .8125rem;
    margin: .375rem 0 0;
}
.fm-assistant-fab {
    align-items: center;
    background: var(--tblr-bg-surface);
    border: 1px solid var(--tblr-border-color);
    border-radius: 50%;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 .25rem 1rem rgba(15, 47, 74, .2);
    display: flex;
    font-size: 1.25rem;
    height: 3.25rem;
    justify-content: center;
    position: fixed;
    right: calc(1rem + env(safe-area-inset-right, 0px));
    width: 3.25rem;
    z-index: 1030;
}
@media print {
    .fm-assistant-fab {
        display: none !important;
    }
}
