/* KLAO login/register skin, "brand split" layout.
   Colours and type come from the user-app design system (apps/user-panel/tailwind.config.mjs
   and src/app/fonts.css): primary-500 #1165ef, primary-600 #0e58d1, primary-1100 #0e1e2f,
   klao-ink #181d27, gray-tertiary/secondary #535862/#717680, action-border #d5d7da,
   action-border-hover #a4a7ae, gray-border #e9eaeb, error-dark #d92d20.

   Prefer variable overrides on keycloak.v2 / PatternFly v5 over forking templates, so Keycloak
   upgrades keep working. The forks that do exist each explain themselves in their own header.

   Layout: at >=1024px the login container becomes two columns, a navy brand panel built out of
   #kc-header and the form in <main>. Below 1024px the panel is removed and the form runs full
   width. The panel copy is not in a template, it comes from the loginTitleHtml message override,
   which template.ftl renders through kcSanitize(...)?no_esc inside #kc-header-wrapper. That is
   why most rules below target bare tags (h2, p, a) by position. kcSanitize does keep class, id and
   href (measured on 26.3.5) and strips aria-label, which is why the one element that needs a hook,
   the logo link, can carry a class. */

/* Roboto, self-hosted. Deliberately not Google Fonts: this page is served to German users and a
   third-party font request from the login screen is a GDPR problem we do not need. Files and
   unicode-ranges copied verbatim from @fontsource/roboto 5.2.10, the same package user-app
   serves. */
@font-face {
  font-family: "Roboto";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/roboto-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Roboto";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/roboto-latin-ext-400-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Roboto";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/roboto-latin-500-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Roboto";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/roboto-latin-ext-500-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --klao-blue: #1165ef;
  --klao-blue-hover: #0e58d1;
  --klao-blue-ring: rgb(17 101 239 / 16%);
  --klao-blue-faint: #f0f6ff;
  --klao-navy: #0e1e2f;
  --klao-text: #181d27;
  --klao-text-muted: #535862;
  --klao-text-subtle: #717680;
  --klao-border: #d5d7da;
  --klao-border-light: #e9eaeb;
  --klao-border-hover: #a4a7ae;
  --klao-success: #47772f;
  --klao-error: #d92d20;
  --klao-radius: 8px;
  --klao-panel-pad-y: 52px;
  --klao-panel-pad-x: clamp(32px, 3.6vw, 56px);
  --klao-form-width: 384px;
  --klao-font: Roboto, "Helvetica Neue", Arial, sans-serif;

  --pf-v5-global--FontFamily--text: var(--klao-font);
  --pf-v5-global--FontFamily--heading: var(--klao-font);
  --pf-v5-global--primary-color--100: var(--klao-blue);
  --pf-v5-global--primary-color--200: var(--klao-blue-hover);
  --pf-v5-global--link--Color: var(--klao-blue);
  --pf-v5-global--link--Color--hover: var(--klao-blue-hover);
  --pf-v5-global--danger-color--100: var(--klao-error);
  --pf-v5-global--Color--100: var(--klao-text);
  --pf-v5-global--Color--200: var(--klao-text-muted);
  --pf-v5-c-button--BorderRadius: var(--klao-radius);

  --keycloak-card-top-color: transparent; /* drop keycloak.v2's blue card stripe */
}

/* ---------- page shell ---------------------------------------------------- */

/* keycloak.v2 paints a fixed background photo on the body. The split fills the viewport itself,
   so it has to go. */
.login-pf body {
  background: #fff;
  height: auto;
  min-height: 100vh;
  min-height: 100dvh; /* dvh: 100vh is the toolbar-hidden height on mobile */
}

.pf-v5-c-login {
  --pf-v5-c-login--PaddingTop: 0;
  --pf-v5-c-login--PaddingBottom: 0;
  --pf-v5-c-login--PaddingRight: 0;
  --pf-v5-c-login--PaddingLeft: 0;
  min-height: 100vh;
  min-height: 100dvh; /* dvh: 100vh is the toolbar-hidden height on mobile */
  padding: 0;
}

/* ---------- >=1024px: two columns ---------------------------------------- */

/* 1024 rather than 768: the panel is 46% of the viewport, so at 900px it is only ~414px wide and
   the statement wraps to three ragged lines. At 1024 it gets 471px, which holds two. */
