/* ===== SYSTÈME DE CHAT FLOTTANT ===== */

/* Container principal - masqué par défaut */
.floating-chat-container {
    display: none; /* Masqué par défaut */
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 9999;
}

/* Visible uniquement si l'utilisateur est connecté */
body.user-logged-in .floating-chat-container {
    display: block;
}

/* ===== BOUTON FLOTTANT CHAT ===== */

.floating-chat-button {
    position: fixed;
    bottom: 100px !important; /* Au milieu (30 + 60 + 10 = 100) */
    right: 30px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(139, 92, 246, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    transition: all 0.3s ease;
    z-index: 10000;
    animation: float-chat 3s ease-in-out infinite;
    position: relative;
}

.floating-chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 35px rgba(139, 92, 246, 0.6);
}

/* Tooltip pour le bouton chat */
.floating-chat-button::before {
    content: 'Chat';
    position: absolute;
    right: 75px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    border: 1px solid rgba(139, 92, 246, 0.5);
}

.floating-chat-button::after {
    content: '';
    position: absolute;
    right: 65px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 6px solid rgba(0, 0, 0, 0.9);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
}

.floating-chat-button:hover::before,
.floating-chat-button:hover::after {
    opacity: 1;
}

@keyframes float-chat {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-8px);
    }
}

/* Badge de notification */
.chat-notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
    animation: pulse-notification 2s ease-in-out infinite;
}

@keyframes pulse-notification {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* ===== PANEL DU CHAT ===== */

.chat-panel {
    position: fixed;
    top: 0;
    right: -450px; /* Caché à droite */
    width: 420px;
    height: 100vh;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.98), rgba(26, 26, 26, 0.98));
    box-shadow: -10px 0 50px rgba(0, 0, 0, 0.5);
    border-left: 2px solid rgba(139, 92, 246, 0.5);
    display: flex;
    flex-direction: column;
    transition: right 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 9998;
}

.chat-panel.active {
    right: 0; /* Visible */
}

/* Header du chat */
.chat-panel-header {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

.chat-panel-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-icon {
    font-size: 28px;
}

.chat-panel-title h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: white;
}

.chat-users-count {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    margin: 3px 0 0 0;
}

.chat-panel-close {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid white;
    border-radius: 50%;
    color: white;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-panel-close:hover {
    background: white;
    color: #8b5cf6;
    transform: rotate(90deg);
}

/* Body du chat */
.chat-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: rgba(0, 0, 0, 0.5);
}

.chat-panel-body::-webkit-scrollbar {
    width: 8px;
}

.chat-panel-body::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.chat-panel-body::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #8b5cf6, #6366f1);
    border-radius: 10px;
}

.chat-panel-body::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #6366f1, #8b5cf6);
}

/* Message de bienvenue */
.chat-welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: rgba(255, 255, 255, 0.6);
}

.chat-welcome-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.chat-welcome-message h4 {
    font-size: 18px;
    color: white;
    margin: 0 0 10px 0;
}

.chat-welcome-message p {
    font-size: 14px;
    margin: 0;
}

/* Container des messages */
.chat-messages-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Message individuel */
.chat-message-item {
    background: rgba(139, 92, 246, 0.1);
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 12px;
    padding: 12px 15px;
    animation: slideInRight 0.3s ease;
    border-left: 3px solid #8b5cf6;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.chat-message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.chat-message-username {
    font-weight: 700;
    color: #a78bfa;
    font-size: 14px;
}

.chat-message-time {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
}

.chat-message-text {
    font-size: 14px;
    color: white;
    line-height: 1.5;
    word-wrap: break-word;
}

/* Footer du chat */
.chat-panel-footer {
    padding: 20px;
    background: rgba(0, 0, 0, 0.8);
    border-top: 2px solid rgba(139, 92, 246, 0.3);
}

.chat-input-wrapper {
    display: flex;
    gap: 10px;
}

#chatMessageInput {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(139, 92, 246, 0.5);
    border-radius: 25px;
    padding: 12px 18px;
    color: white;
    font-size: 14px;
    transition: all 0.3s ease;
}

#chatMessageInput:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.15);
    border-color: #8b5cf6;
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.3);
}

#chatMessageInput::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.chat-send-button {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-send-button:hover {
    transform: scale(1.1);
    box-shadow: 0 5px 20px rgba(139, 92, 246, 0.5);
}

.chat-send-button:active {
    transform: scale(0.95);
}

/* ===== RESPONSIVE ===== */

@media (max-width: 768px) {
    .floating-chat-button {
        bottom: 90px !important; /* Ajusté pour mobile */
        right: 20px;
        width: 55px;
        height: 55px;
        font-size: 24px;
    }
    
    .chat-panel {
        width: 100%;
        right: -100%;
    }
    
    .chat-panel.active {
        right: 0;
    }
}

@media (max-width: 480px) {
    .floating-chat-button {
        bottom: 80px !important; /* Ajusté pour petit mobile */
        width: 50px;
        height: 50px;
        font-size: 22px;
    }
    
    .chat-panel-header {
        padding: 15px;
    }
    
    .chat-panel-title h3 {
        font-size: 18px;
    }
    
    .chat-panel-body {
        padding: 15px;
    }
    
    .chat-panel-footer {
        padding: 15px;
    }
}

/* ===== ÉTAT NON CONNECTÉ ===== */

/* Masquer le chat si NON connecté */
body:not(.user-logged-in) .floating-chat-container {
    display: none !important;
}

/* ===== OVERLAY POUR MOBILE ===== */

.chat-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9997;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.chat-overlay.active {
    display: block;
    opacity: 1;
}

@media (max-width: 768px) {
    .chat-panel.active ~ .chat-overlay {
        display: block;
        opacity: 1;
    }
}