/* shared/forms/page.css
   The federal forms page module (shared/forms/page.js). Tokens from batesstamp/brand.css;
   panels, controls and buttons from batesstamp/styles.css. */

.ff-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
    gap: var(--s6);
    align-items: start;
}

/* Reserves the form's space until start.js mounts it, so the About and FAQ sections do not jump.
   Only with scripting on, since without it the form never mounts; not on Fill your own PDF
   (data-generic), whose root is mounted at once and stays small until a file is chosen; released
   (ff-blocked, set by boot.js) when a library fails to load and the form will never mount. */
@media (scripting: enabled) {
    #form-root:empty:not([data-generic]):not(.ff-blocked) {
        min-height: 100vh;
    }
}

/* Section navigation stays above the form while it scrolls. */
.ff-nav {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    gap: var(--s1) var(--s4);
    margin-bottom: var(--s4);
    padding: var(--s3) var(--s4);
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
}

/* Targets at least 24px tall (WCAG 2.5.8); the negative margin keeps the text where it was. */
.ff-nav a {
    display: inline-block;
    min-height: 24px;
    padding: 2px 4px;
    margin: -2px -4px;
    color: var(--navy);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
}

.ff-nav a:hover {
    text-decoration: underline;
}

.ff-section {
    scroll-margin-top: 72px;
}

.ff-section > summary {
    list-style: none;
    cursor: pointer;
}

.ff-section > summary::-webkit-details-marker {
    display: none;
}

.ff-section > summary .section-title {
    margin-bottom: 0;
}

.ff-section[open] > summary .section-title {
    margin-bottom: var(--s4);
}

/* A drawn chevron in place of the disclosure triangle. */
.ff-section > summary .section-title::before {
    content: '';
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg);
    transition: transform var(--transition);
}

.ff-section[open] > summary .section-title::before {
    transform: rotate(45deg);
}

.ff-optional {
    font-size: 0.8125rem;
    font-weight: 400;
    color: var(--muted);
}

.ff-label {
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--ink);
}

.ff-readonly {
    display: block;
    min-height: 40px;
    padding: 8px 12px;
    font-size: 0.9375rem;
    color: var(--text-2);
    background: var(--sunken);
    border-radius: var(--radius-sm);
}

.ff-error {
    margin-top: var(--s1);
    font-size: 0.875rem;
    color: var(--error);
}

.ff-page [aria-invalid="true"] {
    border-color: var(--error);
}

/* The district picker: a text box with a filtered list under it. */
.ff-district {
    position: relative;
}

.ff-district-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 30;
    max-height: 288px;
    margin: 0;
    padding: 4px 0;
    overflow-y: auto;
    list-style: none;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.ff-district-option {
    padding: 8px 12px;
    font-size: 0.9375rem;
    color: var(--text-heading);
    cursor: pointer;
}

.ff-district-option:hover {
    background: var(--gray-100);
}

.ff-district-option[aria-selected="true"] {
    background: var(--navy);
    color: var(--white);
}

.ff-district-none {
    padding: 8px 12px;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.ff-choice,
.ff-attorney {
    margin: 0;
    padding: 0;
    border: 0;
}

.ff-choice legend,
.ff-attorney legend,
.ff-card legend {
    margin-bottom: var(--s2);
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--ink);
}

.ff-choice .checkbox-group {
    margin-top: var(--s1);
}

.ff-choice .checkbox-group label,
.ff-page .checkbox-group label {
    margin: 0;
    font-weight: 400;
}

.ff-page .ff-exhibit-text {
    min-height: 16em;
}

.ff-exhibit-toggle {
    margin: 0 0 var(--s4);
}

.ff-card {
    margin: 0 0 var(--s4);
    padding: var(--s4);
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
}

.ff-card legend {
    padding: 0 var(--s1);
}

/* The exhibit text as it will print: a paper-like block under the textarea. */
.ff-exhibit-preview {
    margin: var(--s2) 0 0;
    padding: var(--s3) var(--s4);
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
    font-family: var(--font-display);
    font-size: 0.875rem;
    line-height: 1.4;
    color: var(--text);
    overflow-wrap: anywhere;
}

.ff-exhibit-preview h4 {
    margin: var(--s2) 0;
    /* Centred, as the exhibit page draws its headings. */
    text-align: center;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
}

.ff-exhibit-preview p,
.ff-exhibit-preview ol,
.ff-exhibit-preview ul {
    margin: 0 0 var(--s2);
}

.ff-exhibit-preview ol,
.ff-exhibit-preview ul {
    padding-left: var(--s5);
}

.ff-exhibit-preview .ff-exhibit-sub {
    padding-left: var(--s5);
}

.ff-exhibit-preview > :first-child {
    margin-top: 0;
}

.ff-exhibit-preview > :last-child {
    margin-bottom: 0;
}