@media (min-width: 1024px) {
  .pf-v5-c-login__container {
    /* PF only makes the container a grid from 1200px. Without this, 1024-1199 (iPad landscape,
       small laptops) stacked the panel as a ~100px band above the form, its copy overlapping. */
    display: grid;
    grid-template-columns: 46fr 54fr;
    grid-template-areas: "header main";
    gap: 0;
    width: 100%;
    max-width: none;
    min-height: 100vh;
    min-height: 100dvh; /* dvh: 100vh is the toolbar-hidden height on mobile */
    padding-inline: 0;
  }

  /* #kc-header carries the realm-name banner in stock keycloak.v2. Here it is the brand panel:
       wordmark as ::before, oversized mark as ::after, copy and legal links from the loginTitleHtml
       message inside #kc-header-wrapper. */
  #kc-header {
    grid-area: header;
    /* PF gives .pf-v5-c-login__header a block margin, which left a white strip above the panel. */
    margin: 0;
    align-self: stretch;
    position: relative;
    z-index: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: var(--klao-panel-pad-y) var(--klao-panel-pad-x);
    background: var(--klao-navy);
  }

  /* The wordmark links to klao.eu, so it has to be a real element rather than a pseudo-element.
       The only markup in this panel is the loginTitleHtml message, so the anchor comes from there
       and the image stays here. kcSanitize keeps class and href but strips aria-label (measured on
       26.3.5), so the anchor's accessible name is its own text, clipped out of sight below.

       Logo and legal row are both out of flow, leaving the statement and its subtitle as the only
       flow children of #kc-header-wrapper, which is what centres them on the panel's true middle.
       The wrapper is the positioned ancestor, and its box already starts at the panel's padding,
       so top/left 0 puts the logo exactly on the panel's top-left padding corner. */
  .klao-panel-logo {
    position: absolute;
    top: 0;
    left: 0;
    width: 99px; /* the asset is 297x72, so 24px tall makes it 99 wide */
    height: 24px;
    background: url("../img/logo-wordmark.png") left center / auto 24px no-repeat;
    /* one asset for both grounds: the dark wordmark reversed out to solid white */
    filter: brightness(0) invert(1);
    /* the link text is the accessible name, so it is pushed out of the box rather than removed */
    overflow: hidden;
    text-indent: 110%;
    white-space: nowrap;
    text-decoration: none;
    transition: opacity 0.12s ease-in-out;
  }

  .klao-panel-logo:hover {
    opacity: 0.78;
  }

  /* the text is clipped, so the ring is the only focus cue there is */
  .klao-panel-logo:focus-visible {
    outline: 2px solid rgb(255 255 255 / 70%);
    outline-offset: 5px;
    border-radius: 2px;
  }

  #kc-header::after {
    content: "";
    position: absolute;
    z-index: -1;
    /* Anchored by its top as a share of the panel height, not by a negative bottom: the design
           used bottom: -20% against a 1000px panel, and with the panel as tall as the viewport that
           made the mark ride higher on short windows.

           Size and placement are a deliberate step back from the design's 104% / 63.4%, which read as
           too heavy a wedge behind the copy. `left` is derived: the apex sits at 49.3% of the
           artwork's width, so left = apexTarget - 0.493 * width holds the apex at ~19% of the panel
           width as the mark shrinks. */
    left: -24%;
    top: 64%;
    width: 88%;
    aspect-ratio: 34.88 / 28.673;
    background: url("../img/panel-mark.svg") center / contain no-repeat;
    opacity: 0.55;
    pointer-events: none;
  }

  /* Absolutely filling the panel's padding box rather than flex: 1. As a flow child it stopped
       48px short of the bottom, which pushed the statement off centre. */
  #kc-header-wrapper {
    position: absolute;
    inset: var(--klao-panel-pad-y) var(--klao-panel-pad-x);
    /* it carries PF's .pf-v5-c-brand, which sets margin-bottom: 48px. Margins count toward an
           absolutely positioned box's insets, so that 48px ate the bottom of the panel. */
    margin: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 18px;
    /* undo keycloak.v2's realm-banner treatment */
    font-size: inherit;
    text-transform: none;
    letter-spacing: normal;
    text-align: start;
    white-space: normal;
  }

  #kc-header-wrapper h2 {
    margin: 0;
    max-width: 24ch;
    /* fluid so it degrades between 1024 and a wide desktop instead of leaning on the breakpoint
           alone. Resolves to 36px at 1440 */
    font-size: clamp(28px, 2.5vw, 36px);
    font-weight: 500;
    line-height: 1.22;
    letter-spacing: -0.02em;
    color: #fff;
  }

  #kc-header-wrapper p {
    margin: 0;
    max-width: 42ch;
    font-size: 16px;
    font-weight: 400;
    line-height: 28px;
    color: rgb(255 255 255 / 62%);
  }

  /* last paragraph of the message is the legal link row, pinned to the panel's bottom padding
       (#kc-header is the positioned ancestor) so it sits on the same edge as the wordmark's top */
  #kc-header-wrapper p:last-child {
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    margin: 0;
    /* the 42ch measure above is for the subtitle prose. On the link row it forced the German
           links onto two lines */
    max-width: none;
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    font-size: 13px;
    line-height: 20px;
  }

  #kc-header-wrapper p:last-child a {
    color: rgb(255 255 255 / 55%);
    text-decoration: none;
  }

  #kc-header-wrapper p:last-child a:hover,
  #kc-header-wrapper p:last-child a:focus-visible {
    color: rgb(255 255 255 / 85%);
    text-decoration: underline;
  }

  .pf-v5-c-login__main {
    grid-area: main;
    /* Vertical padding is a floor, not the spacing itself: while the column is taller than the
         form, justify-content: center supplies the rest.

         Viewport-relative rather than fixed because the register form is ~741px tall, so this padding
         decides where the page starts scrolling (below roughly 741 / 0.94 = 790px). A flat 64/72
         pushed that to ~880px and made ordinary laptop windows scroll. A flat 28/44 held it low but
         left almost no air on a short window. */
    padding-block: clamp(20px, 3vh, 56px);
    padding-inline: 40px;
  }
}

/* ---------- <1024px: no panel ------------------------------------------- */

@media (max-width: 1023.98px) {
  /* The panel is dropped rather than restacked as a band. At these widths the statement either
       crowds or fills the top third of the screen with something nobody came for. */
  #kc-header {
    display: none;
  }

  .pf-v5-c-login__container {
    grid-template-columns: min(100%, 34rem);
    grid-template-areas: "main";
    justify-content: center;
    padding-inline: 20px;
    min-height: 100vh;
    min-height: 100dvh; /* dvh: 100vh is the toolbar-hidden height on mobile */
  }

  .pf-v5-c-login__main {
    padding-block: clamp(20px, 3vh, 48px);
    padding-inline: 0;
  }
}

