/* =============================================
   Chat CSS – refactored for mobile
   ============================================= */

/* ── Wrapper ── */
.asp-chat-page-wrapper {
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px;
}

@media (max-width: 767.98px) {
    .asp-chat-page-wrapper {
        padding: 0;
    }
}

/* ── Layout container ── */
.chat-layout {
    display: flex;
    border: 1px solid var(--border-default, #E5E7EB);
    border-radius: var(--radius-md, 8px);
    overflow: hidden;
    background: var(--surface-default, #fff);
    height: calc(100vh - 160px);
    min-height: 500px;
}

/* ── Columns ── */
.chat-sidebar-col {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-default, #E5E7EB);
    min-height: 0;
}

.chat-panel-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ── Sidebar ── */
.chat-sidebar {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--surface-soft, #F7F8FC);
    min-height: 0;
}

.chat-sidebar-header {
    background: var(--surface-default, #fff);
    padding: 12px 16px;
    flex-shrink: 0;
}

/* ── Conversation list ── */
.chat-conversation-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

.chat-conv-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-default, #E5E7EB);
    cursor: pointer;
    transition: background-color 0.15s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-conv-item:hover {
    background-color: var(--brand-primary-soft, #EEEAFE);
}

.chat-conv-item.active {
    background-color: var(--brand-primary-soft, #EEEAFE);
    border-left: 3px solid var(--brand-primary, #2D16C8);
}

.chat-conv-item.unread .chat-conv-name {
    font-weight: 700;
}

.chat-conv-avatar-placeholder {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--brand-primary-soft, #EEEAFE);
    color: var(--brand-primary, #2D16C8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.chat-conv-avatar-img {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.chat-conv-info {
    flex: 1;
    min-width: 0;
}

.chat-conv-name {
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conv-preview {
    font-size: 0.775rem;
    color: var(--text-muted, #6B7280);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.chat-conv-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

.chat-conv-time {
    font-size: 0.7rem;
    color: var(--text-muted, #6B7280);
    white-space: nowrap;
}

.chat-unread-badge {
    background: var(--brand-primary, #2D16C8);
    color: #fff;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0 4px;
}

/* ── Conversation panel ── */
#chatPanel {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.chat-conv-header {
    background: #fff;
    flex-shrink: 0;
    padding: 10px 16px;
    min-height: 60px;
}

.chat-conv-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--brand-primary-soft, #EEEAFE);
    color: var(--brand-primary, #2D16C8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
    font-size: 0.9rem;
}

/* ── Messages ── */
.chat-messages {
    background: var(--surface-soft, #F7F8FC);
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    padding: 12px;
}

.chat-message {
    display: flex;
    gap: 8px;
    max-width: 75%;
}

.chat-message.own {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message.other {
    align-self: flex-start;
}

.chat-message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--brand-primary-soft, #EEEAFE);
    color: var(--brand-primary, #2D16C8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    flex-shrink: 0;
    align-self: flex-end;
}

.chat-message-bubble {
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 0.875rem;
    line-height: 1.45;
    word-break: break-word;
}

.chat-message.own .chat-message-bubble {
    background: var(--brand-primary, #2D16C8);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message.other .chat-message-bubble {
    background: var(--surface-default, #fff);
    color: var(--text-body, #374151);
    border: 1px solid var(--border-default, #E5E7EB);
    border-bottom-left-radius: 4px;
}

.chat-message-deleted .chat-message-bubble {
    background: var(--surface-subtle, #F3F4F6) !important;
    color: var(--text-muted, #6B7280) !important;
    font-style: italic;
    border-color: var(--border-default, #E5E7EB) !important;
}

.chat-message-time {
    font-size: 0.67rem;
    color: var(--text-muted, #6B7280);
    margin-top: 2px;
    text-align: right;
}

.chat-message.other .chat-message-time {
    text-align: left;
}

/* ── Input area ── */
.chat-input-area {
    background: var(--surface-default, #fff);
    flex-shrink: 0;
    padding: 6px 12px;
    border-top: 2px solid var(--border-default, #E5E7EB);
}

.chat-input {
    resize: none;
    border-radius: 20px !important;
    max-height: 100px;
    overflow-y: auto;
    border-color: var(--border-strong, #D1D5DB);
    font-size: 0.875rem;
    line-height: 1.4;
}

.chat-input:focus {
    box-shadow: 0 0 0 0.15rem rgba(45, 22, 200, 0.18);
    border-color: rgba(45, 22, 200, 0.45);
}

.chat-attach-btn {
    border-radius: 50% !important;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    font-size: 1rem;
    flex-shrink: 0;
}

.chat-send-btn {
    width: 38px;
    height: 38px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50% !important;
    flex-shrink: 0;
}

/* ── Empty state ── */
.chat-empty-icon {
    font-size: 2.8rem;
    line-height: 1;
}

.chat-empty-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-body, #374151);
}

.chat-empty-subtitle {
    font-size: 0.825rem;
    color: var(--text-muted, #6B7280);
    max-width: 260px;
    line-height: 1.5;
}

/* ── Back button (mobile only) ── */
.chat-back-btn {
    flex-shrink: 0;
    padding: 4px 8px;
}

/* ── Navbar badge ── */
.asp-nav-icon-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
}

.chat-nav-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    transform: translate(50%, -50%);
    background: #DC2626;
    color: #fff;
    border-radius: 50%;
    min-width: 17px;
    height: 17px;
    font-size: 0.62rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    pointer-events: none;
    border: 1.5px solid #fff;
    z-index: 1;
    line-height: 1;
}

/* ── Reconnection Banner ── */
.chat-reconnect-banner {
    padding: 8px 16px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: var(--radius-sm, 6px);
    margin-bottom: 8px;
}

.chat-reconnect-banner.warning {
    background: #FFF7ED;
    color: #D97706;
    border: 1px solid #D97706;
}

.chat-reconnect-banner.success {
    background: #ECFDF3;
    color: #16A34A;
    border: 1px solid #16A34A;
}

.chat-reconnect-banner.danger {
    background: #FEF2F2;
    color: #DC2626;
    border: 1px solid #DC2626;
}

/* ── Inline image ── */
.chat-inline-image {
    max-width: 220px;
    max-height: 220px;
    border-radius: 8px;
    cursor: pointer;
    object-fit: cover;
    display: block;
}

.chat-message-image {
    padding: 4px !important;
    background: transparent !important;
    border: none !important;
}

.chat-message.own .chat-message-image {
    background: transparent !important;
}

/* ── PDF file ── */
.chat-message-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface-subtle, #F3F4F6);
    border: 1px solid var(--border-default, #E5E7EB);
    border-radius: 10px;
    text-decoration: none;
    color: var(--text-body, #374151);
    transition: background 0.15s;
    font-size: 0.85rem;
}

.chat-message-file:hover {
    background: var(--brand-primary-soft, #EEEAFE);
    color: var(--brand-primary, #2D16C8);
}

.chat-message-file-icon {
    font-size: 1.4rem;
    color: #DC2626;
    flex-shrink: 0;
}

.chat-message.own .chat-message-file {
    background: rgba(255,255,255,0.18);
    border-color: rgba(255,255,255,0.25);
    color: #fff;
}

.chat-message.own .chat-message-file:hover {
    background: rgba(255,255,255,0.28);
    color: #fff;
}

.chat-message.own .chat-message-file-icon {
    color: rgba(255,255,255,0.85);
}

/* ── Group icon ── */
.chat-conv-group-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--brand-primary, #2D16C8);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

/* ── Conversation menu ── */
.chat-conv-menu {
    position: relative;
    flex-shrink: 0;
    margin-left: 2px;
}

.chat-conv-menu-btn {
    background: none;
    border: none;
    padding: 4px 6px;
    border-radius: var(--radius-sm, 6px);
    color: var(--text-muted, #6B7280);
    cursor: pointer;
    display: none;
    font-size: 0.9rem;
    line-height: 1;
}

.chat-conv-item:hover .chat-conv-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-conv-menu-btn:hover {
    background: var(--border-default, #E5E7EB);
}

.chat-conv-dropdown {
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--surface-default, #fff);
    border: 1px solid var(--border-default, #E5E7EB);
    border-radius: var(--radius-md, 8px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    z-index: 200;
    min-width: 180px;
    overflow: hidden;
}

.chat-conv-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    background: none;
    border: none;
    font-size: 0.85rem;
    color: var(--text-body, #374151);
    cursor: pointer;
    text-align: left;
    transition: background 0.1s;
}

.chat-conv-dropdown-item:hover {
    background: var(--surface-soft, #F7F8FC);
}

.chat-conv-dropdown-item.text-danger {
    color: #DC2626;
}

.chat-conv-dropdown-item.text-danger:hover {
    background: #FEF2F2;
}

/* ── Loading skeleton ── */
.chat-inbox-skeleton {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-default, #E5E7EB);
    animation: chatSkeletonPulse 1.4s ease-in-out infinite;
}

.chat-inbox-skeleton-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #E5E7EB;
    flex-shrink: 0;
}

.chat-inbox-skeleton-lines {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-inbox-skeleton-line {
    height: 10px;
    border-radius: 6px;
    background: #E5E7EB;
}

.chat-inbox-skeleton-line.short {
    width: 55%;
}

@keyframes chatSkeletonPulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.45; }
}

/* ── Message states ── */
.chat-message.sending {
    opacity: 0.6;
}

.chat-message.sending .chat-message-bubble {
    background: #E5E7EB !important;
    color: #6B7280 !important;
}

.chat-conv-item .chat-unread-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--brand-primary, #2D16C8);
    flex-shrink: 0;
}

#sendBtn.loading {
    pointer-events: none;
    opacity: 0.7;
}

#sendBtn.loading::after {
    content: "";
    display: inline-block;
    width: 13px;
    height: 13px;
    border: 2px solid rgba(255,255,255,0.5);
    border-top-color: #fff;
    border-radius: 50%;
    animation: chatSpinBtn 0.7s linear infinite;
    vertical-align: -2px;
}

@keyframes chatSpinBtn {
    to { transform: rotate(360deg); }
}

/* ── Active conversation flex ── */
#activeConversation {
    min-height: 0;
    flex: 1;
}

#typingIndicator {
    flex-shrink: 0;
}

/* =============================================
   MOBILE  (≤ 767px)
   ============================================= */
@media (max-width: 767.98px) {
    .chat-layout {
        height: calc(100vh - 110px);
        min-height: 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
        position: relative;
    }

    .chat-sidebar-col {
        position: absolute;
        inset: 0;
        width: 100%;
        border-right: none;
        z-index: 1;
        transition: transform 0.25s ease, opacity 0.25s ease;
    }

    .chat-panel-col {
        position: absolute;
        inset: 0;
        width: 100%;
        z-index: 2;
        transform: translateX(100%);
        transition: transform 0.25s ease;
        background: var(--surface-default, #fff);
    }

    .chat-layout.chat-mobile-conv-open .chat-sidebar-col {
        transform: translateX(-100%);
        opacity: 0;
        pointer-events: none;
    }

    .chat-layout.chat-mobile-conv-open .chat-panel-col {
        transform: translateX(0);
    }

    .chat-message {
        max-width: 88%;
    }

    .chat-messages {
        padding: 10px;
    }

    .chat-conv-header {
        padding: 8px 10px;
        min-height: 54px;
    }

    .chat-sidebar-header {
        padding: 10px 12px;
    }

    .chat-input-area {
        padding: 8px 10px;
    }

    .chat-attach-btn {
        width: 34px;
        height: 34px;
        font-size: 0.9rem;
    }

    .chat-send-btn {
        width: 34px;
        height: 34px;
    }

    .chat-empty-icon {
        font-size: 2.4rem;
    }

    .chat-empty-subtitle {
        max-width: 220px;
    }

    #totalUnreadBadge {
        font-size: 0.7rem;
        min-width: 20px;
        height: 20px;
        padding: 0 5px;
        display: none;
        align-items: center;
        justify-content: center;
        line-height: 1;
    }

    #totalUnreadBadge.has-unread {
        display: inline-flex !important;
    }
}

/* totalUnreadBadge global reset */
#totalUnreadBadge {
    line-height: 1;
    vertical-align: middle;
}

/* ── Nav badge fix ── */
.chat-nav-badge {
    top: 2px;
    right: 2px;
    transform: translate(50%, -50%);
}

@media (max-width: 991.98px) {
    /* Trên mobile, asp-nav-icon-btn đã bị đổi thành full-width
       nên badge phải định vị lại theo góc trái icon */
    .asp-nav-icon-btn .chat-nav-badge {
        top: 50%;
        right: auto;
        left: 24px;
        transform: translateY(-150%);
    }
}