/*
 * Login theme «preseller» (design port B5). Colours come only from the generated tokens (tokens.css: preset E light in
 * :root, dark under prefers-color-scheme); sizes and weights follow design/tokens/preseller.tokens.json. Mobile-first:
 * one column, max 420 px, no horizontal scroll at 320 px. The p-* classes are reached through theme.properties; the
 * element rules under .p-page give the base pages we do not restyle by hand (error, info, expired, reset and update
 * password, logout confirm, register) the same look.
 */

/* ---------- Frame ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body,
.p-page {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--p-ui-background);
  color: var(--p-ui-foreground);
  font-family: "IBM Plex Sans", "Noto Sans Armenian", system-ui, sans-serif;
  font-size: 16px;
  line-height: 24px;
  overflow-wrap: break-word;
}

.p-login {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 420px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 56px 24px 32px;
}

.p-header {
  margin: 0 0 32px;
}

/* The lockup slot: 152 x 28; the lockup image (C1). */
.p-brand {
  display: flex;
  align-items: center;
  width: 152px;
  max-width: 100%;
  height: 28px;
  color: var(--p-accent-primary);
  font-size: 20px;
  line-height: 28px;
  font-weight: 700;
  white-space: nowrap;
}

.p-brand img {
  display: block;
  height: 28px;
  width: auto;
  max-width: 100%;
}

.p-card {
  flex: 1 0 auto;
  width: 100%;
}

.p-form-header {
  margin: 0 0 24px;
}

.p-title,
.p-page h1 {
  margin: 0;
  color: var(--p-ui-foreground);
  font-size: 24px;
  line-height: 32px;
  font-weight: 600;
}

.p-page h2,
.p-page h3 {
  margin: 24px 0 8px;
  font-size: 16px;
  line-height: 22px;
  font-weight: 600;
}

.p-required {
  margin: 0 0 8px;
  color: var(--p-ui-muted-foreground);
  font-size: 14px;
  line-height: 20px;
}

.p-page .required {
  color: var(--p-status-not-delivered-fg);
}

.p-page p {
  margin: 0 0 16px;
  color: var(--p-ui-foreground-2);
}

.p-page ul,
.p-page ol {
  margin: 0 0 16px;
  padding-left: 20px;
}

/* Signed-in-as line on pages after the user is known. */
.p-username {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
  margin-top: 0;
}

.p-username-text {
  color: var(--p-ui-foreground);
  font-weight: 600;
}

/* ---------- Fields ---------- */

.p-form {
  margin: 0;
}

.p-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 24px;
}

.p-field:last-child {
  margin-bottom: 0;
}

.p-form + .p-field,
.p-field + .p-form {
  margin-top: 16px;
}

.p-label,
.p-page label {
  color: var(--p-ui-foreground-2);
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
}

.p-input,
.p-page input[type="text"],
.p-page input[type="email"],
.p-page input[type="tel"],
.p-page input[type="password"],
.p-page input[type="number"],
.p-page input:not([type]),
.p-page select,
.p-page textarea {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 52px;
  margin: 0;
  padding: 12px 16px;
  border: 1.5px solid var(--p-ui-border-strong);
  border-radius: var(--p-radius-control);
  background: var(--p-ui-surface);
  color: var(--p-ui-foreground);
  font: inherit;
  font-size: 18px;
  line-height: 26px;
  font-weight: 500;
  appearance: none;
}

.p-page select {
  padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--p-ui-muted-foreground) 50%),
    linear-gradient(135deg, var(--p-ui-muted-foreground) 50%, transparent 50%);
  background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
}

.p-page select[multiple] {
  padding-right: 16px;
  background-image: none;
}

.p-textarea,
.p-page textarea {
  min-height: 104px;
  resize: vertical;
}

.p-input::placeholder,
.p-page input::placeholder,
.p-page textarea::placeholder {
  color: var(--p-ui-muted-foreground);
  opacity: 1;
}

.p-input[aria-invalid="true"],
.p-page input[aria-invalid="true"],
.p-page select[aria-invalid="true"],
.p-page textarea[aria-invalid="true"] {
  border-color: var(--p-status-not-delivered-fg);
}

.p-input:disabled,
.p-page input:disabled,
.p-page select:disabled,
.p-page textarea:disabled {
  background: var(--p-ui-surface-2);
  color: var(--p-ui-muted-foreground);
}

.p-hint {
  color: var(--p-ui-muted-foreground);
  font-size: 14px;
  line-height: 20px;
}

