/**
 * Community Chat Stylesheet
 * 
 * - Full Dark Mode & Light Mode support for Nhalavn Theme
 * - Responsive 2-column Chatroom Layout
 * 
 * @package Nhalavn
 * @version 1.0.0
 */

/* ========================================================================== */
/* 1. LAYOUT & CONTAINER                                                      */
/* ========================================================================== */

.td-chat-wrapper {
    position: relative;
    border-radius: 16px;
    background: var(--bs-body-bg, #ffffff);
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    height: 750px;
    max-height: calc(100vh - 160px);
    display: flex;
}

[data-bs-theme="dark"] .td-chat-wrapper {
    background: #14171d;
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

/* ========================================================================== */
/* 2. LEFT PANE: ROOMS LIST                                                   */
/* ========================================================================== */

.td-chat-rooms-pane {
    width: 280px;
    min-width: 250px;
    border-right: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(0, 0, 0, 0.015);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
}

[data-bs-theme="dark"] .td-chat-rooms-pane {
    border-right-color: rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.2);
}

.td-chat-rooms-header {
    padding: 16px 18px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

[data-bs-theme="dark"] .td-chat-rooms-header {
    border-bottom-color: rgba(255, 255, 255, 0.06);
}

.td-chat-rooms-header h6 {
    margin: 0;
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--bs-secondary, #6c757d);
}

.td-chat-rooms-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.td-chat-room-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 12px;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    transition: all 0.15s ease-in-out;
    border: 1px solid transparent;
    user-select: none;
}

.td-chat-room-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

[data-bs-theme="dark"] .td-chat-room-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.td-chat-room-item.is-active {
    background: rgba(var(--bs-primary-rgb, 13, 110, 253), 0.12);
    border-color: rgba(var(--bs-primary-rgb, 13, 110, 253), 0.25);
    color: var(--bs-primary, #0d6efd);
    font-weight: 600;
}

[data-bs-theme="dark"] .td-chat-room-item.is-active {
    background: rgba(var(--bs-primary-rgb, 13, 110, 253), 0.2);
    border-color: rgba(var(--bs-primary-rgb, 13, 110, 253), 0.4);
    color: #6ea8fe;
}

.td-chat-room-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    color: var(--bs-secondary, #6c757d);
    flex-shrink: 0;
    transition: transform 0.15s ease;
}

[data-bs-theme="dark"] .td-chat-room-icon {
    background: rgba(255, 255, 255, 0.08);
    color: #94a3b8;
}

.td-chat-room-item.is-active .td-chat-room-icon {
    background: var(--bs-primary, #0d6efd);
    color: #fff;
    transform: scale(1.05);
}

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

.td-chat-room-name {
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.td-chat-room-desc {
    font-size: 11px;
    color: var(--bs-secondary, #6c757d);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.td-chat-room-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
    background: #fef3c7;
    color: #b45309;
    border: 1px solid #fde68a;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

/* ========================================================================== */
/* 3. RIGHT PANE: CHAT MAIN VIEWPORT                                          */
/* ========================================================================== */

.td-chat-main-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bs-body-bg, #ffffff);
    position: relative;
}

[data-bs-theme="dark"] .td-chat-main-pane {
    background: #14171d;
}

/* Header */
.td-chat-main-header {
    padding: 14px 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bs-body-bg, #ffffff);
    z-index: 5;
}

[data-bs-theme="dark"] .td-chat-main-header {
    border-bottom-color: rgba(255, 255, 255, 0.08);
    background: #14171d;
}

.td-chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.td-chat-toggle-rooms-btn {
    display: none;
    background: none;
    border: none;
    color: inherit;
    font-size: 18px;
    padding: 6px;
    cursor: pointer;
    border-radius: 8px;
}

.td-chat-current-title {
    font-size: 16px;
    font-weight: 800;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.td-chat-current-desc {
    font-size: 12px;
    color: var(--bs-secondary, #6c757d);
    margin: 2px 0 0 0;
}

.td-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.td-chat-btn-action {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: transparent;
    color: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
}

[data-bs-theme="dark"] .td-chat-btn-action {
    border-color: rgba(255, 255, 255, 0.08);
}

.td-chat-btn-action:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--bs-primary, #0d6efd);
}

[data-bs-theme="dark"] .td-chat-btn-action:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* Pinned Bar */
.td-chat-pinned-bar {
    background: #fffbeb;
    color: #92400e;
    border-bottom: 1px solid #fef3c7;
    padding: 8px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    gap: 10px;
}

[data-bs-theme="dark"] .td-chat-pinned-bar {
    background: rgba(217, 119, 6, 0.12);
    color: #fde68a;
    border-bottom-color: rgba(217, 119, 6, 0.2);
}

.td-chat-pinned-content {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.td-chat-pinned-badge {
    background: #f59e0b;
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

/* ========================================================================== */
/* 4. MESSAGES LIST & BUBBLES                                                 */
/* ========================================================================== */

.td-chat-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.td-chat-loading-state,
.td-chat-empty-state {
    margin: auto;
    text-align: center;
    padding: 40px 20px;
    color: var(--bs-secondary, #6c757d);
}

.td-chat-load-more-btn {
    align-self: center;
    font-size: 12px;
    font-weight: 600;
    padding: 5px 14px;
    border-radius: 20px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: transparent;
    color: inherit;
    cursor: pointer;
    transition: all 0.15s ease;
}

.td-chat-load-more-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

[data-bs-theme="dark"] .td-chat-load-more-btn {
    border-color: rgba(255, 255, 255, 0.1);
}

[data-bs-theme="dark"] .td-chat-load-more-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* Single Message Row */
.td-chat-message-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    position: relative;
}

.td-chat-message-row.is-pinned {
    background: rgba(245, 158, 11, 0.05);
    border-radius: 12px;
    padding: 10px 12px;
    border-left: 3px solid #f59e0b;
}

.td-chat-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.td-chat-avatar-wrap img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.td-chat-content-wrap {
    flex: 1;
    min-width: 0;
}

.td-chat-meta-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.td-chat-sender-name {
    font-size: 13px;
    font-weight: 700;
    color: inherit;
}

/* User Badges */
.td-chat-role-badge {
    font-size: 10px;
    font-weight: 800;
    padding: 1px 6px;
    border-radius: 6px;
    letter-spacing: 0.2px;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.td-chat-role-badge.badge-admin {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    box-shadow: 0 1px 4px rgba(220, 38, 38, 0.25);
}

.td-chat-role-badge.badge-mod {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    box-shadow: 0 1px 4px rgba(37, 99, 235, 0.25);
}

.td-chat-role-badge.badge-vip {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
    box-shadow: 0 1px 4px rgba(217, 119, 6, 0.25);
}

.td-chat-role-badge.badge-member {
    background: rgba(0, 0, 0, 0.06);
    color: var(--bs-secondary, #64748b);
}

[data-bs-theme="dark"] .td-chat-role-badge.badge-member {
    background: rgba(255, 255, 255, 0.08);
    color: #94a3b8;
}

.td-chat-time {
    font-size: 11px;
    color: var(--bs-secondary, #6c757d);
    opacity: 0.8;
}

/* Text Bubble */
.td-chat-bubble {
    display: inline-block;
    max-width: 100%;
    padding: 9px 14px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid rgba(0, 0, 0, 0.05);
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    color: inherit;
}

[data-bs-theme="dark"] .td-chat-bubble {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.07);
}

.td-chat-message-row.is-me .td-chat-bubble {
    background: rgba(var(--bs-primary-rgb, 13, 110, 253), 0.08);
    border-color: rgba(var(--bs-primary-rgb, 13, 110, 253), 0.18);
}

[data-bs-theme="dark"] .td-chat-message-row.is-me .td-chat-bubble {
    background: rgba(var(--bs-primary-rgb, 13, 110, 253), 0.16);
    border-color: rgba(var(--bs-primary-rgb, 13, 110, 253), 0.3);
}

.td-chat-bubble.is-deleted {
    font-style: italic;
    opacity: 0.6;
    background: transparent !important;
    border: 1px dashed rgba(0, 0, 0, 0.1) !important;
}

[data-bs-theme="dark"] .td-chat-bubble.is-deleted {
    border-color: rgba(255, 255, 255, 0.1) !important;
}

/* Attachments */
.td-chat-msg-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.td-chat-attachment-img {
    max-width: 220px;
    max-height: 180px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid rgba(0, 0, 0, 0.08);
    cursor: zoom-in;
    transition: transform 0.15s ease;
}

.td-chat-attachment-img:hover {
    transform: scale(1.02);
}

/* Actions Menu on Hover */
.td-chat-msg-actions {
    opacity: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    transition: opacity 0.15s ease;
}

.td-chat-message-row:hover .td-chat-msg-actions {
    opacity: 1;
    pointer-events: auto;
}

.td-chat-btn-msg-action {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: var(--bs-body-bg, #fff);
    color: var(--bs-secondary, #6c757d);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.1s ease;
}

[data-bs-theme="dark"] .td-chat-btn-msg-action {
    background: #1e232b;
    border-color: rgba(255, 255, 255, 0.1);
    color: #94a3b8;
}

.td-chat-btn-msg-action:hover {
    color: var(--bs-danger, #dc3545);
    border-color: var(--bs-danger, #dc3545);
}

/* ========================================================================== */
/* 5. INPUT & FOOTER BAR                                                      */
/* ========================================================================== */

.td-chat-footer-bar {
    padding: 12px 18px 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    background: var(--bs-body-bg, #ffffff);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

[data-bs-theme="dark"] .td-chat-footer-bar {
    border-top-color: rgba(255, 255, 255, 0.08);
    background: #14171d;
}

/* Upload Preview */
.td-chat-attachment-previews {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0;
}

.td-chat-preview-item {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.td-chat-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.td-chat-btn-remove-preview {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border: none;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* Emoji Bar */
.td-chat-quick-emojis {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.td-chat-emoji-pill {
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    padding: 2px 7px;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
    transition: transform 0.1s ease;
}

[data-bs-theme="dark"] .td-chat-emoji-pill {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.08);
}

.td-chat-emoji-pill:hover {
    transform: scale(1.2);
}

/* Input Form Row */
.td-chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 14px;
    padding: 6px 12px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

[data-bs-theme="dark"] .td-chat-input-row {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.08);
}

.td-chat-input-row:focus-within {
    border-color: var(--bs-primary, #0d6efd);
    box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb, 13, 110, 253), 0.15);
}

.td-chat-textarea {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    outline: none;
    padding: 6px 0;
    max-height: 120px;
    min-height: 24px;
    font-size: 14px;
    line-height: 1.5;
    color: inherit;
}

.td-chat-input-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-bottom: 2px;
}

.td-chat-btn-tool {
    background: transparent;
    border: none;
    color: var(--bs-secondary, #6c757d);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.td-chat-btn-tool:hover {
    color: var(--bs-primary, #0d6efd);
    background: rgba(0, 0, 0, 0.05);
}

[data-bs-theme="dark"] .td-chat-btn-tool:hover {
    background: rgba(255, 255, 255, 0.08);
}

.td-chat-btn-send {
    background: var(--bs-primary, #0d6efd);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 6px 14px;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.td-chat-btn-send:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

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

/* Guest prompt */
.td-chat-guest-prompt {
    padding: 14px 18px;
    text-align: center;
    background: rgba(0, 0, 0, 0.02);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    font-size: 13px;
    color: var(--bs-secondary, #6c757d);
}

[data-bs-theme="dark"] .td-chat-guest-prompt {
    background: rgba(255, 255, 255, 0.02);
    border-top-color: rgba(255, 255, 255, 0.06);
}

/* New message alert floating badge */
.td-chat-new-msg-toast {
    position: absolute;
    bottom: 85px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bs-primary, #0d6efd);
    color: #fff;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 6px;
    animation: bounce 1s infinite alternate;
}

@keyframes bounce {
    from { transform: translate(-50%, 0); }
    to { transform: translate(-50%, -4px); }
}

/* ========================================================================== */
/* 6. RESPONSIVE MOBILE BEHAVIOR                                              */
/* ========================================================================== */

@media (max-width: 768px) {
    .td-chat-wrapper {
        height: calc(100vh - 120px);
    }

    .td-chat-toggle-rooms-btn {
        display: block;
    }

    .td-chat-rooms-pane {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        width: 80%;
        max-width: 300px;
        background: var(--bs-body-bg, #ffffff);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.2);
        transform: translateX(-100%);
    }

    [data-bs-theme="dark"] .td-chat-rooms-pane {
        background: #14171d;
    }

    .td-chat-rooms-pane.is-open {
        transform: translateX(0);
    }
}
