/*
 * Wire Transfer Instructions Generator
 *
 * Look follows the Vehicle Bill of Sale page (Bootstrap 5 colors and form
 * style), written by hand so the page loads no third-party files.
 *
 * Sections:
 *   1. Tokens
 *   2. Base
 *   3. Page layout
 *   4. Form
 *   5. Buttons and status
 *   6. Preview frame
 *   7. Printed document (shared by preview and print)
 *   8. Print
 */

/* ========== 1. Tokens ========== */
:root {
    --color-text: #212529;
    --color-muted: #6c757d;
    --color-border: #ced4da;
    --color-surface: #ffffff;
    --color-page: #f3f5f8;
    --color-primary: #0d6efd;
    --color-primary-hover: #0b5ed7;
    --color-secondary: #6c757d;
    --color-secondary-hover: #5c636a;
    --color-danger: #dc3545;
    --color-danger-hover: #bb2d3b;
    --color-success: #146c43;
    --color-warning-border: #d39e00;
    --color-warning-text: #664d03;
    --color-warning-bg: #fff3cd;
    --color-focus-ring: rgba(13, 110, 253, 0.25);

    --radius: 0.375rem;
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

    /* US Letter. Preview padding equals the print margin, so line breaks match. */
    --paper-width: 8.5in;
    --paper-height: 11in;
    --paper-margin: 0.5in;
}

/* ========== 2. Base ========== */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-page);
}

h1, h2, h3 {
    line-height: 1.2;
}

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

/* ========== 3. Page layout ========== */
.container {
    max-width: 1320px;
    margin: 0 auto;
    padding: 0 1rem;
}

.site-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 1.25rem 0 1rem;
    text-align: center;
}

.privacy-notice {
    display: inline-block;
    max-width: 46rem;
    margin: 0;
    padding: 0.5rem 0.875rem;
    font-size: 0.9rem;
    background: #e7f1ff;
    border: 1px solid #b6d4fe;
    border-radius: var(--radius);
}

.noscript-notice {
    padding: 1rem;
    color: var(--color-danger);
}

/* Mobile first: one column, form then preview. */
.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.5rem;
    padding-top: 1.5rem;
    padding-bottom: 3rem;
}

@media (min-width: 992px) {
    .layout {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        align-items: start;
    }

    /*
     * Intentional: the preview panel is not sticky and has no height cap.
     * It shows at full width and full height, and the page scrolls normally,
     * so there is never a second scrollbar inside the panel.
     */

    .mobile-only {
        display: none !important;
    }
}

/* ========== 4. Form ========== */
.required-mark {
    color: var(--color-danger);
}

.required-legend {
    margin: 0.75rem 0;
    font-size: 0.875rem;
    color: var(--color-muted);
}

.form-section {
    margin: 0 0 1.25rem;
    padding: 1.25rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

/* Float puts the legend inside the card instead of on its border. */
.form-section > legend {
    float: left;
    width: 100%;
    padding: 0 0 0.5rem;
    margin-bottom: 1rem;
    font-size: 1.2rem;
    font-weight: 600;
    border-bottom: 1px solid var(--color-border);
}

.form-section > legend + * {
    clear: both;
}

.legend-hint {
    display: block;
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--color-muted);
}

.optional-section > summary {
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: 600;
}

.optional-section[open] > summary {
    margin-bottom: 1rem;
}

.sub-section {
    margin: 0 0 1rem;
    padding: 0;
    border: 0;
}

.sub-section > legend {
    padding: 0;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.field-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
}

@media (min-width: 576px) {
    .field-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .field-wide {
        grid-column: 1 / -1;
    }
}

.field label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 500;
}

.field input,
.field textarea {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    /* 16px or larger stops iOS Safari from zooming in on focus. */
    font-size: 1rem;
    font-family: inherit;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.field textarea {
    resize: vertical;
}

.field input:focus,
.field textarea:focus {
    outline: 0;
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.25rem var(--color-focus-ring);
}

/* Monospace makes 0/O and 1/l/I easy to tell apart. */
.field .identifier-input {
    font-family: var(--font-mono);
    letter-spacing: 0.03em;
}

.field [aria-invalid="true"] {
    border-color: var(--color-danger);
}

.field .has-warning {
    border-color: var(--color-warning-border);
}

.field-hint {
    margin: 0.25rem 0 0;
    font-size: 0.85rem;
    color: var(--color-muted);
}

.field-message {
    margin: 0.375rem 0 0;
    font-size: 0.875rem;
}

.field-message:empty {
    display: none;
}

.field-message[data-level="error"] {
    color: var(--color-danger);
}

.field-message[data-level="warning"] {
    padding: 0.25rem 0.5rem;
    color: var(--color-warning-text);
    background: var(--color-warning-bg);
    border-radius: var(--radius);
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
}

/* ========== 5. Buttons and status ========== */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    font-weight: 500;
    font-family: inherit;
    line-height: 1.5;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: var(--radius);
}

