/* Chat Popup Styles */
/* Chat Tabs Inside Chat Section */
.home-chat-tabs-compact {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(59, 130, 246, 0.2);
    background: rgba(0, 0, 0, 0.15);
}

.home-chat-tab-btn {
    padding: 8px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 6px;
    color: #a0a8b8;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .home-chat-tab-btn:hover {
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(59, 130, 246, 0.3);
    }

    .home-chat-tab-btn.active {
        background: rgba(59, 130, 246, 0.25);
        border-color: rgba(59, 130, 246, 0.5);
        color: #60a5fa;
    }

/* Chat Input Wrapper */
.home-chat-input-wrapper-compact {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    margin-top: 12px;
}

.home-chat-input-compact {
    flex: 1;
    padding: 10px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 6px;
    color: #e0e7ef;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    min-height: 50px;
}

    .home-chat-input-compact:focus {
        outline: none;
        border-color: rgba(59, 130, 246, 0.5);
        box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
    }
.chat-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.chat-popup-container {
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    background: linear-gradient(180deg, rgba(26, 31, 46, 0.98) 0%, rgba(15, 20, 25, 0.98) 100%);
    backdrop-filter: blur(20px);
    border: 2px solid rgba(59, 130, 246, 0.4);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease-out;
    overflow: hidden;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.chat-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(59, 130, 246, 0.3);
    background: rgba(0, 0, 0, 0.2);
}

.chat-popup-title {
    color: #e0e7ef;
    font-size: 18px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

.chat-popup-close {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 6px;
    color: #f87171;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-popup-close:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.5);
    transform: scale(1.1);
}

.chat-popup-tabs {
    padding: 12px 20px;
    border-bottom: 1px solid rgba(59, 130, 246, 0.2);
    background: rgba(0, 0, 0, 0.15);
}

.chat-popup-main-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.chat-popup-sub-tabs {
    display: flex;
    gap: 8px;
}

.chat-popup-tab {
    padding: 8px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 6px;
    color: #a0a8b8;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
}

.chat-tab-icon {
    font-size: 20px;
    line-height: 1;
}

.chat-popup-tab:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(59, 130, 246, 0.3);
}

.chat-popup-tab.active {
    background: rgba(59, 130, 246, 0.25);
    border-color: rgba(59, 130, 246, 0.5);
    color: #60a5fa;
}

.chat-popup-subtab {
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(59, 130, 246, 0.15);
    border-radius: 6px;
    color: #8892a6;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-popup-subtab:hover {
    background: rgba(255, 255, 255, 0.05);
}

.chat-popup-subtab.active {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.3);
    color: #60a5fa;
}

.chat-popup-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 20px;
    gap: 16px;
}

.chat-popup-messages {
    flex: 1;
    min-height: 300px;
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.chat-popup-message,
.chat-popup-message-item {
    display: flex;
    gap: 12px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    border: 1px solid rgba(59, 130, 246, 0.1);
    transition: all 0.2s;
}

.chat-popup-message:hover,
.chat-popup-message-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(59, 130, 246, 0.2);
}

.chat-popup-message-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.chat-message-user-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.35);
    font-size: 20px;
    flex-shrink: 0;
    border: 1px solid rgba(59, 130, 246, 0.22);
}

.chat-message-user-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-popup-message-content {
    flex: 1;
}

.chat-popup-message-user {
    color: #60a5fa;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
}

.chat-popup-message-text {
    color: #e0e7ef;
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 4px;
    word-wrap: break-word;
}

.chat-popup-message-time {
    color: #8892a6;
    font-size: 11px;
}

.chat-popup-empty {
    color: #8892a6;
    font-size: 14px;
    text-align: center;
    padding: 40px 20px;
}

.chat-popup-input-area {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chat-popup-input {
    flex: 1;
    padding: 12px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 8px;
    color: #e0e7ef;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 70px;
    max-height: 150px;
}

.chat-popup-input:focus {
    outline: none;
    border-color: rgba(59, 130, 246, 0.5);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chat-popup-send-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.8) 0%, rgba(37, 99, 235, 0.8) 100%);
    border: 1px solid rgba(59, 130, 246, 0.5);
    border-radius: 8px;
    color: #ffffff;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.chat-popup-send-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(59, 130, 246, 1) 0%, rgba(37, 99, 235, 1) 100%);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    transform: translateY(-1px);
}

.chat-popup-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Scrollbar Styling */
.chat-popup-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-popup-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

.chat-popup-messages::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.5);
    border-radius: 4px;
}

.chat-popup-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(59, 130, 246, 0.7);
}

