/* ============================================================
   MESSAGES AVD — messages-avd.css v1.0
   Design system aligné sur drive.css
   ============================================================ */

/* ════════════════════════════════════════════════════════════
   1. APP LAYOUT
════════════════════════════════════════════════════════════ */
#avMessagesApp {
    display: flex;
    height: 100vh;
    overflow: hidden;
    position: relative;
    background: var(--avd-bg);
}

/* ── Override main pour messages ─────────────────────────── */
#avdMain {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100vh;
    overflow: hidden;
    min-width: 0;
}

/* ════════════════════════════════════════════════════════════
   2. MESSAGES CONTENT ZONE (2 colonnes)
════════════════════════════════════════════════════════════ */
#avdMessagesContent {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

/* ════════════════════════════════════════════════════════════
   3. CONVERSATIONS PANEL (colonne gauche)
════════════════════════════════════════════════════════════ */
.avm-conversations-panel {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--avd-border);
    background: var(--avd-sidebar-bg);
    overflow: hidden;
}
body.light-mode .avm-conversations-panel {
    box-shadow: 2px 0 12px rgba(0,0,0,0.06);
}

/* Liste scrollable */
.avm-conv-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}
.avm-conv-list::-webkit-scrollbar { width: 3px; }
.avm-conv-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
}
body.light-mode .avm-conv-list::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.1);
}

/* ── Conversation item ───────────────────────────────────── */
.avm-conv-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: var(--avd-transition);
    border-bottom: 1px solid var(--avd-border);
    position: relative;
}
.avm-conv-item:hover {
    background: rgba(255,255,255,0.04);
}
body.light-mode .avm-conv-item:hover {
    background: rgba(0,0,0,0.03);
}
.avm-conv-item.active {
    background: rgba(102,126,234,0.1);
    border-left: 3px solid var(--avd-primary);
}
.avm-conv-item.unread .avm-conv-name {
    font-weight: 800;
    color: var(--avd-text);
}
.avm-conv-item.unread .avm-conv-preview {
    color: var(--avd-text-muted);
}

/* Avatar conversation */
.avm-conv-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--avd-primary), var(--avd-primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}
.avm-conv-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
.avm-conv-avatar.group {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border-radius: 14px;
}
.avm-conv-online-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--avd-green);
    border: 2px solid var(--avd-sidebar-bg);
}

/* Infos conversation */
.avm-conv-info {
    flex: 1;
    min-width: 0;
}
.avm-conv-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 3px;
}
.avm-conv-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--avd-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.avm-conv-time {
    font-size: 10px;
    color: var(--avd-text-dim);
    flex-shrink: 0;
}
.avm-conv-preview {
    font-size: 11px;
    color: var(--avd-text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.avm-conv-unread-badge {
    font-size: 9px;
    font-weight: 800;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 20px;
    background: var(--avd-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ════════════════════════════════════════════════════════════
   4. CHAT PANEL (colonne droite)
════════════════════════════════════════════════════════════ */
.avm-chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--avd-bg);
    overflow: hidden;
}

/* ── Empty state ─────────────────────────────────────────── */
.avm-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
}
.avm-empty-icon {
    font-size: 56px;
    color: var(--avd-text-dim);
    margin-bottom: 20px;
    opacity: 0.5;
}
.avm-empty-title {
    font-size: 18px;
    font-weight: 800;
    color: var(--avd-text-muted);
    margin-bottom: 8px;
}
.avm-empty-sub {
    font-size: 13px;
    color: var(--avd-text-dim);
    line-height: 1.6;
}

/* ── Chat active ─────────────────────────────────────────── */
.avm-chat-active {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Chat header ─────────────────────────────────────────── */
.avm-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--avd-border);
    background: var(--avd-header-bg);
    backdrop-filter: blur(20px);
    flex-shrink: 0;
    min-height: 60px;
}
.avm-back-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid var(--avd-border);
    background: var(--avd-input-bg);
    color: var(--avd-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    transition: var(--avd-transition);
    flex-shrink: 0;
}
.avm-back-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--avd-text);
}
.avm-chat-header-user {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.avm-chat-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--avd-primary), var(--avd-primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
    overflow: hidden;
}
.avm-chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.avm-chat-header-avatar.group {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border-radius: 12px;
}
.avm-chat-header-name {
    font-size: 14px;
    font-weight: 800;
    color: var(--avd-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.avm-chat-header-status {
    font-size: 11px;
    color: var(--avd-text-dim);
    margin-top: 1px;
}
.avm-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.avm-chat-action-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid var(--avd-border);
    background: var(--avd-input-bg);
    color: var(--avd-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    transition: var(--avd-transition);
}
.avm-chat-action-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--avd-text);
    border-color: var(--avd-border-hover);
}
body.light-mode .avm-chat-action-btn:hover {
    background: rgba(0,0,0,0.06);
}

