/* =========================================================
   Herd Genetics — base theme
   "Field notebook": warm paper, deep pine, pasture green, wheat.
   Every page stylesheet draws its colours, fonts and radii
   from the tokens below. Original variable and class names
   are kept so existing templates and scripts keep working.
   ========================================================= */

/* Fonts (Source Sans 3 / Serif 4 / Code Pro) are loaded with <link> in base.html. */

:root {
    /* ---- Original names (used across templates & JS) ---- */
    --background-a: #f4f2ea;          /* paper */
    --background-b: #1d3328;          /* deep pine (nav, footer, headers) */
    --text-a: #1f2a24;
    --text-b: #f8f6ef;
    --shadow: rgba(29, 51, 40, 0.12);
    --outlines: #dcd7c8;
    --green: #287d45;                 /* pasture green: actions, selection (4.7:1 with --text-b) */
    --red: #c0453a;                   /* barn red: delete, missed */

    /* ---- Extended palette ---- */
    --surface: #fffdf7;               /* cards, inputs, tables */
    --muted: #5f6b63;
    --dark-soft: #2b4a3a;             /* hover on dark surfaces */
    --accent: #d4a53c;                /* wheat: decorative rules on dark */

    --green-dark: #22703d;
    --green-tint: #e7f2ea;
    --red-dark: #a03a30;
    --red-tint: #fbebe8;
    --gold: #b98a2a;                  /* pending / attention */
    --gold-dark: #85620f;
    --gold-tint: #fbf4e2;

    --light-grey: #eeebe1;
    --row-alt: #f8f6ef;
    --row-hover: var(--green-tint);
    --focus: rgba(46, 139, 78, 0.35);
    --dot: rgba(29, 51, 40, 0.07);    /* notebook dot grid on <body> */
    --neutral-strong: #5f6b63;        /* grey fill behind light text (in-progress dots) */

    /* Button hover backgrounds. Kept apart from --green-dark / --red-dark,
       which are text colours and get lighter in dark mode. */
    --green-hover: #1f6638;
    --red-hover: #a03a30;

    /* ---- Shape & motion ---- */
    --radius: 14px;
    --radius-small: 8px;
    --shadow-sm: 0 1px 2px rgba(29, 51, 40, 0.06), 0 3px 10px var(--shadow);
    --shadow-md: 0 6px 22px rgba(29, 51, 40, 0.16);
    --transition: 150ms ease;
    --content-width: 1200px;

    /* ---- Type ---- */
    --font-sans: "Source Sans 3", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --font-serif: "Source Serif 4", Charter, "Iowan Old Style", Georgia, "Times New Roman", serif;
    --font-mono: "Source Code Pro", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --font: var(--font-sans);

    color-scheme: light;
}

/* ---------- Dark mode ----------
   Only the tokens change; the dark pine nav, footer and table headers stay
   as they are. The theme follows the system setting until the visitor uses
   the nav toggle, which sets data-theme="light" | "dark" on <html>
   (see the inline script in base.html and js/theme.js).
   Keep the two token lists below identical. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --background-a: #111a15;          /* page */
        --text-a: #e4e6df;
        --shadow: rgba(0, 0, 0, 0.35);
        --outlines: #2f3e36;

        --surface: #18221d;               /* cards, inputs, tables */
        --muted: #9ba79f;

        --green-dark: #6cc48a;            /* green text, links */
        --green-tint: #1c3326;
        --red-dark: #f0958b;              /* error text */
        --red-tint: #3a2220;
        --gold: #c99a35;
        --gold-dark: #e2c172;             /* text on --gold-tint */
        --gold-tint: #2f2918;

        --light-grey: #232f29;
        --row-alt: #1c2722;
        --focus: rgba(79, 176, 113, 0.45);
        --dot: rgba(248, 246, 239, 0.045);
        --neutral-strong: #56635b;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 3px 10px var(--shadow);
        --shadow-md: 0 6px 22px rgba(0, 0, 0, 0.45);

        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --background-a: #111a15;          /* page */
    --text-a: #e4e6df;
    --shadow: rgba(0, 0, 0, 0.35);
    --outlines: #2f3e36;

    --surface: #18221d;               /* cards, inputs, tables */
    --muted: #9ba79f;

    --green-dark: #6cc48a;            /* green text, links */
    --green-tint: #1c3326;
    --red-dark: #f0958b;              /* error text */
    --red-tint: #3a2220;
    --gold: #c99a35;
    --gold-dark: #e2c172;             /* text on --gold-tint */
    --gold-tint: #2f2918;

    --light-grey: #232f29;
    --row-alt: #1c2722;
    --focus: rgba(79, 176, 113, 0.45);
    --dot: rgba(248, 246, 239, 0.045);
    --neutral-strong: #56635b;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 3px 10px var(--shadow);
    --shadow-md: 0 6px 22px rgba(0, 0, 0, 0.45);

    color-scheme: dark;
}