.p-error {
  display: block;
  color: var(--p-status-not-delivered-fg);
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
}

/* Password input with its reveal button (base passwordVisibility.js keeps aria-label current; we show it as text). */
.p-input-group {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.p-input-group > .p-input {
  flex: 1 1 auto;
}

.p-btn-reveal {
  flex: 0 0 auto;
  min-width: 52px;
  min-height: 52px;
  padding: 0 12px;
  border: 1.5px solid var(--p-ui-border-strong);
  border-radius: var(--p-radius-control);
  background: var(--p-ui-surface);
  color: var(--p-accent-primary);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.p-btn-reveal::before {
  content: attr(aria-label);
}

.p-btn-reveal > i {
  display: none;
}

/* Checkboxes and radios: native control, accent colour. */
.p-check,
.p-page input[type="checkbox"],
.p-page input[type="radio"] {
  width: 20px;
  height: 20px;
  margin: 0 8px 0 0;
  vertical-align: -4px;
  accent-color: var(--p-accent-primary);
}

.p-page .checkbox label,
.p-page .radio label {
  color: var(--p-ui-foreground);
  font-weight: 400;
  font-size: 16px;
  line-height: 24px;
}

.p-field-settings {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 16px;
}

/* Base login.ftl renders the remember-me / forgot-password row even when the realm turns both off. */
.p-field-settings:not(:has(input, a)) {
  display: none;
}

.p-form-options,
.p-form-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- Buttons ---------- */

.p-btn,
.p-page button[type="submit"],
.p-page input[type="submit"],
.p-page input[type="button"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  min-height: 48px;
  margin: 0;
  padding: 12px 20px;
  border-width: 1.5px;
  border-style: solid;
  border-radius: var(--p-radius-control);
  font: inherit;
  font-size: 16px;
  line-height: 24px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  white-space: normal;
  cursor: pointer;
  appearance: none;
}

/* Colours by variant; an unmarked .p-btn or submit reads as primary. */
.p-btn {
  border-color: var(--p-accent-primary);
  background: var(--p-accent-primary);
  color: var(--p-accent-foreground);
}

.p-btn-primary,
.p-page button[type="submit"]:not(.p-btn-secondary),
.p-page input[type="submit"]:not(.p-btn-secondary) {
  border-color: var(--p-accent-primary);
  background: var(--p-accent-primary);
  color: var(--p-accent-foreground);
}

.p-btn-primary:hover,
.p-page button[type="submit"]:not(.p-btn-secondary):hover,
.p-page input[type="submit"]:not(.p-btn-secondary):hover {
  border-color: var(--p-accent-hover);
  background: var(--p-accent-hover);
}

.p-btn-secondary,
.p-page input[type="button"] {
  border-color: var(--p-ui-border-strong);
  background: var(--p-ui-surface);
  color: var(--p-ui-foreground);
}

.p-btn-secondary:hover,
.p-page input[type="button"]:hover {
  background: var(--p-ui-surface-2);
}

.p-page .p-btn-block {
  display: flex;
  width: 100%;
}

/* The primary call to action: 56 px tall (the boards). */
.p-page .p-btn-primary.p-btn-block,
.p-page .p-btn-large {
  min-height: 56px;
  font-size: 18px;
  line-height: 26px;
}

.p-btn:disabled,
.p-btn[aria-disabled="true"],
.p-disabled,
.p-page input[type="submit"]:disabled,
.p-page button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

/* ---------- Links ---------- */

.p-link,
.p-page a {
  color: var(--p-accent-primary);
  font-weight: 600;
  text-decoration: none;
  text-underline-offset: 3px;
}

.p-link:hover,
.p-page a:hover {
  color: var(--p-accent-hover);
  text-decoration: underline;
}

/* A button styled as a link keeps the button colours. */
.p-page a.p-btn,
.p-page a.p-btn:hover {
  text-decoration: none;
}

.p-page a.p-btn-primary {
  color: var(--p-accent-foreground);
}

.p-page a.p-btn-secondary {
  color: var(--p-ui-foreground);
}

/* Info area under the form (e.g. «no account? register», «back to login»). */
.p-info {
  margin-top: 24px;
  color: var(--p-ui-foreground-2);
  text-align: center;
}

.p-mt {
  margin-top: 16px;
}

/* ---------- Phone OTP pages (S-phone, S-telegram) ---------- */

/* Two forms in a row (code, then resend). */
.p-form + .p-form {
  margin-top: 16px;
}

/* The note under a button, e.g. «send again in 30 s». */
.p-page p.p-hint {
  margin: 8px 0 0;
  color: var(--p-ui-muted-foreground);
}

/* Lead text: «we sent a code to …», «open the bot …». */
.p-page .p-muted {
  margin: 0 0 24px;
  color: var(--p-ui-muted-foreground);
}

/* The number the Telegram link is for, between the lead text and the button. */
.p-page .p-muted + .p-phone {
  margin-top: -8px;
}

.p-page .p-phone {
  margin: 0 0 24px;
  color: var(--p-ui-muted-foreground);
  font-size: 15px;
  line-height: 22px;
  font-variant-numeric: tabular-nums;
}

/* «Other number»: a centred accent text link under the buttons. */
.p-page .p-alt-link {
  margin: 24px 0 0;
  text-align: center;
}

.p-alt-link .p-link,
.p-page .p-alt-link a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: 16px;
  line-height: 24px;
}

/* ---------- Focus ---------- */

/* 2 px ring in the accent ring colour outside a 2 px gap in the page colour. */
.p-page a:focus-visible,
.p-page button:focus-visible,
.p-page input:focus-visible,
.p-page select:focus-visible,
.p-page textarea:focus-visible,
.p-page [tabindex]:focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--p-ui-background), 0 0 0 4px var(--p-accent-ring);
}

