/* ==========================================================================
   auth.css - Stile condiviso delle pagine di autenticazione
   Usato da login.php e da src/verifica_otp.php
   Palette derivata dal logo ERP LFS: arancio #E66239 + ardesia #44555F
   ========================================================================== */

:root {
    --auth-primary: #E66239;
    --auth-primary-dark: #C94E28;
    --auth-primary-soft: rgba(230, 98, 57, 0.12);
    --auth-primary-ring: rgba(230, 98, 57, 0.18);

    --auth-slate: #44555F;
    --auth-slate-dark: #33424B;

    --auth-text: #1F2A30;
    --auth-text-soft: #6B7A84;
    --auth-text-muted: #94A3AB;

    --auth-surface: #FFFFFF;
    --auth-border: #E3E8EC;
    --auth-border-strong: #CFD8DE;
    --auth-field: #F7F9FA;

    --auth-danger: #D93025;
    --auth-danger-soft: #FDECEA;
    --auth-success: #1E8E3E;
    --auth-success-soft: #E8F5EC;

    --auth-radius: 22px;
    --auth-radius-sm: 12px;

    --auth-shadow: 0 1px 2px rgba(31, 42, 48, 0.04),
                   0 12px 28px -8px rgba(31, 42, 48, 0.12),
                   0 40px 64px -32px rgba(31, 42, 48, 0.18);
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

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

html {
    height: 100%;
}

body.auth-page {
    margin: 0;
    min-height: 100%;
    padding: 32px 20px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 28px;

    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--auth-text);
    background-color: #F2F5F7;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Sfondo decorato: due aloni sfumati nei colori del marchio.
   Sta in un pseudo-elemento fisso per non influenzare il layout. */
body.auth-page::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(56rem 36rem at 12% -10%, rgba(230, 98, 57, 0.16), transparent 60%),
        radial-gradient(48rem 34rem at 92% 108%, rgba(68, 85, 95, 0.20), transparent 62%),
        linear-gradient(170deg, #FBFCFD 0%, #EFF3F5 100%);
}

/* Trama a griglia appena percettibile, per dare profondita' allo sfondo. */
body.auth-page::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: 0.55;
    background-image:
        linear-gradient(rgba(68, 85, 95, 0.045) 1px, transparent 1px),
        linear-gradient(90deg, rgba(68, 85, 95, 0.045) 1px, transparent 1px);
    background-size: 56px 56px;
    -webkit-mask-image: radial-gradient(70% 60% at 50% 45%, #000 0%, transparent 100%);
    mask-image: radial-gradient(70% 60% at 50% 45%, #000 0%, transparent 100%);
}

/* --------------------------------------------------------------------------
   Card
   -------------------------------------------------------------------------- */

.auth-card {
    width: 100%;
    max-width: 440px;
    padding: 40px 38px 34px;
    background: var(--auth-surface);
    border: 1px solid rgba(255, 255, 255, 0.85);
    border-radius: var(--auth-radius);
    box-shadow: var(--auth-shadow);
    animation: auth-card-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.auth-card--otp {
    max-width: 480px;
}

@keyframes auth-card-in {
    from { opacity: 0; transform: translateY(14px) scale(0.985); }
    to   { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------------------
   Intestazione della card
   -------------------------------------------------------------------------- */

.auth-header {
    text-align: center;
    margin-bottom: 28px;
}

.auth-logo {
    display: block;
    height: 92px;
    width: auto;
    margin: 0 auto 20px;
}

.auth-title {
    margin: 0 0 8px;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--auth-text);
}

.auth-subtitle {
    margin: 0;
    font-size: 14.5px;
    font-weight: 500;
    line-height: 1.55;
    color: var(--auth-text-soft);
}

.auth-subtitle strong {
    color: var(--auth-text);
    font-weight: 600;
    white-space: nowrap;
}

/* Icona circolare usata nella pagina OTP al posto del logo */
.auth-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    margin-bottom: 20px;
    border-radius: 20px;
    font-size: 30px;
    color: var(--auth-primary);
    background: var(--auth-primary-soft);
}

/* --------------------------------------------------------------------------
   Avvisi
   -------------------------------------------------------------------------- */

.auth-alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 20px;
    padding: 13px 15px;
    border-radius: var(--auth-radius-sm);
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.45;
    text-align: left;
    animation: auth-alert-in 0.35s ease both;
}

.auth-alert i {
    flex: none;
    font-size: 18px;
    line-height: 1.2;
}

.auth-alert--error {
    color: #8E1B13;
    background: var(--auth-danger-soft);
    border: 1px solid rgba(217, 48, 37, 0.22);
}

.auth-alert--success {
    color: #13632B;
    background: var(--auth-success-soft);
    border: 1px solid rgba(30, 142, 62, 0.22);
}

@keyframes auth-alert-in {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------------------
   Campi del modulo
   -------------------------------------------------------------------------- */

.auth-field {
    margin-bottom: 18px;
}

.auth-label {
    display: block;
    margin-bottom: 7px;
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--auth-text-soft);
}

.auth-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.auth-input-wrap > i {
    position: absolute;
    left: 15px;
    font-size: 19px;
    color: var(--auth-text-muted);
    pointer-events: none;
    transition: color 0.2s ease;
}

.auth-input {
    width: 100%;
    height: 50px;
    padding: 0 16px 0 45px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    color: var(--auth-text);
    background: var(--auth-field);
    border: 1.5px solid var(--auth-border);
    border-radius: var(--auth-radius-sm);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.auth-input::placeholder {
    color: var(--auth-text-muted);
    font-weight: 400;
}

.auth-input:hover {
    border-color: var(--auth-border-strong);
}

.auth-input:focus {
    background: var(--auth-surface);
    border-color: var(--auth-primary);
    box-shadow: 0 0 0 4px var(--auth-primary-ring);
}

.auth-input-wrap:focus-within > i {
    color: var(--auth-primary);
}

/* Campo password: spazio a destra per il pulsante mostra/nascondi */
.auth-input--password {
    padding-right: 48px;
}

.auth-toggle-pw {
    position: absolute;
    right: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    font-size: 19px;
    color: var(--auth-text-muted);
    background: none;
    border: none;
    border-radius: 9px;
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.auth-toggle-pw:hover {
    color: var(--auth-text);
    background: rgba(68, 85, 95, 0.07);
}

.auth-toggle-pw:focus-visible {
    outline: 2px solid var(--auth-primary);
    outline-offset: 1px;
}

/* --------------------------------------------------------------------------
   Checkbox "Ricordami"
   -------------------------------------------------------------------------- */

.auth-options {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 4px 0 24px;
}

.auth-check {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--auth-text-soft);
    cursor: pointer;
    user-select: none;
}

.auth-check input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.auth-check .box {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: var(--auth-surface);
    border: 1.5px solid var(--auth-border-strong);
    border-radius: 6px;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.auth-check .box::after {
    content: "";
    width: 9px;
    height: 5px;
    margin-top: -2px;
    border: 2px solid #fff;
    border-top: 0;
    border-right: 0;
    transform: rotate(-45deg) scale(0.5);
    opacity: 0;
    transition: transform 0.18s ease, opacity 0.18s ease;
}

.auth-check input:checked + .box {
    background: var(--auth-primary);
    border-color: var(--auth-primary);
}

.auth-check input:checked + .box::after {
    transform: rotate(-45deg) scale(1);
    opacity: 1;
}

.auth-check input:focus-visible + .box {
    box-shadow: 0 0 0 4px var(--auth-primary-ring);
}

.auth-link {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--auth-primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

.auth-link:hover {
    color: var(--auth-primary-dark);
    text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Pulsante principale
   -------------------------------------------------------------------------- */

.auth-button {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    width: 100%;
    height: 52px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: #fff;
    background: linear-gradient(180deg, #EC6C43 0%, var(--auth-primary) 100%);
    border: none;
    border-radius: var(--auth-radius-sm);
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(201, 78, 40, 0.24),
                0 8px 18px -6px rgba(201, 78, 40, 0.45);
    transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.auth-button i {
    font-size: 18px;
    transition: transform 0.2s ease;
}

.auth-button:hover {
    filter: brightness(1.04);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(201, 78, 40, 0.24),
                0 12px 24px -6px rgba(201, 78, 40, 0.5);
}

.auth-button:hover i {
    transform: translateX(3px);
}

.auth-button:active {
    transform: translateY(0);
    filter: brightness(0.97);
    box-shadow: 0 1px 2px rgba(201, 78, 40, 0.3);
}

.auth-button:focus-visible {
    outline: 2px solid var(--auth-primary-dark);
    outline-offset: 3px;
}

.auth-button:disabled {
    cursor: not-allowed;
    filter: saturate(0.6);
    opacity: 0.75;
    transform: none;
}

/* Stato di invio: testo sostituito da uno spinner */
.auth-button.is-loading {
    color: transparent;
    pointer-events: none;
}

.auth-button.is-loading i {
    opacity: 0;
}

.auth-button.is-loading::after {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: auth-spin 0.7s linear infinite;
}

@keyframes auth-spin {
    to { transform: rotate(360deg); }
}

/* --------------------------------------------------------------------------
   Campi OTP
   -------------------------------------------------------------------------- */

.otp-inputs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 22px;
}

.otp-inputs input {
    width: 100%;
    max-width: 58px;
    height: 66px;
    padding: 0;
    font-family: inherit;
    font-size: 26px;
    font-weight: 700;
    text-align: center;
    color: var(--auth-text);
    background: var(--auth-field);
    border: 1.5px solid var(--auth-border);
    border-radius: 14px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease,
                background-color 0.2s ease, transform 0.15s ease;
}

.otp-inputs input:hover {
    border-color: var(--auth-border-strong);
}

.otp-inputs input.is-filled {
    background: var(--auth-surface);
    border-color: var(--auth-border-strong);
}

.otp-inputs input:focus {
    background: var(--auth-surface);
    border-color: var(--auth-primary);
    box-shadow: 0 0 0 4px var(--auth-primary-ring);
    transform: translateY(-2px);
}

.otp-inputs input.paste-animate {
    background: var(--auth-primary-soft);
    border-color: var(--auth-primary);
}

/* Errore: i campi vibrano e diventano rossi */
.otp-inputs.has-error input {
    border-color: rgba(217, 48, 37, 0.55);
    background: var(--auth-danger-soft);
}

.otp-inputs.has-error {
    animation: auth-shake 0.4s ease;
}

@keyframes auth-shake {
    0%, 100% { transform: translateX(0); }
    20%      { transform: translateX(-7px); }
    40%      { transform: translateX(6px); }
    60%      { transform: translateX(-4px); }
    80%      { transform: translateX(2px); }
}

/* Conto alla rovescia di validita' del codice */
.otp-timer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    margin-bottom: 22px;
    font-size: 13px;
    font-weight: 600;
    color: var(--auth-text-soft);
}

.otp-timer i {
    font-size: 16px;
}

.otp-timer .value {
    font-variant-numeric: tabular-nums;
    color: var(--auth-text);
}

.otp-timer.is-expired {
    color: var(--auth-danger);
}

.otp-timer.is-expired .value {
    color: var(--auth-danger);
}

.otp-resend {
    margin-top: 22px;
    padding-top: 20px;
    border-top: 1px solid var(--auth-border);
    font-size: 13.5px;
    font-weight: 500;
    text-align: center;
    color: var(--auth-text-soft);
}

.otp-resend a.is-disabled {
    color: var(--auth-text-muted);
    pointer-events: none;
    text-decoration: none;
}

/* --------------------------------------------------------------------------
   Pie' di pagina
   -------------------------------------------------------------------------- */

.auth-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 20px;
    font-size: 13px;
    font-weight: 600;
    color: var(--auth-text-soft);
    text-decoration: none;
    transition: color 0.2s ease;
}

.auth-back:hover {
    color: var(--auth-primary);
}

body.auth-page footer {
    width: 100%;
    padding-bottom: 28px;
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    color: var(--auth-text-muted);
}

body.auth-page footer p {
    margin: 3px 0;
}

body.auth-page footer a {
    color: var(--auth-text-soft);
    font-weight: 600;
    text-decoration: none;
}

body.auth-page footer a:hover {
    color: var(--auth-primary);
}

body.auth-page .footer-content {
    display: block;
}

body.auth-page .version {
    text-align: center;
}

.config-exists-message {
    max-width: 440px;
    margin: 0 auto;
    padding: 18px 20px;
    font-weight: 600;
    text-align: center;
    color: #8E1B13;
    background: var(--auth-danger-soft);
    border: 1px solid rgba(217, 48, 37, 0.22);
    border-radius: var(--auth-radius-sm);
}

/* --------------------------------------------------------------------------
   Adattamento su schermi piccoli
   -------------------------------------------------------------------------- */

@media (max-width: 520px) {
    body.auth-page {
        padding: 24px 16px 0;
        gap: 20px;
    }

    .auth-card {
        padding: 32px 22px 26px;
        border-radius: 18px;
    }

    .auth-logo {
        height: 78px;
    }

    .auth-title {
        font-size: 23px;
    }

    .otp-inputs {
        gap: 7px;
    }

    .otp-inputs input {
        height: 58px;
        font-size: 22px;
        border-radius: 12px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
