/*
 * Referral form: a narrow column with the intro, notes for vets, then the numbered steps
 * (each a bordered box). Markup: view.php; behaviour: script.js.
 */

.blk--referral-form {
    --rf-line: var(--neutral-200);
    --rf-field-line: var(--neutral-300);
    --rf-ink: var(--black);
    --rf-label: var(--neutral-800);
    --rf-muted: var(--neutral-700);
    --rf-wash: var(--neutral-100);
    --rf-beige: var(--tertiary-50);
    --rf-error-text: #B42318;   /* darker than --error, for small text (4.5:1) */
    width: 100%;
    max-width: 720px;
    margin-inline: auto;
}

.blk--referral-form [hidden] {
    display: none !important;
}

.blk--referral-form small {
    color: var(--rf-muted);
    font-size: 13px;
    font-weight: 300;
}

.referral-form__req {
    color: var(--tertiary-600);
}

/* ---------- Intro and notes ---------- */

.referral-form__intro {
    margin-bottom: var(--step-8);
}

.referral-form__intro .text-group__body {
    margin-top: var(--step-5);
}

.referral-form__owner {
    margin: calc(var(--step-8) * -1 + var(--step-6)) 0 var(--step-8);
    padding: var(--step-5) var(--step-6);
    border-radius: var(--radius);
    background: var(--rf-wash);
    font-size: 15px;
    line-height: 1.6;
}

.referral-form__owner strong {
    color: var(--neutral-700);
    font-weight: 500;
}

.referral-form__owner a {
    text-underline-offset: 3px;
}

.referral-form__notice {
    display: flex;
    gap: 14px;
    margin-bottom: var(--step-7);
    padding: var(--step-6);
    border-left: 3px solid var(--tertiary-600);
    border-radius: var(--radius);
    background: var(--rf-beige);
    color: var(--rf-ink);
}

.referral-form__notice + .referral-form__notice {
    margin-top: calc(var(--step-7) * -.5);
}

.referral-form__notice-icon {
    flex-shrink: 0;
    margin-top: 2px;
    color: var(--tertiary-600);
}

