/* ═══════════════════════════════════════════════════
   ADMIN CHAT — Telegram-like
   ═══════════════════════════════════════════════════ */

.chat-page {
    display: flex;
    height: calc(100vh - 160px);
    min-height: 600px;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,.04);
}

/* ─── Sidebar ─── */
.chat-sidebar {
    width: 340px;
    flex-shrink: 0;
    border-inline-end: 1px solid var(--bs-border-color);
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, rgba(var(--bs-primary-rgb), .02), transparent);
}
.chat-sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--bs-border-color);
    background: var(--bs-body-bg);
}
.chat-sidebar-header .row-1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.chat-sidebar-header h6 {
    margin: 0;
    font-weight: 700;
    font-size: .95rem;
    color: var(--bs-heading-color);
}
.chat-new-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: var(--bs-primary);
    color: #fff;
    border: none;
    border-radius: 50px;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}
.chat-new-btn:hover { background: #6558d6; transform: translateY(-1px); }

.chat-conv-search {
    position: relative;
}
.chat-conv-search input {
    width: 100%;
    padding: 8px 36px 8px 12px;
    border: 1px solid var(--bs-border-color);
    border-radius: 50px;
    font-size: .82rem;
    background: rgba(var(--bs-primary-rgb), .04);
    color: var(--bs-body-color);
    transition: all .15s;
}
.chat-conv-search input:focus {
    outline: none;
    background: var(--bs-body-bg);
    border-color: rgba(var(--bs-primary-rgb), .4);
    box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), .1);
}
.chat-conv-search i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--bs-secondary-color);
    font-size: .95rem;
    pointer-events: none;
}

.chat-conversations-list {
    flex: 1;
    overflow-y: auto;
    background: var(--bs-body-bg);
}
.chat-conversations-list::-webkit-scrollbar { width: 5px; }
.chat-conversations-list::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,.12);
    border-radius: 3px;
}

/* ─── Conversation item ─── */
.conv-item {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background .12s;
    border-bottom: 1px solid rgba(0,0,0,.03);
    position: relative;
}
.conv-item:hover {
    background: rgba(var(--bs-primary-rgb), .05);
}
.conv-item.active {
    background: rgba(var(--bs-primary-rgb), .1);
}
.conv-item.active::before {
    content: '';
    position: absolute;
    inset-inline-start: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--bs-primary);
}

.conv-avatar {
    position: relative;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(var(--bs-primary-rgb), .1);
}
.conv-avatar img { width: 100%; height: 100%; object-fit: cover; }
.conv-avatar .online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: #28c76f;
    border: 2px solid var(--bs-body-bg);
    border-radius: 50%;
}