/* ---------- Alerts ---------- */

.p-alert {
  display: flex;
  gap: 8px;
  margin: 0 0 24px;
  padding: 12px 16px;
  border-radius: var(--p-radius-control);
  background: var(--p-accent-tint);
  color: var(--p-ui-foreground);
  font-size: 15px;
  line-height: 22px;
}

.p-alert-info {
  background: var(--p-accent-tint);
  color: var(--p-ui-foreground);
}

.p-alert-error {
  background: var(--p-status-not-delivered-bg);
  color: var(--p-status-not-delivered-fg);
  font-weight: 500;
}

.p-alert-warning {
  background: var(--p-status-needs-decision-bg);
  color: var(--p-status-needs-decision-fg);
}

.p-alert-text {
  min-width: 0;
}

/* Base error.ftl / info.ftl message paragraphs. */
.p-page #kc-error-message p,
.p-page #kc-info-message p {
  color: var(--p-ui-foreground);
}

/* ---------- Choice lists (OTP credential picker, authenticator picker) ---------- */

.p-select-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0 0 24px;
  padding: 0;
  list-style: none;
}

/* login-otp.ftl: each credential is a label.p-choice after its hidden radio. */
.p-choice {
  display: block;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}

.p-choice-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.p-choice-header,
.p-select-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  border: 1.5px solid var(--p-ui-border-strong);
  border-radius: var(--p-radius-control);
  background: var(--p-ui-surface);
  color: var(--p-ui-foreground);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.p-choice-input:checked + label .p-choice-header,
.p-choice-input:checked + .p-choice-header {
  border-color: var(--p-accent-primary);
  background: var(--p-accent-tint);
}

.p-choice-input:focus-visible + label .p-choice-header,
.p-choice-input:focus-visible + .p-choice-header {
  box-shadow: 0 0 0 2px var(--p-ui-background), 0 0 0 4px var(--p-accent-ring);
}

.p-choice-icon,
.p-select-icon,
.p-select-arrow {
  flex: 0 0 auto;
}

.p-choice-icon:empty,
.p-select-icon:empty,
.p-select-arrow:empty {
  display: none;
}

.p-choice-title,
.p-select-heading {
  font-weight: 600;
}

.p-select-body {
  flex: 1 1 auto;
  min-width: 0;
}

.p-select-description {
  color: var(--p-ui-muted-foreground);
  font-size: 14px;
  line-height: 20px;
}

.p-select-fill {
  flex: 1 1 auto;
}

/* ---------- Identity providers ---------- */

.p-social {
  margin-top: 24px;
}

.p-social-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* ---------- Languages ---------- */

.p-locales {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 28px;
  margin-top: 48px;
  padding-top: 8px;
}

.p-locales .p-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: 16px;
  line-height: 24px;
}

.p-locales .p-link[aria-current="true"] {
  color: var(--p-ui-foreground);
  text-decoration: underline;
}

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: no-preference) {
  .p-btn,
  .p-link,
  .p-input,
  .p-page a,
  .p-page input,
  .p-page select,
  .p-page textarea {
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
  }
}
