/* ==========================================================================
   PMS Design System — mobile first
   Single source of truth for tokens and shared components.
   Loaded by every layout (admin, auth, public) before any layout stylesheet.

   Breakpoints (em, so they respect the user's font-size zoom):
     40em   640px   small tablet / large phone landscape
     48em   768px   tablet portrait
     64em  1024px   tablet landscape / small laptop
     80em  1280px   laptop
     96em  1536px   desktop
    120em  1920px   large desktop
    160em  2560px   ultrawide

   Base styles target 320px. Every media query is min-width: layout only ever
   gains complexity as space allows, never fights a desktop default.
   ========================================================================== */

/* --- Tokens ------------------------------------------------------------- */
:root {
    /* Brand */
    --navy-900: #0d1b30;
    --navy-800: #10213d;
    --navy-700: #1b3157;
    --brand-gold: #d6a648;

    --primary-700: #1c4bb8;
    --primary-600: #2560db;
    --primary-500: #3b7bf5;
    --primary-100: #e3edfe;
    --primary-50: #f2f7ff;

    --teal-700: #0a6f62;
    --teal-600: #0d8b78;
    --teal-100: #dcf5ee;

    /* Neutrals */
    --n-0: #ffffff;
    --n-25: #fbfcfe;
    --n-50: #f6f8fb;
    --n-100: #eef1f6;
    --n-200: #e2e7ef;
    --n-300: #cbd3e0;
    --n-400: #97a3b6;
    --n-500: #6b7890;
    --n-600: #4d5a72;
    --n-700: #364256;

    /* Semantic. Contrast against --surface verified at AA or better:
       text 14.6:1, text-muted 4.9:1, primary 5.6:1, danger 6.4:1, success 5.4:1. */
    --canvas: var(--n-50);
    --surface: var(--n-0);
    --surface-sunken: var(--n-25);
    --border: var(--n-200);
    --border-strong: var(--n-300);
    --text: #162032;
    --text-muted: var(--n-500);
    --text-subtle: var(--n-400);

    --primary: var(--primary-600);
    --primary-hover: var(--primary-700);
    --primary-soft: var(--primary-100);
    --on-primary: #ffffff;

    --success: #0b6b52;
    --success-soft: #d8f5e9;
    --warning: #7a5000;
    --warning-soft: #fdf0d0;
    --danger: #a5231b;
    --danger-soft: #fdeceb;
    --info: var(--primary-700);
    --info-soft: var(--primary-100);

    /* Type. Fluid between 320px and 1920px, then held steady so an ultrawide
       monitor does not turn body copy into headlines. */
    --font: "Inter var", Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-base: clamp(0.9375rem, 0.92rem + 0.08vw, 1rem);
    --text-md: clamp(1rem, 0.97rem + 0.1vw, 1.0625rem);
    --text-lg: clamp(1.0625rem, 1.02rem + 0.18vw, 1.1875rem);
    --text-xl: clamp(1.25rem, 1.18rem + 0.3vw, 1.5rem);
    --text-2xl: clamp(1.5rem, 1.36rem + 0.55vw, 1.875rem);
    --text-3xl: clamp(1.875rem, 1.68rem + 0.8vw, 2.5rem);

    /* Spacing: 4px base */
    --sp-1: 0.25rem;
    --sp-2: 0.5rem;
    --sp-3: 0.75rem;
    --sp-4: 1rem;
    --sp-5: 1.25rem;
    --sp-6: 1.5rem;
    --sp-8: 2rem;
    --sp-10: 2.5rem;
    --sp-12: 3rem;
    --sp-16: 4rem;

    /* Fluid gutter: 16px on a 320px phone, 32px from tablet up. */
    --gutter: clamp(1rem, 0.6rem + 2vw, 2rem);
    /* Fluid vertical rhythm for public page sections. */
    --section-gap: clamp(3rem, 1.5rem + 7vw, 6rem);

    --radius-sm: 6px;
    --radius: 8px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-full: 999px;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.07), 0 2px 4px rgba(16, 24, 40, 0.04);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);

    --ring: 0 0 0 3px rgba(59, 123, 245, 0.3);
    --transition: 140ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Minimum hit area. WCAG 2.5.5 asks for 44x44 on touch; relaxed to a
       denser 36px only where the pointer is precise and the screen is large. */
    --tap: 44px;

    --content-max: 75rem;   /* 1200px — comfortable on a 1280px laptop */
}

