/**
 * Syndic Tunisie - Chat Interface Styles
 * Design "Waww" - Modern Messenger/WhatsApp Style
 */

/* ============================================
   CSS Variables for Chat
   ============================================ */
:root {
    /* Chat Colors */
    --chat-primary: #1f4f5f;
    --chat-secondary: #4f5d2f;
    --chat-accent: #e67e22;
    --chat-accent-dark: #7b1e35;

    /* Message Bubbles */
    --chat-bubble-sent: #1f4f5f;
    --chat-bubble-sent-text: #ffffff;
    --chat-bubble-received: #ffffff;
    --chat-bubble-received-text: #1f2937;

    /* Chat UI */
    --chat-bg: #f3f5f4;
    --chat-sidebar-bg: #ffffff;
    --chat-header-bg: #ffffff;
    --chat-input-bg: #ffffff;
    --chat-border: rgba(31, 79, 95, 0.14);
    --chat-hover: rgba(31, 79, 95, 0.06);
    --chat-active: rgba(31, 79, 95, 0.12);

    /* Status Colors */
    --chat-online: #4f5d2f;
    --chat-offline: #94a3b8;
    --chat-unread: #7b1e35;

    /* Shadows */
    --chat-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --chat-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --chat-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);

    /* Animations */
    --chat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode */
[data-theme="dark"] {
    --chat-bubble-sent: #5f8b9a;
    --chat-bubble-sent-text: #ffffff;
    --chat-bubble-received: #273445;
    --chat-bubble-received-text: #e2e8f0;

    --chat-bg: #111827;
    --chat-sidebar-bg: #1f2937;
    --chat-header-bg: #1f2937;
    --chat-input-bg: #273445;
    --chat-border: rgba(255, 255, 255, 0.1);
    --chat-hover: rgba(255, 255, 255, 0.05);
    --chat-active: rgba(255, 255, 255, 0.1);
    --chat-online: #93a86b;
    --chat-unread: #d78396;
}

/* ============================================
   Chat Container Layout
   ============================================ */
.chat-container {
    display: flex;
    height: calc(100vh - 140px);
    min-height: 500px;
    background: var(--chat-bg);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: var(--chat-shadow-lg);
}

.chat-container-full {
    height: calc(100vh - 80px);
}

.chat-dock {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 420px;
    height: 600px;
    border-radius: 18px;
    z-index: 950;
}

.chat-embed .chat-dock {
    position: static;
    width: 100%;
    height: 100%;
    border-radius: 0;
    box-shadow: none;
}

.chat-embed .chat-dock-toggle {
    display: none;
}

.chat-embed .chat-container {
    flex-direction: row;
}

.chat-embed .chat-sidebar {
    width: 180px;
    min-width: 180px;
    max-height: none;
}

.chat-embed .chat-main {
    min-height: 0;
}

.chat-embed .chat-sidebar.hidden,
.chat-embed .chat-main.hidden {
    display: flex;
}

/* ──────────────────────────────────────────────────────────
   Embed (panel widget) : input en haut + messages récents d'abord
   ────────────────────────────────────────────────────────── */

/* Input remonte au-dessus de la zone messages */
.chat-embed .chat-input-area {
    order: -1;
    border-top: none;
    border-bottom: 1px solid var(--chat-border, rgba(31, 79, 95, 0.12));
}

/* Messages : plus récent en haut (flex column-reverse) */
.chat-embed .chat-messages {
    flex-direction: column-reverse;
}

/* Scrollbar reste propre avec column-reverse */
.chat-embed .chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-embed .chat-back-btn {
    display: none;
}

.chat-embed .chat-empty {
    padding: 16px;
}

.chat-embed .chat-empty-icon {
    width: 52px;
    height: 52px;
    font-size: 22px;
    margin-bottom: 12px;
}

.chat-embed .chat-empty-title {
    font-size: 14px;
}

.chat-embed .chat-empty-text {
    font-size: 12px;
}

.chat-dock.is-minimized {
    height: 56px;
    width: 320px;
    overflow: hidden;
}

