/**
 * Styles pour la messagerie client
 * Widget de chat flottant
 */

/* Force la structure flex correcte de la fenêtre */
.client-chat-window {
    flex-direction: column !important;
    height: 600px !important;
    min-height: 450px !important;
    max-height: calc(100vh - 120px) !important;
    position: fixed !important;
    bottom: 90px !important;
    right: 20px !important;
    width: 480px !important; /* Augmenté de 380px à 480px pour plus de confort */
    max-width: calc(100vw - 40px) !important;
    background: #fff !important;
    border-radius: 15px !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2) !important;
    z-index: 9999 !important;
    overflow: hidden !important;
}

/* Responsive : sur mobile, prendre plus de largeur */
@media (max-width: 768px) {
    .client-chat-window {
        width: calc(100vw - 20px) !important;
        right: 10px !important;
        bottom: 70px !important;
    }
}

/* Masquer par défaut */
.client-chat-window:not(.show) {
    display: none !important;
}

/* Afficher quand la classe 'show' est présente */
.client-chat-window.show {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Afficher quand style inline est appliqué */
.client-chat-window[style*="display: flex"],
.client-chat-window[style*="display: block"] {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* En-tête - Toujours visible en haut */
.client-chat-header {
    flex: 0 0 auto !important; /* Ne grandit ni ne se réduit */
    height: auto !important;
    min-height: 60px !important;
    padding: 15px 20px !important;
}

/* Bouton de fermeture - Toujours cliquable */
.client-chat-header .close-btn {
    pointer-events: auto !important;
    cursor: pointer !important;
    z-index: 10 !important;
    position: relative !important;
}

/* Zone des messages - Prend l'espace central */
.client-messages-container {
    flex: 1 1 auto !important; /* Grandit pour remplir l'espace disponible */
    overflow-y: auto !important;
    overflow-x: hidden !important;
    min-height: 200px !important;
    padding: 15px !important;
}

/* Zone de saisie - Toujours visible en bas */
.client-message-input-area {
    flex: 0 0 auto !important; /* Ne grandit ni ne se réduit */
    padding: 10px 15px !important;
    margin: 0 !important;
    background: #fff !important;
    border-top: 1px solid #e0e0e0 !important;
}

/* Container de saisie */
.client-message-input-container {
    display: flex !important;
    gap: 8px !important;
    align-items: center !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Bouton d'upload - Toujours visible */
.client-file-upload-btn {
    display: flex !important;
    width: 40px !important;
    height: 40px !important;
    flex-shrink: 0 !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    background: #fff !important;
    border: 1px solid #ddd !important;
    color: #667eea !important;
    cursor: pointer !important;
}

.client-file-upload-btn:hover {
    background: #f5f5f5 !important;
    border-color: #667eea !important;
}

/* Textarea - Fond blanc, texte noir */
.client-message-input-container textarea {
    flex: 1 1 auto !important;
    height: 40px !important;
    min-height: 40px !important;
    max-height: 80px !important;
    background: #ffffff !important;
    color: #000000 !important;
    border: 1px solid #ddd !important;
    border-radius: 20px !important;
    padding: 10px 15px !important;
    font-size: 14px !important;
    resize: none !important;
}

.client-message-input-container textarea::placeholder {
    color: #999 !important;
}

/* Bouton d'envoi - Toujours visible */
.client-message-input-container button {
    display: flex !important;
    width: 40px !important;
    height: 40px !important;
    flex-shrink: 0 !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
    border: none !important;
    cursor: pointer !important;
}

/* Prévisualisation de fichier */
#clientFilePreviewContainer {
    flex: 0 0 auto !important;
    max-height: 120px !important;
}

/* Bouton de chat flottant */
.client-chat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    z-index: 9998;
    transition: all 0.3s ease;
}

.client-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(102, 126, 234, 0.6);
}

/* Badge de messages non lus */
.client-chat-toggle .badge,
#clientChatUnreadBadge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 24px;
    height: 24px;
    padding: 4px 8px;
    border-radius: 12px;
    background: #ff4444 !important;
    color: #fff !important;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(255, 68, 68, 0.5);
    animation: pulse-badge 2s ease-in-out infinite;
}

/* Badge spécial pour devis en attente */
#clientChatUnreadBadge.badge-quote-pending {
    background: #ff4444 !important;
    color: #fff !important;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(255, 68, 68, 0.7);
    animation: pulse-badge 2s ease-in-out infinite;
}

