/*
    EasySign - the entire stylesheet.

    Hand-written, no component library, no web fonts. The person this product exists to serve is a
    signer on prepaid mobile data using a cheap Android handset, and Bootstrap plus jQuery is about
    300 KB before a single line of our own code. A font file is another 100-300 KB and a
    render-blocking request, to change the shape of letters that were already legible.

    The design follows the two briefs held in docs/:

      Web Design Brief.md      Trust-forward B2B restraint. One typeface, about three brand
                               colours, whitespace as the layout tool, sections separated by
                               background BANDS rather than borders, flat surfaces, one CTA
                               vocabulary repeated everywhere, and a hard contrast rule.
                               Applied to the public pages.

      design-evaluation.md     The working-screen brief. Full viewport width, a left rail of
                               roughly a sixth, identical zone order in every row, warm off-white
                               ground with pure white cards, six colour families with exactly one
                               meaning each, two type weights, and every loud figure paired with a
                               quiet caption. Applied to the application screens.

    They do not conflict; they describe different surfaces. Buttons are the one thing deliberately
    shared across both, because "one CTA vocabulary" is worth more than surface-specific polish.

    The colour basis is the existing EasySign product: its blue, its navy grid headers, its pale
    blue banded rows, its six pastel signer colours, its dark user chip.

    House rules encoded here:
      - an application screen uses the width of the display, never a fixed 1200px column
      - running prose keeps a reading measure, so widening the frame never widens the line length
      - anything over ~300ms shows an obvious busy state that survives prefers-reduced-motion
      - colour is never the only signal
      - ASCII only
*/

/* =================================================================================================
   1. Tokens

   Six colour families, one meaning each, per design-evaluation.md section 3. Any more and the
   semantic mapping collapses - which is exactly what happened in the product being replaced, where
   a success message was rendered in the same red as the validation errors above it.

       blue     information, navigation, the primary action
       ink      text, dark bands, grid headers
       green    done, confirmed, signed
       amber    needs attention, held for review, on trial
       red      refused, failed, declined
       neutral  ground, hairlines, muted captions

   The signer palette below is a DATA palette, not a brand palette. It identifies which of six
   people a field belongs to and carries no other meaning, so it sits outside that count.
   ================================================================================================= */