/* ── Messages container ──────────────────────────────────── */
.avm-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.avm-messages::-webkit-scrollbar { width: 4px; }
.avm-messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
}
body.light-mode .avm-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.12);
}

/* ── Message bubbles ─────────────────────────────────────── */
.avm-message-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 72%;
    animation: avdFadeIn 0.18s ease;
}
.avm-message-row.sent {
    margin-left: auto;
    flex-direction: row-reverse;
}
.avm-message-row.received {
    margin-right: auto;
}

.avm-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--avd-primary), var(--avd-primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
    overflow: hidden;
}
.avm-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.avm-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.55;
    max-width: 100%;
    word-break: break-word;
    position: relative;
}
.avm-message-row.sent .avm-bubble {
    background: linear-gradient(135deg, var(--avd-primary), var(--avd-primary-dark));
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 16px rgba(102,126,234,0.35);
}
.avm-message-row.received .avm-bubble {
    background: var(--avd-card);
    color: var(--avd-text);
    border: 1px solid var(--avd-border);
    border-bottom-left-radius: 4px;
}
body.light-mode .avm-message-row.received .avm-bubble {
    background: #ffffff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.avm-msg-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 3px;
    font-size: 10px;
    color: var(--avd-text-dim);
}
.avm-message-row.sent .avm-msg-meta {
    justify-content: flex-end;
}
.avm-msg-check {
    font-size: 10px;
    color: var(--avd-text-dim);
}
.avm-msg-check.read { color: var(--avd-primary); }

/* Date separator */
.avm-date-separator {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 14px 0;
    color: var(--avd-text-dim);
    font-size: 11px;
    font-weight: 600;
}
.avm-date-separator::before,
.avm-date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--avd-border);
}

/* Sender name (groups) */
.avm-sender-name {
    font-size: 10px;
    font-weight: 700;
    color: var(--avd-primary);
    margin-bottom: 3px;
    padding-left: 2px;
}

/* Typing indicator */
.avm-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--avd-card);
    border: 1px solid var(--avd-border);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    margin-bottom: 4px;
}
.avm-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--avd-text-dim);
    animation: avmTyping 1.2s infinite;
}
.avm-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.avm-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes avmTyping {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%            { transform: translateY(-5px); opacity: 1; }
}

/* ── Attachment preview ──────────────────────────────────── */
.avm-attachment-preview {
    padding: 10px 18px;
    border-top: 1px solid var(--avd-border);
    background: var(--avd-sidebar-bg);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
}
.avm-attachment-thumb {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--avd-border);
    flex-shrink: 0;
}
.avm-attachment-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.avm-attachment-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* ── Input bar ───────────────────────────────────────────── */
.avm-input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 18px;
    border-top: 1px solid var(--avd-border);
    background: var(--avd-header-bg);
    backdrop-filter: blur(20px);
    flex-shrink: 0;
}

.avm-attach-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--avd-border);
    background: var(--avd-input-bg);
    color: var(--avd-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: var(--avd-transition);
    flex-shrink: 0;
}
.avm-attach-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--avd-text);
}
body.light-mode .avm-attach-btn:hover { background: rgba(0,0,0,0.06); }

.avm-input {
    flex: 1;
    background: var(--avd-input-bg);
    border: 1px solid var(--avd-border);
    border-radius: 12px;
    padding: 10px 16px;
    font-family: inherit;
    font-size: 13px;
    color: var(--avd-text);
    outline: none;
    transition: var(--avd-transition);
    min-width: 0;
}
.avm-input::placeholder { color: var(--avd-text-dim); }
.avm-input:focus {
    border-color: var(--avd-primary);
    background: rgba(102,126,234,0.06);
    box-shadow: 0 0 0 3px rgba(102,126,234,0.12);
}

