/* ==========================================================================
   UX AMELIORATIONS - Accessibilite, Raccourcis, Mode Compact, Reactions, Presence
   ========================================================================== */

/* ==========================================================================
   1. ACCESSIBILITE WCAG 2.1
   ========================================================================== */

/* Skip Link pour navigation rapide */
.skip-link {
    position: absolute;
    top: -50px;
    left: 0;
    background: var(--accent);
    color: white;
    padding: 12px 24px;
    z-index: 10001;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 var(--rayon) 0;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid var(--accent-hover);
    outline-offset: 2px;
}

/* Focus Visible pour tous elements interactifs */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Focus specifique pour boutons */
button:focus-visible,
.btn-icon:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(26, 115, 232, 0.2);
}

/* Focus pour les messages (navigation clavier) */
.message:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
    border-radius: var(--rayon);
}

.message.message-focus {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
    background: var(--accent-leger);
}

/* Zone de messages avec role="log" */
.messages-container[role="log"] {
    position: relative;
}

/* Annonces screen reader (visuellement cache) */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Zone d'annonces live */
.aria-live-region {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --bordure: #000;
        --texte-secondaire: #000;
    }

    button, .btn-icon, .btn-primary {
        border-width: 2px;
    }
}

/* ==========================================================================
   2. RACCOURCIS CLAVIER - Modal d'aide
   ========================================================================== */

/* Overlay modal */
.modal-raccourcis-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal-raccourcis-overlay.active {
    display: flex;
    opacity: 1;
}

/* Modal content */
.modal-raccourcis {
    background: var(--fond-principal);
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-width: 700px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.2s ease;
}

.modal-raccourcis-overlay.active .modal-raccourcis {
    transform: scale(1);
}

/* Modal header */
.modal-raccourcis-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--bordure);
}

.modal-raccourcis-header h2 {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 18px;
    font-weight: 600;
    color: var(--texte-principal);
    margin: 0;
}

.modal-raccourcis-header h2 i {
    color: var(--accent);
}

.btn-fermer-modal {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: var(--fond-tertiaire);
    color: var(--texte-secondaire);
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-fermer-modal:hover {
    background: var(--accent);
    color: white;
}

/* Modal body */
.modal-raccourcis-body {
    padding: 24px;
    overflow-y: auto;
    max-height: calc(80vh - 140px);
}

/* Grid des sections */
.raccourcis-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

@media (max-width: 600px) {
    .raccourcis-grid {
        grid-template-columns: 1fr;
    }
}

/* Section de raccourcis */
.raccourcis-section {
    background: var(--fond-secondaire);
    border-radius: 12px;
    padding: 16px;
}

.raccourcis-section-titre {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--texte-secondaire);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--bordure);
}

/* Liste des raccourcis */
.raccourcis-liste {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.raccourci-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
}

.raccourci-touches {
    display: flex;
    gap: 4px;
}

.touche {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    background: var(--fond-principal);
    border: 1px solid var(--bordure);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    font-family: monospace;
    color: var(--texte-principal);
    box-shadow: 0 2px 0 var(--bordure);
}

.raccourci-description {
    font-size: 13px;
    color: var(--texte-principal);
}

/* Modal footer */
.modal-raccourcis-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--bordure);
    background: var(--fond-secondaire);
}

.raccourcis-astuce {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--texte-secondaire);
}

.raccourcis-astuce i {
    color: var(--accent);
}

/* Hints raccourcis (affiches quand Alt maintenu) */
.raccourci-hint {
    position: absolute;
    background: var(--accent);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    font-family: monospace;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.15s ease;
}

body.afficher-hints .raccourci-hint {
    opacity: 1;
    transform: scale(1);
}

/* ==========================================================================
   3. MODE COMPACT
   ========================================================================== */

/* Toggle Mode Compact dans le menu */
.mode-affichage-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--fond-tertiaire);
    border-radius: 8px;
    margin: 8px 16px;
}

.mode-affichage-toggle span {
    font-size: 12px;
    color: var(--texte-secondaire);
}