/* Badge pour messages normaux */
#clientChatUnreadBadge.badge-messages {
    background: #667eea !important;
    color: #fff !important;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.5);
    animation: pulse-badge 2s ease-in-out infinite;
}

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


/* Fenêtre de chat */
.client-chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 550px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
    min-height: 400px; /* Hauteur minimale pour garantir l'affichage */
}

.client-chat-window.show {
    display: flex !important;
}

/* S'assurer que tous les enfants directs respectent le flex */
.client-chat-window > * {
    width: 100%;
}

/* En-tête du chat */
.client-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* Ne se réduit jamais */
    min-height: 70px;
}

.client-chat-header h5 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.client-chat-header .close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.client-chat-header .close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Zone des messages */
.client-messages-container {
    flex: 1 1 0; /* Prend l'espace disponible mais peut se réduire à 0 */
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: #f5f5f5;
    min-height: 200px; /* Hauteur minimale pour lire */
    height: 0; /* Important : force le calcul flex */
}

/* Messages */
.client-message {
    margin-bottom: 15px;
    display: flex;
}

.client-message.message-user {
    justify-content: flex-end;
}

.client-message.message-admin {
    justify-content: flex-start;
}

.client-message-bubble {
    max-width: 85%; /* Augmenté de 75% à 85% pour plus d'espace */
    padding: 10px 14px;
    border-radius: 18px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    word-wrap: break-word;
}

/* Messages spéciaux (devis) prennent plus de largeur */
.client-message-bubble .quote-message {
    max-width: 100% !important;
    width: 100% !important;
}

/* Bouton "Voir la commande" */
.client-message-bubble .btn-success {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%) !important;
    border: none !important;
    color: #fff !important;
    font-weight: 500 !important;
    transition: all 0.3s ease !important;
}

.client-message-bubble .btn-success:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.4) !important;
}

/* Styles pour la popup de devis - Mode Sombre */
#quoteModal .modal-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%) !important;
    color: #fff !important;
    border: 1px solid #0f3460;
}

#quoteModal .modal-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: #fff !important;
    border-bottom: 2px solid #533c8e;
}

#quoteModal .modal-footer {
    background: #16213e !important;
    border-top: 2px solid #0f3460;
}

#quoteModal .btn-close {
    filter: invert(1);
}

.quote-details {
    font-size: 14px;
    color: #fff !important;
}

.quote-details h6,
.quote-details h5,
.quote-details p,
.quote-details span,
.quote-details strong {
    color: #fff !important;
}

.quote-details .text-muted {
    color: #b0b0b0 !important;
}

.quote-details .table {
    color: #fff !important;
    background-color: transparent !important;
}

.quote-details .table th {
    background-color: #0f3460 !important;
    border-top: none;
    border-bottom: 2px solid #533c8e !important;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #fff !important;
}

.quote-details .table td {
    border-top: 1px solid #0f3460 !important;
    border-bottom: 1px solid #0f3460 !important;
    vertical-align: middle;
    color: #fff !important;
    background-color: transparent !important;
}

.quote-details .table tbody tr {
    background-color: transparent !important;
}

.quote-details .table tbody tr:hover {
    background-color: rgba(15, 52, 96, 0.3) !important;
}

/* Assurer que tout le texte dans le tableau est blanc */
.quote-details .table th *,
.quote-details .table td * {
    color: #fff !important;
}

/* Classe text-end dans le tableau */
.quote-details .table .text-end {
    color: #fff !important;
}

.quote-details .bg-light {
    background: #0f3460 !important;
    border: 1px solid #533c8e !important;
}

.quote-details .badge {
    font-size: 11px;
    padding: 6px 12px;
}

/* Boutons dans la popup */
#quoteModalFooter .btn {
    font-weight: 500;
    padding: 8px 16px;
}

#quoteModalFooter .btn-secondary {
    background: #4a4a4a !important;
    border: none;
    color: #fff !important;
}

#quoteModalFooter .btn-success {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%) !important;
    border: none;
    color: #fff !important;
}

#quoteModalFooter .btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    border: none;
    color: #fff !important;
}



.message-user .client-message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message-admin .client-message-bubble {
    background: #fff;
    color: #333;
    border-bottom-left-radius: 4px;
}

.client-message-time {
    font-size: 10px;
    margin-top: 5px;
    opacity: 0.7;
}

.message-user .client-message-time {
    text-align: right;
}