.avm-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, var(--avd-primary), var(--avd-primary-dark));
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    transition: var(--avd-transition);
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(102,126,234,0.4);
}
.avm-send-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 22px rgba(102,126,234,0.55);
}
.avm-send-btn:disabled {
    opacity: 0.5;
    transform: none;
    cursor: not-allowed;
}

/* ════════════════════════════════════════════════════════════
   5. SEARCH RESULTS DROPDOWN
════════════════════════════════════════════════════════════ */
#userSearchResults {
    background: #1e293b;
    border: 1px solid var(--avd-border);
    border-radius: 14px;
    padding: 6px;
    max-height: 280px;
    overflow-y: auto;
    box-shadow: var(--avd-shadow-lg);
}
body.light-mode #userSearchResults {
    background: #ffffff;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.avm-search-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: var(--avd-transition);
}
.avm-search-result-item:hover {
    background: rgba(255,255,255,0.06);
}
body.light-mode .avm-search-result-item:hover {
    background: rgba(0,0,0,0.04);
}
.avm-search-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--avd-primary), var(--avd-primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
}
.avm-search-name {
    font-size: 12px;
    font-weight: 700;
    color: var(--avd-text);
}
.avm-search-email {
    font-size: 10px;
    color: var(--avd-text-dim);
}

/* ════════════════════════════════════════════════════════════
   6. GROUP MODAL EXTRAS
════════════════════════════════════════════════════════════ */
.avm-group-photo-upload {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}
.avm-group-photo-preview {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    background: rgba(245,158,11,0.12);
    border: 2px dashed rgba(245,158,11,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: var(--avd-amber);
    flex-shrink: 0;
    overflow: hidden;
}
.avm-group-photo-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 16px;
}

.avm-textarea {
    resize: vertical;
    min-height: 70px;
    max-height: 140px;
    line-height: 1.5;
}

.avm-member-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 500;
    background: #1e293b;
    border: 1px solid var(--avd-border);
    border-radius: 12px;
    padding: 6px;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: var(--avd-shadow-lg);
    margin-top: 4px;
}
body.light-mode .avm-member-results {
    background: #ffffff;
}

.avm-selected-members {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}
.avm-member-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px 4px 8px;
    background: rgba(102,126,234,0.12);
    border: 1px solid rgba(102,126,234,0.25);
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    color: var(--avd-primary);
}
.avm-member-chip button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--avd-primary);
    font-size: 10px;
    display: flex;
    align-items: center;
    padding: 0;
    opacity: 0.7;
    transition: opacity 0.15s;
}
.avm-member-chip button:hover { opacity: 1; }

/* ── Unread badge dans header filter ─────────────────────── */
.avd-msg-badge {
    font-size: 9px;
    font-weight: 800;
    padding: 1px 6px;
    border-radius: 20px;
    background: var(--avd-primary);
    color: #fff;
    margin-left: 4px;
}

/* ════════════════════════════════════════════════════════════
   7. LOADING STATE
════════════════════════════════════════════════════════════ */
.avm-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px;
    color: var(--avd-text-dim);
    font-size: 12px;
    font-weight: 600;
}

/* ════════════════════════════════════════════════════════════
   8. LIGHT MODE OVERRIDES
════════════════════════════════════════════════════════════ */
body.light-mode .avm-conversations-panel {
    background: #ffffff;
}
body.light-mode .avm-conv-item:last-child {
    border-bottom: none;
}
body.light-mode .avm-chat-panel {
    background: #f1f5f9;
}
body.light-mode .avm-messages {
    background: #f1f5f9;
}
body.light-mode .avm-message-row.received .avm-bubble {
    background: #ffffff;
    border-color: rgba(0,0,0,0.08);
    color: #1e293b;
}
body.light-mode .avm-input-bar {
    background: rgba(255,255,255,0.97);
}
body.light-mode .avm-chat-header {
    background: rgba(255,255,255,0.97);
}

