/**
 * Pages d'authentification (login, mot de passe oublié, réinitialisation, changement obligatoire).
 * Feuille commune : les couleurs viennent du thème actif (variables.css chargé avant, --color-primary*).
 * Balisage : templates/components/auth_brand.php (panneau violet) + .auth-panel > .auth-box (formulaire).
 */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    /* Replis si variables.css non chargé */
    --color-primary: #7c3aed;
    --color-primary-dark: #5b21b6;
    --color-primary-rgb: 124, 58, 237;
    --auth-ink: #0f172a;
    --auth-muted: #64748b;
    --auth-line: #e2e8f0;
}

html { -webkit-text-size-adjust: 100%; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    min-height: 100vh;
    color: var(--auth-ink);
    background: #fff;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.auth { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 100vh; }

/* ===== Panneau de marque (couleur du thème) ===== */
.auth-brand {
    position: relative; overflow: hidden;
    display: flex; flex-direction: column; justify-content: space-between;
    padding: 56px 64px;
    color: #fff;
    background:
        radial-gradient(90% 60% at 100% 0%, rgba(255,255,255,0.16), transparent 60%),
        radial-gradient(70% 50% at 0% 100%, rgba(0,0,0,0.22), transparent 65%),
        linear-gradient(155deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
}
.brand-top { display: flex; align-items: center; gap: 14px; }
.brand-badge {
    width: 48px; height: 48px; border-radius: 14px; background: #fff;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 20px rgba(0,0,0,0.18);
}
.brand-badge img { width: 30px; height: 30px; object-fit: contain; }
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: 0.18em; }

.brand-body { max-width: 460px; }
.brand-body h1 { font-size: clamp(28px, 3vw, 40px); line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; }
.brand-body > p { margin-top: 16px; font-size: 16px; line-height: 1.6; color: rgba(255,255,255,0.82); }

.brand-points { list-style: none; margin-top: 36px; display: grid; gap: 18px; }
.brand-points li { display: flex; align-items: flex-start; gap: 14px; }
.brand-points .pt-icon {
    flex: 0 0 38px; width: 38px; height: 38px; border-radius: 11px;
    background: rgba(255,255,255,0.14); border: 1px solid rgba(255,255,255,0.22);
    display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.brand-points strong { display: block; font-size: 15px; font-weight: 600; }
.brand-points span.pt-text { display: block; font-size: 14px; color: rgba(255,255,255,0.75); }
.brand-foot { font-size: 13px; color: rgba(255,255,255,0.7); }

/* ===== Colonne formulaire ===== */
.auth-panel { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 48px 32px; background: #fff; }
.auth-box { width: 100%; max-width: 400px; }

.mobile-brand { display: none; align-items: center; gap: 12px; margin-bottom: 32px; }
.mobile-brand .brand-badge { background: rgba(var(--color-primary-rgb), 0.08); box-shadow: none; }
.mobile-brand .brand-name { color: var(--color-primary); }

.auth-box h2 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.auth-box .lead { margin-top: 8px; color: var(--auth-muted); font-size: 15px; }

form { margin-top: 32px; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 600; font-size: 14px; color: #1e293b; }

.input-wrapper { position: relative; }
.input-wrapper > i.lead-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: #94a3b8; font-size: 14px; pointer-events: none; }
.form-control {
    width: 100%; height: 48px; padding: 0 14px 0 42px;
    border: 1px solid #cbd5e1; border-radius: 10px; background: #fff;
    font: inherit; font-size: 15px; color: var(--auth-ink);
    transition: border-color .15s, box-shadow .15s;
}
.form-control::placeholder { color: #94a3b8; }
.form-control:hover { border-color: #94a3b8; }
.form-control:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 4px rgba(var(--color-primary-rgb), 0.14); }
.form-control.has-toggle { padding-right: 52px; }

.toggle-password {
    position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
    width: 38px; height: 38px; border: 0; background: none; cursor: pointer;
    color: #64748b; font-size: 15px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
}
.toggle-password:hover { color: var(--color-primary); background: rgba(var(--color-primary-rgb), 0.07); }
.toggle-password:focus-visible, .forgot-link:focus-visible, .btn:focus-visible, .legal a:focus-visible {
    outline: 3px solid rgba(var(--color-primary-rgb), 0.45); outline-offset: 2px;
}

.form-row { display: flex; justify-content: flex-end; margin: -6px 0 24px; }
.forgot-link { font-size: 14px; color: var(--color-primary); text-decoration: none; font-weight: 600; border-radius: 4px; }
.forgot-link:hover { text-decoration: underline; }

.btn {
    width: 100%; height: 48px; border: 0; cursor: pointer;
    background: var(--color-primary); color: #fff;
    font: inherit; font-size: 15px; font-weight: 600; border-radius: 10px;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    transition: background .15s, box-shadow .15s, transform .1s;
    box-shadow: 0 1px 2px rgba(15,23,42,0.12), 0 6px 16px rgba(var(--color-primary-rgb), 0.28);
}
.btn:hover { background: var(--color-primary-dark); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .75; cursor: progress; }

.alert { padding: 12px 14px; border-radius: 10px; margin-top: 24px; font-size: 14px; display: flex; align-items: flex-start; gap: 10px; border: 1px solid transparent; }
.alert i { margin-top: 2px; }
.alert-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.alert + form { margin-top: 24px; }

.legal { margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--auth-line); color: #94a3b8; font-size: 12px; line-height: 1.8; text-align: center; }
.legal a { color: #64748b; text-decoration: none; border-radius: 3px; }
.legal a:hover { color: var(--color-primary); text-decoration: underline; }

/* ===== Mouvement ===== */
@keyframes lg-rise    { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes lg-slide-x { from { opacity: 0; transform: translateX(-22px); } to { opacity: 1; transform: none; } }
@keyframes lg-fade    { from { opacity: 0; } to { opacity: 1; } }
@keyframes lg-drift   { from { transform: translate(0, 0) scale(1); } to { transform: translate(46px, -36px) scale(1.18); } }
@keyframes lg-halo    { 0% { box-shadow: 0 8px 20px rgba(0,0,0,0.18), 0 0 0 0 rgba(255,255,255,0.45); }
                        70%, 100% { box-shadow: 0 8px 20px rgba(0,0,0,0.18), 0 0 0 16px rgba(255,255,255,0); } }
@keyframes lg-shake   { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-9px); } 40% { transform: translateX(8px); }
                        60% { transform: translateX(-5px); } 80% { transform: translateX(4px); } }
@keyframes lg-spin    { to { transform: rotate(360deg); } }

/* Panneau de marque : deux halos lumineux qui dérivent lentement derrière le texte */
.auth-brand::before, .auth-brand::after {
    content: ""; position: absolute; border-radius: 50%; pointer-events: none;
    background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.28), rgba(255,255,255,0) 68%);
    animation: lg-drift 14s ease-in-out infinite alternate;
}
.auth-brand::before { width: 420px; height: 420px; top: -140px; right: -120px; }
.auth-brand::after  { width: 340px; height: 340px; bottom: -120px; left: -90px; animation-duration: 19s; animation-direction: alternate-reverse; }
.brand-top, .brand-body, .brand-foot { position: relative; z-index: 1; }

/* Entrée échelonnée du panneau de marque */
.brand-top  { animation: lg-rise 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
.brand-badge { animation: lg-halo 3.2s ease-out 1s infinite; }
.brand-body h1 { animation: lg-rise 0.8s cubic-bezier(0.2, 0.7, 0.2, 1) 0.15s backwards; }
.brand-body > p { animation: lg-rise 0.8s cubic-bezier(0.2, 0.7, 0.2, 1) 0.28s backwards; }
.brand-points li { animation: lg-slide-x 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
.brand-points li:nth-child(1) { animation-delay: 0.45s; }
.brand-points li:nth-child(2) { animation-delay: 0.58s; }
.brand-points li:nth-child(3) { animation-delay: 0.71s; }
.brand-foot { animation: lg-fade 1s ease 0.9s backwards; }
.brand-points .pt-icon { transition: transform 0.25s ease, background 0.25s ease; }
.brand-points li:hover .pt-icon { transform: scale(1.1) rotate(-4deg); background: rgba(255,255,255,0.24); }

/* Entrée échelonnée du formulaire */
.auth-box > * { animation: lg-rise 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
.auth-box > :nth-child(1) { animation-delay: 0.05s; }
.auth-box > :nth-child(2) { animation-delay: 0.12s; }
.auth-box > :nth-child(3) { animation-delay: 0.19s; }
.auth-box > :nth-child(4) { animation-delay: 0.26s; }
.auth-box > :nth-child(5) { animation-delay: 0.33s; }
.auth-box > :nth-child(6) { animation-delay: 0.4s; }

/* Champs : l'icône prend la couleur du thème au focus */
.input-wrapper > i.lead-icon { transition: color 0.2s ease, transform 0.2s ease; }
.input-wrapper:focus-within > i.lead-icon { color: var(--color-primary); transform: translateY(-50%) scale(1.12); }

/* Bouton : reflet qui traverse au survol, flèche qui avance */
.btn { position: relative; overflow: hidden; }
.btn::before {
    content: ""; position: absolute; top: 0; bottom: 0; left: -60%; width: 40%; pointer-events: none;
    background: linear-gradient(100deg, transparent, rgba(255,255,255,0.28), transparent);
    transform: skewX(-18deg); transition: left 0.6s ease;
}
.btn:hover::before { left: 120%; }
.btn .fa-arrow-right { transition: transform 0.2s ease; }
.btn:hover .fa-arrow-right { transform: translateX(4px); }

/* Envoi en cours : le libellé laisse la place à un spinner */
.btn.is-loading > * { visibility: hidden; }
.btn.is-loading::after {
    content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; animation: lg-spin 0.7s linear infinite;
}

/* Erreur : le message secoue légèrement pour attirer l'oeil */
.alert-error { animation: lg-rise 0.4s ease backwards, lg-shake 0.5s ease 0.35s; }
.alert-success { animation: lg-rise 0.4s ease backwards; }

/* ===== Tablette / mobile : le panneau de marque disparaît, le formulaire garde la vedette ===== */
@media (max-width: 960px) {
    .auth { grid-template-columns: 1fr; }
    .auth-brand { display: none; }
    .auth-panel { justify-content: flex-start; padding: 40px 24px 32px; min-height: 100vh; }
    .mobile-brand { display: flex; }
}
@media (max-width: 380px) {
    .auth-panel { padding: 28px 18px; }
    .auth-box h2 { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
    .btn.is-loading::after { animation: lg-spin 1.6s linear infinite !important; }
}


/* ===== Éléments utilisés par les pages autres que le login ===== */
.auth-box .lead + .alert { margin-top: 24px; }
.alert-info { background: #eff6ff; color: #1e3a8a; border-color: #bfdbfe; }
.alert strong { font-weight: 700; }

.form-help { display: block; margin-top: 6px; font-size: 12px; color: var(--auth-muted); }
.field-error { display: none; margin-top: 6px; font-size: 13px; color: #b91c1c; }
.form-group.has-error .field-error { display: block; }
.form-group.has-error .form-control { border-color: #ef4444; box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.12); }

.auth-links { margin-top: 28px; text-align: center; font-size: 14px; }
.back-link { display: inline-flex; align-items: center; gap: 8px; color: var(--auth-muted); text-decoration: none; font-weight: 600; border-radius: 4px; transition: color 0.2s ease; }
.back-link:hover { color: var(--color-primary); }
.back-link i { transition: transform 0.2s ease; }
.back-link:hover i { transform: translateX(-4px); }
.back-link:focus-visible { outline: 3px solid rgba(var(--color-primary-rgb), 0.45); outline-offset: 2px; }

.security-tips { margin-top: 28px; padding: 16px 18px; border-radius: 12px; background: #f8fafc; border: 1px solid var(--auth-line); font-size: 13px; color: var(--auth-muted); }
.security-tips strong { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: #334155; font-size: 13px; }
.security-tips ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }

/* Les champs sans icône d'en-tête (ex. libellé seul) restent alignés */
.form-group > label i { margin-right: 6px; color: var(--color-primary); }

/* Lien présenté comme un bouton (ex. « Se connecter » après une réinitialisation) */
a.btn { text-decoration: none; }
.auth-links .btn { margin-top: 4px; }
