/* Hub Chat System Styles */
/* Floating chat button + draggable/resizable popup with two-panel tabs */

/* ==================== FLOATING ACTION BUTTON ==================== */
.chat-fab {
    position: fixed;
    bottom: 24px;
    left: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
    z-index: 9990;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(102, 126, 234, 0.5);
}

.chat-fab:active {
    transform: scale(0.95);
}

.chat-fab i {
    font-size: 24px;
    color: white;
}

.chat-fab .unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: #ef4444;
    color: white;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

.chat-fab .unread-badge:empty,
.chat-fab .unread-badge[data-count="0"] {
    display: none;
}

/* ==================== CHAT POPUP CONTAINER ==================== */
.chat-popup {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 380px;
    height: 500px;
    min-width: 320px;
    min-height: 400px;
    max-width: 90vw;
    max-height: 80vh;
    background: var(--bg-card, white);
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-color, #e1e5e9);
}

.chat-popup.open {
    display: flex;
    animation: chatPopupOpen 0.3s ease;
}

.chat-popup.expanded {
    width: 600px !important;
    height: 70vh !important;
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    transform: translate(-50%, -50%) !important;
}

@keyframes chatPopupOpen {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==================== CHAT HEADER (Draggable) ==================== */
.chat-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: move;
    user-select: none;
    flex-shrink: 0;
}

