/* Karla (SIL Open Font License), variable font, Latin subset. Source: Fontsource (https://fontsource.org/fonts/karla) */
@font-face {
    font-family: "Karla";
    font-style: normal;
    font-weight: 200 800;
    font-display: swap;
    src: url("../fonts/karla-latin-wght-normal.woff2") format("woff2");
}

/* ======================================================================
   Tokens, and the Keycloak / PatternFly hooks that take plain values
   (assigning a variable is far cheaper to maintain than overriding a rule)
   ====================================================================== */
:root {
    /* Brand */
    --magnolia-dark: #02373F;
    --magnolia-dark-hover: #05505c;
    /* Accessible variants of the brand green and sage (the logo and artwork keep the original #00B054) */
    --magnolia-link: #00873F;          /* 4.63:1 on white (text needs 4.5:1) */
    --magnolia-link-on-dark: #4CD08A;  /* 6.6:1 on the dark page background */
    --magnolia-input-border: #6E9F83;  /* 3.02:1 on white (field boundaries need 3:1, WCAG 1.4.11) */
    --magnolia-band: #E2F0E4;

    /* Shape */
    --magnolia-card-width: 34rem; /* stock Keycloak width at desktop sizes */
    --magnolia-card-radius: 16px;
    --magnolia-card-padding: 40px;
    --magnolia-gap: 24px;
    --magnolia-radius: 8px;
    --magnolia-input-height: 48px;
    --magnolia-button-height: 44px;
    --magnolia-logo-height: 40px; /* header logo */

    --magnolia-font: "Karla", "Helvetica Neue", Arial, sans-serif;

    /* PatternFly: font, base size (also drives buttons, inputs, checkboxes), text, link and primary colours */
    --pf-v5-global--FontFamily--text: var(--magnolia-font);
    --pf-v5-global--FontFamily--heading: var(--magnolia-font);
    --pf-v5-global--FontSize--md: 0.875rem;
    accent-color: var(--magnolia-dark);
    --pf-v5-global--Color--100: var(--magnolia-dark);
    --pf-v5-global--link--Color: var(--magnolia-link);
    --pf-v5-global--link--Color--hover: var(--magnolia-link);
    --pf-v5-global--primary-color--100: var(--magnolia-dark);
    --pf-v5-global--primary-color--200: var(--magnolia-dark-hover);

    /* Keycloak v2 */
}

/* ======================================================================
   Page: background, vertical centring, footer
   ====================================================================== */

/* Fit the artwork to the viewport width and pin it to the bottom edge instead of cropping it ("cover") */
.login-pf body {
    background: var(--magnolia-dark) url("../img/background.svg") no-repeat fixed center bottom / 100% auto;
}

/*
 * One column as tall as the viewport: the card is centred in the space above the footer (its auto margins share the
 * free space), and the footer sits at the bottom of the page. With no free space, the footer simply follows the card
 * and the page scrolls.
 */
.login-pf .pf-v5-c-login {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    padding: 1.5rem 1rem 0;
}

/* template.ftl renders the footer below the card */
#kc-page-footer {
    padding: 1.5rem 1rem;
    text-align: center;
    color: #fff;
    font-size: 0.75rem;
}

/* The footer sits on the dark background, where the link colour used on white would not have enough contrast */
#kc-page-footer a {
    color: var(--magnolia-link-on-dark);
}

/* A narrow screen breaks the line before the company name, not inside it (footer.ftl marks the part to keep together) */
#kc-page-footer .nowrap {
    white-space: nowrap;
}

/* ======================================================================
   Card: PatternFly's container holds the stock <header> (our logo) and <main> (the form),
   so no template override is needed to get the logo inside the white box.
   ====================================================================== */

/* PatternFly only makes the container a grid on wide screens; a plain block is all we need */
.login-pf .pf-v5-c-login__container {
    display: block;
    max-width: var(--magnolia-card-width);
    margin: auto; /* centred in the free space above the footer */
    padding: 0; /* PatternFly adds side padding here on wide screens */
    background: #fff;
    border-radius: var(--magnolia-card-radius);
    overflow: hidden;
}