/* The shell tracks the screen rather than stranding content in a narrow ribbon
   between two dead margins. Margins stay proportional (~5-6% a side) instead of
   growing without limit. Prose blocks (.site-article) are capped separately at
   ~48rem, because line length drives readability, not available width. */
@media (min-width: 80em)  { :root { --content-max: 80rem; } }   /* 1280px */
@media (min-width: 90em)  { :root { --content-max: 90rem; } }   /* 1440px */
@media (min-width: 120em) { :root { --content-max: 112rem; } }  /* 1920px */
@media (min-width: 160em) { :root { --content-max: 140rem; } }  /* 2560px */
@media (min-width: 200em) { :root { --content-max: 165rem; } }  /* 3200px */

@media (min-width: 64em) and (pointer: fine) {
    :root { --tap: 36px; }
}

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

html {
    -webkit-text-size-adjust: 100%;
    /* The sticky form action bar floats over content that precedes it, so any
       scroll-into-view must stop short of it or the control lands underneath
       and clicks hit the bar instead. */
    scroll-padding-bottom: 7rem;
    /* `clip`, never `hidden`: overflow-x:hidden turns the root into a scroll
       container, which silently disables `position: sticky` on the sidebar and
       table headers. `clip` prevents sideways scrolling without that side
       effect. */
    overflow-x: clip;
}

body {
    margin: 0;
    background: var(--canvas);
    color: var(--text);
    font-family: var(--font);
    font-size: var(--text-base);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    overflow-x: clip;
}

h1, h2, h3, h4 {
    margin: 0;
    line-height: 1.2;
    letter-spacing: -0.018em;
    font-weight: 640;
    /* Long unbroken words (URLs, slugs) must not push the layout wide. */
    overflow-wrap: break-word;
}
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-md); }
p { margin: 0; overflow-wrap: break-word; }

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

/* Any component rule that sets `display` outranks the UA's [hidden] rule, so
   JS toggling `.hidden` silently stops working. Make [hidden] authoritative. */
[hidden] { display: none !important; }

code, kbd {
    font-family: var(--font-mono);
    font-size: 0.9em;
    overflow-wrap: break-word;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* --- Focus + skip link -------------------------------------------------- */
:focus-visible {
    outline: 2px solid var(--primary-500);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible { outline: none; }

.skip-link {
    position: fixed;
    top: -100px;
    left: var(--sp-3);
    z-index: 200;
    padding: var(--sp-3) var(--sp-4);
    background: var(--navy-800);
    color: #fff;
    border-radius: var(--radius);
    text-decoration: none;
    font-weight: 600;
    transition: top var(--transition);
}
.skip-link:focus { top: var(--sp-3); }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* --- Icons -------------------------------------------------------------- */
.icon {
    width: 1.125em;
    height: 1.125em;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: -0.18em;
}
.icon-lg { width: 1.5em; height: 1.5em; }

/* --- Buttons ------------------------------------------------------------ */
.button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    min-height: var(--tap);
    padding: var(--sp-2) var(--sp-4);
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--primary);
    color: var(--on-primary);
    font: inherit;
    font-weight: 600;
    line-height: 1.25;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}
.button:hover,
.btn:hover { background: var(--primary-hover); }

.button.secondary,
.btn-secondary {
    background: var(--surface);
    border-color: var(--border-strong);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}
.button.secondary:hover,
.btn-secondary:hover { background: var(--n-50); border-color: var(--n-400); }

