/* =========================================================
   THEME OPENIG — Styles consolidés et homogènes (FINAL)
   Objectif : styles communs à tous les formulaires FTL (Keycloak)
   ========================================================= */

/* =========================================================
   RESET / BASE
   ========================================================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { min-height: 100%; }

html {
  background-color: #f7f7f7;
  background-image: url("https://www.openig.org/sites/default/files/2024-05/mesh-header.svg");
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  background-attachment: fixed;
}

body {
  background: transparent;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 5vh 1rem;
  overflow-y: auto;
  font-family: "OpenSans_Regular", sans-serif;
  color: #0a0a0a;
  min-height: 100vh;
  font-size: 16px;
}

/* iOS : éviter les soucis de background fixed */
@supports (-webkit-touch-callout: none) {
  html { background-attachment: scroll; background-position: center top; }
}

/* Petites hauteurs : réduire l’espace */
@media (max-height: 700px) {
  body { padding: 3vh 1rem; }
}

/* =========================================================
   PANEL (conteneur principal)
   ========================================================= */
.panel {
  width: 100%;
  max-width: 720px;
  margin: auto 0;
  background: rgba(255,255,255,0.95);
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.06);
  padding: 2.25rem;
  overflow: hidden;
}

@media (min-width: 768px) {
  .panel { padding: 2.5rem 3rem; }
}

/* =========================================================
   LOGO
   ========================================================= */
.logo-openig {
  width: 83px;
  height: 86px;
  margin: 0 auto 1rem;
  display: block;
}

/* =========================================================
   TITRE
   ========================================================= */
#kc-page-title {
  text-align: center;
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  color: #0b2f2a;
}

/* =========================================================
   FORM — groupes / labels (PatternFly v5)
   ========================================================= */
.pf-v5-c-form__group { margin-bottom: 1rem; }

.pf-v5-c-form__label,
.pf-v5-c-form__label-text {
  font-weight: 400 !important;
  font-size: 1.05rem;
  color: #0a0a0a;
}

/* =========================================================
   INPUTS (généraux)
   ========================================================= */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="url"],
input[type="tel"],
textarea,
select {
  width: 100%;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.08);
  background: #fff;
  box-shadow: 0 4px 10px rgba(0,0,0,0.04);
  font-size: 1rem;
}

/* Ellipsis (inputs PF + selects natifs) */
.pf-v5-c-form-control,
select {
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------------------------------------------------
   Select natif : flèche custom + espace anti-chevauchement
   - IMPORTANT : on applique aussi aux .kc-dd-source au cas où
     le JS n'a pas encore remplacé le select (ou si désactivé).
   - Objectif : reproduire le rendu “prod avant” (texte jamais
     sous la flèche, ellipsis avant la zone flèche).
   --------------------------------------------------------- */
select:not(.kc-dd-source),
select.kc-dd-source {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;

  /* Espace à droite volontairement plus grand :
     évite que l'ellipsis passe sous la flèche */
  padding-right: 64px;

  background-image:
    linear-gradient(45deg, transparent 50%, rgba(0,0,0,0.55) 50%),
    linear-gradient(135deg, rgba(0,0,0,0.55) 50%, transparent 50%),
    linear-gradient(to right, transparent, transparent);

  /* Décalage flèche : un peu plus à gauche qu'avant pour créer
     un “petit espace” entre ellipsis et flèche */
  background-position:
    calc(100% - 28px) calc(50% - 4px),
    calc(100% - 20px) calc(50% - 4px),
    0 0;

  background-size: 6px 6px, 6px 6px, 100% 100%;
  background-repeat: no-repeat;
}

/* Focus accessible */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 4px rgba(62,160,143,0.28),
    0 12px 22px rgba(0,0,0,0.10);
}

/* =========================================================
   BOUTONS (PatternFly v5)
   ========================================================= */
.pf-v5-c-button,
.pf-c-button {
  border-radius: 14px !important;
  font-size: 1.1rem;
  font-weight: 700;
  box-shadow: 0 6px 14px rgba(0,0,0,0.06);
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    background-color 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease;
}

/* Supprime overlays PF */
.pf-v5-c-button::after,
.pf-c-button::after {
  border: none !important;
  box-shadow: none !important;
  background: transparent !important;
}

/* Inputs Keycloak qui sont des boutons */
input.pf-v5-c-button,
input.pf-c-button { -webkit-appearance: none; appearance: none; }

/* Largeur standard centrée (desktop & mobile) */
#kc-form-buttons .pf-v5-c-button,
#kc-form-buttons .pf-c-button,
#kc-form-login #kc-login,
#kc-form-rattachement .pf-v5-c-button,
#kc-form-rattachement .pf-c-button,
#kc-registration a {
  display: block;
  width: 100%;
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
  padding: 14px 22px;
  text-align: center;

  /* Mobile : éviter l’overflow des libellés */
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Primaire */
.pf-v5-c-button.pf-m-primary,
.pf-c-button.pf-m-primary,
#kc-form-login #kc-login {
  background-color: #3ea08f;
  color: #fff;
  border: none;
  cursor: pointer;
}