.login-pf .pf-v5-c-login__main {
    background: transparent;
    box-shadow: none;
    margin-block-end: 0;
}

/* Logo: the stock header shows the realm name as text; show our logo instead (the name stays for screen readers) */
.login-pf .pf-v5-c-login__container > .pf-v5-c-login__header {
    margin: 0;
    padding: var(--magnolia-card-padding) var(--magnolia-card-padding) 0;
}

/*
 * Header: the application's logo (its "Logo URL") or the Magnolia logo, --magnolia-logo-height tall at its natural width, with the
 * application's name, if any, below it. A long name wraps onto more lines. template.ftl renders both.
 */
.login-pf #kc-header-wrapper {
    margin: 0;
    text-align: left;
    text-transform: none; /* the stock header styling is centred, upper-case and letter-spaced */
    letter-spacing: normal;
}

.login-pf #kc-header-wrapper img {
    display: block;
    height: var(--magnolia-logo-height);
    max-width: 100%;
    object-fit: contain; /* keeps the proportions if the card is narrower than the logo */
    object-position: left center;
}

.login-pf #kc-header-wrapper .kc-brand-name {
    display: block;
    margin-top: 12px;
    color: var(--magnolia-dark);
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.25;
    overflow-wrap: anywhere; /* an unbroken very long word wraps instead of widening the card */
}

/* Page title: shown under the logo on every page except the login page, where it stays for screen readers only */
.login-pf .pf-v5-c-login__main-header {
    border-top: 0;
    padding-block: var(--magnolia-gap) 0;
    padding-inline: var(--magnolia-card-padding);
}

.login-pf .pf-v5-c-login__main-header .pf-v5-c-title {
    color: var(--magnolia-dark);
    font-size: 1.5rem;
    font-weight: 500;
    line-height: 1.25;
}

.login-pf :is([data-page-id="login-login"], [data-page-id="login-login-username"]) .pf-v5-c-login__main-header {
    padding-block: 0;
}

.login-pf :is([data-page-id="login-login"], [data-page-id="login-login-username"]) #kc-page-title {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.login-pf .pf-v5-c-login__main > .pf-v5-c-login__main-body {
    padding-inline: var(--magnolia-card-padding);
    padding-block: var(--magnolia-gap) var(--magnolia-card-padding);
    color: var(--magnolia-dark);
}

.login-pf .pf-v5-c-login__main-body p:not(:last-child) {
    margin-bottom: var(--magnolia-gap);
}

/* ======================================================================
   Forms
   ====================================================================== */
.login-pf .pf-v5-c-form__group-label,
.login-pf .pf-v5-c-form__label {
    line-height: 20px;
}

.login-pf .pf-v5-c-form__label-text {
    font-size: 0.8125rem;
    font-weight: 500;
}

/* Inputs: PatternFly has no radius/border variables for them, so the box is repainted here */
.login-pf .pf-v5-c-form-control,
.login-pf .pf-v5-c-input-group {
    height: var(--magnolia-input-height);
    border: 1px solid var(--magnolia-input-border);
    border-radius: var(--magnolia-radius);
    background: #fff; /* also for the read-only username field, which PatternFly greys */
    box-shadow: none;
    overflow: hidden;
}

/* PatternFly draws its own borders/underline with pseudo-elements */
.login-pf .pf-v5-c-form-control::before,
.login-pf .pf-v5-c-form-control::after {
    display: none;
}

.login-pf .pf-v5-c-form-control input {
    height: 100%;
    padding-inline: 16px;
    outline: 0;
    color: var(--magnolia-dark); /* PatternFly's input colour does not follow --Color--100 */
    font-size: 1rem; /* below 16px iOS Safari zooms the page when a field is focused */
}

