/* ============================================
   Macingo AuthServer - Stili UI Condivisi
   ============================================ */

/* === CSS Variables (Design Tokens) === */
:root {
    /* Brand Colors */
    --color-primary: #0070AD;
    --color-primary-dark: #004d7a;
    --color-primary-darker: #00304d;
    --color-accent: #76b852;
    --color-accent-dark: #5a9a3c;
    
    /* Semantic Colors */
    --color-success: #059669;
    --color-success-light: #10b981;
    --color-error: #dc2626;
    --color-error-bg: #fef2f2;
    --color-error-border: #fecaca;
    --color-warning: #d97706;
    --color-info: #1d4ed8;
    --color-info-bg: #eff6ff;
    --color-info-border: #bfdbfe;
    
    /* Neutral Colors */
    --color-text-primary: #111827;
    --color-text-secondary: #374151;
    --color-text-muted: #6b7280;
    --color-text-light: #9ca3af;
    --color-bg-white: #ffffff;
    --color-bg-light: #f3f4f6;
    --color-border: #e5e7eb;
    
    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    
    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 50%;
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.2);
    --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --shadow-glow: 0 0 20px rgba(0, 112, 173, 0.3);
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --transition-slow: 0.3s ease;
    --transition-bounce: 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* === Base Reset === */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--color-text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* === Animations Keyframes === */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

@keyframes successPop {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes checkmark {
    0% { stroke-dashoffset: 50; }
    100% { stroke-dashoffset: 0; }
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 0.5;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

/* === Auth Page Layout === */
.auth-page {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 50%, var(--color-primary-darker) 100%);
    background-size: 200% 200%;
    background-attachment: fixed;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--spacing-lg);
    animation: gradientShift 15s ease infinite;
}

/* Background decorative elements */
.auth-page::before {
    content: '';
    position: fixed;
    top: -50%;
    right: -50%;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(255,255,255,0.05) 0%, transparent 70%);
    pointer-events: none;
    animation: float 8s ease-in-out infinite;
}

.auth-page::after {
    content: '';
    position: fixed;
    bottom: -50%;
    left: -50%;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(255,255,255,0.03) 0%, transparent 70%);
    pointer-events: none;
    animation: float 10s ease-in-out infinite reverse;
}

/* === Logo === */
.logo-container {
    margin: 30px 0 20px 0;
    animation: fadeInDown 0.6s ease-out;
}

.auth-logo {
    display: block;
    width: 220px;
    max-width: 60vw;
    height: auto;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15));
    transition: transform var(--transition-slow), filter var(--transition-slow);
}

.auth-logo:hover {
    transform: scale(1.03);
    filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.2));
}

/* === Card Container === */
.auth-container {
    max-width: 400px;
    width: 100%;
    position: relative;
    z-index: 1;
}

/* === Card === */
.auth-card {
    background: rgba(255, 255, 255, 0.98);
    border-radius: var(--radius-xl);
    padding: 28px 24px;
    box-shadow: var(--shadow-xl);
    animation: fadeInUp 0.5s ease-out;
    animation-fill-mode: backwards;
    animation-delay: 0.1s;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
}

/* Subtle gradient overlay on card */
.auth-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
    opacity: 0;
    transition: opacity var(--transition-base);
}

.auth-card:hover::before {
    opacity: 1;
}

/* === Typography === */
.card-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0 0 6px 0;
    color: var(--color-text-primary);
    text-align: center;
    animation: fadeIn 0.4s ease-out 0.2s backwards;
}

.card-subtitle {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin: 0 0 24px 0;
    text-align: center;
    animation: fadeIn 0.4s ease-out 0.3s backwards;
}

/* === Form Elements === */
.form-group {
    margin-bottom: var(--spacing-md);
    position: relative;
    text-align: left;
    animation: fadeInUp 0.4s ease-out backwards;
}

.form-group:nth-child(1) { animation-delay: 0.2s; }
.form-group:nth-child(2) { animation-delay: 0.25s; }
.form-group:nth-child(3) { animation-delay: 0.3s; }
.form-group:nth-child(4) { animation-delay: 0.35s; }

.input-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
    transition: color var(--transition-base);
}

.form-group:focus-within .input-label {
    color: var(--color-primary);
}

.auth-input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-white);
    color: var(--color-text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color var(--transition-base), box-shadow var(--transition-base), transform var(--transition-fast);
}

.auth-input::placeholder {
    color: var(--color-text-light);
}

.auth-input:hover {
    border-color: #d1d5db;
}

.auth-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 112, 173, 0.1);
}

.auth-input:focus:valid {
    border-color: var(--color-success);
}

.auth-input.input-error {
    border-color: var(--color-error);
    animation: shake 0.4s ease;
}