.conv-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.conv-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3px;
    gap: 8px;
}
.conv-name {
    font-weight: 700;
    font-size: .88rem;
    color: var(--bs-heading-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-time {
    font-size: .68rem;
    color: var(--bs-secondary-color);
    white-space: nowrap;
    flex-shrink: 0;
}

.conv-preview {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}
.conv-last {
    flex: 1;
    font-size: .76rem;
    color: var(--bs-secondary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-mine-arrow {
    color: var(--bs-primary);
    font-size: .8rem;
    margin-inline-end: 2px;
}
.conv-unread {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: #28c76f;
    color: #fff;
    font-size: .68rem;
    font-weight: 800;
    border-radius: 50px;
    flex-shrink: 0;
}
.conv-status {
    font-size: .68rem;
    padding: 2px 8px;
    border-radius: 50px;
    font-weight: 600;
    flex-shrink: 0;
}
.conv-status.online { background: rgba(40,199,111,.12); color: #28c76f; }
.conv-status.offline { background: rgba(143,147,163,.12); color: #8f93a3; }

/* ─── Main pane ─── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: linear-gradient(180deg, rgba(0,0,0,.01), transparent);
}
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--bs-secondary-color);
    font-size: .9rem;
    text-align: center;
    padding: 40px 20px;
}
.chat-empty i {
    font-size: 4rem;
    opacity: .2;
    margin-bottom: 16px;
}

.chat-main-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--bs-border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bs-body-bg);
}
.chat-main-header .chat-admin-avatar {
    width: 42px; height: 42px;
    border-radius: 50%;
    overflow: hidden;
    position: relative;
    background: rgba(var(--bs-primary-rgb), .1);
}
.chat-main-header .chat-admin-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-main-header .admin-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--bs-heading-color);
}
.chat-main-header .admin-status {
    font-size: .75rem;
    color: var(--bs-secondary-color);
    display: flex;
    align-items: center;
    gap: 5px;
}
.chat-main-header .admin-status .dot {
    width: 7px;
    height: 7px;
    background: #28c76f;
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(40,199,111,.15);
}
.chat-main-header .admin-status .dot.offline {
    background: #8f93a3;
    box-shadow: none;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,.12);
    border-radius: 4px;
}

.chat-day-separator {
    text-align: center;
    margin: 12px 0;
    position: relative;
}
.chat-day-separator::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--bs-border-color);
    z-index: 0;
}
.chat-day-separator span {
    position: relative;
    z-index: 1;
    background: var(--bs-body-bg);
    padding: 0 12px;
    font-size: .7rem;
    color: var(--bs-secondary-color);
    font-weight: 600;
}

.chat-message {
    display: flex;
    gap: 8px;
    max-width: 72%;
    animation: msgIn .2s ease;
    align-self: flex-start;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
.chat-message.mine {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.chat-message-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(var(--bs-primary-rgb), .1);
    margin-top: auto;
}
.chat-message-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-message-content {
    max-width: 100%;
    min-width: 0;
}
.chat-message-body {
    padding: 9px 14px;
    border-radius: 14px;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    font-size: .87rem;
    line-height: 1.55;
    word-wrap: break-word;
    color: var(--bs-body-color);
}
.chat-message.mine .chat-message-body {
    background: linear-gradient(135deg, #7367F0, #6558d6);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(115,103,240,.2);
}
.chat-message-time {
    font-size: .65rem;
    opacity: .65;
    margin-top: 3px;
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 0 6px;
}
.chat-message.mine .chat-message-time {
    justify-content: flex-end;
    color: var(--bs-secondary-color);
}
.chat-message.mine .sent-check { color: rgba(0,0,0,.35); }
.chat-message.mine .read-check { color: #28c76f; font-weight: 700; }

/* Typing indicator */
#chatTypingIndicator {
    display: flex;
    gap: 6px;
    padding: 8px 20px;
    font-size: .75rem;
    color: var(--bs-secondary-color);
    align-items: center;
}
.typing-dots {
    display: inline-flex;
    gap: 3px;
}
.typing-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--bs-primary);
    animation: typingBounce 1.4s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* Input bar */
.chat-input-bar {
    border-top: 1px solid var(--bs-border-color);
    padding: 12px 16px;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: var(--bs-body-bg);
}
.chat-input-bar textarea {
    flex: 1;
    resize: none;
    min-height: 42px;
    max-height: 120px;
    padding: 11px 16px;
    border: 1px solid var(--bs-border-color);
    border-radius: 22px;
    font-size: .88rem;
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    font-family: inherit;
    line-height: 1.4;
    transition: all .15s;
}
.chat-input-bar textarea:focus {
    outline: none;
    border-color: rgba(var(--bs-primary-rgb), .4);
    box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), .1);
}
.chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--bs-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    transition: all .15s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
    box-shadow: 0 3px 10px rgba(115,103,240,.25);
}
.chat-send-btn:hover {
    background: #6558d6;
    transform: scale(1.05);
}
.chat-send-btn:disabled {
    background: rgba(var(--bs-primary-rgb), .3);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Navbar badge */
#chatNavBadge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    background: #ea5455;
    color: #fff;
    font-size: .6rem;
    font-weight: 800;
    border-radius: 50px;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bs-body-bg);
    box-shadow: 0 2px 4px rgba(234,84,85,.3);
}
#chatNavBadge.show { display: inline-flex; }

