/**
 * =============================================================================
 * CHAT MODULE - CSS (Theme-Compatible Rewrite)
 * =============================================================================
 * 
 * All colors use CSS variables from app.css.
 * No [data-theme="dark"] selectors — theme handled by variable switching.
 * 
 * @module      Chat
 * @version     3.0.0
 */

/* ============================================
   CHAT CONTAINER & HEADER
   ============================================ */
.chat-container {
    background: var(--bg-card);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 700px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
    position: relative;
    transition: box-shadow 0.3s ease;
}

.chat-container:hover {
    box-shadow: var(--shadow-lg);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--accent);
    color: #fff;
    flex-shrink: 0;
}

.chat-header h3 {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
}

.chat-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ============================================
   ONLINE BADGE
   ============================================ */
.online-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.3);
    padding: 5px 10px;
    border-radius: 20px;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
}

.online-badge>span {
    color: #fff;
}

#onlineNum {
    color: var(--text-primary);
}

.online-badge:hover {
    background: rgba(0, 0, 0, 0.5);
}

.online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    animation: chatPulse 2s infinite;
}

@keyframes chatPulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.clear-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.clear-btn:hover {
    background: #ef4444;
    color: #fff;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #10b981;
    transition: background 0.3s;
}

/* ============================================
   MESSAGES AREA
   ============================================ */
.chat-messages-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg-main);
}

.chat-loading,
.chat-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
    font-size: 14px;
}

.load-sentinel {
    text-align: center;
    padding: 10px;
    color: var(--text-muted);
    font-size: 12px;
}

/* Nút tin mới (trong vùng chat) */
.new-msg-btn {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--accent-light);
    z-index: 20;
    border: none;
    transition: transform 0.2s, background 0.2s;
}

.new-msg-btn:hover {
    background: var(--accent-hover);
    transform: translateX(-50%) translateY(-2px);
}

/* ============================================
   MESSAGE BUBBLES
   ============================================ */
.chat-msg {
    display: flex;
    gap: 10px;
    max-width: 80%;
    position: relative;
    animation: msgFadeIn 0.3s ease;
}

@keyframes msgFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-msg.own {
    margin-left: auto;
    flex-direction: row-reverse;
}

.msg-avatar img {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-color);
    transition: transform 0.2s;
    flex-shrink: 0;
}

.msg-avatar img:hover {
    transform: scale(1.1);
}

.msg-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.msg-meta {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
}

.own .msg-meta {
    flex-direction: row-reverse;
}

.msg-name {
    font-weight: 600;
    color: var(--text-primary);
}

.msg-role {
    font-size: 9px;
    padding: 2px 5px;
    border-radius: 4px;
    background: var(--accent-light);
    color: var(--accent-readable);
}

.msg-time {
    color: var(--text-muted);
}

/* Wrapper bubbles text + images together */
.msg-bubble-wrapper {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 100%;
}

.own .msg-bubble-wrapper {
    align-items: flex-end;
}

/* Content row: bubble + action button */
.msg-content-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.own .msg-content-row {
    flex-direction: row-reverse;
}

/* Bubble */
.msg-text {
    background: var(--bg-hover);
    padding: 10px 14px;
    border-radius: 16px;
    border-top-left-radius: 4px;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.own .msg-text {
    background: var(--accent);
    color: #fff;
    border-radius: 16px;
    border-top-right-radius: 4px;
    border-top-left-radius: 16px;
}

/* Ảnh trong tin nhắn */
.msg-img {
    max-width: 180px;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
}

.msg-img:hover {
    transform: scale(1.02);
}

.msg-img img {
    width: 100%;
    display: block;
}

/* Reply quote */
.msg-reply-quote {
    background: var(--accent-light);
    border-left: 3px solid var(--accent);
    padding: 5px 10px;
    margin-bottom: 4px;
    border-radius: 0 8px 8px 0;
    font-size: 11px;
    color: var(--text-muted);
    cursor: pointer;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: background 0.2s;
}

.msg-reply-quote:hover {
    background: var(--highlight-alpha-strong);
}

.msg-reply-quote strong {
    color: var(--accent-readable);
}

/* Nút reply - ẩn/hiện trên PC, luôn hiện trên mobile */
.action-btn {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: none;
    background: var(--bg-hover);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s, transform 0.2s;
    flex-shrink: 0;
}

.chat-msg:hover .action-btn {
    opacity: 1;
}

.action-btn:hover {
    background: var(--accent);
    color: #fff;
    transform: scale(1.1);
}

@media (max-width: 768px) {
    .action-btn {
        opacity: 1;
    }
}

/* ============================================
   ROLE COLORS — inherited from app.css
   (using CSS variables: --role-boss, --role-admin, etc.)
   ============================================ */

/* ============================================
   INPUT AREA
   ============================================ */
.chat-input-area {
    border-top: 1px solid var(--border-light);
    background: var(--bg-card);
    flex-shrink: 0;
    position: relative;
}

/* Reply bar */
.reply-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border-color);
    border-left: 3px solid var(--accent);
    font-size: 12px;
    color: var(--text-muted);
}

