/* =====================================================
   CHAT PAGE – K Game MMO
   ===================================================== */

/* ---- Body lock cho trang chat ---- */
body.page-chat {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

body.page-chat .site-header {
    flex-shrink: 0;
}

/* ---- Layout shell ---- */
.chat-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: #18191a;
    position: relative; /* neo cho absolute children trên mobile */
}

/* =====================================================
   SIDEBAR
   ===================================================== */
.chat-sidebar {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: #1c1e1f;
    border-right: 1px solid rgba(255,255,255,0.07);
    overflow: hidden;
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
}

.sidebar-head {
    padding: 18px 16px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: #e2e8f0;
}

.sidebar-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.sidebar-search-icon {
    position: absolute;
    left: 10px;
    font-size: 0.82rem;
    opacity: 0.45;
    pointer-events: none;
}

.sidebar-search {
    width: 100%;
    padding: 8px 12px 8px 32px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 999px;
    color: #e2e8f0;
    font-size: 0.85rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.sidebar-search:focus {
    outline: none;
    border-color: rgba(99,102,241,0.55);
    background: rgba(99,102,241,0.06);
}

.sidebar-search::placeholder { color: rgba(148,163,184,0.5); }

/* Conv list */
.conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
}

.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-thumb { background: rgba(148,163,184,0.2); border-radius: 4px; }

.conv-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-radius: 0;
    position: relative;
}

.conv-item:hover { background: rgba(255,255,255,0.04); }

.conv-item.active {
    background: rgba(99,102,241,0.12);
    border-right: 3px solid #6366f1;
}

.conv-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    letter-spacing: -0.01em;
}

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

.conv-name {
    font-size: 0.88rem;
    font-weight: 600;
    color: #e2e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
}

.conv-preview {
    font-size: 0.78rem;
    color: rgba(148,163,184,0.75);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    flex-shrink: 0;
}

.conv-time {
    font-size: 0.7rem;
    color: rgba(148,163,184,0.5);
}

.conv-unread {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #6366f1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
}

.conv-list-empty {
    padding: 32px 16px;
    text-align: center;
    font-size: 0.85rem;
    color: rgba(148,163,184,0.5);
}

/* =====================================================
   MAIN AREA
   ===================================================== */
.chat-main {
    flex: 1;
    min-height: 0;      /* cho phép flex children distribute height đúng */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* =====================================================
   CHAT PANEL
   ===================================================== */
.chat-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Top bar */
.chat-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    background: #1c1e1f;
    flex-shrink: 0;
}

.topbar-back {
    display: none; /* shown only on mobile */
    background: none;
    border: none;
    color: #e2e8f0;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.topbar-peer {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.peer-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.peer-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: #e2e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.peer-status {
    font-size: 0.75rem;
    color: rgba(148,163,184,0.65);
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    animation: statusPulse 2.5s ease-in-out infinite;
}

@keyframes statusPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

.topbar-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.topbar-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: none;
    border: none;
    color: rgba(148,163,184,0.8);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.topbar-btn:hover {
    background: rgba(255,255,255,0.08);
    color: #e2e8f0;
}

/* ---- Messages area ---- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 18px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(148,163,184,0.18); border-radius: 4px; }

/* Date separator */
.msg-date-sep {
    text-align: center;
    font-size: 0.72rem;
    color: rgba(148,163,184,0.45);
    padding: 10px 0 4px;
    position: relative;
}

.msg-date-sep span {
    background: #18191a;
    padding: 0 10px;
    position: relative;
    z-index: 1;
}

.msg-date-sep::before {
    content: '';
    position: absolute;
    left: 0; right: 0;
    top: 50%;
    height: 1px;
    background: rgba(255,255,255,0.05);
}

/* Message row */
.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 3px;
}

.msg-row.me { flex-direction: row-reverse; }

.msg-row.them + .msg-row.me,
.msg-row.me + .msg-row.them { margin-top: 8px; }

/* Avatar in message */
.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    align-self: flex-end;
}

.msg-row.me .msg-avatar { display: none; }

/* Bubble */
.bubble-wrap {
    display: flex;
    flex-direction: column;
    max-width: 68%;
    gap: 2px;
}

.msg-row.me .bubble-wrap { align-items: flex-end; }
.msg-row.them .bubble-wrap { align-items: flex-start; }

.bubble {
    padding: 9px 13px;
    border-radius: 18px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-break: break-word;
    position: relative;
    animation: bubbleIn 0.16s ease-out;
}

