/**
 * Community Chat Widget Styles
 * @fileoverview สไตล์สำหรับ Community Group Chat Widget
 * @author Chahua Development Thailand
 * @version 1.0.0
 */

/* =============================================== */
/* ===      COMMUNITY CHAT BUTTON (HEADER)     === */
/* =============================================== */

.btn-community-chat {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border: none;
    background: linear-gradient(135deg, var(--accent-blue), #0ea5e9);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 12px 24px rgba(14, 165, 233, 0.35);
    z-index: 9998;
}

.btn-community-chat:hover {
    transform: translateY(-4px);
    box-shadow: 0 18px 32px rgba(14, 165, 233, 0.45);
}

.btn-community-chat:focus-visible {
    outline: 3px solid rgba(14, 165, 233, 0.45);
    outline-offset: 3px;
}

.btn-community-chat.is-active {
    opacity: 0;
    transform: scale(0.9);
    pointer-events: none;
}

.btn-community-chat.mobile-hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.btn-community-chat svg {
    width: 24px;
    height: 24px;
}

.chat-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    background: #ef4444;
    color: white;
    font-size: 11px;
    font-weight: bold;
    padding: 3px 6px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
    animation: pulse-badge 2s infinite;
    display: none;
}

.chat-badge.is-visible {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}

@keyframes pulse-badge {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* =============================================== */
/* ===         COMMUNITY CHAT WIDGET           === */
/* =============================================== */

.community-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 420px;
    height: 600px;
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    display: none;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    transition: all 0.3s ease;
}

.community-chat-widget.active {
    display: flex;
}

.community-chat-widget.mobile-hidden {
    display: none !important;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: linear-gradient(135deg, var(--accent-blue), #0ea5e9);
    color: white;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chat-header-icon {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-header-icon svg {
    width: 18px;
    height: 18px;
}

.chat-header-title h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.chat-header-subtitle {
    font-size: 0.75rem;
    opacity: 0.9;
    margin-top: 2px;
}

.chat-header-actions {
    display: flex;
    gap: 0.5rem;
}

.chat-header-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.chat-header-btn svg {
    width: 16px;
    height: 16px;
}

/* Chat Tabs */
.chat-tabs {
    display: flex;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--glass-border);
}

.chat-tab {
    flex: 1;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
    position: relative;
}

.chat-tab:hover {
    background: rgba(14, 165, 233, 0.1);
    color: var(--accent-blue);
}

.chat-tab.active {
    color: var(--accent-blue);
}

.chat-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent-blue);
}

.chat-tab-badge {
    display: none;
    margin-left: 0.5rem;
    background: #ef4444;
    color: white;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 16px;
    text-align: center;
}

.chat-tab-badge.is-visible {
    display: inline-block;
}

/* Chat Body */
.chat-body {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Sidebar - User List */
.chat-sidebar {
    width: 140px;
    background: var(--bg-primary);
    border-right: 1px solid var(--glass-border);
    overflow-y: auto;
    padding: 1rem 0.5rem;
}

.chat-sidebar-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 0.75rem;
    padding: 0 0.5rem;
}

.user-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.user-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.user-item:hover {
    background: rgba(14, 165, 233, 0.1);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-blue), #0ea5e9);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.85rem;
    position: relative;
}

.user-status {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--bg-primary);
}

.user-status.online {
    background: #22c55e;
}

.user-status.offline {
    background: #6b7280;
}

.user-name {
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

/* Chat Content */
.chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-tab-content {
    display: none;
    flex-direction: column;
    height: 100%;
}

.chat-tab-content.active {
    display: flex;
}

.is-hidden {
    display: none !important;
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat-message {
    display: flex;
    gap: 0.75rem;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-blue), #0ea5e9);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.message-content {
    flex: 1;
    max-width: calc(100% - 50px);
}

.message-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.message-sender {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.message-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--accent-blue);
    color: white;
}

.message-text {
    background: var(--glass-bg);
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-primary);
    word-wrap: break-word;
}

/* My Messages */
.chat-message.my-message {
    flex-direction: row-reverse;
}

.chat-message.my-message .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.chat-message.my-message .message-text {
    background: linear-gradient(135deg, var(--accent-blue), #0ea5e9);
    color: white;
}

/* System Messages */
.chat-message.system-message {
    justify-content: center;
}

.chat-message.system-message .message-text {
    background: rgba(14, 165, 233, 0.1);
    color: var(--accent-blue);
    font-size: 0.85rem;
    text-align: center;
    border: 1px solid rgba(14, 165, 233, 0.2);
}

/* Chat Input */
.chat-input-area {
    padding: 1rem;
    border-top: 1px solid var(--glass-border);
    background: var(--bg-primary);
}

.chat-input-wrapper {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    resize: none;
    max-height: 100px;
    min-height: 40px;
    transition: all 0.2s;
}

.chat-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.chat-input-actions {
    display: flex;
    gap: 0.5rem;
}

.chat-input-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-input-btn:hover {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

.chat-send-btn {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

.chat-send-btn:hover {
    background: #0284c7;
    transform: scale(1.05);
}

.chat-send-btn svg {
    width: 18px;
    height: 18px;
}

/* Loading State */
.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--glass-border);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Empty State */
.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    text-align: center;
    color: var(--text-secondary);
}

.chat-empty svg {
    width: 64px;
    height: 64px;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.chat-empty h4 {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.chat-empty p {
    font-size: 0.9rem;
    max-width: 300px;
}

/* =============================================== */
/* ===            RESPONSIVE DESIGN            === */
/* =============================================== */

@media (max-width: 768px) {
    .community-chat-widget {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }

    .chat-sidebar {
        width: 100px;
    }

    .user-name {
        display: none;
    }

    .chat-header-subtitle {
        display: none;
    }
}

@media (max-width: 480px) {
    .chat-sidebar {
        display: none;
    }

    .btn-community-chat {
        width: 48px;
        height: 48px;
        bottom: 16px;
        right: 16px;
    }

    .btn-community-chat svg {
        width: 20px;
        height: 20px;
    }
}

/* =============================================== */
/* ===            SCROLLBAR STYLES             === */
/* =============================================== */

.chat-messages::-webkit-scrollbar,
.chat-sidebar::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.chat-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.chat-sidebar::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.chat-sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--accent-blue);
}
