// =============================================================================
// Patient registration
//
// A long form that one person fills in while another stands at the desk. The
// shape follows from that: fields are grouped into cards so the eye lands on a
// section rather than a wall of forty inputs, the save controls never leave the
// screen, and the rail on the right answers "how much is left?" without anyone
// scrolling to find out.
//
// Control sizing is scoped to .clinic-register on purpose. Taller inputs suit a
// form that is typed into once; a filter bar or a settings tab is not improved
// by 48px controls, so those keep Bootstrap's own metrics.
// =============================================================================

.clinic-register {
    --clinic-field-height: 3rem;
    --clinic-field-radius: 0.75rem;
    --clinic-section-radius: 1rem;

    padding-bottom: 1rem;
}

.clinic-register__grid {
    display: grid;
    gap: 1.5rem;
    align-items: start;
    grid-template-columns: minmax(0, 1fr);
}

.clinic-register__main {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-width: 0;
}

// The rail only earns its column when there is room for it beside the form.
// Below that it would squeeze every field into a gutter, so it is dropped.
@media (min-width: 1200px) {
    .clinic-register__grid {
        grid-template-columns: minmax(0, 1fr) 17rem;
    }

    .clinic-register__aside {
        position: sticky;
        top: calc(var(--clinic-topbar-height) + 1.5rem);
    }
}

.clinic-register__legend {
    margin-top: 0.875rem;
    margin-bottom: 0;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--clinic-text-muted);
}

// -----------------------------------------------------------------------------
// A card of fields
// -----------------------------------------------------------------------------
.clinic-form-section {
    background: var(--clinic-surface);
    border: 1px solid var(--clinic-border);
    border-radius: var(--clinic-section-radius, 1rem);
    box-shadow: 0 1px 2px rgb(15 23 42 / 5%), 0 8px 24px -18px rgb(15 23 42 / 30%);
    overflow: hidden;
}

.clinic-form-section__head {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 1.125rem 1.5rem;
    border-bottom: 1px solid var(--clinic-border);
}

.clinic-form-section__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.625rem;
    font-size: 1rem;
    color: var(--clinic-primary);
    background: color-mix(in srgb, var(--clinic-primary) 10%, transparent);
}

.clinic-form-section__heading {
    min-width: 0;
    margin-inline-end: auto;
}

.clinic-form-section__title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--clinic-text);
}

.clinic-form-section__subtitle {
    margin: 0.125rem 0 0;
    font-size: 0.8125rem;
    line-height: 1.45;
    color: var(--clinic-text-muted);
}

.clinic-form-section__badge {
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--clinic-text-muted);
    background: var(--clinic-surface-alt);
    border: 1px solid var(--clinic-border);
}

// Revealed from resources/js once every required field in the card has a value.
.clinic-form-section__state {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.375rem;
    height: 1.375rem;
    border-radius: 50%;
    font-size: 0.8125rem;
    color: #fff;
    background: #16a34a;
}

.clinic-form-section__toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 0.5rem;
    background: transparent;
    color: var(--clinic-text-muted);
    transition: background-color 120ms ease, transform 200ms ease;

    &:hover,
    &:focus-visible {
        background: var(--clinic-surface-alt);
        color: var(--clinic-text);
    }

    &[aria-expanded="false"] {
        transform: rotate(180deg);
    }
}

.clinic-form-section__body {
    display: grid;
    grid-template-rows: 1fr;
    transition: grid-template-rows 200ms ease;
}

.clinic-form-section__fields {
    overflow: hidden;
    padding: 1.5rem;
}

.clinic-form-section--collapsed .clinic-form-section__body {
    grid-template-rows: 0fr;
}

// -----------------------------------------------------------------------------
// Controls
// -----------------------------------------------------------------------------
.clinic-field {
    position: relative;
}

.clinic-field__icon {
    position: absolute;
    inset-block-start: 50%;
    inset-inline-start: 0.875rem;
    transform: translateY(-50%);
    font-size: 0.9375rem;
    line-height: 1;
    color: var(--clinic-text-muted);
    pointer-events: none;
}

.clinic-register {
    .form-label {
        margin-bottom: 0.375rem;
        font-size: 0.8125rem;
        font-weight: 500;
        color: var(--clinic-text);
    }

    .form-control,
    .form-select {
        min-height: var(--clinic-field-height);
        padding-inline: 0.875rem;
        border-radius: var(--clinic-field-radius);
        border-color: var(--clinic-border);
        background-color: var(--clinic-surface);
        font-size: 0.9375rem;
        transition: border-color 120ms ease, box-shadow 120ms ease;

        &::placeholder {
            color: color-mix(in srgb, var(--clinic-text-muted) 75%, transparent);
        }

        &:focus {
            border-color: var(--clinic-primary);
            box-shadow: 0 0 0 4px color-mix(in srgb, var(--clinic-primary) 14%, transparent);
        }
    }

    textarea.form-control {
        min-height: auto;
        padding-block: 0.75rem;
    }

    .clinic-field--icon {
        .form-control,
        .form-select {
            padding-inline-start: 2.5rem;
        }
    }

    .form-text,
    .invalid-feedback {
        font-size: 0.75rem;
    }
}

