/* ============================================
   GROUP-CHAT.CSS v1.2 - CORRECTION BOUTON CLOSE
   🎨 Styles pour création et gestion de groupes
   ✅ Bouton close reste DANS le modal
   ============================================ */

/* ===== MODAL OVERLAY ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== MODAL CONTAINER ===== */
.modal-container {
    background: var(--background-primary, #ffffff);
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 550px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.4s ease;
    border: 2px solid var(--border-color, #e2e8f0);
    overflow: hidden;
    position: relative; /* ✅ AJOUT : Contexte de positionnement */
}

body.dark-mode .modal-container {
    background: rgba(15, 23, 42, 0.98);
    border-color: rgba(255, 255, 255, 0.1);
}

@keyframes slideUp {
    from { 
        opacity: 0; 
        transform: translateY(40px) scale(0.95); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0) scale(1); 
    }
}

/* ===== MODAL HEADER ===== */
.modal-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 24px 28px;
    border-radius: 22px 22px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: nowrap;
    min-height: 80px;
    position: relative; /* ✅ AJOUT : Contexte pour le bouton close */
    flex-shrink: 0; /* ✅ AJOUT : Empêche la compression */
}

.modal-header h2 {
    font-size: 1.4rem;
    font-weight: 800;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: calc(100% - 60px); /* ✅ AJOUT : Laisse de la place au bouton */
}

.modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.2rem;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative; /* ✅ AJOUT : Reste dans le flux */
    z-index: 1; /* ✅ AJOUT : Au-dessus du contenu */
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.modal-close:active {
    transform: rotate(90deg) scale(0.95);
}

/* ===== MODAL BODY ===== */
.modal-body {
    padding: 28px;
    overflow-y: auto;
    flex: 1;
}

.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: var(--background-secondary, #f1f5f9);
}

body.dark-mode .modal-body::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--border-color, #cbd5e1);
    border-radius: 4px;
}

body.dark-mode .modal-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
}