/* ---------- form column ------------------------------------------------- */

.pf-v5-c-login__main {
  position: relative; /* anchor for the language select */
  /* PF sets align-self: start here. Without stretch the column sizes to its content and the
       vertical centring below does nothing. */
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* "safe" so that a form taller than the viewport overflows downward, where it can be scrolled
       to, rather than equally off both ends. Browsers without support degrade to plain centring. */
  justify-content: safe center;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: #fff;
  box-sizing: border-box;
}

/* Everything in the column shares one measure, centred. PatternFly puts its own inline padding
   on these. The column owns the padding now. */
.pf-v5-c-login__main-header,
.pf-v5-c-login__main-body,
.pf-v5-c-login__main-footer,
.pf-v5-c-login__main-footer-band {
  width: 100%;
  max-width: var(--klao-form-width);
  margin-inline: auto;
  padding-inline: 0;
}

.pf-v5-c-login__main-header {
  display: flex;
  flex-direction: column;
  /* PF sets align-items: center. On a column flex that centres the title box itself, so
       text-align on the heading was never going to left-align it. */
  align-items: stretch;
  /* design rhythm: heading, 6px, subtitle, 26px, first field. The 6px lives here and the 26px on
       .klao-page-sub, which the forked templates emit at the top of the body. */
  padding-block: 0 6px;
  border-top: 0; /* keycloak.v2 draws a 4px card stripe here */
}

#kc-page-title {
  font-size: 28px;
  font-weight: 500;
  line-height: 36px;
  letter-spacing: -0.01em;
  color: var(--klao-text);
  text-align: start;
}

/* the dot from inside the A, reused as punctuation on every page heading */
#kc-page-title::after {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-left: 5px;
  border-radius: 50%;
  background: var(--klao-blue);
  vertical-align: baseline;
}

/* Subtitle under the page heading, from the forked templates. A sibling of the heading rather
   than a child, so the h1's accessible name stays just the title. */
.klao-page-sub {
  margin: 0 0 26px;
  font-size: 15px;
  font-weight: 400;
  line-height: 24px;
  color: var(--klao-text-muted);
}

/* ---------- language select --------------------------------------------- */

/* Not part of signing in, so it sits quietly at the top-right of the form column rather than in
   the heading grid, where PatternFly would squeeze the title to ~245px. */
.pf-v5-c-login__main-header-utilities {
  position: absolute;
  /* fixed to the column's corner, independent of the fluid padding above */
  top: 28px;
  inset-inline-end: 40px;
  display: flex;
  z-index: 1;
}

/* Design puts a globe before the language name. The select is a bare <select> with no room for
   an icon element, so it rides as a background image on the wrapper and the select gets left
   padding to clear it. Inlined to avoid a second asset for a 15px glyph. */
.pf-v5-c-login__main-header-utilities .pf-v5-c-form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%23535862' stroke-width='1.8' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M3 12h18'/%3E%3Cpath d='M12 3a15 15 0 0 1 0 18 15 15 0 0 1 0-18Z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
  --pf-v5-c-form-control--BackgroundColor: #fff;
  --pf-v5-c-form-control--Color: var(--klao-text-muted);
  --pf-v5-c-form-control--FontSize: 13px;
  --pf-v5-c-form-control--PaddingTop: 5px;
  --pf-v5-c-form-control--PaddingBottom: 5px;
  --pf-v5-c-form-control--Width: auto;
  border-radius: 999px;
}

/* The <select> carries its own white background, which painted over the globe on the wrapper.
   Transparent here, and its padding set directly, because PF's PaddingLeft variable applies to
   the wrapper rather than the control inside it. */
.pf-v5-c-login__main-header-utilities .pf-v5-c-form-control {
  /* A native select is as wide as its widest option, not its selected one, so it stretched to
       fit "German (Deutsch)". Where the browser supports it, field-sizing below makes the select
       size to its selected content instead, so the pill hugs whatever the label is and keeps
       working if a locale with a longer native name is added. 112px is the fallback: it fits the
       selected label in both current locales and clips the rest, which is invisible because the
       label is left-aligned. */
  width: 112px;
  overflow: hidden;
}

@supports (field-sizing: content) {
  .pf-v5-c-login__main-header-utilities .pf-v5-c-form-control {
    width: auto;
    overflow: visible;
  }

  .pf-v5-c-login__main-header-utilities .pf-v5-c-form-control > select {
    field-sizing: content;
  }
}

.pf-v5-c-login__main-header-utilities .pf-v5-c-form-control > select {
  width: 100%;
  background: transparent;
  /* left clears the globe drawn on the wrapper, right reserves room for PF's chevron, which is
       absolutely placed against the wrapper's right edge. 24px was 3px too little once field-sizing
       shrank the select to its text. */
  padding-left: 31px;
  padding-right: 34px;
}

/* PF reserves 1.75rem for its chevron, more room than the pill needs in this design */
.pf-v5-c-login__main-header-utilities .pf-v5-c-form-control__utilities {
  padding-inline-end: 6px;
}

.pf-v5-c-login__main-header-utilities .pf-v5-c-form-control::before {
  border-radius: inherit;
  border-color: var(--klao-border-light);
}