/* ════════════════════════════════════════════════════════════
   9. RESPONSIVE — TABLET (≤ 900px)
════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
    .avm-conversations-panel {
        width: 280px;
    }
}

/* ════════════════════════════════════════════════════════════
   10. RESPONSIVE — MOBILE (≤ 768px)
════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    #avdMessagesContent {
        position: relative;
    }

    /* Les 2 colonnes prennent 100% en mobile */
    .avm-conversations-panel {
        position: absolute;
        inset: 0;
        width: 100%;
        z-index: 10;
        transition: transform 0.3s ease;
    }
    .avm-conversations-panel.hidden-mobile {
        transform: translateX(-100%);
        pointer-events: none;
    }

    .avm-chat-panel {
        position: absolute;
        inset: 0;
        z-index: 9;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }
    .avm-chat-panel.active-mobile {
        transform: translateX(0);
        z-index: 11;
    }

    /* Afficher le bouton retour sur mobile */
    .avm-back-btn {
        display: flex !important;
    }

    .avm-messages {
        padding: 14px 14px;
    }

    .avm-message-row {
        max-width: 88%;
    }

    .avm-input-bar {
        padding: 10px 12px;
    }
}

/* ════════════════════════════════════════════════════════════
   11. RESPONSIVE — SMALL MOBILE (≤ 480px)
════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    .avm-conv-item {
        padding: 10px 12px;
    }
    .avm-conv-avatar {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    .avm-message-row {
        max-width: 92%;
    }
    .avm-bubble {
        font-size: 12px;
        padding: 9px 12px;
    }
    .avm-send-btn {
        width: 36px;
        height: 36px;
    }
}

/* ════════════════════════════════════════════════════════════
   DYNAMICALLY RENDERED CLASSES (from JS)
════════════════════════════════════════════════════════════ */

/* ── Search results dropdown ─────────────────────────────── */
.avm-search-results-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: #1e293b;
    border: 1px solid var(--avd-border);
    border-radius: 14px;
    padding: 6px;
    z-index: 2000;
    box-shadow: var(--avd-shadow-lg);
    max-height: 300px;
    overflow-y: auto;
}
body.light-mode .avm-search-results-dropdown {
    background: #ffffff;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

/* ── User search result cards ────────────────────────────── */
.user-result-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: var(--avd-transition);
}
.user-result-card:hover {
    background: rgba(255,255,255,0.06);
}
body.light-mode .user-result-card:hover {
    background: rgba(0,0,0,0.04);
}
.user-result-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.user-result-info { flex: 1; min-width: 0; }
.user-result-name {
    font-size: 12px;
    font-weight: 700;
    color: var(--avd-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-result-email {
    font-size: 10px;
    color: var(--avd-text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.start-chat-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid var(--avd-border);
    background: rgba(102,126,234,0.1);
    color: var(--avd-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: var(--avd-transition);
    flex-shrink: 0;
}
.start-chat-btn:hover {
    background: var(--avd-primary);
    color: #fff;
}

/* ── Conversation cards (rendered by JS) ─────────────────── */
.conversation-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: var(--avd-transition);
    border-bottom: 1px solid var(--avd-border);
    position: relative;
}
.conversation-card:hover {
    background: rgba(255,255,255,0.04);
}
body.light-mode .conversation-card:hover {
    background: rgba(0,0,0,0.03);
}
.conversation-card.active {
    background: rgba(102,126,234,0.1);
    border-left: 3px solid var(--avd-primary);
}
.conversation-card.unread .conversation-name {
    font-weight: 800;
    color: var(--avd-text);
}
.conversation-card.unread .conversation-last-message {
    color: var(--avd-text-muted);
    font-weight: 600;
}
.conversation-card:hover .delete-conversation-btn {
    opacity: 1;
}

/* Avatar wrapper */
.conversation-avatar-wrapper {
    position: relative;
    flex-shrink: 0;
}
.conversation-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

/* Online dot */
.online-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--avd-green);
    border: 2px solid var(--avd-sidebar-bg);
    box-shadow: 0 0 6px rgba(16,185,129,0.6);
}

/* Group indicator */
.group-indicator {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--avd-primary);
    border: 2px solid var(--avd-sidebar-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    color: #fff;
}

/* Conversation text content */
.conversation-content {
    flex: 1;
    min-width: 0;
}
.conversation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 3px;
}
.conversation-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--avd-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conversation-time {
    font-size: 10px;
    color: var(--avd-text-dim);
    flex-shrink: 0;
    white-space: nowrap;
}
.conversation-last-message {
    font-size: 11px;
    color: var(--avd-text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}
.conversation-members-count {
    font-size: 10px;
    color: var(--avd-text-dim);
    margin: 2px 0 0;
}

/* Unread badge */
.unread-badge {
    font-size: 9px;
    font-weight: 800;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 20px;
    background: var(--avd-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Delete button */
.delete-conversation-btn {
    position: absolute;
    right: 10px;
    bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid rgba(239,68,68,0.2);
    background: rgba(239,68,68,0.07);
    color: var(--avd-red);
    font-size: 10px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    opacity: 0;
    transition: var(--avd-transition);
}
.delete-conversation-btn:hover {
    background: rgba(239,68,68,0.15);
}

/* ── Loading spinner ──────────────────────────────────────── */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 20px;
    color: var(--avd-text-dim);
    font-size: 12px;
    font-weight: 600;
}
.modern-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--avd-border);
    border-top-color: var(--avd-primary);
    border-radius: 50%;
    animation: avdSpin 0.8s linear infinite;
}
@keyframes avdSpin {
    to { transform: rotate(360deg); }
}