.btn-ghost { background: transparent; color: var(--text-muted); box-shadow: none; }
.btn-ghost:hover { background: var(--n-100); color: var(--text); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #86160f; }

/* Small only in density, never in hit area. */
.btn-sm { padding: var(--sp-1) var(--sp-3); font-size: var(--text-sm); }
.btn-block { width: 100%; }

.button[disabled],
.btn[disabled],
.button[aria-busy="true"],
.btn[aria-busy="true"] { opacity: 0.6; pointer-events: none; }

/* Inline links inside prose keep their natural size — WCAG 2.5.8 exempts
   them — but standalone ones get a real hit area. */
.text-link {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
    border-radius: var(--radius-sm);
}
.text-link:hover { text-decoration: underline; }
/* Standalone links in table cells and headers are controls, not prose, so they
   get a real hit area. Links inside a sentence are exempt (WCAG 2.5.8). */
td .text-link,
.panel-header .text-link {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    overflow-wrap: anywhere;
}
.table-actions .text-link { padding-inline: var(--sp-2); }

.icon-button {
    display: inline-grid;
    place-items: center;
    width: var(--tap);
    height: var(--tap);
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}

/* --- Cards / panels ----------------------------------------------------- */
.panel,
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.panel {
    padding: var(--sp-4);
    margin-bottom: var(--sp-4);
}
.panel:last-child { margin-bottom: 0; }

.panel-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-3);
    margin-bottom: var(--sp-4);
}
.panel-header h2 { font-size: var(--text-lg); }
.panel-header p { color: var(--text-muted); font-size: var(--text-sm); margin-top: var(--sp-1); }
.panel-header-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.panel-header-actions > * { flex: 1 1 auto; }

.panel-flush { padding: 0; overflow: hidden; }
.panel-flush > .panel-header { padding: var(--sp-4) var(--sp-4) var(--sp-3); margin-bottom: 0; }
.panel-pad { padding: 0 var(--sp-4) var(--sp-4); }

.eyebrow {
    margin: 0;
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

@media (min-width: 48em) {
    .panel { padding: var(--sp-6); margin-bottom: var(--sp-6); }
    .panel-header {
        flex-direction: row;
        align-items: flex-start;
        justify-content: space-between;
        gap: var(--sp-4);
        margin-bottom: var(--sp-5);
    }
    .panel-header-actions { flex: none; }
    .panel-header-actions > * { flex: none; }
    .panel-flush > .panel-header { padding: var(--sp-6) var(--sp-6) var(--sp-4); }
    .panel-pad { padding: 0 var(--sp-6) var(--sp-6); }
}

/* --- Stats -------------------------------------------------------------- */
.metrics,
.stat-grid {
    display: grid;
    /* minmax with a floor small enough for 320px, so cards reflow rather
       than overflow. */
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
    gap: var(--sp-3);
    margin-bottom: var(--sp-4);
}
.metric,
.stat {
    display: block;
    padding: var(--sp-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    color: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
}
a.metric:hover,
a.stat:hover { border-color: var(--primary-500); box-shadow: var(--shadow-md); }

.metric span,
.stat-label {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-weight: 600;
}
.metric strong,
.stat-value {
    display: block;
    margin: var(--sp-2) 0 var(--sp-1);
    font-size: var(--text-3xl);
    font-weight: 660;
    letter-spacing: -0.04em;
    line-height: 1;
}
.metric small,
.stat-hint { display: block; color: var(--text-subtle); font-size: var(--text-sm); }

@media (min-width: 48em) {
    .metrics, .stat-grid { gap: var(--sp-4); margin-bottom: var(--sp-6); }
    .metric, .stat { padding: var(--sp-5); }
}

/* --- Tables ------------------------------------------------------------- */
.table-toolbar {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    flex-wrap: wrap;
    padding: 0 var(--sp-4) var(--sp-3);
    border-bottom: 1px solid var(--border);
}
.table-search { position: relative; flex: 1 1 12rem; min-width: 0; }
.table-search .icon {
    position: absolute;
    left: var(--sp-3);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-subtle);
    pointer-events: none;
}
.table-search input { padding-left: 2.25rem; }
.table-count { color: var(--text-muted); font-size: var(--text-sm); white-space: nowrap; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; text-align: left; }

th {
    padding: var(--sp-3) var(--sp-4);
    background: var(--n-50);
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}
td { padding: var(--sp-4); border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--primary-50); }
tbody tr:last-child td { border-bottom: 0; }
td small { display: block; color: var(--text-muted); margin-top: var(--sp-1); }
td code { color: var(--text-muted); font-size: var(--text-xs); }

