/* =========================================================
   SOCIALWIKI - GROUPS PAGE (MATCHES groups.js)
   Version: 2.0 - Full + Fixes
========================================================= */

/* =========================================================
   MAIN PAGE
========================================================= */

.groups-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* =========================================================
   NAVIGATION - HOME BUTTON
========================================================= */

.groups-navigation {
    padding: 10px 0 20px;
}

.groups-home-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: white;
    color: #1877f2;
    border-radius: 25px;
    text-decoration: none;
    font-weight: 600;
    font-size: 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: all 0.2s ease;
}

.groups-home-button:hover {
    background: #1877f2;
    color: white;
    transform: translateY(-2px);
}

/* =========================================================
   HEADER
========================================================= */

.groups-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 25px;
}

.groups-heading h1 {
    font-size: 36px;
    font-weight: 800;
    color: #050505;
    margin: 0 0 5px 0;
}

.groups-heading p {
    font-size: 15px;
    color: #65676b;
    margin: 0;
}

.create-group-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: linear-gradient(135deg, #1877f2, #166fe5);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 14px rgba(24, 119, 242, 0.35);
}

.create-group-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(24, 119, 242, 0.45);
}

.create-plus {
    font-size: 20px;
    font-weight: 900;
    line-height: 1;
}

/* =========================================================
   SEARCH
========================================================= */

.groups-search-section {
    margin-bottom: 25px;
}

.groups-search-box {
    position: relative;
    display: flex;
    align-items: center;
    background: white;
    border-radius: 12px;
    padding: 0 18px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    transition: box-shadow 0.2s ease;
}

.groups-search-box:focus-within {
    box-shadow: 0 4px 16px rgba(24, 119, 242, 0.2);
}

.search-icon {
    font-size: 18px;
    margin-right: 10px;
    opacity: 0.6;
}

.groups-search-box input {
    flex: 1;
    height: 50px;
    border: none;
    outline: none;
    font-size: 15px;
    background: transparent;
    color: #050505;
}

/* =========================================================
   ⚡ GROUPS GRID - FORCE 3 COLUMNS
========================================================= */

.groups-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 20px !important;
    align-items: start;
}

.groups-loading {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: #65676b;
    font-size: 16px;
}

/* =========================================================
   GROUP CARD
========================================================= */

.group-card {
    background: white;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    transition: all 0.25s ease;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.group-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}

/* الغلاف */
.group-cover {
    width: 100%;
    height: 120px;
    background: linear-gradient(135deg, #1877f2, #8b5cf6);
    position: relative;
    overflow: hidden;
}

.group-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.group-cover-placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1877f2, #8b5cf6);
}

/* الصورة الرمزية */
.group-avatar {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    border: 4px solid white;
    background: white;
    overflow: hidden;
    position: absolute;
    bottom: -35px;
    left: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 2;
}

.group-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.group-avatar-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e4e6eb;
    font-size: 28px;
}

/* محتوى البطاقة */
.group-content {
    padding: 45px 20px 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* ⚡ العنوان + زر Edit */
.group-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 8px;
}

.group-title-row h3 {
    font-size: 17px;
    font-weight: 700;
    color: #050505;
    margin: 0;
    line-height: 1.3;
    flex: 1;
    word-break: break-word;
}

.edit-group-button {
    background: #f0f2f5;
    border: none;
    padding: 5px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #050505;
    transition: 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.edit-group-button:hover {
    background: #e4e6eb;
}

/* الوصف */
.group-description {
    font-size: 13px;
    color: #65676b;
    margin: 0 0 12px 0;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 76px;
}

/* ⚡ Meta info (members + public) */
.group-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 15px;
    font-size: 13px;
    color: #65676b;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f2f5;
    flex-wrap: wrap;
}

.group-meta span {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

/* Action Buttons */
.group-action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

/* زر الانضمام الرئيسي */
.join-group-button {
    width: 100%;
    padding: 11px;
    background: #1877f2;
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: auto;
}

.join-group-button:hover {
    background: #166fe5;
    transform: scale(1.02);
}

.join-group-button.joined {
    background: #e4e6eb;
    color: #050505;
    cursor: default;
}

.join-group-button.joined:hover {
    transform: none;
}

/* أزرار فرعية */
.view-members-button,
.open-group-button,
.invite-people-button {
    padding: 9px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    transition: 0.2s;
    border: none;
}

.view-members-button {
    background: #fff;
    color: #050505;
    border: 1px solid #ddd;
}

.view-members-button:hover {
    background: #f0f2f5;
}

.open-group-button,
.invite-people-button {
    background: #111;
    color: #fff;
}

.open-group-button:hover,
.invite-people-button:hover {
    background: #333;
}

/* =========================================================
   EMPTY STATE
========================================================= */

.groups-empty {
    grid-column: 1 / -1;
    background: white;
    border-radius: 14px;
    padding: 60px 20px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

.groups-empty-icon {
    font-size: 70px;
    margin-bottom: 15px;
    opacity: 0.5;
}

.groups-empty h2 {
    font-size: 20px;
    font-weight: 700;
    color: #050505;
    margin: 0 0 8px 0;
}

.groups-empty p {
    font-size: 14px;
    color: #65676b;
    margin: 0;
}

/* =========================================================
   MODAL
========================================================= */

.group-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.group-modal[hidden] {
    display: none;
}

.group-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.55);
}

.group-modal-content {
    position: relative;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    background: white;
    border-radius: 16px;
    padding: 25px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.group-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #f0f2f5;
}

.group-modal-title-area h2 {
    font-size: 22px;
    font-weight: 800;
    color: #050505;
    margin: 0 0 4px 0;
}