/* Duplicate and Remove, side by side at the foot of a card. */
.ff-card > .ff-link + .ff-link {
    margin-left: var(--s3);
}

/* A link-styled button, at least 24px tall (WCAG 2.5.8); the negative margin keeps its text in
   line with the words around it. */
.ff-link {
    display: inline-block;
    min-height: 24px;
    padding: 2px 4px;
    margin: -2px -4px;
    background: none;
    border: 0;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--navy);
    text-decoration: underline;
    cursor: pointer;
}

.ff-link:hover {
    color: var(--navy-hover);
}

/* The preview and the download stay in view beside the form. */
.ff-side {
    position: sticky;
    top: var(--s5);
    display: flex;
    flex-direction: column;
    gap: var(--s3);
    max-height: calc(100vh - 2 * var(--s5));
    overflow-y: auto;
}

.ff-preview,
.ff-check,
.ff-download-bar {
    flex: none;
    padding: var(--s3) var(--s4);
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
}

.ff-canvas-wrap {
    position: relative;
    min-height: 120px;
    background: var(--sunken);
}

.ff-canvas {
    display: block;
    margin: 0 auto;
    box-shadow: var(--shadow-sm);
}

/* The side preview's canvas is a button that opens the page at full size. */
.ff-zoom-open {
    display: block;
    width: fit-content;
    margin: 0 auto;
    padding: 0;
    background: none;
    border: 0;
    line-height: 0;
    cursor: zoom-in;
}

/* The full-size preview: a modal dialog as wide as the screen allows, up to 1000px, that
   scrolls when the page is taller than the screen. */
.ff-zoom {
    width: min(100vw - 2 * var(--gutter), 1000px);
    max-width: none;
    max-height: calc(100vh - 2 * var(--gutter));
    margin: auto;
    padding: 0;
    overflow-y: auto;
    /* The scrollbar a tall page brings does not narrow the page drawn for the width before it. */
    scrollbar-gutter: stable;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.ff-zoom::backdrop {
    /* brand.css has no scrim token: --ink's RGB at 60%, as the phone bar's shadow uses it. */
    background: rgba(20, 35, 58, 0.6);
}

.ff-zoom-head {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: var(--s2);
    padding: var(--s3) var(--s4);
    font-size: 0.875rem;
    color: var(--text-2);
    background: var(--surface);
    border-bottom: 1px solid var(--rule);
}

.ff-zoom-head .ff-zoom-close {
    margin-left: auto;
}

.ff-zoom-body {
    padding: var(--s4);
    background: var(--sunken);
}

.ff-zoom-canvas {
    display: block;
    box-shadow: var(--shadow-sm);
}

.ff-outline {
    position: absolute;
    border: 2px solid var(--gold);
    border-radius: 2px;
    background: rgba(201, 162, 39, 0.14);
    pointer-events: none;
}

.ff-outline[hidden] {
    display: none;
}

.ff-pager {
    display: flex;
    align-items: center;
    gap: var(--s2);
    margin-top: var(--s3);
    font-size: 0.875rem;
    color: var(--text-2);
}

.ff-page-label {
    min-width: 7em;
    text-align: center;
}

.ff-pager .ff-recipient-select {
    width: auto;
    margin-left: auto;
    min-height: 36px;
}

.ff-icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--control);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.ff-icon-button:disabled {
    color: var(--muted);
    background: var(--sunken);
    cursor: not-allowed;
}

.ff-check h3 {
    margin: 0 0 var(--s3);
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--ink);
}

.ff-check dl {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: var(--s1) var(--s3);
    margin: 0;
    font-size: 0.875rem;
}

.ff-check dt {
    color: var(--text-2);
}

.ff-check dd {
    margin: 0;
    white-space: pre-line;
    overflow-wrap: anywhere;
    color: var(--text);
}

.ff-warnings {
    margin: 0;
    padding: var(--s3) var(--s4) var(--s3) var(--s6);
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text);
    background: var(--warning-bg);
    border-left: 3px solid var(--warning);
    border-radius: var(--radius-sm);
}

/* Beside the form, a long list scrolls in its own box so the preview keeps its room. */
@media (min-width: 900px) {
    .ff-warnings {
        flex: none;
        max-height: max(7.5rem, 22vh);
        overflow-y: auto;
    }
}

.ff-warnings:empty {
    display: none;
}

/* "Show all N warnings" / "Show fewer", after the first three. */
.ff-warnings .ff-warnings-more {
    margin-top: var(--s1);
    list-style: none;
}

.ff-download-bar .button {
    width: 100%;
}

.ff-download-bar .status:empty {
    display: none;
}

.ff-note {
    margin-top: var(--s2);
    font-size: 0.875rem;
    color: var(--text-2);
}

.ff-notice:empty {
    display: none;
}

.ff-notice {
    margin-bottom: var(--s4);
    padding: var(--s3) var(--s4);
    background: var(--warning-bg);
    border-radius: var(--radius-sm);
}

