/*
 * perly's sign-in pages: Keycloak's login theme, drawn from the Paper file ("Perly website",
 * page Application, group "Sign in · Keycloak"). Every number here is a computed value from a
 * frame there — `apps/auth/README.md`, "The login theme", says how they were read.
 *
 * THE MARKUP IS OURS. Every page this theme renders is a template in `../../` that draws its
 * own elements with the `pl-` classes below; nothing restyles PatternFly. A Keycloak page we
 * have not drawn (two-step, passkeys — off in the realm) still renders inside the same shell,
 * and the `.pl-generic` rules at the bottom keep its raw content readable.
 *
 * EVERY COLOUR IS NAMED ONCE, in the `:root` block, as the landing page does
 * (`apps/landing/src/styles/palette.css`, the same Paper palette). A rule reaches a colour only
 * through its variable; `theme.test.ts` fails on a hex anywhere else in this file.
 */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/inter-latin-ext-wght-normal.woff2') format('woff2-variations');
  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: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/inter-latin-wght-normal.woff2') format('woff2-variations');
  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;
}

:root {
  --font-sans: 'Inter', system-ui, sans-serif;

  /* — the palette, as the frames use it; names follow the landing page's where it has one — */
  --white: #ffffff;
  --brand-ink: #0f172a; /* the mark */
  --perly: #7dd3fc; /* the mark's blue bar */
  --ink: #1c1d1f; /* headings, input text, the dark button */
  --ink-app: #242629; /* labels, the outline buttons' text */
  --text-secondary: #505967; /* the lead under a heading */
  --text-tertiary: #687288; /* hints, "or", the footer, the eye icon */
  --border-window: #e6e8eb; /* inputs, outline buttons, the "or" hairlines */
  --surface-subtle: #f4f5f7; /* the picture plate, the "Sent" row */
  --surface-error: #fdf0f0; /* the plate behind a sign-up mistake */
  --destructive: #c4262e; /* a field's error; the destructive token in tokens.css */
  --sent: #007d53; /* "Sent" */
  --ring-ink: #1c1d1f14; /* a focused field's 3px ring */
  --ring-destructive: #c4262e1f; /* an errored field's 3px ring */

  --ease-plate: cubic-bezier(0.22, 1, 0.36, 1); /* the onboarding plate's, Note · Sign in · motion */
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* `hidden` always wins: perly.js hides rows and lines that a class would otherwise lay out. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  background: var(--white);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ———————————————————————————— the split: the step column and the picture plate ——— */

.pl-page {
  display: flex;
  min-height: 100dvh;
  padding: 16px;
}

.pl-step {
  display: flex;
  flex: 0 0 688px;
  flex-direction: column;
  min-width: 0;
  justify-content: space-between;
  gap: 48px;
  min-height: calc(100dvh - 32px);
  padding: 24px 104px 32px;
}

.pl-plate {
  position: sticky;
  top: 16px;
  flex: 1 1 auto;
  height: calc(100dvh - 32px);
  overflow: clip;
  border-radius: 16px;
  background: var(--surface-subtle);
}

/*
 * The picture is drawn on a 720×868 stage, the plate's size in the frames at 1440×900, and
 * scaled to fit whatever plate the window gives it (`perly.js` sets `--pic-scale`), so the
 * scene keeps its composition. The grid is drawn far past the stage so it fills any plate.
 */
.pl-stage {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 720px;
  height: 868px;
  transform: translate(-50%, -50%) scale(var(--pic-scale, 1));
}
.pl-grid {
  position: absolute;
  top: -1736px;
  left: -1440px;
  width: 3600px;
  height: 4340px;
  pointer-events: none;
}
.pic,
.pic-state,
.pl-pic-variant {
  position: absolute;
  inset: 0;
}

/*
 * A picture that tints its plate on a mistake (sign up) marks itself `data-plate-tint`: the
 * whole plate turns pale red, edge to edge, rather than a block on the stage that a larger
 * plate shows the grey around.
 */
.pl-plate {
  transition: background-color 300ms var(--ease-plate);
}
.pl-page[data-state='error'] .pl-plate:has([data-plate-tint]) {
  background: var(--surface-error);
}

/*
 * A page that arrives with a mistake first paints the picture as it was — the door open, the
 * plate grey — and `perly.js` plays it going wrong (Note · Sign in · motion). Without script,
 * or with reduced motion, it is simply drawn in its error state.
 */
@media (prefers-reduced-motion: no-preference) {
  .pl-js .pl-page[data-arrive] .pic-state--error {
    opacity: 0;
  }
  .pl-js .pl-page[data-arrive] .pic-state--ok {
    opacity: 1;
  }
  .pl-js .pl-page[data-arrive] .pl-plate {
    background: var(--surface-subtle);
  }
}

/*
 * The sign-in door's open leaf is its own layer: solid while `perly.js` swings it, so the swing
 * is seen, and gone once the shut door (drawn in the error state) has taken its place.
 */
.pl-page[data-state='error'] .pic-door-leaf {
  opacity: 0;
}
.pl-js .pl-page[data-arrive] .pic-door-leaf,
.pic-door-leaf.is-swinging {
  opacity: 1;
}

/* One of a picture's two states shows: `ok` until a field is wrong, `error` while it is. */
.pl-page[data-state='ok'] .pic-state--error,
.pl-page[data-state='error'] .pic-state--ok {
  opacity: 0;
}
.pic-state {
  transition: opacity 300ms var(--ease-plate);
}

/* ———————————————————————————— the step column ——— */

.pl-top {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  height: 36px;
}
.pl-logo {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--ink);
  text-decoration: none;
}
.pl-logo svg {
  flex-shrink: 0;
}
.pl-logo .pl-mark-ink {
  stroke: var(--brand-ink);
}
.pl-logo .pl-mark-ink-fill {
  fill: var(--brand-ink);
}
.pl-logo .pl-mark-blue {
  fill: var(--perly);
}
.pl-wordmark {
  font-size: 26px;
  font-weight: 600;
  line-height: 28px;
  letter-spacing: -0.04em;
}
.pl-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  line-height: 20px;
}
.pl-switch--session {
  gap: 12px;
}
.pl-switch__note {
  color: var(--text-tertiary);
}
.pl-switch__link {
  color: var(--ink);
  font-weight: 500;
  text-decoration: none;
}
.pl-switch__link:hover {
  text-decoration: underline;
}