.chat-dock.is-minimized .chat-search,
.chat-dock.is-minimized .chat-conversations,
.chat-dock.is-minimized .chat-main {
    display: none;
}

.chat-dock.is-minimized .chat-sidebar {
    width: 100%;
    min-width: 100%;
}

.chat-dock.is-minimized .chat-sidebar-header {
    border-bottom: none;
    padding: 10px 12px;
}

.chat-dock--single.is-minimized .chat-main {
    display: flex;
}

.chat-dock--single.is-minimized .chat-messages,
.chat-dock--single.is-minimized .chat-input-area,
.chat-dock--single.is-minimized .chat-file-preview,
.chat-dock--single.is-minimized .chat-upload-progress,
.chat-dock--single.is-minimized .chat-typing {
    display: none;
}

.chat-dock--single.is-minimized .chat-header {
    border-bottom: none;
}

.chat-dock--single.is-minimized .chat-header-info,
.chat-dock--single.is-minimized .chat-header-actions {
    display: none;
}

.chat-dock--single.is-minimized .chat-header {
    justify-content: space-between;
}

.chat-dock .chat-sidebar {
    width: 170px;
    min-width: 170px;
}

.chat-dock .chat-sidebar-header {
    padding: 12px;
}

.chat-sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.chat-sidebar-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--chat-primary);
}

[data-theme="dark"] .chat-sidebar-title {
    color: #e2e8f0;
}

.chat-dock-toggle {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: none;
    background: var(--chat-hover);
    color: var(--chat-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--chat-transition);
}

.chat-dock-toggle:hover {
    background: var(--chat-active);
    transform: translateY(-1px);
}

.chat-header-actions .chat-dock-toggle {
    background: transparent;
    color: var(--chat-offline);
}

.chat-header-actions .chat-dock-toggle:hover {
    color: var(--chat-primary);
    background: var(--chat-hover);
}

.chat-dock .chat-search input {
    padding: 10px 12px 10px 36px;
    font-size: 12px;
}

.chat-dock .chat-search-icon {
    left: 12px;
}

.chat-dock .chat-conv-item {
    padding: 10px 10px;
    border-radius: 12px;
}

.chat-dock .chat-conv-name {
    font-size: 13px;
}

.chat-dock .chat-conv-preview {
    font-size: 12px;
}

.chat-dock .chat-conv-time {
    font-size: 10px;
}

.chat-dock .chat-header {
    padding: 10px 12px;
}

.chat-dock .chat-messages {
    padding: 12px;
}

.chat-dock .chat-input-area {
    padding: 10px 12px;
}

.chat-dock .chat-input-wrapper {
    padding: 6px 6px 6px 14px;
    border-radius: 18px;
}

.chat-dock .chat-send-btn {
    width: 38px;
    height: 38px;
}

/* ============================================
   Chat Sidebar (Admin View)
   ============================================ */
.chat-sidebar {
    width: 320px;
    min-width: 320px;
    background: var(--chat-sidebar-bg);
    border-right: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(20px);
}

.chat-sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--chat-border);
}

.chat-search {
    position: relative;
}

.chat-search input {
    width: 100%;
    padding: 12px 16px 12px 44px;
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    background: var(--chat-input-bg);
    font-size: 14px;
    transition: var(--chat-transition);
}

.chat-search input:focus {
    outline: none;
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(15, 52, 96, 0.1);
}

.chat-search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--chat-offline);
    font-size: 18px;
}

.chat-conversations {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-conversations::-webkit-scrollbar {
    width: 6px;
}

.chat-conversations::-webkit-scrollbar-thumb {
    background: rgba(15, 52, 96, 0.2);
    border-radius: 3px;
}

/* Conversation Item */
.chat-conv-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-radius: 16px;
    cursor: pointer;
    transition: var(--chat-transition);
    margin-bottom: 4px;
}

.chat-conv-item:hover {
    background: var(--chat-hover);
    transform: translateX(4px);
}

.chat-conv-item.active {
    background: var(--chat-active);
    box-shadow: var(--chat-shadow-sm);
}

.chat-conv-item.unread {
    background: rgba(233, 75, 60, 0.05);
}

.chat-conv-item.unread:hover {
    background: rgba(233, 75, 60, 0.1);
}