/* ── Chat messages (rendered by JS) ──────────────────────── */
.chat-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 72%;
    animation: avdFadeIn 0.18s ease;
    margin-bottom: 4px;
}
.chat-message.own {
    margin-left: auto;
    flex-direction: row-reverse;
}
.chat-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    cursor: pointer;
    transition: transform 0.15s;
}
.chat-message-avatar:hover { transform: scale(1.1); }
.chat-message-content {
    display: flex;
    flex-direction: column;
    max-width: 100%;
}
.chat-message.own .chat-message-content {
    align-items: flex-end;
}
.chat-message-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.55;
    word-break: break-word;
    max-width: 100%;
}
.chat-message.own .chat-message-bubble {
    background: linear-gradient(135deg, var(--avd-primary), var(--avd-primary-dark));
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 16px rgba(102,126,234,0.35);
}
.chat-message:not(.own) .chat-message-bubble {
    background: var(--avd-card);
    color: var(--avd-text);
    border: 1px solid var(--avd-border);
    border-bottom-left-radius: 4px;
}
body.light-mode .chat-message:not(.own) .chat-message-bubble {
    background: #ffffff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.chat-message-time {
    font-size: 10px;
    color: var(--avd-text-dim);
    margin-top: 4px;
    padding: 0 4px;
}

/* Delete button on message */
.message-delete-btn {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: 1px solid rgba(239,68,68,0.2);
    background: rgba(239,68,68,0.08);
    color: var(--avd-red);
    font-size: 10px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: var(--avd-transition);
    flex-shrink: 0;
    align-self: center;
}
.chat-message.message-active .message-delete-btn {
    display: flex;
}
.message-delete-btn:hover {
    background: rgba(239,68,68,0.18);
}

/* ── Chat header (rendered by JS) ────────────────────────── */
.chat-back-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid var(--avd-border);
    background: var(--avd-input-bg);
    color: var(--avd-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    transition: var(--avd-transition);
    flex-shrink: 0;
}
.chat-back-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--avd-text);
}
.chat-header-user {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.chat-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    cursor: pointer;
}
.chat-header-info { min-width: 0; }
.chat-header-info h3 {
    font-size: 14px;
    font-weight: 800;
    color: var(--avd-text);
    margin: 0 0 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-header-status {
    font-size: 11px;
    color: var(--avd-text-dim);
    display: flex;
    align-items: center;
    gap: 4px;
}
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.chat-header-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid var(--avd-border);
    background: var(--avd-input-bg);
    color: var(--avd-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    transition: var(--avd-transition);
}
.chat-header-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--avd-text);
}
.chat-delete-conversation-btn:hover {
    background: rgba(239,68,68,0.1);
    color: var(--avd-red);
    border-color: rgba(239,68,68,0.25);
}

