/* Chat Widget Styles */
.chat-widget {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Chat Message Notifications */
@keyframes slideInRight {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

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

/* Chat Color Variables */
:root {
    --chat-primary: #192e4c;
    --chat-secondary: #f4dbab;
    --chat-sent-bubble: #ffefef;
    --chat-received-bubble: #fffce6;
}

/* Product Banner Styles */
.chat-product-banner {
    border-bottom: 1px solid #bae6fd;
    margin: 0;
    padding: 1rem;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
}

.chat-product-banner-content {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.chat-product-image {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    background: white;
    border: 1px solid #bae6fd;
}

.chat-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-product-banner-info {
    flex: 1;
    min-width: 0;
}

.chat-product-banner-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: #1e293b;
    margin-bottom: 0.5rem;
}

.chat-product-banner-link {
    font-size: 0.9375rem;
    color: #1F3A5F;
    text-decoration: none;
    font-weight: 600;
    display: block;
    margin-bottom: 0.5rem;
    line-height: 1.4;
    transition: color 0.2s;
}

.chat-product-banner-link:hover {
    color: #0f172a;
    text-decoration: underline;
}

.chat-product-banner-link svg {
    display: inline-block;
    vertical-align: middle;
    margin-left: 0.25rem;
}

/* Toggle Button */
.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
    padding: 0;
    overflow: visible;
}

.chat-toggle-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.chat-icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
    display: block;
}

.chat-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--chat-primary);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    border: 2px solid white;
}

/* Panneau liste dans le widget ; z-index inférieur aux popups (.chat-popups-container). */
/* Limité au widget pour ne pas affecter la page projets /projects/{id}/chat */
.chat-widget .chat-container {
    position: absolute;
    bottom: 80px;
    left: 0;
    width: 380px;
    height: 600px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    z-index: 10001;
}

/* Réseau : icône à gauche, panneau liste des discussions à droite (comme marketplace) */
.network-page .chat-widget .chat-container {
    position: fixed;
    left: auto;
    right: 0;
    top: 0;
    bottom: auto;
    width: 380px;
    max-width: calc(100vw - 24px);
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
    transition: transform 0.3s ease-out, visibility 0.3s;
    transform: translateX(100%);
    visibility: hidden;
    pointer-events: none;
}

.network-page .chat-widget .chat-container.chat-panel-open {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
}

/* Marketplace: alignement identique au réseau (bulle ancrée à gauche) */
.marketplace-page .chat-widget,
.marketplace-mobile-page .chat-widget {
    left: 20px;
    right: auto;
}

.marketplace-page .chat-widget .chat-container,
.marketplace-mobile-page .chat-widget .chat-container {
    position: fixed;
    left: auto;
    right: 0;
    top: 0;
    bottom: auto;
    width: 380px;
    max-width: calc(100vw - 24px);
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
    transition: transform 0.3s ease-out, visibility 0.3s;
    transform: translateX(100%);
    visibility: hidden;
    pointer-events: none;
}

.marketplace-page .chat-widget .chat-container.chat-panel-open,
.marketplace-mobile-page .chat-widget .chat-container.chat-panel-open {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
}

/* Chat Header */
.chat-header {
    padding: 16px;
    background: var(--chat-primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.chat-close-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Conversations List */
.chat-conversations-list {
    flex: 1;
    overflow-y: auto;
    background: #f8f9fa;
}

.chat-conversation-item {
    padding: 12px 16px;
    border-bottom: 1px solid #e9ecef;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.2s;
}

.chat-conversation-item:hover {
    background: var(--chat-secondary);
}

.chat-conversation-avatar {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    border-radius: 50%;
    overflow: hidden;
    background: #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #495057;
    flex-shrink: 0;
    position: relative;
}

.chat-conversation-avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.chat-conversation-avatar > div {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
}
.chat-conversation-avatar .chat-group-avatar {
    font-size: 1.25rem;
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
}
.chat-conversation-project-group {
    border-left: 3px solid #3b82f6;
}

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

.chat-conversation-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 2px;
}

.chat-conversation-name {
    font-weight: 600;
    color: #212529;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.chat-conversation-preview {
    font-size: 14px;
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conversation-time {
    font-size: 12px;
    color: #adb5bd;
    flex-shrink: 0;
}

.chat-conversation-time:empty {
    display: none;
}

.chat-conversation-unread {
    background: var(--chat-primary);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
}

/* Chat Window */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
    min-height: 0;
}

.chat-window-header {
    padding: 12px 16px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--chat-secondary);
}