/* Secondaire */
.pf-v5-c-button.pf-m-secondary,
.pf-c-button.pf-m-secondary,
#kc-registration a,
.openig-btn-outline {
  background-color: #fff;
  color: #3ea08f !important;
  border: 2px solid #3ea08f;
  cursor: pointer;
  text-decoration: none;
}

/* Hover */
.pf-v5-c-button:hover,
.pf-c-button:hover,
#kc-registration a:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 22px rgba(0,0,0,0.12);
}

.pf-v5-c-button.pf-m-primary:hover,
.pf-c-button.pf-m-primary:hover,
#kc-form-login #kc-login:hover { background-color: #339987; }

.pf-v5-c-button.pf-m-secondary:hover,
.pf-c-button.pf-m-secondary:hover,
#kc-registration a:hover,
.openig-btn-outline:hover { background-color: #f8f8f8; }

/* Focus boutons */
.pf-v5-c-button:focus-visible,
.pf-c-button:focus-visible,
#kc-registration a:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 4px rgba(62,160,143,0.28),
    0 12px 22px rgba(0,0,0,0.10);
}

/* =========================================================
   LOGIN — Zone inscription
   ========================================================= */
#kc-registration {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
  margin-top: 1.5rem;
}

#kc-registration::before {
  content: "";
  display: block;
  width: 80%;
  height: 1px;
  background: rgba(0,0,0,0.15);
  margin: 0.5rem auto;
}

#kc-registration p,
#kc-registration > *:not(a):not(.login-pf-signup) {
  display: block;
  width: 100%;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

#kc-registration .login-pf-signup { width: 100%; display: block; }
#kc-registration a { border-radius: 14px !important; }

/* =========================================================
   BOUTONS — layout + respiration (tous formulaires)
   ========================================================= */
#kc-form-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#kc-register-form #kc-form-buttons,
#kc-passwd-update-form #kc-form-buttons,
#kc-reset-password-form #kc-form-buttons {
  margin-top: 1rem;
}

/* =========================================================
   MOT DE PASSE — bouton œil
   ========================================================= */
.pf-v5-c-input-group { position: relative; }
.pf-v5-c-input-group input { padding-right: 3.4rem; }

.openig-pw-toggle,
.pf-v5-c-input-group .pf-v5-c-button.pf-m-control {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: #3ea08f;
  border: none;
  border-radius: 12px;
  width: 44px;
  height: 44px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}

.openig-pw-toggle:hover,
.pf-v5-c-input-group .pf-v5-c-button.pf-m-control:hover { background: #339987; }

.openig-pw-toggle:focus-visible,
.pf-v5-c-input-group .pf-v5-c-button.pf-m-control:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 4px rgba(62,160,143,0.28),
    0 10px 18px rgba(0,0,0,0.12);
}

.openig-icon-eye,
.openig-icon-eye-slash {
  display: inline-block;
  width: 18px;
  height: 18px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

.openig-icon-eye {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23ffffff' d='M12 5c-7.633 0-11 7-11 7s3.367 7 11 7 11-7 11-7-3.367-7-11-7Zm0 12a5 5 0 1 1 0-10 5 5 0 0 1 0 10Zm0-8a3 3 0 1 0 0 6 3 3 0 0 0 0-6Z'/%3E%3C/svg%3E");
}

.openig-icon-eye-slash {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23ffffff' d='M2.1 3.51 3.51 2.1 21.9 20.49 20.49 21.9l-2.1-2.1A12.82 12.82 0 0 1 12 21C4.367 21 1 14 1 14a21.38 21.38 0 0 1 5.15-6.4L2.1 3.51ZM12 7c7.633 0 11 7 11 7a20.9 20.9 0 0 1-3.78 5.2l-2.15-2.15A4.98 4.98 0 0 0 12 9a4.9 4.9 0 0 0-1.96.4L8.5 7.86A8.86 8.86 0 0 1 12 7Zm0 4a3 3 0 0 1 3 3c0 .28-.04.55-.11.8l-3.69-3.69c.25-.07.52-.11.8-.11Zm-3 3c0-.28.04-.55.11-.8l3.69 3.69c-.25.07-.52.11-.8.11a3 3 0 0 1-3-3Z'/%3E%3C/svg%3E");
}

/* =========================================================
   OPTIONS (remember me / mdp oublié)
   ========================================================= */
.options-wrapper a {
  display: block;
  margin-bottom: 0.5rem;
  color: #0b2f2a;
  text-decoration: underline;
  font-weight: 600;
}

.options-wrapper label {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #3ea08f;
  cursor: pointer;
}

/* =========================================================
   ALERTES GLOBALES — couleurs visibles
   ========================================================= */
.pf-v5-c-alert {
  width: 100%;
  max-width: 520px;
  margin: 0 auto 1rem;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,0.08);
  background: rgba(255,255,255,0.92);
  box-shadow: 0 6px 14px rgba(0,0,0,0.06);
  border-left-width: 6px;
}