.reply-bar i {
    color: var(--accent-readable);
    margin-right: 6px;
}

.reply-bar strong {
    color: var(--text-primary);
}

.reply-bar button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
}

.reply-bar button:hover {
    color: #ef4444;
}

/* Upload preview */
.upload-preview {
    padding: 10px 14px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border-color);
}

.preview-box {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.preview-thumb {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.preview-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-progress {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
}

.cancel-btn {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #ef4444;
    border: none;
    color: #fff;
    cursor: pointer;
    transition: background 0.2s;
}

.cancel-btn:hover {
    background: #dc2626;
}

/* Cooldown bar */
.cooldown-bar {
    padding: 6px 14px;
    background: rgba(239, 68, 68, 0.1);
    border-bottom: 1px solid var(--border-color);
    font-size: 11px;
    color: #ef4444;
    text-align: center;
}

/* ============================================
   STICKER/EMOJI PICKER
   ============================================ */
.sticker-picker {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: 12px 12px 0 0;
    z-index: 100;
    display: none;
    animation: pickerSlideUp 0.2s ease;
}

@keyframes pickerSlideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sticker-picker.show {
    display: block;
}

.sticker-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}

.sticker-tab {
    flex: 1;
    padding: 8px;
    font-size: 16px;
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s, background 0.2s;
}

.sticker-tab:hover,
.sticker-tab.active {
    opacity: 1;
    background: var(--bg-hover);
}

.sticker-list {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    padding: 8px;
    max-height: 130px;
    overflow-y: auto;
}

.emoji-btn {
    font-size: 18px;
    padding: 4px;
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.15s, background 0.15s;
}

.emoji-btn:hover {
    background: var(--accent-light);
    transform: scale(1.2);
}

/* ============================================
   CHAT FORM
   ============================================ */
.chat-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
}

.btn-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: none;
    background: var(--bg-input);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s, transform 0.2s;
}

.btn-icon:hover:not(:disabled) {
    background: var(--accent);
    color: #fff;
    transform: scale(1.05);
}

.btn-icon:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.text-input {
    flex: 1;
    height: 38px;
    padding: 0 14px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background-color: var(--bg-input);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.text-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

.text-input::placeholder {
    color: var(--text-muted);
}

.btn-send {
    background: var(--accent);
    color: #fff;
}

.btn-send:hover:not(:disabled) {
    background: var(--accent-hover);
}

.login-prompt {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
}

.login-prompt a {
    color: var(--accent-readable);
    font-weight: 600;
}

/* ============================================
   ONLINE PANEL (DROPDOWN)
   ============================================ */
.online-panel {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    width: 220px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    z-index: 1000;
    display: none;
    animation: panelFadeIn 0.2s ease;
}

@keyframes panelFadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.online-panel.show {
    display: block;
}

.online-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.online-panel-header button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
}

.online-list {
    max-height: 200px;
    overflow-y: auto;
}

.online-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    transition: background 0.2s;
}

.online-item:hover {
    background: var(--highlight-alpha);
}

.online-item img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.online-item .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    flex-shrink: 0;
}

.online-item-info {
    display: flex;
    align-items: center;
    gap: 5px;
    flex: 1;
    min-width: 0;
}

.online-item-name {
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.online-item .news-role-tag {
    font-size: 8px;
    padding: 1px 5px;
    flex-shrink: 0;
}

/* ============================================
   @MENTION IN MESSAGES
   ============================================ */
.chat-mention {
    color: var(--accent-readable);
    font-weight: 600;
    text-decoration: none;
    background: var(--accent-light);
    padding: 1px 4px;
    border-radius: 4px;
    transition: background 0.2s;
}

.chat-mention:hover {
    background: var(--highlight-alpha-strong);
    text-decoration: underline;
}

.own .chat-mention {
    color: #ddd6fe;
    background: rgba(255, 255, 255, 0.15);
}

.own .chat-mention:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ============================================
   @MENTION DROPDOWN (autocomplete)
   ============================================ */
.mention-dropdown {
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: 100%;
    margin-bottom: 4px;
    max-height: 220px;
    overflow-y: auto;
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    z-index: 100;
    border: 1px solid var(--border-color);
}

.mention-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.15s;
}

