/* Community Page - Groups + Chat */

.community-section {
    padding-top: var(--space-4);
    padding-bottom: var(--space-4);
}

.community-layout {
    display: flex;
    height: calc(100vh - 200px);
    min-height: 520px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    overflow: hidden;
    background: var(--bg-primary);
    box-shadow: var(--shadow-lg);
}

/* ---- Sidebar ---- */
.community-sidebar {
    width: 300px;
    min-width: 260px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
}

.sidebar-toolbar {
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: 6px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.15);
}

.search-bar-sm {
    height: 32px;
}
.search-bar-sm .input {
    height: 32px;
    font-size: var(--text-xs);
    padding-left: 32px;
}
.search-bar-sm .search-bar-icon {
    font-size: 13px;
    left: 8px;
}
.select-sm {
    height: 32px;
    font-size: var(--text-xs);
    padding: 0 var(--space-3);
    border-radius: var(--radius-sm);
}

.sidebar-toolbar .btn {
    font-size: var(--text-xs);
    padding: 5px var(--space-3);
    border-radius: var(--radius-sm);
}

/* Groups list */
.groups-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-1) var(--space-2);
}
.groups-list::-webkit-scrollbar {
    width: 4px;
}
.groups-list::-webkit-scrollbar-track {
    background: transparent;
}
.groups-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
}
.groups-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Group sections */
.group-section-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding: var(--space-2) var(--space-2) 2px;
    margin-top: var(--space-2);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-heading);
}
.group-section-label:first-child {
    margin-top: var(--space-1);
}
.group-section-icon {
    font-size: 0.7rem;
    opacity: 0.7;
}

/* Group item */
.group-item {
    padding: 8px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-bottom: 2px;
    border: 1px solid transparent;
}
.group-item:hover {
    background: rgba(0, 217, 255, 0.04);
    border-color: rgba(0, 217, 255, 0.08);
}
.group-item.active {
    background: rgba(0, 217, 255, 0.08);
    border-color: rgba(0, 217, 255, 0.2);
    box-shadow: inset 3px 0 0 var(--accent-cyan);
}

.group-item-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 3px;
}

/* Role icon */
.group-role-icon {
    color: var(--accent-cyan);
    font-size: 0.7rem;
    flex-shrink: 0;
    opacity: 0.85;
}
.group-role-member {
    color: var(--accent-green);
}

.group-item-name {
    font-weight: 600;
    font-size: var(--text-xs);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    color: var(--text-primary);
}
.group-item.active .group-item-name {
    color: var(--accent-cyan);
}

.group-item-badges {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* Rank & category tags */
.tag-sm {
    font-size: 0.55rem;
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}
.badge-sm {
    font-size: 0.55rem;
    padding: 1px 5px;
    font-weight: 600;
}

.tag-debutant { background: rgba(0, 230, 118, 0.12); color: #00e676; }
.tag-confirme { background: rgba(68, 138, 255, 0.12); color: #448aff; }
.tag-pro      { background: rgba(255, 171, 0, 0.12); color: #ffab00; }
.tag-expert   { background: rgba(255, 23, 68, 0.12); color: #ff1744; }

.group-item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.65rem;
    color: var(--text-muted);
    padding-left: 18px;
}

/* Join / XS buttons */
.btn-xs {
    font-size: 0.6rem;
    padding: 2px 8px;
    height: auto;
    line-height: 1.5;
    border-radius: var(--radius-sm);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.group-joined-badge {
    color: var(--accent-green);
    font-weight: 700;
}

/* ---- Invitations banner ---- */
.invitations-banner {
    padding: 10px var(--space-3);
    background: linear-gradient(135deg, rgba(123, 104, 238, 0.1), rgba(0, 217, 255, 0.05));
    border-bottom: 1px solid rgba(123, 104, 238, 0.15);
}
.invitation-title {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent-violet);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-family: var(--font-heading);
}
.invitation-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    border-bottom: 1px solid rgba(123, 104, 238, 0.08);
    font-size: var(--text-xs);
}
.invitation-item:last-child {
    border-bottom: none;
}

/* ---- Chat panel ---- */
.community-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-primary);
}

/* Empty state */
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: var(--space-2);
}
.chat-empty-icon {
    font-size: 2.5rem;
    opacity: 0.3;
    filter: grayscale(0.5);
}
.chat-empty p {
    font-size: var(--text-sm);
    opacity: 0.6;
}

/* Chat header */
.chat-header {
    padding: 10px var(--space-4);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    background: var(--bg-secondary);
}
.chat-header-info h3 {
    font-size: var(--text-base);
    font-family: var(--font-heading);
    font-weight: 700;
    margin-bottom: 0;
    letter-spacing: 0.03em;
    color: var(--text-primary);
}
.chat-group-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin: 1px 0 2px;
    max-width: 400px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}
.chat-header-meta {
    font-size: 0.65rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: var(--space-1);
}
.chat-header-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}
.chat-header-actions .btn {
    font-size: 0.8rem;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    opacity: 0.7;
    transition: opacity var(--transition-fast);
}
.chat-header-actions .btn:hover {
    opacity: 1;
}