.pl-question {
  display: flex;
  flex-direction: column;
  gap: 32px;
  width: 100%;
  max-width: 480px;
}
.pl-heading {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.pl-title {
  margin: 0;
  color: var(--ink);
  font-size: 44px;
  font-weight: 600;
  line-height: 48px;
  letter-spacing: -0.03em;
}
.pl-lead {
  margin: 0;
  color: var(--text-secondary);
  font-size: 18px;
  line-height: 27px;
}
.pl-lead strong {
  color: var(--ink);
  font-weight: 500;
}

.pl-form,
.pl-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin: 0;
}
.pl-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.pl-row {
  display: flex;
  gap: 12px;
}
.pl-row > .pl-field {
  flex: 1 1 0;
  min-width: 0;
}
.pl-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.pl-actions--loose {
  gap: 20px;
}
.pl-buttons {
  display: flex;
  gap: 10px;
}

.pl-footer {
  display: flex;
  gap: 20px;
}
.pl-footer a {
  color: var(--text-tertiary);
  font-size: 13px;
  line-height: 18px;
  text-decoration: none;
}
.pl-footer a:hover {
  text-decoration: underline;
}

/* ———————————————————————————— providers and the "or" ——— */

.pl-providers {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pl-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-tertiary);
  font-size: 13px;
  line-height: 18px;
}
.pl-divider::before,
.pl-divider::after {
  flex-grow: 1;
  height: 1px;
  background: var(--border-window);
  content: '';
}

/* ———————————————————————————— fields ——— */

.pl-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pl-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.pl-label {
  color: var(--ink-app);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
}
.pl-label-link {
  color: var(--text-tertiary);
  font-size: 14px;
  line-height: 20px;
  text-decoration: none;
}
.pl-label-link:hover {
  color: var(--ink);
}