.pf-v5-c-login__main-header-utilities .pf-v5-c-form-control:hover {
  --pf-v5-c-form-control--Color: var(--klao-text);
}

.pf-v5-c-login__main-header-utilities .pf-v5-c-form-control:hover::before {
  border-color: var(--klao-border);
}

/* Below the breakpoint the column is narrow and an absolutely positioned pill at its top-right
   sits in the heading's band, where a long title ran under it ("Passwort zurücksetzen" overlapped
   by 39px at 390px wide). Sharing a wrapping row with the heading fixed the overlap but left the
   pill stranded between title and subtitle whenever it wrapped, which is what it does on a phone
   for most titles. So on small screens it gets its own row above the heading, right-aligned, via
   order: -1 in the header's column flex. It never overlaps and never lands mid-copy, whatever the
   title length or language. */
@media (max-width: 1023.98px) {
  .pf-v5-c-login__main-header {
    flex-direction: column;
    align-items: stretch;
  }

  .pf-v5-c-login__main-header-utilities {
    position: static;
    order: -1;
    align-self: flex-end;
    margin-bottom: 16px;
  }
}

/* ---------- labels and field rhythm -------------------------------------- */

/* Design: 14px/500 labels, 6px above the field, 20px between fields. PF's group-label carries
   the pf-v5-u-pb-xs utility (4px, !important), so this needs !important to win. */
.pf-v5-c-form {
  --pf-v5-c-form--GridGap: 20px;
}

.pf-v5-c-form__label {
  --pf-v5-c-form__label--FontSize: 14px;
  --pf-v5-c-form__label--Color: var(--klao-text);
}

/* PF puts the bold on the inner label-text span, not on the label */
.pf-v5-c-form__label-text {
  --pf-v5-c-form__label-text--FontWeight: 500;
  font-weight: 500;
}

.pf-v5-c-form__group-label {
  padding-bottom: 6px !important;
}

/* Every field on these forms is required, so the design marks none of them: no asterisks and no
   "* Required fields" line. Server-side validation is unaffected. */
.pf-v5-c-form__label-required,
.pf-v5-c-check__label-required,
.pf-v5-c-login__main-body .subtitle {
  display: none;
}

/* ---------- inputs ------------------------------------------------------ */

/* PF v5 ships a bottom-underline-only control. The design system uses a bordered box. */
.pf-v5-c-form-control {
  --pf-v5-c-form-control--before--BorderBottomWidth: var(--pf-v5-global--BorderWidth--sm);
  --pf-v5-c-form-control--before--BorderTopColor: var(--klao-border);
  --pf-v5-c-form-control--before--BorderRightColor: var(--klao-border);
  --pf-v5-c-form-control--before--BorderBottomColor: var(--klao-border);
  --pf-v5-c-form-control--before--BorderLeftColor: var(--klao-border);
  --pf-v5-c-form-control--after--BorderBottomWidth: 0;
  --pf-v5-c-form-control--focus--after--BorderBottomWidth: 0;
  --pf-v5-c-form-control--m-error--after--BorderBottomWidth: 0;
  --pf-v5-c-form-control--PaddingTop: 10px;
  --pf-v5-c-form-control--PaddingBottom: 10px;
  --pf-v5-c-form-control--PaddingLeft: 14px;
  --pf-v5-c-form-control--PaddingRight: 2.5rem;
  border-radius: var(--klao-radius);
}

.pf-v5-c-form-control::before {
  border-radius: inherit;
}

.pf-v5-c-form-control:hover:not(:focus-within)::before {
  border-color: var(--klao-border-hover);
}

.pf-v5-c-form-control:focus-within {
  --pf-v5-c-form-control--before--BorderTopColor: var(--klao-blue);
  --pf-v5-c-form-control--before--BorderRightColor: var(--klao-blue);
  --pf-v5-c-form-control--before--BorderBottomColor: var(--klao-blue);
  --pf-v5-c-form-control--before--BorderLeftColor: var(--klao-blue);
  box-shadow: 0 0 0 4px var(--klao-blue-ring);
}

.pf-v5-c-form-control.pf-m-error {
  --pf-v5-c-form-control--before--BorderTopColor: var(--klao-error);
  --pf-v5-c-form-control--before--BorderRightColor: var(--klao-error);
  --pf-v5-c-form-control--before--BorderBottomColor: var(--klao-error);
  --pf-v5-c-form-control--before--BorderLeftColor: var(--klao-error);
  /* PF reserves extra right padding for the status icon hidden below */
  --pf-v5-c-form-control--m-error--PaddingRight: var(--pf-v5-c-form-control--PaddingRight);
}

/* An error is the red border plus the message under the field. PF also drops a status icon
   inside the control at the same right edge as the password eye, so the two overlap. Keep the
   eye and drop the icon, which is aria-hidden decoration. */
.pf-v5-c-form-control.pf-m-error .pf-v5-c-form-control__utilities {
  display: none;
}

/* Keycloak's user-profile fields (register: email, first/last name) mark the input aria-invalid
   but never put pf-m-error on the wrapper, so a red message sat under a grey field. Kept as its
   own rule so an :has()-less browser still gets the pf-m-error one. */
.pf-v5-c-form-control:has(> [aria-invalid="true"]) {
  --pf-v5-c-form-control--before--BorderTopColor: var(--klao-error);
  --pf-v5-c-form-control--before--BorderRightColor: var(--klao-error);
  --pf-v5-c-form-control--before--BorderBottomColor: var(--klao-error);
  --pf-v5-c-form-control--before--BorderLeftColor: var(--klao-error);
}

