/* ── Reset base ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Variabili tema SmartAuth ───────────────────────────────────────────────── */
:root {
    --sa-primary:       #4f3fb7;
    --sa-primary-dark:  #3c2e8a;
    --sa-primary-light: rgba(79, 63, 183, 0.15);
    --sa-primary-mid:   #c9c3f0;
    --sa-text:          #1a1a2e;
    --sa-text-muted:    #6b6b8a;
    --sa-border:        rgba(255, 255, 255, 0.25);
    --sa-bg-start:      #4f3fb7;
    --sa-bg-end:        #764ba2;
    --sa-white:         rgba(255, 255, 255, 0.95);
    --sa-error:         #c0392b;
    --sa-error-bg:      #fdf3f2;
    --sa-success:       #1a7a4a;
    --sa-success-bg:    #f0faf4;
    --sa-radius:        16px;
    --sa-shadow:        0 20px 60px rgba(0, 0, 0, 0.15);
    --sa-input-border:  #e9ecef;
    --sa-input-focus:   rgba(79, 63, 183, 0.25);
}

@media (prefers-color-scheme: dark) {
    :root {
        --sa-primary:       #7b6cd6;
        --sa-primary-dark:  #9b8de6;
        --sa-primary-light: rgba(123, 108, 214, 0.2);
        --sa-primary-mid:   #3a3060;
        --sa-text:          #e8e6f8;
        --sa-text-muted:    #9e9cbf;
        --sa-border:        rgba(255, 255, 255, 0.1);
        --sa-bg-start:      #1a1040;
        --sa-bg-end:        #2d1b69;
        --sa-white:         rgba(26, 23, 48, 0.95);
        --sa-error:         #e87070;
        --sa-error-bg:      #2a1010;
        --sa-success:       #5dd39e;
        --sa-success-bg:    #0d2a1a;
        --sa-shadow:        0 20px 60px rgba(0, 0, 0, 0.40);
        --sa-input-border:  #2e2b4a;
        --sa-input-focus:   rgba(123, 108, 214, 0.3);
    }
}

/* ── Animated background ────────────────────────────────────────────────────── */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: linear-gradient(135deg, var(--sa-bg-start) 0%, var(--sa-bg-end) 100%);
    color: var(--sa-text);
    font-size: 15px;
    line-height: 1.6;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    position: relative;
    overflow: hidden;
}

.bg-shapes {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 0;
    pointer-events: none;
}

.bg-shapes .shape {
    position: absolute;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    animation: float 15s infinite ease-in-out;
}

.bg-shapes .shape:nth-child(1) {
    width: 300px; height: 300px; top: -150px; left: -100px;
    animation-delay: 0s;
}
.bg-shapes .shape:nth-child(2) {
    width: 200px; height: 200px; top: 50%; right: -100px;
    animation-delay: 2s;
}
.bg-shapes .shape:nth-child(3) {
    width: 150px; height: 150px; bottom: -75px; left: 30%;
    animation-delay: 4s;
}
.bg-shapes .shape:nth-child(4) {
    width: 250px; height: 250px; top: 20%; left: 60%;
    animation-delay: 6s;
}

@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-30px) rotate(10deg); }
}

/* ── Layout pagina auth ─────────────────────────────────────────────────────── */
.auth-page-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    position: relative;
    z-index: 1;
}

/* ── Card principale ────────────────────────────────────────────────────────── */
.auth-card {
    background: var(--sa-white);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--sa-border);
    border-radius: var(--sa-radius);
    box-shadow: var(--sa-shadow);
    padding: 2.5rem 2.25rem;
    width: 100%;
    max-width: 420px;
    animation: slideUp 0.6s ease-out;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Header logo + titolo ────────────────────────────────────────────────────── */
.auth-header {
    text-align: center;
    margin-bottom: 1.75rem;
}

.auth-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.75rem;
}

.auth-logo .logo-fallback {
    width: 52px;
    height: 52px;
    background: var(--sa-primary);
    color: #fff;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-logo img {
    max-width: 80px;
    height: auto;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.1));
}

.auth-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--sa-text);
    margin-bottom: 0.2rem;
    letter-spacing: -0.5px;
}

.auth-subtitle {
    font-size: 0.875rem;
    color: var(--sa-text-muted);
}

/* ── Alerts ─────────────────────────────────────────────────────────────────── */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
    line-height: 1.5;
}

.alert-error {
    background: var(--sa-error-bg);
    color: var(--sa-error);
    border: 1px solid var(--sa-error);
}

