/*
 * OBI branding on top of keycloak.v2 (PatternFly 5). Applies to every login page.
 *
 * Dark mode: keycloak.v2 puts .pf-v5-theme-dark on <html> while the OS prefers dark
 * (see darkMode in theme.properties). PatternFly defines its dark values under
 * :where(.pf-v5-theme-dark), which has zero specificity, so the :root block below wins
 * in both modes and :root.pf-v5-theme-dark then overrides it for dark.
 *
 * Contrast (WCAG AA) is measured, not guessed: white on OBI orange is only 2.5:1, so text on
 * orange is dark, and orange text uses the darker --obi-link.
 */

/* ================== Brand tokens ================== */

:root {
    --obi-orange: #ff7e21;
    --obi-orange-hover: #e5660b;
    --obi-on-orange: #ffffff;     /* white as in the previous theme (2.5:1 on --obi-orange, below WCAG AA) */
    --obi-link: #c24e00;          /* OBI orange darkened to 4.8:1 on white */
    --obi-link-hover: #8f3900;
    --obi-brand-text: var(--obi-orange);   /* header text in OBI orange as in the previous theme */
    --obi-page-bg: #f4f4f4;
    --obi-muted-text: #6a6e73;
    --obi-title-color: #363636;   /* page title as in the previous theme */
    --obi-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236a6e73' stroke-width='1.5'/%3E%3C/svg%3E");
    --obi-card-shadow: 0 0.25rem 1.5rem rgba(3, 3, 3, 0.12);
    --obi-chip-bg: #fff;

    --pf-v5-global--primary-color--100: var(--obi-orange);
    --pf-v5-global--primary-color--200: var(--obi-orange-hover);
    --pf-v5-global--primary-color--300: var(--obi-orange);   /* primary buttons in dark mode */
    /* PatternFly switches to these inside form controls, menus and alerts */
    --pf-v5-global--primary-color--dark-100: var(--obi-link);
    --pf-v5-global--primary-color--light-100: #ff8f3f;
    --pf-v5-global--active-color--100: var(--obi-orange);
    --pf-v5-global--link--Color: var(--obi-link);
    --pf-v5-global--link--Color--hover: var(--obi-link-hover);
    --pf-v5-global--link--Color--dark: var(--obi-link);
    --pf-v5-global--link--Color--dark--hover: var(--obi-link-hover);
    --pf-v5-global--link--Color--light: #ff8f3f;
    --pf-v5-global--link--Color--light--hover: #ffb27a;

    /* Variables of keycloak.v2's styles.css */
    --keycloak-bg-logo-url: none;
    --keycloak-card-top-color: var(--obi-orange);

    accent-color: var(--obi-orange);
}

:root.pf-v5-theme-dark {
    --obi-orange-hover: #ff9443;
    --obi-link: #ff8f3f;          /* 6.6:1 on the dark card */
    --obi-link-hover: #ffb27a;
    --obi-brand-text: #ff9443;    /* softened: the pure orange glows on a dark ground */
    --obi-page-bg: #1b1d20;       /* dark grey instead of near-black, the card sits one step above it */
    --obi-card-bg: #26292d;
    --obi-muted-text: #aaabac;
    --obi-title-color: #e6e6e6;
    --obi-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23aaabac' stroke-width='1.5'/%3E%3C/svg%3E");
    --obi-card-shadow: 0 0.25rem 1.5rem rgba(0, 0, 0, 0.45);

    --pf-v5-global--primary-color--dark-100: var(--obi-link);
    --pf-v5-global--primary-color--light-100: var(--obi-link);
    --pf-v5-global--link--Color--light: var(--obi-link);
    --pf-v5-global--link--Color--light--hover: var(--obi-link-hover);

    --pf-v5-c-login__main--BackgroundColor: var(--obi-card-bg);
}

/* Without JavaScript the dark class is never set; keep the browser's own colors light too,
   otherwise <meta name="color-scheme" content="light dark"> gives white text on white. */
:root:not(.pf-v5-theme-dark) {
    color-scheme: light;
}

