/* ============================================================
   Ringover Auth — redesign (login / MFA / magic token)
   Feuille autonome : ne stylise QUE les écrans d'authentification.
   Les écrans portal / consent / logout / error gardent style.css.
   ============================================================ */

:root {
    --auth-accent: #00779e;
    --auth-accent-hover: #026384;
    --auth-text-primary: #162029;
    --auth-text-secondary: #646e7d;
    --auth-text-intermediate: #3d4753;
    --auth-border: #dfe5f3;
    --auth-border-light: #f0f3fa;
    --auth-bg-container: #ffffff;
    --auth-bg-opaque: #ffffff;
    --auth-glass: rgba(255, 255, 255, 0.4);
    --auth-warning: #ff8726;
    --auth-warning-light: rgba(255, 135, 38, 0.08);
    --auth-danger: #e5484d;
    --auth-danger-border: rgba(229, 72, 77, 0.55);
    --auth-placeholder: #8fa8be;
    --auth-radius-sm: 8px;
    --auth-radius-md: 18px;
    --auth-radius-lg: 28px;
}

* {
    margin: 0;
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background-color: #cddcff;
}

body.auth {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--auth-text-primary);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ---------- Layout & background ---------- */
#login-container {
    position: relative;
    width: 100vw;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow: hidden;
    background-image: linear-gradient(215deg, #ccdaff 15%, #c8e6ff 84%);
}

.auth-ellipse {
    position: absolute;
    left: -295px;
    bottom: 396px;
    width: 1144px;
    height: 808px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0) 70%);
    pointer-events: none;
    z-index: 0;
}

/* ---------- Card (glass) ---------- */
.auth-card {
    position: relative;
    z-index: 1;
    width: 602px;
    max-width: 100%;
    background: var(--auth-glass);
    border: 1px solid #ffffff;
    border-radius: var(--auth-radius-lg);
    padding: 8px;
    box-shadow: 0 20px 60px rgba(22, 32, 41, 0.12);
}

.auth-overlay {
    background: var(--auth-bg-container);
    border: 1px solid var(--auth-border-light);
    border-radius: var(--auth-radius-md);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    align-items: center;
}

/* ---------- Header ---------- */
.auth-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.auth-brand img {
    height: 22px;
    width: auto;
    display: block;
}

/* Language dropdown */
.auth-lang {
    position: relative;
}

.auth-lang-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 8px;
    background: none;
    border: none;
    border-radius: var(--auth-radius-sm);
    cursor: pointer;
    font: inherit;
    color: var(--auth-text-intermediate);
    transition: background 0.15s ease;
}

.auth-lang-btn:hover {
    background: #f4f6fb;
}

.auth-lang-flag {
    width: 20px;
    height: 14px;
    border-radius: 2px;
    object-fit: cover;
}

.auth-lang-caret {
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid var(--auth-text-secondary);
    transition: transform 0.15s ease;
}

.auth-lang.open .auth-lang-caret {
    transform: rotate(180deg);
}

.auth-lang-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 150px;
    background: #fff;
    border: 1px solid var(--auth-border);
    border-radius: var(--auth-radius-sm);
    box-shadow: 0 8px 24px rgba(22, 32, 41, 0.14);
    padding: 4px;
    display: none;
    z-index: 20;
}

.auth-lang.open .auth-lang-menu {
    display: block;
}

.auth-lang-menu > div {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--auth-text-primary);
}

.auth-lang-menu > div:hover {
    background: #f4f6fb;
}

