/* ==========================================================================
   FormMaster 2.0 — design system
   --------------------------------------------------------------------------
   Everything is prefixed `fm-` so this file can sit alongside the Bootstrap 4
   that the legacy admin pages still load, without either one fighting the
   other. No element selectors beyond a short reset, so specificity stays flat
   and predictable.

   Built for: a government recruitment portal. Legibility before polish,
   48px touch targets, AA contrast, and sensible behaviour at 320px wide on a
   slow connection.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */
/* ==========================================================================
   FormMaster — legacy class vocabulary, rebased on the unified design system
   --------------------------------------------------------------------------
   Three screens (applications, the form builder, messages) and the public form
   were written against this `fm-` class vocabulary and are verified against
   live data. Rewriting ~250 class names across ten files, including generated
   markup inside builder.js, would risk regressions in code that works, and buy
   nothing a person can see.

   So the markup keeps its names and this file re-points every token it uses at
   the tokens in app.css. Those screens therefore inherit the new palette,
   typography, radii, elevation and — because nothing here is a fixed colour —
   dark mode, with no change to a single line of their markup.

   app.css must load FIRST. This file defines no layout of its own beyond what
   the original did; it is a translation layer, not a second design system.

   Cleanup for a later release: migrate the markup to the app.css vocabulary
   and delete this file. It is not load-bearing, only transitional.
   ========================================================================== */

:root {
    /* brand ---------------------------------------------------------------- */
    --fm-green-900: var(--edo);
    --fm-green-800: var(--edo);
    --fm-green-700: var(--edo-700);
    --fm-green-600: var(--ok);
    --fm-green-100: var(--edo-200);
    --fm-green-050: var(--edo-50);

    /* ink ------------------------------------------------------------------ */
    --fm-ink:       var(--ink);
    --fm-ink-soft:  var(--ink-2);
    --fm-muted:     var(--ink-3);
    --fm-faint:     var(--ink-4);

    /* surfaces ------------------------------------------------------------- */
    --fm-paper:     var(--page);
    --fm-surface:   var(--surface);
    --fm-sunken:    var(--surface-3);
    --fm-rule:      var(--line-2);
    --fm-rule-soft: var(--line);

    /* semantic ------------------------------------------------------------- */
    --fm-attention:    var(--warn);
    --fm-attention-bg: var(--warn-bg);
    --fm-danger:       var(--danger);
    --fm-danger-bg:    var(--danger-bg);
    --fm-info:         var(--info);
    --fm-info-bg:      var(--info-bg);

    /* Review pipeline. These carry meaning, so they stay distinguishable in
       both themes rather than collapsing into the brand colour. */
    --fm-status-new:         var(--ink-3);
    --fm-status-in_review:   var(--warn);
    --fm-status-shortlisted: var(--ok);
    --fm-status-accepted:    var(--s-forms);
    --fm-status-rejected:    var(--danger);
    --fm-status-withdrawn:   var(--ink-4);
    --fm-status-duplicate:   var(--danger);

    /* spacing --------------------------------------------------------------
       The old vocabulary spaces itself on this scale — 247 declarations in
       this file read these. They are fixed rather than aliased to app.css
       because app.css spaces on a different rhythm, and re-pointing them
       would quietly reflow five screens that are already laid out to it.
       An undefined custom property makes the whole declaration invalid, so
       leaving these out does not fall back to a default: it deletes the
       padding outright. */
    --fm-1: .25rem;
    --fm-2: .5rem;
    --fm-3: .75rem;
    --fm-4: 1rem;
    --fm-5: 1.25rem;
    --fm-6: 1.5rem;
    --fm-8: 2rem;
    --fm-10: 2.5rem;
    --fm-12: 3rem;
    --fm-16: 4rem;

    /* type ----------------------------------------------------------------- */
    --fm-font:      var(--font);
    --fm-text-xs:   .8125rem;
    --fm-text-sm:   .9375rem;
    --fm-text-base: 1rem;
    --fm-text-lg:   1.125rem;
    --fm-text-xl:   1.3125rem;
    --fm-text-2xl:  1.5rem;
    --fm-text-3xl:  1.875rem;

    /* geometry and motion -------------------------------------------------- */
    --fm-radius-field: var(--r);
    --fm-radius-card:  var(--r-lg);
    --fm-radius-pill:  var(--r-pill);
    --fm-shadow-raise: var(--lift);
    --fm-shadow-float: var(--lift-2);
    --fm-focus:        var(--focus);
    --fm-ease:         cubic-bezier(.2, .6, .3, 1);
    --fm-reading:      68ch;
    --fm-shell-max:    1320px;
    --fm-topbar:       var(--bar);
    --fm-tabbar:       56px;
}

@media (min-width: 768px) {
    :root { --fm-topbar: 68px; }
}

/* Dark mode: only where it does not harm legibility of official content. */
/* The legacy dark-mode block was removed: app.css owns the theme now, and a
   second set of fixed dark values here would override the aliases above and
   put two different dark palettes on one screen. */

/* --------------------------------------------------------------------------
   2. Reset — scoped tight so Bootstrap pages are not disturbed
   -------------------------------------------------------------------------- */
.fm-app,
.fm-app *,
.fm-app *::before,
.fm-app *::after { box-sizing: border-box; }

.fm-app {
    font-family: var(--fm-font);
    font-size: var(--fm-text-base);
    line-height: 1.55;
    color: var(--fm-ink);
    background: var(--fm-paper);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
}

.fm-app img,
.fm-app svg { max-width: 100%; height: auto; display: block; }

/* Visible keyboard focus everywhere, never removed. */
.fm-app :focus-visible {
    outline: 2px solid var(--fm-green-600);
    outline-offset: 2px;
    border-radius: 4px;
}

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

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

/* The [hidden] attribute must always win.
   Components below set display:flex or display:grid, which has the same
   specificity as the browser's own [hidden] rule — so the later declaration
   wins and the element stays visible. That would show every error message and
   every collapsed panel. This one line is what keeps `hidden` meaning hidden. */
.fm-app [hidden] { display: none !important; }

.fm-skip-link {
    position: absolute; left: var(--fm-4); top: -4rem;
    z-index: 200;
    background: var(--fm-surface); color: var(--fm-ink);
    padding: var(--fm-3) var(--fm-5);
    border-radius: var(--fm-radius-field);
    box-shadow: var(--fm-shadow-float);
    font-weight: 600; text-decoration: none;
    transition: top .18s var(--fm-ease);
}
.fm-skip-link:focus { top: var(--fm-4); }

/* --------------------------------------------------------------------------
   3. Typography
   -------------------------------------------------------------------------- */
.fm-h1, .fm-h2, .fm-h3, .fm-h4 {
    margin: 0 0 var(--fm-3);
    font-weight: 650;
    line-height: 1.22;
    letter-spacing: -0.012em;
    color: var(--fm-ink);
}
.fm-h1 { font-size: var(--fm-text-2xl); }
.fm-h2 { font-size: var(--fm-text-xl); }
.fm-h3 { font-size: var(--fm-text-lg); }
.fm-h4 { font-size: var(--fm-text-base); font-weight: 600; }

@media (min-width: 768px) {
    .fm-h1 { font-size: var(--fm-text-3xl); }
    .fm-h2 { font-size: var(--fm-text-2xl); }
}