:root {
    /* ---- Blue. Sampled from the existing product's Login and Save buttons. ------------------- */
    /* White on this blue measures 5.1:1, so unlike the worked example in the brief it can carry a
       white label safely. Measured rather than assumed - Web Design Brief.md section 3 is emphatic
       that a bright mid-tone hue usually cannot. */
    --brand:        #1668e0;
    --brand-deep:   #0f4fac;   /* hover and pressed; 8.0:1 on white */
    --brand-ink:    #0d3f8a;   /* the blue used at text size */
    --brand-tint:   #e4f0fb;   /* the banded form row, the active rail item */
    --brand-wash:   #f1f7fd;   /* the faintest band, for alternating sections */
    --navy:         #1a2b6d;   /* grid headers, exactly as the product does today */

    /* ---- Ink and neutrals ------------------------------------------------------------------- */
    --ink:          #16212b;
    --ink-soft:     #56646f;   /* darkened from the source palette to clear 4.5:1 on white */
    --line:         #dfe4e8;
    --line-soft:    #eceff2;
    --surface:      #ffffff;

    /* Warm off-white, not grey and not white. design-evaluation.md calls this the cheapest depth
       in the design, and it is right: a pure white card lifts off it with no shadow at all. */
    --ground:       #f5f5f1;

    /* ---- Semantic accents ------------------------------------------------------------------- */
    --good:         #1a6b3f;
    --good-bg:      #e8f5ed;
    --good-line:    #bcdfca;
    --warn:         #8a5200;
    --warn-bg:      #fdf4e3;
    --warn-line:    #f0dcb0;
    --bad:          #a4262c;
    --bad-bg:       #fdedee;
    --bad-line:     #f0c5c7;

    /* ---- The six signer colours, from the existing designer palette ------------------------- */
    --signer-1: #8f9fe8;
    --signer-2: #93d6a6;
    --signer-3: #e79a9a;
    --signer-4: #bdbc94;
    --signer-5: #9fd9d4;
    --signer-6: #dcaadd;
    --signer-cert: #cdcb63;

    /* ---- Type. One family, hierarchy by weight and size only. ------------------------------- */
    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace;

    --fs-caption: 0.75rem;     /* 12px - the quiet line under a loud figure */
    --fs-meta:    0.8125rem;   /* 13px */
    --fs-small:   0.875rem;    /* 14px */
    --fs-body:    1rem;        /* 16px floor. Below this iOS zooms a focused input. */
    --fs-lead:    1.1875rem;   /* 19px */
    --fs-h3:      1.25rem;
    --fs-h2:      1.5rem;
    --fs-h1:      1.9375rem;
    --fs-display: clamp(2.25rem, 1.4rem + 3vw, 3.0625rem);

    --lh-body: 1.6;
    --lh-head: 1.25;

    /* ---- Spacing, on an 8px scale ---------------------------------------------------------- */
    --s1: 0.25rem;  --s2: 0.5rem;  --s3: 1rem;   --s4: 1.5rem;
    --s5: 2rem;     --s6: 3rem;    --s7: 4rem;   --s8: 6rem;
    --band-pad: clamp(2.5rem, 6vw, 5rem);
    --gap: 1rem;

    /* ---- Shape. Pill buttons, softly rounded cards, square-ish controls. -------------------- */
    --radius-pill: 999px;
    --radius-card: 10px;
    --radius:      6px;
    --shadow-card: 0 1px 3px rgba(20, 40, 60, 0.10);
    --shadow-lift: 0 6px 24px rgba(20, 40, 60, 0.12);

    /* ---- The rail. About a sixth of the width, per design-evaluation.md section 2. ---------- */
    --rail-width: 15.5rem;
    --topbar-height: 3.75rem;
}

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

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

body {
    margin: 0;
    font-family: var(--font-ui);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    color: var(--ink);
    background: var(--surface);
}

/* =================================================================================================
   2. Typography

   Two weights carry the whole product: 400 for content, 700 for headings and emphasis. 600 is
   allowed only on small interface labels, where 700 at 13px reads as blunt rather than emphatic.
   ================================================================================================= */

h1, h2, h3, h4 { line-height: var(--lh-head); font-weight: 700; letter-spacing: -0.01em; }

h1 { font-size: var(--fs-h1); margin: 0 0 var(--s2); }
h2 { font-size: var(--fs-h2); margin: var(--s5) 0 var(--s2); }
h3 { font-size: var(--fs-h3); margin: var(--s4) 0 var(--s2); }

/* The one deliberate exception to full width: running text keeps a readable measure however wide
   the frame gets. Widening the layout must never widen the line length. */
p, .prose { max-width: 68ch; }

.lede { font-size: var(--fs-lead); color: var(--ink-soft); margin-top: 0; }

/*
    The eyebrow kicker. A small uppercase label above a heading, so the heading itself can stay one
    short line instead of carrying the context as well. It is the only place uppercase is used, and
    it replaces the centred underlined page titles in the product being replaced - those fight the
    left-to-right scan on a wide working screen.
*/
.eyebrow {
    display: block;
    font-size: var(--fs-meta);
    font-weight: 600;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--brand-ink);
    margin-bottom: var(--s1);
}

a { color: var(--brand-ink); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--brand-deep); }

/*
    Loud figure, quiet caption. design-evaluation.md section 4 makes the case: every prominent
    number is immediately qualified underneath, which is what makes a dense screen read as
    informative rather than assertive.
*/
.figure { display: block; font-size: var(--fs-h2); font-weight: 700; line-height: 1.15; }
.figure-caption { display: block; font-size: var(--fs-caption); color: var(--ink-soft); margin-top: 2px; }

.stat-row { display: flex; flex-wrap: wrap; gap: var(--s5) var(--s6); }