/* PatternFly declares the button colors on the component, so they are overridden there */
.pf-v5-c-button {
    --pf-v5-c-button--m-primary--Color: var(--obi-on-orange);
    --pf-v5-c-button--m-primary--hover--Color: var(--obi-on-orange);
    --pf-v5-c-button--m-primary--focus--Color: var(--obi-on-orange);
    --pf-v5-c-button--m-primary--active--Color: var(--obi-on-orange);
    --pf-v5-c-button--m-secondary--Color: var(--obi-link);
    --pf-v5-c-button--m-secondary--after--BorderColor: var(--obi-link);
    --pf-v5-c-button--m-secondary--hover--Color: var(--obi-link-hover);
    --pf-v5-c-button--m-secondary--hover--after--BorderColor: var(--obi-link-hover);
    --pf-v5-c-button--m-secondary--focus--Color: var(--obi-link-hover);
    --pf-v5-c-button--m-secondary--focus--after--BorderColor: var(--obi-link-hover);
    --pf-v5-c-button--m-secondary--active--Color: var(--obi-link-hover);
    --pf-v5-c-button--m-secondary--active--after--BorderColor: var(--obi-link-hover);
}

/* ================== Page, header and card ================== */

.login-pf body {
    background: var(--obi-page-bg);
}

/* OBI logo above the realm name */
#kc-header::before {
    content: "";
    display: block;
    height: 3.25rem;
    margin-bottom: var(--pf-v5-global--spacer--md);
    background: url("../img/obi-logo.svg") center / contain no-repeat;
}

#kc-header-wrapper {
    color: var(--obi-brand-text) !important;   /* keycloak.v2 forces white with !important */
    font-size: 1.5rem;
    font-weight: 600;
    unicode-bidi: plaintext;   /* keeps "(...)" in realm names intact in right-to-left languages */
}

/* Markup inside the realm's "HTML display name" reads as a subtitle, e.g. the staff realm's
   "(Login with OBI Google Workspace credentials / Windows credentials)" */
#kc-header-wrapper :is(div, p, span, small) {
    margin-top: var(--pf-v5-global--spacer--xs);
    color: var(--obi-muted-text);   /* not Color--200: the login header assumes a dark photo */
    font-size: var(--pf-v5-global--FontSize--sm);
    font-weight: normal;
    letter-spacing: normal;
    line-height: 1.4;
}

.pf-v5-c-login__main {
    box-shadow: var(--obi-card-shadow);
}

/* German titles such as "Mehrfachauthentifizierung konfigurieren" must not break mid-word */
#kc-page-title {
    word-break: normal;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Language selector on its own compact row, top right: next to the title (keycloak.v2's
   70%/30% split) it squeezes most titles onto two or three lines */
div.pf-v5-c-login__main-header:has(.pf-v5-c-login__main-header-utilities) {
    grid-template-columns: minmax(0, 1fr);
}

.pf-v5-c-login__main-header-utilities {
    grid-area: auto;   /* PatternFly places it in column 2 from 768px on */
    order: -1;
    justify-self: end;
}

/* PatternFly leaves the focus ring to the browser (blue); use the accessible brand orange */
:is(a, button, input, select, textarea):focus-visible {
    outline: 2px solid var(--obi-link);
    outline-offset: 1px;
}

/* Links inside text: color alone does not tell them apart in dark mode (WCAG 1.4.1) */
.pf-v5-c-login__main a:not(.pf-v5-c-button) {
    text-decoration: underline;
}

/* keycloak.v2 only hides the "restart login" tooltip, so it still widens phone screens */
.kc-login-tooltip .kc-tooltip-text {
    display: none;
}

.kc-login-tooltip:is(:hover, :focus-within) .kc-tooltip-text {
    display: block;
}

#kc-logout-confirm .instruction {
    margin-bottom: var(--pf-v5-global--spacer--md);
}

/* ================== Identity providers first ================== */

.obi-choices {
    display: grid;
    grid-template-columns: minmax(0, 1fr);   /* don't let long labels widen the card */
    gap: var(--pf-v5-global--spacer--md);
    margin: 0;
    padding: 0;
    list-style: none;
}

/* two classes to outrank PatternFly's .pf-v5-c-button.pf-m-block { display: block } */
.pf-v5-c-button.obi-choice {
    display: flex;
    align-items: center;
    gap: var(--pf-v5-global--spacer--md);
    min-height: 3.25rem;
    font-size: var(--pf-v5-global--FontSize--lg);
    font-weight: var(--pf-v5-global--FontWeight--bold);
    text-align: center;
}