/* Trailing button (password eye, username reset) sits inside the field */
.pf-v5-c-input-group {
  position: relative;
}

.pf-v5-c-input-group > .pf-v5-c-input-group__item:last-child {
  position: absolute;
  inset-block: 0;
  inset-inline-end: 4px;
  display: flex;
  align-items: center;
}

.pf-v5-c-input-group .pf-v5-c-button.pf-m-control {
  --pf-v5-c-button--m-control--BackgroundColor: transparent;
  --pf-v5-c-button--m-control--Color: var(--klao-text-muted);
  --pf-v5-c-button--m-control--hover--BackgroundColor: transparent;
  --pf-v5-c-button--m-control--focus--BackgroundColor: transparent;
  /* PF draws this button's border on ::after, and the bottom edge has its own set of variables.
       Zeroing --after--BorderWidth only covers the resting state: on hover PF put a 2px underline
       back, in its own #0066cc rather than the brand blue. All four states pinned. */
  --pf-v5-c-button--m-control--after--BorderWidth: 0;
  --pf-v5-c-button--m-control--after--BorderBottomWidth: 0;
  --pf-v5-c-button--m-control--hover--after--BorderBottomWidth: 0;
  --pf-v5-c-button--m-control--focus--after--BorderBottomWidth: 0;
  --pf-v5-c-button--m-control--active--after--BorderBottomWidth: 0;
}

/* no hover feedback at all once the underline is gone, so darken the icon instead */
.pf-v5-c-input-group .pf-v5-c-button.pf-m-control:hover {
  --pf-v5-c-button--m-control--Color: var(--klao-text);
}

/* ---------- buttons ----------------------------------------------------- */

/* 44px to match the inputs: 16px/24px text plus 10px block padding. Same as the design. */
.pf-v5-c-button.pf-m-primary,
.pf-v5-c-button.pf-m-secondary {
  --pf-v5-c-button--PaddingTop: 10px;
  --pf-v5-c-button--PaddingBottom: 10px;
  --pf-v5-c-button--LineHeight: 24px;
}

/* PF v5 buttons take their radius from --pf-v5-global--BorderRadius--sm (3px), not from the
   button-scoped variable, so it has to be set directly. 8px, matching the inputs and the
   user-app buttons. Overriding the global would also reshape alerts and other components. */
.pf-v5-c-button.pf-m-primary,
.pf-v5-c-button.pf-m-secondary,
#kc-social-providers .pf-v5-c-button {
  border-radius: var(--klao-radius);
}

/* PF paints the button's visible outline with an ::after pseudo-element carrying its own radius,
   so setting it on the element alone left the border square while the fill was rounded. */
.pf-v5-c-button.pf-m-primary::after,
.pf-v5-c-button.pf-m-secondary::after,
#kc-social-providers .pf-v5-c-button::after {
  border-radius: var(--klao-radius);
}

.pf-v5-c-button.pf-m-primary {
  --pf-v5-c-button--m-primary--BackgroundColor: var(--klao-blue);
  --pf-v5-c-button--m-primary--hover--BackgroundColor: var(--klao-blue-hover);
  --pf-v5-c-button--m-primary--focus--BackgroundColor: var(--klao-blue-hover);
  --pf-v5-c-button--m-primary--active--BackgroundColor: var(--klao-blue-hover);
  font-weight: 500;
}

/* Social / secondary buttons: neutral outline, not brand-blue */
.pf-v5-c-button.pf-m-secondary {
  --pf-v5-c-button--m-secondary--Color: var(--klao-text);
  --pf-v5-c-button--m-secondary--hover--Color: var(--klao-text);
  --pf-v5-c-button--m-secondary--focus--Color: var(--klao-text);
  --pf-v5-c-button--m-secondary--active--Color: var(--klao-text);
  /* design keeps the fill white in both states and moves only the border colour on hover. PF also
       thickens the border from 1px to 2px on hover/focus/active, which made the button visibly
       bulge, so it is pinned to 1px throughout. */
  --pf-v5-c-button--after--BorderWidth: 1px;
  --pf-v5-c-button--m-secondary--after--BorderWidth: 1px;
  --pf-v5-c-button--m-secondary--hover--after--BorderWidth: 1px;
  --pf-v5-c-button--m-secondary--focus--after--BorderWidth: 1px;
  --pf-v5-c-button--m-secondary--active--after--BorderWidth: 1px;
  --pf-v5-c-button--m-secondary--BackgroundColor: #fff;
  --pf-v5-c-button--m-secondary--hover--BackgroundColor: #fff;
  --pf-v5-c-button--m-secondary--focus--BackgroundColor: #fff;
  --pf-v5-c-button--m-secondary--active--BackgroundColor: #fff;
  --pf-v5-c-button--m-secondary--after--BorderColor: var(--klao-border);
  --pf-v5-c-button--m-secondary--hover--after--BorderColor: var(--klao-border-hover);
  --pf-v5-c-button--m-secondary--focus--after--BorderColor: var(--klao-border-hover);
  --pf-v5-c-button--m-secondary--active--after--BorderColor: var(--klao-border-hover);
  font-weight: 500;
}

/* Design sets links at 500, noticeably heavier than PF's 400, which read as plain text next to
   the labels. Applies to "Forgot password?", "Create an account" and the footer links. */
#kc-form-login a,
#kc-info a,
#kc-form-options a,
#kc-reset-password-form a,
.pf-v5-c-login__main-body a,
.pf-v5-c-check__label a {
  font-weight: 500;
}