@keyframes bubbleIn {
    from { opacity: 0; transform: translateY(5px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.bubble.them {
    background: #2d2f31;
    color: #e2e8f0;
    border-bottom-left-radius: 5px;
}

.bubble.me {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: #fff;
    border-bottom-right-radius: 5px;
}

/* Image in bubble */
.bubble-img {
    max-width: 220px;
    border-radius: 12px;
    display: block;
    cursor: pointer;
}

.bubble-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 0;
}

.bubble-file-icon { font-size: 1.4rem; }

.bubble-file-name {
    font-size: 0.82rem;
    font-weight: 500;
    word-break: break-all;
}

/* Timestamp */
.msg-time {
    font-size: 0.68rem;
    color: rgba(148,163,184,0.4);
    padding: 0 4px;
    align-self: flex-end;
}

/* Reaction badge */
.bubble-reactions {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    margin-top: 3px;
}

.react-badge {
    font-size: 0.75rem;
    background: rgba(255,255,255,0.08);
    border-radius: 999px;
    padding: 1px 6px;
    cursor: pointer;
}

/* Context menu */
.msg-ctx-menu {
    position: fixed;
    background: #242526;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 5px 0;
    box-shadow: 0 16px 40px rgba(0,0,0,0.6);
    z-index: 9999;
    min-width: 140px;
}

.msg-ctx-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 14px;
    font-size: 0.85rem;
    color: #e2e8f0;
    cursor: pointer;
    transition: background 0.15s;
}

.msg-ctx-item:hover { background: rgba(255,255,255,0.06); }
.msg-ctx-item.danger { color: #f87171; }

/* ---- Typing indicator ---- */
.typing-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 4px 18px 8px;
}

.peer-avatar-xs {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.typing-bubble {
    background: #2d2f31;
    border-radius: 18px;
    border-bottom-left-radius: 5px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.typing-bubble span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(148,163,184,0.6);
    animation: typingDot 1.1s ease-in-out infinite;
}

.typing-bubble span:nth-child(2) { animation-delay: 0.18s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.36s; }

@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ---- File preview ---- */
.chat-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 8px;
}

.preview-chip {
    display: flex;
    align-items: center;
    gap: 7px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.8rem;
    color: #e2e8f0;
    max-width: 200px;
}

.preview-chip-thumb {
    width: 34px;
    height: 34px;
    object-fit: cover;
    border-radius: 5px;
    flex-shrink: 0;
}

.preview-chip-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.preview-chip-rm {
    background: none;
    border: none;
    color: rgba(148,163,184,0.6);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    flex-shrink: 0;
    padding: 0 2px;
}

.preview-chip-rm:hover { color: #f87171; }

/* ---- Emoji panel ---- */
.emoji-panel {
    border-top: 1px solid rgba(255,255,255,0.06);
    background: #1c1e1f;
    padding: 10px 14px;
    max-height: 200px;
    overflow-y: auto;
}

.emoji-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
}

.emoji-btn-item {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 5px 6px;
    border-radius: 6px;
    transition: background 0.12s;
    line-height: 1;
}

.emoji-btn-item:hover { background: rgba(255,255,255,0.08); }

/* ---- Attach menu ---- */
.attach-wrap { position: relative; }

.attach-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    background: #242526;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 6px 0;
    box-shadow: 0 12px 32px rgba(0,0,0,0.5);
    min-width: 150px;
    z-index: 50;
}

.attach-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 14px;
    font-size: 0.85rem;
    color: #e2e8f0;
    cursor: pointer;
    transition: background 0.15s;
}

.attach-item:hover { background: rgba(255,255,255,0.06); }

/* ---- Input bar ---- */
.chat-inputbar {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 14px 12px;
    border-top: 1px solid rgba(255,255,255,0.07);
    background: #1c1e1f;
    flex-shrink: 0;
}

.inputbar-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    color: rgba(148,163,184,0.8);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.inputbar-btn:hover {
    background: rgba(255,255,255,0.1);
    color: #e2e8f0;
}

.emoji-toggle.active {
    background: rgba(99,102,241,0.2);
    color: #a5b4fc;
    border-color: rgba(99,102,241,0.4);
}

.input-wrap {
    flex: 1;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 2px 6px;
    display: flex;
    align-items: center;
    transition: border-color 0.2s;
}

.input-wrap:focus-within {
    border-color: rgba(99,102,241,0.5);
    background: rgba(99,102,241,0.05);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #e2e8f0;
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    padding: 8px 8px;
    line-height: 1.5;
    overflow-y: auto;
}

.chat-input::placeholder { color: rgba(148,163,184,0.4); }

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: filter 0.15s, transform 0.15s;
    box-shadow: 0 4px 14px rgba(99,102,241,0.45);
}

.send-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.send-btn:active { transform: scale(0.94); }

/* =====================================================
   IMAGE LIGHTBOX
   ===================================================== */
.img-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.88);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.img-lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    cursor: default;
}

/* =====================================================
   RESPONSIVE – MOBILE
   ===================================================== */
@media (max-width: 768px) {
    .chat-sidebar {
        position: absolute;
        top: 0; left: 0; bottom: 0;
        z-index: 10;
        width: 100%;
        transform: translateX(0);
    }

    .chat-sidebar.slide-out {
        transform: translateX(-100%);
    }

    .topbar-back { display: flex; }

    .chat-main {
        position: absolute;
        inset: 0;
        transform: translateX(100%);
        transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
        z-index: 11;
        background: #18191a;
    }

    .chat-main.slide-in {
        transform: translateX(0);
    }

    .bubble-wrap { max-width: 82%; }
}
