.community {
    position: absolute;
    inset: 0;
    z-index: 5;
    background: var(--theme-bg-primary);
    overflow-y: auto;
    padding: var(--theme-space-md, 16px);
    display: flex;
    flex-direction: column;
    gap: var(--theme-space-sm, 12px);
}

.community-close {
    position: absolute;
    top: var(--theme-space-sm, 12px);
    right: var(--theme-space-sm, 12px);
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--theme-text-primary);
    background: var(--theme-bg-secondary, #f5f5f5);
    transition: background 0.15s ease, transform 0.15s ease;
}

.community-close:hover {
    background: var(--theme-bg-tertiary, #ececec);
    transform: scale(1.05);
}

.community-header {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: var(--theme-space-md, 16px);
    padding-right: 96px;
    flex-shrink: 0;
}

.community-image-wrap {
    position: relative;
    width: 120px;
    height: 120px;
    flex-shrink: 0;
}

.community-image {
    width: 100%;
    height: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    object-fit: cover;
    display: block;
}

.community-image-edit {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    color: var(--theme-text-inverse, #fff);
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    transition: opacity 0.15s ease;
    cursor: pointer;
}

.community-image-wrap:hover .community-image-edit,
.community-image-edit:focus-visible {
    opacity: 1;
}

@media (hover: none) {
    .community-image-edit {
        opacity: 1;
        background: rgba(0, 0, 0, 0.35);
    }
}

.community-text {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    flex: 1;
}

.community-name-row {
    display: flex;
    align-items: center;
    gap: var(--theme-space-xs, 8px);
    min-width: 0;
}

.community-name {
    margin: 0;
    font-size: 1.4em;
    font-weight: 600;
    color: var(--theme-text-primary);
    min-width: 0;
}

.community-membership-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--theme-text-secondary);
}