/* ---------- Reset-ish ---------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    background-color: var(--background-a);
    /* faint notebook dot grid */
    background-image: radial-gradient(var(--dot) 1px, transparent 1px);
    background-size: 22px 22px;
    color: var(--text-a);
    font-family: var(--font-sans);
    font-size: 1.0625rem;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;

    display: flex;
    min-height: 100dvh;
    flex-direction: column;
}

/* ---------- Headings ---------- */

h1,
h2,
h3,
h4 {
    font-family: var(--font-serif);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.01em;
    margin-block: 0.6em 0.4em;
    text-wrap: balance;
}

h1 {
    font-size: clamp(1.8rem, 1.3rem + 1.8vw, 2.5rem);
}

h2 {
    font-size: clamp(1.3rem, 1.15rem + 0.7vw, 1.6rem);
}

h3 {
    font-size: 1.2rem;
}

/* Signature motif: a short green rule under page titles.
   Set --title-rule-align: 0 on a container to left-align it. */
main h1::after {
    content: "";
    display: block;
    width: 56px;
    height: 3px;
    margin-top: 14px;
    margin-inline: var(--title-rule-align, auto);
    background-color: var(--green);
    border-radius: 2px;
}

p {
    margin-block: 0.5em;
}

img,
svg {
    max-width: 100%;
}

code,
pre,
kbd,
samp {
    font-family: var(--font-mono);
    font-size: 0.92em;
}

a {
    color: inherit;
}

::selection {
    background-color: var(--green);
    color: var(--text-b);
}

/* ---------- Navigation ---------- */

nav {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 6px 14px;
    min-height: 60px;
    padding: 8px 20px;
    border-bottom: 3px solid var(--accent);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

/* Logo + site name (also used in the footer).
   `a.brand` beats the later `.as-link { all: unset }`. */
a.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    font-family: var(--font-serif);
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    text-decoration: none;
}

.brand img {
    display: block;
    width: 28px;
    height: 28px;
}

nav .brand {
    padding: 6px 8px;
    border-radius: var(--radius-small);
    transition: background-color var(--transition);
}

nav .brand:hover {
    background-color: var(--dark-soft);
}

/* Breadcrumbs (links come from the path_builder template tags) */
nav .path {
    flex: 1;
    flex-wrap: wrap;
    align-items: center;
    min-width: 0;
    padding-left: 14px;
    font-size: 0.95rem;
    border-left: 1px solid var(--dark-soft);
}

nav .path:not(:has(a)) {
    display: none;
}

nav .path > a {
    max-width: 22ch;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    opacity: 0.8;
}

nav .path > a:last-child {
    opacity: 1;
    font-weight: 600;
}

nav a.as-link,
nav button.as-link {
    padding: 6px 8px !important;
    text-decoration: none;
    border-radius: var(--radius-small);
    transition: background-color var(--transition), opacity var(--transition);
}

nav a.as-link:hover,
nav button.as-link:hover {
    opacity: 1;
    background-color: var(--dark-soft);
}

nav .auth {
    align-items: center;
    margin-left: auto;
    font-size: 0.95rem;
}

nav .auth form {
    margin: 0;
    padding: 0 !important;
}

nav .nav-cta {
    padding: 7px 16px !important;
}

/* Light/dark toggle (js/theme.js). Shows the moon in light mode and the sun
   in dark mode, using the same conditions as the dark-mode tokens above.
   Hover changes colour only, never position. */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    color: inherit;
    cursor: pointer;
    background-color: transparent;
    border: 1px solid var(--dark-soft);
    border-radius: 50%;
    opacity: 0.85;
    transition: background-color var(--transition), opacity var(--transition);
}

