/*
 * Farm Books theme: the one theme file (D-341).
 *
 * Every colour and type choice is made in the first block below, and
 * nowhere else: no template, and no other stylesheet, names a colour.
 * Rebranding changes that block alone. The rest of this file applies
 * those tokens to Bootstrap 5.3 (served from core/bootstrap/), to the
 * page patterns every screen shares, and to the Django admin.
 *
 * Palette from D-342; signal colours and Slate form-control borders from
 * D-345. Text pairs meet WCAG 2.1 AA (tests/core/test_theme.py
 * checks them). Harvest Gold is an accent only, never text on white.
 */

:root {
    /* Palette (D-342). Each colour's RGB form, which Bootstrap needs for
       links, sits beside it and must match it. */
    --fb-green: #2F5D50;            /* Field Green: header, primary buttons */
    --fb-green-rgb: 47, 93, 80;
    --fb-green-dark: #244A40;       /* hover */
    --fb-green-dark-rgb: 36, 74, 64;
    --fb-gold: #B8862B;             /* Harvest Gold: sparing accent, never text */
    --fb-off-white: #F7F5F0;        /* page background */
    --fb-white: #FFFFFF;            /* surfaces */
    --fb-charcoal: #1F2933;         /* text */
    --fb-charcoal-rgb: 31, 41, 51;
    --fb-slate: #52606D;            /* secondary text, form-control borders (D-345) */
    --fb-sand: #D9D4C7;             /* borders and rules */
    --fb-success: #1E6B3A;          /* signal colours (D-345): text on their own tint */
    --fb-success-bg: #E6F2EA;
    --fb-warning: #7A4B00;
    --fb-warning-bg: #FDF3DC;
    --fb-danger: #A12622;
    --fb-danger-rgb: 161, 38, 34;
    --fb-danger-bg: #FBE9E8;

    /* Type. System fonts: nothing is downloaded. */
    --fb-font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --fb-font-mono: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
    --fb-font-size: 1rem;
    --fb-font-size-small: 0.875rem;
    --fb-line-height: 1.5;
    --fb-heading-weight: 600;
    --fb-brand-weight: 700;
}


/* What each colour is for. Patterns below use these names. */

:root {
    --fb-page-bg: var(--fb-off-white);
    --fb-surface: var(--fb-white);
    --fb-text: var(--fb-charcoal);
    --fb-text-muted: var(--fb-slate);
    --fb-border: var(--fb-sand);
    --fb-control-border: var(--fb-slate);   /* 3:1 against white, for form controls (D-345) */
    --fb-primary: var(--fb-green);
    --fb-primary-hover: var(--fb-green-dark);
    --fb-on-primary: var(--fb-white);
    --fb-accent: var(--fb-gold);
    --fb-focus: var(--fb-green);
    --fb-focus-on-primary: var(--fb-off-white);
    --fb-radius: 0.375rem;
}


/* Bootstrap, pointed at the tokens */

