/* ============================================================================
   CSP-SAFE UTILITY CLASSES
   Replaces inline style attributes and JS .style manipulation
   to comply with strict Content Security Policy (no 'unsafe-inline').
   ============================================================================ */

/* --- Display utilities --- */
.u-hidden          { display: none !important; }
.u-visible         { display: block !important; }
.u-flex            { display: flex !important; }
.u-inline          { display: inline !important; }
.u-inline-block    { display: inline-block !important; }

/* --- Opacity utilities --- */
.u-opacity-0       { opacity: 0 !important; }
.u-opacity-1       { opacity: 1 !important; }

/* --- Text alignment utilities --- */
.u-text-center     { text-align: center !important; }

/* --- Overflow utilities --- */
.u-overflow-hidden { overflow: hidden !important; }
.u-overflow-auto   { overflow: auto !important; }

/* --- Pointer-event utilities --- */
.u-no-pointer      { pointer-events: none !important; }
.u-pointer-auto    { pointer-events: auto !important; }

/* ============================================================================
   GLOBAL LOADER — styles moved from inline style="" on #global-loader
   ============================================================================ */

#global-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    font-family: 'Lato', sans-serif;
}

#global-loader .loader-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #e3e3e3;
    border-top: 5px solid #1843bf;
    border-radius: 50%;
    animation: global-spin 1s linear infinite;
    margin-bottom: 20px;
}

#global-loader .loader-title {
    color: #1843bf;
    margin: 0 0 10px 0;
    font-weight: 600;
    font-size: 18px;
}

#global-loader .loader-text {
    color: #666;
    margin: 0;
    font-size: 14px;
}

/* ============================================================================
   NAVIGATION LOADER — replaces inline styles in app.js showNavigationLoading()
   ============================================================================ */

.navigation-loader-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: #f8f9fa;
    color: #666;
}

.navigation-loader-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e3e3e3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

.navigation-loader-text {
    font-size: 16px;
    margin: 0;
}

/* ============================================================================
   PAGE-CONTENT — initial hidden state + zero-padding variant
   Replaces style="display: none; padding: 0;" on .page-content elements
   ============================================================================ */

.page-content--initial {
    display: none;
    padding: 0;
}

/* ============================================================================
   BORDER UTILITIES — replaces inline .style.borderColor assignments
   ============================================================================ */

.u-border-error     { border-color: #dc3545 !important; }

/* ============================================================================
   INLINE-FLEX UTILITY
   ============================================================================ */

.u-inline-flex       { display: inline-flex !important; }

/* ============================================================================
   FEEDBACK NOTIFICATION — replaces inline styles in utils.js showFeedback()
   ============================================================================ */

.feedback-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    min-width: 300px;
}

/* ============================================================================
   ERROR ALERT — replaces inline styles in protected-route.js showFallbackError()
   ============================================================================ */

.error-alert-container {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #f44336;
    color: white;
    padding: 15px 20px;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 9999;
    max-width: 400px;
    font-family: Arial, sans-serif;
}

.error-alert-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.error-alert-close-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 18px;
    margin-left: auto;
}

/* ============================================================================
   PROTECTED-ROUTE LOADING — replaces inline styles in showLoading()
   ============================================================================ */

.protected-route-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: #666;
}

.protected-route-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

/* ============================================================================
   HEADER OVERLAY — replaces inline styles in header.js toggleMobileSidebar()
   ============================================================================ */

.header-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.3);
    z-index: 899;
}

/* --- Cursor utilities --- */
.u-cursor-pointer  { cursor: pointer !important; }

/* --- Grid utilities --- */
.u-grid-full       { grid-column: 1 / -1 !important; }

/* ============================================================================
   PARAMETRES NOTIFICATION POPUP — replaces inline .style.cssText in parametres.js showPopup()
   ============================================================================ */

.param-popup-base {
    position: fixed;
    top: 20px;
    right: 20px;
    color: white;
    padding: 16px 20px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15), 0 5px 10px rgba(0, 0, 0, 0.1);
    z-index: 10000;
    font-family: 'Lato', sans-serif;
    font-size: 14px;
    font-weight: 500;
    max-width: 400px;
    min-width: 300px;
    animation: slideInRight 0.3s ease-out;
}

.param-popup-base.success {
    background: #10B981;
    border-left: 4px solid #065F46;
}

.param-popup-base.error {
    background: #EF4444;
    border-left: 4px solid #B91C1C;
}

.param-popup-content {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

.param-popup-icon {
    font-size: 18px;
    opacity: 0.9;
    flex-shrink: 0;
}

.param-popup-text {
    flex: 1;
    line-height: 1.4;
}

.param-popup-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    opacity: 0.7;
    transition: opacity 0.2s ease, background 0.2s ease;
    margin-left: 8px;
    flex-shrink: 0;
}

.param-popup-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