.fm-lede   { font-size: var(--fm-text-lg); color: var(--fm-ink-soft); max-width: 38rem; }
.fm-muted  { color: var(--fm-muted); }
.fm-small  { font-size: var(--fm-text-sm); }
.fm-prose  { max-width: var(--fm-reading); }
.fm-prose p { margin: 0 0 var(--fm-4); }
.fm-prose a { color: var(--fm-green-700); text-underline-offset: 2px; }
.fm-prose :is(h1,h2,h3,h4) { margin-top: var(--fm-6); }
.fm-prose img { border-radius: var(--fm-radius-field); margin: var(--fm-4) 0; }
.fm-prose hr { border: 0; border-top: 1px solid var(--fm-rule); margin: var(--fm-6) 0; }

/* Numerals that line up in tables and totals. */
.fm-tnum { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   4. Buttons
   -------------------------------------------------------------------------- */
.fm-btn {
    --btn-bg: var(--fm-surface);
    --btn-fg: var(--fm-ink);
    --btn-bd: var(--fm-rule);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--fm-2);
    min-height: 48px;
    padding: 0 var(--fm-5);
    font: inherit;
    font-size: var(--fm-text-base);
    font-weight: 600;
    line-height: 1;
    color: var(--btn-fg);
    background: var(--btn-bg);
    border: 1px solid var(--btn-bd);
    border-radius: var(--fm-radius-field);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color .15s var(--fm-ease), border-color .15s var(--fm-ease), color .15s var(--fm-ease);
}
.fm-btn:hover:not(:disabled) { background: var(--fm-sunken); }
.fm-btn:active:not(:disabled) { transform: translateY(1px); }
.fm-btn:disabled, .fm-btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.fm-btn:focus-visible { box-shadow: var(--fm-focus); }

.fm-btn--primary {
    --btn-bg: var(--fm-green-800);
    --btn-fg: var(--inverse-fg);
    --btn-bd: var(--fm-green-800);
}
.fm-btn--primary:hover:not(:disabled) { --btn-bg: var(--fm-green-700); --btn-bd: var(--fm-green-700); }

.fm-btn--danger {
    --btn-bg: var(--fm-surface);
    --btn-fg: var(--fm-danger);
    --btn-bd: var(--fm-rule);
}
.fm-btn--danger:hover:not(:disabled) { --btn-bg: var(--fm-danger-bg); --btn-bd: var(--fm-danger); }

.fm-btn--ghost { --btn-bg: transparent; --btn-bd: transparent; }
.fm-btn--ghost:hover:not(:disabled) { --btn-bg: var(--fm-sunken); }

.fm-btn--sm   { min-height: 38px; padding: 0 var(--fm-3); font-size: var(--fm-text-sm); }
.fm-btn--lg   { min-height: 54px; padding: 0 var(--fm-8); font-size: var(--fm-text-lg); }
.fm-btn--full { width: 100%; }
.fm-btn--icon { padding: 0; width: 44px; min-height: 44px; }

.fm-btn.is-busy { pointer-events: none; position: relative; color: transparent; }
.fm-btn.is-busy::after {
    content: ""; position: absolute;
    width: 18px; height: 18px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    color: var(--btn-fg);
    animation: fm-spin .7s linear infinite;
}
@keyframes fm-spin { to { transform: rotate(360deg); } }

.fm-btn-row { display: flex; flex-wrap: wrap; gap: var(--fm-3); }

/* --------------------------------------------------------------------------
   5. Form fields
   -------------------------------------------------------------------------- */
.fm-field { margin-bottom: var(--fm-6); }

.fm-label {
    display: block;
    margin-bottom: var(--fm-2);
    font-size: var(--fm-text-base);
    font-weight: 600;
    color: var(--fm-ink);
}
.fm-label__required { color: var(--fm-danger); margin-left: 2px; }
.fm-label__optional { font-weight: 400; color: var(--fm-muted); margin-left: var(--fm-2); }

.fm-hint {
    margin: calc(var(--fm-2) * -1) 0 var(--fm-3);
    font-size: var(--fm-text-sm);
    color: var(--fm-muted);
}

.fm-input, .fm-select, .fm-textarea {
    display: block;
    width: 100%;
    min-height: 48px;
    padding: var(--fm-3) var(--fm-4);
    font: inherit;
    /* 16px stops iOS Safari zooming the page when a field is focused. */
    font-size: 16px;
    color: var(--fm-ink);
    background: var(--fm-surface);
    border: 1.5px solid var(--fm-rule);
    border-radius: var(--fm-radius-field);
    transition: border-color .15s var(--fm-ease), box-shadow .15s var(--fm-ease);
    -webkit-appearance: none;
    appearance: none;
}
.fm-textarea { min-height: 120px; resize: vertical; line-height: 1.55; }

.fm-select {
    padding-right: var(--fm-10);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235a6762' d='M1.4 0 6 4.6 10.6 0 12 1.4 6 7.4 0 1.4z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--fm-4) center;
    background-size: 12px 8px;
}

.fm-input::placeholder, .fm-textarea::placeholder { color: var(--fm-faint); }
.fm-input:hover, .fm-select:hover, .fm-textarea:hover { border-color: var(--line-strong); }
.fm-input:focus, .fm-select:focus, .fm-textarea:focus {
    outline: none;
    border-color: var(--fm-green-600);
    box-shadow: var(--fm-focus);
}
.fm-input:disabled, .fm-select:disabled, .fm-textarea:disabled {
    background: var(--fm-sunken); color: var(--fm-muted); cursor: not-allowed;
}

.fm-input.is-invalid, .fm-select.is-invalid, .fm-textarea.is-invalid { border-color: var(--fm-danger); }
.fm-input.is-invalid:focus { box-shadow: 0 0 0 3px rgba(179, 38, 30, .22); }

.fm-error {
    display: flex; align-items: flex-start; gap: var(--fm-2);
    margin-top: var(--fm-2);
    font-size: var(--fm-text-sm);
    font-weight: 500;
    color: var(--fm-danger);
}

.fm-char-count { margin-top: var(--fm-1); font-size: var(--fm-text-xs); color: var(--fm-muted); text-align: right; }
.fm-char-count.is-over { color: var(--fm-danger); font-weight: 600; }

/* Choice controls — the whole row is the target, not just the dot. */
.fm-choice-list { display: grid; gap: var(--fm-2); }

.fm-choice {
    display: flex;
    align-items: flex-start;
    gap: var(--fm-3);
    min-height: 48px;
    padding: var(--fm-3) var(--fm-4);
    background: var(--fm-surface);
    border: 1.5px solid var(--fm-rule);
    border-radius: var(--fm-radius-field);
    cursor: pointer;
    transition: border-color .12s var(--fm-ease), background-color .12s var(--fm-ease);
}
.fm-choice:hover { border-color: var(--line-strong); }
.fm-choice input { flex: none; width: 20px; height: 20px; margin-top: 2px; accent-color: var(--fm-green-600); }
.fm-choice__text { flex: 1; min-width: 0; }
.fm-choice__label { font-weight: 500; }
.fm-choice__hint { display: block; margin-top: 2px; font-size: var(--fm-text-sm); color: var(--fm-muted); }
.fm-choice:has(input:checked) { border-color: var(--fm-green-600); background: var(--fm-green-050); }
.fm-choice:has(input:focus-visible) { box-shadow: var(--fm-focus); }
.fm-choice.is-invalid { border-color: var(--fm-danger); }