:root,
[data-bs-theme=light] {
    --bs-body-font-family: var(--fb-font-sans);
    --bs-font-sans-serif: var(--fb-font-sans);
    --bs-font-monospace: var(--fb-font-mono);
    --bs-body-font-size: var(--fb-font-size);
    --bs-body-line-height: var(--fb-line-height);
    --bs-body-color: var(--fb-text);
    --bs-body-color-rgb: var(--fb-charcoal-rgb);
    --bs-body-bg: var(--fb-page-bg);
    --bs-emphasis-color: var(--fb-text);
    --bs-secondary-color: var(--fb-text-muted);
    --bs-tertiary-bg: var(--fb-page-bg);
    --bs-heading-color: var(--fb-text);
    --bs-border-color: var(--fb-border);
    --bs-border-radius: var(--fb-radius);
    --bs-primary: var(--fb-primary);
    --bs-primary-rgb: var(--fb-green-rgb);
    --bs-link-color: var(--fb-primary);
    --bs-link-color-rgb: var(--fb-green-rgb);
    --bs-link-hover-color: var(--fb-primary-hover);
    --bs-link-hover-color-rgb: var(--fb-green-dark-rgb);
    --bs-focus-ring-color: var(--fb-focus);
    --bs-primary-text-emphasis: var(--fb-primary-hover);
    --bs-primary-bg-subtle: var(--fb-page-bg);
    --bs-primary-border-subtle: var(--fb-border);
    --bs-info-text-emphasis: var(--fb-text);
    --bs-info-bg-subtle: var(--fb-page-bg);
    --bs-info-border-subtle: var(--fb-border);
    --bs-success-text-emphasis: var(--fb-success);
    --bs-success-bg-subtle: var(--fb-success-bg);
    --bs-success-border-subtle: var(--fb-success);
    --bs-warning-text-emphasis: var(--fb-warning);
    --bs-warning-bg-subtle: var(--fb-warning-bg);
    --bs-warning-border-subtle: var(--fb-warning);
    --bs-danger: var(--fb-danger);
    --bs-danger-rgb: var(--fb-danger-rgb);
    --bs-danger-text-emphasis: var(--fb-danger);
    --bs-danger-bg-subtle: var(--fb-danger-bg);
    --bs-danger-border-subtle: var(--fb-danger);
    --bs-form-invalid-color: var(--fb-danger);
    --bs-form-invalid-border-color: var(--fb-danger);
}

.fb .btn {
    --bs-btn-font-weight: var(--fb-heading-weight);
    --bs-btn-padding-x: 1rem;
    --bs-btn-padding-y: 0.5rem;
}

.fb .btn-primary {
    --bs-btn-color: var(--fb-on-primary);
    --bs-btn-bg: var(--fb-primary);
    --bs-btn-border-color: var(--fb-primary);
    --bs-btn-hover-color: var(--fb-on-primary);
    --bs-btn-hover-bg: var(--fb-primary-hover);
    --bs-btn-hover-border-color: var(--fb-primary-hover);
    --bs-btn-active-color: var(--fb-on-primary);
    --bs-btn-active-bg: var(--fb-primary-hover);
    --bs-btn-active-border-color: var(--fb-primary-hover);
    --bs-btn-disabled-color: var(--fb-on-primary);
    --bs-btn-disabled-bg: var(--fb-primary);
    --bs-btn-disabled-border-color: var(--fb-primary);
}

.fb .btn-outline-primary {
    --bs-btn-color: var(--fb-primary);
    --bs-btn-bg: var(--fb-surface);
    --bs-btn-border-color: var(--fb-primary);
    --bs-btn-hover-color: var(--fb-on-primary);
    --bs-btn-hover-bg: var(--fb-primary);
    --bs-btn-hover-border-color: var(--fb-primary);
    --bs-btn-active-color: var(--fb-on-primary);
    --bs-btn-active-bg: var(--fb-primary-hover);
    --bs-btn-active-border-color: var(--fb-primary-hover);
    --bs-btn-disabled-color: var(--fb-primary);
    --bs-btn-disabled-border-color: var(--fb-primary);
}

.fb .btn-outline-danger {
    --bs-btn-color: var(--fb-danger);
    --bs-btn-bg: var(--fb-surface);
    --bs-btn-border-color: var(--fb-danger);
    --bs-btn-hover-color: var(--fb-white);
    --bs-btn-hover-bg: var(--fb-danger);
    --bs-btn-hover-border-color: var(--fb-danger);
    --bs-btn-active-color: var(--fb-white);
    --bs-btn-active-bg: var(--fb-danger);
    --bs-btn-active-border-color: var(--fb-danger);
}

.fb .btn-link {
    --bs-btn-color: var(--fb-primary);
    --bs-btn-hover-color: var(--fb-primary-hover);
    --bs-btn-active-color: var(--fb-primary-hover);
    --bs-btn-font-weight: normal;
}