.obi-choice__label {
    flex: 1;
    min-width: 0;
    white-space: normal;
    unicode-bidi: plaintext;
    /* keep the text centred on the button, not on the space next to the icon */
    margin-inline-end: calc(2rem + var(--pf-v5-global--spacer--md));
}

.obi-choice__icon {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--obi-chip-bg);
    color: var(--obi-link);
    font-size: 1rem;
}

.obi-choice__icon svg {
    width: 1.125rem;
    height: 1.125rem;
}

.obi-divider {
    display: flex;
    align-items: center;
    gap: var(--pf-v5-global--spacer--md);
    margin: var(--pf-v5-global--spacer--lg) 0 var(--pf-v5-global--spacer--md);
    color: var(--obi-muted-text);
    font-size: var(--pf-v5-global--FontSize--sm);
}

.obi-divider::before,
.obi-divider::after {
    content: "";
    flex: 1;
    border-top: 1px solid var(--pf-v5-global--BorderColor--100);
}

/* Deliberately quiet: identity providers are the preferred way to sign in */
.pf-v5-c-button.obi-password-choice {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--pf-v5-global--spacer--sm);
    margin-inline: auto;
    min-height: 2.75rem;   /* still a comfortable touch target */
    font-size: var(--pf-v5-global--FontSize--sm);
}

:root.pf-v5-theme-dark .obi-password-choice {
    --pf-v5-c-button--m-tertiary--after--BorderColor: #8a8d90;   /* PatternFly's is 1.5:1 on the card */
}

.obi-password-choice i {
    color: var(--obi-muted-text);
}

.obi-password-hint {
    margin-top: var(--pf-v5-global--spacer--sm);
    color: var(--obi-muted-text);
    font-size: var(--pf-v5-global--FontSize--sm);
    text-align: center;
}

.obi-back {
    margin-top: var(--pf-v5-global--spacer--sm);
}

.obi-back i {
    margin-inline-end: var(--pf-v5-global--spacer--sm);
}

[dir="rtl"] .obi-back i {
    transform: scaleX(-1);
}

/* ================== View switching (obi-login.js) ================== */

/* Without JavaScript both views stay visible, so the password form is always reachable. */
html:not(.obi-js) #obi-password-button,
html:not(.obi-js) #obi-back-button {
    display: none;
}

html:not(.obi-js) .obi-view--select {
    margin-bottom: var(--pf-v5-global--spacer--lg);
}

html.obi-js #obi-login[data-view="select"] .obi-view--form,
html.obi-js #obi-login[data-view="form"] .obi-view--select {
    display: none;
}

/* Set before the first paint when the user returns to the form, until data-view takes over */
html.obi-js.obi-form-first #obi-login .obi-view--select {
    display: none;
}

html.obi-js.obi-form-first #obi-login .obi-view--form {
    display: block;
}

@keyframes obi-enter-forward {
    from { opacity: 0; transform: translateX(1.5rem); }
}

@keyframes obi-enter-back {
    from { opacity: 0; transform: translateX(-1.5rem); }
}

.obi-enter-forward {
    animation: obi-enter-forward 0.25s ease-out;
}

.obi-enter-back {
    animation: obi-enter-back 0.25s ease-out;
}

[dir="rtl"] .obi-enter-forward {
    animation-name: obi-enter-back;
}

[dir="rtl"] .obi-enter-back {
    animation-name: obi-enter-forward;
}

@media (prefers-reduced-motion: reduce) {
    .obi-enter-forward,
    .obi-enter-back {
        animation: none;
    }
}

/* ================== Small screens ================== */

/* Page title as in the previous theme: centred, lighter and a bit smaller than PatternFly's 3xl */
#kc-page-title {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 300;
    color: var(--obi-title-color);
    margin-block: 0.625rem;
}

/* Header as in the previous theme: logo at the top of the page with air below, realm name and
   subtitle both in OBI orange with the same letter-spacing, the card further down. The header may
   be wider than the 34rem card column so the subtitle does not wrap into four lines. */
.pf-v5-c-login {
    align-items: flex-start;
}

.pf-v5-c-login__header {
    width: min(92vw, 64rem);
    justify-self: center;
    margin-top: 1.5rem;
}

#kc-header::before {
    height: 4.5rem;
    margin-bottom: 3rem;
}

#kc-header-wrapper {
    margin-bottom: 6rem;
}