.btn:focus-visible {
    outline: 0;
    box-shadow: 0 0 0 0.25rem var(--color-focus-ring);
}

.btn-primary {
    color: #fff;
    background: var(--color-primary);
}

.btn-primary:hover {
    background: var(--color-primary-hover);
}

.btn-secondary {
    color: #fff;
    background: var(--color-secondary);
}

.btn-secondary:hover {
    background: var(--color-secondary-hover);
}

.btn-danger {
    color: #fff;
    background: var(--color-danger);
}

.btn-danger:hover {
    background: var(--color-danger-hover);
}

.btn-outline {
    display: block;
    color: var(--color-primary);
    background: var(--color-surface);
    border-color: var(--color-primary);
}

.preview-toolbar h2 {
    margin: 0 0 0.75rem;
    font-size: 1.2rem;
}

.toolbar-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.action-status {
    margin: 0.5rem 0 0;
    font-weight: 500;
}

.action-status:empty {
    display: none;
}

.action-status[data-level="error"] {
    color: var(--color-danger);
}

.action-status[data-level="success"] {
    color: var(--color-success);
}

.check-notice,
.page-count-note {
    margin: 0.5rem 0 0;
    font-size: 0.85rem;
    color: var(--color-muted);
}

.page-count-note {
    color: var(--color-warning-text);
}

.back-link {
    display: inline-block;
    margin-top: 0.5rem;
}

.view-switch {
    display: flex;
    margin-top: 1rem;
}

.view-btn {
    flex: 1;
    padding: 0.5rem 0.75rem;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--color-primary);
    background: var(--color-surface);
    border: 1px solid var(--color-primary);
    cursor: pointer;
}

.view-btn:first-child {
    border-radius: var(--radius) 0 0 var(--radius);
}

.view-btn:last-child {
    border-left: 0;
    border-radius: 0 var(--radius) var(--radius) 0;
}

.view-btn[aria-pressed="true"] {
    color: #fff;
    background: var(--color-primary);
}

.view-btn:focus-visible {
    outline: 0;
    box-shadow: 0 0 0 0.25rem var(--color-focus-ring);
}

/* ========== 6. Preview frame ========== */
/*
 * script.js sets:
 *   --preview-scale          shrink to fit the panel's width (and height on desktop)
 *   --preview-offset         left offset that centers the scaled paper
 *   --paper-rendered-height  real paper height
 * transform does not affect layout, so the frame height is set to the
 * scaled height by hand.
 */
.preview-frame {
    --preview-scale: 1;
    --preview-offset: 0px;
    --paper-rendered-height: var(--paper-height);
    height: calc(var(--paper-rendered-height) * var(--preview-scale));
    margin-top: 1rem;
    overflow: hidden;
}

.paper {
    width: var(--paper-width);
    min-height: var(--paper-height);
    margin: 0;
    padding: var(--paper-margin);
    background: #fff;
    border: 1px solid #c5cbd3;
    transform: translateX(var(--preview-offset)) scale(var(--preview-scale));
    transform-origin: top left;
}

/* ========== 7. Printed document ========== */
/* Sizes in pt so the preview and the printout match. */
.paper {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11pt;
    line-height: 1.35;
    color: #000;
}

/*
 * The sheet uses <header>, <footer>, <section>, and <dl>. Host-site templates
 * (Joomla) often style those tags, so the sheet sets color, background,
 * and spacing explicitly instead of inheriting them.
 */
.paper :is(header, footer, section, h2, h3, p, dl, dt, dd) {
    font-family: inherit;
    color: #000;
    background: none;
    box-shadow: none;
}

.doc-header {
    padding: 0 0 8pt;
    margin: 0 0 14pt;
    text-align: center;
    border-bottom: 2pt solid #000;
}

.doc-title {
    margin: 0;
    font-size: 18pt;
    letter-spacing: 0.04em;
}

.doc-subtitle {
    margin: 4pt 0 0;
    font-size: 10.5pt;
    font-style: italic;
}

.doc-date {
    margin: 4pt 0 0;
    font-size: 9.5pt;
}

.doc-section {
    margin-bottom: 14pt;
    break-inside: avoid;
}