th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--text); background: var(--n-100); }
th[data-sort]::after { content: "↕"; display: inline-block; margin-left: var(--sp-2); opacity: 0.35; }
th[aria-sort="ascending"]::after { content: "↑"; opacity: 1; }
th[aria-sort="descending"]::after { content: "↓"; opacity: 1; }

.table-actions {
    display: flex;
    align-items: center;
    gap: var(--sp-1);
    flex-wrap: wrap;
}
.table-actions form { margin: 0; display: inline-flex; }
.table-actions .icon-button { color: var(--text-muted); }
.table-actions .icon-button:hover { color: var(--text); background: var(--n-100); }
.table-actions .icon-button.danger:hover { color: var(--danger); background: var(--danger-soft); }

.table-no-results { padding: var(--sp-8); text-align: center; color: var(--text-muted); font-size: var(--text-sm); }

/* Phones: a table becomes a stack of labelled cards. No sideways scrolling. */
.table-stack thead { display: none; }
.table-stack tbody tr {
    display: grid;
    gap: var(--sp-2);
    padding: var(--sp-4);
    border-bottom: 1px solid var(--border);
}
.table-stack tbody td {
    display: grid;
    grid-template-columns: minmax(6rem, auto) 1fr;
    align-items: baseline;
    gap: var(--sp-3);
    padding: 0;
    border: 0;
    min-width: 0;
}
.table-stack tbody td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
/* Everything the cell contains belongs in the value column, stacked.
   Without this, auto-placement puts the label in column 1, the first child in
   column 2, and the *second* child back in column 1 -- whose `auto` track then
   grows to fit it and squeezes column 1fr down to nothing. A cell holding a
   link and a title rendered the link ten pixels wide and a hundred and
   eighty-six tall, one character per line. */
.table-stack tbody td > * { grid-column: 2; min-width: 0; }
.table-stack tbody td.table-actions { display: flex; padding-top: var(--sp-2); }
.table-stack tbody td.table-actions::before { content: none; }

@media (min-width: 64em) {
    /* Real table from tablet-landscape up, with a header that stays put. */
    .table-stack thead { display: table-header-group; }
    .table-stack tbody tr { display: table-row; padding: 0; }
    .table-stack tbody td { display: table-cell; padding: var(--sp-4); border-bottom: 1px solid var(--border); }
    .table-stack tbody td::before { content: none; }

    /* A <td> must stay `table-cell`: `display:flex` drops it out of table
       layout and the row's baseline and bottom border stop lining up.
       Right-align inline instead of reaching for flex. */
    .table-stack tbody td.table-actions {
        display: table-cell;
        text-align: right;
        white-space: nowrap;
    }
    .table-stack tbody td.table-actions > * { vertical-align: middle; }
    .table-stack tbody td.table-actions > * + * { margin-left: var(--sp-1); }
    .table-stack tbody td.table-actions .status-form { display: inline-flex; }

    .table-wrap { max-height: 70vh; overflow-y: auto; }
    th { position: sticky; top: 0; z-index: 1; }
    .table-toolbar { padding: 0 var(--sp-6) var(--sp-4); }
    .table-search { flex: 1 1 14rem; max-width: 21rem; }
    .table-count { margin-left: auto; }
}

/* --- Badges ------------------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    padding: 0.1875rem var(--sp-2);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 650;
    line-height: 1.4;
    white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.published, .badge.accepted, .badge-success { background: var(--success-soft); color: var(--success); }
.badge.draft, .badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge.new, .badge.sent, .badge-info { background: var(--info-soft); color: var(--info); }
.badge.resolved, .badge-neutral { background: var(--n-100); color: var(--n-600); }
.badge.rejected, .badge-danger { background: var(--danger-soft); color: var(--danger); }

/* --- Alerts ------------------------------------------------------------- */
.alert,
.notice,
.form-error {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: var(--text-base);
    margin-bottom: var(--sp-4);
}
.alert .icon { margin-top: 0.15em; }
.alert > span:not(.alert-icon) { min-width: 0; }