/* Linear scale */
.fm-scale { display: flex; align-items: flex-end; gap: var(--fm-2); overflow-x: auto; padding-bottom: var(--fm-2); }
.fm-scale__end { font-size: var(--fm-text-sm); color: var(--fm-muted); padding-bottom: var(--fm-3); max-width: 7rem; }
.fm-scale__point { display: flex; flex-direction: column; align-items: center; gap: var(--fm-2); cursor: pointer; flex: none; }
.fm-scale__point input { width: 22px; height: 22px; accent-color: var(--fm-green-600); }
.fm-scale__num { font-size: var(--fm-text-sm); font-weight: 600; color: var(--fm-ink-soft); }

/* Star rating */
.fm-rating { display: flex; gap: var(--fm-1); }
.fm-rating__star {
    width: 44px; height: 44px;
    display: grid; place-items: center;
    font-size: 1.6rem; line-height: 1;
    color: var(--fm-rule);
    background: none; border: 0; cursor: pointer; padding: 0;
    transition: color .12s var(--fm-ease);
}
.fm-rating__star.is-on, .fm-rating__star:hover { color: var(--warn); }

/* Grid questions — horizontally scrollable on a phone, never squashed. */
.fm-grid-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 calc(var(--fm-4) * -1); padding: 0 var(--fm-4); }
.fm-grid-q { width: 100%; border-collapse: collapse; min-width: 32rem; }
.fm-grid-q th, .fm-grid-q td { padding: var(--fm-3); text-align: center; border-bottom: 1px solid var(--fm-rule-soft); }
.fm-grid-q th:first-child, .fm-grid-q td:first-child { text-align: left; font-weight: 500; position: sticky; left: 0; background: var(--fm-surface); min-width: 9rem; }
.fm-grid-q thead th { font-size: var(--fm-text-sm); font-weight: 600; color: var(--fm-muted); }
.fm-grid-q input { width: 20px; height: 20px; accent-color: var(--fm-green-600); }

/* File upload */
.fm-drop {
    display: block;
    padding: var(--fm-6) var(--fm-4);
    text-align: center;
    background: var(--fm-sunken);
    border: 2px dashed var(--fm-rule);
    border-radius: var(--fm-radius-card);
    cursor: pointer;
    transition: border-color .15s var(--fm-ease), background-color .15s var(--fm-ease);
}
.fm-drop:hover, .fm-drop.is-over { border-color: var(--fm-green-600); background: var(--fm-green-050); }
.fm-drop__icon { font-size: 1.75rem; color: var(--fm-green-600); margin-bottom: var(--fm-2); }
.fm-drop__title { font-weight: 600; }
.fm-drop__hint { font-size: var(--fm-text-sm); color: var(--fm-muted); margin-top: var(--fm-1); }

.fm-file {
    display: flex; align-items: center; gap: var(--fm-3);
    padding: var(--fm-3);
    margin-top: var(--fm-3);
    background: var(--fm-surface);
    border: 1px solid var(--fm-rule);
    border-radius: var(--fm-radius-field);
}
.fm-file__thumb { width: 44px; height: 44px; flex: none; border-radius: 6px; object-fit: cover; background: var(--fm-sunken); display: grid; place-items: center; color: var(--fm-muted); }
.fm-file__body { flex: 1; min-width: 0; }
.fm-file__name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-file__meta { font-size: var(--fm-text-sm); color: var(--fm-muted); }
.fm-file__bar { height: 4px; background: var(--fm-rule-soft); border-radius: var(--fm-radius-pill); overflow: hidden; margin-top: var(--fm-2); }
.fm-file__bar span { display: block; height: 100%; background: var(--fm-green-600); transition: width .25s var(--fm-ease); }

/* --------------------------------------------------------------------------
   6. Cards & surfaces
   -------------------------------------------------------------------------- */
.fm-card {
    background: var(--fm-surface);
    border: 1px solid var(--fm-rule);
    border-radius: var(--fm-radius-card);
    padding: var(--fm-5);
}
@media (min-width: 768px) { .fm-card { padding: var(--fm-6); } }

.fm-card--raised { box-shadow: var(--fm-shadow-raise); border-color: var(--fm-rule-soft); }
.fm-card--flush  { padding: 0; overflow: hidden; }

.fm-card__head {
    display: flex; align-items: center; justify-content: space-between; gap: var(--fm-4);
    padding: var(--fm-4) var(--fm-5);
    border-bottom: 1px solid var(--fm-rule-soft);
}
.fm-card__title { font-size: var(--fm-text-lg); font-weight: 650; margin: 0; }
.fm-card__body  { padding: var(--fm-5); }

/* --------------------------------------------------------------------------
   7. Status badges — colour maps to the review pipeline, so it carries meaning
   -------------------------------------------------------------------------- */
.fm-badge {
    display: inline-flex; align-items: center; gap: var(--fm-2);
    padding: var(--fm-1) var(--fm-3);
    font-size: var(--fm-text-sm);
    font-weight: 600;
    line-height: 1.4;
    border-radius: var(--fm-radius-pill);
    background: var(--fm-sunken);
    color: var(--fm-ink-soft);
    white-space: nowrap;
}
.fm-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.fm-badge--plain::before { display: none; }

.fm-badge[data-status="new"]         { color: var(--fm-status-new); }
.fm-badge[data-status="in_review"]   { color: var(--fm-status-in_review);   background: var(--fm-info-bg); }
.fm-badge[data-status="shortlisted"] { color: var(--fm-status-shortlisted); background: var(--ok-bg); }
.fm-badge[data-status="accepted"]    { color: var(--fm-status-accepted);    background: var(--fm-green-050); }
.fm-badge[data-status="rejected"]    { color: var(--fm-status-rejected);    background: var(--fm-danger-bg); }
.fm-badge[data-status="withdrawn"]   { color: var(--fm-status-withdrawn); }
.fm-badge[data-status="duplicate"]   { color: var(--fm-status-duplicate);   background: var(--fm-attention-bg); }

.fm-badge--active   { color: var(--fm-green-600); background: var(--fm-green-050); }
.fm-badge--inactive { color: var(--fm-muted); }

/* --------------------------------------------------------------------------
   8. Notices
   -------------------------------------------------------------------------- */
.fm-notice {
    display: flex; gap: var(--fm-3);
    padding: var(--fm-4);
    border-radius: var(--fm-radius-field);
    border-left: 4px solid var(--fm-info);
    background: var(--fm-info-bg);
    color: var(--fm-ink);
    margin-bottom: var(--fm-5);
}
.fm-notice__icon { flex: none; color: var(--fm-info); font-size: 1.1rem; line-height: 1.5; }
.fm-notice__body { flex: 1; min-width: 0; }
.fm-notice__title { font-weight: 650; margin-bottom: var(--fm-1); }
.fm-notice p:last-child { margin-bottom: 0; }

.fm-notice--success { border-left-color: var(--fm-green-600); background: var(--fm-green-050); }
.fm-notice--success .fm-notice__icon { color: var(--fm-green-600); }
.fm-notice--warning { border-left-color: var(--fm-attention); background: var(--fm-attention-bg); }
.fm-notice--warning .fm-notice__icon { color: var(--fm-attention); }
.fm-notice--error   { border-left-color: var(--fm-danger); background: var(--fm-danger-bg); }
.fm-notice--error .fm-notice__icon { color: var(--fm-danger); }