.mention-item:first-child {
    border-radius: 12px 12px 0 0;
}

.mention-item:last-child {
    border-radius: 0 0 12px 12px;
}

.mention-item:hover,
.mention-item.active {
    background: var(--accent-light);
}

.mention-item img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.mention-info {
    display: flex;
    flex-direction: column;
}

.mention-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
}

.mention-user {
    font-size: 12px;
    color: var(--text-muted);
}

/* ============================================
   RESPONSIVE (Mobile Refinement)
   ============================================ */
@media (max-width: 768px) {
    .chat-container {
        height: 80vh;
        border-radius: 12px;
    }

    .chat-header {
        padding: 10px 12px;
    }

    .chat-header h3 {
        font-size: 14px;
    }

    .chat-messages {
        padding: 12px 10px;
        gap: 8px;
    }

    .chat-msg {
        max-width: 90%;
    }

    .msg-avatar img {
        width: 32px;
        height: 32px;
    }

    .msg-text {
        font-size: 13px;
        padding: 8px 12px;
    }

    .msg-meta {
        font-size: 10px;
    }

    .chat-form {
        padding: 8px 10px;
        gap: 6px;
    }

    .text-input {
        height: 36px;
        font-size: 13px;
    }

    .btn-icon {
        width: 34px;
        height: 34px;
        font-size: 13px;
    }

    .sticker-list {
        grid-template-columns: repeat(6, 1fr);
    }
}

@media (max-width: 480px) {
    .chat-container {
        height: calc(100vh - 120px);
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .chat-msg {
        max-width: 95%;
    }
}

/* ============================================
   MODALS
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: overlayFadeIn 0.2s ease;
}

@keyframes overlayFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-box {
    background-color: var(--bg-card);
    border-radius: 14px;
    width: 90%;
    max-width: 360px;
    border: 1px solid var(--border-color);
    animation: modalPop 0.3s ease;
}

@keyframes modalPop {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    padding: 16px;
    font-size: 15px;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    color: #f59e0b;
}

.modal-body {
    padding: 16px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.modal-footer {
    padding: 12px 16px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    border-top: 1px solid var(--border-color);
}

.modal-btn {
    padding: 8px 18px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s, transform 0.2s;
}

.modal-btn:hover {
    transform: translateY(-1px);
}

.modal-btn.cancel {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-btn.danger {
    background: #ef4444;
    color: #fff;
}

.modal-btn.danger:hover {
    background: #dc2626;
}

/* ============================================
   IMAGE POPUP (FULLSCREEN)
   ============================================ */
.img-popup {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.9);
    animation: overlayFadeIn 0.2s ease;
}

.img-popup img {
    max-width: 90%;
    max-height: 85vh;
    border-radius: 8px;
}

.img-popup button {
    position: absolute;
    top: 20px;
    right: 20px;
    background: none;
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    transition: transform 0.2s;
}

.img-popup button:hover {
    transform: scale(1.2);
}

/* Highlight animation khi nhấn vào reply */
@keyframes highlight {

    0%,
    100% {
        background: transparent;
    }

    50% {
        background: var(--accent-light);
    }
}

/* ============================================
   MULTI-IMAGE UPLOAD PREVIEW
   ============================================ */
.preview-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding-top: 5px;
}

.preview-item {
    position: relative;
    width: 60px;
    height: 60px;
    animation: fadeIn 0.3s ease;
}

.chat-preview-thumb {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-color);
}

.chat-preview-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-preview-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    text-align: center;
    padding: 2px 0;
    backdrop-filter: blur(2px);
    transition: background 0.3s;
}

.chat-preview-progress.done {
    background: #10b981;
}

.chat-preview-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ef4444;
    color: #fff;
    border: 2px solid var(--bg-card);
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, background 0.2s;
    z-index: 2;
}

.chat-preview-remove:hover {
    background: #dc2626;
    transform: scale(1.1);
}

/* Chat Image Grid */
.chat-img-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 5px;
}

.chat-img-thumb {
    width: 60px;
    height: 60px;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid var(--border-color);
}

.chat-img-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s;
}

.chat-img-thumb:hover img {
    transform: scale(1.1);
}

.msg-text+.chat-img-grid {
    margin-top: 8px;
    border-top: 1px solid var(--highlight-alpha);
    padding-top: 5px;
}