.group-modal-title-area p {
    font-size: 13px;
    color: #65676b;
    margin: 0;
}

.close-group-modal {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #f0f2f5;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: #65676b;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.close-group-modal:hover {
    background: #e4e6eb;
    color: #050505;
}

/* =========================================================
   FORM
========================================================= */

.create-group-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.group-form-field,
.group-form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.group-form-field label,
.group-form-group label {
    font-size: 14px;
    font-weight: 600;
    color: #050505;
}

.group-form-field input,
.group-form-field textarea,
.group-form-field select,
.group-form-group input,
.group-form-group textarea,
.group-form-group select {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid #e4e6eb;
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    background: #f8f9fa;
    transition: all 0.2s ease;
    resize: vertical;
}

.group-form-field input:focus,
.group-form-field textarea:focus,
.group-form-group input:focus,
.group-form-group textarea:focus {
    border-color: #1877f2;
    background: white;
    box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.1);
}

.character-hint,
.privacy-hint {
    font-size: 12px;
    color: #65676b;
    margin-top: 2px;
}

/* =========================================================
   IMAGE UPLOAD
========================================================= */

.group-image-upload-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.group-upload-preview {
    width: 100%;
    border-radius: 10px;
    overflow: hidden;
    background: #f0f2f5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.group-upload-preview.cover-preview {
    height: 120px;
}

.group-upload-preview.avatar-preview {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    margin: 0 auto;
}

.group-upload-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.group-upload-button {
    padding: 10px 16px;
    background: #f0f2f5;
    color: #050505;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    align-self: flex-start;
}

.group-upload-button:hover {
    background: #e4e6eb;
}

/* =========================================================
   FORM MESSAGE
========================================================= */

.group-form-message {
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
}

.group-form-message.error {
    background: #ffebee;
    color: #c62828;
}

.group-form-message.success {
    background: #e7f7e7;
    color: #2e7d32;
}

/* =========================================================
   FORM ACTIONS
========================================================= */

.group-form-actions {
    display: flex;
    gap: 12px;
    margin-top: 10px;
}

.group-cancel-button,
.cancel-group-button {
    flex: 1;
    padding: 12px;
    background: #e4e6eb;
    color: #050505;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.group-cancel-button:hover,
.cancel-group-button:hover {
    background: #d8dadf;
}

.group-save-button,
.save-group-button {
    flex: 1;
    padding: 12px;
    background: linear-gradient(135deg, #1877f2, #166fe5);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 14px rgba(24, 119, 242, 0.3);
}

.group-save-button:hover,
.save-group-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(24, 119, 242, 0.45);
}

/* =========================================================
   🆕 GROUP PAGE MODAL (Posts)
========================================================= */

#groupPageModal .group-modal-content {
    max-width: 700px;
    width: 94%;
}

#groupPageModal h2 {
    font-size: 20px;
    font-weight: 700;
}

#groupPostsContainer {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#groupPostContentInput {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 10px;
    font-size: 15px;
    min-height: 80px;
    resize: vertical;
    box-sizing: border-box;
    font-family: inherit;
    background: white;
    outline: none;
    transition: border-color 0.2s;
}

#groupPostContentInput:focus {
    border-color: #1877f2;
    box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.1);
}

/* =========================================================
   🆕 GROUP MEMBERS / INVITE MODALS
========================================================= */

#groupMembersModal .group-modal-content,
#groupInviteModal .group-modal-content {
    max-width: 600px;
    width: 92%;
}

#groupMembersList,
#groupInviteResults {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 60vh;
    overflow-y: auto;
}

#groupInviteSearchInput {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #ddd;
    border-radius: 10px;
    font-size: 15px;
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.2s;
}

#groupInviteSearchInput:focus {
    border-color: #1877f2;
    box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.1);
}

/* =========================================================
   🆕 RTL SUPPORT (العربية)
========================================================= */

[dir="rtl"] .group-title-row {
    flex-direction: row-reverse;
}

[dir="rtl"] .group-meta {
    justify-content: flex-start;
}

[dir="rtl"] .group-avatar {
    left: auto;
    right: 20px;
}

[dir="rtl"] .search-icon {
    margin-right: 0;
    margin-left: 10px;
}

[dir="rtl"] .group-cover-placeholder {
    background: linear-gradient(135deg, #1877f2, #8b5cf6);
}

/* =========================================================
   ⚡ RESPONSIVE
========================================================= */

/* شاشات متوسطة → عمودان */
@media (max-width: 900px) {
    .groups-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* جوال → عمود واحد */
@media (max-width: 700px) {
    .groups-page {
        padding: 15px;
    }
    
    .groups-heading h1 {
        font-size: 26px;
    }
    
    .groups-grid {
        grid-template-columns: 1fr !important;
    }
    
    .create-group-button {
        width: 100%;
        justify-content: center;
    }
    
    .group-modal-content {
        padding: 20px;
    }
    
    #groupPageModal .group-modal-content,
    #groupMembersModal .group-modal-content,
    #groupInviteModal .group-modal-content {
        max-width: 95%;
        padding: 16px;
    }
}

/* شاشات صغيرة جداً */
@media (max-width: 400px) {
    .group-title-row h3 {
        font-size: 15px;
    }
    
    .group-meta {
        font-size: 12px;
        gap: 10px;
    }
    
    .group-action-buttons {
        flex-direction: column;
    }
    
    .view-members-button,
    .open-group-button,
    .invite-people-button {
        width: 100%;
        text-align: center;
    }
}

/* =========================================================
   ✅ END OF FILE
========================================================= */