/* Avatar */
.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    color: #ffffff;
    flex-shrink: 0;
    position: relative;
    text-transform: uppercase;
}

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

.chat-avatar.has-photo {
    background: transparent;
    color: transparent;
}

.chat-avatar.has-photo .chat-avatar-text {
    display: none;
}

.chat-avatar-sm {
    width: 40px;
    height: 40px;
    font-size: 14px;
}

.chat-avatar-lg {
    width: 56px;
    height: 56px;
    font-size: 20px;
}

/* Avatar Color Variations */
.chat-avatar-1 { background: #1f4f5f; }
.chat-avatar-2 { background: #4f5d2f; }
.chat-avatar-3 { background: #e67e22; }
.chat-avatar-4 { background: #7b1e35; }
.chat-avatar-5 { background: #6b7280; }
.chat-avatar-6 { background: #334155; }

/* Online Status Indicator */
.chat-status {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--chat-sidebar-bg);
}

.chat-status.online {
    background: var(--chat-online);
    animation: pulse-online 2s infinite;
}

.chat-status.offline {
    background: var(--chat-offline);
}

@keyframes pulse-online {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
    50% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
}

/* Conversation Info */
.chat-conv-info {
    flex: 1;
    min-width: 0;
    margin-left: 12px;
}

.chat-conv-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--chat-primary);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

[data-theme="dark"] .chat-conv-name {
    color: #e2e8f0;
}

.chat-conv-preview {
    font-size: 13px;
    color: var(--chat-offline);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conv-item.unread .chat-conv-preview {
    color: var(--chat-primary);
    font-weight: 500;
}

/* Conversation Meta */
.chat-conv-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin-left: 8px;
}

.chat-conv-time {
    font-size: 11px;
    color: var(--chat-offline);
    margin-bottom: 4px;
}

/* Unread Badge */
.chat-badge {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--chat-unread);
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: badge-pulse 2s infinite;
}

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

/* ============================================
   Chat Main Area
   ============================================ */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    min-width: 0;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    padding: 16px 24px;
    background: var(--chat-header-bg);
    border-bottom: 1px solid var(--chat-border);
    backdrop-filter: blur(20px);
}

.chat-header-info {
    flex: 1;
    margin-left: 16px;
}

.chat-header-name {
    font-weight: 700;
    font-size: 16px;
    color: var(--chat-primary);
}

[data-theme="dark"] .chat-header-name {
    color: #f1f5f9;
}

.chat-header-status {
    font-size: 13px;
    color: var(--chat-online);
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-header-status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chat-online);
}

.chat-header-status.offline {
    color: var(--chat-offline);
}

.chat-header-status.offline::before {
    background: var(--chat-offline);
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.chat-header-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--chat-hover);
    color: var(--chat-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
}

.chat-header-btn:hover {
    background: var(--chat-active);
    transform: scale(1.05);
}

/* ============================================
   Messages Area
   ============================================ */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(15, 52, 96, 0.2);
    border-radius: 3px;
}

/* Date Separator */
.chat-date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 16px 0;
}

.chat-date-separator span {
    background: rgba(15, 52, 96, 0.1);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 12px;
    color: var(--chat-offline);
    font-weight: 500;
}

[data-theme="dark"] .chat-date-separator span {
    background: rgba(255, 255, 255, 0.1);
}

/* Message Wrapper */
.chat-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 75%;
    animation: message-slide-in 0.3s ease-out;
}

.chat-message.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message.received {
    align-self: flex-start;
}