#kc-header-wrapper :is(div, p, span, small) {
    margin-top: 0;
    color: inherit;
    font-size: inherit;
    font-weight: inherit;
    letter-spacing: inherit;
}

/* Phones and small tablets, like the previous theme: white page without a visible card frame,
   small logo at the top, the language selector as plain text at the top right, realm name and
   subtitle in the same size without letter-spacing. */
@media (max-width: 767px) {
    :root {
        --obi-page-bg: #fff;
        --obi-card-shadow: none;
    }

    .pf-v5-c-login {
        position: relative;
    }

    .pf-v5-c-login__container {
        padding-inline: 0.5rem;
        grid-template-columns: minmax(0, 34rem);
    }

    .pf-v5-c-login__main-header {
        border-top: 0;
    }

    /* The card blends into the page in dark mode too (in light mode both are white) */
    .pf-v5-c-login__main {
        --pf-v5-c-login__main--BackgroundColor: var(--obi-page-bg);
        box-shadow: none;
    }

    .pf-v5-c-login__header {
        margin-top: 1.5rem;
    }

    #kc-header::before {
        height: 2.5rem;
        margin-bottom: 1.25rem;
    }

    #kc-header-wrapper {
        margin-bottom: 1.5rem;
        font-size: 1.25rem;
        letter-spacing: normal;
    }

    #kc-header-wrapper :is(div, p, span, small) {
        font-size: inherit;
        letter-spacing: normal;
    }

    /* Language selector: small text with a chevron at the top right, next to the logo, instead
       of the select box in the card. Still the native <select>; PatternFly's box, border and
       caret are removed and the chevron is drawn as the select's background. */
    .pf-v5-c-login__main-header-utilities {
        position: absolute;
        top: 0.75rem;
        right: 0.75rem;
    }

    .pf-v5-c-login__main-header-utilities .pf-v5-c-form-control {
        width: auto;
        min-width: 0;
        background-color: transparent;
        border: 0;
    }

    .pf-v5-c-login__main-header-utilities .pf-v5-c-form-control::before,
    .pf-v5-c-login__main-header-utilities .pf-v5-c-form-control::after {
        border: 0;
    }

    .pf-v5-c-login__main-header-utilities .pf-v5-c-form-control__utilities {
        display: none;
    }

    /* The select keeps its natural width (the longest option), so the opened list is wide enough;
       the box is transparent and the text right-aligned, so only "English ⌄" is visible. */
    #login-select-toggle {
        width: auto;
        min-height: 2rem;
        padding: 0.25rem 1rem 0.25rem 0.5rem;
        cursor: pointer;
        font-size: var(--pf-v5-global--FontSize--sm);
        color: var(--obi-muted-text);
        text-align: right;
        text-align-last: right;
        background: transparent var(--obi-chevron) no-repeat right center / 0.625rem auto;
    }

    /* The list entries must not inherit the right alignment of the closed field */
    #login-select-toggle option {
        text-align: left;
        text-align-last: left;
    }

    #kc-page-title {
        margin-block: 1rem 1.25rem;
        font-size: 1.25rem;
    }

    /* Less distance between the header text and the title, and wider content like the old card */
    .pf-v5-c-login__main-header {
        padding: 1.5rem 1rem 0.75rem;
    }

    .pf-v5-c-login__main-body {
        padding-inline: 1rem;
    }
}

@media (max-width: 575px) {
    #kc-header::before {
        height: 2.5rem;
    }

    #kc-header-wrapper {
        font-size: 1.25rem;
    }

    /* room for the label beats perfect centring on narrow screens */
    .obi-choice__label {
        margin-inline-end: 0;
    }

    /* 16px inputs stop iOS Safari from zooming into the form on focus */
    .pf-v5-c-form-control > input {
        font-size: 16px;
    }
}

/* Narrow phones: keep the identity provider label on one line */
@media (max-width: 360px) {
    #obi-login .obi-choice {
        gap: 0.75rem;
        font-size: 1rem;
    }
}

/* Sign-in code page (login-email.ftl): hint between the username block and the code field */
.obi-code-hint {
    margin: 0 0 var(--pf-v5-global--spacer--md);
    color: var(--obi-muted-text);
    font-size: var(--pf-v5-global--FontSize--sm);
    line-height: 1.5;
}