.theme-toggle:hover {
    opacity: 1;
    background-color: var(--dark-soft);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

.theme-icon-sun {
    display: none;
}

:root[data-theme="dark"] .theme-icon-sun {
    display: block;
}

:root[data-theme="dark"] .theme-icon-moon {
    display: none;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-icon-sun {
        display: block;
    }

    :root:not([data-theme="light"]) .theme-icon-moon {
        display: none;
    }
}

@media (max-width: 700px) {
    nav {
        flex-wrap: wrap;
        justify-content: space-between;
        padding: 6px 12px;
    }

    nav .path {
        order: 3;
        flex-basis: 100%;
        padding: 4px 0 0;
        border-left: none;
        border-top: 1px solid var(--dark-soft);
    }

    nav .auth {
        gap: 2px;
    }
}

/* Phones: tighten the nav so brand, theme toggle and auth links share one row */
@media (max-width: 420px) {
    nav {
        column-gap: 8px;
    }

    nav a.brand {
        gap: 8px;
        font-size: 1.05rem;
    }

    nav .theme-toggle {
        width: 30px;
        height: 30px;
    }
}

/* ---------- Form controls ---------- */

input,
textarea,
select {
    padding: 8px 11px;
    font: inherit;
    font-size: 1em;
    color: var(--text-a);
    background-color: var(--surface);
    border: 1px solid var(--outlines);
    border-radius: var(--radius-small);
    transition: border-color var(--transition), box-shadow var(--transition);
}

input:hover,
textarea:hover,
select:hover {
    border-color: var(--muted);
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px var(--focus);
}

input[type="checkbox"],
input[type="radio"] {
    accent-color: var(--green);
    width: 1.1em;
    height: 1.1em;
    padding: 0;
}

input:disabled,
textarea:disabled,
select:disabled {
    background-color: var(--light-grey);
    color: var(--muted);
    cursor: not-allowed;
}

textarea {
    resize: vertical;
    line-height: 1.45;
}

select {
    cursor: pointer;
}

button {
    font: inherit;
}

fieldset {
    border: 1px solid var(--outlines);
    border-radius: var(--radius);
}

legend {
    padding: 0 8px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
}

summary {
    cursor: pointer;
    font-weight: 600;
}

table {
    border-collapse: collapse;
}

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

/* ---------- Layout ---------- */

main {
    margin-bottom: 40px;
}

footer {
    margin-top: auto;
    font-size: 0.93rem;
    border-top: 3px solid var(--accent);
}

.footer-inner {
    display: grid;
    grid-template-columns: minmax(240px, 2fr) repeat(3, minmax(150px, 1fr));
    gap: 28px 36px;
    width: min(var(--content-width), 100%);
    margin-inline: auto;
    padding: 40px 24px 28px;
}

.footer-about p {
    max-width: 38ch;
    margin: 12px 0 0;
    opacity: 0.78;
}

.footer-heading {
    margin: 4px 0 12px;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
}

.footer-links {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.footer-links li {
    opacity: 0.85;
    overflow-wrap: anywhere;
}

footer a.as-link {
    text-decoration: none;
    transition: color var(--transition);
}

footer a.as-link:hover {
    color: var(--accent);
    text-decoration: underline;
}

.footer-legal {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px 20px;
    width: min(var(--content-width), 100%);
    margin-inline: auto;
    padding: 16px 24px 22px;
    font-size: 0.85rem;
    border-top: 1px solid var(--dark-soft);
}

.footer-legal p {
    margin: 0;
    opacity: 0.7;
}

@media (max-width: 860px) {
    .footer-inner {
        grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
    }
}

/* ---------- Shared page pieces ---------- */

/* Short explanatory paragraph under a page title */
.page-lead {
    max-width: 62ch;
    margin: -6px auto 28px;
    padding-inline: 16px;
    text-align: center;
    font-size: 1.05rem;
    color: var(--muted);
}

/* Small uppercase label above a heading */
.eyebrow {
    margin: 0 0 6px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--green-dark);
}

/* Row of buttons that wraps on small screens */
.btn-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.btn-row .as-btn {
    padding: 10px 20px;
}

/* Friendly placeholder when a list has nothing in it yet */
.empty-state {
    max-width: 560px;
    margin: 10px auto 0;
    padding: 34px 28px;
    text-align: center;
    background-color: var(--surface);
    border: 2px dashed var(--outlines);
    border-radius: var(--radius);
}

.empty-state h3 {
    margin-top: 0;
}

.empty-state p {
    color: var(--muted);
}

.empty-state .btn-row {
    justify-content: center;
    margin-top: 18px;
}

/* Callout used for important notes in long-form pages */
.warning-note {
    padding: 12px 16px;
    background-color: var(--gold-tint);
    border-left: 4px solid var(--gold);
    border-radius: 0 var(--radius-small) var(--radius-small) 0;
}

/* ---------- Loading spinner ---------- */

loading-symbol {
    --border-width: 4px;
    --width: 32px;

    display: block;
    width: var(--width);
    height: var(--width);
    margin: 14px auto;
    border: var(--border-width) solid var(--outlines);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* ---------- Buttons & links ---------- */

.as-btn {
    all: unset;
    cursor: pointer;
    display: inline-block;
    box-sizing: border-box;
    text-align: center;
    font-weight: 600;
    border-radius: var(--radius-small);
    transition: background-color var(--transition), border-color var(--transition),
        box-shadow var(--transition), transform var(--transition);
}

.as-btn:hover {
    text-decoration: none;
    box-shadow: var(--shadow-sm);
}

.as-btn:active {
    transform: translateY(1px);
    box-shadow: none;
}

.as-btn:focus-visible {
    outline: 2px solid var(--green);
    outline-offset: 2px;
}

.background-green.as-btn:hover {
    background-color: var(--green-hover);
}

.background-red.as-btn:hover {
    background-color: var(--red-hover);
}

.background-a.as-btn:hover,
.background-light-grey.as-btn:hover {
    border-color: var(--green);
    background-color: var(--surface);
}

.as-link {
    all: unset;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

.as-link:hover {
    text-decoration: none;
}

.as-link:focus-visible {
    outline: 2px solid var(--green);
    outline-offset: 2px;
    border-radius: 3px;
}

/* ---------- Utility classes (original names) ---------- */

.pad {
    padding: 10px;
}

.gap {
    gap: 10px;
}

.pad-small {
    padding: 5px;
}

.background-a {
    background-color: var(--surface);
    color: var(--text-a);
    border: 1px solid var(--outlines);
}

.background-b {
    background-color: var(--background-b);
    color: var(--text-b);
}

.background-green {
    background-color: var(--green);
    color: var(--text-b);
}

.background-red {
    background-color: var(--red);
    color: var(--text-b);
}

.background-light-grey {
    background-color: var(--light-grey);
    color: var(--text-a);
    border: 1px solid var(--outlines);
}

.grid-auto-col {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: auto;
    grid-template-rows: 100%;
}

.grid-auto-row {
    display: grid;
    grid-auto-flow: row;
    grid-auto-rows: auto;
    grid-template-columns: 100%;
}

.center-text {
    text-align: center;
}

.display-inline {
    display: inline-block;
}

.flex {
    display: flex;
}

.flex-center {
    display: flex;
    justify-content: center;
    align-items: center;
}

.border-radius {
    border-radius: var(--radius);
}

.box-shadow {
    box-shadow: var(--shadow-sm);
}

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

.full-width {
    width: 100%;
    box-sizing: border-box;
}

.margin-auto {
    margin-inline: auto;
    width: fit-content;
}

.hide {
    display: none;
}

/* ---------- Toast messages ---------- */

.message {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 99;
    width: min(700px, calc(100% - 24px));
    margin: 12px auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    animation: message-in 200ms ease-out;
    overflow-wrap: break-word;
}

@keyframes message-in {
    from {
        opacity: 0;
        translate: 0 -10px;
    }

    to {
        opacity: 1;
        translate: 0 0;
    }
}

/* ---------- Motion preferences ---------- */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }

    loading-symbol {
        animation-duration: 1.5s !important;
    }
}
