/* ========== СТРАНИЦА СООБЩЕСТВ ========== */

.communities-page {
    min-height: calc(100vh - 72px);
    background: var(--body-bg);
    padding: 1rem 0 3rem;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* ========== LAYOUT ========== */

.communities-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 2rem;
    align-items: start;
}

.communities-main {
    min-width: 0;
    overflow: hidden;
}

/* ========== КОНТЕЙНЕР С ФОНОМ ДЛЯ ЗАГОЛОВКА, ВКЛАДОК И ФИЛЬТРОВ ========== */

.communities-controls-wrapper {
    background: var(--post-bg);
    border: 1px solid var(--post-border);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* ========== ЗАГОЛОВОК СТРАНИЦЫ ========== */

.communities-controls-wrapper .page-header {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--post-border);
}

.page-header-content {
    max-width: 100%;
}

.page-title {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.page-title svg {
    color: var(--accent-color);
    flex-shrink: 0;
}

.page-subtitle {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ========== ВКЛАДКИ ========== */

.communities-tabs {
    display: flex;
    gap: 0.5rem;
    background: var(--sidebar-bg);
    border-radius: 8px;
    padding: 0.375rem;
    margin-bottom: 1rem;
    overflow-x: auto;
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: transparent;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-width: 0;
}

.tab-btn:hover {
    background: var(--post-bg);
    color: var(--text-primary);
}

.tab-btn.active {
    background: var(--accent-color);
    color: white;
    box-shadow: 0 2px 6px color-mix(in srgb, var(--accent-color), transparent 60%);
}

.tab-btn svg {
    flex-shrink: 0;
}

/* ========== ПОИСК И ФИЛЬТРЫ ========== */

.communities-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.btn-search {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: var(--sidebar-bg);
    border: 1px solid var(--post-border);
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-search:hover {
    border-color: var(--accent-color);
    background: var(--body-bg);
    color: var(--accent-color);
}

.btn-search svg {
    flex-shrink: 0;
}

/* ========== ФИЛЬТРЫ ========== */

.filter-group {
    position: relative;
}

.filter-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: var(--sidebar-bg);
    border: 1px solid var(--post-border);
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.filter-btn:hover {
    border-color: var(--accent-color);
}

.filter-btn.active {
    border-color: var(--accent-color);
    background: rgba(52, 152, 219, 0.05);
}

.filter-btn svg:last-child {
    transition: transform 0.2s ease;
}

.filter-btn.active svg:last-child {
    transform: rotate(180deg);
}

.filter-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    min-width: 200px;
    background: var(--post-bg);
    border: 2px solid var(--post-border);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    display: none;
    max-height: 400px;
    overflow-y: auto;
    animation: dropdownSlide 0.2s ease;
}

.filter-dropdown.active {
    display: block;
}

@keyframes dropdownSlide {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.filter-option {
    padding: 0.875rem 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-primary);
    font-size: 0.9375rem;
}

.filter-option:hover {
    background: var(--sidebar-bg);
}

.filter-option.active {
    background: rgba(52, 152, 219, 0.1);
    color: var(--accent-color);
    font-weight: 500;
}

.filter-option:first-child {
    border-radius: 10px 10px 0 0;
}

.filter-option:last-child {
    border-radius: 0 0 10px 10px;
}

/* ========== СПИСОК СООБЩЕСТВ ========== */

.communities-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.community-card {
    display: flex;
    gap: 1.5rem;
    padding: 1.5rem;
    background: var(--post-bg);
    border: 1px solid var(--post-border);
    border-radius: 12px;
    transition: all 0.2s ease;
    cursor: pointer;
    min-width: 0;
    overflow: hidden;
}

.community-card:hover {
    border-color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.community-avatar {
    width: 80px;
    height: 80px;
    border-radius: 12px;
    background: var(--sidebar-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    flex-shrink: 0;
    position: relative;
}

.community-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
}

.community-avatar svg {
    color: var(--text-secondary);
    opacity: 0.5;
}

.community-verified-badge {
    position: absolute;
    bottom: -4px;
    right: -4px;
    width: 24px;
    height: 24px;
    background: var(--accent-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--post-bg);
    z-index: 1000000;
}

.community-verified-badge svg {
    width: 14px;
    height: 14px;
    color: white;
    opacity: 1;
}

.community-info {
    flex: 1;
    min-width: 0;
}

.community-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    gap: 1rem;
}

.community-name-wrapper {
    flex: 1;
    min-width: 0;
}

.community-name {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.community-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: var(--sidebar-bg);
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.community-type-badge.private {
    background: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
}

.community-type-badge.closed {
    background: rgba(241, 196, 15, 0.1);
    color: #f1c40f;
}

.community-type-badge svg {
    width: 12px;
    height: 12px;
}

/* ========== РОЛЬ В СООБЩЕСТВЕ ========== */

.community-role-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

.community-role-badge.owner {
    background: linear-gradient(135deg, #f39c12, #e67e22);
}

.community-role-badge.admin {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
}

.community-role-badge.moderator {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
}

.community-role-badge.member {
    background: linear-gradient(135deg, var(--accent-color), var(--button-primary-bg));
}

.community-role-badge svg {
    width: 12px;
    height: 12px;
}

.community-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.community-meta-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.community-meta-item svg {
    width: 16px;
    height: 16px;
}

.community-description {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    line-height: 1.6;
    margin-bottom: 1rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.community-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
}

.community-actions {
    display: flex;
    gap: 0.5rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--button-primary-bg), var(--accent-color));
    color: var(--button-primary-text);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.btn-secondary {
    background: var(--sidebar-bg);
    color: var(--text-primary);
    border: 2px solid var(--post-border);
}

.btn-secondary:hover {
    border-color: var(--accent-color);
    background: var(--post-bg);
}

.btn-outline {
    background: transparent;
    color: var(--accent-color);
    border: 2px solid var(--accent-color);
}

.btn-outline:hover {
    background: var(--accent-color);
    color: white;
}

.btn-success {
    background: #27ae60;
    color: white;
}

.btn-success:hover {
    background: #229954;
    transform: translateY(-2px);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ========== ПУСТЫЕ СОСТОЯНИЯ ========== */

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    background: var(--post-bg);
    border: 1px solid var(--post-border);
    border-radius: 12px;
}

.empty-state-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    color: var(--text-secondary);
    opacity: 0.5;
}

.empty-state-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.empty-state-text {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

/* ========== ЗАГРУЗКА ========== */

.loading-state {
    text-align: center;
    padding: 4rem 2rem;
}

.loading-state p {
    margin-top: 1rem;
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

.spinner-large {
    width: 48px;
    height: 48px;
    border: 4px solid var(--post-border);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.load-more-container {
    text-align: center;
    margin-top: 2rem;
}

/* ========== БОКОВАЯ ПАНЕЛЬ ========== */

.communities-sidebar {
    position: sticky;
    top: 88px;
    width: 320px;
}

.btn-create {
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
    margin-bottom: 1.5rem;
}

.sidebar-card {
    background: var(--post-bg);
    border: 1px solid var(--post-border);
    border-radius: 12px;
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.sidebar-card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--post-border);
}

.sidebar-card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.sidebar-card-body {
    padding: 1.25rem;
}

/* ========== СТАТИСТИКА ========== */

.stat-item {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent-color), var(--button-primary-bg));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.stat-info {
    flex: 1;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 0.25rem;
}

.stat-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

/* ========== КАРТОЧКА ЗАЯВКИ ========== */

.request-card .community-type-badge {
    background: rgba(241, 196, 15, 0.1);
    color: #f1c40f;
}

/* ========== АДАПТИВНОСТЬ ========== */

@media (max-width: 1200px) {
    .communities-layout {
        grid-template-columns: 1fr 280px;
        gap: 1.5rem;
    }
    
    .communities-sidebar {
        width: 280px;
    }
}

@media (max-width: 991px) {
    .communities-layout {
        grid-template-columns: 1fr;
    }
    
    .communities-sidebar {
        position: static;
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
    
    .btn-create {
        grid-column: 1 / -1;
    }
}

@media (max-width: 767px) {
    .communities-page {
        padding: 0.75rem 0 2rem;
    }
    
    .page-title {
        font-size: 1.5rem;
    }
    
    .page-title svg {
        width: 24px;
        height: 24px;
    }
    
    .communities-controls-wrapper {
        padding: 1rem;
    }
    
    .communities-controls-wrapper .page-header {
        padding-bottom: 1rem;
        margin-bottom: 1rem;
    }
    
    .communities-tabs {
        flex-direction: column;
        gap: 0.25rem;
        padding: 0.25rem;
    }
    
    .tab-btn {
        justify-content: flex-start;
        padding: 0.75rem 1rem;
    }
    
    .communities-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .btn-search {
        width: 100%;
    }
    
    .filter-group {
        width: 100%;
    }
    
    .filter-btn {
        width: 100%;
    }
    
    .filter-dropdown {
        width: 100%;
        left: 0;
        right: 0;
    }
    
    .community-card {
        flex-direction: column;
        gap: 1rem;
    }
    
    .community-avatar {
        width: 100%;
        height: 200px;
        border-radius: 12px;
    }
    
    .community-footer {
        flex-direction: column;
        align-items: stretch;
    }
    
    .community-actions {
        flex-direction: column;
    }
    
    .community-actions .btn {
        width: 100%;
    }
    
    .communities-sidebar {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 575px) {
    .communities-page {
        padding: 0.5rem 0 1.5rem;
    }
    
    .container {
        padding: 0 0.75rem;
    }
    
    .page-title {
        font-size: 1.375rem;
    }
    
    .communities-controls-wrapper {
        padding: 0.875rem;
    }
    
    .community-card {
        padding: 1rem;
    }
    
    .community-name {
        font-size: 1rem;
    }
    
    .community-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .community-description {
        font-size: 0.875rem;
    }
}

@media (max-width: 375px) {
    .page-title {
        font-size: 1.25rem;
        flex-direction: column;
        align-items: flex-start;
    }
    
    .tab-btn {
        font-size: 0.875rem;
    }
}

/* ========== ТОП СООБЩЕСТВ ========== */

.top-communities-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.top-communities-loading {
    display: flex;
    justify-content: center;
    padding: 2rem 0;
}

.spinner-small {
    width: 24px;
    height: 24px;
    border: 2px solid var(--post-border);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.top-community-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--sidebar-bg);
    border: 1px solid var(--post-border);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    position: relative;
}

.top-community-item:hover {
    background: var(--body-bg);
    border-color: var(--accent-color);
    transform: translateX(4px);
}

.top-community-rank {
    position: absolute;
    top: -6px;
    left: -6px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: white;
    border: 2px solid var(--post-bg);
    z-index: 2;
}

.top-community-rank.rank-1 {
    background: linear-gradient(135deg, #f39c12, #e67e22);
    box-shadow: 0 2px 8px rgba(243, 156, 18, 0.4);
}

.top-community-rank.rank-2 {
    background: linear-gradient(135deg, #95a5a6, #7f8c8d);
    box-shadow: 0 2px 8px rgba(149, 165, 166, 0.4);
}

.top-community-rank.rank-3 {
    background: linear-gradient(135deg, #cd7f32, #b8860b);
    box-shadow: 0 2px 8px rgba(205, 127, 50, 0.4);
}

.top-community-avatar {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    background: var(--post-bg);
    flex-shrink: 0;
    overflow: visible;
    position: relative;
}

.top-community-avatar-inner {
    width: 100%;
    height: 100%;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.top-community-avatar-inner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.top-community-avatar-inner svg {
    width: 100%;
    height: 100%;
    padding: 12px;
    color: var(--text-secondary);
    opacity: 0.4;
}

.top-community-verified {
    position: absolute;
    bottom: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: var(--accent-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2.5px solid var(--sidebar-bg);
    z-index: 3;
    box-shadow: 0 2px 6px rgba(52, 152, 219, 0.4);
}

.top-community-verified svg {
    width: 11px;
    height: 11px;
    color: white;
    padding: 0;
    opacity: 1;
}

.top-community-info {
    flex: 1;
    min-width: 0;
}

.top-community-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-community-members {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.top-community-members svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

.top-communities-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}