.fb .alert {
    --bs-alert-border-color: var(--fb-border);
    border-left-width: 0.3rem;
}

.fb .table {
    --bs-table-bg: var(--fb-surface);
    --bs-table-color: var(--fb-text);
    --bs-table-border-color: var(--fb-border);
    --bs-table-striped-bg: var(--fb-page-bg);
    --bs-table-hover-bg: var(--fb-page-bg);
    --bs-table-hover-color: var(--fb-text);
}

.fb .card {
    --bs-card-bg: var(--fb-surface);
    --bs-card-border-color: var(--fb-border);
    --bs-card-cap-bg: var(--fb-page-bg);
}


/* Focus: always visible, whatever the control (WCAG 2.4.7) */

:focus-visible {
    outline: 3px solid var(--fb-focus);
    outline-offset: 2px;
}

.fb .btn:focus-visible,
.fb .form-control:focus,
.fb .form-select:focus,
.fb .form-check-input:focus,
.fb :is(input, select, textarea, button):focus-visible {
    outline: 3px solid var(--fb-focus);
    outline-offset: 2px;
    box-shadow: none;
}

.fb-header :focus-visible,
.fb-header a:focus-visible {
    outline-color: var(--fb-focus-on-primary);
}


/* Page */

.fb {
    background: var(--fb-page-bg);
    color: var(--fb-text);
    font-family: var(--fb-font-sans);
}

.fb h1,
.fb h2,
.fb h3 {
    color: var(--fb-text);
    font-weight: var(--fb-heading-weight);
}

.fb h1 { font-size: 1.6rem; margin-bottom: 0.75rem; }
.fb h2 { font-size: 1.2rem; margin-top: 1.75rem; margin-bottom: 0.6rem; }

.fb small,
.fb .form-text {
    color: var(--fb-text-muted);
}

.fb-skip-link {
    position: absolute;
    left: 0.5rem;
    top: 0.5rem;
    z-index: 1000;
    padding: 0.5rem 1rem;
    background: var(--fb-surface);
    color: var(--fb-primary);
    border-radius: var(--fb-radius);
}

.fb-header {
    background: var(--fb-primary);
    color: var(--fb-on-primary);
    border-bottom: 4px solid var(--fb-accent);
}

.fb-header a {
    color: var(--fb-on-primary);
}

.fb-header-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem 1.5rem;
    padding-block: 0.6rem;
}

.fb-brand {
    font-size: 1.25rem;
    font-weight: var(--fb-brand-weight);
    letter-spacing: 0.01em;
    text-decoration: none;
}

.fb-brand:hover {
    text-decoration: underline;
}

.fb-account {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 1rem;
    font-size: var(--fb-font-size-small);
}

.fb-nav {
    background: var(--fb-surface);
    border-bottom: 1px solid var(--fb-border);
}

.fb-nav ul {
    display: flex;
    flex-wrap: wrap;
    margin: 0;
    padding: 0;
    list-style: none;
}

.fb-nav a {
    display: block;
    padding: 0.7rem 0.8rem;
    color: var(--fb-text);
    text-decoration: none;
    border-bottom: 3px solid transparent;
}

.fb-nav a:hover {
    color: var(--fb-primary);
    border-bottom-color: var(--fb-border);
}

.fb-nav a[aria-current=page] {
    color: var(--fb-primary);
    font-weight: var(--fb-heading-weight);
    border-bottom-color: var(--fb-primary);
}

.fb-main {
    padding-block: 1.5rem 3rem;
}

.fb-lead {
    color: var(--fb-text-muted);
    max-width: 52rem;
}

/* Sign-in and the other pages before signing in: one narrow card */
.fb-entrance {
    max-width: 30rem;
    margin: 1.5rem auto;
    padding: 1.75rem;
    background: var(--fb-surface);
    border: 1px solid var(--fb-border);
    border-radius: 0.5rem;
}

