/* CSS Variables */
:root {
    --gradient-primary: linear-gradient(135deg, #ff5100e5 0%, #ffcfb877 100%);
    --gradient-secondary: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --gradient-tertiary: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --glass-background: rgba(255, 255, 255, 0.25);
    --glass-border: rgba(255, 255, 255, 0.18);
    --text-primary: #2d3748;
    --text-secondary: #4a5568;
    --color-primary: #667eea;
    --color-success: #48bb78;
    --color-danger: #f56565;
    --color-info: #4299e1;
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 25px 80px rgba(0, 0, 0, 0.4);
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gradient-primary);
    min-height: 100vh;
    overflow: hidden;
    position: relative;
}

/* Animated Background */
.background-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    overflow: hidden;
}

.floating-shapes {
    position: absolute;
    width: 100%;
    height: 100%;
}

.shape {
    position: absolute;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    animation: float 6s ease-in-out infinite;
    backdrop-filter: blur(10px);
}

.shape:nth-child(1) {
    width: 80px;
    height: 80px;
    top: 20%;
    left: 10%;
    animation-delay: 0s;
    animation-duration: 8s;
}

.shape:nth-child(2) {
    width: 120px;
    height: 120px;
    top: 60%;
    left: 80%;
    animation-delay: 2s;
    animation-duration: 10s;
}

.shape:nth-child(3) {
    width: 60px;
    height: 60px;
    top: 80%;
    left: 20%;
    animation-delay: 4s;
    animation-duration: 7s;
}

.shape:nth-child(4) {
    width: 100px;
    height: 100px;
    top: 10%;
    left: 70%;
    animation-delay: 1s;
    animation-duration: 9s;
}

.shape:nth-child(5) {
    width: 40px;
    height: 40px;
    top: 40%;
    left: 5%;
    animation-delay: 3s;
    animation-duration: 6s;
}

/* Tech Device Particles */
.tech-particles {
    position: absolute;
    width: 100%;
    height: 100%;
}