/* ---------- Title ---------- */
.auth-title {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.auth-title h1 {
    font-size: 16px;
    font-weight: 600;
    line-height: 24px;
    color: var(--auth-text-primary);
}

.auth-title p {
    font-size: 14px;
    font-weight: 400;
    color: var(--auth-text-secondary);
}

/* ---------- Main / forms ---------- */
.auth-main {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.auth-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 24px;
    text-align: left;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.auth-field label {
    font-size: 14px;
    font-weight: 500;
    color: var(--auth-text-primary);
}

.auth-input-wrap {
    position: relative;
    width: 100%;
}

.auth-input {
    width: 100%;
    height: 48px;
    border: 1px solid var(--auth-border);
    border-radius: var(--auth-radius-sm);
    background: var(--auth-bg-opaque);
    padding: 0 16px;
    font-size: 14px;
    color: var(--auth-text-primary);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-input::placeholder {
    color: var(--auth-placeholder);
}

.auth-input:focus {
    border-color: var(--auth-accent);
    box-shadow: 0 0 0 3px rgba(0, 119, 158, 0.12);
}

.auth-field.has-error .auth-input {
    border-color: var(--auth-danger);
}

/* Autofill : Chrome force un fond clair et ignore background-color.
   On neutralise via box-shadow interne + text-fill-color, en s'appuyant
   sur les variables pour rester cohérent en light comme en dark. */
.auth-input:-webkit-autofill,
.auth-input:-webkit-autofill:hover,
.auth-input:-webkit-autofill:focus,
.auth-input:-webkit-autofill:active,
.auth-code input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 1000px var(--auth-bg-opaque) inset;
    box-shadow: 0 0 0 1000px var(--auth-bg-opaque) inset;
    -webkit-text-fill-color: var(--auth-text-primary);
    caret-color: var(--auth-text-primary);
    transition: background-color 9999s ease-in-out 0s;
}

.auth-field-error {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--auth-danger);
}

.auth-input-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--auth-text-secondary);
    cursor: pointer;
    user-select: none;
    background: none;
    border: none;
}

.auth-input-toggle.hidden-block {
    display: none !important;
}

.auth-reset {
    display: inline-block;
    font-size: 13px;
    font-weight: 500;
    color: var(--auth-accent);
    cursor: pointer;
}

.auth-reset:hover {
    text-decoration: underline;
}

/* ---------- Divider ---------- */
.auth-divider {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    color: var(--auth-text-secondary);
    font-size: 14px;
    white-space: nowrap;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--auth-border);
}

/* ---------- Provider cards (email step) ---------- */
.auth-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    width: 100%;
}

.auth-card-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--auth-bg-opaque);
    border: 1px solid var(--auth-border);
    border-radius: var(--auth-radius-md);
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
    min-width: 0;
}

.auth-card-btn:hover {
    border-color: var(--auth-accent);
    box-shadow: 0 4px 14px rgba(0, 119, 158, 0.12);
}

.auth-card-btn:active {
    transform: scale(0.98);
}

.auth-card-icon {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: var(--auth-radius-sm);
    background: no-repeat center / 26px;
}

.auth-card-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--auth-text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Provider pills (password step) ---------- */
.auth-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    width: 100%;
}

.auth-pill {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--auth-bg-opaque);
    border: 1px solid var(--auth-border);
    border-radius: var(--auth-radius-sm);
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 26px;
}

.auth-pill:hover {
    border-color: var(--auth-accent);
    box-shadow: 0 4px 14px rgba(0, 119, 158, 0.12);
}

.auth-pill:active {
    transform: scale(0.96);
}

/* Provider icons */
.provider-google { background-image: url('../img/google.svg'); }
.provider-apple { background-image: url('../img/apple.svg'); }
.provider-microsoft { background-image: url('../img/microsoft.svg'); }
.provider-linkedin { background-image: url('../img/linkedin.svg'); }
.provider-facebook { background-image: url('../img/facebook.svg'); }
.provider-sso { background-image: url('../img/sso.svg'); }