/* =================================================================================================
   3. Layout

   Two shells.

   The application shell is a fixed top bar, a left rail and a content column that takes everything
   left over - no fixed centre column, because a 1200px layout on a 2560px monitor leaves two
   thirds of the display empty while the user scrolls sideways past content that would have fitted.

   The public shell is a single column of full-width bands, alternating white, tint and ink.
   ================================================================================================= */

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.topbar-inner {
    display: flex;
    align-items: center;
    gap: var(--s3);
    min-height: var(--topbar-height);
    padding-inline: var(--s4);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--s2);
    font-size: 1.1875rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--ink);
    text-decoration: none;
    white-space: nowrap;
}

.brand:hover { color: var(--ink); }

/* The signature motif: a drawn stroke resting on a signing line. It is what the product does,
   rather than a generic padlock or document glyph. Web Design Brief.md section 7. */
.brand-mark { flex: 0 0 auto; display: block; color: var(--brand); }

.topbar-spacer { margin-left: auto; }

/*
    The user chip. Dark, so the identity of the person signed in is unmistakable against the white
    bar - carried over from the existing product, where it is the strongest element in the header.
*/
.user-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--s2);
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius-pill);
    background: var(--ink);
    color: #ffffff;
    font-size: var(--fs-small);
    font-weight: 600;
    white-space: nowrap;
}

.user-chip svg { flex: 0 0 auto; }

.shell { display: flex; align-items: stretch; min-height: calc(100vh - var(--topbar-height)); }

.rail {
    flex: 0 0 var(--rail-width);
    width: var(--rail-width);
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: var(--s4) 0 var(--s6);
}

.rail-group + .rail-group { margin-top: var(--s5); }