/* Responsive — mobile sheet above bottom nav */
@media (max-width: 767.98px) {
    .chat-popup-overlay {
        align-items: flex-end;
        padding: 0;
        z-index: 10050;
    }

    .chat-popup-container {
        width: 100%;
        max-width: 100%;
        max-height: min(85vh, calc(100dvh - var(--mobile-header-total, 106px) - var(--s-2)));
        border-radius: 14px 14px 0 0;
        border-bottom: none;
        margin-bottom: calc(var(--bottomnav-h, 56px) + var(--safe-bot, 0px));
        animation: chatSheetUp 0.28s ease-out;
    }

    @keyframes chatSheetUp {
        from {
            transform: translateY(100%);
            opacity: 0.6;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    .chat-popup-messages {
        min-height: 180px;
        max-height: none;
        flex: 1;
    }

    .chat-popup-content {
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }
}

/* Chat Inline Styles (for dashboard) */
.chat-inline-container {
    width: 100%;
    background: linear-gradient(180deg, rgba(26, 31, 46, 0.98) 0%, rgba(15, 20, 25, 0.98) 100%);
    backdrop-filter: blur(20px);
    border: 2px solid rgba(59, 130, 246, 0.4);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden;
}

.chat-inline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(59, 130, 246, 0.3);
    background: rgba(0, 0, 0, 0.2);
}

.chat-inline-title {
    color: #e0e7ef;
    font-size: 18px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

.chat-inline-tabs {
    padding: 12px 20px;
    border-bottom: 1px solid rgba(59, 130, 246, 0.2);
    background: rgba(0, 0, 0, 0.15);
    width: 100%;
    display: block;
    text-align: left;
}

.chat-inline-main-tabs {
    display: flex;
    gap: 8px;
    justify-content: flex-start;
    align-items: center;
}

.chat-inline-container .chat-inline-tab {
    padding: 8px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 6px;
    color: #a0a8b8;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
}

.chat-inline-container .chat-inline-tab:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(59, 130, 246, 0.3);
}

.chat-inline-container .chat-inline-tab.active {
    background: rgba(59, 130, 246, 0.25);
    border-color: rgba(59, 130, 246, 0.5);
    color: #60a5fa;
}

.chat-inline-content {
    display: flex !important;
    flex-direction: column !important;
    flex: 1;
    min-height: 0;
    padding: 20px;
    gap: 16px;
    width: 100%;
}

.chat-inline-messages {
    flex: 1;
    min-height: 300px;
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.chat-inline-message-item {
    display: flex;
    gap: 12px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    border: 1px solid rgba(59, 130, 246, 0.1);
    transition: all 0.2s;
}

.chat-inline-message-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(59, 130, 246, 0.2);
}

.chat-inline-message-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.chat-inline-message-content {
    flex: 1;
}

.chat-inline-message-user {
    color: #60a5fa;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
}

.chat-inline-message-text {
    color: #e0e7ef;
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 4px;
    word-wrap: break-word;
}

.chat-inline-message-time {
    color: #8892a6;
    font-size: 11px;
}

.chat-inline-empty {
    color: #8892a6;
    font-size: 14px;
    text-align: center;
    padding: 40px 20px;
}

.chat-inline-input-area {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chat-inline-input {
    flex: 1;
    padding: 12px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 8px;
    color: #e0e7ef;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 70px;
    max-height: 150px;
}

.chat-inline-input:focus {
    outline: none;
    border-color: rgba(59, 130, 246, 0.5);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chat-inline-send-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.8) 0%, rgba(37, 99, 235, 0.8) 100%);
    border: 1px solid rgba(59, 130, 246, 0.5);
    border-radius: 8px;
    color: #ffffff;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.chat-inline-send-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(59, 130, 246, 1) 0%, rgba(37, 99, 235, 1) 100%);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    transform: translateY(-1px);
}

.chat-inline-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Scrollbar Styling for Inline */
.chat-inline-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-inline-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

.chat-inline-messages::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.5);
    border-radius: 4px;
}

.chat-inline-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(59, 130, 246, 0.7);
}

/* Responsive for Inline */
@media (max-width: 768px) {
    .chat-inline-messages {
        min-height: 200px;
        max-height: 300px;
    }
}

/* Threaded replies */
.chat-thread-root {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-thread-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
}

.chat-thread-icon-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 6px;
    background: rgba(59, 130, 246, 0.12);
    color: #93c5fd;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.chat-thread-icon-btn:hover {
    background: rgba(59, 130, 246, 0.28);
    border-color: rgba(59, 130, 246, 0.45);
    color: #bfdbfe;
}

.chat-thread-icon-btn.is-expanded {
    background: rgba(59, 130, 246, 0.32);
    border-color: rgba(59, 130, 246, 0.55);
    color: #dbeafe;
}

.chat-thread-icon-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
    border-radius: 999px;
    background: #3b82f6;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    line-height: 14px;
    text-align: center;
}

.chat-thread-replies {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
    padding: 8px 8px 8px 12px;
    border-left: 2px solid rgba(59, 130, 246, 0.35);
    background: rgba(0, 0, 0, 0.15);
    border-radius: 0 6px 6px 0;
}

.chat-thread-replies--popup {
    margin-left: 44px;
}

.chat-thread-replies--inline {
    margin-left: 44px;
}

.chat-thread-replies--home {
    grid-column: 1 / -1;
    margin-left: 40px;
}

.chat-thread-reply-item {
    display: grid;
    grid-template-columns: 28px 1fr;
    gap: 8px;
    align-items: start;
}

.chat-thread-reply-avatar {
    width: 28px;
    height: 28px;
    font-size: 10px;
}

.chat-thread-reply-top {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 2px;
}

.chat-thread-reply-top strong {
    color: #93c5fd;
    font-size: 12px;
}

.chat-thread-time {
    color: #6b7280;
    font-size: 10px;
}

.chat-thread-reply-text {
    margin: 0;
    color: #d1d5db;
    font-size: 13px;
    line-height: 1.4;
    word-break: break-word;
}

.chat-reply-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    margin-bottom: 8px;
    border-left: 3px solid rgba(59, 130, 246, 0.6);
    background: rgba(59, 130, 246, 0.1);
    border-radius: 4px;
}

.chat-reply-preview-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.chat-reply-preview-label {
    color: #6b7280;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.chat-reply-preview-content strong {
    color: #93c5fd;
    font-size: 12px;
}

.chat-reply-preview-text {
    color: #9ca3af;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-reply-preview-cancel {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
    color: #9ca3af;
    cursor: pointer;
    font-size: 12px;
}

.chat-reply-preview-cancel:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