/* Messages spéciaux */
.quote-message {
    background: #fff !important;
    border: 2px solid #2196F3;
    padding: 12px;
    border-radius: 12px;
    color: #333 !important;
}

.quote-message strong {
    color: #2196F3;
}

.system-message {
    background: #fffbea !important;
    color: #856404 !important;
    text-align: center;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
}

/* Zone de saisie */
.client-message-input-area {
    padding: 12px 15px; /* Réduit le padding vertical */
    background: #fff;
    border-top: 1px solid #e0e0e0;
    flex-shrink: 0; /* Empêche la zone de saisie de se réduire */
    flex-grow: 0; /* Ne grandit pas */
    width: 100%;
    position: relative;
    min-height: 60px; /* Hauteur minimale ajustée */
    box-sizing: border-box;
}

.client-message-input-container {
    display: flex !important;
    gap: 8px;
    align-items: center; /* Alignement centré pour meilleure visibilité */
    width: 100%;
}

.client-message-input-container textarea {
    flex: 1 1 auto;
    border: 1px solid #e0e0e0 !important;
    border-radius: 20px;
    padding: 10px 15px;
    resize: none;
    max-height: 60px; /* Réduit pour laisser de la place */
    min-height: 40px;
    height: 40px; /* Hauteur par défaut */
    font-size: 14px;
    font-family: inherit;
    background: #ffffff !important;
    color: #000000 !important;
    line-height: 1.4;
}

.client-message-input-container textarea::placeholder {
    color: #999 !important;
}

.client-message-input-container textarea:focus {
    outline: none;
    border-color: #667eea;
    background: #ffffff !important;
    color: #000000 !important;
}

.client-message-input-container button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    display: flex !important;
    align-items: center;
    justify-content: center;
}

.client-message-input-container button:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.client-message-input-container button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Bouton d'upload de fichiers */
.client-file-upload-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid #e0e0e0;
    background: #fff;
    color: #667eea;
    cursor: pointer;
    transition: all 0.2s;
    display: flex !important;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin: 0;
}

.client-file-upload-btn:hover {
    background: #f5f5f5;
    border-color: #667eea;
    transform: scale(1.05);
}

.client-file-upload-btn i {
    font-size: 16px;
}

/* Prévisualisation de fichier */
.client-file-preview-item {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #333;
}

.client-file-preview-item img,
.client-file-preview-item video {
    max-width: 100px;
    max-height: 100px;
    border-radius: 6px;
    object-fit: cover;
}

.client-file-preview-item .remove-file {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #f44336;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
}

.client-file-preview-item .remove-file:hover {
    background: #d32f2f;
}

/* Indicateur de nouveaux messages */
.new-message-indicator {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: #667eea;
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    display: none;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    z-index: 10;
    opacity: 0;
    transition: all 0.3s ease;
}

.new-message-indicator.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.new-message-indicator:hover {
    background: #5568d3;
    transform: translateX(-50%) translateY(-2px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.5);
}

.new-message-indicator i {
    animation: bounce 1s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

/* Scrollbar personnalisée */
.client-messages-container::-webkit-scrollbar {
    width: 5px;
}

.client-messages-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.client-messages-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.client-messages-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Animations */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.client-chat-window {
    animation: slideInUp 0.3s ease-out;
}

.client-message {
    animation: slideInUp 0.2s ease-out;
}

/* Indicateur de frappe */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #999;
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

/* Badge de statut */
.online-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4caf50;
    display: inline-block;
    margin-right: 8px;
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.3);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.3);
    }
    50% {
        box-shadow: 0 0 0 5px rgba(76, 175, 80, 0.1);
    }
}

/* Responsive */
@media (max-width: 480px) {
    .client-chat-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        right: 10px;
        bottom: 80px;
    }
    
    .client-chat-toggle {
        width: 55px;
        height: 55px;
        font-size: 22px;
    }
    
    .client-message-bubble {
        max-width: 85%;
    }
}

/* Dark mode support (optionnel) */
@media (prefers-color-scheme: dark) {
    .client-chat-window {
        background: #2d2d2d;
    }
    
    .message-admin .client-message-bubble {
        background: #3d3d3d;
        color: #f0f0f0;
    }
    
    .client-messages-container {
        background: #1e1e1e;
    }
    
    .client-message-input-area {
        background: #2d2d2d;
        border-top-color: #444;
    }
    
    .client-message-input-container textarea {
        background: #3d3d3d;
        color: #f0f0f0;
        border-color: #444;
    }
}