.rail-heading {
    margin: 0 var(--s4) var(--s2);
    padding-bottom: var(--s2);
    border-bottom: 1px solid var(--line);
    font-size: var(--fs-meta);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

.rail-item {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.6rem var(--s4);
    color: var(--ink);
    font-size: var(--fs-small);
    font-weight: 600;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background-color 0.12s ease;
}

.rail-item:hover { background: var(--brand-wash); color: var(--ink); }

/* The active state carries three signals, not one: tint, a left bar, and the aria-current
   attribute a screen reader announces. Colour is never doing this alone. */
.rail-item[aria-current="page"] {
    background: var(--brand-tint);
    border-left-color: var(--brand);
    color: var(--brand-ink);
}

.rail-item svg { flex: 0 0 auto; color: var(--ink-soft); }
.rail-item[aria-current="page"] svg { color: var(--brand); }

/*
    A section of the product that is designed but not yet built. Shown rather than hidden, because
    the shape of the product is part of what is being reviewed - and shown as plainly inert, with a
    word rather than a greyed-out link, so nobody clicks it expecting a screen.
*/
.rail-item.is-pending { color: var(--ink-soft); cursor: default; font-weight: 400; }
.rail-item.is-pending:hover { background: transparent; }
.rail-item.is-pending svg { opacity: 0.5; }
.rail-item .pill { margin-left: auto; }

.content {
    flex: 1 1 auto;
    min-width: 0;                /* without this a wide table stretches the flex item */
    background: var(--ground);
    padding: var(--s5) var(--s5) var(--s8);
}

/*
    An application surface fills the space it was given. Inside the shell the rail has already
    taken its share, so the content is simply 100% wide; standing alone it falls back to the house
    rule of 92% with a 1200px floor.
*/
.app-surface {
    width: min(100%, max(1200px, 92%));
    max-width: none;
    margin-inline: auto;
    padding-inline: var(--s3);
}

.shell .app-surface { width: 100%; padding-inline: 0; }

/* Single-column forms and legal prose are not application screens, so they keep a measure. */
.narrow { width: min(100%, 36rem); margin-inline: auto; padding-inline: var(--s3); }

.shell .narrow { margin-inline: 0; padding-inline: 0; }

/* A public page that is a single column rather than a set of bands still needs the band rhythm
   around it. Scoped away from the application shell, where the content column supplies its own. */
main:not(.content) > .narrow,
main:not(.content) > .app-surface { padding-block: var(--band-pad); }

/* ---- The mobile rail ------------------------------------------------------------------------
   Below the tablet breakpoint the rail becomes a horizontal strip above the content. It stays a
   plain scrolling list rather than a hamburger drawer, because a drawer needs JavaScript and an
   administrator on a cheap handset should not lose navigation when a script fails to load.
   --------------------------------------------------------------------------------------------- */

@media (max-width: 60rem) {
    .shell { display: block; }

    .rail {
        width: auto;
        display: flex;
        gap: var(--s1);
        overflow-x: auto;
        padding: var(--s2) var(--s3);
        border-right: 0;
        border-bottom: 1px solid var(--line);
        -webkit-overflow-scrolling: touch;
    }

    .rail-group { display: contents; }
    .rail-group + .rail-group { margin-top: 0; }
    .rail-heading { display: none; }

    .rail-item {
        flex: 0 0 auto;
        white-space: nowrap;
        border-left: 0;
        border-bottom: 3px solid transparent;
        border-radius: var(--radius);
        padding: 0.5rem 0.75rem;
    }

    .rail-item[aria-current="page"] { border-left: 0; border-bottom-color: var(--brand); }

    .content { padding: var(--s4) var(--s3) var(--s7); }
    .topbar-inner { padding-inline: var(--s3); }
}

/* ---- Public bands ---------------------------------------------------------------------------
   Web Design Brief.md section 2, rule 4: separate sections with background bands, not borders.
   Alternate white, tint and ink down the page and the structure appears without a single divider.
   --------------------------------------------------------------------------------------------- */

.band { padding-block: var(--band-pad); }
.band-inner { width: min(100%, 1200px); margin-inline: auto; padding-inline: var(--s4); }

.band.tint { background: var(--brand-wash); }
.band.tint-strong { background: var(--brand-tint); }

.band.ink { background: var(--ink); color: #ffffff; }
.band.ink h1, .band.ink h2, .band.ink h3 { color: #ffffff; }
.band.ink .lede, .band.ink .muted { color: #c4cfd8; }
.band.ink .eyebrow { color: #8fbcf5; }
.band.ink a { color: #a9cdfa; }

/* Repeating content is 3-up, collapsing to one column on a phone. Once the reader learns the
   pattern they scan fast, which is the whole reason for fixing it. */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s5); }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s5); }

@media (max-width: 60rem) { .grid-3, .grid-2 { grid-template-columns: 1fr; gap: var(--s4); } }

/* A borderless block, grouped by spacing and tint alone. The public counterpart to .card. */
.block h3 { margin-top: 0; }
.block p:last-child { margin-bottom: 0; }

.band .btn-row { margin-top: var(--s4); }

footer.foot {
    background: var(--ink);
    color: #c4cfd8;
    font-size: var(--fs-small);
    padding-block: var(--s5);
}

footer.foot a { color: #a9cdfa; }
footer.foot .band-inner { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); }

/* =================================================================================================
   4. Page header

   Every application screen opens the same way: eyebrow, title and an optional one-line summary on
   the left, the primary action alone on the right. Fixing the position of the terminal action is
   the point - design-evaluation.md section 6, positional consistency.
   ================================================================================================= */

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--s3);
    flex-wrap: wrap;
    margin-bottom: var(--s4);
    padding-bottom: var(--s3);
    border-bottom: 1px solid var(--line);
}

.page-head h1 { margin-bottom: 0; }
.page-head .lede { font-size: var(--fs-small); margin-bottom: 0; }
.page-head-actions { display: flex; gap: var(--s2); flex-wrap: wrap; }

/* =================================================================================================
   5. Cards and panels

   Application cards keep a hairline and a very soft shadow. That is a deliberate departure from
   the public brief's borderless rule: on a dense working screen the edge is what establishes the
   grid the eye scans down, and removing it makes a list of records read as one undifferentiated
   wall. Public bands stay borderless, where there is room for whitespace to do the same job.
   ================================================================================================= */

.card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: var(--s4);
}