.tech-device {
    position: absolute;
    animation: device-float 8s linear infinite;
    opacity: 0.4;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

.tech-device svg {
    width: 100%;
    height: 100%;
    fill: rgba(255, 255, 255, 0.8);
}

/* Main Container */
.login-wrapper {
    position: relative;
    z-index: 10;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.login-container {
    background: var(--glass-background);
    backdrop-filter: blur(10px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 3rem;
    width: 100%;
    max-width: 450px;
    box-shadow: var(--shadow-xl);
    transform: translateY(50px);
    opacity: 0;
    animation: slideInUp 1s cubic-bezier(0.4, 0, 0.2, 1) 0.5s forwards;
    position: relative;
    overflow: hidden;
}

.login-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    animation: shimmer 3s ease-in-out infinite;
}

/* Logo Animation */
.logo {
    text-align: center;
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0;
    transform: scale(0.5) rotate(-180deg);
    animation: logoReveal 1.2s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.8s forwards;
    position: relative;
}

.logo::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 120px;
    height: 120px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    animation: pulse-ring 2s ease-in-out infinite 1.5s;
}

/* Title Animation */
.title {
    text-align: center;
    color: #ff5100e5;
    font-size: 1.6rem;
    font-weight: 800;
    margin-bottom: 2rem;
    opacity: 50;
    letter-spacing: 0.1em;
}

.title-char {
    display: inline-block;
    animation: typeIn 1.5s ease-out forwards;
    opacity: 0;
}

/* Flash Messages */
.flash-messages {
    margin-bottom: 1.5rem;
}

.flash-message {
    padding: 1rem 1.25rem;
    border-radius: 16px;
    margin-bottom: 0.75rem;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation: slideInDown 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.flash-error {
    background: rgba(245, 101, 101, 0.2);
    color: #fed7d7;
    border-left: 4px solid var(--color-danger);
}

.flash-success {
    background: rgba(72, 187, 120, 0.2);
    color: #c6f6d5;
    border-left: 4px solid var(--color-success);
}

.flash-info {
    background: rgba(66, 153, 225, 0.2);
    color: #bee3f8;
    border-left: 4px solid var(--color-info);
}

/* Form Styling */
.login-form {
    opacity: 0;
    animation: fadeInUp 0.8s ease-out 1.2s forwards;
}

.form-group {
    margin-bottom: 1.5rem;
    position: relative;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

.form-input {
    width: 100%;
    padding: 1rem 1.25rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    font-size: 1rem;
    color: white;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
}

.form-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.form-input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.form-input:focus + .form-label {
    color: white;
    transform: translateY(-2px);
}

/* Checkbox Group */
.checkbox-group {
    display: flex;
    align-items: center;
    margin-bottom: 2rem;
    gap: 0.75rem;
}

.checkbox-input {
    width: 20px;
    height: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    position: relative;
    cursor: pointer;
    transition: all 0.3s ease;
}

.checkbox-input:checked {
    background: var(--color-primary);
    border-color: var(--color-primary);
    transform: scale(1.1);
}

.checkbox-input:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 0.8rem;
    font-weight: bold;
}

.checkbox-label {
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

/* Authentication Toggle */
.auth-toggle {
    display: flex;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    padding: 0.5rem;
    margin-bottom: 2rem;
    gap: 0.5rem;
    opacity: 0;
    animation: fadeInUp 0.8s ease-out 1.0s forwards;
}

.toggle-option {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem 0.75rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    background: transparent;
    border: 1px solid transparent;
}

.toggle-option.active {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.toggle-option:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
}

.toggle-icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    transition: transform 0.3s ease;
}

.toggle-option.active .toggle-icon {
    transform: scale(1.1);
}

.toggle-option span {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    font-weight: 600;
    transition: color 0.3s ease;
}

.toggle-option.active span {
    color: rgba(255, 255, 255, 1);
}

/* FIDO2 Form Styles */
.fido2-form {
    opacity: 0;
    animation: fadeInUp 0.8s ease-out 1.2s forwards;
}

.fido2-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    margin-bottom: 1.5rem;
    transition: all 0.3s ease;
}

.status-icon {
    font-size: 1.8rem;
    transition: transform 0.3s ease;
}

.status-icon.spinning {
    animation: spin 1s linear infinite;
}

.status-text {
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
    text-align: center;
}

.fido2-error {
    background: rgba(245, 101, 101, 0.2);
    border: 2px solid rgba(245, 101, 101, 0.5);
    border-radius: 12px;
    padding: 1rem;
    margin-top: 1rem;
    color: #fed7d7;
    text-align: center;
    font-weight: 500;
}

.fido2-error.error-animation {
    animation: shake 0.3s ease-in-out;
}

/* Login Button */
.login-btn {
    width: 100%;
    padding: 1.25rem;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.1));
    backdrop-filter: blur(20px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 16px;
    color: white;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.fido2-btn {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.3), rgba(118, 75, 162, 0.2));
    border-color: rgba(102, 126, 234, 0.4);
}

.fido2-btn:hover {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.4), rgba(118, 75, 162, 0.3));
    border-color: rgba(102, 126, 234, 0.6);
}

.btn-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
}

.login-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s ease;
}

.login-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.15));
}

.login-btn:hover::before {
    left: 100%;
}

.login-btn:active {
    transform: translateY(-1px);
}

/* Demo Info */
.demo-info {
    margin-top: 2rem;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    text-align: center;
    opacity: 0;
    animation: fadeIn 0.8s ease-out 1.8s forwards;
}

.demo-info strong {
    color: rgba(255, 255, 255, 0.95);
    font-size: 1rem;
    display: block;
    margin-bottom: 0.5rem;
}

.demo-credentials {
    color: rgba(255, 255, 255, 0.8);
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 1.1rem;
    font-weight: 600;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.75rem;
    border-radius: 12px;
    letter-spacing: 0.05em;
}

/* Animations */
@keyframes float {
    0%, 100% { transform: translateY(0px) rotate(0deg); }
    33% { transform: translateY(-20px) rotate(120deg); }
    66% { transform: translateY(10px) rotate(240deg); }
}