.fb-section {
    background: var(--fb-surface);
    border: 1px solid var(--fb-border);
    border-radius: 0.5rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
}

.fb-section > :last-child {
    margin-bottom: 0;
}

.fb-section > h2:first-child {
    margin-top: 0;
}


/* Form controls Django draws without classes look like Bootstrap's */

.fb :is(input:not([type=checkbox], [type=radio], [type=hidden], [type=submit], [type=button], [type=reset], [type=file]), select, textarea) {
    max-width: 100%;
    min-height: 2.4rem;
    padding: 0.35rem 0.6rem;
    font: inherit;
    color: var(--fb-text);
    background-color: var(--fb-surface);
    border: 1px solid var(--fb-control-border);
    border-radius: var(--fb-radius);
}

.fb :is(input, select, textarea):disabled,
.fb :is(input, textarea)[readonly] {
    background-color: var(--fb-page-bg);
}

.fb :is(input, textarea)::placeholder {
    color: var(--fb-text-muted);
    opacity: 1;
}

.fb input[type=checkbox],
.fb input[type=radio] {
    width: 1.15rem;
    height: 1.15rem;
    vertical-align: -0.2rem;
    accent-color: var(--fb-primary);
}

.fb label {
    font-weight: 500;
}

.fb-field {
    margin-bottom: 1rem;
}

.fb-field > label {
    display: block;
    margin-bottom: 0.3rem;
}

.fb-field :is(input:not([type=checkbox], [type=radio]), select, textarea) {
    width: 100%;
}

.fb-field-check > label {
    display: inline;
    margin-left: 0.4rem;
}

.fb-field .form-text ul {
    margin: 0.25rem 0 0;
    padding-left: 1.1rem;
}

/* Filter forms on lists and reports: fields side by side */
.fb-filter {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem 1rem;
    margin: 0;
}

.fb-filter > span {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Errors beside their field, and the page's own list of problems */
.fb .errorlist,
.fb .errors {
    color: var(--fb-danger);
    font-weight: 500;
}

.fb .errorlist {
    margin: 0.25rem 0 0;
    padding: 0;
    list-style: none;
    font-size: var(--fb-font-size-small);
}

.fb ul.errors,
.fb div.errors:not(:empty) {
    margin: 0.25rem 0;
}

.fb ul.errors[role=alert],
.fb .fb-problems {
    padding: 0.75rem 1rem 0.75rem 2rem;
    background: var(--fb-danger-bg);
    border-left: 0.3rem solid var(--fb-danger);
    border-radius: var(--fb-radius);
}

.fb .warnings {
    padding: 0.75rem 1rem;
    margin: 0.75rem 0;
    color: var(--fb-text);
    background: var(--fb-warning-bg);
    border: 1px solid var(--fb-warning);
    border-left-width: 0.3rem;
    border-radius: var(--fb-radius);
}

.fb .warnings > :last-child {
    margin-bottom: 0;
}


/* Buttons Django and allauth draw without classes */

.fb button:not(.btn) {
    padding: 0.4rem 0.9rem;
    font: inherit;
    font-weight: var(--fb-heading-weight);
    color: var(--fb-primary);
    background: var(--fb-surface);
    border: 1px solid var(--fb-primary);
    border-radius: var(--fb-radius);
    cursor: pointer;
}

.fb button:not(.btn):hover {
    color: var(--fb-on-primary);
    background: var(--fb-primary);
}

/* The one large, obvious action of a screen, such as Save */
.fb .fb-primary-action > :is(button, a) {
    display: inline-block;
    min-width: 9rem;
    padding: 0.6rem 1.75rem;
    font-size: 1.1rem;
    font-weight: var(--fb-heading-weight);
    text-align: center;
    text-decoration: none;
    color: var(--fb-on-primary);
    background: var(--fb-primary);
    border: 1px solid var(--fb-primary);
    border-radius: var(--fb-radius);
}

.fb .fb-primary-action > :is(button, a):hover {
    color: var(--fb-on-primary);
    background: var(--fb-primary-hover);
}

.fb .fb-primary-action > button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.fb .fb-primary-action > button:disabled:hover {
    background: var(--fb-primary);
}


/* Tables: money right-aligned, totals set apart */

.fb .table {
    margin-bottom: 0.75rem;
}

.fb .table > thead th {
    color: var(--fb-text-muted);
    font-size: var(--fb-font-size-small);
    font-weight: var(--fb-heading-weight);
    vertical-align: bottom;
    background: var(--fb-page-bg);
    border-bottom: 2px solid var(--fb-border);
}

.fb .table td,
.fb .table th {
    vertical-align: top;
}

.fb .amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.fb .amount input {
    text-align: right;
}

.fb tr.total > td {
    font-weight: var(--fb-brand-weight);
    border-top: 2px solid var(--fb-text);
    background: var(--fb-page-bg);
}

.fb .fb-record th {
    width: 14rem;
    color: var(--fb-text-muted);
    font-weight: 500;
}

.fb-table-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    margin-bottom: 0.5rem;
}