.card + .card { margin-top: var(--s3); }

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s3);
    flex-wrap: wrap;
    margin: calc(var(--s4) * -1) calc(var(--s4) * -1) var(--s4);
    padding: var(--s3) var(--s4);
    border-bottom: 1px solid var(--line);
    background: var(--brand-wash);
    border-radius: var(--radius-card) var(--radius-card) 0 0;
}

.card-head h2, .card-head h3 { margin: 0; font-size: var(--fs-h3); }

/* Flush content - a table that should reach the card edge rather than sit inside its padding. */
.card-flush { margin: var(--s4) calc(var(--s4) * -1) calc(var(--s4) * -1); }
.card-flush table { border-radius: 0 0 var(--radius-card) var(--radius-card); overflow: hidden; }

.stack > * + * { margin-top: var(--s3); }

.row-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap);
    flex-wrap: wrap;
}

/*
    The context panel. design-evaluation.md section 5.1: state back to the user what they asked
    for, on a visibly different surface, with the escape hatch inside that same surface, so nobody
    has to hunt for how to change what they asked. Used for the version being edited, and later for
    the signer's request summary.
*/
.context-panel {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--s3);
    flex-wrap: wrap;
    background: var(--brand-tint);
    border: 1px solid #c5ddf5;
    border-radius: var(--radius-card);
    padding: var(--s3) var(--s4);
}

.context-panel .figure { font-size: var(--fs-h3); }
.context-panel p { margin: 0; max-width: none; }

/* An empty state is a card with room to breathe and exactly one thing to do next. */
.empty-state { text-align: center; padding: var(--s6) var(--s4); }
.empty-state p { margin-inline: auto; }

/* =================================================================================================
   6. Forms
   ================================================================================================= */

label { display: block; font-weight: 600; margin-bottom: var(--s1); }

.hint { display: block; color: var(--ink-soft); font-size: var(--fs-small); font-weight: 400; }

input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number],
input[type=search], input[type=date], input[type=file], select, textarea {
    width: 100%;
    padding: 0.6rem 0.7rem;
    /* 1rem, not smaller: iOS Safari zooms the page when a focused input is under 16px, and leaves
       the layout shifted after the keyboard closes. */
    font-size: var(--fs-body);
    font-family: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid #c8d0d7;
    border-radius: var(--radius);
}