.online-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-green);
    margin-right: 2px;
    animation: pulse-dot 2s ease-in-out infinite;
    box-shadow: 0 0 4px rgba(0, 230, 118, 0.5);
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; box-shadow: 0 0 4px rgba(0, 230, 118, 0.5); }
    50% { opacity: 0.6; box-shadow: 0 0 8px rgba(0, 230, 118, 0.3); }
}

/* ---- Messages ---- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-3) var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.chat-messages::-webkit-scrollbar {
    width: 5px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 4px;
}

.chat-message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    max-width: 75%;
    animation: msg-in 0.2s ease-out;
}
@keyframes msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.chat-message.own {
    margin-left: auto;
    flex-direction: row-reverse;
}

.chat-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--bg-primary);
    flex-shrink: 0;
    letter-spacing: 0.03em;
}

.chat-bubble {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    min-width: 60px;
}
.chat-message.own .chat-bubble {
    background: rgba(0, 217, 255, 0.08);
    border-color: rgba(0, 217, 255, 0.15);
}

.chat-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
}
.chat-username {
    font-weight: 700;
    font-size: 0.7rem;
    color: var(--accent-cyan);
    letter-spacing: 0.02em;
}
.chat-time {
    font-size: 0.6rem;
    color: var(--text-muted);
    opacity: 0.7;
}
.chat-text {
    font-size: var(--text-sm);
    line-height: 1.5;
    word-break: break-word;
    color: var(--text-secondary);
}

.chat-pm-notice {
    text-align: center;
    font-size: 0.65rem;
    color: var(--accent-violet);
    padding: 4px var(--space-2);
    font-style: italic;
    opacity: 0.8;
}

/* ---- Input area ---- */
.chat-input-area {
    padding: 10px var(--space-4);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    background: var(--bg-secondary);
}
.chat-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}
.chat-form .input {
    flex: 1;
    resize: none;
    max-height: 72px;
    min-height: 36px;
    font-size: var(--text-sm);
    padding: 8px 12px;
    border-radius: var(--radius-lg);
    background: var(--bg-input);
}
.chat-form .btn {
    padding: 8px 16px;
    font-size: var(--text-xs);
    border-radius: var(--radius-lg);
    flex-shrink: 0;
}

/* ---- PM panel ---- */
.chat-pm-panel {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.pm-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px var(--space-4);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}
.pm-header h4 {
    font-size: var(--text-sm);
    font-family: var(--font-heading);
    font-weight: 700;
    margin: 0;
    letter-spacing: 0.03em;
}
.pm-list {
    flex: 1;
    overflow-y: auto;
}
.pm-item {
    padding: 10px var(--space-4);
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition-fast);
}
.pm-item:hover {
    background: rgba(255, 255, 255, 0.02);
}
.pm-unread {
    background: rgba(123, 104, 238, 0.06);
    border-left: 2px solid var(--accent-violet);
}
.pm-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 3px;
}
.pm-text {
    font-size: var(--text-xs);
    line-height: 1.45;
    color: var(--text-secondary);
}

.pm-badge {
    background: var(--accent-violet);
    color: white;
    font-size: 0.55rem;
    padding: 0 4px;
    border-radius: 8px;
    font-weight: 700;
    min-width: 14px;
    text-align: center;
    line-height: 14px;
}

/* ---- Invite modal ---- */
.invite-search-wrapper {
    padding: var(--space-3) var(--space-4) 0;
}
.invite-search-wrapper .input {
    font-size: var(--text-xs);
}
.invite-list {
    max-height: 400px;
    overflow-y: auto;
}
.invite-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px var(--space-4);
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition-fast);
}
.invite-item:hover {
    background: rgba(255, 255, 255, 0.02);
}
.invite-item:last-child {
    border-bottom: none;
}
.invite-user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: var(--text-sm);
    font-weight: 500;
}

/* ---- PM Toast notification ---- */
.pm-toast {
    position: fixed;
    top: 80px;
    right: 20px;
    background: linear-gradient(135deg, rgba(123, 104, 238, 0.95), rgba(0, 217, 255, 0.85));
    color: white;
    padding: 10px 20px;
    border-radius: var(--radius-lg);
    font-size: var(--text-xs);
    font-weight: 600;
    z-index: var(--z-toast);
    opacity: 0;
    transform: translateX(100px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    box-shadow: 0 4px 24px rgba(123, 104, 238, 0.35);
    backdrop-filter: blur(8px);
}
.pm-toast-show {
    opacity: 1;
    transform: translateX(0);
}

/* ---- CTA card (non-logged) ---- */
.community-cta {
    text-align: center;
    padding: var(--space-8) var(--space-6);
    max-width: 500px;
    margin: 0 auto;
}
.community-cta-icon {
    font-size: 2.5rem;
    margin-bottom: var(--space-4);
    opacity: 0.7;
}
.community-cta h2 {
    font-size: var(--text-xl);
    margin-bottom: var(--space-4);
}
.community-cta .btn {
    font-size: var(--text-sm);
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .community-layout {
        flex-direction: column;
        height: auto;
        min-height: auto;
        border-radius: var(--radius-lg);
    }
    .community-sidebar {
        width: 100%;
        min-width: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        max-height: 280px;
    }
    .community-chat {
        min-height: 380px;
    }
    .chat-message {
        max-width: 90%;
    }
    .chat-header-info h3 {
        font-size: var(--text-sm);
    }
}