.login-pf .pf-v5-c-form-control:focus-within,
.login-pf .pf-v5-c-input-group:focus-within {
    border-color: var(--magnolia-dark);
    /* An inner outline paints above the children (e.g. the password toggle), unlike an inset box-shadow */
    outline: 1px solid var(--magnolia-dark);
    outline-offset: -1px;
}

.login-pf .pf-v5-c-form-control:has(input[aria-invalid="true"]),
.login-pf .pf-v5-c-input-group:has(input[aria-invalid="true"]) {
    border-color: var(--pf-v5-global--danger-color--100);
}

/* Password field: the show/hide button lives inside the same box */
.login-pf .pf-v5-c-input-group .pf-v5-c-form-control {
    height: 100%;
    border: 0;
    border-radius: 0;
    outline: 0;
}

.login-pf .pf-v5-c-input-group .pf-v5-c-button.pf-m-control {
    padding-inline: 8px 16px;
    background: transparent;
}

.login-pf .pf-v5-c-input-group .pf-v5-c-button.pf-m-control::after {
    display: none;
}

/* Show/hide password icon (replaces the Font Awesome glyph) */
.login-pf [data-password-toggle] i {
    display: inline-block;
    width: 24px;
    height: 24px;
    font-size: 0;
    vertical-align: middle;
    background-color: var(--magnolia-dark);
    mask: url("../img/eye.svg") center / contain no-repeat;
}

.login-pf [data-password-toggle] i.fa-eye-slash {
    mask-image: url("../img/eye-off.svg");
}

/* ======================================================================
   Buttons (colours come from the PatternFly variables set in :root)
   ====================================================================== */
.login-pf .pf-v5-c-button.pf-m-primary,
.login-pf .pf-v5-c-button.pf-m-secondary,
.login-pf .pf-v5-c-button.pf-m-tertiary {
    /* <a> buttons don't centre their label vertically like <button> does */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--magnolia-button-height);
    border-radius: var(--magnolia-radius);
    font-weight: 500;
}

.login-pf .pf-v5-c-button.pf-m-primary::after,
.login-pf .pf-v5-c-button.pf-m-secondary::after,
.login-pf .pf-v5-c-button.pf-m-tertiary::after {
    border-radius: inherit;
}

/* Outlined buttons (identity providers, "back"): set larger than the primary one, with tighter side padding */
.login-pf .pf-v5-c-button.pf-m-tertiary,
.login-pf .pf-v5-c-button.pf-m-secondary {
    padding-inline: 24px;
    font-size: 1rem;
}

.login-pf .pf-v5-c-button.pf-m-tertiary::after,
.login-pf .pf-v5-c-button.pf-m-secondary::after {
    border: 1px solid var(--magnolia-dark);
}

.login-pf .pf-v5-c-button.pf-m-tertiary:hover,
.login-pf .pf-v5-c-button.pf-m-tertiary:focus,
.login-pf .pf-v5-c-button.pf-m-secondary:hover,
.login-pf .pf-v5-c-button.pf-m-secondary:focus {
    background-color: rgba(2, 55, 63, 0.06);
}

/* ======================================================================
   Bottom band: identity providers (and the registration link, which is not used)
   ====================================================================== */
.login-pf .pf-v5-c-login__main-body > .pf-v5-c-login__main-footer:has(#kc-social-providers, #kc-info) {
    /* the same space above the band (white) as inside it, above the first button */
    margin: var(--magnolia-card-padding) calc(-1 * var(--magnolia-card-padding)) calc(-1 * var(--magnolia-card-padding));
    padding: var(--magnolia-card-padding);
    background: var(--magnolia-band);
}

.login-pf .kc-login-divider {
    display: none;
}

/* Identity providers (or organizations, on the organization picker): one button per row, however many there are */
.login-pf :is(#kc-social-providers, #kc-user-organizations) ul {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.login-pf :is(#kc-social-providers, #kc-user-organizations) .pf-v5-c-button {
    /* Long provider names wrap instead of stretching the button past the card (which clips it) */
    white-space: normal;
    overflow-wrap: anywhere;
}