/* ===== MODAL FOOTER ===== */
.modal-footer {
    padding: 20px 28px;
    border-top: 2px solid var(--border-color, #e2e8f0);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

body.dark-mode .modal-footer {
    border-top-color: rgba(255, 255, 255, 0.1);
}

/* ===== FORM GROUPS ===== */
.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-primary, #1e293b);
    margin-bottom: 8px;
}

body.dark-mode .form-group label {
    color: var(--text-primary, #f8fafc);
}

.form-input,
.form-textarea {
    width: 100%;
    padding: 14px 16px;
    border-radius: 12px;
    border: 2px solid var(--border-color, #e2e8f0);
    font-size: 0.95rem;
    transition: all 0.3s ease;
    background: var(--background-primary, #ffffff);
    color: var(--text-primary, #1e293b);
    font-family: inherit;
}

body.dark-mode .form-input,
body.dark-mode .form-textarea {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary, #f8fafc);
}

.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
    max-height: 150px;
}

/* ===== GROUP PHOTO UPLOAD ===== */
.group-photo-upload {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    padding: 20px;
    background: rgba(102, 126, 234, 0.05);
    border-radius: 16px;
    border: 2px dashed rgba(102, 126, 234, 0.3);
}

body.dark-mode .group-photo-upload {
    background: rgba(102, 126, 234, 0.1);
}

.group-photo-preview {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    color: white;
    overflow: hidden;
    border: 4px solid white;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

body.dark-mode .group-photo-preview {
    border-color: rgba(255, 255, 255, 0.1);
}

.upload-photo-btn {
    padding: 10px 20px;
    border-radius: 10px;
    border: 2px solid #667eea;
    background: transparent;
    color: #667eea;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.upload-photo-btn:hover {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* ===== MEMBER SEARCH RESULTS ===== */
.member-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 8px;
    max-height: 300px;
    overflow-y: auto;
    background: var(--background-primary, #ffffff);
    border: 2px solid var(--border-color, #e2e8f0);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 1000;
}

body.dark-mode .member-search-results {
    background: rgba(15, 23, 42, 0.98);
    border-color: rgba(255, 255, 255, 0.1);
}

.member-search-result {
    background: transparent;
    border-bottom: 2px solid var(--border-color, #e2e8f0);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.member-search-result:last-child {
    border-bottom: none;
}

body.dark-mode .member-search-result {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

.member-search-result:hover {
    background: rgba(102, 126, 234, 0.08);
}

.member-result-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #667eea;
    flex-shrink: 0;
}

.member-result-info {
    flex: 1;
    min-width: 0;
}

.member-result-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary, #1e293b);
    margin-bottom: 2px;
}

body.dark-mode .member-result-name {
    color: var(--text-primary, #f8fafc);
}

.member-result-email {
    font-size: 0.8rem;
    color: var(--text-secondary, #64748b);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.add-member-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.add-member-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* ===== SELECTED MEMBERS ===== */
.selected-members {
    margin-top: 16px;
    min-height: 60px;
}

.no-members-selected {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-secondary, #64748b);
}

.no-members-selected i {
    font-size: 2.5rem;
    opacity: 0.3;
    margin-bottom: 12px;
    display: block;
    color: #667eea;
}

.selected-members-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.selected-member-chip {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 8px 12px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    animation: chipIn 0.3s ease;
}

@keyframes chipIn {
    from { 
        opacity: 0; 
        transform: scale(0.8); 
    }
    to { 
        opacity: 1; 
        transform: scale(1); 
    }
}

.selected-member-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.selected-member-name {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.remove-member-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 0.8rem;
}

.remove-member-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.members-count {
    margin-top: 12px;
    font-size: 0.85rem;
    color: #667eea;
    font-weight: 600;
    text-align: center;
}

/* ===== BUTTONS ===== */
.btn-primary,
.btn-secondary,
.btn-danger {
    padding: 14px 24px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.4);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: transparent;
    color: #667eea;
    border: 2px solid #667eea;
}

.btn-secondary:hover {
    background: rgba(102, 126, 234, 0.1);
    transform: translateY(-2px);
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(239, 68, 68, 0.4);
}

/* ===== NO RESULTS / ERROR STATE ===== */
.no-results,
.error-state {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-secondary, #64748b);
}

.no-results i,
.error-state i {
    font-size: 2.5rem;
    opacity: 0.3;
    margin-bottom: 12px;
    display: block;
}

.error-state {
    color: #ef4444;
}

.error-state i {
    color: #ef4444;
}

/* ===== GROUP BADGE IN CONVERSATION LIST ===== */
.conversation-group-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ===== GROUP SETTINGS SECTIONS ===== */
.group-settings-section {
    margin-bottom: 28px;
    padding-bottom: 24px;
    border-bottom: 2px solid var(--border-color, #e2e8f0);
}

body.dark-mode .group-settings-section {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

.group-settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.section-title {
    font-size: 1rem;
    font-weight: 800;
    color: var(--text-primary, #1e293b);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

body.dark-mode .section-title {
    color: var(--text-primary, #f8fafc);
}

.group-info-display {
    display: flex;
    gap: 16px;
    align-items: center;
    padding: 16px;
    background: rgba(102, 126, 234, 0.05);
    border-radius: 16px;
}

body.dark-mode .group-info-display {
    background: rgba(102, 126, 234, 0.1);
}

.group-settings-avatar {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #667eea;
    flex-shrink: 0;
}

.group-info-text {
    flex: 1;
    min-width: 0;
}

.group-settings-name {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-primary, #1e293b);
    margin-bottom: 4px;
}

body.dark-mode .group-settings-name {
    color: var(--text-primary, #f8fafc);
}

.group-settings-desc {
    font-size: 0.9rem;
    color: var(--text-secondary, #64748b);
    margin-bottom: 6px;
}

.group-settings-meta {
    font-size: 0.8rem;
    color: #667eea;
    font-weight: 600;
}

/* ===== GROUP MEMBERS LIST ===== */
.group-members-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.group-member-item {
    background: var(--background-primary, #ffffff);
    border: 2px solid var(--border-color, #e2e8f0);
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.3s ease;
}

body.dark-mode .group-member-item {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.1);
}

.group-member-item:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.05);
}

.member-item-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #667eea;
    flex-shrink: 0;
}

.member-item-info {
    flex: 1;
    min-width: 0;
}

.member-item-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary, #1e293b);
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

body.dark-mode .member-item-name {
    color: var(--text-primary, #f8fafc);
}

.member-item-email {
    font-size: 0.8rem;
    color: var(--text-secondary, #64748b);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.member-badge {
    font-size: 0.65rem;
    padding: 3px 8px;
    border-radius: 6px;
    font-weight: 700;
    text-transform: uppercase;
}

.member-badge.creator {
    background: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
    color: white;
}

.member-badge.admin {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.member-badge.self {
    background: #10b981;
    color: white;
}

.member-item-actions {
    display: flex;
    gap: 6px;
}

.member-action-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.member-action-btn:hover {
    background: #667eea;
    color: white;
    transform: scale(1.1);
}

.member-action-btn.danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.member-action-btn.danger:hover {
    background: #ef4444;
    color: white;
}

/* ===== DANGER ZONE ===== */
.danger-zone {
    background: rgba(239, 68, 68, 0.05);
    border-radius: 16px;
    padding: 20px;
    border: 2px solid rgba(239, 68, 68, 0.2);
}

body.dark-mode .danger-zone {
    background: rgba(239, 68, 68, 0.1);
}

/* ===== GROUP MESSAGE SENDER NAME ===== */
.group-message-sender {
    font-size: 0.75rem;
    font-weight: 700;
    color: #667eea;
    margin-bottom: 4px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .modal-container {
        max-width: 95%;
        max-height: 95vh;
        border-radius: 20px;
    }

    .modal-header {
        padding: 20px 20px;
    }

    .modal-header h2 {
        font-size: 1.2rem;
    }

    .modal-body {
        padding: 20px;
    }

    .modal-footer {
        padding: 16px 20px;
        flex-direction: column;
    }

    .btn-primary,
    .btn-secondary,
    .btn-danger {
        width: 100%;
    }

    .group-photo-preview {
        width: 80px;
        height: 80px;
        font-size: 2rem;
    }

    .selected-member-chip {
        font-size: 0.85rem;
        padding: 6px 10px;
    }

    .group-info-display {
        flex-direction: column;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .modal-header h2 {
        font-size: 1.1rem;
    }

    .member-search-results {
        max-height: 250px;
    }

    .group-member-item {
        padding: 10px 12px;
    }

    .member-item-avatar {
        width: 38px;
        height: 38px;
    }
}

console.log('✅ group-chat.css loaded (v1.2 - Modal close button FIXED)');