/* ── Attachments ──────────────────────────────────────────── */
.message-attachment {
    margin-top: 6px;
}
.message-attachment-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(255,255,255,0.08);
    border-radius: 10px;
    margin-top: 6px;
    border: 1px solid var(--avd-border);
}
.chat-message.own .message-attachment-file {
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.2);
}
.message-attachment-icon {
    font-size: 20px;
    color: var(--avd-primary);
    flex-shrink: 0;
}
.chat-message.own .message-attachment-icon { color: rgba(255,255,255,0.9); }
.message-attachment-info { flex: 1; min-width: 0; }
.message-attachment-name {
    font-size: 11px;
    font-weight: 700;
    color: var(--avd-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-message.own .message-attachment-name { color: rgba(255,255,255,0.95); }
.message-attachment-size {
    font-size: 10px;
    color: var(--avd-text-dim);
}
.chat-message.own .message-attachment-size { color: rgba(255,255,255,0.6); }

/* ── Mobile messages-container state ─────────────────────── */
@media (max-width: 768px) {
    .messages-container.mobile-chat-active .avm-conversations-panel {
        transform: translateX(-100%);
        pointer-events: none;
    }
    .messages-container.mobile-chat-active .avm-chat-panel {
        transform: translateX(0);
        z-index: 11;
    }
}

/* ── Shared Post Premium bubble ──────────────────────────── */
.shared-post-bubble-premium {
    padding: 0 !important;
    overflow: hidden;
    min-width: 280px;
    max-width: 340px;
    background: var(--avd-card) !important;
    border: 1px solid var(--avd-border) !important;
}
.chat-message.own .shared-post-bubble-premium {
    background: var(--avd-card) !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2) !important;
}
.shared-post-header-premium {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px 8px;
    border-bottom: 1px solid var(--avd-border);
}
.shared-post-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    font-weight: 700;
    color: var(--avd-text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.shared-post-channel-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 6px;
}
.shared-post-cover {
    width: 100%;
    height: 120px;
    overflow: hidden;
}
.shared-post-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.shared-post-body-premium {
    padding: 12px 14px;
    cursor: pointer;
    transition: var(--avd-transition);
}
.shared-post-body-premium:hover {
    background: rgba(255,255,255,0.03);
}
.shared-post-title-premium {
    font-size: 13px;
    font-weight: 800;
    color: var(--avd-text);
    margin: 0 0 8px;
    line-height: 1.4;
}
.shared-post-excerpt {
    font-size: 11px;
    color: var(--avd-text-muted);
    line-height: 1.5;
    margin-bottom: 10px;
}
.shared-post-author-section {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.shared-post-author-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.shared-post-author-info { min-width: 0; }
.shared-post-author-name {
    font-size: 11px;
    font-weight: 700;
    color: var(--avd-text);
    display: flex;
    align-items: center;
    gap: 4px;
}
.shared-post-date {
    font-size: 10px;
    color: var(--avd-text-dim);
    display: flex;
    align-items: center;
    gap: 3px;
}
.shared-post-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
}
.shared-post-tag {
    font-size: 9px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 20px;
    background: rgba(102,126,234,0.1);
    color: var(--avd-primary);
}
.shared-post-tag-more {
    font-size: 9px;
    color: var(--avd-text-dim);
    font-weight: 600;
}
.shared-post-stats {
    display: flex;
    gap: 10px;
    font-size: 10px;
    color: var(--avd-text-dim);
}
.shared-post-stats span {
    display: flex;
    align-items: center;
    gap: 3px;
}
.shared-post-view-btn-premium {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 14px;
    background: linear-gradient(135deg, var(--avd-primary), var(--avd-primary-dark));
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    transition: var(--avd-transition);
}
.shared-post-view-btn-premium:hover {
    opacity: 0.9;
}

/* ── Shared Item bubble (spreadsheet / folder) ───────────── */
.shared-item-bubble {
    padding: 0 !important;
    overflow: hidden;
    min-width: 260px;
    max-width: 320px;
    background: var(--avd-card) !important;
    border: 1px solid var(--avd-border) !important;
}
.chat-message.own .shared-item-bubble {
    background: var(--avd-card) !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2) !important;
}
.shared-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px 8px;
    border-bottom: 1px solid var(--avd-border);
}
.shared-item-header.type-spreadsheet { background: rgba(16,185,129,0.05); }
.shared-item-header.type-folder      { background: rgba(245,158,11,0.05); }
.shared-item-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    font-weight: 700;
    color: var(--avd-text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.shared-item-perm-pill {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 9px;
    font-weight: 800;
    padding: 2px 7px;
    border-radius: 20px;
}
.shared-item-perm-pill.view {
    background: rgba(102,126,234,0.1);
    color: var(--avd-primary);
}
.shared-item-body {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    text-decoration: none;
    cursor: pointer;
    transition: var(--avd-transition);
}
.shared-item-body:hover { background: rgba(255,255,255,0.03); }
.shared-item-type-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.shared-item-type-icon.spreadsheet {
    background: rgba(16,185,129,0.12);
    color: var(--avd-green);
}
.shared-item-type-icon.folder {
    background: rgba(245,158,11,0.12);
    color: var(--avd-amber);
}
.shared-item-info { flex: 1; min-width: 0; }
.shared-item-name {
    font-size: 13px;
    font-weight: 800;
    color: var(--avd-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 5px;
}
.shared-item-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.shared-item-meta-tag {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    color: var(--avd-text-dim);
    font-weight: 600;
}
.shared-item-meta-tag.highlight { color: var(--avd-green); }
.shared-folder-doc-count {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    color: var(--avd-amber);
    font-weight: 700;
}
.shared-item-divider {
    border: none;
    border-top: 1px solid var(--avd-border);
    margin: 0;
}
.shared-item-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    transition: var(--avd-transition);
    color: #fff;
}
.shared-item-cta.type-spreadsheet {
    background: linear-gradient(135deg, var(--avd-green), #059669);
}
.shared-item-cta.type-folder {
    background: linear-gradient(135deg, var(--avd-amber), #d97706);
}
.shared-item-cta:hover { opacity: 0.9; }

/* ── Mini plan badges ─────────────────────────────────────── */
.mini-plan-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    font-size: 8px;
    font-weight: 800;
}
.mini-plan-badge.platinum {
    background: linear-gradient(135deg, #a5b4fc, #7c3aed);
    color: #fff;
}
.mini-plan-badge.pro {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
}
.mini-plan-badge.basic {
    background: rgba(100,116,139,0.2);
    color: var(--avd-text-muted);
}

/* ── Group modal (rendered by JS into body) ───────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(8px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-container {
    background: #1a2235;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--avd-radius-xl);
    max-width: 480px;
    width: 100%;
    box-shadow: var(--avd-shadow-lg);
    overflow: hidden;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}
body.light-mode .modal-container {
    background: #ffffff;
    border-color: rgba(0,0,0,0.1);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--avd-border);
    flex-shrink: 0;
}
.modal-header h2 {
    font-size: 15px;
    font-weight: 800;
    color: var(--avd-text);
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}
.modal-close {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid var(--avd-border);
    background: var(--avd-input-bg);
    color: var(--avd-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: var(--avd-transition);
}
.modal-close:hover { background: rgba(239,68,68,0.1); color: var(--avd-red); }
.modal-body {
    padding: 20px 22px;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 22px;
    border-top: 1px solid var(--avd-border);
    flex-shrink: 0;
}
.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 10px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    background: linear-gradient(135deg, var(--avd-primary), var(--avd-primary-dark));
    color: #fff;
    box-shadow: 0 4px 14px rgba(102,126,234,0.35);
    transition: var(--avd-transition);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 22px rgba(102,126,234,0.5); }
.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 10px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    background: var(--avd-input-bg);
    border: 1px solid var(--avd-border);
    color: var(--avd-text-muted);
    transition: var(--avd-transition);
}
.btn-secondary:hover { background: rgba(255,255,255,0.1); color: var(--avd-text); }
.btn-danger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 10px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.2);
    color: var(--avd-red);
    transition: var(--avd-transition);
}
.btn-danger:hover { background: rgba(239,68,68,0.2); }
.section-title {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--avd-text-dim);
    margin-bottom: 12px;
}

/* ── Group settings modal fields ──────────────────────────── */
.group-settings-section {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--avd-border);
}
.group-settings-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

/* ── CSS variables for JS-referenced vars ─────────────────── */
:root {
    --text-primary:   var(--avd-text);
    --text-secondary: var(--avd-text-muted);
    --text-tertiary:  var(--avd-text-dim);
}