.chat-header-title {
    flex: 1;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header-title i {
    font-size: 16px;
}

.chat-header-controls {
    display: flex;
    gap: 8px;
}

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

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

.chat-header-btn i {
    font-size: 12px;
}

/* ==================== TAB BAR (Two-Panel) ==================== */
.chat-tabs {
    display: flex;
    background: var(--bg-secondary, #f8f9fa);
    border-bottom: 1px solid var(--border-color, #e1e5e9);
    flex-shrink: 0;
}

.chat-tab {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary, #6c757d);
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.chat-tab:hover {
    background: var(--bg-hover, #e9ecef);
    color: var(--text-primary, #333);
}

.chat-tab.active {
    color: #667eea;
    background: var(--bg-card, white);
}

.chat-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 3px 3px 0 0;
}

.chat-tab .tab-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #ef4444;
    color: white;
    font-size: 10px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-tab .tab-badge:empty,
.chat-tab .tab-badge[data-count="0"] {
    display: none;
}

/* ==================== CHAT CONTENT PANELS ==================== */
.chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.chat-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    flex-direction: column;
}

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

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

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

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

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

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary, #999);
}

/* Message Styles */
.chat-message {
    display: flex;
    gap: 8px;
    max-width: 80%;
    align-self: flex-start;
    align-items: flex-start;
}

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

.chat-message-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 10px;
    font-weight: 600;
    flex-shrink: 0;
    margin-top: 2px;
}

.chat-message-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.chat-message-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.chat-message-author {
    font-weight: 600;
    color: var(--text-primary, #333);
}

.chat-message.own .chat-message-author {
    color: #667eea;
}

.chat-message-time {
    color: var(--text-secondary, #999);
}

.chat-message-bubble {
    padding: 8px 12px;
    border-radius: 12px;
    background: #3d3555 !important;
    color: #e8e0f0 !important;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    white-space: pre-wrap;
    display: inline-block;
}

.chat-message.own .chat-message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
    border-bottom-right-radius: 4px;
}

.chat-message:not(.own) .chat-message-bubble {
    border-bottom-left-radius: 4px;
}

/* System Messages */
.chat-message.system {
    max-width: 100%;
    align-self: center;
}

.chat-message.system .chat-message-bubble {
    background: transparent;
    color: var(--text-secondary, #999);
    font-size: 12px;
    font-style: italic;
    padding: 8px 16px;
}

/* Chat Links */
.chat-link {
    color: #7aa2f7 !important;
    text-decoration: underline;
    word-break: break-all;
    transition: color 0.2s ease;
}

.chat-link:hover {
    color: #9db8ff !important;
}

.chat-message.own .chat-link {
    color: #b8d4ff !important;
}

.chat-message.own .chat-link:hover {
    color: #ffffff !important;
}

/* Event Links - Special styling */
.chat-event-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(122, 162, 247, 0.15) !important;
    border-radius: 6px;
    text-decoration: none !important;
    word-break: normal;
    border: 1px solid rgba(122, 162, 247, 0.3);
    transition: all 0.2s ease;
}

.chat-event-link:hover {
    background: rgba(122, 162, 247, 0.25) !important;
    border-color: rgba(122, 162, 247, 0.5);
}

.chat-event-link i {
    font-size: 12px;
    opacity: 0.8;
}

.chat-message.own .chat-event-link {
    background: rgba(255, 140, 50, 0.6) !important;
    border-color: rgba(255, 140, 50, 0.75);
    color: #fff0f3 !important;
}

.chat-message.own .chat-event-link:hover {
    background: rgba(255, 140, 50, 0.75) !important;
    border-color: rgba(255, 140, 50, 0.9);
    color: #ffffff !important;
}

/* ==================== USER MODERATION ICONS ==================== */
.chat-mod-icons {
    display: inline-flex;
    gap: 6px;
    margin-left: 6px;
    opacity: 0.6;
    transition: opacity 0.15s;
}

.chat-message:hover .chat-mod-icons {
    opacity: 1;
}

.chat-mod-icon {
    font-size: 11px;
    color: #666;
    cursor: pointer;
    padding: 2px;
    background: none;
    border: none;
    transition: all 0.15s;
    position: relative;
}

.chat-mod-icon:hover {
    transform: scale(1.2);
}

.chat-mod-icon.mute:hover,
.chat-mod-icon.mute.active {
    color: #fbbf24;
}

.chat-mod-icon.block:hover,
.chat-mod-icon.block.active {
    color: #ef4444;
}

/* Tooltip for mod icons */
.chat-mod-icon::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: #1a1a2e;
    color: #fff;
    font-size: 10px;
    white-space: nowrap;
    border-radius: 4px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    margin-bottom: 4px;
    border: 1px solid rgba(255,255,255,0.1);
    z-index: 10;
}

.chat-mod-icon:hover::after {
    opacity: 1;
}

/* Hide mod icons on own messages */
.chat-message.own .chat-mod-icons {
    display: none;
}

/* ==================== MUTED USERS PANEL ==================== */
.muted-users-panel {
    display: none;
    position: absolute;
    top: 48px;
    left: 0;
    right: 0;
    background: var(--bg-card, #2a2a3e);
    border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.1));
    z-index: 10;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.muted-users-panel.open {
    display: block;
}

.muted-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: rgba(251, 191, 36, 0.1);
    border-bottom: 1px solid rgba(251, 191, 36, 0.2);
    font-size: 13px;
    font-weight: 600;
    color: #fbbf24;
}

.muted-panel-header i {
    margin-right: 6px;
}

.muted-panel-close {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
    transition: color 0.2s;
}

.muted-panel-close:hover {
    color: #fff;
}

.muted-users-list {
    padding: 8px;
}

.no-muted {
    text-align: center;
    color: #666;
    font-size: 12px;
    padding: 16px;
    margin: 0;
}

.muted-user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    transition: background 0.2s;
}

.muted-user-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.muted-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

.muted-user-name {
    flex: 1;
    font-size: 13px;
    color: var(--text-primary, #e1e5e9);
}

.unmute-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.2s;
}

.unmute-btn:hover {
    background: #fbbf24;
    color: #1a1a2e;
}

/* Muted count badge on header button */
.muted-count {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: #fbbf24;
    color: #1a1a2e;
    font-size: 10px;
    font-weight: 600;
    display: none;
    align-items: center;
    justify-content: center;
}

/* Position relative for the muted button to show badge */
#chatMutedBtn {
    position: relative;
}