/* ---------- checkboxes and footer bands --------------------------------- */

/* PF renders validation text in its own dark red (#a30000), so the page carried two reds: the
   field border and the alert on #d92d20, the message beneath on #a30000. Field errors stay inline
   text rather than borrowing the alert's panel, because the red border already contains them and
   on register five boxed messages would be unreadable, but the colour, size and weight match. */
.pf-v5-c-helper-text__item-text.pf-m-error,
.pf-v5-c-helper-text__item.pf-m-error,
.pf-v5-c-form__helper-text .pf-m-error {
  --pf-v5-c-helper-text__item-text--Color: var(--klao-error);
  color: var(--klao-error);
  font-size: 14px;
  font-weight: 400;
  line-height: 20px;
}

.pf-v5-c-check__label {
  --pf-v5-c-check__label--Color: var(--klao-text-muted);
  --pf-v5-c-check__label--FontSize: 14px;
}

.pf-v5-c-check__input {
  accent-color: var(--klao-blue);
}

/* No rule above the footer link. The design separates it by space alone. */
.pf-v5-c-login__main-footer-band {
  border-top: 0;
  padding-block: 20px 0;
  text-align: center;
  font-size: 14px;
  line-height: 20px;
  color: var(--klao-text-muted);
}

/* ---------- password requirement checklist ------------------------------ */

/* Rendered by the forked password-validation.ftl. Stock Keycloak shows only the unmet rules, as
   full sentences, and only on blur. All rules stay visible the whole time and pick up a tick as
   they are met, which is the pattern NN/G and most design systems converge on. Two columns
   because one measures ~98px tall and this form cannot spare it. */
.klao-pw-reqs {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 16px;
  row-gap: 6px;
  font-size: 13px;
  line-height: 20px;
}

.klao-pw-req {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--klao-text-subtle);
}

.klao-pw-req svg {
  flex-shrink: 0;
}

/* Unmet is a neutral circle, not a red cross: nothing has gone wrong while someone is still
   typing, and opening every field in an error state is hostile. */
.klao-pw-req[data-met="true"] {
  color: var(--klao-success);
}

.klao-pw-req .klao-pw-check {
  display: none;
}

.klao-pw-req[data-met="true"] .klao-pw-check {
  display: block;
}

.klao-pw-req[data-met="true"] .klao-pw-circle {
  display: none;
}

@media (max-width: 380px) {
  .klao-pw-reqs {
    grid-template-columns: 1fr;
  }
}

/* ---------- per-page rhythm deltas -------------------------------------- */

/* The design uses slightly different spacing per page. template.ftl stamps
   data-page-id="login-${pageId}" on <body>, which is the cleanest hook for it. Login is 6px
   heading gap / 26px to the first field and 20px between fields, register 6px / 24px / 18px (it
   has more fields), reset 8px / 26px / 20px. */
body[data-page-id="login-register"] .pf-v5-c-login__main-header {
  padding-block: 0 6px;
}

body[data-page-id="login-register"] .klao-page-sub {
  margin-bottom: 24px;
}

body[data-page-id="login-register"] .pf-v5-c-form {
  --pf-v5-c-form--GridGap: 18px;
}

body[data-page-id="login-login-reset-password"] .pf-v5-c-login__main-header {
  padding-block: 0 8px;
}

/* Register: first and last name share a row, 12px apart, as in the design. Below 480px two
   ~167px fields are too tight and they stack. Everything else spans both columns. */
@media (min-width: 480px) {
  #kc-register-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 12px;
  }

  #kc-register-form > * {
    grid-column: 1 / -1;
  }

  #kc-register-form > .pf-v5-c-form__group:has(#firstName),
  #kc-register-form > .pf-v5-c-form__group:has(#lastName) {
    grid-column: auto;
  }
}

/* The requirement checklist sits 10px under its field on register, not the 18px form gap */
#kc-register-form .klao-pw-reqs {
  margin-top: 10px;
}

/* ---------- page-level messages ----------------------------------------- */

/* Keycloak renders these with PatternFly's alert: a 2px top rule, square corners, a pale tint
   and 700-weight text in a dark hue, none of which belongs to this design language. Restyled as a
   soft panel: tinted fill, hairline border, the same 8px radius as the inputs and buttons, and
   400-weight ink text with the colour carried by the border and the icon.

   The icon is drawn into a slot that already exists but is always empty: template.ftl emits
   <span class="${properties.kcFeedbackSuccessIcon!}"></span> and keycloak.v2 never defines those
   properties, so the span renders with no content and zero width. Filling it from CSS needs no
   template change. */
.pf-v5-c-alert.pf-m-inline {
  display: grid;
  grid-template-columns: 16px 1fr;
  /* column-gap only. PF's grid-template-areas declares three rows (icon/title, description,
       actiongroup) and Keycloak fills only the first, so a row-gap would add 2 x 10px of dead
       height for rows that are 0px tall. */
  column-gap: 10px;
  row-gap: 0;
  align-items: start;
  padding: 12px 14px;
  border: 1px solid var(--klao-border-light);
  border-radius: var(--klao-radius);
  background: #fff;
}

.pf-v5-c-alert.pf-m-inline .pf-v5-c-alert__icon {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  padding: 0;
  font-size: 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 16px 16px;
}

.pf-v5-c-alert.pf-m-inline .pf-v5-c-alert__title {
  font-size: 14px;
  font-weight: 400;
  line-height: 20px;
  color: var(--klao-text);
}

