@font-face {
    font-family: "Kanit";
    src: url("../fonts/Kanit-Bold.ttf") format("truetype");
    font-style: normal;
    font-weight: 700;
    font-display: swap;
}

@font-face {
    font-family: "Encode Sans";
    src: url("../fonts/EncodeSans-Variable.ttf") format("truetype");
    font-style: normal;
    font-weight: 100 900;
    font-stretch: 75% 125%;
    font-display: swap;
}

:root {
    --navy-950: #7a0024;
    --navy-900: #ab0033;
    --navy-800: #ab0033;
    --gold-600: #bc955c;
    --gold-500: #bc955c;
    --gold-200: #ead9bd;
    --gold-100: #f7f0e5;
    --ink: #54565a;
    --muted: #6d6f73;
    --line: #d7d7d8;
    --paper: #fff;
    --success: #166534;
    --danger: #b42318;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-width: 320px;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(194, 154, 90, 0.12), transparent 32rem),
        #eef1f4;
    font-family: "Encode Sans", Arial, sans-serif;
}

button,
input,
select {
    font: inherit;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 72px;
    padding: 12px clamp(18px, 4vw, 56px);
    color: var(--ink);
    background: rgba(255, 255, 255, 0.98);
    border-bottom: 4px solid var(--navy-900);
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-brand img {
    width: min(310px, 42vw);
    height: auto;
    object-fit: contain;
}

.app-brand span {
    display: block;
}

.app-brand span {
    padding-left: 12px;
    color: var(--muted);
    border-left: 2px solid var(--gold-500);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.back-link {
    color: var(--navy-900);
    font-size: 0.88rem;
    font-weight: 700;
    text-underline-offset: 4px;
}

.app-navigation {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 18px;
    align-items: center;
    justify-content: flex-end;
}

.workspace {
    width: min(1180px, calc(100% - 32px));
    margin: 28px auto 56px;
}

.control-panel {
    position: sticky;
    z-index: 10;
    top: 12px;
    display: grid;
    grid-template-columns: minmax(300px, 0.9fr) minmax(360px, 1.4fr) auto;
    gap: 18px;
    align-items: end;
    margin-bottom: 22px;
    padding: 18px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(13, 27, 42, 0.08);
    border-radius: 14px;
    box-shadow: 0 14px 40px rgba(13, 27, 42, 0.12);
    backdrop-filter: blur(10px);
}

.control-label {
    display: block;
    margin-bottom: 8px;
    color: var(--navy-800);
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.mode-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 4px;
    background: #edf0f3;
    border-radius: 10px;
}

.mode-tab {
    min-height: 42px;
    padding: 8px 12px;
    color: #465360;
    background: transparent;
    border: 0;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 650;
}

.mode-tab[aria-selected="true"] {
    color: #fff;
    background: var(--navy-900);
    box-shadow: 0 4px 12px rgba(13, 27, 42, 0.18);
}

.lookup-row {
    display: flex;
    gap: 8px;
}

.lookup-row input {
    width: 100%;
    min-height: 44px;
    padding: 9px 12px;
    color: var(--ink);
    background: #fff;
    border: 1px solid #bcc5cf;
    border-radius: 8px;
    outline: 0;
}

.lookup-row input:focus {
    border-color: var(--gold-600);
    box-shadow: 0 0 0 3px rgba(194, 154, 90, 0.2);
}

.lookup-help {
    min-height: 18px;
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 0.78rem;
}

.lookup-help.is-success {
    color: var(--success);
}

.lookup-help.is-error {
    color: var(--danger);
}

.manual-note {
    min-height: 68px;
    margin: 0;
    padding: 12px 14px;
    color: #4d5965;
    background: var(--gold-100);
    border: 1px solid var(--gold-200);
    border-radius: 9px;
    font-size: 0.84rem;
    line-height: 1.45;
}

.is-hidden {
    display: none !important;
}

.actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding-bottom: 24px;
}

.button {
    min-height: 44px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.87rem;
    font-weight: 700;
    white-space: nowrap;
}

.button:disabled {
    cursor: wait;
    opacity: 0.65;
}

.button-primary {
    color: #fff;
    background: var(--navy-900);
}

.button-secondary {
    color: var(--navy-900);
    background: #fff;
    border-color: #bdc6cf;
}

.document-sheet {
    position: relative;
    width: min(8.5in, 100%);
    min-height: 11in;
    margin: 0 auto;
    padding: 0.48in 0.66in 0.52in;
    overflow: hidden;
    background: var(--paper);
    border: 1px solid #e2e5e8;
    box-shadow: 0 25px 70px rgba(13, 27, 42, 0.16);
}

.document-background {
    position: absolute;
    z-index: 0;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    pointer-events: none;
    user-select: none;
}

.document-sheet > :not(.document-background) {
    position: relative;
    z-index: 1;
}

.document-stack {
    display: grid;
    gap: 26px;
}

.document-page-continuation {
    display: flex;
    flex-direction: column;
}

.document-page:first-child {
    display: flex;
    flex-direction: column;
}

.document-page-continuation .document-footer {
    position: static;
    right: auto;
    bottom: auto;
    left: auto;
    flex: 0 0 auto;
    margin-top: auto;
}

.letterhead {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 18px;
    align-items: center;
    padding-bottom: 18px;
    border-bottom: 2px solid var(--gold-500);
}

.letterhead-brand {
    display: flex;
    align-items: center;
    min-width: 0;
}

.letterhead-logo {
    width: 330px;
    max-width: 68%;
    height: auto;
}

.institution-area {
    margin: 0 0 0 15px;
    padding-left: 15px;
    color: var(--gold-600);
    border-left: 2px solid var(--gold-500);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.folio-box {
    min-width: 116px;
    padding: 10px 12px;
    text-align: right;
    background: #f5f6f7;
    border-left: 3px solid var(--navy-800);
}

.folio-box span,
.folio-box strong {
    display: block;
}

.folio-box span {
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.folio-box strong {
    color: var(--navy-900);
    font-size: 0.78rem;
}

.document-title {
    margin: 24px 0 7px;
    color: var(--navy-900);
    font-family: "Kanit", "Encode Sans", Arial, sans-serif;
    font-weight: 700;
    font-size: 1.46rem;
    letter-spacing: 0.08em;
    text-align: center;
    text-transform: uppercase;
}

.document-subtitle {
    margin: 0 0 18px;
    color: var(--muted);
    font-size: 0.76rem;
    letter-spacing: 0.12em;
    text-align: center;
    text-transform: uppercase;
}

.intro-text {
    margin: 0 0 14px;
    font-family: "Encode Sans", Arial, sans-serif;
    font-size: 0.95rem;
    line-height: 1.65;
    text-align: justify;
}

.data-card {
    border: 1px solid #ccd3da;
    border-top: 4px solid var(--navy-800);
}

.data-card-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0;
    padding: 10px 15px;
    color: #fff;
    background: var(--navy-900);
    font-size: 0.72rem;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.data-card-heading span {
    color: #d9e0e6;
    font-size: 0.55rem;
    letter-spacing: 0.08em;
}

.section-gap {
    margin-top: 14px;
}

.data-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.field {
    min-width: 0;
    padding: 8px 12px 7px;
    border-bottom: 1px solid var(--line);
}

.field:nth-child(odd) {
    border-right: 1px solid var(--line);
}

.field-wide {
    grid-column: 1 / -1;
    border-right: 0 !important;
}

.field:last-child {
    border-bottom: 0;
}

.field label {
    display: block;
    margin-bottom: 3px;
    color: var(--navy-800);
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.field label span {
    color: var(--muted);
    font-weight: 600;
    letter-spacing: normal;
    text-transform: none;
}

.data-section-heading {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0;
    padding: 7px 12px;
    color: var(--navy-800);
    background: var(--gold-100);
    border-bottom: 1px solid var(--gold-200);
    font-size: 0.66rem;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.data-section-heading span {
    color: var(--muted);
    font-size: 0.56rem;
    letter-spacing: 0.08em;
}

.document-input {
    width: 100%;
    padding: 3px 0 5px;
    color: var(--ink);
    background: transparent;
    border: 0;
    border-bottom: 1px dashed #9aa5af;
    border-radius: 0;
    outline: 0;
    font-family: "Encode Sans", Arial, sans-serif;
    font-size: 0.88rem;
    font-weight: 600;
}

.document-input:focus {
    border-bottom-color: var(--gold-600);
    box-shadow: 0 2px 0 var(--gold-600);
}

.document-input[readonly] {
    color: #28323c;
    border-bottom-style: solid;
    border-bottom-color: transparent;
}

.document-input:disabled {
    color: #28323c;
    opacity: 1;
    border-bottom-color: transparent;
}

.document-stack.is-manual .document-input {
    font-family: "Encode Sans", Arial, sans-serif;
    font-size: 0.93rem;
    font-weight: 600;
    letter-spacing: 0.018em;
}

.conditional-input {
    margin-top: 7px;
    padding-left: 9px;
    border-left: 2px solid var(--gold-500);
}

.conditional-block {
    margin-top: 8px;
    padding: 8px 10px;
    background: var(--gold-100);
    border-left: 3px solid var(--gold-500);
}

.conditional-block label {
    color: var(--navy-800);
}

.questionnaire-grid .question-field {
    padding-top: 12px;
    padding-bottom: 12px;
}

.questionnaire-grid .question-field > label {
    margin-bottom: 7px;
    color: var(--navy-800);
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    text-transform: none;
}

.registration-meta {
    display: grid;
    grid-template-columns: 1fr 0.7fr;
    gap: 24px;
    margin-top: 14px;
    padding: 9px 12px;
    background: #f5f6f7;
    border-left: 3px solid var(--gold-500);
}

.meta-label,
.meta-value {
    display: block;
}

.meta-label {
    color: var(--muted);
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.meta-value {
    margin-top: 4px;
    font-family: "Encode Sans", Arial, sans-serif;
    font-size: 0.92rem;
    font-weight: 700;
}

.statement {
    margin: 12px 0 0;
    color: #3c4650;
    font-family: "Encode Sans", Arial, sans-serif;
    font-size: 0.75rem;
    line-height: 1.55;
    text-align: justify;
}

.privacy-notice {
    margin-top: 12px;
    padding: 10px 12px;
    color: #3c4650;
    background: #f6f7f8;
    border: 1px solid #ccd3da;
    border-left: 4px solid var(--gold-500);
}

.privacy-notice h2 {
    margin: 0 0 6px;
    color: var(--navy-900);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.privacy-notice p {
    margin: 4px 0;
    font-family: "Encode Sans", Arial, sans-serif;
    font-size: 0.61rem;
    line-height: 1.35;
    text-align: justify;
}

.privacy-notice a {
    color: var(--navy-800);
    font-weight: 700;
}

.privacy-consent {
    display: flex;
    gap: 7px;
    align-items: flex-start;
    margin-top: 7px;
    color: var(--navy-900);
    font-size: 0.61rem;
    font-weight: 700;
    line-height: 1.35;
}

.privacy-consent input {
    flex: 0 0 auto;
    width: 14px;
    height: 14px;
    margin: 1px 0 0;
    accent-color: var(--navy-800);
}

.document-footer {
    position: absolute;
    right: 0.66in;
    bottom: 0.34in;
    left: 0.66in;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding-top: 8px;
    color: #697581;
    border-top: 1px solid var(--gold-200);
    font-size: 0.6rem;
    line-height: 1.35;
}

.privacy-footer {
    gap: 20px;
    font-size: 0.56rem;
}

.dated-footer {
    display: block;
    padding-top: 0;
    border-top: 0;
}

.registration-meta-footer {
    margin: 0 0 7px;
    padding: 6px 10px;
}

.registration-meta-footer .meta-value {
    margin-top: 2px;
    font-size: 0.82rem;
}

.footer-bottom-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    padding-top: 7px;
    border-top: 1px solid var(--gold-200);
}

.footer-bottom-row.footer-rights-only {
    justify-content: flex-end;
}

.footer-bottom-row.footer-rights-only > div:first-child {
    max-width: none;
}

.footer-bottom-row.footer-page-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: end;
}

.footer-page-row .page-number {
    grid-column: 2;
    justify-self: center;
}

.footer-page-row .rights-notice {
    grid-column: 3;
    justify-self: end;
}

.page-number-footer {
    position: static;
    right: auto;
    bottom: auto;
    left: auto;
    flex: 0 0 auto;
    justify-content: center;
    margin-top: auto;
    padding-top: 6px;
    border-top: 0;
}

.document-page:first-child .page-number-footer {
    position: absolute;
    right: 0.66in;
    bottom: 0.08in;
    left: 0.66in;
    margin: 0;
    padding: 0;
}

.footer-bottom-row > div:first-child {
    max-width: 78%;
}

.document-page:first-child .intro-text {
    margin-bottom: 10px;
    font-size: 0.82rem;
    line-height: 1.4;
}

.document-page:first-child .document-title {
    margin-top: 16px;
}

.document-page:first-child .document-subtitle {
    margin-bottom: 12px;
}

.document-page:first-child .section-gap {
    margin-top: 10px;
}

.document-page:first-child .field {
    padding-top: 5px;
    padding-bottom: 5px;
}

.privacy-footer > div:first-child {
    max-width: 72%;
}

.page-number,
.rights-notice {
    flex: 0 0 auto;
    text-align: right;
}

.page-number {
    padding: 2px 10px;
    color: var(--navy-900);
    background: rgba(255, 255, 255, 0.88);
    border-radius: 999px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-align: center;
    white-space: nowrap;
}

.footer-page-row .page-number {
    max-width: none;
}

.document-footer strong {
    color: var(--navy-800);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.confirmation-overlay {
    position: fixed;
    z-index: 50;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(20, 24, 29, 0.62);
    backdrop-filter: blur(3px);
}

.confirmation-card {
    width: min(540px, 100%);
    padding: 28px;
    color: var(--ink);
    background: #fff;
    border-top: 5px solid var(--navy-900);
    border-radius: 14px;
    box-shadow: 0 28px 80px rgba(13, 27, 42, 0.3);
}

.confirmation-icon {
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    margin-bottom: 14px;
    color: #fff;
    background: var(--success);
    border-radius: 50%;
    font-size: 1.6rem;
    font-weight: 800;
}

.confirmation-card h2 {
    margin: 0 0 8px;
    color: var(--navy-900);
    font-size: 1.32rem;
}

.confirmation-card > p {
    margin: 0;
    line-height: 1.5;
}

.confirmation-details {
    display: grid;
    gap: 0;
    margin: 20px 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
}

.confirmation-details > div {
    display: grid;
    grid-template-columns: 130px minmax(0, 1fr);
    gap: 14px;
    padding: 10px 12px;
    background: #fff;
}

.confirmation-details > div + div {
    border-top: 1px solid var(--line);
}

.confirmation-details dt {
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.confirmation-details dd {
    min-width: 0;
    margin: 0;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.status-success {
    color: var(--success);
}

.status-error {
    color: var(--danger);
}

.confirmation-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.download-confirmation {
    min-height: 1.4em;
    margin-top: 12px !important;
    color: var(--success);
    font-size: 0.82rem;
    font-weight: 700;
    text-align: right;
}

.toast {
    position: fixed;
    z-index: 30;
    right: 24px;
    bottom: 24px;
    max-width: 390px;
    padding: 13px 16px;
    color: #fff;
    background: var(--navy-900);
    border-left: 4px solid var(--gold-500);
    border-radius: 8px;
    box-shadow: 0 14px 36px rgba(13, 27, 42, 0.25);
    font-size: 0.86rem;
    line-height: 1.4;
}

.toast.is-error {
    background: #7a271a;
    border-left-color: #fda29b;
}

@media (max-width: 900px) {
    .control-panel {
        position: static;
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .actions {
        padding: 0;
    }

    .document-sheet {
        min-height: auto;
        padding: 32px 34px 140px 46px;
    }

    .document-footer {
        right: 34px;
        bottom: 28px;
        left: 46px;
    }
}

@media (max-width: 620px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .app-brand {
        flex-direction: column;
        align-items: flex-start;
        gap: 7px;
        width: 100%;
    }

    .app-brand img {
        width: min(300px, 100%);
    }

    .app-brand span {
        padding-left: 0;
        border-left: 0;
    }

    .app-brand span,
    .back-link {
        font-size: 0.72rem;
    }

    .app-navigation {
        justify-content: flex-start;
        width: 100%;
    }

    .workspace {
        width: min(100% - 20px, 1180px);
        margin-top: 18px;
    }

    .control-panel {
        padding: 14px;
    }

    .mode-tabs,
    .lookup-row,
    .actions {
        grid-template-columns: 1fr;
        flex-direction: column;
    }

    .button {
        width: 100%;
    }

    .document-sheet {
        padding: 24px 22px 150px 34px;
    }

    .letterhead {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .letterhead-brand {
        flex-direction: column;
        align-items: flex-start;
    }

    .letterhead-logo {
        width: min(300px, 100%);
        max-width: 100%;
    }

    .institution-area {
        margin: 8px 0 0;
        padding: 7px 0 0;
        border-top: 1px solid var(--gold-500);
        border-left: 0;
    }

    .folio-box {
        grid-column: 1 / -1;
        text-align: left;
    }

    .data-grid,
    .registration-meta {
        grid-template-columns: 1fr;
    }

    .field:nth-child(odd) {
        border-right: 0;
    }

    .field-wide {
        grid-column: auto;
    }

    .document-footer {
        right: 22px;
        left: 34px;
        gap: 12px;
    }

    .data-card-heading {
        gap: 8px;
    }

    .privacy-footer > div:first-child {
        max-width: 68%;
    }

    .footer-bottom-row > div:first-child {
        max-width: 68%;
    }
}

@page {
    size: letter portrait;
    margin: 0;
}

@media print {
    html,
    body {
        width: 8.5in;
        height: 11in;
        margin: 0;
        background: #fff;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    .no-print {
        display: none !important;
    }

    .workspace {
        width: auto;
        margin: 0;
    }

    .document-stack {
        display: block;
    }

    .document-sheet {
        width: 8.5in;
        height: 11in;
        min-height: 11in;
        margin: 0;
        padding: 0.48in 0.66in 0.52in;
        border: 0;
        box-shadow: none;
        break-after: page;
        page-break-after: always;
    }

    .document-sheet:last-child {
        break-after: auto;
        page-break-after: auto;
    }

    .document-page-continuation {
        padding-top: 0.34in;
        padding-bottom: 0.3in;
    }

    .document-page-continuation .letterhead {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 14px;
        padding-bottom: 10px;
    }

    .document-page-continuation .letterhead-logo {
        width: 285px;
        max-width: 68%;
    }

    .document-page-continuation .institution-area {
        margin: 0 0 0 12px;
        padding-left: 12px;
        font-size: 0.66rem;
    }

    .document-page-continuation .folio-box {
        padding: 8px 10px;
    }

    .document-page-continuation .document-title {
        margin: 14px 0 4px;
        font-size: 1.3rem;
    }

    .document-page-continuation .document-subtitle {
        margin-bottom: 10px;
        font-size: 0.67rem;
    }

    .document-page-continuation .data-card-heading {
        padding: 8px 12px;
    }

    .document-page-continuation .questionnaire-grid .question-field {
        padding-top: 7px;
        padding-bottom: 7px;
    }

    .document-page-continuation .questionnaire-grid .question-field > label {
        margin-bottom: 4px;
        font-size: 0.67rem;
    }

    .document-page-continuation .conditional-block {
        margin-top: 5px;
        padding: 6px 8px;
    }

    .document-page-continuation .conditional-input {
        margin-top: 4px;
    }

    .document-page-continuation .privacy-notice {
        margin-top: 8px;
        padding: 8px 10px;
    }

    .document-page-continuation .privacy-notice h2 {
        margin-bottom: 4px;
        font-size: 0.66rem;
    }

    .document-page-continuation .privacy-notice p {
        margin: 3px 0;
        font-size: 0.56rem;
        line-height: 1.28;
    }

    .document-page-continuation .privacy-consent {
        margin-top: 4px;
        font-size: 0.56rem;
        line-height: 1.25;
    }

    .document-page-continuation .privacy-consent input {
        width: 12px;
        height: 12px;
    }

    .document-page-continuation .statement {
        margin: 7px 0 6px;
        font-size: 0.64rem;
        line-height: 1.35;
    }

    .document-page-continuation .registration-meta-footer {
        margin-bottom: 5px;
        padding: 5px 9px;
    }

    .document-page-continuation .registration-meta-footer .meta-value {
        font-size: 0.76rem;
    }

    .document-page-continuation .document-footer {
        position: static;
        right: auto;
        bottom: auto;
        left: auto;
    }

    .document-input {
        border-bottom-color: transparent;
    }

    .document-input::placeholder {
        color: transparent;
    }

    select.document-input {
        appearance: none;
        -webkit-appearance: none;
    }

    .document-footer {
        right: 0.66in;
        bottom: 0.34in;
        left: 0.66in;
    }
}