@keyframes message-slide-in {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.sent {
    animation-name: message-slide-in-right;
}

@keyframes message-slide-in-right {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.chat-message.received {
    animation-name: message-slide-in-left;
}

@keyframes message-slide-in-left {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Message Bubble */
.chat-bubble {
    padding: 12px 16px;
    border-radius: 20px;
    max-width: 100%;
    word-wrap: break-word;
    position: relative;
    box-shadow: var(--chat-shadow-sm);
}

.chat-message.sent .chat-bubble {
    background: var(--chat-bubble-sent);
    color: var(--chat-bubble-sent-text);
    border-bottom-right-radius: 6px;
}

.chat-message.received .chat-bubble {
    background: var(--chat-bubble-received);
    color: var(--chat-bubble-received-text);
    border-bottom-left-radius: 6px;
}

.chat-bubble-content {
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
}

/* Message Meta */
.chat-bubble-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
    font-size: 11px;
    opacity: 0.7;
}

.chat-bubble-time {
    font-weight: 500;
}

/* Read Status Checkmarks */
.chat-read-status {
    display: flex;
    font-size: 14px;
}

.chat-read-status.read {
    color: #60a5fa;
}

/* ============================================
   Typing Indicator
   ============================================ */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
}

.chat-typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--chat-bubble-received);
    border-radius: 20px;
    border-bottom-left-radius: 6px;
}

.chat-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chat-offline);
    animation: typing-bounce 1.4s infinite ease-in-out;
}

.chat-typing-dot:nth-child(1) { animation-delay: 0s; }
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ============================================
   Input Area
   ============================================ */
.chat-input-area {
    padding: 16px 24px;
    background: var(--chat-input-bg);
    border-top: 1px solid var(--chat-border);
    backdrop-filter: blur(20px);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--chat-bg);
    border-radius: 24px;
    padding: 8px 8px 8px 20px;
    border: 1px solid var(--chat-border);
    transition: var(--chat-transition);
}

.chat-input-wrapper:focus-within {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(15, 52, 96, 0.1);
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-size: 14px;
    line-height: 1.5;
    max-height: 120px;
    min-height: 24px;
    padding: 8px 0;
    font-family: inherit;
}

.chat-input:focus {
    outline: none;
}

.chat-input::placeholder {
    color: var(--chat-offline);
}

.chat-input-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-action-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--chat-offline);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: var(--chat-transition);
}

.chat-action-btn:hover {
    color: var(--chat-primary);
    background: var(--chat-hover);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--chat-bubble-sent);
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: var(--chat-transition);
}

.chat-send-btn:hover {
    transform: scale(1.05);
    box-shadow: var(--chat-shadow-md);
}

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

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

.chat-send-btn svg {
    transition: transform 0.3s ease;
}

.chat-send-btn:hover svg {
    transform: translateX(2px);
}

/* Character Counter */
.chat-char-count {
    font-size: 11px;
    color: var(--chat-offline);
    text-align: right;
    margin-top: 4px;
    padding-right: 8px;
}

.chat-char-count.warning {
    color: var(--chat-accent);
}

.chat-char-count.danger {
    color: var(--chat-unread);
}

/* ============================================
   File Attachment
   ============================================ */
.chat-file-input {
    display: none;
}

.chat-file-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--chat-hover);
    border-radius: 12px;
    margin-bottom: 8px;
}

.chat-file-preview-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--chat-primary);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-file-preview-info {
    flex: 1;
    min-width: 0;
}

.chat-file-preview-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-file-preview-size {
    font-size: 11px;
    color: var(--chat-offline);
}

.chat-file-preview-remove {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--chat-unread);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-file-preview-remove:hover {
    background: rgba(233, 75, 60, 0.1);
}

/* Message Attachments */
.chat-attachment {
    margin-top: 8px;
}

.chat-attachment-image {
    max-width: 280px;
    max-height: 200px;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--chat-transition);
}

.chat-attachment-image:hover {
    transform: scale(1.02);
}

.chat-attachment-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: var(--chat-transition);
}

.chat-message.received .chat-attachment-file {
    background: rgba(15, 52, 96, 0.1);
}

.chat-attachment-file:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chat-message.received .chat-attachment-file:hover {
    background: rgba(15, 52, 96, 0.15);
}

.chat-attachment-file-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.chat-message.received .chat-attachment-file-icon {
    background: var(--chat-primary);
    color: #ffffff;
}

.chat-attachment-file-info {
    flex: 1;
    min-width: 0;
}

.chat-attachment-file-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-attachment-file-size {
    font-size: 11px;
    opacity: 0.7;
}

/* Upload Progress */
.chat-upload-progress {
    padding: 12px;
    background: var(--chat-hover);
    border-radius: 12px;
    margin-bottom: 8px;
}