.fb-pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
}


/* Entry screens */

.fb-entry-header {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
    gap: 0.75rem 1rem;
}

.fb-entry-header > div > label {
    display: block;
    margin-bottom: 0.25rem;
}

.fb-entry-header :is(input:not([type=checkbox], [type=radio]), select) {
    width: 100%;
}

.fb-entry-header .fb-wide {
    grid-column: span 2;
}

/* The vendor field's list of matches (D-346) */
.fb-combobox {
    position: relative;
}

.fb-combobox-list {
    position: absolute;
    z-index: 1000;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 16rem;
    overflow-y: auto;
    margin: 0.125rem 0 0;
    padding: 0.25rem 0;
    list-style: none;
    background: var(--fb-surface);
    color: var(--fb-text);
    border: 1px solid var(--fb-control-border);
    border-radius: var(--fb-radius);
}

.fb-combobox-list [role=option] {
    padding: 0.25rem 0.75rem;
    cursor: pointer;
}

.fb-combobox-list [role=option]:hover {
    background: var(--fb-page-bg);
}

.fb-combobox-list [role=option][aria-selected=true] {
    background: var(--fb-primary);
    color: var(--fb-on-primary);
}

.fb-lines :is(select, input) {
    width: 100%;
    min-width: 7rem;
}

.fb-lines .amount input {
    min-width: 7.5rem;
}

.fb fieldset {
    margin: 1rem 0;
    padding: 0.75rem 1rem;
    background: var(--fb-surface);
    border: 1px solid var(--fb-accent);
    border-radius: var(--fb-radius);
}

.fb legend {
    float: none;
    width: auto;
    padding: 0 0.4rem;
    font-size: 1rem;
    font-weight: var(--fb-heading-weight);
}

/* The remainder and Save, kept in view at the foot of the screen */
.fb-action-bar {
    position: sticky;
    bottom: 0;
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1.5rem;
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: var(--fb-surface);
    border: 1px solid var(--fb-border);
    border-top: 3px solid var(--fb-primary);
    border-radius: var(--fb-radius);
}

.fb-action-bar p {
    margin: 0;
}

.fb-remainder output {
    font-size: 1.25rem;
    font-weight: var(--fb-brand-weight);
    font-variant-numeric: tabular-nums;
}

.fb-remainder.is-unbalanced output {
    color: var(--fb-danger);
}

.fb-remainder.is-balanced output {
    color: var(--fb-success);
}


/* Home */

.fb-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 1rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.fb-tiles a {
    display: block;
    height: 100%;
    padding: 1rem 1.25rem;
    color: var(--fb-text);
    text-decoration: none;
    background: var(--fb-surface);
    border: 1px solid var(--fb-border);
    border-radius: 0.5rem;
}