.chat-back-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: #495057;
}

.chat-recipient-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.chat-recipient-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #495057;
}

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

.chat-recipient-name {
    font-weight: 600;
    color: #212529;
}

/* Messages Area */
.chat-messages-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    position: relative;
    min-height: 0;
    max-height: 100%;
}

.chat-message {
    display: flex;
    gap: 8px;
    max-width: 75%;
    width: auto;
    align-self: flex-start;
    animation: slideIn 0.3s ease-out;
}

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

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

.chat-message-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    border-radius: 50%;
    overflow: hidden;
    background: #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    position: relative;
    font-weight: 600;
    color: #495057;
    flex-shrink: 0;
}

.chat-message-avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.chat-message-avatar > div {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: inherit;
}

.chat-message-content {
    background: var(--chat-received-bubble);
    padding: 10px 14px;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.chat-message.sent .chat-message-content {
    background: var(--chat-sent-bubble);
    color: #333;
}

.chat-message-text {
    margin: 0;
    word-wrap: break-word;
    line-height: 1.5;
}
.chat-message-link {
    color: var(--chat-primary, #1F3A5F);
    text-decoration: underline;
}
.chat-message-link:hover {
    text-decoration: none;
}
.chat-message.sent .chat-message-link {
    color: #0d3a6e;
}

.chat-message-time {
    font-size: 11px;
    color: #6c757d;
    margin-top: 4px;
}

.chat-message.sent .chat-message-time {
    color: #6c757d;
}

.chat-message-attachment {
    margin-top: 8px;
}

.chat-message-attachment img,
.chat-message-attachment video {
    max-width: 100%;
    border-radius: 8px;
}

.chat-message-youtube {
    margin-top: 8px;
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
}

.chat-message-youtube iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 8px;
}

.chat-message-audio {
    margin-top: 8px;
}

.chat-message-audio audio {
    width: 100%;
}

.chat-message-file {
    margin-top: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-message.sent .chat-message-file {
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.chat-message-file a {
    color: inherit;
    text-decoration: none;
    flex: 1;
}

/* Input Area */
.chat-input-area {
    padding: 12px;
    border-top: 1px solid #e9ecef;
    background: white;
    flex-shrink: 0;
    min-height: fit-content;
}

.chat-input-tools {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.chat-tool-btn {
    background: none;
    border: none;
    color: #6c757d;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: background 0.2s;
}

.chat-tool-btn:hover {
    background: var(--chat-secondary);
}

.chat-youtube-input {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px;
    background: var(--chat-secondary);
    border-radius: 8px;
}

.chat-youtube-input input {
    flex: 1;
    padding: 6px 12px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 14px;
}

.chat-youtube-input button {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.chat-audio-recorder {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px;
    background: var(--chat-secondary);
    border-radius: 8px;
}

/* Preview Area */
.chat-preview-area {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0 16px 16px 16px;
    border: 1px solid rgba(160, 13, 38, 0.2);
    border-radius: 8px;
    background: var(--chat-secondary);
    overflow: hidden;
    max-height: 200px;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.chat-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--chat-primary);
    color: white;
    border-bottom: 1px solid rgba(160, 13, 38, 0.3);
    font-size: 12px;
    font-weight: 600;
}

.chat-preview-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

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

.chat-preview-content {
    padding: 8px 12px;
    max-height: 150px;
    overflow-y: auto;
}

.chat-preview-item {
    position: relative;
    margin-bottom: 8px;
}

.chat-preview-item:last-child {
    margin-bottom: 0;
}

.chat-preview-image {
    max-width: 100%;
    max-height: 120px;
    border-radius: 6px;
    display: block;
    object-fit: contain;
}

.chat-preview-video {
    max-width: 100%;
    max-height: 120px;
    border-radius: 6px;
    display: block;
}

.chat-preview-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: white;
    border-radius: 6px;
    border: 1px solid #dee2e6;
}

.chat-preview-file-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e9ecef;
    border-radius: 4px;
    flex-shrink: 0;
}

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

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

.chat-preview-file-size {
    font-size: 12px;
    color: #6c757d;
}

.chat-preview-remove {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.chat-preview-remove:hover {
    background: #f8d7da;
}

.chat-preview-youtube {
    padding: 8px;
    background: white;
    border-radius: 6px;
    border: 1px solid #dee2e6;
}

.chat-preview-youtube-url {
    font-size: 14px;
    color: #495057;
    word-break: break-all;
}

.chat-audio-timer {
    flex: 1;
    text-align: center;
    font-weight: 600;
    color: #495057;
}

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.chat-message-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #dee2e6;
    border-radius: 24px;
    resize: none;
    font-size: 14px;
    font-family: inherit;
    max-height: 120px;
    min-height: 44px;
}

.chat-message-input:focus {
    outline: none;
    border-color: var(--chat-primary);
}

.chat-send-btn {
    padding: 10px 20px;
    background: var(--chat-primary);
    color: white;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    transition: background 0.2s, opacity 0.2s;
    height: 44px;
    flex-shrink: 0;
}

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

.chat-send-btn:not(:disabled):hover {
    background: #8a0b20;
}

.chat-loading {
    padding: 20px;
    text-align: center;
    color: #6c757d;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    /* Widget positioning on mobile */
    .chat-widget {
        bottom: 16px;
        left: 16px;
        right: auto;
        margin: 0;
        width: auto;
        height: auto;
    }
    
    /* Ensure container is independent and centered when open */
    .chat-widget .chat-container {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        width: 100dvw !important;
        height: 100vh !important;
        height: 100dvh !important;
        margin: 0 !important;
        padding: 0 !important;
        transform: none !important;
    }
    
    /* Toggle button - larger and more accessible on mobile */
    .chat-toggle-btn {
        width: 56px;
        height: 56px;
        box-shadow: 0 4px 16px rgba(160, 13, 38, 0.4);
    }
    
    .chat-toggle-btn:active {
        transform: scale(0.95);
    }
    
    .chat-unread-badge {
        width: 22px;
        height: 22px;
        font-size: 11px;
        top: -3px;
        right: -3px;
    }
    
    /* Full screen container on mobile - perfectly centered */
    .chat-container {
        width: 100vw !important;
        width: 100dvw !important; /* Dynamic viewport width for mobile browsers */
        height: 100vh !important;
        height: 100dvh !important; /* Dynamic viewport height for mobile browsers */
        bottom: 0 !important;
        left: 0 !important;
        top: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        border-radius: 0 !important;
        position: fixed !important;
        max-width: none !important;
        max-height: none !important;
        transform: none !important;
        box-sizing: border-box !important;
    }
    
    /* Header - larger touch targets */
    .chat-header {
        padding: 16px 20px;
        min-height: 56px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    
    .chat-header h3 {
        font-size: 20px;
    }
    
    .chat-close-btn {
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
        border-radius: 50%;
        transition: background 0.2s;
    }
    
    .chat-close-btn:active {
        background: rgba(255, 255, 255, 0.2);
    }
    
    /* Conversations list - better spacing */
    .chat-conversation-item {
        padding: 16px 20px;
        min-height: 72px;
        gap: 16px;
    }
    
    .chat-conversation-item:active {
        background: var(--chat-secondary);
    }
    
    .chat-conversation-avatar {
        width: 52px;
        height: 52px;
    }
    
    .chat-conversation-name {
        font-size: 16px;
        margin-bottom: 6px;
    }
    
    .chat-conversation-preview {
        font-size: 15px;
    }
    
    .chat-conversation-time {
        font-size: 13px;
        margin-top: 6px;
    }
    
    .chat-conversation-unread {
        width: 22px;
        height: 22px;
        font-size: 12px;
    }
    
    /* Chat window header - mobile optimized */
    .chat-window-header {
        padding: 14px 16px;
        min-height: 56px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }
    
    .chat-back-btn {
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
        border-radius: 50%;
        transition: background 0.2s;
    }
    
    .chat-back-btn:active {
        background: rgba(0, 0, 0, 0.1);
    }
    
    .chat-recipient-avatar {
        width: 44px;
        height: 44px;
    }
    
    .chat-recipient-name {
        font-size: 17px;
    }
    
    /* Messages area - better padding and spacing */
    .chat-messages-area {
        padding: 16px 12px;
        gap: 16px;
        /* Account for safe area on devices with notches */
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
    
    /* Messages - larger on mobile, better touch targets */
    .chat-message {
        max-width: 85%;
        gap: 10px;
    }
    
    .chat-message-avatar {
        width: 36px;
        height: 36px;
        font-size: 13px;
    }
    
    .chat-message-content {
        padding: 12px 16px;
        border-radius: 16px;
        font-size: 15px;
        line-height: 1.5;
    }
    
    .chat-message-text {
        font-size: 15px;
        line-height: 1.6;
    }
    
    .chat-message-time {
        font-size: 12px;
        margin-top: 6px;
    }
    
    /* Product banner - mobile optimized */
    .chat-product-banner {
        padding: 0.75rem !important;
    }
    
    .chat-product-image {
        width: 60px !important;
        height: 60px !important;
    }
    
    .chat-product-banner-title {
        font-size: 0.8125rem !important;
    }
    
    .chat-product-banner-link {
        font-size: 0.75rem !important;
    }
    
    /* Input area - mobile optimized */
    .chat-input-area {
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        border-top: 1px solid #e9ecef;
        background: white;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
    }
    
    .chat-input-tools {
        gap: 12px;
        margin-bottom: 10px;
        flex-wrap: wrap;
    }
    
    .chat-tool-btn {
        padding: 10px;
        min-width: 44px;
        min-height: 44px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #f8f9fa;
        transition: all 0.2s;
    }
    
    .chat-tool-btn:active {
        background: var(--chat-secondary);
        transform: scale(0.95);
    }
    
    .chat-tool-btn svg {
        width: 22px;
        height: 22px;
    }
    
    /* YouTube input - mobile friendly */
    .chat-youtube-input {
        padding: 12px;
        gap: 10px;
        margin-bottom: 10px;
        flex-wrap: wrap;
    }
    
    .chat-youtube-input input {
        flex: 1;
        min-width: 0;
        padding: 10px 14px;
        font-size: 15px;
        min-height: 44px;
    }
    
    .chat-youtube-input button {
        padding: 10px 16px;
        min-height: 44px;
        font-size: 15px;
        border-radius: 8px;
    }
    
    /* Audio recorder - mobile optimized */
    .chat-audio-recorder {
        padding: 12px;
        gap: 10px;
        margin-bottom: 10px;
    }
    
    .chat-audio-timer {
        font-size: 16px;
    }
    
    .chat-audio-recorder button {
        padding: 10px 16px;
        min-height: 44px;
        font-size: 15px;
        border-radius: 8px;
    }
    
    /* Input row - better spacing */
    .chat-input-row {
        gap: 10px;
        align-items: flex-end;
    }
    
    .chat-message-input {
        padding: 12px 16px;
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 48px;
        max-height: 150px;
        border-radius: 24px;
        line-height: 1.5;
    }
    
    .chat-send-btn {
        padding: 12px 24px;
        min-width: 80px;
        min-height: 48px;
        font-size: 15px;
        border-radius: 24px;
        font-weight: 600;
    }
    
    .chat-send-btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    /* Preview area - mobile optimized */
    .chat-preview-area {
        margin: 0 12px 12px 12px;
        max-height: 180px;
        border-radius: 12px;
    }
    
    .chat-preview-header {
        padding: 10px 14px;
        font-size: 13px;
        min-height: 44px;
    }
    
    .chat-preview-close {
        padding: 6px;
        min-width: 32px;
        min-height: 32px;
        border-radius: 50%;
    }
    
    .chat-preview-content {
        padding: 10px 14px;
        max-height: 130px;
    }
    
    .chat-preview-image,
    .chat-preview-video {
        max-height: 100px;
    }
    
    /* Message attachments - better sizing */
    .chat-message-attachment img,
    .chat-message-attachment video {
        max-width: 100%;
        max-height: 250px;
        border-radius: 12px;
    }
    
    .chat-message-youtube {
        border-radius: 12px;
    }
    
    /* Loading state */
    .chat-loading {
        padding: 24px;
        font-size: 15px;
    }
    
    /* Safe area support for devices with notches */
    @supports (padding: max(0px)) {
        .chat-container {
            padding-top: env(safe-area-inset-top);
            padding-bottom: env(safe-area-inset-bottom);
            padding-left: env(safe-area-inset-left);
            padding-right: env(safe-area-inset-right);
        }
        
        .chat-header {
            padding-top: max(16px, env(safe-area-inset-top));
        }
        
        .chat-input-area {
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }
    }
}

/* Extra small devices (phones in portrait) */
@media (max-width: 480px) {
    .chat-toggle-btn {
        width: 52px;
        height: 52px;
        bottom: 12px;
        left: 12px;
    }
    
    .chat-message {
        max-width: 90%;
    }
    
    .chat-message-content {
        padding: 10px 14px;
        font-size: 14px;
    }
    
    .chat-input-tools {
        gap: 8px;
    }
    
    .chat-tool-btn {
        min-width: 40px;
        min-height: 40px;
        padding: 8px;
    }
    
    .chat-tool-btn svg {
        width: 20px;
        height: 20px;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .chat-container {
        width: 100vw !important;
        width: 100dvw !important;
        height: 100vh !important;
        height: 100dvh !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .chat-header {
        min-height: 48px;
        padding: 12px 20px;
    }
    
    .chat-messages-area {
        padding: 12px;
    }
    
    .chat-input-area {
        padding: 10px 16px;
    }
    
    .chat-message-input {
        min-height: 44px;
        font-size: 15px;
    }
    
    .chat-send-btn {
        min-height: 44px;
        padding: 10px 20px;
    }
}

/* ========== Popups de discussion (plusieurs fenêtres en bas) ========== */
.chat-popups-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    justify-content: flex-start;
    z-index: 10050; /* au-dessus du panneau liste (.chat-container 10001) */
    max-width: calc(100vw - 100px);
    pointer-events: none;
}
.chat-popups-container > * {
    pointer-events: auto;
}

.chat-popup {
    width: 340px;
    height: 420px;
    min-height: 320px;
    max-height: 80vh;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
    animation: chatPopupSlideUp 0.25s ease-out;
}
@keyframes chatPopupSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-popup-header {
    padding: 10px 12px;
    background: #811A1B;
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
}
.chat-popup-header-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.chat-popup-header-avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.chat-popup-header-avatar > div {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
    color: white;
}
.chat-popup-title {
    font-weight: 600;
    font-size: 0.9375rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}
.chat-popup-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.chat-popup-header-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255,255,255,0.2);
    color: white;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.chat-popup-header-btn:hover {
    background: rgba(255,255,255,0.35);
}
.chat-popup-close {
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(255,255,255,0.2);
    color: white;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}
.chat-popup-close:hover {
    background: rgba(255,255,255,0.35);
}

.chat-popup-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    background: #f8f9fa;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
}
.chat-popup-messages .chat-message {
    margin-bottom: 0;
    max-width: 82%;
    width: auto;
    align-self: flex-start;
}
.chat-popup-messages .chat-message.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.chat-popup-messages .chat-loading {
    text-align: center;
    color: #6c757d;
    padding: 1rem;
    width: 100%;
}

/* Members popup */
.chat-popup-members {
    max-width: 320px;
}
.chat-popup-members .chat-popup-header {
    padding: 10px 12px;
}
.chat-popup-members-list {
    padding: 12px;
    max-height: 280px;
    overflow-y: auto;
}
.chat-popup-member-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}
.chat-popup-member-item:last-child {
    border-bottom: none;
}
.chat-member-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.chat-member-avatar-placeholder {
    background: #811A1B;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
}
.chat-popup-member-name {
    font-size: 0.9375rem;
    color: #333;
}
.chat-member-banned {
    font-size: 0.75rem;
    color: #999;
    font-weight: normal;
}

.chat-popup-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px 12px;
    background: #f1f5f9;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}
.chat-popup-tool-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #475569;
    transition: background 0.2s, color 0.2s;
}
.chat-popup-tool-btn:hover {
    background: var(--chat-primary, #1F3A5F);
    color: white;
}
.chat-popup-tool-btn svg {
    width: 16px;
    height: 16px;
}
.chat-popup-youtube-row {
    display: flex;
    gap: 6px;
    padding: 6px 12px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    align-items: center;
    flex-shrink: 0;
}
.chat-popup-youtube-row input {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.8125rem;
}
.chat-popup-youtube-ok,
.chat-popup-youtube-cancel {
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.8125rem;
    cursor: pointer;
    border: none;
}
.chat-popup-youtube-ok {
    background: var(--chat-primary, #1F3A5F);
    color: white;
}
.chat-popup-youtube-cancel {
    background: #e2e8f0;
    color: #475569;
}
.chat-popup-input-row {
    padding: 10px 12px;
    background: white;
    border-top: 1px solid #e9ecef;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}
.chat-popup-input-row textarea {
    flex: 1;
    min-height: 40px;
    max-height: 100px;
    padding: 8px 12px;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    font-size: 0.9375rem;
    resize: none;
    font-family: inherit;
}
.chat-popup-input-row textarea:focus {
    outline: none;
    border-color: var(--chat-primary);
}
.chat-popup-send {
    padding: 8px 14px;
    background: var(--chat-primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    flex-shrink: 0;
}
.chat-popup-send:hover {
    filter: brightness(1.1);
}
.chat-popup-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ========== Panneau Messages dans la sidebar (bordeaux + icône bulle) ========== */
.sidebar-chat-panel .sidebar-panel-title {
    background: #811A1B;
    color: white;
    border-radius: 8px;
}
.sidebar-chat-panel .sidebar-panel-title:hover {
    background: #9a2021;
    color: white;
}
.sidebar-chat-panel .sidebar-accordion-arrow {
    color: rgba(255, 255, 255, 0.9);
}
.sidebar-chat-panel .sidebar-panel-icon.sidebar-chat-panel-icon {
    width: 18px;
    height: 18px;
    object-fit: contain;
    flex-shrink: 0;
}

/* ========== Liste des messages (sidebar accueil réseau) – UI/UX revue ========== */
#sidebarChatAccordionContent.sidebar-accordion-content,
.sidebar-accordion-content[data-content="messages"] {
    padding: 0 !important;
}

.sidebar-chat-list-wrap {
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    min-height: 120px;
}

.sidebar-chat-list-hint {
    font-size: 0.8125rem;
    color: var(--gray-500, #6b7280);
    margin: 0 0 0.75rem 0;
    padding: 1px 1.25rem;
    line-height: 1.4;
}

.sidebar-chat-conversations-list {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-radius: 10px;
    overflow: hidden;
}

/* Conteneur scrollable de la liste (élément déplacé par JS) */
.sidebar-chat-conversations-list .chat-conversations-list {
    flex: 1;
    min-height: 0;
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--gray-50, #f9fafb);
    border-radius: 10px;
    padding: 0.375rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

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

.sidebar-chat-conversations-list .chat-conversations-list::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-chat-conversations-list .chat-conversations-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

/* Carte conversation dans la sidebar */
.sidebar-chat-conversations-list .chat-conversation-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0.625rem;
    margin-bottom: 0.375rem;
    border-radius: 10px;
    border: none;
    background: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    cursor: pointer;
    transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.sidebar-chat-conversations-list .chat-conversation-item:last-child {
    margin-bottom: 0;
}

.sidebar-chat-conversations-list .chat-conversation-item:hover {
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

.sidebar-chat-conversations-list .chat-conversation-item:active {
    transform: translateY(0);
}

/* Avatar dans la sidebar */
.sidebar-chat-conversations-list .chat-conversation-avatar {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 12px;
    overflow: hidden;
    background: linear-gradient(135deg, #e5e7eb 0%, #d1d5db 100%);
    flex-shrink: 0;
}

.sidebar-chat-conversations-list .chat-conversation-info {
    flex: 1;
    min-width: 0;
}

.sidebar-chat-conversations-list .chat-conversation-head {
    margin-bottom: 2px;
}

.sidebar-chat-conversations-list .chat-conversation-name {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--gray-900, #111827);
}

.sidebar-chat-conversations-list .chat-conversation-time {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--gray-400, #9ca3af);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.sidebar-chat-conversations-list .chat-conversation-preview {
    font-size: 0.8125rem;
    color: var(--gray-500, #6b7280);
    line-height: 1.35;
}

/* Badge non lus dans la sidebar */
.sidebar-chat-conversations-list .chat-conversation-unread {
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.35rem;
    font-size: 0.6875rem;
    font-weight: 700;
    color: white;
    background: #811A1B;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* État vide et chargement dans la sidebar */
.sidebar-chat-conversations-list .chat-loading {
    padding: 2rem 1rem;
    text-align: center;
    font-size: 0.875rem;
    color: var(--gray-500, #6b7280);
    background: white;
    border-radius: 10px;
    margin: 0.375rem 0;
    line-height: 1.5;
}

.sidebar-chat-unread {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.35rem;
    margin-left: 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
    background: #811A1B;
    border-radius: 999px;
    vertical-align: middle;
}