/*
 * The public e-signature pages: the signing page (/esign/sign/<token>/) and
 * the mail opt-out page, on home/templates/esign/_public_base.html. Loaded
 * through the esignPublic bundle ({% render_bundle 'esignPublic' 'css' %} in
 * <head>), so states rendered without JavaScript are styled too (UI-1). The
 * pages run without MUI and their CSP has style-src 'self' (no inline
 * styles), so the theme's values are copied here as custom properties;
 * esignPublic.tokens.test.ts checks each against the theme.
 *
 * Classes the templates use:
 *   .es-header (56 px bar with the logo, 44 px on phones), .es-main, .es-footer
 *   .es-card; inside it .es-eyebrow, h1, h2, p, .es-secondary, .es-caption,
 *   .es-notice (role="status" for information), .es-details (the disclosure),
 *   .es-actions with .es-button.es-button--neutral first, then
 *   .es-button.es-button--primary (or --danger, the action that ends a
 *   request) last: the order on screen from 600 px;
 *   .es-button--danger-outline opens that action, with no more weight than a
 *   neutral button; .es-link-button for a text button;
 *   .es-keep holds Print and the disclosure page's link (UXD-5)
 *   The disclosure page (/esign-disclosure/v<version>): one .es-card article
 *   The frame view (esignPublic.ts sets data-es-view="frame" on <html>):
 *   a <section> > .es-frame-bar (.es-frame-heading > .es-frame-title,
 *   .es-frame-from; a.es-link-button.es-frame-pdf and
 *   a.es-icon-button.es-frame-pdf-icon, the unsigned PDF (OQ-28), one of
 *   them by width; .es-link-button.es-frame-decline; .es-frame-reload
 *   with .es-frame-reload-text, .es-link-button and .es-icon-button) and
 *   .es-frame-area > .es-frame, .es-overlay (.es-spinner), .es-cover
 *   (.es-panel; the decline panel's .es-field holds a label and a textarea).
 *   The section fills the window; the bar grows with its words and the
 *   frame area takes the rest.
 *   The panel the consent card's "no" opens: a .es-card of .es-choice blocks,
 *   each a button and the line that says what it does; the decline panel then
 *   stands in a .es-card of its own
 *   .es-visually-hidden
 */