.fb-tiles a:hover {
    border-color: var(--fb-primary);
}

.fb-tiles strong {
    display: block;
    margin-bottom: 0.2rem;
    color: var(--fb-primary);
    font-size: 1.05rem;
}

.fb-tiles span {
    color: var(--fb-text-muted);
    font-size: var(--fb-font-size-small);
}

.fb-badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    margin-left: 0.25rem;
    color: var(--fb-warning);
    font-size: var(--fb-font-size-small);
    font-weight: var(--fb-heading-weight);
    background: var(--fb-warning-bg);
    border: 1px solid var(--fb-warning);
    border-radius: 1rem;
}


/* The two-factor set-up QR code */

.fb-qr {
    display: block;
    width: 12rem;
    height: 12rem;
    margin: 0.5rem 0 1rem;
    padding: 0.5rem;
    background: var(--fb-white);
    border: 1px solid var(--fb-border);
}


/* Phone-sized screens */

@media (max-width: 575.98px) {
    .fb h1 { font-size: 1.35rem; }
    .fb-entrance { margin: 0.75rem 0; padding: 1.25rem; }
    .fb-entry-header .fb-wide { grid-column: auto; }
    .fb .fb-record th { width: auto; }
    .fb-nav a { padding: 0.55rem 0.6rem; }
}


/* Django admin: a light matching theme (D-341). The admin's own dark
   mode is switched off in config/templates/admin/base.html. */

:root,
html[data-theme="light"] {
    --primary: var(--fb-green);
    --secondary: var(--fb-green-dark);
    --accent: var(--fb-gold);
    --primary-fg: var(--fb-white);
    --body-fg: var(--fb-charcoal);
    --body-bg: var(--fb-white);
    --body-quiet-color: var(--fb-slate);
    --body-medium-color: var(--fb-charcoal);
    --body-loud-color: var(--fb-charcoal);
    --header-color: var(--fb-white);
    --header-branding-color: var(--fb-white);
    --header-bg: var(--fb-green);
    --header-link-color: var(--fb-white);
    --breadcrumbs-fg: var(--fb-white);
    --breadcrumbs-link-fg: var(--fb-white);
    --breadcrumbs-bg: var(--fb-green-dark);
    --link-fg: var(--fb-green);
    --link-hover-color: var(--fb-green-dark);
    --link-selected-fg: var(--fb-green-dark);
    --hairline-color: var(--fb-sand);
    --border-color: var(--fb-sand);
    --error-fg: var(--fb-danger);
    --message-success-bg: var(--fb-success-bg);
    --message-warning-bg: var(--fb-warning-bg);
    --message-error-bg: var(--fb-danger-bg);
    --darkened-bg: var(--fb-off-white);
    --selected-bg: var(--fb-sand);
    --selected-row: var(--fb-warning-bg);
    --button-fg: var(--fb-white);
    --button-bg: var(--fb-green);
    --button-hover-bg: var(--fb-green-dark);
    --default-button-bg: var(--fb-green-dark);
    --default-button-hover-bg: var(--fb-green);
    --close-button-bg: var(--fb-slate);
    --close-button-hover-bg: var(--fb-charcoal);
    --delete-button-bg: var(--fb-danger);
    --delete-button-hover-bg: var(--fb-charcoal);
    --object-tools-fg: var(--fb-white);
    --object-tools-bg: var(--fb-slate);
    --object-tools-hover-bg: var(--fb-charcoal);
    --font-family-primary: var(--fb-font-sans);
    --font-family-monospace: var(--fb-font-mono);
}

#header {
    border-bottom: 4px solid var(--fb-accent);
}

/* The admin draws its name in its accent colour; gold is never text. */
#site-name a:link,
#site-name a:visited {
    color: var(--fb-on-primary);
}
