:root {
    --primary: #10b981;
    --primary-light: #34d399;
    --primary-dark: #059669;
    --accent: #3b82f6;
    --bg-main: #f1f5f9;
    --glass-bg: rgba(255, 255, 255, 0.82);
    --glass-border: rgba(226, 232, 240, 0.5);
    --text-main: #0f172a;
    --text-muted: #64748b;
    --error: #ef4444;
    --border-color: #e2e8f0;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Cairo', sans-serif;
}

html {
    overflow-x: hidden;
    width: 100%;
}

body {
    background: var(--bg-main);
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-main);
    overflow-x: hidden;
    overflow-y: auto;
    position: relative;
    -webkit-font-smoothing: antialiased;
}

/* Page login - fond tradition irakien / Babylone */
body.login-page {
    background: linear-gradient(135deg, rgba(139, 90, 43, 0.15) 0%, rgba(30, 64, 98, 0.12) 50%, rgba(180, 140, 80, 0.1) 100%),
                url('/assets/login-bg-iraq.png') center center / cover no-repeat;
    background-attachment: fixed;
}
body.login-page::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(241, 245, 249, 0.55);
    z-index: 0;
    pointer-events: none;
}
body.login-page .login-container {
    position: relative;
    z-index: 2;
}
[data-theme="dark"] body.login-page::before {
    background: rgba(15, 23, 42, 0.75);
}
html[dir="rtl"] body { direction: rtl; }
html[dir="ltr"] body { direction: ltr; }

.shape {
    position: absolute;
    filter: blur(100px);
    z-index: 1;
    border-radius: 50%;
    animation: float 25s infinite alternate;
    opacity: 0.7;
}

.shape-1 {
    width: 500px;
    height: 500px;
    background: rgba(16, 185, 129, 0.12);
    top: -150px;
    right: -100px;
}

.shape-2 {
    width: 350px;
    height: 350px;
    background: rgba(59, 130, 246, 0.08);
    bottom: -80px;
    left: -80px;
    animation-delay: -8s;
}

.shape-3 {
    width: 250px;
    height: 250px;
    background: rgba(139, 92, 246, 0.06);
    bottom: 30%;
    right: 30%;
    animation-delay: -15s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(-40px, 40px) scale(1.05); }
}

.login-container {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 420px;
    padding: 20px;
    margin: 0 auto;
}

.glass-panel {
    position: relative;
    z-index: 2;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 40px 32px;
    box-shadow:
        0 20px 50px -12px rgba(0, 0, 0, 0.08),
        0 0 0 1px rgba(255, 255, 255, 0.5) inset;
    transition: transform 0.4s ease, box-shadow 0.4s ease;
}

.glass-panel:hover {
    transform: translateY(-4px);
    box-shadow:
        0 28px 60px -12px rgba(0, 0, 0, 0.12),
        0 0 0 1px rgba(255, 255, 255, 0.5) inset;
}

.env-status {
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 20px;
    font-size: 0.9rem;
    line-height: 1.4;
    overflow-wrap: break-word;
    min-width: 0;
}
.env-status.env-ok {
    background: rgba(16, 185, 129, 0.15);
    color: var(--primary-dark);
    border: 1px solid rgba(16, 185, 129, 0.3);
}
.env-status.env-error {
    background: rgba(239, 68, 68, 0.12);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.env-status .env-url {
    font-size: 0.8rem;
    opacity: 0.85;
    margin-top: 6px;
    word-break: break-all;
    overflow-wrap: break-word;
}

/* État chargement vérification serveur */
.env-status-loading {
    display: flex !important;
    align-items: center;
    gap: 10px;
    background: rgba(59, 130, 246, 0.12);
    color: var(--accent);
    border: 1px solid rgba(59, 130, 246, 0.3);
}
.env-status-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(59, 130, 246, 0.3);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: env-spin 0.8s linear infinite;
}
@keyframes env-spin {
    to { transform: rotate(360deg); }
}

