/* ========================================
   CHAT SYSTEM STYLES
   ======================================== */

/* Chat Icon (Bottom Right) */
.chat-icon {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: var(--gradient-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
    z-index: 9998;
}

.chat-icon:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.chat-icon-bubble {
    font-size: 28px;
    animation: bounce 2s infinite;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    border-radius: 12px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: bold;
    min-width: 20px;
    text-align: center;
}

/* Chat Panel */
.chat-panel {
    position: fixed;
    bottom: 90px;
    right: 20px;
    display: none;
    z-index: 9999;
    gap: 10px;
}

.chat-panel.show {
    display: flex;
}

/* User List */
.chat-user-list {
    width: 320px;
    height: 380px;
    background: rgba(26, 26, 46, 0.98);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--gradient-primary);
    border-radius: 12px 12px 0 0;
    border-bottom: 1px solid var(--border-color);
}

.chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: white;
}

.close-chat-panel {
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.close-chat-panel:hover {
    background: var(--border-hover);
}

/* Users Container */
.chat-users-container {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-user-item {
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
    margin-bottom: 2px;
}

.chat-user-item:hover {
    background: rgba(102, 126, 234, 0.1);
}

.chat-user-item.has-unread {
    background: rgba(102, 126, 234, 0.05);
    border-left: 3px solid #ff4757;
}

/* Chat Section Headers and Dividers */
.chat-section-header {
    padding: 8px 16px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-section-divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 8px 16px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-section-divider::before,
.chat-section-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.chat-section-divider::before {
    margin-right: 8px;
}

.chat-section-divider::after {
    margin-left: 8px;
}

.chat-user-item.has-unread:hover {
    background: rgba(255, 71, 87, 0.25);
}

.chat-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.chat-user-info {
    flex: 1;
    min-width: 0;
}

.chat-user-name {
    font-weight: 500;
    color: #e0e0e0;
    font-size: 13px;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-user-last-message {
    display: none;
    /* Hidden to save space */
}

.chat-user-unread {
    background: #ff4757;
    color: white;
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: bold;
    min-width: 20px;
    text-align: center;
    flex-shrink: 0;
}

/* Search */
.chat-search {
    padding: 12px;
    border-top: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.2);
    position: relative;
}

.chat-search input {
    width: 100%;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: #e0e0e0;
    font-size: 14px;
    outline: none;
    transition: all 0.3s;
}

.chat-search input:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--gradient-start);
}

.chat-search-results {
    position: absolute;
    bottom: 100%;
    left: 12px;
    right: 12px;
    max-height: 200px;
    overflow-y: auto;
    background: rgba(26, 26, 46, 0.98);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 8px;
    display: none;
}

.chat-search-results.show {
    display: block;
}

/* Chat Windows Container */
.chat-windows {
    gap: 10px;
    flex-direction: row-reverse;
}

/* Individual Chat Window */
.chat-window {
    width: 350px;
    height: 380px;
    background: rgba(26, 26, 46, 0.98);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

.chat-window.minimized {
    height: 48px;
    overflow: hidden;
    margin-top: auto;
}

.chat-window.minimized .chat-messages,
.chat-window.minimized .chat-input-container {
    display: none;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-window-header {
    padding: 8px 16px;
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
    cursor: move;
}

.chat-user-name {
    flex: 1;
    font-weight: 600;
    color: white;
    font-size: 14px;
}

.minimize-chat,
.close-chat {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.minimize-chat:hover,
.close-chat:hover {
    background: var(--border-hover);
}

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

.chat-message {
    display: flex;
    gap: 8px;
    max-width: 80%;
}

.chat-message.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.chat-message-content {
    background: rgba(102, 126, 234, 0.2);
    padding: 10px 14px;
    border-radius: 16px;
    color: #e0e0e0;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.chat-message.sent .chat-message-content {
    background: var(--gradient-primary);
    color: white;
}

.chat-message-time {
    font-size: 11px;
    color: #888;
    margin-top: 4px;
}

/* Input Area */
.chat-input-container {
    padding: 12px;
    border-top: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    gap: 8px;
}

.chat-input-container input {
    flex: 1;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: #e0e0e0;
    font-size: 14px;
    outline: none;
    transition: all 0.3s;
}

.chat-input-container input:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--gradient-start);
}

.send-message {
    background: var(--gradient-primary);
    border: none;
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s;
}

.send-message:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.send-message:active {
    transform: translateY(0);
}

/* Loading State */
.chat-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #888;
}

.chat-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(102, 126, 234, 0.2);
    border-top-color: var(--gradient-start);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 12px;
}

/* Empty State */
.chat-empty {
    text-align: center;
    padding: 40px 20px;
    color: #888;
}

.chat-empty p {
    margin: 8px 0;
}

/* Scrollbar Styling */
.chat-users-container::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar,
.chat-search-results::-webkit-scrollbar {
    width: 6px;
}

.chat-users-container::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track,
.chat-search-results::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.chat-users-container::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb,
.chat-search-results::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.5);
    border-radius: 3px;
}

.chat-users-container::-webkit-scrollbar-thumb:hover,
.chat-messages::-webkit-scrollbar-thumb:hover,
.chat-search-results::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.7);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .chat-icon {
        bottom: 15px;
        right: 15px;
        width: 50px;
        height: 50px;
    }

    .chat-icon-bubble {
        font-size: 24px;
    }

    .chat-panel {
        bottom: 75px;
        right: 10px;
        left: 10px;
    }

    .chat-user-list,
    .chat-window {
        width: 100%;
        max-width: 400px;
    }

    .chat-windows {
        flex-direction: column-reverse;
    }
}