.referral-form__notice--info { border-left-color: #2B6CB0; background: #EAF2FB; }
.referral-form__notice--warning { border-left-color: #C08A1E; background: #FFF5DB; }
.referral-form__notice--error { border-left-color: #C0392B; background: #FDECEB; }
.referral-form__notice--success { border-left-color: #0B6B47; background: #E5F4EC; }
.referral-form__notice--info .referral-form__notice-icon { color: #2B6CB0; }
.referral-form__notice--warning .referral-form__notice-icon { color: #9A6A00; }
.referral-form__notice--error .referral-form__notice-icon { color: #B42318; }
.referral-form__notice--success .referral-form__notice-icon { color: #0B6B47; }

.referral-form__notice-title {
    margin-bottom: 6px;
    color: var(--rf-ink);
    font-weight: 500;
}

.referral-form__notice-text {
    font-size: 15px;
    line-height: 1.6;
}

.referral-form__notice-text > * {
    margin: 0;
    color: var(--rf-ink);
}

.referral-form__notice-text > * + * {
    margin-top: .6em;
}

.referral-form__notice-text a {
    color: var(--tertiary-600);
    text-underline-offset: 3px;
}

/* ---------- Steps ---------- */

.referral-form__step {
    min-width: 0;
    margin: 0 0 var(--step-7);
    padding: var(--step-7);
    border: 1px solid var(--rf-line);
    border-radius: var(--radius);
}

.referral-form__step legend {
    display: flex;
    align-items: center;
    gap: var(--step-3);
    margin-left: calc(var(--step-2) * -1);
    padding: 0 var(--step-2);
    color: var(--rf-ink);
    font-size: 20px;
    font-weight: 400;
}

.referral-form__step-number {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--tertiary-600);
    color: var(--white);
    font-size: 14px;
    font-weight: 500;
}

.referral-form__grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--step-5) var(--step-6);
}

.referral-form__grid > .referral-form__field--wide {
    grid-column: 1 / -1;
}

.referral-form__stack {
    display: flex;
    flex-direction: column;
    gap: var(--step-7);
}

/* ---------- Fields ---------- */

.referral-form__field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    color: var(--rf-label);
    font-size: 15px;
}

.referral-form__field > span:first-child,
.referral-form__label {
    font-weight: 400;
}

.blk--referral-form :is(input[type="text"], input[type="email"], input[type="tel"], input[type="number"], input[type="date"], select, textarea) {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--rf-field-line);
    border-radius: 8px;
    background: var(--white);
    color: var(--rf-ink);
    font-size: 16px; /* 16px keeps iOS from zooming in */
    font-weight: 300;
    line-height: 1.4;
    letter-spacing: normal;
    -webkit-text-fill-color: currentColor;
}

.blk--referral-form ::placeholder {
    color: var(--neutral-500);
    opacity: 1;
}

.blk--referral-form :is(input, textarea, select):-webkit-autofill {
    -webkit-text-fill-color: var(--rf-ink);
    -webkit-box-shadow: 0 0 0 1000px var(--white) inset;
}

.blk--referral-form textarea {
    min-height: 96px;
    resize: vertical;
}

.blk--referral-form input[readonly] {
    background: var(--rf-wash);
    color: var(--rf-muted);
}

.blk--referral-form :is(input, select, textarea, button):focus-visible {
    outline: 2px solid var(--tertiary-600);
    outline-offset: 2px;
}

.blk--referral-form :is(input[type="radio"], input[type="checkbox"]) {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--tertiary-600);
}

/* Radio and checkbox groups */
.referral-form__choice {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
    color: var(--rf-label);
    font-size: 15px;
}

.referral-form__options {
    display: flex;
    flex-wrap: wrap;
    gap: var(--step-2) var(--step-6);
}

.referral-form__options label {
    display: inline-flex;
    align-items: center;
    gap: var(--step-2);
    cursor: pointer;
}

/* Follow-ups under their question */
.referral-form__detail {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 520px;
    margin-top: 10px;
    font-size: 14px;
}

.referral-form__hint {
    margin-top: var(--step-2);
    color: var(--rf-muted);
    font-size: 14px;
}

.referral-form__alert {
    margin-top: 10px;
    padding: 10px 14px;
    border-left: 3px solid var(--tertiary-600);
    border-radius: 8px;
    background: var(--rf-beige);
    color: var(--rf-ink);
    font-size: 14px;
    line-height: 1.5;
}

/* ---------- Email verification ---------- */

.referral-form__verify {
    margin-top: var(--step-5);
    padding-top: var(--step-5);
    border-top: 1px solid var(--rf-line);
}

.referral-form__verify > .referral-form__field--wide {
    margin-top: var(--step-5);
}

.referral-form__turnstile:not(:empty) {
    margin-top: var(--step-5);
}

.referral-form__verify-actions,
.referral-form__code {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--step-4);
    margin-top: var(--step-5);
}

.referral-form__code .referral-form__field {
    width: 160px;
}

.referral-form__code input {
    font-variant-numeric: tabular-nums;
    letter-spacing: .3em;
}

.referral-form__remember {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    color: var(--rf-label);
    font-size: 15px;
    cursor: pointer;
}

.referral-form__remember input {
    margin-top: 2px !important;
}

.referral-form__remember small {
    display: block;
}

.referral-form__text-button {
    padding: var(--step-2) 0;
    color: var(--tertiary-600);
    font-size: 14px;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.referral-form__verified {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: var(--step-4);
    color: var(--success);
    font-weight: 400;
}

/* Status lines (verifying, sending): only take room when there's something to say */
.referral-form__status {
    margin-top: var(--step-4);
    font-size: 14px;
}

.referral-form__status:empty {
    display: none;
}

.referral-form__status[data-tone="error"] {
    color: var(--rf-error-text);
}

.referral-form__status[data-tone="success"] {
    color: var(--success);
}

.blk--referral-form .is-working {
    opacity: .6;
    cursor: progress;
}

/* ---------- Diagnostics: one row per test (name · OD · OS · Not performed) ---------- */

.referral-form__tests {
    gap: var(--step-2);
}

.referral-form__tests > small {
    margin-bottom: var(--step-1);
}

.referral-form__tests-head,
.referral-form__test {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr) 150px;
    align-items: center;
    gap: var(--step-2) var(--step-3);
}

.referral-form__tests-head {
    padding: 0 var(--step-3);
    font-size: 13px;
    font-weight: 500;
}

.referral-form__test {
    padding: 10px var(--step-3);
    border: 1px solid var(--rf-line);
    border-radius: 8px;
    background: var(--neutral-50);
}

.referral-form__test-eye {
    display: flex;
    flex-direction: column;
    gap: var(--step-1);
}

.referral-form__test-eye-label {
    display: none;
    font-size: 13px;
    font-weight: 500;
}

.blk--referral-form .referral-form__test :is(input[type="number"], select) {
    padding: var(--step-2) 10px;
}

.blk--referral-form .referral-form__test :is(input, select):disabled {
    border-color: var(--rf-line);
    background: var(--neutral-100);
    color: var(--neutral-500);
    cursor: not-allowed;
}

.referral-form__test.is-skipped .referral-form__test-name {
    color: var(--rf-muted);
}

.referral-form__test-skip {
    display: inline-flex;
    align-items: center;
    gap: var(--step-2);
    font-size: 14px;
    white-space: nowrap;
    cursor: pointer;
}

.referral-form__test > .referral-form__error {
    grid-column: 1 / -1;
}

/* ---------- Records ---------- */

/* The real file input sits invisibly over the "Attach files" button */
.referral-form__picker {
    position: relative;
    align-self: flex-start;
    cursor: pointer;
}

.referral-form__picker input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.referral-form__picker:focus-within .btn {
    outline: 2px solid var(--tertiary-600);
    outline-offset: 2px;
}

.referral-form__file-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.referral-form__file-list:empty {
    display: none;
}

.referral-form__file-list li {
    display: flex;
    align-items: center;
    gap: var(--step-3);
    margin: 0;
    padding: 10px var(--step-3);
    border: 1px solid var(--rf-line);
    border-radius: 8px;
    font-size: 14px;
}

.referral-form__file-list li + li {
    margin-top: 6px;
}

.referral-form__file-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    color: var(--rf-ink);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.referral-form__file-size {
    color: var(--rf-muted);
    white-space: nowrap;
}

/* ---------- Consent, sending, done ---------- */

.referral-form__consent {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-top: var(--step-7);
    padding: var(--step-5);
    border-radius: 8px;
    background: var(--rf-wash);
    color: var(--rf-label);
    font-size: 15px;
    line-height: 1.5;
    cursor: pointer;
}

.referral-form__consent input {
    margin-top: 2px !important;
}

.referral-form__submit {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--step-5);
}