/* Formulaire désactivé tant que connexion non vérifiée */
.login-form-pending {
    pointer-events: none;
    opacity: 0.65;
}
.login-form-pending .submit-btn {
    cursor: not-allowed;
}

.logo-section {
    text-align: center;
    margin-bottom: 32px;
}

.logo-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary-light), var(--primary-dark));
    border-radius: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto 14px;
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.3);
    position: relative;
    overflow: hidden;
}

.logo-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 40%, rgba(255,255,255,0.2) 50%, transparent 60%);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%) rotate(-45deg); }
    30%, 100% { transform: translateX(100%) rotate(-45deg); }
}

.logo-icon .logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 16px;
    position: relative;
    z-index: 1;
}

.medical-cross {
    width: 30px;
    height: 30px;
    fill: white;
}

.logo-section h1 {
    font-size: 1.4rem;
    font-weight: 800;
    margin-bottom: 4px;
    color: var(--text-main);
}

.logo-section p {
    font-size: 0.88rem;
    color: var(--text-muted);
    font-weight: 500;
}

.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-muted);
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 14px;
    width: 20px;
    height: 20px;
    fill: #94a3b8;
    transition: fill 0.2s ease;
    pointer-events: none;
}
html[dir="rtl"] .input-icon { left: auto; right: 14px; }

.input-wrapper input {
    width: 100%;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 14px 12px 42px;
    color: var(--text-main);
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s ease;
    font-family: 'Cairo', sans-serif;
}

html[dir="rtl"] .input-wrapper input { padding: 12px 42px 12px 14px; }

.input-wrapper input::placeholder {
    color: #94a3b8;
}

.input-wrapper input:focus {
    border-color: var(--primary);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.input-wrapper input:focus ~ .input-icon,
.input-wrapper input:not(:placeholder-shown) ~ .input-icon {
    fill: var(--primary);
}

.error-message {
    font-size: 0.82rem;
    color: var(--error);
    display: block;
    margin-top: 5px;
    opacity: 0;
    transform: translateY(-4px);
    transition: all 0.2s ease;
}

.input-group.error .error-message {
    opacity: 1;
    transform: translateY(0);
}

.input-group.error .input-wrapper input {
    border-color: var(--error);
    background: rgba(239, 68, 68, 0.03);
}

.form-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    font-size: 0.85rem;
}

.remember-me {
    display: flex;
    align-items: center;
    cursor: pointer;
    color: var(--text-muted);
    user-select: none;
    gap: 6px;
}

.remember-me input {
    accent-color: var(--primary);
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.forgot-password {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease;
}

.forgot-password:hover {
    color: var(--primary-dark);
}

.submit-btn {
    width: 100%;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 14px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
    font-family: 'Cairo', sans-serif;
    position: relative;
    overflow: hidden;
}

.submit-btn:hover {
    background: var(--primary-dark);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.3);
    transform: translateY(-1px);
}

.submit-btn:active {
    transform: translateY(0);
}

.submit-btn:disabled,
button[type="submit"]:disabled,
input[type="submit"]:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

button[type="submit"]:not(:disabled),
input[type="submit"]:not(:disabled),
button.submit-btn:not(:disabled) {
    cursor: pointer;
}

.submit-btn.loading .btn-text { opacity: 0; }
.submit-btn.loading .loader { display: block !important; }

.loader {
    width: 22px;
    height: 22px;
    border: 2.5px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
    position: absolute;
}

@keyframes spin { to { transform: rotate(360deg); } }

.footer-text {
    text-align: center;
    margin-top: 24px;
    font-size: 0.8rem;
    color: #94a3b8;
}

/* --- DARK MODE (Login Page) --- */
[data-theme="dark"] {
    --bg-main: #0f172a;
    --glass-bg: rgba(30, 41, 59, 0.9);
    --glass-border: rgba(51, 65, 85, 0.6);
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border-color: #334155;
}

[data-theme="dark"] .glass-panel {
    box-shadow:
        0 20px 50px -12px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(51, 65, 85, 0.5) inset;
}