/* "Preview" opens the full-size preview from the bar; only on phones, where the preview is far
   below the form. A 44px target. */
.ff-preview-button {
    display: none;
}

/* Wide screens: the options sit under the button in the side column. */
.ff-bar-options .checkbox-group {
    margin-top: var(--s2);
}

/* Text pasted from saved details, the restored draft, and the Clear confirmation. */
.ff-from-saved {
    margin: 0 0 var(--s3);
    font-size: 0.8125rem;
    color: var(--muted);
}

.ff-draft-notice {
    background: var(--sunken);
}

/* The exhibit editor's toolbar: plain buttons that write the markup at the caret. */
.ff-exhibit-tools {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s1);
    margin-bottom: var(--s1);
}

.ff-tool {
    min-height: 32px;
    padding: 4px 10px;
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--control);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.ff-tool:hover {
    background: var(--sunken);
}

/* A character no font can print: the one warning that is an error. */
.ff-warnings .ff-warning-error {
    color: var(--error);
    font-weight: 600;
}

/* "Before you serve": the form's practice reminders, collapsed under the download. */
.ff-serve {
    padding: var(--s3) var(--s4);
    font-size: 0.875rem;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
}

.ff-serve summary {
    min-height: 24px;
    line-height: 24px;
    font-weight: 600;
    color: var(--ink);
    cursor: pointer;
}

.ff-serve ul {
    margin: var(--s2) 0 0;
    padding-left: var(--s5);
    line-height: 1.5;
}

.ff-serve li + li {
    margin-top: var(--s1);
}

/* A field's longer help (form.json "helpMore"), collapsed: once before the recipient cards for a
   recipient field, after the control for a case-level one. */
.ff-help-more {
    margin: 0 0 var(--s4);
    padding: var(--s3) var(--s4);
    font-size: 0.875rem;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius-md);
}

.ff-help-more summary {
    min-height: 24px;
    line-height: 24px;
    font-weight: 600;
    color: var(--ink);
    cursor: pointer;
}

.ff-help-more p {
    margin: var(--s2) 0 0;
    line-height: 1.5;
    color: var(--text-2);
}

/* A field focused near the top is not hidden under the sticky section nav. */
html.ff-has-bar {
    scroll-padding-top: 72px;
}

/* Phone and narrow tablet: form first, preview below, and the download bar fixed to the bottom
   of the screen the whole time. page.js keeps --ff-bar-height at the bar's height so the page is
   padded by it and nothing ends up underneath. */
@media (max-width: 899px) {
    .ff-layout {
        grid-template-columns: minmax(0, 1fr);
        gap: var(--s5);
    }

    .ff-nav,
    .ff-side {
        position: static;
    }

    .ff-side {
        max-height: none;
        overflow: visible;
    }

    html.ff-has-bar body {
        padding-bottom: var(--ff-bar-height, 120px);
    }

    /* A field focused near the bottom scrolls clear of the fixed bar (WCAG 2.4.11). */
    html.ff-has-bar {
        scroll-padding-bottom: var(--ff-bar-height, 120px);
    }

    .ff-download-bar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        /* Under the site header (z-index 20), so the open Tools sheet covers the bar. */
        z-index: 15;
        padding: var(--s3) var(--gutter) calc(var(--s3) + env(safe-area-inset-bottom));
        background: var(--paper);
        border: 0;
        border-top: 1px solid var(--rule);
        border-radius: 0;
        box-shadow: 0 -4px 16px rgba(20, 35, 58, 0.08);
    }

    .ff-bar-options {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0 var(--s4);
    }

    .ff-bar-options .ff-note,
    .ff-bar-options .checkbox-group {
        margin-top: var(--s1);
        min-height: 0;
    }

    .ff-bar-options .ff-preview-button {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
        min-width: 44px;
        margin: var(--s1) 0 0;
        padding: 0 var(--s1);
    }

    .ff-download-bar .status {
        margin-top: var(--s2);
    }
}

/* A phone on its side: a fixed bar would take a third of the screen, so the bar stays in the
   page under the form, framed as on a wide screen, and the page is not padded for it. */
@media (max-width: 899px) and (max-height: 500px) {
    .ff-download-bar {
        position: static;
        padding: var(--s3) var(--s4);
        background: var(--surface);
        border: 1px solid var(--rule);
        border-radius: var(--radius-md);
        box-shadow: none;
    }

    html.ff-has-bar body {
        padding-bottom: 0;
    }

    html.ff-has-bar {
        scroll-padding-bottom: 0;
    }
}

/* Review: the names check and the practice checklist at the end of the form. */
.ff-review .ff-section-body {
    display: flex;
    flex-direction: column;
    gap: var(--s4);
}

.ff-review .ff-check[hidden] {
    display: none;
}