// -----------------------------------------------------------------------------
// Age or date of birth
//
// The switch sits where a label would, because in this one column the choice of
// what is being recorded *is* the label. It only appears once the script has
// run; without it the block is the plain date field and its own label.
// -----------------------------------------------------------------------------
/*
 | An ordinary dropdown, like every other one on this screen.
 |
 | It began as a quiet, borderless control on the theory that it was a label
 | rather than a field. On the form it read as neither: a word with a chevron
 | floating over an empty box, while Gender and Blood group beside it were
 | plainly dropdowns. It is a choice the person makes, so it looks like one.
 */
.clinic-dob__switch {
    margin-bottom: 0.375rem;

    .form-select {
        // Sized to its longest option rather than stretched across the column,
        // so the value box beside it gets the room instead.
        width: auto;
        min-width: 8.5rem;
        max-width: 100%;
    }
}

// The switch already names the field, so the date input's own label would say
// the same word twice.
.clinic-dob--enhanced .clinic-dob__date .form-label {
    display: none;
}

/*
 | The switch and the value on one line, beside the name.
 |
 | "Age or date of birth?" and "which one" are a single question, and stacking
 | the chooser above the box made them read as two — with the chooser floating
 | unlabelled over an empty field. Side by side, the switch reads as the label
 | it is.
 |
 | Only when the script has run. Without it there is no switch to place, and
 | the block stays the plain date field it has always been.
 */
.clinic-dob--inline.clinic-dob--enhanced {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;

    // Sized to its longest option ("Date of birth") and no wider.
    .clinic-dob__switch {
        flex: 0 0 auto;
        margin-bottom: 0;

        // Drops the chooser onto the same baseline as the input beside it,
        // clearing the label row that input does not have.
        margin-top: 1.75rem;
    }

    [data-clinic-dob-age],
    .clinic-dob__date {
        flex: 1 1 auto;
        min-width: 0;
    }

    // The age box has no label of its own — the switch is it — so it needs the
    // same top offset to line up with the name field beside it.
    [data-clinic-dob-age] { margin-top: 1.75rem; }
}

.clinic-check {
    padding-inline-start: 1.75rem;

    .form-check-input {
        width: 1.05rem;
        height: 1.05rem;
        margin-inline-start: -1.75rem;
        border-color: var(--clinic-border);
        border-radius: 0.3125rem;

        &:checked {
            background-color: var(--clinic-primary);
            border-color: var(--clinic-primary);
        }

        &:focus {
            border-color: var(--clinic-primary);
            box-shadow: 0 0 0 4px color-mix(in srgb, var(--clinic-primary) 14%, transparent);
        }
    }

    .form-check-label {
        color: var(--clinic-text-muted);
    }
}

// The duplicate confirmation is a decision, not a preference. It gets a surface
// of its own so it is not ticked on the way past.
.clinic-check--emphasis {
    padding: 1rem;
    padding-inline-start: 2.75rem;
    border: 1px solid #f59e0b;
    border-radius: 1rem;
    background: color-mix(in srgb, #f59e0b 8%, var(--clinic-surface));

    .form-check-label {
        font-weight: 500;
        color: var(--clinic-text);
    }
}

// -----------------------------------------------------------------------------
// Completion rail
// -----------------------------------------------------------------------------
.clinic-form-progress {
    padding: 1.25rem;
    background: var(--clinic-surface);
    border: 1px solid var(--clinic-border);
    border-radius: 1rem;
    box-shadow: 0 1px 2px rgb(15 23 42 / 5%);
}

.clinic-form-progress__title {
    margin: 0 0 0.875rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--clinic-text-muted);
}

.clinic-form-progress__list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.clinic-form-progress__link {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.375rem 0;
    font-size: 0.8125rem;
    color: var(--clinic-text-muted);
    text-decoration: none;
    border-radius: 0.5rem;

    &:hover {
        color: var(--clinic-text);
    }
}

.clinic-form-progress__dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 1.25rem;
    height: 1.25rem;
    border: 1.5px solid var(--clinic-border);
    border-radius: 50%;
    font-size: 0.75rem;
    color: transparent;
    background: var(--clinic-surface);
    transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.clinic-form-progress__step--done {
    .clinic-form-progress__dot {
        color: #fff;
        background: #16a34a;
        border-color: #16a34a;
    }

    .clinic-form-progress__label {
        color: var(--clinic-text);
    }
}

.clinic-form-progress__required {
    color: var(--bs-danger);
}

.clinic-form-progress__meta {
    margin: 0.875rem 0 0;
    padding-top: 0.75rem;
    border-top: 1px solid var(--clinic-border);
    font-size: 0.75rem;
    color: var(--clinic-text-muted);
}

// -----------------------------------------------------------------------------
// Draft state
// -----------------------------------------------------------------------------
.clinic-draft-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4375rem;
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--clinic-border);
    border-radius: 999px;
    font-size: 0.75rem;
    color: var(--clinic-text-muted);
    background: var(--clinic-surface);
}