/* --------------------------------------------------------------------------
   9. Tables — rules rather than cards, so dense data stays readable
   -------------------------------------------------------------------------- */
.fm-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--fm-rule); border-radius: var(--fm-radius-card); background: var(--fm-surface); }
.fm-table { width: 100%; border-collapse: collapse; font-size: var(--fm-text-sm); }
.fm-table th, .fm-table td { padding: var(--fm-3) var(--fm-4); text-align: left; vertical-align: middle; }
.fm-table thead th {
    position: sticky; top: 0; z-index: 2;
    background: var(--fm-sunken);
    font-weight: 650; font-size: var(--fm-text-xs);
    color: var(--fm-ink-soft);
    border-bottom: 1px solid var(--fm-rule);
    white-space: nowrap;
}
.fm-table tbody tr { border-bottom: 1px solid var(--fm-rule-soft); }
.fm-table tbody tr:last-child { border-bottom: 0; }
.fm-table tbody tr:hover { background: var(--fm-green-050); }
.fm-table tbody tr.is-selected { background: var(--fm-green-100); }
.fm-table__sort { background: none; border: 0; padding: 0; font: inherit; font-weight: inherit; color: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: var(--fm-1); }
.fm-table__sort:hover { color: var(--fm-green-700); }
.fm-table td.fm-nowrap { white-space: nowrap; }
.fm-table__sticky-first th:first-child, .fm-table__sticky-first td:first-child { position: sticky; left: 0; background: var(--fm-surface); z-index: 1; }
.fm-table__sticky-first thead th:first-child { background: var(--fm-sunken); z-index: 3; }

/* --------------------------------------------------------------------------
   10. Empty states — an invitation to act, not an apology
   -------------------------------------------------------------------------- */
.fm-empty { text-align: center; padding: var(--fm-12) var(--fm-5); }
.fm-empty__icon { font-size: 2.25rem; color: var(--fm-faint); margin-bottom: var(--fm-4); }
.fm-empty__title { font-size: var(--fm-text-lg); font-weight: 650; margin-bottom: var(--fm-2); }
.fm-empty__text { color: var(--fm-muted); max-width: 26rem; margin: 0 auto var(--fm-5); }

/* --------------------------------------------------------------------------
   11. Admin shell — top bar on all sizes, bottom tabs on phones
   -------------------------------------------------------------------------- */
.fm-shell { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; background: var(--fm-paper); }

.fm-topbar {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; gap: var(--fm-4);
    min-height: var(--fm-topbar);
    padding: 0 var(--fm-4);
    padding-top: env(safe-area-inset-top);
    background: var(--fm-green-800);
    color: #fff;
}
.fm-topbar__brand { display: flex; align-items: center; gap: var(--fm-3); font-weight: 700; font-size: var(--fm-text-lg); color: #fff; text-decoration: none; letter-spacing: -0.015em; flex: 1; min-width: 0; }
.fm-topbar__brand img { height: 34px; width: auto; border-radius: 6px; flex: none; }
.fm-topbar__brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.fm-topbar__nav { display: none; align-items: center; gap: var(--fm-1); }
.fm-topbar__link {
    display: inline-flex; align-items: center; gap: var(--fm-2);
    padding: var(--fm-2) var(--fm-3);
    border-radius: var(--fm-radius-field);
    color: rgba(255,255,255,.82);
    font-size: var(--fm-text-sm); font-weight: 500;
    text-decoration: none;
    transition: background-color .15s var(--fm-ease), color .15s var(--fm-ease);
}
.fm-topbar__link:hover { background: rgba(255,255,255,.12); color: #fff; }
.fm-topbar__link.is-current { background: rgba(255,255,255,.18); color: #fff; font-weight: 600; }

.fm-topbar__end { display: flex; align-items: center; gap: var(--fm-2); flex: none; }
.fm-topbar__icon {
    position: relative;
    width: 44px; height: 44px;
    display: grid; place-items: center;
    border-radius: var(--fm-radius-field);
    background: transparent; border: 0; cursor: pointer;
    color: rgba(255,255,255,.9); font-size: 1.05rem;
    text-decoration: none;
}
.fm-topbar__icon:hover { background: rgba(255,255,255,.14); color: #fff; }
.fm-topbar__count {
    position: absolute; top: 6px; right: 5px;
    min-width: 18px; height: 18px; padding: 0 4px;
    display: grid; place-items: center;
    background: var(--fm-danger); color: #fff;
    font-size: 11px; font-weight: 700; line-height: 1;
    border-radius: var(--fm-radius-pill);
    border: 2px solid var(--fm-green-800);
}

@media (min-width: 992px) {
    .fm-topbar { padding: 0 var(--fm-6); gap: var(--fm-6); }
    .fm-topbar__brand { flex: none; }
    .fm-topbar__nav { display: flex; flex: 1; }
}

.fm-main { flex: 1; width: 100%; max-width: var(--fm-shell-max); margin: 0 auto; padding: var(--fm-5) var(--fm-4) var(--fm-10); }
@media (min-width: 768px) { .fm-main { padding: var(--fm-8) var(--fm-6) var(--fm-12); } }
@media (max-width: 991.98px) { .fm-main { padding-bottom: calc(var(--fm-tabbar) + env(safe-area-inset-bottom) + var(--fm-6)); } }

/* Bottom tab bar: reviewers do work on their phones, and thumb reach
   beats a menu tucked in the top corner. */
.fm-tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    display: flex;
    background: var(--fm-surface);
    border-top: 1px solid var(--fm-rule);
    padding-bottom: env(safe-area-inset-bottom);
}
.fm-tabbar__item {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: var(--fm-tabbar);
    padding: var(--fm-2) var(--fm-1);
    color: var(--fm-muted);
    font-size: 11px; font-weight: 600;
    text-decoration: none;
    position: relative;
}
.fm-tabbar__item i, .fm-tabbar__item svg { font-size: 1.15rem; }
.fm-tabbar__item.is-current { color: var(--fm-green-700); }
.fm-tabbar__item.is-current::before { content: ""; position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--fm-green-600); }
.fm-tabbar__count { position: absolute; top: 6px; left: 55%; min-width: 16px; height: 16px; padding: 0 4px; display: grid; place-items: center; background: var(--fm-danger); color: #fff; font-size: 10px; border-radius: var(--fm-radius-pill); }
@media (min-width: 992px) { .fm-tabbar { display: none; } }

.fm-page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--fm-4); margin-bottom: var(--fm-6); }
.fm-page-head__text { min-width: 0; }
.fm-page-head__text p { margin: var(--fm-1) 0 0; color: var(--fm-muted); }

/* --------------------------------------------------------------------------
   12. Stat tiles — flat tinted blocks, no shadow, distinct from content cards
   -------------------------------------------------------------------------- */
.fm-stats { display: grid; gap: var(--fm-3); grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: var(--fm-6); }
@media (min-width: 768px) { .fm-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--fm-4); } }