.community-membership-badge--open {
    color: var(--theme-success, #16a34a);
}

.community-membership-badge--moderated {
    color: var(--theme-warning, #d97706);
}

.community-membership-badge--closed {
    color: var(--theme-danger, #dc2626);
}

.community-description {
    color: var(--theme-text-secondary);
    white-space: pre-wrap;
}

.community-actions {
    margin-top: calc(var(--theme-space-sm, 12px));
    padding-top: 10px;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: var(--theme-space-xs, 8px);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.community-actions .community-action {
    align-self: auto;
    margin-top: 0;
    flex: 0 0 auto;
    white-space: nowrap;
}

.community-action {
    align-self: flex-start;
    margin-top: 8px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    background: var(--theme-color-primary, #2e7df1);
    color: var(--theme-text-inverse, #fff);
    transition: background 0.15s ease, transform 0.15s ease, filter 0.15s ease;
}

.community-action:hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

.community-action--leave {
    background: var(--theme-bg-tertiary, #ececec);
    color: var(--theme-text-primary);
}

.community-action--leave:hover {
    background: var(--theme-color-danger, #dc2626);
    color: var(--theme-text-inverse, #fff);
    filter: none;
}

.community-action-group {
    margin-top: 8px;
    display: flex;
    gap: var(--theme-space-xs, 8px);
    flex-wrap: wrap;
}

.community-action-group .community-action {
    margin-top: 0;
}

.community-action--declineInvite {
    background: var(--theme-bg-tertiary, #ececec);
    color: var(--theme-text-primary);
}

.community-action--declineInvite:hover {
    background: var(--theme-color-danger, #dc2626);
    color: var(--theme-text-inverse, #fff);
    filter: none;
}

.community-action--accept {
    background: var(--theme-color-primary, #2e7df1);
    color: var(--theme-text-inverse, #fff);
}

.community-action-group--requested {
    align-items: center;
}

.community-action-pending {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--theme-bg-tertiary, #ececec);
    color: var(--theme-text-secondary);
    font-size: 0.9em;
    font-weight: 500;
}

.community-action--cancelRequest {
    background: var(--theme-bg-tertiary, #ececec);
    color: var(--theme-text-primary);
}

.community-action--cancelRequest:hover {
    background: var(--theme-color-danger, #dc2626);
    color: var(--theme-text-inverse, #fff);
    filter: none;
}

.community-edit {
    position: absolute;
    top: var(--theme-space-sm, 12px);
    right: calc(var(--theme-space-sm, 12px) + 44px);
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--theme-text-primary);
    background: var(--theme-bg-secondary, #f5f5f5);
    transition: background 0.15s ease, transform 0.15s ease;
}

.community-edit:hover {
    background: var(--theme-bg-tertiary, #ececec);
    transform: scale(1.05);
}

.community-tabs {
    display: flex;
    flex-direction: row;
    gap: var(--theme-space-xs, 6px);
    margin-top: var(--theme-space-sm, 12px);
    padding: var(--theme-space-xs, 6px);
    background: var(--theme-bg-secondary, #f5f5f5);
    border-radius: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
}

.community-tabs::-webkit-scrollbar {
    height: 6px;
}

.community-tabs::-webkit-scrollbar-thumb {
    background: var(--theme-bg-tertiary, #ddd);
    border-radius: 3px;
}

.community-tab {
    flex: 1 0 auto;
    min-width: 84px;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--theme-text-secondary);
    background: transparent;
    font-size: 0.85em;
    font-weight: 500;
    line-height: 1.1;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.community-tab:hover {
    background: var(--theme-bg-tertiary, #ececec);
    color: var(--theme-text-primary);
}

.community-tab.is-active {
    background: var(--theme-color-primary, #2e7df1);
    color: var(--theme-text-inverse, #fff);
}

.community-tab-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.community-tab-label {
    text-align: center;
    white-space: nowrap;
}

.community-panel-refresh {
    position: absolute;
    top: var(--theme-space-sm, 12px);
    right: calc(var(--theme-space-sm, 12px) + 44px);
    z-index: 6;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--theme-bg-secondary, #f5f5f5);
    color: var(--theme-text-primary);
    cursor: pointer;
    transition: background 0.15s ease;
}

/* Owner has an extra edit button, so shift the refresh one slot further left */
.community-panel-refresh--owner {
    right: calc(var(--theme-space-sm, 12px) + 88px);
}

.community-panel-refresh:hover {
    background: var(--theme-bg-tertiary, #ececec);
}

.community-panel-refresh.is-refreshing {
    cursor: default;
    color: var(--theme-color-primary, #2e7df1);
}

.community-panel-refresh.is-refreshing svg {
    animation: community-refresh-spin 0.7s linear infinite;
}

@keyframes community-refresh-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.community-panel {
    position: relative;
    flex: 1;
    min-height: 200px;
    margin-top: var(--theme-space-sm, 12px);
    padding: var(--theme-space-md, 16px);
    border-radius: 12px;
    background: var(--theme-bg-secondary, #f5f5f5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.community-panel.community-panel--welcome,
.community-panel.community-panel--members,
.community-panel.community-panel--repository {
    align-items: flex-start;
    justify-content: flex-start;
    overflow-y: auto;
}

.community-panel.community-panel--repository {
    display: block;
}

.community-panel.community-panel--chat,
.community-panel.community-panel--notices,
.community-panel.community-panel--bots {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--theme-bg-primary);
}

.community-panel-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--theme-text-secondary);
    text-align: center;
}

.community-panel-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--theme-bg-primary);
    color: var(--theme-color-primary, #2e7df1);
}

.community-panel-text {
    margin: 0;
    font-size: 1em;
    font-weight: 500;
}

.community-edit-form {
    display: flex;
    flex-direction: column;
    gap: var(--theme-space-md, 16px);
}

.community-edit-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.community-edit-label {
    font-size: 0.9em;
    font-weight: 600;
    color: var(--theme-text-primary);
}

.community-edit-input,
.community-edit-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--theme-bg-tertiary, #ddd);
    border-radius: 8px;
    background: var(--theme-bg-primary);
    color: var(--theme-text-primary);
    font-family: inherit;
    font-size: 1em;
    line-height: 1.4;
    transition: border-color 0.15s ease;
}

.community-edit-input:focus,
.community-edit-textarea:focus {
    outline: none;
    border-color: var(--theme-color-primary, #2e7df1);
}

.community-edit-textarea {
    resize: vertical;
    min-height: 80px;
}

.community-edit-resources {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
}

.community-edit-resource {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--theme-bg-tertiary, #ddd);
    border-radius: 8px;
    background: var(--theme-bg-primary);
    color: var(--theme-text-primary);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.community-edit-resource:hover {
    background: var(--theme-bg-secondary, #f5f5f5);
}

.community-edit-resource-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--theme-text-secondary);
}

.community-edit-resource-label {
    flex: 1;
    font-size: 0.95em;
}

.community-edit-resource-checkbox {
    accent-color: var(--theme-color-primary, #2e7df1);
}

.community-edit-membership {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.community-edit-membership-option {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--theme-bg-tertiary, #ddd);
    border-radius: 8px;
    background: var(--theme-bg-primary);
    color: var(--theme-text-primary);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.community-edit-membership-option:hover {
    background: var(--theme-bg-secondary, #f5f5f5);
}

.community-edit-membership-label {
    font-size: 0.95em;
}

.community-edit-membership-radio {
    accent-color: var(--theme-color-primary, #2e7df1);
}

.community-edit-footer {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    gap: var(--theme-space-sm, 12px);
}

.community-edit-cancel,
.community-edit-save {
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}

.community-edit-cancel {
    background: var(--theme-bg-secondary, #f5f5f5);
    color: var(--theme-text-primary);
}

.community-edit-cancel:hover {
    background: var(--theme-bg-tertiary, #ececec);
}

.community-edit-save {
    background: var(--theme-color-primary, #2e7df1);
    color: var(--theme-text-inverse, #fff);
}

.community-edit-save:hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

@media (max-width: 560px) {
    .community {
        padding: var(--theme-space-sm, 12px);
    }

    .community-header {
        gap: var(--theme-space-sm, 12px);
        padding-right: 48px;
    }

    .community-image-wrap {
        width: 72px;
        height: 72px;
    }

    .community-tab {
        min-width: 72px;
        padding: 8px 10px;
        font-size: 0.78em;
    }

    .community-tab-icon {
        width: 24px;
        height: 24px;
    }

    .community-tab-label {
        max-width: 72px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}