/*
 * The label is always centred in the whole button, with or without an icon: the icon sits at the left edge, out of the
 * flow, and the label's side padding keeps a long, wrapping name clear of it.
 */
.login-pf #kc-social-providers .pf-v5-c-button img {
    position: absolute;
    inset-inline-start: 24px;
    top: 50%;
    translate: 0 -50%;
    width: 20px;
    height: 20px;
}

.login-pf #kc-social-providers .pf-v5-c-button:has(> img:not([src$="/social/default.svg"])) > span {
    padding-inline: 32px;
}

/* On a button too narrow for that (very small screens), the icon goes above the label, which takes the full width */
.login-pf #kc-social-providers li {
    container-type: inline-size;
}

@container (max-width: 15rem) {
    .login-pf #kc-social-providers .pf-v5-c-button {
        flex-direction: column;
        gap: 8px;
        padding-block: 12px;
    }

    .login-pf #kc-social-providers .pf-v5-c-button img {
        position: static;
        translate: none;
    }

    .login-pf #kc-social-providers .pf-v5-c-button:has(> img:not([src$="/social/default.svg"])) > span {
        width: 100%;
        padding-inline: 0;
    }
}

/* Keycloak's generic fallback icon says nothing about the provider: hide it */
.login-pf #kc-social-providers img[src$="/social/default.svg"] {
    display: none;
}

.login-pf .pf-v5-c-login__main-footer-band {
    margin: 0;
    padding: 0;
    border: 0;
    text-align: left;
}

/* PatternFly's grey text utility is !important */
.login-pf .pf-v5-c-login__main-footer-band .pf-v5-u-color-200 {
    color: var(--magnolia-dark) !important;
}

/* Alerts (warnings, errors, success messages) */
.login-pf .pf-v5-c-alert {
    border-radius: var(--magnolia-radius);
    overflow: hidden;
}

/* ======================================================================
   Accessibility: keyboard focus and disabled states
   ====================================================================== */

/* Visible keyboard focus for links, buttons and checkboxes (the browser default varies by browser and is amber in Chrome) */
.login-pf :is(a, button, .pf-v5-c-check__input):focus-visible {
    outline: 2px solid var(--magnolia-dark);
    outline-offset: 2px;
}

/* The show/hide password button sits inside the field, whose own focus ring already shows */
.login-pf .pf-v5-c-input-group .pf-v5-c-button.pf-m-control:focus-visible {
    outline: 0;
}

/* The footer sits on the dark page background */
#kc-page-footer a:focus-visible {
    outline-color: #fff;
}

/*
 * Disabled (the login form disables its button on submit; provider links get pf-m-aria-disabled after a click):
 * keep the brand colours, dimmed, instead of PatternFly's grey.
 */
.login-pf .pf-v5-c-button.pf-m-primary {
    --pf-v5-c-button--disabled--BackgroundColor: var(--magnolia-dark);
    --pf-v5-c-button--disabled--Color: #fff;
}

.login-pf .pf-v5-c-button.pf-m-secondary,
.login-pf .pf-v5-c-button.pf-m-tertiary {
    --pf-v5-c-button--disabled--BackgroundColor: transparent;
    --pf-v5-c-button--disabled--Color: var(--magnolia-dark);
}

.login-pf .pf-v5-c-button:disabled,
.login-pf .pf-v5-c-button.pf-m-aria-disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ======================================================================
   Small screens (phones): a little less padding, gap and logo height so the form gets more of the width.
   Inputs and buttons keep their height, which is the touch target.
   ====================================================================== */
@media (max-width: 480px) {
    :root {
        --magnolia-card-padding: 24px;
        --magnolia-gap: 20px;
        --magnolia-logo-height: 32px;
    }

    .login-pf .pf-v5-c-login {
        padding: 1rem 0.75rem 0;
    }

    .login-pf .pf-v5-c-form {
        --pf-v5-c-form--GridGap: 1.25rem;
    }
}