/* ---------- Buttons ---------- */
.auth-footer {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.auth-btn-primary {
    width: 100%;
    height: 44px;
    border: none;
    border-radius: var(--auth-radius-sm);
    background: var(--auth-accent);
    color: #fff;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

.auth-btn-primary:hover {
    background: var(--auth-accent-hover);
}

.auth-btn-primary:active {
    transform: scale(0.99);
}

.auth-btn-link {
    width: 100%;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--auth-accent);
    cursor: pointer;
}

.auth-btn-link:hover {
    text-decoration: underline;
}

/* SweetAlert : bouton de confirmation aligné sur le bouton principal "Continue" */
.swal-button--confirm {
    background-color: var(--auth-accent);
}

.swal-button--confirm:not([disabled]):hover {
    background-color: var(--auth-accent-hover) !important;
}

.swal-button--confirm:focus {
    box-shadow: 0 0 0 3px rgba(0, 119, 158, 0.29);
}

/* ---------- Terms ---------- */
.auth-terms {
    font-size: 12px;
    line-height: 18px;
    color: var(--auth-text-secondary);
    text-align: center;
    max-width: 352px;
}

.auth-terms a {
    color: inherit;
    text-decoration: underline;
}

/* ---------- Top error message (existing #error_message) ---------- */
#error_message {
    width: 100%;
    text-align: center;
    color: var(--auth-danger);
    font-size: 14px;
    font-weight: 500;
}

#error_message:empty {
    display: none;
}

/* ---------- Alert banner (warning) ---------- */
.auth-alert {
    display: flex;
    width: 100%;
    border-radius: var(--auth-radius-sm);
    overflow: hidden;
}

.auth-alert-bar {
    width: 4px;
    flex-shrink: 0;
    background: var(--auth-warning);
}

.auth-alert-body {
    flex: 1;
    display: flex;
    gap: 8px;
    padding: 16px 20px;
    background: var(--auth-warning-light);
    align-items: flex-start;
}

.auth-alert-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    background: no-repeat center / contain url('../img/warning.svg');
}

.auth-alert-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    text-align: left;
}

.auth-alert-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--auth-text-primary);
}

.auth-alert-text {
    font-size: 14px;
    color: var(--auth-text-primary);
}

.auth-alert-btn {
    align-self: flex-start;
    height: 40px;
    padding: 0 16px;
    border: none;
    border-radius: var(--auth-radius-sm);
    background: #333;
    color: #fff;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.auth-alert-btn:hover {
    opacity: 0.88;
}

/* ---------- Illustration (OTP / magic) ---------- */
.auth-illustration {
    width: 200px;
    height: 133px;
    margin: 0 auto;
    background: no-repeat center / contain url('../img/illustration-email.png');
}

/* ---------- Code inputs (OTP / magic) ---------- */
.auth-code {
    display: flex;
    gap: 12px;
    justify-content: center;
    width: 100%;
}

.auth-code input {
    width: 48px;
    height: 58px;
    text-align: center;
    font-size: 22px;
    font-weight: 600;
    color: var(--auth-text-primary);
    border: 1px solid var(--auth-border);
    border-radius: var(--auth-radius-sm);
    background: var(--auth-bg-opaque);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-code input:focus {
    border-color: var(--auth-accent);
    box-shadow: 0 0 0 3px rgba(0, 119, 158, 0.12);
}

.auth-hint {
    font-size: 14px;
    color: var(--auth-text-secondary);
    text-align: center;
}

.auth-resend {
    text-align: center;
    font-size: 14px;
    color: var(--auth-text-secondary);
}

.auth-resend a {
    color: var(--auth-accent);
    font-weight: 500;
    cursor: pointer;
}

.auth-resend a:hover {
    text-decoration: underline;
}

.auth-resend a.disabled {
    color: var(--auth-text-secondary);
    opacity: 0.5;
    pointer-events: none;
    cursor: default;
    text-decoration: none;
}

/* ---------- Step visibility (email <-> password) ---------- */
.auth-form .step-password-only {
    display: none;
}

.auth-form.pw-step .step-email-only {
    display: none;
}

.auth-form.pw-step .step-password-only {
    display: flex;
}

/* SSO form toggle (reuses #login-container.sso from existing JS) */
#auth2-form-sso {
    display: none;
}

#login-container.sso #auth2-form-password,
#login-container.sso .auth-cards,
#login-container.sso .auth-title-default {
    display: none;
}

#login-container.sso #auth2-form-sso {
    display: flex;
}

/* ---------- Loader ---------- */
.loader {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    z-index: 10000;
    overflow: hidden;
}