.doc-section-title {
    margin: 0 0 4pt;
    padding-bottom: 3pt;
    font-size: 11.5pt;
    border-bottom: 1pt solid #000;
}

.doc-rows {
    margin: 0;
}

.doc-row {
    display: grid;
    grid-template-columns: 1.9in minmax(0, 1fr);
    gap: 0 12pt;
    padding: 3pt 0;
    border-bottom: 0.5pt solid #bbb;
}

.doc-row dt {
    font-weight: 700;
}

/* pre-wrap keeps the user's spacing and line breaks exactly as entered. */
.doc-row dd {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* Long account numbers have no spaces; break-all lets them wrap instead of overflowing. */
.doc-row dd.is-identifier {
    font-family: var(--font-mono);
    font-size: 11.5pt;
    letter-spacing: 0.03em;
    word-break: break-all;
    font-variant-numeric: slashed-zero;
}

.doc-row dd.is-missing {
    font-style: italic;
    color: var(--color-muted);
}

.doc-disclaimer {
    margin: 18pt 0 0;
    padding: 6pt 0 0;
    font-size: 8.5pt;
    border-top: 1pt solid #000;
}

.doc-disclaimer p {
    margin: 0;
}

/*
 * Reading view: the same document reflowed for a phone screen.
 * Labels sit above values, and identifiers are large and bold so they
 * can be copied by hand character by character.
 * Screen only: printing always uses the US Letter styles above.
 */
@media screen {
    .preview-frame[data-view="reading"] {
        height: auto;
        overflow: visible;
    }

    .preview-frame[data-view="reading"] .paper {
        width: auto;
        min-height: 0;
        padding: 1.25rem 1rem;
        font-size: 1.05rem;
        line-height: 1.45;
        border-radius: var(--radius);
        transform: none;
    }

    .preview-frame[data-view="reading"] .doc-title {
        font-size: 1.2rem;
    }

    .preview-frame[data-view="reading"] .doc-subtitle,
    .preview-frame[data-view="reading"] .doc-date {
        font-size: 0.85rem;
    }

    .preview-frame[data-view="reading"] .doc-section-title {
        font-size: 1rem;
    }

    .preview-frame[data-view="reading"] .doc-row {
        grid-template-columns: minmax(0, 1fr);
        padding: 0.5rem 0;
    }

    .preview-frame[data-view="reading"] .doc-row dt {
        font-size: 0.8rem;
        font-weight: 600;
        color: #495057;
        text-transform: uppercase;
        letter-spacing: 0.03em;
    }

    .preview-frame[data-view="reading"] .doc-row dd.is-identifier {
        font-size: 1.35rem;
        font-weight: 700;
        letter-spacing: 0.06em;
    }

    .preview-frame[data-view="reading"] .doc-disclaimer {
        font-size: 0.8rem;
    }
}

/* ========== 8. Print ========== */
/*
 * Page margin is 0 on purpose. With no margin, browsers have no room to
 * print their own header and footer lines (date, page title, URL).
 * The sheet supplies its own 0.5in margin as padding instead (see .paper below).
 */
@page {
    size: letter;
    margin: 0;
}

@media print {
    /*
     * Print only the sheet. This page is embedded in a Joomla article, so it
     * has menus, headers, sticky bars, and footers this file knows nothing
     * about. Rule: hide every element that is not the sheet, not inside the
     * sheet, and does not contain the sheet.
     */
    body :not(:has(#paper)):not(#paper):not(#paper *) {
        display: none !important;
    }

    /*
     * Flatten every container around the sheet (html, body, Joomla wrappers,
     * this tool's own panels) so the sheet starts at the top-left of page 1.
     * !important is needed to beat the Joomla template's own rules.
     */
    :has(#paper) {
        display: block !important;
        position: static !important;
        float: none !important;
        width: auto !important;
        max-width: none !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        box-shadow: none !important;
        background: none !important;
        overflow: visible !important;
        transform: none !important;
    }

    /* Undo the on-screen preview sizing and scaling. */
    .paper {
        width: auto;
        min-height: 0;
        margin: 0;
        /* Must match --paper-margin. Replaces the @page margin (see above). */
        padding: 0.5in;
        border: 0;
        border-radius: 0;
        transform: none;
        /* If the sheet runs to page 2, repeat the top/bottom margin there too. */
        -webkit-box-decoration-break: clone;
        box-decoration-break: clone;
    }

    /* A missing value prints as a blank line to write on, not as "Not entered". */
    .doc-row dd.is-missing {
        color: transparent;
        border-bottom: 1pt solid #000;
    }
}