.clinic-draft-restore {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
    padding: 0.875rem 1.125rem;
    border: 1px solid var(--clinic-border);
    border-radius: 1rem;
    background: var(--clinic-surface);
    box-shadow: 0 1px 2px rgb(15 23 42 / 5%);

    > .bi {
        color: var(--clinic-primary);
    }
}

.clinic-draft-restore__text {
    margin-inline-end: auto;
    font-size: 0.875rem;
    color: var(--clinic-text);
}

// -----------------------------------------------------------------------------
// What happens after the record exists
// -----------------------------------------------------------------------------
.clinic-next-steps {
    padding: 1.25rem 1.5rem;
    border: 1px dashed var(--clinic-border);
    border-radius: 1rem;
    background: var(--clinic-surface-alt);
}

.clinic-next-steps__title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--clinic-text);

    .bi {
        color: var(--clinic-text-muted);
    }
}

.clinic-next-steps__intro {
    margin: 0.375rem 0 1rem;
    font-size: 0.8125rem;
    line-height: 1.5;
    color: var(--clinic-text-muted);
}

.clinic-next-steps__list {
    display: grid;
    gap: 0.875rem;
    margin: 0;
    padding: 0;
    list-style: none;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
}

.clinic-next-steps__item {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    font-size: 0.8125rem;

    > .bi {
        margin-top: 0.125rem;
        color: var(--clinic-primary);
    }
}

.clinic-next-steps__label {
    display: block;
    font-weight: 600;
    color: var(--clinic-text);
}

.clinic-next-steps__desc {
    display: block;
    line-height: 1.45;
    color: var(--clinic-text-muted);
}

// -----------------------------------------------------------------------------
// Sticky action bar
// -----------------------------------------------------------------------------
.clinic-form-actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin-top: 1.5rem;
    // Bleeds into the content padding so the bar reads as a floor for the page
    // rather than a card that happens to be last.
    margin-inline: -1.5rem;
    padding: 0.875rem 1.5rem;
    border-top: 1px solid var(--clinic-border);
    background: color-mix(in srgb, var(--clinic-surface) 88%, transparent);
    backdrop-filter: blur(8px);

    .btn {
        display: inline-flex;
        align-items: center;
        gap: 0.4375rem;
        min-height: 2.75rem;
        padding-inline: 1.125rem;
        border-radius: 0.75rem;
        font-size: 0.9375rem;
        font-weight: 500;
    }
}

.clinic-form-actions__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.clinic-form-actions__start,
.clinic-form-actions__end {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

// On a phone the secondary controls stop competing for the same row as the one
// button the user actually came here to press.
@media (max-width: 575.98px) {
    .clinic-form-actions__inner {
        flex-direction: column-reverse;
        align-items: stretch;
    }

    .clinic-form-actions__end .btn {
        flex: 1 1 0;
        justify-content: center;
    }

    .clinic-form-actions__start {
        justify-content: center;
    }
}

.clinic-btn-primary {
    color: #fff;
    border: 0;
    background-image: linear-gradient(180deg, var(--clinic-primary) 0%, #6366f1 100%);
    box-shadow: 0 1px 2px rgb(79 70 229 / 30%), 0 8px 20px -10px rgb(79 70 229 / 60%);
    transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;

    &:hover,
    &:focus-visible {
        color: #fff;
        filter: brightness(1.06);
        transform: translateY(-1px);
        box-shadow: 0 2px 4px rgb(79 70 229 / 32%), 0 12px 24px -10px rgb(79 70 229 / 65%);
    }

    &:active {
        transform: translateY(0);
    }
}

.clinic-btn-quiet {
    color: var(--clinic-text-muted);
    text-decoration: none;

    &:hover,
    &:focus-visible {
        color: var(--clinic-text);
    }
}

// -----------------------------------------------------------------------------
// Dark theme
// -----------------------------------------------------------------------------
[data-bs-theme="dark"] {
    .clinic-form-section,
    .clinic-form-progress,
    .clinic-draft-restore {
        box-shadow: none;
    }

    .clinic-next-steps {
        background: color-mix(in srgb, var(--clinic-surface) 60%, #000);
    }

    .clinic-register .form-control,
    .clinic-register .form-select {
        background-color: color-mix(in srgb, var(--clinic-surface) 70%, #000);
    }

    .clinic-form-actions {
        background: color-mix(in srgb, var(--clinic-surface) 90%, transparent);
    }
}

// The collapse and the button lift are both decorative.
@media (prefers-reduced-motion: reduce) {
    .clinic-form-section__body,
    .clinic-form-section__toggle,
    .clinic-form-progress__dot,
    .clinic-btn-primary {
        transition: none;
    }

    .clinic-btn-primary:hover {
        transform: none;
    }
}

// The action bar is a screen control; on paper it is a strip of dead ink.
@media print {
    .clinic-form-actions,
    .clinic-register__aside,
    .clinic-draft-chip,
    .clinic-draft-restore {
        display: none !important;
    }
}