input:hover, select:hover, textarea:hover { border-color: #9fb0bd; }

input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible, a:focus-visible, [tabindex]:focus-visible {
    outline: 3px solid var(--brand);
    outline-offset: 1px;
}

input[type=checkbox], input[type=radio] {
    width: auto;
    min-width: 1.05rem;
    min-height: 1.05rem;
    accent-color: var(--brand);
}

.field + .field { margin-top: var(--s3); }

.field-error { display: block; color: var(--bad); font-size: var(--fs-small); font-weight: 600; margin-top: var(--s1); }

/* A label that is a choice rather than a title, so it must not be bold. */
.choice { font-weight: 400; display: flex; align-items: flex-start; gap: 0.55rem; }
.choice input { margin-top: 0.28rem; }

.field-narrow { max-width: 9rem; }

/*
    Banded form rows - the existing product's strongest layout idea, kept.

    A two-column grid of label and control with alternating pale blue and white bands. On a long
    settings screen the band is what keeps a label tied to its own control across a wide viewport,
    which is exactly where a plain stacked form starts to fall apart.

    Below the tablet breakpoint it stacks, because two columns at 380px gives neither enough room.
*/
.form-rows {
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    overflow: hidden;
}

.form-row {
    display: grid;
    grid-template-columns: minmax(12rem, 22rem) 1fr;
    gap: var(--s3);
    align-items: start;
    padding: 0.85rem var(--s4);
    background: var(--surface);
}

.form-row:nth-child(odd) { background: var(--brand-tint); }

.form-row > label, .form-row > .form-label { margin-bottom: 0; padding-top: 0.55rem; }
.form-row .hint { margin-top: var(--s1); }
.form-row .form-value { padding-top: 0.55rem; }

@media (max-width: 60rem) {
    .form-row { grid-template-columns: 1fr; gap: var(--s1); padding: 0.75rem var(--s3); }
    .form-row > label, .form-row > .form-label, .form-row .form-value { padding-top: 0; }
}

/* A destructive action under an edit form: ruled off from Save so it never reads as part of it. */
.price-delete { margin-top: var(--s4); padding-top: var(--s3); border-top: 1px solid var(--line); }
.price-delete h3 { font-size: var(--fs-body); }

/* =================================================================================================
   7. Buttons

   One CTA vocabulary, repeated everywhere, in both shells: a solid primary and an outline
   secondary, the same shape and the same labels throughout. The pill radius is the identity
   marker, and it is the one styling decision deliberately shared by the public and working pages.
   ================================================================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s2);
    /* 44px floor. A signer is using a thumb, not a mouse. */
    min-height: 44px;
    padding: 0.6rem 1.4rem;
    font-size: var(--fs-small);
    font-family: inherit;
    font-weight: 600;
    line-height: 1.2;
    color: #ffffff;
    background: var(--brand);
    border: 1px solid var(--brand);
    border-radius: var(--radius-pill);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover { background: var(--brand-deep); border-color: var(--brand-deep); color: #ffffff; }

.btn.secondary { color: var(--brand-ink); background: var(--surface); border-color: #b9c6d2; }
.btn.secondary:hover { color: var(--brand-deep); background: var(--brand-wash); border-color: var(--brand); }

.btn.ghost { color: var(--brand-ink); background: transparent; border-color: transparent; }
.btn.ghost:hover { color: var(--brand-deep); background: var(--brand-wash); border-color: transparent; }

/* Destructive actions are red, and they are the only red control in the product. */
.btn.danger { color: #ffffff; background: var(--bad); border-color: var(--bad); }
.btn.danger:hover { background: #8b1f24; border-color: #8b1f24; }

.btn.small { min-height: 34px; padding: 0.3rem 0.85rem; font-size: var(--fs-meta); }
.btn.wide { width: 100%; }

.btn:disabled, .btn[aria-disabled=true] { opacity: 0.6; cursor: not-allowed; }
.btn.is-busy { cursor: progress; }

.btn-row { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }

/*
    The busy state. Two things about it matter more than how it looks: it appears on submit, BEFORE
    the server responds, so the gap between the user acting and the screen reacting is near zero;
    and it is cleared on failure as well as success, because a spinner left spinning after an error
    reads as a crash.
*/
.spinner {
    display: none;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.btn.is-busy .spinner { display: inline-block; }
.btn.is-busy .label-idle { display: none; }
.btn .label-busy { display: none; }
.btn.is-busy .label-busy { display: inline; }

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

/* A page-level busy bar, for a wait that blocks a whole region. */
.busy-bar {
    height: 3px;
    border-radius: var(--radius-pill);
    background: linear-gradient(90deg, transparent, var(--brand), transparent);
    background-size: 40% 100%;
    background-repeat: no-repeat;
    animation: sweep 1.1s ease-in-out infinite;
}

@keyframes sweep {
    0%   { background-position: -40% 0; }
    100% { background-position: 140% 0; }
}

/*
    Reduced motion keeps a CLEARLY VISIBLE busy state and drops only the movement. Removing the
    indicator would trade an accessibility preference for the appearance of a frozen screen.
*/
@media (prefers-reduced-motion: reduce) {
    .spinner { animation: none; border-right-color: currentColor; opacity: 0.55; }
    .busy-bar { animation: none; background: var(--brand); opacity: 0.5; }
    .btn, .rail-item, .chip, .chip-ghost { transition: none !important; }
    * { scroll-behavior: auto !important; }
}

/* =================================================================================================
   8. Messages

   Success is GREEN and errors are RED. The product being replaced rendered
   "Successful | User Details Saved." in red, in a modal, in the same colour as its validation
   errors. Colour is never the only signal either: each message carries a bold lead-in and the
   correct ARIA role, so it is announced as a status or as an alert.
   ================================================================================================= */

.note {
    border: 1px solid;
    border-left-width: 4px;
    border-radius: var(--radius);
    padding: 0.8rem 1rem;
    margin-bottom: var(--s3);
    font-size: var(--fs-small);
}

.note:empty { display: none; }

.note.good { color: var(--good); background: var(--good-bg); border-color: var(--good-line); }
.note.bad  { color: var(--bad);  background: var(--bad-bg);  border-color: var(--bad-line); }
.note.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.note.info { color: var(--brand-ink); background: var(--brand-tint); border-color: #c5ddf5; }

.note strong { display: block; font-size: var(--fs-body); }
.note ul { margin: var(--s2) 0 0; padding-left: 1.1rem; }
.note p { max-width: none; }
.note p:last-child { margin-bottom: 0; }

/* =================================================================================================
   9. Tables

   Navy header on white rows, as the product does today. Wide content scrolls inside its own
   container so the page body never scrolls sideways.
   ================================================================================================= */

.table-scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: var(--fs-small); }

thead th {
    background: var(--navy);
    color: #ffffff;
    font-weight: 600;
    font-size: var(--fs-meta);
    letter-spacing: 0.02em;
    white-space: nowrap;
    text-align: left;
    padding: 0.6rem 0.7rem;
}

tbody th, td { padding: 0.6rem 0.7rem; text-align: left; border-bottom: 1px solid var(--line-soft); }

tbody th { background: var(--brand-tint); font-weight: 600; white-space: nowrap; }

tbody tr:hover td { background: var(--brand-wash); }

tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* A key-and-value table, where the left column is a label rather than the heading of a list. */
.kv tbody th { width: 14rem; }

/* =================================================================================================
   10. Status pills

   Colour plus a glyph plus a word - three signals, so a colour-blind reader loses nothing.
   design-evaluation.md section 10 lists colour-only meaning as the source page's real weakness.
   ================================================================================================= */

.pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.12rem 0.6rem;
    border-radius: var(--radius-pill);
    font-size: var(--fs-meta);
    font-weight: 600;
    white-space: nowrap;
    background: var(--ground);
    border: 1px solid var(--line);
    color: var(--ink-soft);
}

.pill::before { font-size: 0.85em; line-height: 1; font-weight: 700; }

.pill.good { background: var(--good-bg); border-color: var(--good-line); color: var(--good); }
.pill.good::before { content: "+"; }

.pill.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.pill.warn::before { content: "!"; }

.pill.bad { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad); }
.pill.bad::before { content: "x"; }

.pill.info { background: var(--brand-tint); border-color: #c5ddf5; color: var(--brand-ink); }
.pill.info::before { content: "i"; }

.pill.plain::before { content: none; }

.pill.small { font-size: var(--fs-caption); padding: 0.05rem 0.45rem; }

.pill.mono { font-family: var(--font-mono); font-weight: 400; }

/*
    A badge that overlaps the edge of its card. design-evaluation.md section 5.4: a badge sitting
    neatly inside the padding reads as content, while one that breaks the edge reads as a label
    applied to the card - which is what a badge is.
*/
.badge-corner {
    position: absolute;
    top: -0.6rem;
    left: var(--s4);
    padding: 0.15rem 0.7rem;
    border-radius: var(--radius-pill);
    background: var(--navy);
    color: #ffffff;
    font-size: var(--fs-caption);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* =================================================================================================
   11. The field designer

   Field chips are absolutely positioned HTML elements over the page image, never shapes painted
   into a canvas. That is the highest-leverage decision in the designer: dragging, hit testing,
   focus rings, keyboard access, the remove button and per-signer colour all come free from the
   browser. Painting into a canvas means writing every one of them by hand.
   ================================================================================================= */

/* The designer genuinely is a rail plus a working area, so it gets its own inner split rather than
   inheriting the page rhythm. */
.designer-layout {
    display: grid;
    grid-template-columns: 15rem minmax(0, 1fr);
    gap: var(--s4);
    align-items: start;
}

@media (max-width: 60rem) { .designer-layout { grid-template-columns: 1fr; } }

.designer-panel { display: flex; flex-direction: column; gap: var(--s2); }

.panel-heading {
    font-size: var(--fs-meta);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-soft);
    margin: var(--s3) 0 var(--s1);
}

.panel-heading:first-child { margin-top: 0; }

.designer-surface {
    position: relative;
    display: inline-block;
    max-width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow-card);
    line-height: 0;
    cursor: crosshair;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.designer-surface img { display: block; max-width: 100%; height: auto; border-radius: var(--radius); }

.chip-layer { position: absolute; inset: 0; }

.chip {
    position: absolute;
    box-sizing: border-box;
    border: 1px solid rgba(0, 0, 0, 0.35);
    border-radius: 3px;
    font: 600 11px/1.1 inherit;
    color: var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 0;
    cursor: grab;
    /* Essential on touch: without it a drag on the chip scrolls the page instead. */
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.chip:focus-visible { outline: 3px solid var(--ink); outline-offset: 1px; }
.chip.is-dragging { cursor: grabbing; opacity: 0.85; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35); }
.chip.is-selected { border-color: var(--ink); border-width: 2px; }

.chip-label { pointer-events: none; padding: 0 2px; text-align: center; }

/* Remove control. A separate target, so dragging a chip cannot delete it by accident. */
.chip-remove {
    position: absolute;
    top: -9px;
    right: -9px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.4);
    background: var(--surface);
    color: var(--bad);
    font: 700 11px/1 inherit;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    touch-action: none;
}

/* Resize handle, bottom right. A signature box needs sizing, and typing fractions is not sizing. */
.chip-resize {
    position: absolute;
    right: -6px;
    bottom: -6px;
    width: 14px;
    height: 14px;
    border: 1px solid rgba(0, 0, 0, 0.45);
    background: var(--surface);
    cursor: nwse-resize;
    display: none;
    touch-action: none;
}

.chip.is-selected .chip-remove,
.chip.is-selected .chip-resize,
.chip:hover .chip-remove,
.chip:hover .chip-resize { display: flex; }

/* The ghost that follows the pointer when dragging a new field off the palette. */
.chip-ghost {
    position: fixed;
    z-index: 50;
    pointer-events: none;
    border: 2px dashed var(--ink);
    border-radius: 3px;
    opacity: 0.75;
    font: 600 11px/1.1 inherit;
    color: var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
}

/*
    The signer palette. Each button is both a click target and a drag source, and each carries an
    initials badge as well as its colour - so which signer a field belongs to is never conveyed by
    colour alone. Ink text on the pastel swatch measures well above 4.5:1 on all six.
*/
.palette-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.7rem;
    min-height: 40px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font-size: var(--fs-small);
    font-weight: 600;
    font-family: inherit;
    text-align: left;
    cursor: grab;
    touch-action: none;
}

.palette-item:hover:not(:disabled) { border-color: #9fb0bd; background: var(--brand-wash); }
.palette-item:disabled { cursor: not-allowed; opacity: 0.55; }
.palette-item.is-armed { outline: 3px solid var(--brand); outline-offset: 1px; }

.palette-swatch {
    flex: 0 0 auto;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.18);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-caption);
    font-weight: 700;
    color: var(--ink);
}

/* =================================================================================================
   12. Utilities
   ================================================================================================= */

.muted { color: var(--ink-soft); }
.small { font-size: var(--fs-small); }
.caption { font-size: var(--fs-caption); color: var(--ink-soft); }
.mono { font-family: var(--font-mono); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.nowrap { white-space: nowrap; }
.full-measure { max-width: none; }

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

/* Skip link: off screen until focused, then the first thing a keyboard user reaches. */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 100;
    padding: 0.6rem 1rem;
    background: var(--ink);
    color: #ffffff;
    border-radius: 0 0 var(--radius) 0;
}

.skip-link:focus { left: 0; color: #ffffff; }

@media print {
    .topbar, .rail, footer.foot, .btn, .page-head-actions { display: none !important; }
    .content { background: #fff; padding: 0; }
    .card { border: 1px solid #999; box-shadow: none; break-inside: avoid; }
}
