/* Conteneur principal du chat */
.espoir-chat-widget {
    position: fixed;
    bottom: 100px;
    right: 80px;
    z-index: 9998;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 180px);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: espoirChatSlideUp 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.espoir-chat-widget.open {
    display: flex;
}

@keyframes espoirChatSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ===== HEADER ===== */
.espoir-chat-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, #0d6efd 0%, #1977cc 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.espoir-chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.espoir-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.espoir-chat-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.espoir-chat-header-info {
    display: flex;
    flex-direction: column;
}

.espoir-chat-header-info h6 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: white;
}

.espoir-chat-header-info span {
    font-size: 12px;
    opacity: 0.8;
}

.espoir-chat-status-online {
    color: #4ade80;
}

.espoir-chat-status-offline {
    color: #f87171;
}

.espoir-chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background 0.2s;
    line-height: 1;
}

.espoir-chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ===== TYPE SELECTION ===== */
.espoir-chat-type-select {
    padding: 12px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.espoir-chat-type-btn {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid #dee2e6;
    border-radius: 20px;
    background: white;
    color: #6c757d;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.espoir-chat-type-btn:hover {
    border-color: #0d6efd;
    color: #0d6efd;
}

.espoir-chat-type-btn.active {
    border-color: #0d6efd;
    background: #e7f1ff;
    color: #0d6efd;
}

/* ===== MEDECIN SELECTION ===== */
.espoir-chat-medecin-select {
    padding: 12px 20px;
    background: #fff;
    border-bottom: 1px solid #e9ecef;
    flex-shrink: 0;
    display: none;
}

.espoir-chat-medecin-select.show {
    display: block;
}

.espoir-chat-medecin-select select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    font-size: 13px;
    background: white;
}

/* ===== MESSAGES ===== */
.espoir-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 200px;
}

.espoir-chat-message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: espoirMsgFadeIn 0.3s ease;
}

@keyframes espoirMsgFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.espoir-chat-message.patient {
    align-self: flex-end;
    background: #0d6efd;
    color: white;
    border-bottom-right-radius: 4px;
}

.espoir-chat-message.medecin {
    align-self: flex-start;
    background: white;
    color: #212529;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.espoir-chat-message.ia {
    align-self: flex-start;
    background: #e8f5e9;
    color: #1b5e20;
    border-bottom-left-radius: 4px;
}

.espoir-chat-message.systeme {
    align-self: center;
    background: #fff3cd;
    color: #856404;
    font-size: 12px;
    padding: 6px 14px;
    border-radius: 20px;
    max-width: 90%;
    text-align: center;
}

.espoir-chat-message .msg-time {
    font-size: 10px;
    opacity: 0.7;
    margin-top: 4px;
    display: block;
}

.espoir-chat-message.patient .msg-time {
    text-align: right;
    color: rgba(255, 255, 255, 0.8);
}

.espoir-chat-message .msg-avatar {
    display: none;
}

/* ===== TYPING INDICATOR ===== */
.espoir-chat-typing {
    display: none;
    padding: 8px 16px;
    font-size: 13px;
    color: #6c757d;
    font-style: italic;
}

.espoir-chat-typing.show {
    display: block;
}

.espoir-chat-typing-dots {
    display: inline-block;
    animation: espoirTypingDots 1.4s infinite;
}

@keyframes espoirTypingDots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60% { content: '...'; }
}

/* ===== INPUT ===== */
.espoir-chat-input-area {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #e9ecef;
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.espoir-chat-input-area textarea {
    flex: 1;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    resize: none;
    outline: none;
    font-family: inherit;
    max-height: 80px;
    transition: border-color 0.2s;
    background: #f8f9fa;
}

.espoir-chat-input-area textarea:focus {
    border-color: #0d6efd;
    background: white;
}

.espoir-chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: #0d6efd;
    color: white;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.espoir-chat-send-btn:hover {
    background: #0b5ed7;
    transform: scale(1.05);
}

.espoir-chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .espoir-chat-widget {
        bottom: 80px;
        right: 10px;
        width: calc(100vw - 20px);
        height: calc(100vh - 150px);
        max-height: calc(100vh - 150px);
        border-radius: 12px;
    }
    
    .espoir-chat-message {
        max-width: 90%;
        font-size: 13px;
        padding: 8px 12px;
    }
    
    .espoir-chat-header {
        padding: 12px 16px;
    }
    
    .espoir-chat-messages {
        padding: 12px 14px;
    }
    
    .espoir-chat-input-area {
        padding: 8px 12px;
    }
    
    .espoir-chat-input-area textarea {
        font-size: 13px;
        padding: 6px 12px;
    }
    
    .espoir-chat-type-btn {
        font-size: 12px;
        padding: 6px 10px;
    }
}

@media (max-width: 480px) {
    .espoir-chat-widget {
        bottom: 75px;
        right: 8px;
        width: calc(100vw - 16px);
        height: calc(100vh - 140px);
        max-height: calc(100vh - 140px);
        border-radius: 10px;
    }
    
    .espoir-chat-header-info h6 {
        font-size: 13px;
    }
}

/* ===== SCROLLBAR ===== */
.espoir-chat-messages::-webkit-scrollbar {
    width: 4px;
}

.espoir-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.espoir-chat-messages::-webkit-scrollbar-thumb {
    background: #ced4da;
    border-radius: 4px;
}

.espoir-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #adb5bd;
}