.pf-v5-c-alert.pf-m-danger {
  background: rgba(255, 235, 235, 0.95);
  border-left-color: #c83535;
  color: #8b1d1d;
}

.pf-v5-c-alert.pf-m-success {
  background: rgba(230, 247, 243, 0.95);
  border-left-color: #3ea08f;
  color: #0b5f55;
}

.pf-v5-c-alert.pf-m-warning {
  background: rgba(255, 244, 220, 0.95);
  border-left-color: #f0ab00;
  color: #7a4a00;
}

.pf-v5-c-alert.pf-m-info {
  background: rgba(230, 240, 255, 0.95);
  border-left-color: #0066cc;
  color: #003a8f;
}

/* =========================================================
   ERREURS INLINE (sous champs)
   ========================================================= */
.kc-error-message-inline {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  border: 1px solid rgba(200,53,53,0.35);
  background: rgba(255,241,241,0.92);
  color: #8b1d1d;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.kc-error-message-inline::before {
  content: "";
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  margin-top: 1px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23c83535' stroke-width='2.4' stroke-linecap='round' d='M6 6l12 12M18 6 6 18'/%3E%3C/svg%3E");
}

/* =========================================================
   CHECKLIST mots de passe (REGISTER + UPDATE PASSWORD)
   ========================================================= */
#kc-register-form #password-policy-errors,
#kc-passwd-update-form #password-policy-errors {
  margin-top: 0.35rem !important;
  padding-left: 0 !important;
  list-style: none;
}

#kc-register-form #password-policy-errors .pf-v5-c-helper-text__item,
#kc-passwd-update-form #password-policy-errors .pf-v5-c-helper-text__item {
  margin-top: 0.25rem;
}

.kc-error-message-inline + #password-policy-errors {
  margin-top: 0.5rem !important;
}

/* =========================================================
   PF FORM GRID — éviter le double espacement
   ========================================================= */
#kc-register-form.pf-v5-c-form,
#kc-passwd-update-form.pf-v5-c-form,
#kc-reset-password-form.pf-v5-c-form {
  --pf-v5-c-form--GridGap: 0.75rem !important;
}

#kc-register-form.pf-v5-c-form .pf-v5-c-form__group,
#kc-passwd-update-form.pf-v5-c-form .pf-v5-c-form__group,
#kc-reset-password-form.pf-v5-c-form .pf-v5-c-form__group {
  margin-bottom: 0 !important;
}

/* =========================================================
   REGISTER — CGU + reCAPTCHA
   ========================================================= */
#kc-register-form p.terms-text {
  text-align: center;
  font-size: 0.95rem;
  margin: 0.6rem 0 0.35rem !important;
}

#kc-register-form .g-recaptcha {
  display: block;
  width: 100%;
  margin: 0.35rem auto 0 !important;
}

#kc-register-form .g-recaptcha > div {
  margin: 0 auto !important;
}

/* =========================================================
   RESET PASSWORD — texte explicatif sous le formulaire
   ========================================================= */
#kc-reset-password-form + .login-pf-signup,
#kc-reset-password-form ~ .login-pf-signup,
.login-pf-signup.separation {
  text-align: center;
  max-width: 520px;
  margin: 1rem auto 0;
  font-size: 0.95rem;
  line-height: 1.45;
  color: #0a0a0a;
}

/* =========================================================
   RATTACHEMENT — champs hérités + départements modernisés
   ========================================================= */
.nom-champ { display: inline-block; margin: 12px 0 0 0; }
.champs-a-completer { text-align: left; }
.champ-texte { margin-bottom: 12px; }
.champ-description { width: 100%; height: 150px; resize: vertical; }

.champ-departements {
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 10px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.04);
  background: #fff;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  padding: 12px 16px;
  gap: 16px;
}

.champ-departements .colonne {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.champ-departements span {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.champ-departements label {
  cursor: pointer;
  user-select: none;
}

/* layout rattachement */
#kc-form-rattachement #initialBtns,
#kc-form-rattachement #attachPanel .kc-stack,
#kc-form-rattachement #createPanel .kc-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Attach panel: max-width historique aligné */
#kc-form-rattachement #attachPanel label.pf-v5-c-form__label,
#kc-form-rattachement #attachPanel select {
  display: block;
  width: 100%;
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
}

#kc-form-rattachement .kc-actions-row {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

@media (min-width: 520px) {
  #kc-form-rattachement .kc-actions-row { flex-direction: row; }
  #kc-form-rattachement .kc-actions-row > * { width: 100%; max-width: none; }
}

#kc-form-rattachement .kc-divider {
  width: 100%;
  max-width: 520px;
  height: 1px;
  margin: 1.25rem auto;
  background: rgba(0,0,0,0.18);
}