.alert-success {
    background: var(--sa-success-bg);
    color: var(--sa-success);
    border: 1px solid var(--sa-success);
}

.alert-icon {
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid currentColor;
    margin-top: 1px;
}

/* ── Form controls ───────────────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--sa-text);
    margin-bottom: 0.35rem;
    letter-spacing: 0.01em;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.9375rem;
    border: 2px solid var(--sa-input-border);
    border-radius: 12px;
    background: var(--sa-white);
    color: var(--sa-text);
    transition: all 0.3s ease;
    outline: none;
    font-family: inherit;
    height: 52px;
}

.form-control:focus {
    border-color: var(--sa-primary);
    box-shadow: 0 0 0 4px var(--sa-input-focus);
}

.form-control::placeholder {
    color: var(--sa-text-muted);
    opacity: 0.7;
}

.input-with-toggle { position: relative; }
.input-with-toggle .form-control { padding-right: 2.5rem; }

.pwd-toggle {
    position: absolute;
    right: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--sa-text-muted);
    padding: 0.25rem;
    display: flex;
    align-items: center;
    border-radius: 4px;
    transition: color 0.15s;
}
.pwd-toggle:hover { color: var(--sa-primary); }

.otp-input {
    text-align: center;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: 0.5rem;
    padding: 0.75rem 1rem;
    font-family: 'Courier New', monospace;
    height: auto !important;
}

/* ── Checkbox ────────────────────────────────────────────────────────────────── */
.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
    color: var(--sa-text-muted);
}
.form-check input[type=checkbox] {
    width: 18px;
    height: 18px;
    accent-color: var(--sa-primary);
    cursor: pointer;
    border: 2px solid var(--sa-input-border);
    border-radius: 4px;
}
.form-check label { cursor: pointer; }

/* ── Pulsante primario ───────────────────────────────────────────────────────── */
.btn-primary {
    display: block;
    width: 100%;
    height: 52px;
    padding: 0.7rem 1rem;
    background: linear-gradient(135deg, var(--sa-primary) 0%, var(--sa-bg-end) 100%);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    letter-spacing: 0.01em;
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(79, 63, 183, 0.4);
}
.btn-primary:active { transform: translateY(0); }

/* ── Link secondari ──────────────────────────────────────────────────────────── */
.form-footer { text-align: center; margin-top: 1rem; }

.link-secondary {
    font-size: 0.875rem;
    color: var(--sa-text-muted);
    text-decoration: none;
    transition: color 0.15s;
}
.link-secondary:hover { color: var(--sa-primary); }

/* ── Validation ──────────────────────────────────────────────────────────────── */
.field-error { display: block; font-size: 0.8rem; color: var(--sa-error); margin-top: 0.25rem; }
.form-control.input-validation-error { border-color: var(--sa-error); }

/* ── OTP info ────────────────────────────────────────────────────────────────── */
.otp-info {
    background: var(--sa-primary-light);
    border: 1px solid var(--sa-primary-mid);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
    color: var(--sa-text);
    line-height: 1.55;
}
.otp-info p + p { margin-top: 0.4rem; }
.otp-expiry { color: var(--sa-text-muted); }

/* ── TOTP setup ──────────────────────────────────────────────────────────────── */
.totp-steps { display: flex; flex-direction: column; gap: 1.5rem; }

.totp-step { display: flex; gap: 1rem; align-items: flex-start; }

.step-number {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    background: var(--sa-primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    font-weight: 700;
    margin-top: 2px;
}

.step-content { flex: 1; font-size: 0.9rem; }
.step-content p { margin-bottom: 0.75rem; color: var(--sa-text-muted); }
.step-content p:last-child { margin-bottom: 0; }

.qr-container {
    background: #fff;
    border: 1px solid var(--sa-border);
    border-radius: 8px;
    padding: 1rem;
    display: inline-block;
    margin-bottom: 0.75rem;
}

.qr-image { display: block; width: 180px; height: 180px; image-rendering: pixelated; }

.manual-key { font-size: 0.8125rem; margin-bottom: 0.75rem; }
.manual-key summary { cursor: pointer; color: var(--sa-primary); user-select: none; margin-bottom: 0.4rem; }

.key-box {
    background: var(--sa-bg);
    border: 1px solid var(--sa-border);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    margin-top: 0.4rem;
}
.key-box code {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    letter-spacing: 0.08em;
    color: var(--sa-primary);
    word-break: break-all;
}

/* ── Footer ──────────────────────────────────────────────────────────────────── */
.page-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
}
