/* ========== CSS Reset & Base ========== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2962FF;
    --primary-dark: #0039CB;
    --primary-light: #768FFF;
    --accent: #00BFA5;
    --accent-light: #5DF2D6;
    --bg-white: #FFFFFF;
    --bg-light: #F5F7FA;
    --bg-card: #FFFFFF;
    --text-primary: #1A1A2E;
    --text-secondary: #6B7280;
    --text-muted: #9CA3AF;
    --border-color: #E5E7EB;
    --border-focus: #2962FF;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 16px rgba(41,98,255,0.10);
    --shadow-lg: 0 10px 40px rgba(41,98,255,0.12);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-light);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========== Background Decoration ========== */
.bg-decoration {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.bg-decoration::before {
    content: '';
    position: absolute;
    top: -30%;
    right: -20%;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(41,98,255,0.06) 0%, transparent 70%);
    border-radius: 50%;
    animation: float 8s ease-in-out infinite;
}

.bg-decoration::after {
    content: '';
    position: absolute;
    bottom: -20%;
    left: -15%;
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(0,191,165,0.05) 0%, transparent 70%);
    border-radius: 50%;
    animation: float 10s ease-in-out infinite reverse;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(20px, -30px); }
}

/* ========== Login Container ========== */
.login-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    padding: 20px;
    animation: fadeInUp 0.6s ease-out;
}

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

/* ========== Logo Section ========== */
.logo-section {
    text-align: center;
    margin-bottom: 32px;
}

.logo-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.logo-icon {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-md);
    object-fit: contain;
    filter: drop-shadow(0 2px 8px rgba(41,98,255,0.15));
    transition: var(--transition);
}

.logo-icon:hover {
    transform: scale(1.05);
}

.logo-text {
    font-size: 28px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.logo-tagline {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.3px;
}

/* ========== Card ========== */
.login-card {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    padding: 32px 24px;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(229, 231, 235, 0.6);
    backdrop-filter: blur(10px);
}

.login-card-header {
    margin-bottom: 28px;
}

.login-card-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.login-card-header p {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ========== Form Elements ========== */
.form-group {
    margin-bottom: 20px;
    position: relative;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: 0.2px;
}

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

.input-icon {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    font-size: 16px;
    z-index: 2;
    transition: var(--transition);
}

.form-input {
    width: 100%;
    padding: 14px 14px 14px 44px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 15px;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-white);
    transition: var(--transition);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

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

.form-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(41,98,255,0.10);
}

.form-input:focus ~ .input-icon,
.form-input:focus + .input-icon {
    color: var(--primary);
}

.input-wrapper:focus-within .input-icon {
    color: var(--primary);
}

/* Password Toggle */
.password-toggle {
    position: absolute;
    right: 14px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    z-index: 2;
    transition: var(--transition);
}

.password-toggle:hover {
    color: var(--primary);
}

/* ========== CAPTCHA Section ========== */
.captcha-section {
    margin-bottom: 24px;
}

.captcha-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: 0.2px;
}

.captcha-box {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.captcha-display {
    width: 100%;
    min-height: 56px;
    background: linear-gradient(135deg, #f0f4ff 0%, #e8f5e9 50%, #fff8e1 100%);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

/* Captcha noise lines */
.captcha-display::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 8px,
        rgba(0,0,0,0.03) 8px,
        rgba(0,0,0,0.03) 9px
    );
}

.captcha-display::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        -30deg,
        transparent,
        transparent 12px,
        rgba(41,98,255,0.04) 12px,
        rgba(41,98,255,0.04) 13px
    );
}

.captcha-numbers {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 14px;
    position: relative;
    z-index: 1;
}

.captcha-digit {
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 2px;
    color: var(--text-primary);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.08);
}

.captcha-digit:nth-child(1) {
    color: #2962FF;
    transform: rotate(-3deg);
}
.captcha-digit:nth-child(2) {
    color: #D32F2F;
    transform: rotate(2deg) translateX(2px);
}
.captcha-digit:nth-child(3) {
    color: #00796B;
    transform: rotate(-1deg) translateX(-1px);
}
.captcha-digit:nth-child(4) {
    color: #F57C00;
    transform: rotate(3deg);
}