#kc-form-rattachement .kc-subtext {
  width: 100%;
  max-width: 520px;
  margin: 0 auto 0.75rem;
  text-align: center;
  font-weight: 600;
  color: rgba(0,0,0,0.78);
}

/* Séparateur OU (corrigé mobile : plus de "ligne sur le OU") */
#kc-form-rattachement .kc-or {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  text-align: center;
}

#kc-form-rattachement .kc-or span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 12px;
  font-weight: 800;
  font-size: 1.15rem;
  line-height: 1.2;
  color: #000;
  padding: 0;
}

#kc-form-rattachement .kc-or span::before,
#kc-form-rattachement .kc-or span::after {
  content: "";
  flex: 1 1 auto;
  height: 2px;
  background: rgba(0,0,0,0.75);
}

#kc-form-rattachement #createPanel .champ-departements { margin-bottom: 1rem; }

/* createPanel : champs textes pleine largeur */
#kc-form-rattachement #createPanel .champ-texte { width: 100%; }

/* =========================================================
   DROPDOWN MODERNE — STRUCTURE & TYPOLOGY (search-in-input)
   NOTE : le “petit espace” entre ellipsis et flèche est géré
          via padding-right augmenté + position flèche.
   ========================================================= */
.kc-dd{
  position: relative;
  width: 100%;
}

/* STRUCTURE (attachPanel) : conserve 520px centré */
#kc-form-rattachement #attachPanel .kc-dd{
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
}

/* TYPOLOGY (createPanel) : pleine largeur du panel */
#kc-form-rattachement #createPanel .kc-dd{
  max-width: 100%;
  margin-left: 0;
  margin-right: 0;
}

.kc-dd__control{ position: relative; }

/* Input visible (valeur sélectionnée + ellipsis) */
.kc-dd__input{
  width: 100%;
  padding-right: 64px; /* zone réservée (ellipsis + flèche + marge) */
  cursor: pointer;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Flèche (décalée légèrement pour laisser respirer le texte) */
.kc-dd__arrow{
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: 1rem;
}

/* Ouvert : bords carrés bas (continuité avec liste) */
.kc-dd--open .kc-dd__input{
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

/* Panel (liste uniquement) — aligné sous le champ */
.kc-dd__panel{
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% - 1px);

  display: none;
  flex-direction: column;

  background: #fff;
  border: 1px solid rgba(0,0,0,0.12);
  border-top: none;
  border-radius: 0 0 14px 14px;

  box-shadow: 0 14px 32px rgba(0,0,0,0.18);
  z-index: 110;

  overflow: hidden;
  animation: kc-dd-open 160ms ease-out;
}

.kc-dd.kc-dd--open .kc-dd__panel{ display: flex; }

@keyframes kc-dd-open{
  from{ opacity:0; transform: translateY(-4px); }
  to{ opacity:1; transform: translateY(0); }
}

.kc-dd__list{
  overflow-y: auto;
  min-height: 0;
  padding: 6px 0;
  -webkit-overflow-scrolling: touch;
}

.kc-dd__item{
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
}

.kc-dd__item:hover,
.kc-dd__item.is-active{
  background: rgba(62,160,143,0.14);
}

.kc-dd__empty{
  padding: 14px;
  text-align: center;
  color: #777;
  font-style: italic;
}

/* =========================================================
   MOBILE — ajustements généraux
   ========================================================= */
@media (max-width: 640px){
  .panel { padding: 1.5rem; }
  #kc-page-title { font-size: 1.35rem; }

  /* Boutons : confort de lecture + responsive */
  #kc-form-rattachement .pf-v5-c-button,
  #kc-form-rattachement .pf-c-button {
    padding: 12px 16px;
    font-size: 1.02rem;
  }

  /* Dropdown : reste sous le champ (pas de bottom sheet) */
  .kc-dd__panel{
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% - 1px);
    border-radius: 0 0 14px 14px;
  }
}

/* =========================================================
   COMPAT — select source (si visible avant remplacement JS)
   ========================================================= */
select.kc-dd-source{
  /* Le select peut être “source” du dropdown custom ; si le JS
     l’a déplacé hors écran, ces règles n’impactent pas le rendu.
     Si le JS n’a pas tourné, on garde un style propre. */
  box-shadow: 0 4px 10px rgba(0,0,0,0.04);
}