/* Password input wrapper */
.password-input-wrapper {
    position: relative;
}

.password-input-wrapper .auth-input {
    padding-right: 48px;
}

/* Password toggle button */
.password-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: background var(--transition-base);
}

.password-toggle:hover {
    background: rgba(0, 112, 173, 0.08);
}

.password-toggle svg {
    width: 20px;
    height: 20px;
    stroke: var(--color-text-muted);
    fill: none;
    transition: stroke var(--transition-base);
}

.password-toggle:hover svg {
    stroke: var(--color-primary);
}

/* === OTP Code Input === */
.otp-container {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: var(--spacing-lg);
}

.otp-input {
    width: 48px;
    height: 56px;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 600;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-white);
    color: var(--color-text-primary);
    transition: all var(--transition-base);
    animation: fadeInUp 0.3s ease-out backwards;
}

.otp-input:nth-child(1) { animation-delay: 0.1s; }
.otp-input:nth-child(2) { animation-delay: 0.15s; }
.otp-input:nth-child(3) { animation-delay: 0.2s; }
.otp-input:nth-child(4) { animation-delay: 0.25s; }
.otp-input:nth-child(5) { animation-delay: 0.3s; }
.otp-input:nth-child(6) { animation-delay: 0.35s; }

.otp-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 112, 173, 0.15);
    transform: scale(1.05);
}

.otp-input.filled {
    border-color: var(--color-success);
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
}

/* === Buttons === */
.btn {
    width: 100%;
    border: none;
    padding: 14px 20px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.95rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:active::after {
    width: 300px;
    height: 300px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-dark) 100%);
    color: var(--color-bg-white);
    box-shadow: 0 4px 12px rgba(118, 184, 82, 0.35);
    animation: fadeInUp 0.4s ease-out 0.4s backwards;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(118, 184, 82, 0.45);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: var(--color-bg-light);
    color: var(--color-text-secondary);
    border: 2px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-border);
    border-color: #d1d5db;
}

.btn-outline {
    background: transparent;
    color: var(--color-primary);
    border: 2px solid var(--color-primary);
}

.btn-outline:hover {
    background: var(--color-primary);
    color: var(--color-bg-white);
}

/* Loading state */
.btn-loading {
    color: transparent;
    pointer-events: none;
}

.btn-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === Links === */
.link {
    font-size: 0.85rem;
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition-base);
    position: relative;
}

.link::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--color-primary);
    transition: width var(--transition-base);
}

.link:hover::after {
    width: 100%;
}

.link:hover {
    color: var(--color-primary-dark);
}

.forgot-password-row {
    text-align: right;
    margin-bottom: 20px;
    margin-top: -8px;
    animation: fadeIn 0.4s ease-out 0.35s backwards;
}

/* === Alerts === */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-md);
    font-size: 0.9rem;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    animation: fadeInDown 0.3s ease-out;
}

.alert-success {
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
    border: 1px solid #a7f3d0;
    color: var(--color-success);
}

.alert-error {
    background: var(--color-error-bg);
    border: 1px solid var(--color-error-border);
    color: var(--color-error);
    animation: shake 0.4s ease;
}

.alert-info {
    background: var(--color-info-bg);
    border: 1px solid var(--color-info-border);
    color: var(--color-info);
}

.alert-warning {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: var(--color-warning);
}

/* Alert icons */
.alert-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* === Validation === */
.text-danger {
    color: var(--color-error);
    display: block;
    margin-top: 6px;
    font-size: 0.8rem;
    animation: fadeIn 0.2s ease-out;
}

.error-text {
    text-align: center;
    font-size: 0.85rem;
    color: var(--color-error);
    margin-bottom: var(--spacing-md);
    animation: shake 0.4s ease;
}

/* === Email Pill === */
.email-pill {
    display: block;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    background: var(--color-bg-light);
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
    word-break: break-all;
    margin-bottom: var(--spacing-md);
    animation: fadeIn 0.3s ease-out 0.2s backwards;
    transition: background var(--transition-base);
}

.email-pill:hover {
    background: var(--color-border);
}

/* === Step Indicator === */
.step-indicator {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
    animation: fadeIn 0.4s ease-out 0.1s backwards;
}

.step {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all var(--transition-base);
}

.step.completed {
    background: var(--color-success);
    color: var(--color-bg-white);
    animation: successPop 0.4s ease-out;
}

.step.active {
    background: var(--color-primary);
    color: var(--color-bg-white);
    box-shadow: 0 0 0 4px rgba(0, 112, 173, 0.2);
    animation: pulse 2s infinite;
}

.step.pending {
    background: var(--color-border);
    color: var(--color-text-light);
}

.step-line {
    width: 30px;
    height: 2px;
    background: var(--color-border);
    align-self: center;
    transition: background var(--transition-base);
}