/* ==================== MESSAGE INPUT ==================== */
.chat-input-container {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color, #e1e5e9);
    background: var(--bg-card, white);
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border-color, #e1e5e9);
    border-radius: 20px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    overflow-y: auto;
    background: var(--bg-secondary, #f8f9fa);
    color: var(--text-primary, #333);
    transition: border-color 0.2s ease;
}

.chat-input:focus {
    outline: none;
    border-color: #667eea;
    background: var(--bg-card, white);
}

.chat-input::placeholder {
    color: var(--text-secondary, #999);
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chat-send-btn i {
    font-size: 16px;
}

/* ==================== MY EVENTS LIST ==================== */
.events-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.event-chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.event-chat-item:hover {
    background: var(--bg-hover, #f0f2f5);
}

.event-chat-item.completed {
    opacity: 0.6;
}

.event-chat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.event-chat-icon.cooking { background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); color: white; }
.event-chat-icon.fishing { background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%); color: white; }
.event-chat-icon.foraging { background: linear-gradient(135deg, #10b981 0%, #059669 100%); color: white; }
.event-chat-icon.hunting { background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%); color: white; }
.event-chat-icon.mining { background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%); color: white; }
.event-chat-icon.bug { background: linear-gradient(135deg, #14b8a6 0%, #0d9488 100%); color: white; }

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

.event-chat-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary, #333);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.event-chat-meta {
    font-size: 12px;
    color: var(--text-secondary, #999);
    display: flex;
    align-items: center;
    gap: 6px;
}

.event-chat-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #ef4444;
    color: white;
    font-size: 10px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.event-chat-badge:empty,
.event-chat-badge[data-count="0"] {
    display: none;
}

/* ==================== EVENT CHAT HEADER (Back Button) ==================== */
.event-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color, #e1e5e9);
    background: var(--bg-secondary, #f8f9fa);
}

.event-chat-back {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: var(--bg-card, white);
    color: var(--text-primary, #333);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.event-chat-back:hover {
    background: var(--bg-hover, #e9ecef);
}

.event-chat-title {
    flex: 1;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary, #333);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==================== RESIZE HANDLE ==================== */
.chat-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    opacity: 0.3;
    transition: opacity 0.2s ease;
}

.chat-resize-handle:hover {
    opacity: 0.7;
}

.chat-resize-handle::before {
    content: '';
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 10px;
    height: 10px;
    border-right: 2px solid var(--text-secondary, #999);
    border-bottom: 2px solid var(--text-secondary, #999);
}

/* ==================== EMPTY STATES ==================== */
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px;
    text-align: center;
    color: var(--text-secondary, #999);
}

.chat-empty i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.chat-empty p {
    font-size: 14px;
    margin: 0;
}

/* ==================== LOADING STATE ==================== */
.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: var(--text-secondary, #999);
    font-size: 13px;
    gap: 8px;
}

.chat-loading i {
    animation: spin 1s linear infinite;
}

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

/* ==================== LOGIN REQUIRED ==================== */
.chat-login-required {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px;
    text-align: center;
}

.chat-login-required i {
    font-size: 48px;
    color: #667eea;
    margin-bottom: 16px;
}

.chat-login-required h3 {
    margin: 0 0 8px 0;
    color: var(--text-primary, #333);
    font-size: 16px;
}

.chat-login-required p {
    margin: 0 0 16px 0;
    color: var(--text-secondary, #999);
    font-size: 14px;
}

.chat-login-btn {
    padding: 10px 24px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* ==================== DARK MODE SUPPORT ==================== */
[data-theme="dark"] .chat-popup {
    background: var(--bg-card, #1e1e2e);
    border-color: var(--border-color, #3a3a4a);
}

[data-theme="dark"] .chat-tabs {
    background: var(--bg-secondary, #252535);
}

[data-theme="dark"] .chat-tab.active {
    background: var(--bg-card, #1e1e2e);
}

[data-theme="dark"] .chat-message-bubble {
    background: var(--bg-secondary, #252535);
}

[data-theme="dark"] .chat-input {
    background: var(--bg-secondary, #252535);
    border-color: var(--border-color, #3a3a4a);
}

[data-theme="dark"] .chat-input:focus {
    background: var(--bg-card, #1e1e2e);
}

[data-theme="dark"] .event-chat-header {
    background: var(--bg-secondary, #252535);
}

[data-theme="dark"] .event-chat-back {
    background: var(--bg-card, #1e1e2e);
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 480px) {
    .chat-fab {
        bottom: 16px;
        left: 16px;
        width: 50px;
        height: 50px;
    }
    
    .chat-popup {
        bottom: 76px;
        right: 8px;
        left: 8px;
        width: auto;
        max-width: none;
        height: 60vh;
    }
    
    .chat-popup.expanded {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        transform: none;
    }
}