/* Status banners clear themselves after a few seconds; this is the fade out.
   Collapsing the box as well as fading it stops the page jumping when it goes. */
.alert.is-leaving {
    opacity: 0;
    transform: translateY(-0.25rem);
    margin-block: 0;
    padding-block: 0;
    max-height: 0;
    overflow: hidden;
    border-width: 0;
    transition: opacity 0.25s ease, transform 0.25s ease,
                max-height 0.3s ease, padding 0.3s ease, margin 0.3s ease;
}

@media (prefers-reduced-motion: reduce) {
    .alert.is-leaving { transition: none; }
}
.notice, .alert-success { background: var(--success-soft); border-color: #a9e6cd; color: var(--success); }
.alert-info { background: var(--info-soft); border-color: #bcd6fb; color: var(--info); }
.alert-warning { background: var(--warning-soft); border-color: #f2d99a; color: var(--warning); }
.form-error, .auth-error, .alert-danger { background: var(--danger-soft); border-color: #f5c2be; color: var(--danger); }
.alert-dismiss {
    display: grid;
    place-items: center;
    width: var(--tap);
    height: var(--tap);
    margin: calc(var(--sp-2) * -1) calc(var(--sp-2) * -1) 0 auto;
    background: none;
    border: 0;
    color: inherit;
    opacity: 0.6;
    cursor: pointer;
    font: inherit;
    font-size: var(--text-lg);
}
.alert-dismiss:hover { opacity: 1; }

/* --- Empty states ------------------------------------------------------- */
.empty-state,
.empty {
    display: grid;
    justify-items: center;
    gap: var(--sp-2);
    padding: var(--sp-8) var(--sp-4);
    text-align: center;
    color: var(--text-muted);
    background: var(--surface-sunken);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
}
.empty-icon {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin-bottom: var(--sp-2);
    border-radius: var(--radius-md);
    background: var(--primary-soft);
    color: var(--primary);
}
.empty h3 { color: var(--text); }
.empty p { max-width: 42ch; font-size: var(--text-sm); }
.empty .button { margin-top: var(--sp-3); }

@media (min-width: 48em) {
    .empty-state, .empty { padding: var(--sp-12) var(--sp-6); }
}

/* --- Forms -------------------------------------------------------------- */
/* Centred, not left-aligned: a capped panel pinned to the left dumps every
   pixel of slack on the right, which reads as a broken layout rather than a
   deliberate margin. Widening in step with the shell lets .field-row spread
   into two or three columns instead of leaving the space empty. */
.form-panel { max-width: 48rem; margin-inline: auto; }
@media (min-width: 80em)  { .form-panel { max-width: 58rem; } }
@media (min-width: 120em) { .form-panel { max-width: 68rem; } }

.form-panel form,
.form-stack { display: grid; gap: var(--sp-5); }

/* `align-content: start` stops the rows inside a field from stretching to match
   a taller sibling in the same .field-row, which was pushing inputs in adjacent
   columns to different heights. */
.field {
    display: grid;
    gap: var(--sp-2);
    min-width: 0;
    align-content: start;
}

/* Flex, not grid: a grid label puts the required asterisk on its own line. */
.field-label,
.form-panel > label,
.form-panel .field > label,
.fieldset > .field > label,
.auth-form label,
.contact-form .field > label {
    display: flex;
    align-items: baseline;
    gap: var(--sp-2);
    flex-wrap: wrap;
    font-size: var(--text-sm);
    font-weight: 620;
    color: var(--text);
}
.field-required { color: var(--danger); font-weight: 700; line-height: 1; }
.field-hint,
.form-panel small,
.field small { color: var(--text-muted); font-size: var(--text-sm); font-weight: 400; }
.field-error-text {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-2);
    color: var(--danger);
    font-size: var(--text-sm);
    font-weight: 600;
}
.field-error-text .icon { flex: none; margin-top: 0.15em; }

.form-error-summary { align-items: flex-start; }
.form-error-summary ul { margin: var(--sp-2) 0 0; padding-left: var(--sp-5); }
.form-error-summary li { margin-top: var(--sp-1); font-weight: 500; }
.form-error-summary a { color: inherit; }

.is-near-limit { color: var(--danger); font-weight: 700; }

.input,
.select,
.textarea,
.form-panel input,
.form-panel select,
.form-panel textarea,
.auth-form input,
.contact-form input,
.contact-form textarea,
.site-search input,
.floating-search-form input {
    width: 100%;
    min-height: var(--tap);
    padding: var(--sp-2) var(--sp-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    /* 16px on phones stops iOS Safari zooming the viewport on focus. */
    font-size: max(1rem, var(--text-base));
    font-weight: 400;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.textarea,
.form-panel textarea,
.contact-form textarea { resize: vertical; min-height: 6rem; line-height: 1.6; }

@media (min-width: 64em) {
    .input, .select, .textarea,
    .form-panel input, .form-panel select, .form-panel textarea,
    .auth-form input, .contact-form input, .contact-form textarea { font-size: var(--text-base); }
}

.input:focus,
.select:focus,
.textarea:focus,
.form-panel input:focus,
.form-panel select:focus,
.form-panel textarea:focus,
.auth-form input:focus,
.contact-form input:focus,
.contact-form textarea:focus {
    border-color: var(--primary-500);
    box-shadow: var(--ring);
    outline: none;
}
.input[aria-invalid="true"],
.textarea[aria-invalid="true"] { border-color: var(--danger); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px rgba(165, 35, 27, 0.2); }
.input::placeholder, .textarea::placeholder { color: var(--text-subtle); }

.select,
.form-panel select {
    appearance: none;
    padding-right: var(--sp-8);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%236b7890' stroke-width='1.75' stroke-linecap='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--sp-3) center;
    background-size: 1rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    min-height: var(--tap);
    font-weight: 500;
    cursor: pointer;
}
.checkbox-label input {
    /* 24px keeps the control itself above the WCAG 2.5.8 minimum, independent
       of the label's larger clickable area. */
    width: 1.5rem;
    height: 1.5rem;
    accent-color: var(--primary);
    flex: none;
    cursor: pointer;
}

/* Auto-fitting field pairs. `min(100%, …)` keeps them from overflowing 320px. */
.field-row,
.settings-pair {
    display: grid;
    gap: var(--sp-4);
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
}

.fieldset { border: 0; padding: 0; margin: var(--sp-2) 0 0; display: grid; gap: var(--sp-5); min-width: 0; }
.fieldset > legend,
.form-panel h3 {
    padding: 0;
    margin: 0 0 var(--sp-1);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.form-help { color: var(--text-muted); font-size: var(--text-sm); }

.form-actions {
    display: flex;
    flex-direction: column-reverse;
    gap: var(--sp-3);
    padding-top: var(--sp-4);
    border-top: 1px solid var(--border);
}
.form-actions-sticky {
    position: sticky;
    bottom: 0;
    z-index: 5;
    background: linear-gradient(to top, var(--surface) 72%, rgba(255, 255, 255, 0));
    margin: 0 calc(var(--sp-4) * -1) calc(var(--sp-4) * -1);
    padding: var(--sp-4);
}

/* Every focusable control keeps clearance from the sticky bar when scrolled to,
   whether by keyboard focus, an error jump, or scrollIntoView. */
.field,
.checkbox-label,
.input,
.select,
.textarea,
.fieldset { scroll-margin-bottom: 7rem; }

@media (min-width: 48em) {
    .form-actions { flex-direction: row; justify-content: flex-end; }
    .form-actions-sticky {
        margin: 0 calc(var(--sp-6) * -1) calc(var(--sp-6) * -1);
        padding: var(--sp-4) var(--sp-6);
    }
}

.menu-toggles { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-6); }

/* Contact-form honeypot: hidden from people, reachable by bots. */
.trap { position: absolute; width: 0; height: 0; overflow: hidden; opacity: 0; }

/* --- Pager -------------------------------------------------------------- */
.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-6);
    border-top: 1px solid var(--border);
}

.pager-count {
    margin: 0;
    color: var(--text-muted);
    font-size: var(--text-sm);
}