.pl-input {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding-inline: 14px;
  border: 1px solid var(--border-window);
  border-radius: 10px;
  background: var(--white);
}
.pl-input:focus-within {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--ring-ink);
}
.pl-input input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  line-height: 22px;
}
.pl-input input[type='password'] {
  letter-spacing: 0.12em;
}
.pl-input input::placeholder {
  color: var(--text-tertiary);
  letter-spacing: normal;
}
.pl-eye {
  display: flex;
  flex-shrink: 0;
  margin: 0 -4px 0 8px;
  padding: 4px;
  border: 0;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
}
.pl-eye svg {
  display: block;
}
.pl-eye .pl-eye__shut,
.pl-eye[aria-pressed='true'] .pl-eye__open {
  display: none;
}
.pl-eye[aria-pressed='true'] .pl-eye__shut {
  display: block;
}

.pl-hint {
  color: var(--text-tertiary);
  font-size: 13px;
  line-height: 18px;
}
.pl-error {
  display: flex;
  align-items: start;
  gap: 6px;
  color: var(--destructive);
  font-size: 13px;
  line-height: 18px;
  transition: opacity 300ms var(--ease-plate);
}
.pl-error svg {
  flex-shrink: 0;
  margin-top: 2px;
}
.pl-error a {
  color: inherit;
  font-weight: 500;
}
.pl-field--error .pl-input {
  border-color: var(--destructive);
  box-shadow: 0 0 0 3px var(--ring-destructive);
}
/* Typing clears the mistake: the field, its line and the picture change together. */
.pl-field--cleared .pl-input {
  border-color: var(--border-window);
  box-shadow: none;
  transition:
    border-color 300ms var(--ease-plate),
    box-shadow 300ms var(--ease-plate);
}
.pl-field--cleared .pl-input:focus-within {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--ring-ink);
}
.pl-field--cleared .pl-error {
  opacity: 0;
}

.pl-check {
  display: flex;
  align-items: start;
  gap: 10px;
  cursor: pointer;
}
.pl-check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.pl-check__box {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border: 1px solid var(--border-window);
  border-radius: 5px;
  background: var(--white);
  color: var(--white);
  font-size: 12px;
  font-weight: 600;
  line-height: 18px;
}
.pl-check input:checked + .pl-check__box {
  border-color: var(--ink);
  background: var(--ink);
}
.pl-check input:not(:checked) + .pl-check__box > span {
  visibility: hidden;
}
.pl-check input:focus-visible + .pl-check__box {
  box-shadow: 0 0 0 3px var(--ring-ink);
}
.pl-check__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* The address a mail went to, and that it went. */
.pl-sent {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding-inline: 14px;
  border-radius: 10px;
  background: var(--surface-subtle);
}
.pl-sent__address {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 22px;
}
.pl-sent__address svg {
  flex-shrink: 0;
  color: var(--text-secondary);
}
.pl-sent__address span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pl-sent__state {
  color: var(--sent);
  font-size: 13px;
  font-weight: 500;
  line-height: 18px;
}

/* ———————————————————————————— buttons ——— */

.pl-button {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 44px;
  margin: 0;
  padding-inline: 20px;
  border: 1px solid var(--ink);
  border-radius: 10px;
  background: var(--ink);
  color: var(--white);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  line-height: 20px;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 100ms ease-out;
}
.pl-button:hover {
  opacity: 0.88;
}
.pl-button:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px var(--ring-ink);
}
.pl-button--block {
  width: 100%;
}
.pl-button--start {
  align-self: start;
}
.pl-button--outline {
  border-color: var(--border-window);
  background: var(--white);
  color: var(--ink-app);
}
.pl-button--outline:hover {
  opacity: 1;
  border-color: var(--text-tertiary);
}
.pl-button[disabled] {
  opacity: 0.6;
  cursor: default;
}
.pl-button svg {
  flex-shrink: 0;
}

.pl-back {
  display: inline-flex;
  align-self: start;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  text-decoration: none;
}
.pl-back:hover {
  text-decoration: underline;
}

.pl-note {
  margin: 0;
  color: var(--text-tertiary);
  font-size: 13px;
  line-height: 18px;
}
.pl-note a {
  color: inherit;
  text-decoration: none;
}
.pl-note a:hover {
  text-decoration: underline;
}

/*
 * <TEMP UI - MUST BE REVIEWED> Sign up's bot check: Google's floating badge is hidden, and its
 * notice is a note under the button instead, as Google's terms allow (register.ftl).
 */