/* Dropdown widget (navbar) */
.chat-widget {
    min-width: 360px;
    max-width: 420px;
    border-radius: 14px;
    overflow: hidden;
}
.chat-widget-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--bs-border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(90deg, rgba(var(--bs-primary-rgb), .06), transparent);
}
.chat-widget-header h6 { margin: 0; font-size: .9rem; font-weight: 700; }
.chat-widget-admins { max-height: 340px; overflow-y: auto; }
.chat-admin-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background .15s;
    text-decoration: none;
    color: inherit;
}
.chat-admin-row:hover { background: rgba(var(--bs-primary-rgb), .06); }
.chat-admin-avatar {
    position: relative;
    width: 38px; height: 38px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(var(--bs-primary-rgb), .1);
}
.chat-admin-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-admin-avatar .online-dot {
    position: absolute;
    bottom: 1px; right: 1px;
    width: 11px; height: 11px;
    background: #28c76f;
    border: 2px solid var(--bs-body-bg);
    border-radius: 50%;
}
.chat-admin-info { flex: 1; min-width: 0; }
.chat-admin-name {
    font-weight: 600;
    font-size: .85rem;
    color: var(--bs-heading-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-admin-username { font-size: .72rem; color: var(--bs-secondary-color); }
.chat-admin-unread {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    background: #ea5455;
    color: #fff;
    font-size: .7rem;
    font-weight: 800;
    border-radius: 50px;
}
.chat-widget-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--bs-border-color);
    text-align: center;
    background: rgba(0,0,0,.01);
}
.chat-widget-footer a {
    font-size: .78rem;
    font-weight: 600;
    text-decoration: none;
}

@media (max-width: 767px) {
    .chat-page { flex-direction: column; height: auto; min-height: auto; }
    .chat-sidebar { width: 100%; max-height: 320px; border-inline-end: none; border-bottom: 1px solid var(--bs-border-color); }
    .chat-message { max-width: 88%; }
    .chat-widget { min-width: auto; width: 100vw !important; }
}

/* ═══════════════════════════════════════════════════
   V2 PATCH — back button + skeleton
   ═══════════════════════════════════════════════════ */

.chat-back-btn {
    width: 36px;
    height: 36px;
    background: rgba(var(--bs-primary-rgb), .1);
    border: none;
    border-radius: 50%;
    color: var(--bs-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all .15s;
    flex-shrink: 0;
}
.chat-back-btn:hover {
    background: rgba(var(--bs-primary-rgb), .2);
    transform: translateX(-2px);
}

.chat-skeleton {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px;
}
.chat-skeleton-item {
    height: 44px;
    background: rgba(0,0,0,.05);
    border-radius: 14px;
    animation: skPulse 1.5s ease-in-out infinite;
}
.chat-skeleton-item.mine {
    width: 60%;
    margin-inline-start: auto;
}
.chat-skeleton-item.other {
    width: 55%;
}
@keyframes skPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .4; }
}

/* ═══════════════════════════════════════════════════
   SMOOTH TRANSITIONS
   ═══════════════════════════════════════════════════ */

.chat-messages {
    scroll-behavior: smooth;
}

.chat-message {
    animation: msgIn .18s ease-out;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Prevent layout shift from image loading */
.chat-message-avatar {
    background: rgba(var(--bs-primary-rgb), .08);
}

/* Smooth scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,.15);
    border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,.25);
}

/* ═══════════════════════════════════════════════════
   ANTI-FLICKER
   ═══════════════════════════════════════════════════ */

/* Remove animation from re-rendered messages */
.chat-message {
    animation: none !important;
}

/* Only animate truly new messages (those added via JS append) */
.chat-message.just-added {
    animation: msgIn .2s ease-out;
}

/* Prevent double scrollbar flicker */
.chat-messages {
    overflow-y: scroll !important;
    scrollbar-gutter: stable;
}

/* Prevent image loading flicker */
.chat-message-avatar img {
    background-color: rgba(115, 103, 240, .08);
    min-width: 100%;
    min-height: 100%;
}