/* Animation class for slide-out removal */
.param-popup-slide-out {
    animation: slideOutRight 0.3s ease-in !important;
}

/* ============================================================================
   PARAMETRES — copy-button background feedback classes
   ============================================================================ */

.param-bg-success { background: #28a745 !important; }

/* ============================================================================
   QR CODE IMAGE — replaces inline .style.maxWidth / .style.height
   ============================================================================ */

.param-qr-image {
    max-width: 256px;
    height: auto;
}

/* ============================================================================
   PARAMETRES NOTIFICATION OVERLAY — overlay + popup for parametres.js
   ============================================================================ */

.param-notification-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.param-notification-overlay--visible {
    opacity: 1;
}

.param-notification-popup {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    transform: scale(0.8);
    transition: transform 0.3s ease;
}

.param-notification-overlay--visible .param-notification-popup {
    transform: scale(1);
}

/* ============================================================================
   TEXT & COLOR UTILITIES — replaces inline .style.color / .style.fontSize
   ============================================================================ */

.u-text-error       { color: #dc3545 !important; }
.u-text-small        { font-size: 0.8rem !important; }

/* ============================================================================
   MARGIN UTILITIES — replaces inline .style.marginTop
   ============================================================================ */

.u-mt-quarter        { margin-top: 0.25rem !important; }
.u-mt-half           { margin-top: 0.5rem !important; }
.u-mt-1              { margin-top: 1rem !important; }

/* ============================================================================
   VISIBILITY UTILITY — replaces inline .style.visibility = 'hidden'
   ============================================================================ */

.u-invisible         { visibility: hidden !important; }

/* ============================================================================
   USER-CREATION NOTIFICATION — replaces inline .style.cssText in showTemporaryMessage()
   ============================================================================ */

.uc-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--app-primary);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    font-weight: 500;
    animation: slideInRight 0.3s ease-out;
}

.uc-notification--exit {
    animation: slideOutRight 0.3s ease-in;
}

/* ============================================================================
   PERMISSIONS EMPTY STATE — replaces inline style="" in renderUsers()
   ============================================================================ */

.perm-empty-state {
    text-align: center;
    padding: 2rem;
    color: #666;
}

.perm-empty-state-icon {
    font-size: 2rem;
    margin-bottom: 1rem;
    display: block;
}

.perm-inactive-badge {
    font-size: 0.7rem;
}

/* ============================================================================
   PERMISSIONS LOADING TD — replaces inline style on loading <td>
   ============================================================================ */

.perm-loading-td {
    padding: 0;
    border: none;
}

/* ============================================================================
   DELETE MODAL — replaces inline style="" in deleteUser() template
   ============================================================================ */

.delete-modal-icon   { color: #dc3545; font-size: 2rem; }
.delete-modal-title  { color: #dc3545; margin: 1rem 0; }
.delete-modal-text   { font-size: 1.1rem; font-weight: bold; }
.delete-modal-warning {
    background: #fff3cd;
    padding: 1rem;
    border-radius: 6px;
    margin: 1rem 0;
}
.delete-modal-warning-text { margin: 0; color: #856404; }
.delete-modal-warning-list { margin: 0.5rem 0 0 1rem; color: #856404; }

/* ============================================================================
   GROUPS ERROR ICON — replaces inline style on gestion_groupes error icon
   ============================================================================ */

.groups-error-icon   { font-size: 3rem; color: #dc3545; }

/* ============================================================================
   COPY BUTTON SUCCESS — replaces inline .style.background in permissions.js
   ============================================================================ */

.copy-btn-success    { background: #27ae60 !important; }

/* ============================================================================
   PERMISSIONS LOADING — replaces dynamic <style id="app-loading-styles">
   in permissions.js addLoadingStyles()
   ============================================================================ */

.app-loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
    min-height: 400px;
}

.app-loading-spinner {
    position: relative;
    width: 60px;
    height: 60px;
    margin-bottom: 2rem;
}

.app-loading-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid transparent;
    border-radius: 50%;
    animation: app-spin 1.2s linear infinite;
}

.app-loading-ring:nth-child(1) {
    border-top-color: #1e3a8a;
    animation-delay: 0s;
}

.app-loading-ring:nth-child(2) {
    border-right-color: #f59e0b;
    animation-delay: 0.2s;
    width: 80%;
    height: 80%;
    top: 10%;
    left: 10%;
}

.app-loading-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    background: linear-gradient(45deg, #1e3a8a, #f59e0b);
    border-radius: 50%;
    animation: app-pulse 1s ease-in-out infinite alternate;
}

@keyframes app-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes app-pulse {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1.3); opacity: 0.7; }
}

.app-loading-text {
    color: #495057;
}

.app-loading-title {
    margin: 0 0 0.5rem 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #212529;
}

.app-loading-subtitle {
    margin: 0;
    font-size: 0.9rem;
    opacity: 0.8;
}

.app-loading-dots {
    display: inline-block;
}

.app-loading-dots span {
    display: inline-block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background-color: #1e3a8a;
    margin: 0 1px;
    animation: app-dots-bounce 1.4s infinite ease-in-out;
}

.app-loading-dots span:nth-child(1) { animation-delay: 0s; }
.app-loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.app-loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes app-dots-bounce {
    0%, 80%, 100% {
        opacity: 0;
        transform: scale(1);
    }
    40% {
        opacity: 1;
        transform: scale(1.2);
    }
}

/* ============================================================================
   SESSION WARNING MODAL — replaces dynamic <style> in app.js showSessionWarning()
   ============================================================================ */

.session-warning-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(var(--app-secondary-rgb, 71, 85, 105), 0.15) 0%, rgba(var(--app-primary-rgb, 30, 41, 59), 0.35) 50%, rgba(var(--app-secondary-rgb, 71, 85, 105), 0.15) 100%);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.3s ease;
}

