:root {
    --brand: #3D3E8F;
    --accent: #3D3E8F;
    --ink: #222;
    --muted: #666;
    --line: #b9b9c4;
    --error: #b42318;
    --error-bg: #fef3f2;
    --ok-bg: #ecfdf3;
    --ok: #067647;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: #e9eaf0;
    color: var(--ink);
    font: 15px/1.45 Arial, "Helvetica Neue", Helvetica, sans-serif;
}

.sheet {
    max-width: 920px;
    margin: 24px auto;
    background: #fff;
    box-shadow: 0 2px 14px rgba(0, 0, 0, .12);
}

/* ---------- Header / footer (portal branding) ---------- */
/* White header so any logo colour stays visible; the brand colour is the bar underneath. */
.brand-header {
    background: #fff;
    color: #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 16px 28px;
    min-height: 100px;
}
.brand-header .brand-id { max-width: 55%; }
.brand-header .logo { max-height: 72px; max-width: 100%; display: block; }
.brand-header .brand-name { font-size: 24px; font-weight: bold; color: var(--brand); }
.brand-header .contact { text-align: right; font-size: 14px; line-height: 1.6; }
.brand-header .contact a { color: inherit; text-decoration: none; }
.brand-header .form-code { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
/* Light logos (white / light-grey / yellow lettering on transparent) get a neutral dark background. */
.brand-header.dark { background: linear-gradient(135deg, #1f2933 0%, #323f4b 100%); color: #fff; }
.brand-header.dark .form-code { color: rgba(255, 255, 255, .7); }
.brand-header.dark .brand-name { color: #fff; }
.brand-bar { height: 8px; background: var(--brand); border-bottom: 4px solid var(--accent); }

.brand-footer {
    background: var(--brand);
    color: #fff;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 28px;
    font-size: 12px;
}

main { padding: 18px 28px 28px; }

.title {
    text-align: center;
    color: var(--brand);
    font-weight: normal;
    text-decoration: underline;
    text-underline-offset: 4px;
    margin: 6px 0 2px;
    font-size: 28px;
}
.subtitle { text-align: center; font-style: italic; color: #444; margin: 0 0 18px; }

/* ---------- Notices ---------- */
.notice { padding: 14px 16px; border-radius: 6px; margin: 14px 0; }
.notice.error { background: var(--error-bg); color: var(--error); border: 1px solid #fecdca; }
.notice.success { background: var(--ok-bg); color: var(--ok); border: 1px solid #abefc6; text-align: center; padding: 28px; }
.notice.success h2 { margin-top: 0; }

/* ---------- Prefilled (read-only) block ---------- */
.prefilled { margin-bottom: 8px; }
.lock-note { font-size: 13px; color: var(--muted); background: #f4f4f8; padding: 6px 10px; border-radius: 4px; margin: 0 0 8px; }
.row { display: flex; gap: 22px; }
.field { flex: 1; display: flex; align-items: baseline; gap: 6px; padding: 8px 0; min-width: 0; }
.field.grow-3 { flex: 3; }
.field.grow-2 { flex: 2; }
.field label { white-space: nowrap; }
.field .value {
    flex: 1;
    min-width: 40px;
    border-bottom: 1px solid var(--line);
    font-weight: bold;
    padding: 0 4px 1px;
    min-height: 1.4em;
    overflow-wrap: anywhere;
}

.field .editable { background: #fffbea; font-weight: bold; }
.field.invalid .editable { border-bottom-color: var(--error); }
.req { color: var(--error); }
.notice.info { background: #eff4ff; color: #1d3f8f; border: 1px solid #c7d7fe; text-align: center; padding: 28px; }
.notice h2 { margin-top: 0; }

/* Honeypot: off-screen rather than display:none, so naive bots still fill it */
.hp { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }

/* ---------- Sections ---------- */
fieldset.section { border: 0; margin: 14px 0 0; padding: 0; min-width: 0; }
.bar {
    display: block;
    width: 100%;
    background: var(--brand);
    color: #fff;
    padding: 3px 10px;
    font-size: 15px;
}
.section.invalid .bar { box-shadow: inset 4px 0 0 var(--error); }

.tick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 16px; padding: 12px 10px 4px; }
.tick { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.tick input, .sources input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; }
.other-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.line-input {
    flex: 1;
    border: 0;
    border-bottom: 1px solid var(--line);
    font: inherit;
    padding: 4px;
    outline: none;
}
.line-input:focus, textarea:focus { border-color: var(--brand); background: #f7f7fc; }
.line-input:disabled { background: transparent; }

.instructions { font-size: 14px; padding: 6px 12px 2px; font-style: italic; }
.instructions ol { margin: 4px 0 6px; padding-left: 40px; }
.instructions li { margin-bottom: 6px; }

table.sources { width: 100%; border-collapse: collapse; font-size: 14px; }
.sources th { background: var(--brand); color: #fff; text-align: left; padding: 3px 8px; font-weight: normal; }
.sources td { border: 1px solid #d5d5de; padding: 6px 8px; vertical-align: middle; }
.sources td label { cursor: pointer; display: block; }
.sources ul { margin: 0; padding-left: 18px; }
.c-tick { width: 70px; text-align: center !important; }

.block-label { display: block; padding: 8px 10px 2px; font-size: 14px; }
textarea {
    width: calc(100% - 20px);
    margin: 0 10px;
    border: 0;
    border-bottom: 1px solid var(--line);
    font: inherit;
    resize: vertical;
    outline: none;
    padding: 4px;
}

/* ---------- Uploads ---------- */
.upload {
    margin: 10px 0 0;
    border: 2px dashed #c9c9d6;
    border-radius: 6px;
    padding: 14px;
    text-align: center;
}
.upload.drag { border-color: var(--brand); background: #f4f4fb; }
.upload input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload .hint { display: block; color: var(--muted); font-size: 13px; margin-top: 8px; }
.file-list { list-style: none; margin: 10px 0 0; padding: 0; text-align: left; }
.file-list li { display: flex; justify-content: space-between; padding: 6px 8px; border-bottom: 1px solid #eee; }

/* ---------- Declaration / signature ---------- */
.declaration { margin-top: 20px; }
.brand-text { color: var(--brand); }
.declaration p { margin: 0 0 10px; }
.accept { margin: 4px 0; font-weight: bold; }
.accept.invalid { color: var(--error); }

.sign-row { display: flex; gap: 40px; align-items: flex-start; margin-top: 18px; flex-wrap: wrap; }
.sign-block { flex: 1 1 340px; }
.date-block { flex: 0 1 220px; display: flex; flex-direction: column; }
.sign-block > label, .date-block > label { display: block; margin-bottom: 6px; }
.sig-wrap { position: relative; }
#sig-pad {
    width: 100%;
    height: 150px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #fcfcff;
    touch-action: none;
    cursor: crosshair;
    display: block;
}
.sign-block.invalid #sig-pad { border-color: var(--error); }
.sig-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #b8b8c8;
    font-style: italic;
    pointer-events: none;
}
input[type=date] {
    font: inherit;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 4px;
}
.date-block.invalid input { border-color: var(--error); }

.error-text { display: block; color: var(--error); font-size: 13px; padding: 4px 10px 0; min-height: 0; }
.error-text:empty { display: none; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    border: 1px solid var(--brand);
    color: var(--brand);
    background: #fff;
    padding: 8px 18px;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
}
.btn.primary { background: var(--brand); color: #fff; font-size: 16px; padding: 12px 32px; }
.btn:disabled { opacity: .6; cursor: wait; }
.link-btn { background: none; border: 0; color: var(--brand); text-decoration: underline; cursor: pointer; font: inherit; font-size: 13px; padding: 4px 0; }
.actions { text-align: center; margin-top: 28px; }

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

/* ---------- Mobile ---------- */
@media (max-width: 680px) {
    .sheet { margin: 0; box-shadow: none; }
    main { padding: 14px 16px 24px; }
    .brand-header { flex-direction: column; align-items: flex-start; padding: 14px 16px; }
    .brand-header .logo { max-width: 100%; max-height: 64px; }
    .brand-header .contact { text-align: left; font-size: 13px; }
    .brand-footer { padding: 8px 16px; }
    .row { flex-direction: column; gap: 0; }
    .field { flex-wrap: wrap; }
    .tick-grid { grid-template-columns: 1fr; }
    .title { font-size: 22px; }
    .sources thead th:last-child { font-size: 12px; }
    .c-tick { width: 44px; }
}