.loader.hidden {
    display: none;
}

.loader-ringover:before {
    content: "";
    position: absolute;
    z-index: 1;
    width: 195px;
    height: 195px;
    top: 50%;
    left: 50%;
    background: url('../img/loaderbg.png') no-repeat center / contain;
    border-radius: 50%;
    animation: auth-rotating 2s linear infinite;
}

.loader-ringover:after {
    content: "";
    position: absolute;
    z-index: 2;
    width: 200px;
    height: 200px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: url('../img/logo-loader.svg') no-repeat center / 200px;
}

@keyframes auth-rotating {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

.hidden {
    visibility: hidden !important;
}

.hidden-block {
    display: none !important;
}

/* ---------- Responsive (mobile) ---------- */
@media (max-width: 640px) {
    #login-container {
        padding: 12px;
        align-items: flex-start;
    }

    .auth-card {
        width: 100%;
        border-radius: 24px;
    }

    .auth-overlay {
        padding: 20px 16px;
    }

    .auth-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .auth-code input {
        width: 40px;
        height: 48px;
        font-size: 18px;
    }
}

@media (max-width: 360px) {
    .auth-cards {
        grid-template-columns: 1fr;
    }
}

/* ---------- Dark mode ---------- */
@media (prefers-color-scheme: dark) {
    /* On redéfinit les tokens : la plupart des éléments consomment ces
       variables, donc les textes/bordures/fonds s'adaptent automatiquement. */
    :root {
        --auth-text-primary: #e6e8ec;
        --auth-text-secondary: #bcc4ce;
        --auth-text-intermediate: #c2c9d2;
        --auth-border: #3a3f47;
        --auth-border-light: #2f333a;
        --auth-bg-container: #23262b;
        --auth-bg-opaque: #2b2f36;
        --auth-glass: rgba(255, 255, 255, 0.06);
        --auth-placeholder: #6b7684;
    }

    html { background-color: #1c1f24; }

    body.auth { color: var(--auth-text-primary); }

    #login-container {
        background-image: linear-gradient(215deg, #2a2f3a 15%, #232a33 84%);
    }

    .auth-card {
        border-color: rgba(255, 255, 255, 0.12);
    }

    /* Logo Ringover : version texte blanc en dark mode */
    .auth-brand img[src*="logo-ringover-full"] { display: none; }
    .auth-brand::before {
        content: "";
        height: 22px;
        width: 95px;
        background: url('../img/logo-ringover-darkmode.svg') no-repeat left center / contain;
    }

    /* Survols du sélecteur de langue */
    .auth-lang-btn:hover,
    .auth-lang-menu > div:hover { background: #2f333a; }

    .auth-lang-menu {
        background: #23262b;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    }

    /* Halo : la version blanche fait une tache en dark, on passe sur une
       lueur froide très subtile */
    .auth-ellipse {
        background: radial-gradient(circle, rgba(140, 165, 205, 0.10) 0%, rgba(140, 165, 205, 0) 70%);
    }

    /* Illustration email (OTP / magic token) : variante dark */
    .auth-illustration {
        background-image: url('../img/illustration-email-darkmode.png');
    }

    /* Icônes providers nécessitant une variante claire */
    .provider-apple { background-image: url('../img/apple-dark.svg'); }
    .provider-sso { background-image: url('../img/sso-dark.svg'); }

    /* Popups SweetAlert : thème sombre */
    .swal-modal { background-color: #23262b; }
    .swal-title { color: #e6e8ec; }
    .swal-text,
    .swal-content { color: #bcc4ce; }
    .swal-button--cancel {
        background-color: #2b2f36;
        color: #e6e8ec;
    }
    .swal-button--cancel:hover {
        background-color: #343941 !important;
    }
    /* Masques de l'icône succès : sinon des traits blancs apparaissent sur fond sombre */
    .swal-icon--success:after,
    .swal-icon--success:before,
    .swal-icon--success__hide-corners {
        background-color: #23262b;
    }
}