.session-warning-content {
    background: var(--blanc, #FFFFFF);
    border-radius: var(--app-radius, 8px);
    padding: 36px 32px;
    max-width: 460px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow-lg, 0 10px 30px rgba(0,0,0,0.10));
    animation: slideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 2px solid var(--app-border, #e2e8f0);
    position: relative;
    overflow: hidden;
}

.session-warning-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--bleu-new-agency, #1e293b) 0%, var(--beige-sable, #475569) 50%, var(--bleu-new-agency, #1e293b) 100%);
}

.session-warning-header {
    margin-bottom: 24px;
}

.session-warning-header i {
    font-size: 48px;
    color: var(--beige-sable, #475569);
    margin-bottom: 16px;
    background: var(--beige-clair, #f1f5f9);
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.session-warning-header h3 {
    margin: 0;
    color: var(--bleu-new-agency, #1e293b);
    font-size: 24px;
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
}

.session-warning-body {
    margin-bottom: 28px;
}

.session-warning-body p {
    margin: 8px 0;
    color: var(--gris-texte, #1e293b);
    font-size: 16px;
    font-family: 'Lato', sans-serif;
}

.session-warning-timer {
    margin-top: 16px;
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--beige-clair, #f1f5f9) 0%, var(--gris-light, #f8fafc) 100%);
    border-radius: var(--app-radius, 8px);
    font-weight: bold;
    font-size: 16px;
    color: var(--bleu-nuit, #0f172a);
    border: 2px solid var(--beige-sable, #475569);
    display: inline-block;
    max-width: 260px;
    min-width: 260px;
    text-align: center;
}

.session-warning-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.session-warning-actions button {
    padding: 12px 20px;
    border: none;
    border-radius: var(--app-radius, 8px);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-smooth, 0.3s cubic-bezier(0.4, 0, 0.2, 1));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: 'Montserrat', sans-serif;
    text-transform: uppercase;
    min-width: 140px;
    height: 44px;
    white-space: nowrap;
    text-align: center;
    line-height: 1.2;
    letter-spacing: 0.5px;
    box-sizing: border-box;
}

@media (max-width: 480px) {
    .session-warning-actions {
        flex-direction: column;
        align-items: center;
    }

    .session-warning-actions button {
        width: 100%;
        max-width: 240px;
        font-size: 13px;
        padding: 12px 16px;
        height: 40px;
    }

    .session-warning-timer {
        font-size: 14px;
        padding: 10px 16px;
        max-width: 200px;
    }
}

.session-warning-actions .btn-primary {
    background: linear-gradient(135deg, var(--bleu-new-agency, #1e293b) 0%, var(--app-accent, #334155) 100%);
    color: var(--blanc, #FFFFFF);
    box-shadow: var(--shadow-sm, 0 2px 8px rgba(0,0,0,0.1));
}

.session-warning-actions .btn-primary:hover {
    background: linear-gradient(135deg, var(--bleu-nuit, #0f172a) 0%, var(--bleu-new-agency, #1e293b) 100%);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md, 0 4px 12px rgba(0,0,0,0.15));
}

.session-warning-actions .btn-secondary {
    background: transparent;
    color: var(--beige-sable, #475569);
    border: 2px solid var(--beige-sable, #475569);
}

.session-warning-actions .btn-secondary:hover {
    background: var(--beige-sable, #475569);
    color: var(--blanc, #FFFFFF);
    transform: translateY(-1px);
}

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

@keyframes slideIn {
    from {
        transform: translateY(-60px) scale(0.8);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

@media (max-width: 600px) {
    .session-warning-content {
        padding: 28px 24px;
        margin: 20px;
        width: calc(100% - 40px);
        max-width: none;
    }

    .session-warning-header h3 {
        font-size: 20px;
    }

    .session-warning-header i {
        width: 70px;
        height: 70px;
        font-size: 40px;
    }

    .session-warning-body p {
        font-size: 14px;
    }
}
