/* ============================================================
   BeneLove — Feuille de style principale
   Thème festival : violet foncé / orange / blanc
   Responsive Bootstrap 5 + sidebar rétractable
   ============================================================ */

/* ---- Variables CSS ---- */
:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 64px;
    --sidebar-bg: #1a0a2e;         /* Violet nuit festival */
    --sidebar-active: #6f42c1;     /* Violet actif */
    --sidebar-hover: rgba(111, 66, 193, 0.25);
    --topbar-height: 60px;
    --accent-color: #fd7e14;       /* Orange festival */
    --text-light: rgba(255,255,255,0.85);
    --text-muted-sidebar: rgba(255,255,255,0.5);
    --card-shadow: 0 2px 12px rgba(0,0,0,0.08);
    --transition: all 0.25s ease;
}

/* ============================================================
   GLOBAL
   ============================================================ */
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: #f0f2f5;
    color: #2d2d2d;
    min-height: 100vh;
}

/* Scrollbar personnalisée */
::-webkit-scrollbar        { width: 6px; height: 6px; }
::-webkit-scrollbar-track  { background: #f0f0f0; }
::-webkit-scrollbar-thumb  { background: #bbb; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #888; }

/* ============================================================
   PRÉCHARGEUR (preloader)
   ============================================================ */
.preloader {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--sidebar-bg);
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.preloader-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: preloader-spin 0.8s linear infinite;
}

@keyframes preloader-spin {
    to { transform: rotate(360deg); }
}

.preloader.hide {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* ============================================================
   LAYOUT PRINCIPAL (sidebar + contenu)
   ============================================================ */
.wrapper {
    display: flex;
    min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    transition: var(--transition);
    box-shadow: 4px 0 20px rgba(0,0,0,0.25);
}

/* Header de la sidebar : logo + nom de l'app */
.sidebar-header {
    position: relative;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
    color: var(--text-light);
    font-size: 1.3rem;
    font-weight: 700;
}

.sidebar-brand i {
    font-size: 1.5rem;
    color: var(--accent-color);
}

.sidebar-brand-icon {
    font-size: 1.4rem;
    line-height: 1;
    color: var(--accent-color);
}

.brand-text {
    background: linear-gradient(135deg, #fff 0%, var(--accent-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Voyant d'état de la connexion à la base de données */
.db-status-dot {
    position: absolute;
    top: 50%;
    right: 1rem;
    transform: translateY(-50%);
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.3);
    transition: var(--transition);
}

.db-status-dot.connected {
    background-color: #20c997;
    box-shadow: 0 0 6px rgba(32, 201, 151, 0.8);
}

.db-status-dot.disconnected {
    background-color: #dc3545;
    box-shadow: 0 0 6px rgba(220, 53, 69, 0.8);
}

/* Menu de navigation */
.sidebar-menu {
    flex: 1;
    padding: 0.75rem 0;
    overflow-y: auto;
}

.sidebar-menu .nav-link {
    color: var(--text-muted-sidebar);
    padding: 0.7rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-radius: 0;
    transition: var(--transition);
    position: relative;
    font-size: 0.9rem;
}

.sidebar-menu .nav-link i {
    font-size: 1rem;
    width: 20px;
    text-align: center;
}

.sidebar-menu .nav-link:hover {
    color: #fff;
    background: var(--sidebar-hover);
    padding-left: 1.5rem;
}

.sidebar-menu .nav-link.active {
    color: #fff;
    background: var(--sidebar-active);
    font-weight: 600;
}

.sidebar-menu .nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent-color);
    border-radius: 0 2px 2px 0;
}

/* Séparateur dans le menu */
.nav-divider {
    height: 1px;
    background: rgba(255,255,255,0.1);
    margin: 0.5rem 1rem;
}

/* Pied de la sidebar : info utilisateur */
.sidebar-version {
    font-size: .7rem;
    opacity: .5;
    color: #fff;
    text-align: center;
    margin-top: .25rem;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex: 1;
    min-width: 0;
}

.user-info > i {
    font-size: 1.5rem;
    color: var(--text-muted-sidebar);
    flex-shrink: 0;
}

.user-name  { color: var(--text-light); font-weight: 600; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role  { color: var(--text-muted-sidebar); font-size: 0.75rem; }
.user-assoc { color: var(--text-muted-sidebar); font-size: 0.7rem; opacity: .7; }
.badge-super { font-size: 0.6rem; }
.td-actions-nowrap { white-space: nowrap; }

.logout-btn { padding: 0.25rem 0.5rem; }

/* ============================================================
   CONTENU PRINCIPAL
   ============================================================ */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    min-width: 0;        /* empêche le flex-item de dépasser la largeur du viewport */
    overflow-x: hidden;  /* contenu large (ex. Gantt) ne scroll pas la page entière */
}

/* Barre supérieure */
.topbar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.topbar-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1a1a2e;
    margin: 0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

/* Zone de contenu */
.page-content { flex: 1; padding-top: 1.5rem; }

/* Messages flash */
.flash-container .alert { border-radius: 8px; font-size: 0.9rem; }

/* ============================================================
   PAGE DE CONNEXION
   ============================================================ */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a0a2e 0%, #3d1a6e 50%, #6f42c1 100%);
    padding: 2rem 1rem;
}