.toggle-compact {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--bordure);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.toggle-compact::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-compact.actif {
    background: var(--accent);
}

.toggle-compact.actif::after {
    transform: translateX(20px);
}

/* Mode Compact Active */
body.mode-compact .message {
    margin-bottom: 4px;
    gap: 8px;
}

body.mode-compact .message-avatar {
    width: 24px;
    height: 24px;
    font-size: 10px;
}

body.mode-compact .message-avatar .avatar-humain,
body.mode-compact .message-avatar .avatar-ia-carre {
    width: 24px;
    height: 24px;
    font-size: 9px;
}

body.mode-compact .message-header {
    display: inline;
    margin-bottom: 0;
}

body.mode-compact .message-auteur {
    font-size: 12px;
    display: inline;
}

body.mode-compact .message-date {
    font-size: 10px;
    display: inline;
    margin-left: 8px;
}

body.mode-compact .message-texte {
    font-size: 13px;
    line-height: 1.4;
}

body.mode-compact .message-contenu {
    display: inline;
}

/* Messages consecutifs du meme auteur en mode compact */
body.mode-compact .message.meme-auteur .message-avatar {
    visibility: hidden;
}

body.mode-compact .message.meme-auteur .message-header {
    display: none;
}

body.mode-compact .message.meme-auteur {
    margin-top: 0;
    padding-left: 36px;
}

/* Indicateur mode compact dans header */
.indicateur-mode-compact {
    display: none;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: var(--accent-leger);
    border-radius: 4px;
    font-size: 10px;
    color: var(--accent);
}

body.mode-compact .indicateur-mode-compact {
    display: flex;
}

/* ==========================================================================
   4. REACTIONS AUX MESSAGES
   ========================================================================== */

/* Container des reactions sous le message */
.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    min-height: 0;
}

.message-reactions:empty {
    display: none;
}

/* Chip de reaction */
.reaction-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--fond-tertiaire);
    border: 1px solid var(--bordure);
    border-radius: 16px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

.reaction-chip:hover {
    background: var(--accent-leger);
    border-color: var(--accent);
    transform: scale(1.05);
}

.reaction-chip.ma-reaction {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.reaction-chip .reaction-emoji {
    font-size: 16px;
    line-height: 1;
}

.reaction-chip .reaction-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--texte-secondaire);
}

.reaction-chip.ma-reaction .reaction-count {
    color: white;
}

/* Bouton ajouter reaction */
.btn-ajouter-reaction {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--fond-tertiaire);
    border: 1px dashed var(--bordure);
    border-radius: 50%;
    cursor: pointer;
    opacity: 0;
    transition: all 0.15s ease;
    color: var(--texte-secondaire);
    font-size: 12px;
}

.message:hover .btn-ajouter-reaction {
    opacity: 1;
}

.btn-ajouter-reaction:hover {
    background: var(--accent-leger);
    border-color: var(--accent);
    border-style: solid;
    color: var(--accent);
}

/* Picker de reactions rapides */
.reaction-picker {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    background: var(--fond-principal);
    border: 1px solid var(--bordure);
    border-radius: 24px;
    padding: 8px 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    display: none;
    gap: 4px;
    z-index: 1000;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    transition: all 0.2s ease;
}

.reaction-picker.active {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
}

.reaction-picker-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.reaction-picker-btn:hover {
    background: var(--fond-tertiaire);
    transform: scale(1.2);
}

/* Separateur dans le picker */
.reaction-picker-separator {
    width: 1px;
    height: 24px;
    background: var(--bordure);
    margin: 0 4px;
}

/* Bouton plus d'emojis */
.reaction-picker-more {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    background: var(--fond-tertiaire);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: var(--texte-secondaire);
    transition: all 0.15s ease;
}

.reaction-picker-more:hover {
    background: var(--accent);
    color: white;
}

/* Animation ajout reaction */
@keyframes reactionPop {
    0% { transform: scale(0); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.reaction-chip.nouvelle {
    animation: reactionPop 0.3s ease;
}

/* Tooltip des reacteurs */
.reaction-tooltip {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--fond-principal);
    border: 1px solid var(--bordure);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--texte-principal);
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    opacity: 0;
    visibility: hidden;
    transition: all 0.15s ease;
    z-index: 1001;
}

