* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary-color: #2563eb;
    --primary-dark: #1e3a8a;
    --primary-light: #3b82f6;
    --accent-cyan: #06b6d4;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-light: #94a3b8;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1);
    --gradient-brand: linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #0891b2 100%);
}

body {
    font-family: 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
    overflow-x: hidden;
    overflow-y: auto;
    direction: ltr;
}

body::before {
    content: '';
    position: fixed;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.06) 1px, transparent 1px);
    background-size: 48px 48px;
    animation: moveBackground 60s linear infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes moveBackground {
    0% { transform: translate(0, 0); }
    100% { transform: translate(48px, 48px); }
}

.login-container {
    width: 100%;
    max-width: 1100px;
    background: var(--bg-primary);
    border-radius: 24px;
    box-shadow: var(--shadow-xl), 0 0 0 1px rgba(0,0,0,0.05);
    overflow: hidden;
    display: grid;
    grid-template-columns: 1fr 1fr;
    position: relative;
    z-index: 1;
    animation: slideUp 0.6s ease-out;
    margin: 20px auto;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Visual / Splash ===== */
.login-visual {
    background: var(--gradient-brand);
    padding: 50px 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.login-visual::before {
    content: '';
    position: absolute;
    width: 320px;
    height: 320px;
    background: rgba(255,255,255,0.08);
    border-radius: 50%;
    top: -110px;
    left: -110px;
}

.login-visual::after {
    content: '';
    position: absolute;
    width: 220px;
    height: 220px;
    background: rgba(6,182,212,0.15);
    border-radius: 50%;
    bottom: -60px;
    right: -60px;
}

.visual-image {
    width: 100%;
    max-width: 420px;
    height: 380px;
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 30px;
    position: relative;
    z-index: 1;
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
    border: 2px solid rgba(255,255,255,0.15);
}

.visual-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.visual-text {
    text-align: center;
    color: white;
    position: relative;
    z-index: 1;
}

.visual-text h2 {
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 12px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.visual-text p {
    font-size: 15px;
    opacity: 0.9;
    line-height: 1.6;
    max-width: 360px;
    margin: 0 auto;
}

/* ===== Form Section ===== */
.login-form-section {
    padding: 56px 50px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    max-height: 92vh;
    overflow-y: auto;
}

.login-form-section::-webkit-scrollbar { width: 6px; }
.login-form-section::-webkit-scrollbar-track { background: var(--bg-secondary); }
.login-form-section::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
.login-form-section::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ===== Header (single product logo) ===== */
.company-header {
    text-align: center;
    margin-bottom: 36px;
}

.product-logo-wrapper {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    background: #ffffff;
    border-radius: 16px;
    border: 2px solid var(--primary-color);
    box-shadow: 0 0 0 4px rgba(37,99,235,0.12);
    margin-bottom: 18px;
}

.product-logo-img {
    max-width: 78%;
    max-height: 78%;
    object-fit: contain;
}

.system-title h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
    letter-spacing: -0.3px;
}

.system-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.2px;
}

/* ===== Form Elements ===== */
.form-content { display: none; }
.form-content.active { display: block; animation: fadeIn 0.3s ease-in; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.form-group { margin-bottom: 20px; }

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.input-wrapper { position: relative; }

.form-input {
    width: 100%;
    padding: 14px 16px;
    padding-left: 46px;      /* icon on LEFT for LTR */
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 15px;
    color: var(--text-primary);
    transition: all 0.3s ease;
    background: var(--bg-primary);
    direction: ltr;
    text-align: left;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(37,99,235,0.1);
}

.form-input.error { border-color: var(--error-color); }
.form-input.error:focus { box-shadow: 0 0 0 4px rgba(239,68,68,0.1); }

/* Icon on the LEFT for LTR */
.input-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    pointer-events: none;
}

/* Password toggle on the RIGHT for LTR */
.toggle-password {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    transition: color 0.2s ease;
}
.toggle-password:hover { color: var(--text-secondary); }

/* When password field has toggle, leave space on right too */
#password { padding-right: 46px; }

.error-message {
    display: none;
    font-size: 13px;
    color: var(--error-color);
    margin-top: 6px;
    font-weight: 500;
}
.error-message.show { display: block; animation: shake 0.3s ease; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* ===== Form Options ===== */
.form-options {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.remember-me {
    display: flex;
    align-items: center;
    gap: 8px;
}

.remember-me input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.remember-me label {
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.forgot-link {
    font-size: 14px;
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}
.forgot-link:hover { text-decoration: underline; }

/* ===== Submit Button ===== */
.submit-button {
    width: 100%;
    padding: 15px;
    background: var(--gradient-brand);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 14px rgba(37,99,235,0.35);
    position: relative;
    overflow: hidden;
}

.submit-button::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;
}
.submit-button:hover::before { left: 100%; }

.submit-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(37,99,235,0.45);
}
.submit-button:active { transform: translateY(0); }

.submit-button:disabled {
    background: var(--text-light);
    cursor: not-allowed;
    box-shadow: none;
}

.loading-spinner {
    display: none;
    width: 20px; height: 20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.submit-button.loading .button-text { display: none; }
.submit-button.loading .loading-spinner { display: block; }

/* ===== Two-Factor Section ===== */
.two-factor-header {
    text-align: center;
    margin-bottom: 24px;
}

.two-factor-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    background: rgba(37,99,235,0.1);
    color: var(--primary-color);
    border-radius: 16px;
    margin-bottom: 16px;
}

.two-factor-header h3 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.two-factor-desc {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.masked-email {
    font-weight: 700;
    color: var(--primary-color);
    white-space: nowrap;
}

.otp-input-group {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin: 20px 0;
    direction: ltr;
}

.otp-digit {
    width: 52px;
    height: 58px;
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    transition: all 0.3s ease;
    color: var(--text-primary);
}
.otp-digit:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(37,99,235,0.1);
}

.otp-timer {
    text-align: center;
    margin: 15px 0;
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.timer-value {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 16px;
}
.timer-value.warning { color: var(--warning-color); }
.timer-value.expired { color: var(--error-color); }

.two-factor-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-top: 20px;
}

.resend-otp {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    transition: color 0.2s ease;
}
.resend-otp:hover:not(:disabled) { color: var(--primary-dark); }
.resend-otp:disabled {
    color: var(--text-light);
    cursor: not-allowed;
    text-decoration: none;
}

.back-to-login {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s ease;
}
.back-to-login:hover { color: var(--primary-color); }

/* ===== Footer ===== */
.login-footer {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}
.version-info {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 8px;
}
.support-info {
    font-size: 13px;
    color: var(--text-secondary);
}
.support-info a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}
.support-info a:hover { text-decoration: underline; }

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 500;
    display: none;
    animation: slideDown 0.3s ease;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
.alert.show { display: flex; align-items: center; gap: 10px; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #10b981; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #ef4444; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #f59e0b; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #3b82f6; }

/* ===== CAPTCHA ===== */
.captcha-container {
    margin: 20px 0;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 2px solid var(--border-color);
}
.captcha-header { margin-bottom: 12px; }
.captcha-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.captcha-instruction { font-size: 12px; color: var(--text-secondary); }
.captcha-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-items: center;
}
.captcha-canvas-wrapper { position: relative; }
.captcha-canvas {
    width: 100%;
    height: 80px;
    background: white;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    position: relative;
    overflow: hidden;
}
.captcha-canvas canvas { width: 100%; height: 100%; display: block; }
.captcha-refresh {
    position: absolute;
    bottom: 6px; right: 6px;
    background: rgba(255,255,255,0.95);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}
.captcha-refresh:hover {
    background: white;
    transform: rotate(180deg);
    box-shadow: var(--shadow-md);
}
.captcha-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.captcha-input {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 18px;
    text-align: center;
    font-weight: 600;
    letter-spacing: 4px;
    transition: all 0.3s ease;
    text-transform: uppercase;
}
.captcha-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(37,99,235,0.1);
}
.captcha-input.error { border-color: var(--error-color); }
.captcha-hint { font-size: 11px; color: var(--text-light); text-align: center; }

/* ===== Responsive ===== */
@media (max-width: 968px) {
    .login-container { grid-template-columns: 1fr; }
    .login-visual { display: none; }
    .login-form-section { padding: 40px 30px; max-height: none; }
}

@media (max-width: 480px) {
    body { padding: 10px; }
    .login-form-section { padding: 30px 20px; }
    .company-header { margin-bottom: 28px; }
    .otp-digit { width: 44px; height: 52px; font-size: 20px; }
    .captcha-content { grid-template-columns: 1fr; }
    .captcha-canvas { height: 70px; }
    .form-options { flex-direction: column; align-items: flex-start; gap: 12px; }
}

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

@media (prefers-contrast: high) {
    .form-input, .otp-digit { border-width: 3px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}