.captcha-input-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.captcha-input {
    width: 100%;
    padding: 14px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 15px;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-white);
    text-align: center;
    letter-spacing: 6px;
    transition: var(--transition);
    outline: none;
    -webkit-appearance: none;
}

.captcha-input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 1px;
}

.captcha-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(41,98,255,0.10);
}

.captcha-refresh {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    padding: 2px 0;
    transition: var(--transition);
    align-self: flex-end;
}

.captcha-refresh i {
    font-size: 11px;
    transition: transform 0.4s ease;
}

.captcha-refresh:hover i {
    transform: rotate(180deg);
}

.captcha-refresh:hover {
    color: var(--primary-dark);
}

/* ========== Submit Button ========== */
.btn-login {
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    color: #FFFFFF;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    letter-spacing: 0.3px;
    -webkit-appearance: none;
}

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

.btn-login:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(41,98,255,0.30);
}

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

.btn-login:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

.btn-login:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.btn-login .spinner {
    display: none;
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 0 auto;
}

.btn-login.loading .btn-text { display: none; }
.btn-login.loading .spinner { display: inline-block; }

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

/* ========== Forgot Password ========== */
.forgot-password {
    text-align: right;
    margin-bottom: 24px;
    margin-top: -8px;
}

.forgot-password a {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}

.forgot-password a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

/* ========== Register Link ========== */
.register-link {
    text-align: center;
    margin-top: 24px;
    font-size: 14px;
    color: var(--text-secondary);
}

.register-link a {
    color: var(--primary);
    font-weight: 700;
    text-decoration: none;
    transition: var(--transition);
}

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

/* ========== Footer ========== */
.login-footer {
    text-align: center;
    margin-top: 28px;
    animation: fadeInUp 0.8s ease-out 0.2s both;
}

.login-footer p {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.5;
}

.login-footer .secure-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 8px;
}

.login-footer .secure-badge i {
    font-size: 13px;
}

/* ========== Error Message ========== */
.error-message {
    display: none;
    background: #FEF2F2;
    border: 1px solid #FECACA;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: 13px;
    color: #DC2626;
    font-weight: 500;
    align-items: center;
    gap: 8px;
}

.error-message.show {
    display: flex;
}

.error-message i {
    font-size: 14px;
    flex-shrink: 0;
}

/* ========== Success Message ========== */
.success-message {
    display: none;
    background: #F0FDF4;
    border: 1px solid #BBF7D0;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: 13px;
    color: #16A34A;
    font-weight: 500;
    align-items: center;
    gap: 8px;
}

.success-message.show {
    display: flex;
}

/* ========== Responsive ========== */
@media (max-width: 480px) {
    .login-container {
        padding: 16px;
        max-width: 100%;
    }

    .login-card {
        padding: 28px 20px;
        border-radius: var(--radius-lg);
    }

    .logo-text {
        font-size: 24px;
    }

    .logo-icon {
        width: 44px;
        height: 44px;
    }
}

@media (max-width: 360px) {
    .captcha-numbers {
        gap: 10px;
    }
}

/* Safe area for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

/* ========== Input validation states ========== */
.form-input.error,
.captcha-input.error {
    border-color: #EF4444;
    box-shadow: 0 0 0 3px rgba(239,68,68,0.08);
}

.form-input.success {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0,191,165,0.08);
}

/* ========== Shake animation for errors ========== */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

.shake {
    animation: shake 0.5s ease;
}

/* ========== Flash Message (Server-side) ========== */
.flash-message {
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 500;
    animation: fadeInUp 0.4s ease-out;
}

.flash-message.alert-danger {
    background: #FEF2F2;
    border: 1px solid #FECACA;
    color: #DC2626;
}

.flash-message.alert-success {
    background: #F0FDF4;
    border: 1px solid #BBF7D0;
    color: #16A34A;
}

.flash-message i {
    font-size: 14px;
    flex-shrink: 0;
}

/* ========== Hide Scrollbar Globally ========== */
::-webkit-scrollbar {
    width: 0px;
    background: transparent;
    display: none;
}
* {
    -ms-overflow-style: none;
    scrollbar-width: none;
}