.fm-stat { padding: var(--fm-4); background: var(--fm-surface); border: 1px solid var(--fm-rule); border-radius: var(--fm-radius-field); }
.fm-stat__value { font-size: var(--fm-text-2xl); font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.fm-stat__label { font-size: var(--fm-text-sm); color: var(--fm-muted); margin-top: var(--fm-1); }
.fm-stat__delta { font-size: var(--fm-text-sm); font-weight: 600; margin-top: var(--fm-2); }
.fm-stat__delta.is-up   { color: var(--fm-green-600); }
.fm-stat__delta.is-down { color: var(--fm-danger); }
.fm-stat--accent { background: var(--fm-green-050); border-color: var(--fm-green-100); }
.fm-stat--accent .fm-stat__value { color: var(--fm-green-800); }

/* --------------------------------------------------------------------------
   13. Tabs, toolbar, pagination
   -------------------------------------------------------------------------- */
.fm-tabs { display: flex; gap: var(--fm-1); border-bottom: 1px solid var(--fm-rule); margin-bottom: var(--fm-5); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.fm-tab {
    padding: var(--fm-3) var(--fm-4);
    background: none; border: 0; border-bottom: 3px solid transparent;
    font: inherit; font-size: var(--fm-text-sm); font-weight: 600;
    color: var(--fm-muted); cursor: pointer; white-space: nowrap;
    display: inline-flex; align-items: center; gap: var(--fm-2);
    min-height: 48px;
}
.fm-tab:hover { color: var(--fm-ink); }
.fm-tab.is-current { color: var(--fm-green-800); border-bottom-color: var(--fm-green-600); }
.fm-tab__count { background: var(--fm-sunken); border-radius: var(--fm-radius-pill); padding: 1px var(--fm-2); font-size: var(--fm-text-xs); font-weight: 700; }

.fm-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--fm-3); margin-bottom: var(--fm-4); }
.fm-toolbar__grow { flex: 1 1 14rem; min-width: 0; }

.fm-search { position: relative; }
.fm-search .fm-input { padding-left: var(--fm-10); }
.fm-search__icon { position: absolute; left: var(--fm-4); top: 50%; transform: translateY(-50%); color: var(--fm-faint); pointer-events: none; }

.fm-pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--fm-3); margin-top: var(--fm-5); }
.fm-pagination__info { font-size: var(--fm-text-sm); color: var(--fm-muted); }
.fm-pagination__pages { display: flex; gap: var(--fm-1); }

/* Bulk-action bar appears only when rows are selected. */
.fm-bulkbar {
    position: sticky; bottom: var(--fm-4); z-index: 40;
    display: flex; flex-wrap: wrap; align-items: center; gap: var(--fm-3);
    padding: var(--fm-3) var(--fm-4);
    margin-top: var(--fm-4);
    background: var(--fm-green-800); color: #fff;
    border-radius: var(--fm-radius-card);
    box-shadow: var(--fm-shadow-float);
}
.fm-bulkbar__count { font-weight: 650; }
.fm-bulkbar .fm-btn { --btn-bg: rgba(255,255,255,.14); --btn-fg: var(--inverse-fg); --btn-bd: rgba(255,255,255,.28); }
.fm-bulkbar .fm-btn:hover:not(:disabled) { --btn-bg: rgba(255,255,255,.24); }

/* --------------------------------------------------------------------------
   14. Public form — the ledger rail is the distinctive element
   -------------------------------------------------------------------------- */
.fm-form-page { min-height: 100vh; min-height: 100dvh; background: var(--fm-paper); }

.fm-form-masthead {
    background: var(--fm-green-800);
    color: #fff;
    padding: var(--fm-6) var(--fm-4);
    padding-top: calc(var(--fm-6) + env(safe-area-inset-top));
}
.fm-form-masthead__inner { max-width: var(--fm-reading); margin: 0 auto; }
.fm-form-masthead__org { display: flex; align-items: center; gap: var(--fm-3); font-size: var(--fm-text-sm); color: rgba(255,255,255,.78); margin-bottom: var(--fm-4); }
.fm-form-masthead__org img { height: 30px; border-radius: 5px; }
.fm-form-masthead h1 { font-size: var(--fm-text-2xl); font-weight: 700; line-height: 1.2; margin: 0 0 var(--fm-2); letter-spacing: -0.015em; }
.fm-form-masthead p { margin: 0; color: rgba(255,255,255,.85); max-width: 36rem; }
@media (min-width: 768px) { .fm-form-masthead { padding: var(--fm-10) var(--fm-6); } .fm-form-masthead h1 { font-size: var(--fm-text-3xl); } }

.fm-form-masthead--image { position: relative; background-size: cover; background-position: center; }
.fm-form-masthead--image::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(7,43,33,.72), rgba(7,43,33,.92)); }
.fm-form-masthead--image .fm-form-masthead__inner { position: relative; }

.fm-form-layout { max-width: var(--fm-reading); margin: 0 auto; padding: var(--fm-5) var(--fm-4) var(--fm-16); }
@media (min-width: 1024px) {
    .fm-form-layout {
        max-width: 66rem;
        display: grid;
        grid-template-columns: 15rem minmax(0, 1fr);
        gap: var(--fm-10);
        align-items: start;
        padding: var(--fm-8) var(--fm-6) var(--fm-16);
    }
}

/* ---- The rail: vertical on desktop, segmented bar on mobile ---- */
.fm-rail { display: none; }
@media (min-width: 1024px) {
    .fm-rail { display: block; position: sticky; top: var(--fm-8); }
}
.fm-rail__title { font-size: var(--fm-text-sm); font-weight: 650; color: var(--fm-muted); margin-bottom: var(--fm-4); }
.fm-rail__list { list-style: none; margin: 0; padding: 0; position: relative; }
.fm-rail__list::before { content: ""; position: absolute; left: 11px; top: 10px; bottom: 10px; width: 2px; background: var(--fm-rule); }
.fm-rail__item { position: relative; padding: 0 0 var(--fm-5) var(--fm-8); }
.fm-rail__item:last-child { padding-bottom: 0; }
.fm-rail__dot {
    position: absolute; left: 0; top: 2px;
    width: 24px; height: 24px;
    display: grid; place-items: center;
    background: var(--fm-paper);
    border: 2px solid var(--fm-rule);
    border-radius: 50%;
    font-size: 12px; font-weight: 700; color: var(--fm-muted);
}
/* Both are <span>, so they need to be blocks or the section name and its
   count run together as "Personal details7 questions". */
.fm-rail__label { display: block; font-size: var(--fm-text-sm); font-weight: 500; color: var(--fm-muted); line-height: 1.35; }
.fm-rail__meta  { display: block; font-size: var(--fm-text-xs); color: var(--fm-faint); margin-top: 2px; }