[data-theme="dark"] .glass-panel:hover {
    box-shadow:
        0 28px 60px -12px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(51, 65, 85, 0.5) inset;
}

[data-theme="dark"] .shape-1 {
    background: rgba(52, 211, 153, 0.08);
}

[data-theme="dark"] .shape-2 {
    background: rgba(96, 165, 250, 0.06);
}

[data-theme="dark"] .shape-3 {
    background: rgba(167, 139, 250, 0.05);
}

[data-theme="dark"] .input-wrapper input {
    background: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
}

[data-theme="dark"] .input-wrapper input::placeholder {
    color: #64748b;
}

[data-theme="dark"] .input-wrapper input:focus {
    background: #1e293b;
    border-color: var(--primary);
}

[data-theme="dark"] .footer-text {
    color: #64748b;
}

[data-theme="dark"] .input-icon {
    fill: #64748b;
}

/* Bouton thème clair/sombre - coin fixe */
.login-dark-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.login-dark-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: scale(1.05);
}

[data-theme="dark"] .login-dark-toggle {
    color: #fbbf24;
    border-color: #475569;
}

[data-theme="dark"] .login-dark-toggle:hover {
    color: #fde68a;
    border-color: #fbbf24;
}

/* Sélecteur langue - au-dessus du formulaire, centré */
.login-lang-row {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}
.lang-switch {
    display: inline-flex;
    gap: 4px;
    background: var(--glass-bg);
    padding: 6px 10px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
}
.lang-switch button {
    padding: 8px 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: 'Cairo', sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
    border-radius: 8px;
    transition: all 0.2s;
}
.lang-switch button.active {
    background: var(--primary);
    color: white;
}
.lang-switch button:hover:not(.active) {
    background: rgba(16, 185, 129, 0.1);
    color: var(--primary);
}

/* --- Login Responsive --- */
@media (max-width: 480px) {
    body.login-page {
        padding: 0 12px;
    }
    .login-container {
        width: 100%;
        max-width: calc(100vw - 24px);
        padding: 12px 0;
        margin: 0 auto;
        overflow: hidden;
    }
    .glass-panel {
        width: 100%;
        max-width: 100%;
        padding: 24px 20px;
        border-radius: 20px;
    }
    .logo-section { margin-bottom: 24px; }
    .logo-icon {
        width: 56px;
        height: 56px;
    }
    .logo-section h1 { font-size: 1.2rem; }
    .logo-section p { font-size: 0.82rem; }
    .input-group { margin-bottom: 16px; }
    .input-wrapper input { padding: 11px 12px 11px 40px; font-size: 0.9rem; }
    html[dir="rtl"] .input-wrapper input { padding: 11px 40px 11px 12px; }
    .form-actions {
        flex-wrap: wrap;
        gap: 12px;
        margin-bottom: 20px;
    }
    .submit-btn { padding: 12px; font-size: 0.95rem; }
    .login-dark-toggle {
        top: 12px;
        right: 12px;
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
    }
    html[dir="ltr"] .login-dark-toggle { right: 12px; left: auto; }
    html[dir="rtl"] .login-dark-toggle { right: 12px; left: auto; }
    .login-lang-row {
        margin-bottom: 12px;
    }
    .lang-switch {
        padding: 4px 8px;
    }
    .lang-switch button { padding: 6px 12px; font-size: 0.85rem; }
    .footer-text { font-size: 0.75rem; margin-top: 16px; }
    .shape-1 { width: 280px; height: 280px; top: -80px; }
    .shape-2 { width: 200px; height: 200px; }
    .shape-3 { width: 150px; height: 150px; }
}

@media (max-width: 360px) {
    body.login-page { padding: 0 8px; }
    .login-container { max-width: calc(100vw - 16px); }
    .glass-panel { padding: 20px 16px; }
    .logo-section h1 { font-size: 1.1rem; }
    .login-lang-row { margin-bottom: 10px; }
    .lang-switch button { padding: 5px 10px; font-size: 0.8rem; }
}