@keyframes device-float {
    0% {
        transform: translateY(100vh) translateX(0) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 0.6;
    }
    90% {
        opacity: 0.6;
    }
    100% {
        transform: translateY(-100px) translateX(100px) rotate(360deg);
        opacity: 0;
    }
}

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

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes logoReveal {
    0% {
        opacity: 0;
        transform: scale(0.5) rotate(-180deg);
    }
    50% {
        opacity: 1;
        transform: scale(1.2) rotate(0deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

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

@keyframes pulse-ring {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.4);
        opacity: 0;
    }
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-5px);
    }
    75% {
        transform: translateX(5px);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .login-container {
        padding: 2rem;
        margin: 1rem;
        max-width: none;
    }
    
    .logo {
        font-size: 3rem;
    }
    
    .title {
        font-size: 1.5rem;
    }

    .auth-toggle {
        flex-direction: column;
        gap: 0.25rem;
    }

    .toggle-option {
        flex-direction: row;
        justify-content: center;
        padding: 0.75rem;
    }

    .toggle-icon {
        margin-bottom: 0;
        margin-right: 0.5rem;
        font-size: 1.25rem;
    }

    .fido2-status {
        flex-direction: column;
        gap: 0.75rem;
        padding: 1.25rem;
    }

    .status-text {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .login-wrapper {
        padding: 1rem;
    }
    
    .login-container {
        padding: 1.5rem;
    }
    
    .logo {
        font-size: 2.5rem;
    }

    .auth-toggle {
        padding: 0.25rem;
        margin-bottom: 1.5rem;
    }

    .toggle-option {
        padding: 0.5rem;
    }

    .toggle-option span {
        font-size: 0.8rem;
    }

    .toggle-icon {
        font-size: 1.1rem;
        margin-right: 0.25rem;
    }

    .fido2-status {
        padding: 1rem;
        gap: 0.5rem;
    }

    .status-icon {
        font-size: 1.5rem;
    }

    .status-text {
        font-size: 0.85rem;
    }

    .login-btn {
        padding: 1rem;
        font-size: 1rem;
    }

    .btn-spinner {
        width: 18px;
        height: 18px;
    }
}

/* ========================================
   FLASH MESSAGES & ALERTS
======================================== */
.flash-messages {
  margin-bottom: 20px;
}

.flash-success {
  background: var(--auto-color-3);
  color: var(--auto-color-4);
  padding: 12px 20px;
  border-radius: 5px;
  border-left: 4px solid var(--auto-color-68);
  margin-bottom: 10px;
}

.flash-error {
  background: var(--auto-color-1);
  color: var(--auto-color-2);
  padding: 12px 20px;
  border-radius: 5px;
  border-left: 4px solid var(--auto-color-57);
  margin-bottom: 10px;
}

.flash-warning {
  background: var(--auto-color-5);
  color: var(--auto-color-6);
  padding: 12px 20px;
  border-radius: 5px;
  border-left: 4px solid var(--auto-color-70);
  margin-bottom: 10px;
}

.flash-info {
  background: var(--auto-color-86);
  color: var(--auto-color-88);
  padding: 12px 20px;
  border-radius: 5px;
  border-left: 4px solid var(--auto-color-72);
  margin-bottom: 10px;
}

/* Login Success Animation */
@keyframes slideDownOut {
    0% {
        transform: translateY(0);
        opacity: 1;
        filter: blur(0px);
    }
    50% {
        opacity: 0.8;
        filter: blur(1px);
    }
    100% {
        transform: translateY(100vh);
        opacity: 0;
        filter: blur(3px);
    }
}

@keyframes backgroundFadeOut {
    0% {
        opacity: 1;
        filter: blur(0px);
    }
    50% {
        opacity: 0.6;
        filter: blur(2px);
    }
    100% {
        opacity: 0;
        filter: blur(5px);
        transform: scale(1.1);
    }
}

@keyframes successGlow {
    0% {
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    }
    50% {
        box-shadow: 0 20px 60px rgba(16, 185, 129, 0.4), 
                    0 0 40px rgba(16, 185, 129, 0.3);
    }
    100% {
        box-shadow: 0 20px 60px rgba(16, 185, 129, 0.2), 
                    0 0 20px rgba(16, 185, 129, 0.2);
    }
}

/* Success Animation Classes */
.login-wrapper.login-success {
    animation: slideDownOut 1.2s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
    z-index: 1000;
}

.login-wrapper.login-success .login-container {
    animation: successGlow 0.6s ease-out;
    border: 2px solid rgba(16, 185, 129, 0.3);
    background: linear-gradient(135deg, 
        rgba(255, 255, 255, 0.35) 0%, 
        rgba(255, 255, 255, 0.25) 100%);
}

.background-animation.background-success {
    animation: backgroundFadeOut 1.2s ease-out forwards;
}

/* Synchronize body background color at end of login animation */
.login-success body {
    animation: transitionToDashboardBg 1.2s ease-out forwards;
}

@keyframes transitionToDashboardBg {
    0% {
        background: var(--gradient-primary); /* Login orange gradient */
    }
    50% {
        background: linear-gradient(135deg, #ff8a50 0%, #f0f0f0 100%); /* Transition blend */
    }
    100% {
        background: #f8f9fa; /* Dashboard light gray */
    }
}

/* Success state for elements */
.login-success .title {
    color: #059669;
    text-shadow: 0 0 20px rgba(16, 185, 129, 0.5);
}

.login-success .logo {
    transform: scale(1.1);
    filter: drop-shadow(0 0 10px rgba(16, 185, 129, 0.6));
    transition: all 0.3s ease;
}

/* Ensure smooth animations */
.login-wrapper {
    transition: transform 0.3s ease, opacity 0.3s ease;
    will-change: transform, opacity;
}

.background-animation {
    transition: opacity 0.3s ease, filter 0.3s ease;
    will-change: opacity, filter, transform;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    @keyframes slideDownOut {
        0% {
            transform: translateY(0);
            opacity: 1;
        }
        100% {
            transform: translateY(150vh);
            opacity: 0;
        }
    }
    
    .login-wrapper.login-success {
        animation-duration: 1s;
    }
}

/* ================================================
   LOGIN SLIDE-IN ANIMATIONS (After Logout)
   ================================================ */

/* Login slides in from top (reverse of dashboard slide-in) */
@keyframes slideInFromTopLogin {
    0% {
        transform: translateY(-100vh);
        opacity: 0;
        filter: blur(3px);
    }
    50% {
        opacity: 0.8;
        filter: blur(1px);
    }
    100% {
        transform: translateY(0);
        opacity: 1;
        filter: blur(0px);
    }
}

@keyframes backgroundFadeInLogin {
    0% {
        opacity: 0;
        filter: blur(5px);
        transform: scale(1.1);
    }
    50% {
        opacity: 0.6;
        filter: blur(2px);
    }
    100% {
        opacity: 1;
        filter: blur(0px);
        transform: scale(1);
    }
}

@keyframes transitionFromDashboardBg {
    0% {
        background: #f8f9fa; /* Dashboard light gray - start from dashboard color */
    }
    50% {
        background: linear-gradient(135deg, #ff8a50 0%, #f0f0f0 100%); /* Smooth transition blend */
    }
    100% {
        background: var(--gradient-primary); /* Login orange gradient - end with login color */
    }
}

/* Login entering animation classes */
.login-wrapper.login-entering {
    transform: translateY(-100vh);
    opacity: 0;
    filter: blur(3px);
}

.login-wrapper.login-enter-active {
    animation: slideInFromTopLogin 1.2s cubic-bezier(0.23, 1, 0.320, 1) forwards;
}

.background-animation.background-entering {
    opacity: 0;
    filter: blur(5px);
    transform: scale(1.1);
}

.background-animation.background-enter-active {
    animation: backgroundFadeInLogin 1.2s ease-out forwards;
}

body.login-entering-bg {
    animation: transitionFromDashboardBg 1.2s ease-out forwards;
}

/* Add orange glow during login slide-in */
.login-enter-active .login-container {
    animation: loginSlideInGlow 0.8s ease-out 0.4s;
}

@keyframes loginSlideInGlow {
    0% {
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    }
    50% {
        box-shadow: 0 20px 60px rgba(255, 81, 0, 0.4), 
                    0 0 40px rgba(255, 81, 0, 0.3);
    }
    100% {
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    }
}