.referral-form__closing {
    margin-bottom: var(--step-5);
    color: var(--rf-muted);
    font-style: italic;
}

/* Off-screen for people; still in the form for bots */
.referral-form__trap {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.referral-form__done {
    padding: var(--step-8);
    border-radius: var(--radius);
    background: var(--rf-wash);
    color: var(--neutral-700);
    font-size: 18px;
    line-height: 1.6;
}

.referral-form__done:focus {
    outline: none;
}

.referral-form__done .btn {
    margin-top: var(--step-6);
}

/* ---------- Field messages (script.js) ---------- */

.referral-form__error {
    display: block;
    margin-top: 2px;
    color: var(--rf-error-text) !important;
    font-size: 13px;
    font-weight: 400 !important;
}

/* (the consent box is in a stack with a large gap: pull its message up under it) */
.referral-form__consent + .referral-form__error {
    margin-top: calc(var(--step-7) * -1 + var(--step-2));
}

.blk--referral-form .has-error :is(input[type="text"], input[type="email"], input[type="tel"], input[type="number"], input[type="date"], select, textarea) {
    border-color: var(--error) !important;
}

.referral-form__test.has-error,
.referral-form__consent.has-error {
    box-shadow: inset 0 0 0 1px var(--error);
}

.referral-form__files.has-error .btn {
    border-color: var(--error);
}

/* ---------- Phones ---------- */

@media (max-width: 600px) {
    .referral-form__step {
        padding: var(--step-6) var(--step-5);
    }

    .referral-form__grid {
        grid-template-columns: 1fr;
    }

    .referral-form__options {
        flex-direction: column;
        gap: 10px;
    }

    .referral-form__submit .btn {
        width: 100%;
    }

    .referral-form__tests-head {
        display: none;
    }

    .referral-form__test {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-areas: "name skip" "od os";
    }

    .referral-form__test-name { grid-area: name; }
    .referral-form__test-eye:nth-of-type(1) { grid-area: od; }
    .referral-form__test-eye:nth-of-type(2) { grid-area: os; }

    .referral-form__test-skip {
        grid-area: skip;
        justify-self: end;
    }

    .referral-form__test-eye-label {
        display: block;
    }
}