.fm-rail__item.is-current .fm-rail__dot { border-color: var(--fm-green-600); color: var(--fm-green-700); background: var(--fm-green-050); }
.fm-rail__item.is-current .fm-rail__label { color: var(--fm-ink); font-weight: 650; }
.fm-rail__item.is-done .fm-rail__dot { background: var(--fm-green-600); border-color: var(--fm-green-600); color: #fff; }
.fm-rail__item.is-done .fm-rail__label { color: var(--fm-ink-soft); }

/* Mobile equivalent */
.fm-railbar { margin-bottom: var(--fm-5); }
@media (min-width: 1024px) { .fm-railbar { display: none; } }
.fm-railbar__meta { display: flex; justify-content: space-between; align-items: baseline; font-size: var(--fm-text-sm); margin-bottom: var(--fm-2); }
.fm-railbar__step { font-weight: 650; }
.fm-railbar__pct { color: var(--fm-muted); font-variant-numeric: tabular-nums; }
.fm-railbar__track { display: flex; gap: 3px; }
.fm-railbar__seg { flex: 1; height: 6px; border-radius: var(--fm-radius-pill); background: var(--fm-rule); transition: background-color .3s var(--fm-ease); }
.fm-railbar__seg.is-done { background: var(--fm-green-600); }
.fm-railbar__seg.is-current { background: linear-gradient(90deg, var(--fm-green-600) 50%, var(--fm-rule) 50%); }

/* ---- Question sections ---- */
.fm-section {
    background: var(--fm-surface);
    border: 1px solid var(--fm-rule);
    border-left: 4px solid var(--fm-green-600);
    border-radius: var(--fm-radius-card);
    padding: var(--fm-5);
    margin-bottom: var(--fm-5);
}
@media (min-width: 768px) { .fm-section { padding: var(--fm-8); } }
.fm-section__head { margin-bottom: var(--fm-6); padding-bottom: var(--fm-4); border-bottom: 1px solid var(--fm-rule-soft); }
.fm-section__title { font-size: var(--fm-text-xl); font-weight: 650; margin: 0 0 var(--fm-2); letter-spacing: -0.01em; }
.fm-section__desc { color: var(--fm-ink-soft); }
.fm-section__desc :last-child { margin-bottom: 0; }

.fm-actions {
    display: flex; gap: var(--fm-3); align-items: center;
    padding-top: var(--fm-5);
    border-top: 1px solid var(--fm-rule-soft);
    margin-top: var(--fm-6);
}
.fm-actions__spacer { flex: 1; }

/* On a phone the navigation sticks to the bottom so it is always in reach. */
@media (max-width: 767.98px) {
    .fm-actions {
        position: sticky; bottom: 0; z-index: 30;
        margin: var(--fm-6) calc(var(--fm-5) * -1) calc(var(--fm-5) * -1);
        padding: var(--fm-3) var(--fm-5) calc(var(--fm-3) + env(safe-area-inset-bottom));
        background: var(--fm-surface);
        border-top: 1px solid var(--fm-rule);
        border-radius: 0 0 var(--fm-radius-card) var(--fm-radius-card);
    }
    .fm-actions .fm-btn { flex: 1; padding: 0 var(--fm-3); }
    .fm-actions__spacer { display: none; }
}

.fm-autosave { font-size: var(--fm-text-sm); color: var(--fm-muted); display: flex; align-items: center; gap: var(--fm-2); }
.fm-autosave.is-saving { color: var(--fm-info); }
.fm-autosave.is-saved  { color: var(--fm-green-600); }

/* ---- Completion receipt: the one moment that gets to be memorable ---- */
.fm-receipt { max-width: 34rem; margin: 0 auto; text-align: center; }
.fm-receipt__mark {
    width: 72px; height: 72px; margin: 0 auto var(--fm-5);
    display: grid; place-items: center;
    background: var(--fm-green-050);
    border: 2px solid var(--fm-green-600);
    border-radius: 50%;
    color: var(--fm-green-600); font-size: 2rem;
}
.fm-receipt__title { font-size: var(--fm-text-2xl); font-weight: 700; margin-bottom: var(--fm-3); letter-spacing: -0.015em; }
.fm-receipt__text  { color: var(--fm-ink-soft); margin-bottom: var(--fm-8); }

.fm-stub {
    position: relative;
    background: var(--fm-surface);
    border: 1px solid var(--fm-rule);
    border-radius: var(--fm-radius-card);
    padding: var(--fm-6) var(--fm-5) var(--fm-5);
    text-align: left;
}

/* The perforation: this is a receipt stub you tear off and keep.
   It is a real element sitting between the code and the details, rather than
   an absolutely positioned line at 50% — at a fixed percentage it landed
   wherever the content happened to be and struck through a row of text. */
.fm-stub__perf {
    position: relative;
    height: 0;
    border-top: 2px dashed var(--fm-rule);
    /* Negative margins equal to the card padding, so the line and its notches
       reach the card edges. */
    margin: var(--fm-6) calc(var(--fm-5) * -1) var(--fm-5);
}
.fm-stub__notch {
    position: absolute; top: -11px;
    width: 20px; height: 20px;
    background: var(--fm-paper);
    border: 1px solid var(--fm-rule);
    border-radius: 50%;
}
.fm-stub__notch--l { left: -11px;  clip-path: inset(0 0 0 50%); }
.fm-stub__notch--r { right: -11px; clip-path: inset(0 50% 0 0); }

.fm-stub__label { font-size: var(--fm-text-sm); color: var(--fm-muted); margin-bottom: var(--fm-2); }
.fm-stub__code {
    font-size: var(--fm-text-2xl);
    font-weight: 700;
    letter-spacing: 0.06em;
    font-variant-numeric: tabular-nums;
    color: var(--fm-green-800);
    word-break: break-all;
}
.fm-stub__rows { display: grid; gap: var(--fm-3); }
.fm-stub__row { display: flex; justify-content: space-between; gap: var(--fm-4); font-size: var(--fm-text-sm); }
.fm-stub__row dt { color: var(--fm-muted); }
.fm-stub__row dd { margin: 0; font-weight: 600; text-align: right; }

/* --------------------------------------------------------------------------
   15. Builder
   -------------------------------------------------------------------------- */
.fm-builder { display: grid; gap: var(--fm-5); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) {
    .fm-builder { grid-template-columns: 15rem minmax(0, 1fr) 17rem; gap: var(--fm-6); align-items: start; }
}

.fm-palette { position: sticky; top: calc(var(--fm-topbar) + var(--fm-4)); }
.fm-palette__group { margin-bottom: var(--fm-5); }
.fm-palette__title { font-size: var(--fm-text-sm); font-weight: 650; color: var(--fm-muted); margin-bottom: var(--fm-2); }
.fm-palette__list { display: grid; gap: var(--fm-1); }
.fm-palette__item {
    display: flex; align-items: center; gap: var(--fm-3);
    width: 100%; min-height: 44px;
    padding: var(--fm-2) var(--fm-3);
    background: var(--fm-surface);
    border: 1px solid var(--fm-rule);
    border-radius: var(--fm-radius-field);
    font: inherit; font-size: var(--fm-text-sm); font-weight: 500;
    color: var(--fm-ink); text-align: left; cursor: pointer;
    transition: border-color .12s var(--fm-ease), background-color .12s var(--fm-ease);
}
.fm-palette__item:hover { border-color: var(--fm-green-600); background: var(--fm-green-050); }
.fm-palette__item i { color: var(--fm-green-700); width: 18px; text-align: center; flex: none; }

/* On phones the palette becomes a horizontal strip. */
@media (max-width: 1099.98px) {
    .fm-palette { position: static; }
    .fm-palette__list { display: flex; gap: var(--fm-2); overflow-x: auto; padding-bottom: var(--fm-2); -webkit-overflow-scrolling: touch; }
    .fm-palette__item { flex: none; width: auto; }
}

.fm-qcard {
    position: relative;
    background: var(--fm-surface);
    border: 1px solid var(--fm-rule);
    border-radius: var(--fm-radius-card);
    padding: var(--fm-4);
    margin-bottom: var(--fm-3);
    transition: border-color .12s var(--fm-ease), box-shadow .12s var(--fm-ease);
}
.fm-qcard:hover { border-color: var(--line-strong); }
.fm-qcard.is-open { border-left: 4px solid var(--fm-green-600); box-shadow: var(--fm-shadow-raise); }
.fm-qcard.is-dragging { opacity: .55; }
.fm-qcard.fm-drop-target { border-color: var(--fm-green-600); border-style: dashed; }

.fm-qcard__bar { display: flex; align-items: center; gap: var(--fm-2); margin-bottom: var(--fm-3); }
.fm-qcard__handle { cursor: grab; color: var(--fm-faint); width: 32px; height: 32px; display: grid; place-items: center; border-radius: 6px; background: none; border: 0; flex: none; }
.fm-qcard__handle:hover { background: var(--fm-sunken); color: var(--fm-ink); }
.fm-qcard__handle:active { cursor: grabbing; }
.fm-qcard__type { display: inline-flex; align-items: center; gap: var(--fm-2); font-size: var(--fm-text-sm); color: var(--fm-muted); font-weight: 500; }
.fm-qcard__grow { flex: 1; }
.fm-qcard__tools { display: flex; gap: var(--fm-1); }
.fm-qcard__tool { width: 36px; height: 36px; display: grid; place-items: center; background: none; border: 0; border-radius: 6px; color: var(--fm-muted); cursor: pointer; }
.fm-qcard__tool:hover { background: var(--fm-sunken); color: var(--fm-ink); }
.fm-qcard__tool--danger:hover { background: var(--fm-danger-bg); color: var(--fm-danger); }

.fm-qcard__preview { padding-left: var(--fm-8); }
.fm-qcard__q { font-weight: 600; margin-bottom: var(--fm-1); }
.fm-qcard__ghost { color: var(--fm-faint); font-size: var(--fm-text-sm); }

.fm-qcard__editor { padding-left: var(--fm-8); border-top: 1px solid var(--fm-rule-soft); margin-top: var(--fm-3); padding-top: var(--fm-4); }
.fm-opt-row { display: flex; align-items: center; gap: var(--fm-2); margin-bottom: var(--fm-2); }
.fm-opt-row .fm-input { min-height: 42px; }
.fm-opt-row__grip { color: var(--fm-faint); cursor: grab; flex: none; width: 20px; text-align: center; }

.fm-step-head {
    display: flex; align-items: center; gap: var(--fm-3);
    padding: var(--fm-3) var(--fm-4);
    background: var(--fm-green-050);
    border: 1px solid var(--fm-green-100);
    border-radius: var(--fm-radius-field);
    margin-bottom: var(--fm-3);
}
.fm-step-head__n { width: 26px; height: 26px; display: grid; place-items: center; background: var(--fm-green-800); color: #fff; border-radius: 50%; font-size: 12px; font-weight: 700; flex: none; }

/* The step card. builder.js builds head + instructions + field list inside this
   wrapper; without a rule here the three sit flush against one another and the
   canvas reads as one undifferentiated column of fields. */
.fm-step {
    border: 1px solid var(--fm-rule);
    border-radius: var(--fm-radius-card);
    background: var(--fm-surface);
    padding: var(--fm-4);
    margin-bottom: var(--fm-5);
}
.fm-step:last-child { margin-bottom: 0; }
.fm-step.is-dragging { opacity: .6; }
.fm-step-fields { display: flex; flex-direction: column; gap: var(--fm-3); margin-top: var(--fm-3); }
.fm-step-fields:empty::after {
    content: "No questions in this section yet.";
    display: block; padding: var(--fm-5); text-align: center;
    border: 1px dashed var(--fm-rule); border-radius: var(--fm-radius-field);
    color: var(--fm-muted); font-size: var(--fm-text-sm);
}

/* Hint shown under a control rather than under a label — same voice as .fm-hint,
   but it follows its field instead of preceding it, so the margins invert. */
.fm-field__hint {
    margin: var(--fm-2) 0 0;
    font-size: var(--fm-text-sm);
    color: var(--fm-muted);
}

.fm-row-check { width: 18px; height: 18px; accent-color: var(--fm-green-600); cursor: pointer; }

.fm-inspector { position: sticky; top: calc(var(--fm-topbar) + var(--fm-4)); }
@media (max-width: 1099.98px) { .fm-inspector { position: static; } }

.fm-switch { display: flex; align-items: center; justify-content: space-between; gap: var(--fm-3); padding: var(--fm-3) 0; min-height: 48px; cursor: pointer; }
.fm-switch__text { flex: 1; min-width: 0; }
.fm-switch__label { font-weight: 500; font-size: var(--fm-text-sm); }
.fm-switch__hint { font-size: var(--fm-text-xs); color: var(--fm-muted); }
.fm-switch input { flex: none; width: 20px; height: 20px; accent-color: var(--fm-green-600); }
.fm-switch + .fm-switch { border-top: 1px solid var(--fm-rule-soft); }

/* --------------------------------------------------------------------------
   16. Analytics
   -------------------------------------------------------------------------- */
.fm-chart { position: relative; height: 240px; }
.fm-chart--tall { height: 320px; }

.fm-bars { display: grid; gap: var(--fm-3); }
.fm-bar__top { display: flex; justify-content: space-between; gap: var(--fm-4); font-size: var(--fm-text-sm); margin-bottom: var(--fm-1); }
.fm-bar__label { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-bar__value { color: var(--fm-muted); flex: none; font-variant-numeric: tabular-nums; }
.fm-bar__track { height: 10px; background: var(--fm-sunken); border-radius: var(--fm-radius-pill); overflow: hidden; }
.fm-bar__fill { height: 100%; background: var(--fm-green-600); border-radius: var(--fm-radius-pill); transition: width .4s var(--fm-ease); }

.fm-qsummary { border: 1px solid var(--fm-rule); border-radius: var(--fm-radius-card); background: var(--fm-surface); margin-bottom: var(--fm-4); overflow: hidden; }
.fm-qsummary__head { padding: var(--fm-4) var(--fm-5); border-bottom: 1px solid var(--fm-rule-soft); }
.fm-qsummary__q { font-weight: 650; }
.fm-qsummary__meta { font-size: var(--fm-text-sm); color: var(--fm-muted); margin-top: var(--fm-1); }
.fm-qsummary__body { padding: var(--fm-5); }

.fm-quotes { display: grid; gap: var(--fm-2); max-height: 18rem; overflow-y: auto; }

/* These are anchors, so the colour and underline have to be reset explicitly
   or the browser default turns a quote card into a blue hyperlink. */
.fm-quote {
    display: block;
    padding: var(--fm-3) var(--fm-4);
    background: var(--fm-sunken);
    border-left: 3px solid var(--fm-rule);
    border-radius: var(--fm-radius-field);
    font-size: var(--fm-text-sm);
    color: var(--fm-ink);
    text-decoration: none;
    transition: border-color .12s var(--fm-ease), background-color .12s var(--fm-ease);
}
.fm-quote:hover {
    border-left-color: var(--fm-green-600);
    background: var(--fm-green-050);
    color: var(--fm-ink);
}

/* --------------------------------------------------------------------------
   17. Messaging
   -------------------------------------------------------------------------- */
.fm-inbox { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--fm-5); }
@media (min-width: 992px) { .fm-inbox { grid-template-columns: 22rem minmax(0, 1fr); align-items: start; } }

.fm-threadlist { border: 1px solid var(--fm-rule); border-radius: var(--fm-radius-card); background: var(--fm-surface); overflow: hidden; }
.fm-threadlist__scroll { max-height: 70vh; overflow-y: auto; }

.fm-thread {
    display: block; width: 100%; text-align: left;
    padding: var(--fm-4);
    background: none; border: 0; border-bottom: 1px solid var(--fm-rule-soft);
    cursor: pointer; font: inherit; color: inherit;
}
.fm-thread:hover { background: var(--fm-green-050); }
.fm-thread.is-current { background: var(--fm-green-100); }
.fm-thread.is-unread .fm-thread__subject { font-weight: 700; }
.fm-thread.is-unread::after { content: ""; }
.fm-thread__top { display: flex; align-items: baseline; justify-content: space-between; gap: var(--fm-3); }
.fm-thread__who { font-weight: 600; font-size: var(--fm-text-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-thread__time { font-size: var(--fm-text-xs); color: var(--fm-muted); flex: none; }
.fm-thread__subject { font-size: var(--fm-text-sm); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-thread__preview { font-size: var(--fm-text-sm); color: var(--fm-muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.fm-conv { border: 1px solid var(--fm-rule); border-radius: var(--fm-radius-card); background: var(--fm-surface); display: flex; flex-direction: column; min-height: 26rem; }
.fm-conv__head { padding: var(--fm-4) var(--fm-5); border-bottom: 1px solid var(--fm-rule-soft); display: flex; align-items: center; gap: var(--fm-3); }
.fm-conv__body { flex: 1; padding: var(--fm-5); display: flex; flex-direction: column; gap: var(--fm-4); max-height: 52vh; overflow-y: auto; }
.fm-conv__foot { padding: var(--fm-4) var(--fm-5); border-top: 1px solid var(--fm-rule-soft); }

.fm-msg { max-width: 85%; }
.fm-msg__bubble { padding: var(--fm-3) var(--fm-4); border-radius: var(--fm-radius-card); background: var(--fm-sunken); }
.fm-msg__bubble p:last-child { margin-bottom: 0; }
.fm-msg__meta { font-size: var(--fm-text-xs); color: var(--fm-muted); margin-top: var(--fm-1); display: flex; align-items: center; gap: var(--fm-2); }
.fm-msg--mine { margin-left: auto; }
.fm-msg--mine .fm-msg__bubble { background: var(--fm-green-800); color: #fff; }
.fm-msg--mine .fm-msg__bubble a { color: var(--edo-200); }
.fm-msg--mine .fm-msg__meta { justify-content: flex-end; }
.fm-msg--note .fm-msg__bubble { background: var(--fm-attention-bg); border: 1px dashed var(--fm-attention); }

.fm-msg__read { color: var(--fm-green-600); }

/* --------------------------------------------------------------------------
   18. Modal, toast, misc
   -------------------------------------------------------------------------- */
.fm-modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: var(--fm-4); background: rgba(7, 43, 33, .55); }
.fm-modal__panel { width: 100%; max-width: 34rem; max-height: 88vh; overflow-y: auto; background: var(--fm-surface); border-radius: var(--fm-radius-card); box-shadow: var(--fm-shadow-float); }
.fm-modal__head { display: flex; align-items: center; justify-content: space-between; gap: var(--fm-4); padding: var(--fm-5); border-bottom: 1px solid var(--fm-rule-soft); }
.fm-modal__body { padding: var(--fm-5); }
.fm-modal__foot { display: flex; justify-content: flex-end; gap: var(--fm-3); padding: var(--fm-5); border-top: 1px solid var(--fm-rule-soft); }
@media (max-width: 575.98px) {
    .fm-modal { padding: 0; align-items: flex-end; }
    .fm-modal__panel { max-width: none; max-height: 92vh; border-radius: var(--fm-radius-card) var(--fm-radius-card) 0 0; }
    .fm-modal__foot { flex-direction: column-reverse; padding-bottom: calc(var(--fm-5) + env(safe-area-inset-bottom)); }
    .fm-modal__foot .fm-btn { width: 100%; }
}

.fm-toasts { position: fixed; z-index: 120; top: calc(var(--fm-topbar) + var(--fm-3)); right: var(--fm-4); left: var(--fm-4); display: grid; gap: var(--fm-2); pointer-events: none; }
@media (min-width: 576px) { .fm-toasts { left: auto; width: 23rem; } }

.fm-toast {
    display: flex; align-items: flex-start; gap: var(--fm-3);
    padding: var(--fm-3) var(--fm-4);
    background: var(--inverse-bg); color: var(--inverse-fg);
    border-radius: var(--fm-radius-field);
    box-shadow: var(--fm-shadow-float);
    font-size: var(--fm-text-sm);
    pointer-events: auto;
    animation: fm-toast-in .22s var(--fm-ease);
}
.fm-toast--success { background: var(--fm-green-700); }
.fm-toast--error   { background: var(--fm-danger); }
.fm-toast__close { background: none; border: 0; color: inherit; opacity: .7; cursor: pointer; padding: 0 0 0 var(--fm-2); font-size: 1rem; }
.fm-toast.is-leaving { animation: fm-toast-out .2s var(--fm-ease) forwards; }
@keyframes fm-toast-in  { from { opacity: 0; transform: translateY(-8px); } }
@keyframes fm-toast-out { to   { opacity: 0; transform: translateY(-8px); } }

.fm-chip { display: inline-flex; align-items: center; gap: var(--fm-2); padding: var(--fm-1) var(--fm-3); background: var(--fm-sunken); border-radius: var(--fm-radius-pill); font-size: var(--fm-text-sm); }
.fm-chip__x { background: none; border: 0; cursor: pointer; color: var(--fm-muted); padding: 0; line-height: 1; }

.fm-skeleton { background: linear-gradient(90deg, var(--fm-sunken) 25%, var(--fm-rule-soft) 50%, var(--fm-sunken) 75%); background-size: 200% 100%; animation: fm-shimmer 1.3s linear infinite; border-radius: var(--fm-radius-field); }
@keyframes fm-shimmer { to { background-position: -200% 0; } }

.fm-divider { border: 0; border-top: 1px solid var(--fm-rule); margin: var(--fm-6) 0; }

/* Layout helpers */
.fm-stack > * + * { margin-top: var(--fm-4); }
.fm-row { display: flex; flex-wrap: wrap; gap: var(--fm-3); align-items: center; }
.fm-grid-2 { display: grid; gap: var(--fm-4); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 768px) { .fm-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.fm-field--half  { grid-column: span 1; }
.fm-hide-sm { display: none; }
@media (min-width: 768px) { .fm-hide-sm { display: revert; } .fm-only-sm { display: none; } }

@media print {
    .fm-topbar, .fm-tabbar, .fm-actions, .fm-toolbar, .fm-bulkbar, .fm-toasts { display: none !important; }
    .fm-app { background: var(--surface); }
    .fm-card, .fm-section, .fm-stub { border: 1px solid var(--line-strong); box-shadow: none; break-inside: avoid; }
}


/* --------------------------------------------------------------------------
   The unified shell owns navigation now. These rules remain in the file above
   because the original markup still references them on pages not yet migrated;
   where the new shell is in use they must not paint a second bar.
   -------------------------------------------------------------------------- */
.app .fm-topbar, .app .fm-tabbar { display: none !important; }
.app .fm-app { background: transparent; }
.app .fm-main { padding: 0; max-width: none; }