.chat-upload-progress-bar {
    height: 4px;
    background: var(--chat-border);
    border-radius: 2px;
    overflow: hidden;
}

.chat-upload-progress-fill {
    height: 100%;
    background: var(--chat-bubble-sent);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.chat-upload-progress-text {
    font-size: 12px;
    color: var(--chat-offline);
    margin-top: 6px;
    text-align: center;
}

/* ============================================
   Empty State
   ============================================ */
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
}

.chat-empty-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--chat-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    color: var(--chat-offline);
    margin-bottom: 20px;
}

.chat-empty-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--chat-primary);
    margin-bottom: 8px;
}

[data-theme="dark"] .chat-empty-title {
    color: #e2e8f0;
}

.chat-empty-text {
    font-size: 14px;
    color: var(--chat-offline);
    max-width: 280px;
}

/* ============================================
   Navigation Badge
   ============================================ */
.nav-chat-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--chat-unread);
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    margin-left: auto;
    animation: badge-pulse 2s infinite;
}

/* ============================================
   Notification Sound Indicator
   ============================================ */
.chat-sound-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--chat-offline);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: var(--chat-transition);
}

.chat-sound-toggle:hover {
    background: var(--chat-hover);
}

.chat-sound-toggle.muted {
    opacity: 0.5;
}

/* ============================================
   Image Lightbox
   ============================================ */
.chat-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.chat-lightbox.active {
    opacity: 1;
    visibility: visible;
}

.chat-lightbox img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
    box-shadow: var(--chat-shadow-lg);
}

.chat-lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
}

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

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 992px) {
    .chat-container {
        height: calc(100vh - 100px);
        border-radius: 16px;
    }

    .chat-sidebar {
        width: 280px;
        min-width: 280px;
    }

    .chat-dock {
        right: 16px;
        bottom: 16px;
        width: 380px;
        height: 560px;
    }
}

@media (max-width: 768px) {
    .chat-container {
        flex-direction: column;
        height: calc(100vh - 80px);
        border-radius: 0;
    }

    .chat-dock {
        position: static;
        width: 100%;
        height: calc(100vh - 80px);
        border-radius: 0;
    }

    .chat-sidebar {
        width: 100%;
        min-width: 100%;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--chat-border);
    }

    .chat-sidebar.hidden {
        display: none;
    }

    .chat-main {
        flex: 1;
        min-height: 0;
    }

    .chat-main.hidden {
        display: none;
    }

    .chat-message {
        max-width: 85%;
    }

    .chat-back-btn {
        display: flex;
    }
}

.chat-back-btn {
    display: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--chat-hover);
    color: var(--chat-primary);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
}

/* ============================================
   Animations
   ============================================ */
.chat-fade-in {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

/* New message notification */
.chat-new-message-indicator {
    position: sticky;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 20px;
    background: var(--chat-primary);
    color: #ffffff;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: var(--chat-shadow-md);
    animation: bounce-in 0.3s ease-out;
}

@keyframes bounce-in {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    50% {
        transform: translateX(-50%) translateY(-5px);
    }
    100% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ============================================
   Utilities
   ============================================ */
.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.chat-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--chat-border);
    border-top-color: var(--chat-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error state */
.chat-error {
    padding: 16px;
    background: rgba(233, 75, 60, 0.1);
    border: 1px solid rgba(233, 75, 60, 0.2);
    border-radius: 12px;
    color: var(--chat-unread);
    text-align: center;
    margin: 16px;
}

/* Success toast */
.chat-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    background: var(--chat-primary);
    color: #ffffff;
    border-radius: 12px;
    font-size: 14px;
    box-shadow: var(--chat-shadow-lg);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 9998;
}

.chat-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ============================================
   Floating Chat Button + Panel
   ============================================ */
.chat-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 980;
}

.chat-fab--berg {
    right: 170px; /* 24px + 130px (button width) + 16px (gap) */
}

.chat-fab-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 130px;
    height: 46px;
    border-radius: 999px;
    border: none;
    background: var(--chat-accent);
    color: #ffffff;
    font-weight: 700;
    box-shadow: var(--chat-shadow-md);
    cursor: pointer;
    transition: var(--chat-transition);
    position: relative;
    padding: 0 16px;
}