.grecaptcha-badge {
  visibility: hidden;
}
.pl-note--google {
  margin-top: 12px;
}

/* A message Keycloak sends that no field owns: shown above the form, as the error line is. */
.pl-alert {
  margin: 0;
}

/* The invite and the reset share one template; only one of each pair shows. */
html:not([data-invite]) .pl-when-invite,
html[data-invite] .pl-when-reset {
  display: none;
}

.pl-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ———————————————————————————— motion ——— */

/* On first load of sign in, the marshaller waves the raised wand toward the door twice. */
@keyframes pl-wave {
  0%,
  100% {
    transform: rotate(0deg);
  }
  25%,
  75% {
    transform: rotate(-9deg);
  }
  50% {
    transform: rotate(4deg);
  }
}
.pl-page[data-wave] [data-pic-wave] {
  transform-box: fill-box;
  transform-origin: 0% 100%;
  animation: pl-wave 600ms var(--ease-plate) 2;
}
/* The composer's caret, while `perly.js` types its questions. */
@keyframes pl-caret {
  50% {
    opacity: 0;
  }
}
.pl-js [data-pic-question]::after {
  display: inline-block;
  width: 1.5px;
  height: 1.15em;
  margin-left: 1px;
  background: currentColor;
  vertical-align: -0.2em;
  content: '';
  animation: pl-caret 1s steps(1) infinite;
}
.pl-js [data-pic-question].is-typing::after {
  animation: none;
}

@media (prefers-reduced-motion: reduce) {
  .pic-state,
  .pl-plate,
  .pl-error,
  .pl-field--cleared .pl-input {
    transition: none;
  }
  .pl-js [data-pic-question]::after {
    display: none;
  }
  .pl-page[data-wave] [data-pic-wave] {
    animation: none;
  }
}

/* ———————————————————————————— narrower windows ——— */

@media (max-width: 1199px) {
  .pl-step {
    flex-basis: 50%;
    padding-inline: clamp(24px, 6vw, 104px);
  }
}

/* Note · Phone: under 900px the plate goes and the column takes the width with 20px sides. */
@media (max-width: 899px) {
  .pl-page {
    padding: 0;
  }
  .pl-plate {
    display: none;
  }
  .pl-step {
    flex: 1 1 auto;
    gap: 40px;
    min-height: 100dvh;
    padding: 20px 20px 28px;
  }
  .pl-question {
    gap: 28px;
  }
  .pl-heading {
    gap: 12px;
  }
  .pl-logo svg {
    width: 24px;
    height: 24px;
  }
  .pl-wordmark {
    font-size: 22px;
    line-height: 24px;
  }
  .pl-switch__note {
    display: none;
  }
  .pl-question {
    max-width: none;
  }
  .pl-title {
    font-size: 32px;
    line-height: 36px;
  }
  .pl-lead {
    font-size: 16px;
    line-height: 24px;
  }
}

/* ———————————————————————————— a page this theme has not drawn ——— */

.pl-generic p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 22px;
}
.pl-generic a {
  color: var(--ink);
}
.pl-generic input[type='text'],
.pl-generic input[type='email'],
.pl-generic input[type='password'] {
  width: 100%;
  height: 44px;
  padding-inline: 14px;
  border: 1px solid var(--border-window);
  border-radius: 10px;
  font: inherit;
  font-size: 15px;
}
.pl-generic input[type='submit'],
.pl-generic button {
  height: 44px;
  padding-inline: 20px;
  border: 1px solid var(--ink);
  border-radius: 10px;
  background: var(--ink);
  color: var(--white);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

/*
 * <TEMP UI - MUST BE REVIEWED> Two-step sign-in (login-config-totp.ftl, login-otp.ftl): the
 * numbered setup steps, the QR code and its key, and the choice between authenticators.
 */
.pl-steps {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 20px;
}
.pl-steps li > * {
  display: block;
  margin-top: 8px;
}
.pl-qr {
  border-radius: 8px;
  border: 1px solid var(--border-window);
}
.pl-key {
  font-family: ui-monospace, monospace;
  font-size: 13px;
  word-break: break-all;
  user-select: all;
}
.pl-choices {
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 8px;
}
.pl-choice {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 14px;
}