.login-container  { width: 100%; max-width: 420px; }

.login-header { text-align: center; margin-bottom: 2rem; }

.login-logo {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    font-size: 2.5rem;
    color: var(--accent-color);
    border: 2px solid rgba(255,255,255,0.3);
}

.login-title    { color: #fff; font-size: 2rem; font-weight: 800; margin-bottom: 0.25rem; }
.login-version  { color: rgba(255,255,255,0.6); font-size: 0.8rem; }
.login-subtitle { color: rgba(255,255,255,0.7); font-size: 0.9rem; }

.login-card {
    background: rgba(255,255,255,0.95);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.login-footer {
    color: rgba(255,255,255,0.6);
    font-size: 0.8rem;
    text-align: center;
    margin-top: 1.5rem;
}

.auth-flash { width: 100%; max-width: 420px; margin-bottom: 1rem; }

/* ============================================================
   CARTES DE STATISTIQUES (dashboard)
   ============================================================ */
.stat-card {
    border-radius: 12px;
    padding: 1.25rem;
    color: #fff;
    position: relative;
    overflow: hidden;
    box-shadow: var(--card-shadow);
    transition: transform 0.2s;
}

.stat-card:hover { transform: translateY(-2px); }

.stat-card::before {
    content: '';
    position: absolute;
    right: -20px;
    top: -20px;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
}

.text-orange { color: #fd7e14 !important; }
.bg-orange   { background-color: #fd7e14 !important; color: #fff !important; }

@keyframes blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}
.text-blink-red { color: #dc3545 !important; animation: blink 1s step-start infinite; }
.bg-blink-red   { background-color: #dc3545 !important; animation: blink 1s step-start infinite; }

.stat-card-primary { background: linear-gradient(135deg, #0d6efd, #6610f2); }
.stat-card-success { background: linear-gradient(135deg, #198754, #20c997); }
.stat-card-danger  { background: linear-gradient(135deg, #dc3545, #fd7e14); }
.stat-card-warning { background: linear-gradient(135deg, #ffc107, #fd7e14); color: #1a1a2e; }
.stat-card-info    { background: linear-gradient(135deg, #0dcaf0, #0d6efd); }

.stat-icon  { font-size: 2rem; margin-bottom: 0.5rem; opacity: 0.9; }
.stat-value { font-size: 2.25rem; font-weight: 800; line-height: 1; }
.stat-label { font-size: 0.85rem; opacity: 0.85; margin-top: 0.25rem; }
.stat-link  { display: block; font-size: 0.8rem; opacity: 0.8; margin-top: 0.5rem; color: inherit; text-decoration: none; }
.stat-link:hover { opacity: 1; text-decoration: underline; }

/* ============================================================
   CARTES GÉNÉRIQUES
   ============================================================ */
.card { border: none; border-radius: 12px; box-shadow: var(--card-shadow); }
.card-header { background: transparent; border-bottom: 1px solid #f0f0f0; padding: 1rem 1.25rem; }
.card-header h5, .card-header h6 { font-weight: 600; }
.dashboard-progress { height: 10px; border-radius: 5px; }
.dashboard-progress .progress-bar { border-radius: 5px; }

/* ============================================================
   SÉLECTEUR D'IMPORTANCE
   ============================================================ */
.importance-selector { display: flex; flex-wrap: wrap; gap: 0.75rem; }

.importance-option input[type="radio"] { display: none; }

.importance-btn {
    cursor: pointer;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    text-align: center;
    transition: var(--transition);
    opacity: 0.5;
    border: 2px solid transparent;
    font-size: 0.85rem;
}

.importance-option input:checked + .importance-btn {
    opacity: 1;
    transform: scale(1.05);
    border-color: rgba(0,0,0,0.2);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* ============================================================
   BADGE D'IMPORTANCE
   ============================================================ */
.importance-badge { font-size: 0.85rem; letter-spacing: 1px; }

/* ============================================================
   NIVEAUX D'IMPORTANCE — NIVEAUX DE GRIS
   1=Nouveau  2=Connu  3=Famille  4=Fidèle  5=Confiance
   ============================================================ */
.bg-gray-1 { background-color: #adb5bd !important; color: #212529 !important; }
.bg-gray-2 { background-color: #6c757d !important; color: #fff    !important; }
.bg-gray-3 { background-color: #495057 !important; color: #fff    !important; }
.bg-gray-4 { background-color: #343a40 !important; color: #fff    !important; }
.bg-gray-5 { background-color: #212529 !important; color: #fff    !important; }

.border-gray-1 { border-color: #adb5bd !important; }
.border-gray-2 { border-color: #6c757d !important; }
.border-gray-3 { border-color: #495057 !important; }
.border-gray-4 { border-color: #343a40 !important; }
.border-gray-5 { border-color: #212529 !important; }

/* ============================================================
   CARTES BÉNÉVOLES (vue grille)
   ============================================================ */
.volunteer-card {
    border-left: 4px solid;
    transition: transform 0.15s, box-shadow 0.15s;
}
.volunteer-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,0.12); }

/* ============================================================
   CARTES FESTIVALS
   ============================================================ */
.festival-card {
    border-top: 4px solid var(--accent-color);
    transition: transform 0.15s, box-shadow 0.15s;
}
.festival-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,0.12); }

/* ============================================================
   ALERTES PANEL
   ============================================================ */
.opacity-60 { opacity: 0.6; }

/* ============================================================
   ÉDITEUR EMAIL
   ============================================================ */
.email-editor {
    min-height: 200px;
    font-family: inherit;
    resize: vertical;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 0.75rem;
    outline: none;
    line-height: 1.6;
}
.email-editor:focus { border-color: #86b7fe; box-shadow: 0 0 0 0.2rem rgba(13,110,253,.25); }
.email-editor:empty::before { content: attr(placeholder); color: #adb5bd; }
.email-toolbar { border-radius: 6px 6px 0 0; }

/* ============================================================
   GANTT — Surcharges du thème Frappe Gantt
   ============================================================ */
.gantt .grid-header { fill: #1a0a2e; }
.gantt .grid-row:nth-child(even) { fill: #f8f5ff; }
.gantt .tick { stroke: #e0d5f0; }
.gantt .bar-group .bar { rx: 4; ry: 4; }
.gantt .bar-group .bar-label { fill: #fff; font-size: 12px; }
.gantt-popup { background: #fff; padding: 0.75rem; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.2); min-width: 200px; }

/* ============================================================
   SIDEBAR RÉDUITE (desktop uniquement)
   Icônes seules, titres en tooltip au survol
   ============================================================ */
@media (min-width: 768px) {
    .sidebar.collapsed {
        width: var(--sidebar-collapsed-width);
    }

    .sidebar.collapsed .sidebar-header {
        padding: 1.25rem 0;
        justify-content: center;
    }

    .sidebar.collapsed .sidebar-brand {
        justify-content: center;
    }

    .sidebar.collapsed .brand-text {
        display: none;
    }

    .sidebar.collapsed .db-status-dot {
        display: none;
    }

    .sidebar.collapsed .sidebar-menu .nav-link {
        justify-content: center;
        padding: 0.7rem 0;
        gap: 0;
    }

    .sidebar.collapsed .sidebar-menu .nav-link:hover {
        padding-left: 0;
    }

    .sidebar.collapsed .sidebar-menu .nav-link span:not(.badge) {
        display: none;
    }

    .sidebar.collapsed .sidebar-menu .nav-link .badge {
        position: absolute;
        top: 4px;
        right: 6px;
        font-size: 0.6rem;
        min-width: 16px;
        height: 16px;
        padding: 0 3px;
        line-height: 16px;
    }

    .sidebar.collapsed .nav-divider {
        margin: 0.5rem 0.5rem;
    }

    .sidebar.collapsed .sidebar-footer {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
        padding: 0.75rem 0;
    }

    .sidebar.collapsed .user-info > div {
        display: none;
    }

    .sidebar.collapsed .user-info {
        gap: 0;
    }

    .main-content.sidebar-collapsed {
        margin-left: var(--sidebar-collapsed-width);
    }
}

/* Icône du bouton collapse : rotation fluide */
#sidebarCollapseBtn i {
    transition: transform 0.25s ease;
}

/* ============================================================
   OVERLAY MOBILE
   ============================================================ */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

/* ============================================================
   RESPONSIVE — Mobile & Tablette
   ============================================================ */
@media (max-width: 767.98px) {
    /* Sidebar masquée par défaut sur mobile */
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-overlay.visible {
        display: block;
    }

    /* Décale le voyant d'état pour laisser la place au bouton de fermeture */
    .db-status-dot {
        right: 2.75rem;
    }

    /* Le contenu prend toute la largeur sur mobile */
    .main-content {
        margin-left: 0;
    }

    /* Réduction de la taille des cartes stats sur mobile */
    .stat-card { padding: 1rem; }
    .stat-value { font-size: 1.75rem; }

    /* Tables responsives */
    .table-responsive { font-size: 0.85rem; }
}

/* ============================================================
   UTILITAIRES
   ============================================================ */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Animation de chargement */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.5; }
}
.loading { animation: pulse 1.5s infinite; }

/* ============================================================
   POSTES À POURVOIR (festival detail)
   ============================================================ */
.post-progress { height: 8px; }
.post-progress-bar { width: 0; transition: width 0.4s ease; }

/* Colonne commentaire dans le tableau des affectations */
.assignment-notes-cell { max-width: 180px; }

/* Tableau des postes — colonne checkbox et mini barre de progression */
.th-check           { width: 36px; }
.post-mini-progress { height: 4px; width: 60px; margin: 0 auto; }

/* Badge association/admin dans la topbar */
.topbar-asso-name {
    font-size: inherit;
    font-weight: 600;
    color: var(--accent-color);
    letter-spacing: .04em;
    text-transform: uppercase;
}

@keyframes topbar-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: .25; }
}
.topbar-asso-blink { animation: topbar-blink 2s ease-in-out infinite; }

/* ============================================================
   TRI DES TABLEAUX — tri client-side par clic sur les en-têtes
   ============================================================ */
.th-sortable {
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}
.th-sortable:hover {
    opacity: 0.82;
}
.th-sort-asc,
.th-sort-desc {
    background-color: rgba(255, 255, 255, 0.12) !important;
}
/* ============================================================
   IMPRESSION — réinitialisation commune du layout (sidebar/topbar)
   pour toutes les pages disposant d'une fonction d'impression
   ============================================================ */
@media print {
    .sidebar, .topbar, #sidebarOverlay, .no-print { display: none !important; }
    .wrapper { display: block !important; min-height: 0 !important; }
    .main-content { margin-left: 0 !important; min-height: 0 !important; overflow: visible !important; }
    .page-content { padding: 0 !important; }
    body { background: #fff !important; }

    /* Les animations de clignotement n'ont pas de sens à l'impression et
       peuvent figer le contenu sur une image à opacité 0 (texte invisible) */
    .text-blink-red, .bg-blink-red, .topbar-asso-blink {
        animation: none !important;
        opacity: 1 !important;
    }
}

.sort-icon {
    font-size: 0.85em;
    margin-left: 0.2rem;
    vertical-align: middle;
    opacity: 0.9;
}

/* ============================================================
   BOUTONS PERSONNALISÉS — variante orange (couleur de marque)
   ============================================================ */
.btn-outline-orange {
    color: var(--accent-color);
    border-color: var(--accent-color);
}
.btn-outline-orange:hover,
.btn-outline-orange:focus,
.btn-outline-orange:active {
    color: #fff;
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}
