/* Minimalist and Modern Chat UI */

/* Root Variables for Consistency */
:root {
    --primary-bg: #f7f9fc;
    --primary-accent: linear-gradient(135deg, #6b7280, #3b82f6);
    --secondary-accent: #10b981;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --bubble-sent: linear-gradient(135deg, #3b82f6, #60a5fa);
    --bubble-received: #e5e7eb;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --neumorphic-shadow: 4px 4px 8px rgba(0, 0, 0, 0.1), -4px -4px 8px rgba(255, 255, 255, 0.8);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset and Base Styles */
.chat-bubble, .chat-modal, .chat-container {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    box-sizing: border-box;
}

/* Fournisseur Bubble */
.chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--secondary-accent);
    color: #fff;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--neumorphic-shadow);
    transition: var(--transition);
    z-index: 9999;
}

.chat-bubble:hover {
    transform: scale(1.05);
    background: linear-gradient(135deg, #10b981, #34d399);
}

.chat-bubble .badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #fff;
    border-radius: 50%;
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 600;
    display: none;
    box-shadow: var(--shadow);
}

/* Fournisseur Modal */
.chat-modal {
    display: none;
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 360px;
    height: 520px;
    background: var(--primary-bg);
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    z-index: 9999;
}

.chat-modal-header {
    background: var(--primary-accent);
    color: #fff;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 16px;
    font-weight: 600;
}

.chat-modal-header .close-chat {
    cursor: pointer;
    font-size: 20px;
    transition: var(--transition);
}

.chat-modal-header .close-chat:hover {
    transform: rotate(90deg);
}

.chat-modal-body {
    height: 330px;
    overflow-y: auto;
    padding: 16px;
    background: rgba(255, 255, 255, 0.7);
    scrollbar-width: thin;
    scrollbar-color: #6b7280 #e5e7eb;
}

.chat-modal-body::-webkit-scrollbar {
    width: 6px;
}

.chat-modal-body::-webkit-scrollbar-track {
    background: #e5e7eb;
    border-radius: 3px;
}

.chat-modal-body::-webkit-scrollbar-thumb {
    background: #6b7280;
    border-radius: 3px;
}

.chat-modal-body.loading::before {
    content: 'Chargement...';
    display: block;
    text-align: center;
    padding: 10px;
    color: var(--text-secondary);
    font-size: 14px;
}

.chat-modal-footer {
    padding: 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-modal-footer textarea {
    width: 100%;
    resize: none;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 12px;
    height: 48px;
    font-size: 14px;
    background: #fff;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
    transition: var(--transition);
    display: block;
}

.chat-modal-footer textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chat-modal-footer .button-container {
    display: flex;
    justify-content: flex-end;
}

.chat-modal-footer .btn {
    padding: 8px 16px;
    background: var(--primary-accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.chat-modal-footer .btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.chat-modal-footer .btn .spinner {
    display: none;
}

.chat-modal-footer .btn .spinner i {
    font-size: 14px;
}

.chat-modal-footer .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* SAV WhatsApp-like Interface */
.chat-container {
    display: flex;
    height: 640px;
    background: var(--primary-bg);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.chat-sidebar {
    width: 30%;
    border-right: 1px solid rgba(0, 0, 0, 0.05);
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.9);
    scrollbar-width: thin;
    scrollbar-color: #6b7280 #e5e7eb;
}

.chat-sidebar::-webkit-scrollbar {
    width: 6px;
}

.chat-sidebar::-webkit-scrollbar-track {
    background: #e5e7eb;
    border-radius: 3px;
}

.chat-sidebar::-webkit-scrollbar-thumb {
    background: #6b7280;
    border-radius: 3px;
}

.search-container {
    padding: 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.search-container input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
    transition: var(--transition);
}

.search-container input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.contact-list {
    max-height: 580px;
    overflow-y: auto;
}

.chat-sidebar .contact {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: var(--transition);
}

.chat-sidebar .contact:hover {
    background: rgba(0, 0, 0, 0.02);
}

.chat-sidebar .contact.active {
    background: var(--primary-accent);
    color: #fff;
}

.chat-sidebar .contact.active .name,
.chat-sidebar .contact.active .unread {
    color: #fff;
}

.chat-sidebar .contact .name {
    font-weight: 500;
    font-size: 15px;
    color: var(--text-primary);
}

.chat-sidebar .contact .unread {
    float: right;
    background: #ef4444;
    color: #fff;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 500;
    display: none;
}

.chat-main {
    width: 70%;
    display: flex;
    flex-direction: column;
}

.chat-main-header {
    background: var(--primary-accent);
    color: #fff;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    font-size: 16px;
    font-weight: 600;
}

.chat-main-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: rgba(229, 231, 235, 0.5);
    scrollbar-width: thin;
    scrollbar-color: #6b7280 #e5e7eb;
}

.chat-main-body::-webkit-scrollbar {
    width: 6px;
}

.chat-main-body::-webkit-scrollbar-track {
    background: #e5e7eb;
    border-radius: 3px;
}

.chat-main-body::-webkit-scrollbar-thumb {
    background: #6b7280;
    border-radius: 3px;
}

.chat-main-body.loading::before {
    content: 'Chargement...';
    display: block;
    text-align: center;
    padding: 10px;
    color: var(--text-secondary);
    font-size: 14px;
}

.chat-main-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-main-footer textarea {
    width: 100%;
    resize: none;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    background: #fff;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
    transition: var(--transition);
}

.chat-main-footer textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chat-main-footer .btn {
    padding: 8px 16px;
    background: var(--primary-accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    align-self: flex-end;
}

.chat-main-footer .btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.chat-main-footer .btn .spinner {
    margin-left: 8px;
}

.chat-main-footer .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Shared Message Styles */
.chat-message {
    margin: 8px 0;
    display: flex;
    flex-direction: column;
}

.chat-message.sent {
    align-items: flex-end;
}

.chat-message.received {
    align-items: flex-start;
}

.chat-message .sender-name {
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-secondary);
}

.chat-message.sent .sender-name {
    color: #60a5fa;
}

.chat-message .bubble {
    display: inline-block;
    padding: 8px 12px;
    border-radius: 12px;
    max-width: 70%;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    transition: var(--transition);
}

.chat-message .bubble:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.chat-message.sent .bubble {
    background: var(--bubble-sent);
    color: #fff;
}

.chat-message.received .bubble {
    background: var(--bubble-received);
    color: var(--text-primary);
}

.chat-message .time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}