/* BERG IA button distinct color (green) */
.chat-fab--berg .chat-fab-btn {
    background: var(--chat-secondary);
}

.chat-fab-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--chat-shadow-lg);
}

.chat-fab-label {
    font-size: 13px;
    white-space: nowrap;
}

.chat-fab-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--chat-unread);
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: var(--chat-shadow-sm);
}

/* Panels s'ouvrent vers le bas depuis le topbar */
.chat-fab-panel {
    position: fixed;
    right: 16px;
    top: 68px;  /* sous le topbar sticky */
    bottom: auto;
    width: 760px;
    height: 600px;
    max-height: calc(100vh - 82px);
    background: var(--card, #eef2f0);
    color: var(--text, #0f172a);
    border-radius: 18px;
    box-shadow: var(--shadow, 0 12px 36px rgba(15, 23, 42, 0.18));
    overflow: hidden;
    z-index: 1050;
    display: none;
    border: 1px solid var(--line, rgba(15, 52, 96, 0.12));
}

[data-theme="dark"] .chat-fab-panel {
    background: var(--card, #1e293b);
    border-color: var(--line, rgba(255, 255, 255, 0.1));
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

/* BERG IA panel : même ancrage droit, z-index supérieur */
.chat-fab-panel--berg {
    right: 16px;
    z-index: 1051;
}

.chat-fab-panel.is-open {
    display: flex;
    flex-direction: column;
    animation: slideDownFab 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideDownFab {
    from { opacity: 0; transform: translateY(-10px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.chat-fab-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    font-weight: 700;
    font-size: 15px;
    border-bottom: 1px solid var(--line, rgba(15, 52, 96, 0.1));
    background: var(--bg, #f8fafc);
    color: var(--text, #0f172a);
    flex-shrink: 0;
}

[data-theme="dark"] .chat-fab-panel-header {
    background: #1e293b; /* Couleur de fond solide et sombre */
    border-color: rgba(255, 255, 255, 0.1);
    color: #f8fafc; /* Texte clair pour contraste max */
}

.chat-fab-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: rgba(15, 52, 96, 0.1);
    color: var(--text, #0f172a);
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

[data-theme="dark"] .chat-fab-close {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
}

.chat-fab-close:hover {
    background: var(--bad, #ef4444);
    color: #ffffff;
    transform: scale(1.05);
}

.chat-fab-frame {
    width: 100%;
    flex: 1;
    border: 0;
    display: block;
    background: var(--card, #eef2f0);
}

@media (max-width: 1100px) {
    .chat-fab-panel {
        right: 12px;
        top: 62px;
        width: calc(100vw - 270px); /* s'adapte à la largeur dispo (sidebar ~240px) */
        max-width: 760px;
        height: 560px;
        max-height: calc(100vh - 76px);
    }

    .chat-fab-panel--berg {
        right: 12px;
    }
}

@media (max-width: 768px) {
    .chat-fab-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        z-index: 2000; /* Plein écran sur mobile */
    }

    .chat-fab-panel--berg {
        right: 0;
        top: 0;
        bottom: 0;
    }
    
    .chat-fab-panel-header {
        padding: 16px;
    }
    
    .chat-fab-close {
        width: 40px;
        height: 40px;
    }
}

/* ============================================
   Sidebar Sections — Adhérents inscrits
   ============================================ */

/* Label de section (Conversations / Adhérents) */
.chat-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--chat-offline);
    padding: 10px 18px 5px;
    user-select: none;
}

/* Item adhérent sans conversation (nouveau) */
.chat-conv-item.chat-conv-new {
    opacity: 0.82;
}
.chat-conv-item.chat-conv-new:hover {
    opacity: 1;
    background: var(--chat-hover);
}
.chat-conv-item.chat-conv-new .chat-conv-preview {
    color: var(--chat-offline);
    font-style: italic;
    font-size: 12px;
}
.chat-conv-item.chat-conv-new .chat-avatar {
    border: 1.5px dashed var(--chat-border);
}