.pf-v5-c-alert.pf-m-success {
  background: #f1f6ee;
  border-color: #cfe0c4;
}

.pf-v5-c-alert.pf-m-success .pf-v5-c-alert__icon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2347772f' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6.5 9.2 17.3 4 12.1'/%3E%3C/svg%3E");
}

.pf-v5-c-alert.pf-m-danger {
  background: #fef3f2;
  border-color: #f9d3d3;
}

.pf-v5-c-alert.pf-m-danger .pf-v5-c-alert__icon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23d92d20' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7.5v5.5'/%3E%3Cpath d='M12 16.4h.01'/%3E%3C/svg%3E");
}

/* Keycloak also emits warning and info. Same construction, different hue. Tokens from user-app:
   orange-600 / orange-100, primary-500 / primary-100 / bg-light-blue. */
.pf-v5-c-alert.pf-m-warning {
  background: #fdf7f4;
  border-color: #fae4d9;
}

.pf-v5-c-alert.pf-m-warning .pf-v5-c-alert__icon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23dc5d1e' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 4.5 22 19.5H2Z'/%3E%3Cpath d='M12 10v4'/%3E%3Cpath d='M12 17.4h.01'/%3E%3C/svg%3E");
}

.pf-v5-c-alert.pf-m-info {
  background: var(--klao-blue-faint);
  border-color: #cfe0fc;
}

.pf-v5-c-alert.pf-m-info .pf-v5-c-alert__icon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%231165ef' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 16.5v-5'/%3E%3Cpath d='M12 7.6h.01'/%3E%3C/svg%3E");
}

/* Position. template.ftl emits the alert before the nested form section, and the subtitle is the
   first thing that section emits, so the alert landed between the heading and its subtitle and
   split them apart. They are siblings inside main-body, so ordering them is enough. */
.pf-v5-c-login__main-body {
  display: flex;
  flex-direction: column;
}

.pf-v5-c-login__main-body > * {
  order: 3;
}

.pf-v5-c-login__main-body > .klao-page-sub {
  order: 1;
}

.pf-v5-c-login__main-body > .pf-v5-c-alert {
  order: 2;
  margin-block: 0 20px !important; /* pf-v5-u-mb-md is a utility class */
}

/* even spacing around the alert when a subtitle is above it. Without :has the subtitle keeps its
   normal 26px, which is a good fallback */
.pf-v5-c-login__main-body:has(> .pf-v5-c-alert) > .klao-page-sub {
  margin-bottom: 20px;
}

/* ---------- error / info / expired pages -------------------------------- */

/* error.ftl and info.ftl both render <p class="instruction"> plus an optional trailing link, and
   base Keycloak leaves them as unstyled body copy. Styling them here gives the whole family the
   same shape as every other page without forking either template. login-page-expired.ftl is
   forked and uses .klao-page-sub directly. */
#kc-error-message .instruction,
#kc-info-message .instruction {
  margin: 0 0 26px;
  font-size: 15px;
  font-weight: 400;
  line-height: 24px;
  color: var(--klao-text-muted);
}

#kc-error-message > p:last-child:not(.instruction),
#kc-info-message > p:last-child:not(.instruction) {
  margin: 0;
  text-align: center;
}

#kc-error-message a,
#kc-info-message a {
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
}

/* ---------- IdP review page (locked email) ------------------------------- */

/* The email on the first-broker-login review page belongs to the identity provider, so the forked
   idp-review-user-profile.ftl renders it readonly rather than disabled. A disabled input would not
   be submitted, and email is a required attribute. Painted inert here so it does not invite
   typing, and pinned across the interaction states, since PF keeps its focus and hover treatment
   on a readonly control. */
#kc-idp-review-profile-form .pf-v5-c-form-control:has(input[readonly]),
#kc-idp-review-profile-form .pf-v5-c-form-control:has(input[readonly]):hover,
#kc-idp-review-profile-form .pf-v5-c-form-control:has(input[readonly]):focus-within {
  background: var(--klao-border-light);
  border-color: var(--klao-border);
  box-shadow: none;
}

#kc-idp-review-profile-form input[readonly] {
  color: var(--klao-text-muted);
  cursor: default;
  background: transparent;
}


/* ---------- terms page (social signups land here) ------------------------ */

/* Keycloak's own terms.ftl, shown by the TERMS_AND_CONDITIONS required action. It is on the
   critical path for every Google signup, so it gets the same treatment as the rest: body copy as
   a subtitle, a full-width primary, and Decline as a quiet link rather than a second button
   competing with Accept. No fork, terms.ftl's markup is styled as-is. */
body[data-page-id="login-terms"] .pf-v5-c-login__main-header {
  padding-block: 0 8px;
}

body[data-page-id="login-terms"] .pf-v5-c-login__main-body > div:first-child {
  /* the wrapper carries pf-v5-u-mb-md-on-md, a PF utility class with !important */
  margin-bottom: 26px !important;
}

body[data-page-id="login-terms"] .pf-v5-c-login__main-body > div:first-child p {
  margin: 0;
  font-size: 15px;
  font-weight: 400;
  line-height: 24px;
  color: var(--klao-text-muted);
}

/* terms.ftl calls actionGroup with horizontal=true, which lays the two buttons side by side */
body[data-page-id="login-terms"] .pf-v5-c-form__actions {
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 20px;
  /* PF's -8px gutter margin made the button 400px against the form's 384px measure */
  margin: 0;
}