.step-line.completed {
    background: var(--color-success);
}

/* === Success Icon === */
.icon-success {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px auto;
    background: linear-gradient(135deg, var(--color-success) 0%, var(--color-success-light) 100%);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: successPop 0.5s ease-out;
    box-shadow: 0 4px 20px rgba(5, 150, 105, 0.3);
}

.icon-success svg {
    width: 32px;
    height: 32px;
    stroke: var(--color-bg-white);
    fill: none;
    stroke-width: 2.5;
}

.icon-success svg path {
    stroke-dasharray: 50;
    animation: checkmark 0.5s ease-out 0.3s forwards;
}

/* === Footer === */
.auth-footer {
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--radius-md);
    margin: var(--spacing-md) 0 0 0;
    padding: 14px 20px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    animation: fadeInUp 0.4s ease-out 0.5s backwards;
    backdrop-filter: blur(10px);
}

.auth-footer a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 600;
    transition: color var(--transition-base);
}

.auth-footer a:hover {
    color: var(--color-primary-dark);
    text-decoration: underline;
}

/* === Legal Links === */
.legal-links {
    text-align: center;
    margin-top: var(--spacing-md);
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.7);
    animation: fadeIn 0.4s ease-out 0.6s backwards;
}

.legal-links a {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    margin: 0 6px;
    transition: color var(--transition-base);
}

.legal-links a:hover {
    color: var(--color-bg-white);
    text-decoration: underline;
}

/* === Info Text === */
.info-text {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    line-height: 1.6;
    margin: 0 0 20px 0;
    text-align: center;
}

/* === Legal Consent === */
.legal-consent {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-align: left;
    line-height: 1.5;
    margin: 16px 0 16px 0;
}

.legal-consent a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
}

.legal-consent a:hover {
    text-decoration: underline;
    color: var(--color-primary-dark);
}

.verify-text {
    font-size: 0.9rem;
    line-height: 1.5;
    margin: 0 0 20px 0;
    color: var(--color-text-muted);
    text-align: center;
}

/* === Resend Link === */
.resend-container {
    text-align: center;
    margin-top: var(--spacing-md);
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.resend-link {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
    transition: color var(--transition-base);
}

.resend-link:hover {
    color: var(--color-primary-dark);
    text-decoration: underline;
}

.resend-link.disabled {
    color: var(--color-text-light);
    cursor: not-allowed;
    pointer-events: none;
}

.countdown {
    font-weight: 600;
    color: var(--color-primary);
}

/* === Utility Classes === */
.visually-hidden {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

/* === Social Login === */
.social-divider {
    display: flex;
    align-items: center;
    margin: 20px 0;
    gap: 12px;
    animation: fadeIn 0.4s ease-out 0.45s backwards;
}

.social-divider::before,
.social-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-border);
}

.social-divider span {
    font-size: 0.8rem;
    color: var(--color-text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.social-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: fadeInUp 0.4s ease-out 0.5s backwards;
}

.social-buttons form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-social {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition-base);
    border: 2px solid var(--color-border);
    background: var(--color-bg-white);
    color: var(--color-text-secondary);
}

.btn-social:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-social:active {
    transform: translateY(0);
}

.social-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.btn-google:hover {
    border-color: #4285F4;
    background: #f8faff;
}

.btn-apple {
    background: var(--color-text-primary);
    color: var(--color-bg-white);
    border-color: var(--color-text-primary);
}

.btn-apple:hover {
    background: #000;
    border-color: #000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn-apple .social-icon {
    fill: currentColor;
}

.text-center {
    text-align: center;
}

.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }

/* === Error Page === */
.error-page {
    text-align: center;
    padding: var(--spacing-lg) 0;
}

.error-icon {
    width: 56px;
    height: 56px;
    color: var(--color-error);
    margin-bottom: var(--spacing-md);
}

/* === Responsive === */
@media (max-width: 600px) {
    .auth-page {
        padding: var(--spacing-md);
    }
    
    .logo-container {
        margin: 20px 0 16px 0;
    }
    
    .auth-logo {
        width: 180px;
    }
    
    .auth-card {
        padding: 24px 20px;
        border-radius: var(--radius-lg);
    }
    
    .otp-input {
        width: 42px;
        height: 50px;
        font-size: 1.25rem;
    }
    
    .otp-container {
        gap: 6px;
    }
}

@media (max-width: 380px) {
    .otp-input {
        width: 38px;
        height: 46px;
        font-size: 1.1rem;
    }
    
    .otp-container {
        gap: 4px;
    }
}

/* === Focus States for Accessibility === */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .auth-input {
        border-width: 3px;
    }
    
    .btn {
        border: 2px solid currentColor;
    }
}