@font-face {
    font-family: 'Plus Jakarta Sans';
    font-style: normal;
    font-display: swap;
    font-weight: 400;
    src: url(../media/plus-jakarta-sans-latin-400-normal.9eb2a7e5bc8f2a766ae0.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Plus Jakarta Sans';
    font-style: normal;
    font-display: swap;
    font-weight: 600;
    src: url(../media/plus-jakarta-sans-latin-600-normal.7720d76571fb9da9b24d.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Metrics close to the real face, so text keeps its box while it loads
   (as templates/react_landing.html). */
@font-face {
    font-family: 'Plus Jakarta Sans Fallback';
    src: local('Arial');
    size-adjust: 105.42%;
    ascent-override: 98.46%;
    descent-override: 21.06%;
    line-gap-override: 0%;
}

:root {
    /* theme/DefaultColors.tsx, light theme as the app builds it */
    --es-bg: #F2F6FA;                 /* grey.100 */
    --es-surface: #ffffff;            /* background.default */
    --es-divider: #e5eaef;            /* divider */
    --es-text: #2A3547;               /* text.primary */
    --es-text-secondary: #5A6A85;     /* grey.500, 5.5:1 on white */
    --es-input-border: #5B6F8F;       /* grey.400, 5.1:1 on white: a field's edge (WCAG 1.4.11) */
    --es-primary: #395FDA;            /* primary.main */
    --es-primary-dark: #2C4FC4;       /* primary.dark */
    --es-primary-light: #ECF2FF;      /* primary.light */
    --es-info-dark: #1565C0;          /* info.dark */
    --es-info-light: #EBF3FE;         /* info.light */
    --es-warning-dark: #8A5300;       /* warning.dark */
    --es-warning-light: #FEF5E5;      /* warning.light */
    --es-error-dark: #9E3B3B;         /* error.dark */
    --es-error-light: #FFD8D8;        /* error.light */
    /* theme/Typography.tsx */
    --es-font: 'Plus Jakarta Sans', 'Plus Jakarta Sans Fallback', sans-serif;
    /* shape.borderRadius; AppDialog's paper radius and L width */
    --es-radius-control: 7px;
    --es-radius-card: 16px;
    --es-card-width: 640px;
    /* an 8 px scale, the side gutter, phone tap targets, the header */
    --es-space-1: 8px;
    --es-space-2: 16px;
    --es-space-3: 24px;
    --es-space-4: 32px;
    --es-gutter: 16px;
    --es-tap: 44px;
    --es-header: 56px;
}

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

[hidden] { display: none !important; }

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

body {
    margin: 0;
    min-height: 100vh;
    background: var(--es-bg);
    color: var(--es-text);
    font-family: var(--es-font);
    font-size: 1rem;
    line-height: 1.6;
}

a { color: var(--es-primary); }
a:hover { color: var(--es-primary-dark); }

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

.es-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;
}

/* Header, main and footer of the base template */

.es-header {
    display: flex;
    align-items: center;
    height: var(--es-header);
    padding: 0 var(--es-gutter);
    background: var(--es-surface);
    border-bottom: 1px solid var(--es-divider);
}

.es-header img,
.es-frame-bar img {
    display: block;
    flex: none;
    width: auto;
    height: 30px;
}

/* The logo is a link to our home page (block brand in _public_base.html, and
   the frame bar), at least 30 px tall (WCAG 2.5.8); the ring is :focus-visible's. */
.es-brand {
    display: inline-flex;
    flex: none;
    align-items: center;
    border-radius: 4px;
}

.es-main { padding: 0 var(--es-gutter) var(--es-space-3); }

.es-footer {
    max-width: var(--es-card-width);
    margin: 0 auto;
    padding: 0 var(--es-gutter) var(--es-space-4);
    color: var(--es-text-secondary);
    font-size: 0.875rem;
    text-align: center;
}

.es-footer ul {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--es-space-1) var(--es-space-2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.es-footer a { color: inherit; }

/* The support address, kept out of the HTML (templatetags/esign_public.py)
   and shown by esignPublic.ts startEmailReveal. */
.es-email { overflow-wrap: anywhere; }

/* The support address before it is shown. */
.es-email-hidden {
    display: inline-block;
    padding: 0 6px;
    border: 0;
    border-radius: 6px;
    background: var(--es-divider);
    color: inherit;
    font: inherit;
    font-size: 0.75rem;
    cursor: pointer;
}

/* The card */

.es-card {
    max-width: var(--es-card-width);
    margin: var(--es-space-2) auto 0;
    padding: var(--es-space-2);
    background: var(--es-surface);
    border: 1px solid var(--es-divider);
    border-radius: var(--es-radius-card);
    overflow-wrap: anywhere;
}

/* theme h4: 21 px, 600 */
.es-card h1 {
    margin: 0 0 var(--es-space-1);
    font-size: 1.3125rem;
    font-weight: 600;
    line-height: 1.6rem;
}

.es-card h2 {
    margin: var(--es-space-3) 0 var(--es-space-1);
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.5;
}

.es-card p { margin: 0 0 var(--es-space-1); }

.es-card ul { margin: 0 0 var(--es-space-1); padding-left: 1.25em; }

.es-eyebrow {
    margin: 0 0 var(--es-space-1);
    color: var(--es-text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.es-secondary {
    color: var(--es-text-secondary);
    font-size: 0.875rem;
}

.es-caption {
    color: var(--es-text-secondary);
    font-size: 0.75rem;
}

.es-notice {
    margin: var(--es-space-2) 0;
    padding: 12px var(--es-space-2);
    border-radius: var(--es-radius-control);
    background: var(--es-warning-light);
    color: var(--es-warning-dark);
}

.es-notice[role="status"] {
    background: var(--es-info-light);
    color: var(--es-info-dark);
}

.es-details { margin: var(--es-space-2) 0; }

.es-details summary {
    padding: 10px 0;
    color: var(--es-primary);
    cursor: pointer;
}

/* Buttons: from 600 px one row, right aligned, the neutral one left of the
   primary. The DOM is that order, so Tab meets them as they are seen (WCAG
   2.4.3, 1.3.2). Under 600 px they stack with the primary on top
   (column-reverse), so there Tab reaches the neutral one, below, first. */

.es-actions {
    display: flex;
    flex-direction: column-reverse;
    gap: var(--es-space-1);
    margin-top: var(--es-space-3);
}

.es-choice { margin-top: var(--es-space-3); }

.es-choice .es-secondary { margin: var(--es-space-1) 0 0; }

.es-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: var(--es-tap);
    padding: 0 var(--es-space-2);
    border: 1px solid transparent;
    border-radius: var(--es-radius-control);
    background: transparent;
    color: var(--es-text);
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.es-button--primary {
    background: var(--es-primary);
    color: var(--es-surface);
}

.es-button--primary:hover { background: var(--es-primary-dark); }

.es-button--danger {
    background: var(--es-error-dark);
    color: var(--es-surface);
}

.es-button--danger:hover { filter: brightness(0.9); }

.es-button--danger-outline {
    border-color: var(--es-error-dark);
    color: var(--es-error-dark);
}

.es-button--danger-outline:hover { background: var(--es-error-light); }

.es-button--neutral { border-color: var(--es-divider); }

.es-button--neutral:hover { background: var(--es-bg); }

.es-button:disabled { cursor: progress; opacity: 0.7; }

/* Past .es-card p, or the line sits on what is above it. */
.es-card .es-keep {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--es-space-1) var(--es-space-2);
    margin: var(--es-space-2) 0 var(--es-space-1);
}

.es-keep a { color: var(--es-primary); }

form + .es-caption { margin-top: var(--es-space-2); }

.es-link-button {
    min-height: 24px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--es-primary);
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
}

@media (min-width: 600px) {
    .es-card {
        margin-top: var(--es-space-4);
        padding: var(--es-space-3);
    }

    .es-actions {
        flex-direction: row;
        justify-content: flex-end;
    }

    .es-button { width: auto; }
}

/* The frame view: the page's own header and footer give way to one 56 px
   bar, and the frame fills the rest of the window. */

html[data-es-view="frame"] body { overflow: hidden; overscroll-behavior: contain; }

html[data-es-view="frame"] .es-header,
html[data-es-view="frame"] .es-footer { display: none; }

html[data-es-view="frame"] .es-main { padding: 0; }

/* The frame view's section: the bar, then the frame area to the bottom of
   the window, however tall the bar grows. */
html[data-es-view="frame"] #esign-public-root > section,
html[data-es-view="frame"] .es-frame-box > section {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

@supports (height: 100dvh) {
    html[data-es-view="frame"] #esign-public-root > section,
    html[data-es-view="frame"] .es-frame-box > section { height: 100dvh; }
}

/* OQ-36: the frame view built at the Agree tap, while start/ is out. Fixed
   to the window, so it adds no scroll height under the card, and hidden
   (the script also makes it inert and aria-hidden); the answer shows it
   where it is, since an iframe that moves loads again. */
.es-frame-box--pending {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    visibility: hidden;
    pointer-events: none;
}

@supports (height: 100dvh) {
    .es-frame-box--pending { height: 100dvh; }
}

.es-frame-box--pending > section {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* The title and the sender wrap, so the whole of each reads at 320 px and
   with wider text spacing (WCAG 1.4.10, 1.4.12): the bar is at least 56 px
   and grows with them. */
.es-frame-bar {
    display: flex;
    flex: none;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px var(--es-space-1);
    min-height: var(--es-header);
    padding: 6px var(--es-gutter);
    background: var(--es-surface);
    border-bottom: 1px solid var(--es-divider);
}

.es-frame-heading { flex: 1 1 0; min-width: 0; }

.es-frame-title,
.es-frame-from {
    margin: 0;
    overflow-wrap: anywhere;
}

.es-frame-title {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.25;
}

.es-frame-from {
    color: var(--es-text-secondary);
    font-size: 0.75rem;
    line-height: 1.4;
}

.es-frame-reload {
    display: flex;
    flex: none;
    align-items: center;
    gap: var(--es-space-1);
    color: var(--es-text-secondary);
    font-size: 0.875rem;
}

.es-icon-button {
    display: none;
    align-items: center;
    justify-content: center;
    width: var(--es-tap);
    height: var(--es-tap);
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--es-primary-light);
    color: var(--es-primary);
    cursor: pointer;
}

@media (max-width: 599.98px) {
    .es-frame-reload-text,
    .es-frame-reload .es-link-button { display: none; }

    .es-frame-reload .es-icon-button { display: inline-flex; }

    /* OQ-37: a slimmer logo bar (the 30 px logo still fits) and the card's
       16 px top padding, so Agree sits nearer the first screen. */
    .es-header { height: 44px; }

    .es-card { padding-top: var(--es-space-2); }

    /* A phone's bar: the logo and the two actions on the first line, the
       title and the sender across the whole of the second. */
    .es-frame-heading { order: 1; flex-basis: 100%; }

    .es-frame-decline { margin-left: auto; }

    /* OQ-28: the 44 px PDF button, before Decline on the first line. */
    .es-frame-pdf { display: none; }

    .es-frame-pdf-icon {
        display: inline-flex;
        margin-left: auto;
    }

    .es-frame-pdf-icon:not([hidden]) ~ .es-frame-decline { margin-left: 0; }
}

/* A text button is 44 px tall under a finger: a phone-width window, or a
   touch screen at any width, a phone on its side included (QA-041, RC-06).
   Width alone still decides the layout above. */
@media (max-width: 599.98px), (pointer: coarse) {
    .es-link-button { min-height: var(--es-tap); }
}

.es-frame-pdf {
    flex: none;
    font-size: 0.875rem;
}

.es-frame-pdf-icon {
    flex: none;
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
}

.es-frame-decline {
    flex: none;
    font-size: 0.875rem;
}

/* Hidden while a panel covers the frame: the panel has its own way on. */
html[data-es-cover] .es-frame-reload,
html[data-es-cover] .es-frame-pdf,
html[data-es-cover] .es-frame-pdf-icon,
html[data-es-cover] .es-frame-decline { display: none; }

.es-frame-area {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
}

.es-frame,
.es-overlay,
.es-cover {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
}

.es-frame iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}

.es-overlay,
.es-cover {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--es-space-1);
    padding: var(--es-space-2);
    background: var(--es-surface);
    text-align: center;
}

.es-overlay {
    color: var(--es-text-secondary);
    transition: opacity 200ms ease-out;
}

.es-overlay--done { opacity: 0; pointer-events: none; }

/* A panel taller than the frame area (a phone on its side, a window the
   keyboard shrinks, large text) starts at the top and scrolls down, so its
   heading and warning are never cut off above (QA-043). The cover starts at
   the top; its panel's auto margins centre it while it fits and become 0
   when it does not. justify-content: center put half the overflow above the
   scroll origin, out of reach. */
.es-cover {
    justify-content: flex-start;
    overflow-y: auto;
}

.es-cover > .es-panel {
    margin-top: auto;
    margin-bottom: auto;
}

.es-panel { width: 100%; max-width: 480px; }

.es-panel h2 {
    margin: 0 0 var(--es-space-1);
    font-size: 1rem;
    font-weight: 600;
}

.es-panel .es-actions { justify-content: center; }

/* The finishing panel ("One moment…"): the spinner centred over its line,
   as on the loading overlay (a block 28 px wide stays at the left edge). */
.es-panel > .es-spinner {
    margin-right: auto;
    margin-bottom: var(--es-space-1);
    margin-left: auto;
}

/* The decline panel in a card of its own (no form open): the card's width
   and the card's buttons, right aligned from 600 px. */
.es-card .es-panel { max-width: none; }

.es-card .es-panel .es-actions { justify-content: flex-end; }

.es-field {
    margin-top: var(--es-space-2);
    text-align: left;
}

.es-field label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
}

.es-field textarea,
.es-field input {
    box-sizing: border-box;
    display: block;
    width: 100%;
    padding: var(--es-space-1);
    border: 1px solid var(--es-input-border);
    border-radius: var(--es-radius-control);
    font: inherit;
    resize: vertical;
}

.es-field .es-secondary { margin: 4px 0 0; }

/* F32: the star row under the won't-be-completed card. Five radios drawn as
   stars, each a 44 px target; up to the one picked a filled star, after it an
   outline, so the two differ in shape, not only hue (both 3:1 or more on the
   card: grey.400 5.1:1, primary.main 5.3:1). The comment field is 16 px so a
   phone does not zoom into it. */
.es-feedback { text-align: left; }
.es-stars { margin: 0; padding: 0; border: 0; min-width: 0; }
.es-stars legend { padding: 0; font-weight: 600; }
.es-stars-row { display: flex; gap: 4px; margin-top: var(--es-space-1); }
.es-star {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--es-tap);
    min-height: var(--es-tap);
    border-radius: var(--es-radius-control);
    color: var(--es-input-border);
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
}
.es-star:has(input:focus-visible) { outline: 2px solid var(--es-primary); outline-offset: 2px; }
.es-star .es-star-on { display: none; }
.es-star:has(input:checked),
.es-star:has(~ .es-star input:checked) { color: var(--es-primary); }
.es-star:has(input:checked) .es-star-on,
.es-star:has(~ .es-star input:checked) .es-star-on { display: inline; }
.es-star:has(input:checked) .es-star-off,
.es-star:has(~ .es-star input:checked) .es-star-off { display: none; }
.es-feedback .es-notice:focus { outline: none; }
.es-feedback .es-field textarea { font-size: 16px; }

.es-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--es-primary-light);
    border-top-color: var(--es-primary);
    border-radius: 50%;
    animation: es-spin 0.8s linear infinite;
}

@keyframes es-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .es-overlay { transition: none; }
    .es-spinner { animation-duration: 2.4s; }
}

/* Print keeps the consent and drops the controls (UXD-5). */
@media print {
    body { background: #ffffff; }

    .es-header,
    .es-footer,
    .es-actions,
    .es-notice,
    .es-keep,
    .es-details summary { display: none !important; }

    .es-card {
        max-width: none;
        margin: 0;
        padding: 0;
        border: 0;
    }
}

/* The failure panel's link to copy by hand when the clipboard fails (RC-12):
   16 px so iOS does not zoom when it is focused. */
.es-copy-box {
    display: block;
    margin-top: var(--es-space-2);
    text-align: left;
}

.es-copy-input {
    box-sizing: border-box;
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: var(--es-space-1);
    border: 1px solid var(--es-input-border);
    border-radius: var(--es-radius-control);
    font-family: inherit;
    font-size: 16px;
}