body[data-page-id="login-terms"] #kc-accept {
  width: 100%;
  margin: 0;
}

/* Decline reads as the quiet way out, matching "Back to sign in" on the reset page */
body[data-page-id="login-terms"] #kc-decline {
  margin: 0;
  align-self: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--klao-blue);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
}

body[data-page-id="login-terms"] #kc-decline::after {
  border: 0;
}

body[data-page-id="login-terms"] #kc-decline:hover {
  color: var(--klao-blue-hover);
  text-decoration: underline;
}

/* Reset: "Back to sign in" is a quiet centred link under the button, not a second block button.
   Rendered by the forked login-reset-password.ftl. */
.klao-back-row {
  display: flex;
  justify-content: center;
  /* no margin: it is a grid child of .pf-v5-c-form, so the form's own 20px gap already provides
       the design's spacing. A margin on top of that made it 40px. */
}

.klao-back-row a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
}

/* ---------- vertical rhythm on the login page ---------------------------- */

/* The design runs one 20px gap the whole way down the column: field, field, remember row,
   button, "or", provider button, footer link. PatternFly contributes several extra offsets on top
   of the form's own 20px grid gap, each zeroed here rather than fought with margins. */

/* pf-v5-u-pt-xs on the actions group added 4px on top of the grid gap. It is a PatternFly
   utility class, so it carries !important and has to be matched. */
.pf-v5-c-form__actions {
  padding-top: 0 !important;
}

/* Remember-me and "Forgot password?" ride in the password field's helper text (login.ftl passes
   the checkbox as nested content), which PF spaces 4px under the input. The design treats it as a
   normal row in the stack.

   Direct child only: field.ftl also renders a .pf-v5-c-form__helper-text inside
   #input-error-container-<name> for validation messages. Those must hug their field, not sit a
   full row away. */
#kc-form-login > .pf-v5-c-form__group > .pf-v5-c-form__helper-text {
  margin-top: 20px;
}

/* A field error belongs to the field above it */
[id^="input-error-container-"] .pf-v5-c-form__helper-text {
  margin-top: 6px;
}

/* Remember-me and the forgot link share a space-between row. On a narrow phone in German both
   halves wrapped to two lines side by side. Wrapping the row drops the link underneath instead. */
#kc-form-login > .pf-v5-c-form__group > .pf-v5-c-form__helper-text > .pf-v5-c-helper-text {
  flex-wrap: wrap;
  gap: 8px 16px;
}

#kc-form-login .pf-v5-c-helper-text__item-text,
#kc-form-login .pf-v5-c-check__label {
  font-size: 14px;
  line-height: 20px;
}

/* field.password always renders a helper-text row, even when there is nothing to put in it. On
   register nothing ever goes there, so the whole row is dropped. Matching on :empty does not
   work, because the inner div contains whitespace. The T&C group is excluded: its helper text is
   the "you must accept the terms" error (register-commons.ftl). */
#kc-register-form > .pf-v5-c-form__group:not(#kc-registration-terms) > .pf-v5-c-form__helper-text {
  display: none;
}

/* PF pads the provider list and its items to sit above a footer band that the design does not
   have. The spacing is carried by the divider and info bands instead. */
#kc-social-providers ul,
#kc-social-providers li {
  /* pf-v5-u-pb-sm / pb-0 on these are utility classes, so !important is required */
  padding-bottom: 0 !important;
}

/* the column owns its bottom padding */
.pf-v5-c-login__main-body {
  padding-bottom: 0;
}

/* ---------- social divider ---------------------------------------------- */

/* keycloak.v2 puts the "or sign in with" label in a footer band directly before
   #kc-social-providers and renders it as a plain line of text under a rule. Selecting it by that
   adjacency is exact, since #kc-info is the only other band and it is not followed by the
   provider list. Without :has() the band keeps its default top border, a readable fallback. */
.pf-v5-c-login__main-footer-band:has(+ #kc-social-providers) {
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 0;
  padding-block: 0;
  margin-block: 20px;
  text-align: initial;
}

.pf-v5-c-login__main-footer-band:has(+ #kc-social-providers)::before,
.pf-v5-c-login__main-footer-band:has(+ #kc-social-providers)::after {
  content: "";
  flex-grow: 1;
  height: 1px;
  background: var(--klao-border-light);
}

.pf-v5-c-login__main-footer-band:has(+ #kc-social-providers) > span {
  flex-shrink: 0;
  font-size: 13px;
  line-height: 20px;
  color: var(--klao-text-subtle);
}

/* the provider list carries .pf-v5-c-login__main-body, so it already picks up the shared measure
   above. This only removes the band spacing PF adds under it */
#kc-social-providers ul {
  margin-block: 0;
}

/* Provider button: icon and label together in the middle, 15px/500, as in the design. PF's
   space-between comes from a utility class, hence the !important here. */
#kc-social-providers .pf-v5-c-button {
  justify-content: center !important;
  gap: 10px;
  font-size: 15px;
}

#kc-social-providers .pf-v5-c-button svg,
#kc-social-providers .pf-v5-c-button .kc-social-provider-logo {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* kcFormSocialAccountNameClass is pf-v5-u-m-auto, margin: auto !important on the label. In a
   flex row that auto margin eats all the free space, which pinned the icon to the left edge and
   centred the text ~100px away from it. */
#kc-social-providers .pf-v5-c-button > .pf-v5-u-m-auto {
  margin: 0 !important;
}