.reaction-chip:hover .reaction-tooltip {
    opacity: 1;
    visibility: visible;
}

/* ==========================================================================
   5. INDICATEURS DE PRESENCE
   ========================================================================== */

/* Badge de presence */
.presence-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--fond-principal);
    z-index: 10;
}

.presence-badge.en-ligne {
    background: #34a853;
}

.presence-badge.absent {
    background: #fbbc05;
}

.presence-badge.hors-ligne {
    background: #9aa0a6;
}

.presence-badge.ne-pas-deranger {
    background: #ea4335;
}

/* Animation presence en ligne */
.presence-badge.en-ligne::after {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: 50%;
    background: #34a853;
    opacity: 0;
    animation: presencePulse 2s infinite;
}

@keyframes presencePulse {
    0%, 100% { transform: scale(1); opacity: 0; }
    50% { transform: scale(1.5); opacity: 0.3; }
}

/* Header de presence dans le chat */
.presence-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--fond-secondaire);
    border-bottom: 1px solid var(--bordure);
    font-size: 12px;
    color: var(--texte-secondaire);
}

.presence-header .participants {
    display: flex;
    gap: 4px;
}

.presence-header .participant-avatar {
    position: relative;
    width: 24px;
    height: 24px;
}

.presence-header .participant-avatar img,
.presence-header .participant-avatar .avatar-initiales {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--fond-principal);
}

.presence-header .participant-avatar .presence-badge {
    width: 8px;
    height: 8px;
    bottom: -1px;
    right: -1px;
}

/* Indicateur de frappe */
.typing-presence {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--fond-secondaire);
    border-radius: 16px;
    margin: 8px 0;
    font-size: 13px;
    color: var(--texte-secondaire);
    animation: fadeIn 0.2s ease;
}

.typing-presence .typing-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent-leger);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 600;
    color: var(--accent);
}

.typing-presence .typing-dots {
    display: flex;
    gap: 3px;
}

.typing-presence .typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--texte-tertiaire);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-presence .typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-presence .typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-4px); opacity: 1; }
}

/* Receipts de lecture */
.message-receipts {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    font-size: 11px;
    color: var(--texte-tertiaire);
}

.receipt-icon {
    font-size: 12px;
}

.receipt-icon.envoye {
    color: var(--texte-tertiaire);
}

.receipt-icon.recu {
    color: var(--texte-tertiaire);
}

.receipt-icon.lu {
    color: var(--accent);
}

/* Avatars des lecteurs */
.message-lecteurs {
    display: flex;
    margin-left: 4px;
}

.message-lecteurs .lecteur-avatar {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid var(--fond-principal);
    margin-left: -4px;
    font-size: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-leger);
    color: var(--accent);
    font-weight: 600;
}

.message-lecteurs .lecteur-avatar:first-child {
    margin-left: 0;
}

/* ==========================================================================
   6. ANIMATIONS ET TRANSITIONS GLOBALES
   ========================================================================== */

/* Transition douce pour le mode compact */
.message,
.message-avatar,
.message-contenu,
.message-header,
.message-texte {
    transition: all 0.2s ease;
}

/* Animation d'entree pour nouveaux elements */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-slide-up {
    animation: slideUp 0.3s ease;
}

/* ==========================================================================
   7. RESPONSIVE
   ========================================================================== */

@media (max-width: 768px) {
    /* Modal raccourcis en plein ecran sur mobile */
    .modal-raccourcis {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .raccourcis-grid {
        grid-template-columns: 1fr;
    }

    /* Reactions plus grandes pour touch */
    .reaction-chip {
        padding: 6px 12px;
        font-size: 16px;
    }

    .reaction-picker {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 16px 16px 0 0;
        padding: 16px;
        justify-content: center;
    }

    .reaction-picker-btn {
        width: 48px;
        height: 48px;
        font-size: 24px;
    }

    /* Presence header plus compact */
    .presence-header {
        padding: 6px 12px;
    }
}
