/* ================================================================
   MESSAGES — Japanese Messenger Style
   Nihongo AI Coach
   ================================================================
   Chủ đề: Nhẹ nhàng, tinh tế, phong cách Nhật Bản
   Sắc hồng sakura + hiệu ứng glassmorphism + micro-interactions
   ================================================================ */

/* --- Container: Full width, no max-width --- */
.messages-container {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
    height: calc(100vh - 64px - 40px); /* navbar + padding */
}

.messages-layout {
    display: flex;
    height: 100%;
    background: var(--glass-bg, rgba(255, 255, 255, 0.82));
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-radius: 0;
    border: none;
    box-shadow: none;
    overflow: hidden;
    position: relative;
}

/* Subtle gradient overlay on the edges for depth */
.messages-layout::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 0% 50%, rgba(244, 63, 127, 0.03) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

.messages-sidebar,
.messages-chat-area {
    position: relative;
    z-index: 1;
}

/* ================================================================
   SIDEBAR — Conversation List
   ================================================================ */
.messages-sidebar {
    width: 380px;
    min-width: 380px;
    border-right: 1px solid var(--border-soft, rgba(255, 182, 193, 0.18));
    display: flex;
    flex-direction: column;
    background: var(--bg-card, rgba(255, 255, 255, 0.45));
    position: relative;
}

/* Header */
.messages-sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border-soft, rgba(255, 182, 193, 0.12));
}

.messages-sidebar-header-inner {
    display: flex;
    align-items: center;
    gap: 6px;
}

.messages-sidebar-header h5 {
    font-size: 1.15rem;
    letter-spacing: -0.3px;
    color: var(--text-main, #1e293b);
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.messages-sidebar-header h5::before {
    content: none;
}

/* ================================================================
   NAV BACK BUTTON — Shared (sidebar header + empty state)
   ================================================================ */
.messages-nav-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 12px;
    border: none;
    background: transparent;
    color: var(--text-muted, #64748b);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    flex-shrink: 0;
    text-decoration: none;
    position: relative;
}

.messages-nav-back:hover {
    background: var(--accent-sakura-soft, rgba(244, 63, 127, 0.08));
    color: var(--accent-sakura, #f43f5e);
    transform: translateX(-2px);
}

.messages-nav-back:active {
    transform: translateX(-2px) scale(0.92);
}

.messages-nav-back svg {
    transition: transform 0.2s ease;
}

.messages-nav-back:hover svg {
    transform: translateX(-1px);
}

/* Tooltip on hover */
.messages-nav-back::after {
    content: attr(title);
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    background: rgba(30, 41, 59, 0.9);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 8px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s ease;
    backdrop-filter: blur(8px);
}

.messages-nav-back:hover::after {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

/* ================================================================
   EMPTY STATE — Top Bar Back Button
   ================================================================ */
.messages-empty-top-bar {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 2;
}

.messages-empty-top-bar .messages-nav-back {
    background: var(--bg-card, rgba(255, 255, 255, 0.75));
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--border-soft, rgba(255, 182, 193, 0.1));
}

.messages-empty-top-bar .messages-nav-back:hover {
    background: rgba(244, 63, 127, 0.12);
    box-shadow: 0 2px 12px rgba(244, 63, 94, 0.12);
}

/* Search */
.messages-search {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-soft, rgba(255, 182, 193, 0.1));
}

.messages-search-input {
    width: 100%;
    border: 1.5px solid transparent;
    border-radius: 14px;
    padding: 10px 16px 10px 38px;
    font-size: 0.85rem;
    font-family: 'Nunito', sans-serif;
    background: var(--input-bg, rgba(255, 255, 255, 0.7));
    color: var(--input-text, #1e293b);
    outline: none;
    transition: all 0.3s ease;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 14px center;
    background-size: 16px;
}

.messages-search-input:focus {
    border-color: var(--accent-sakura, #f43f5e);
    background-color: rgba(255, 255, 255, 0.95);
    box-shadow: 0 0 0 4px rgba(244, 63, 94, 0.08);
}

.messages-search-input::placeholder {
    color: var(--input-placeholder, #94a3b8);
    font-weight: 500;
}

/* Conversation List */
.messages-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
}

/* Scrollbar */
.messages-sidebar-list::-webkit-scrollbar {
    width: 4px;
}
.messages-sidebar-list::-webkit-scrollbar-track {
    background: transparent;
}
.messages-sidebar-list::-webkit-scrollbar-thumb {
    background: rgba(244, 63, 94, 0.15);
    border-radius: 99px;
}
.messages-sidebar-list::-webkit-scrollbar-thumb:hover {
    background: rgba(244, 63, 94, 0.3);
}

/* Conversation Item */
.messages-conversation-item {
    display: flex !important;
    align-items: center !important;
    gap: 12px;
    padding: 12px 16px !important;
    margin: 4px 8px !important;
    width: calc(100% - 16px) !important;
    box-sizing: border-box !important;
    text-decoration: none;
    color: var(--text-main, #1e293b);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    border-radius: 14px;
    position: relative;
}

.messages-conversation-item:hover {
    background: var(--accent-sakura-soft, rgba(244, 63, 127, 0.07));
    transform: translateX(2px);
}

.messages-conversation-item.active {
    background: linear-gradient(135deg, rgba(244, 63, 127, 0.10), rgba(244, 63, 127, 0.04));
    border: 1px solid rgba(244, 63, 127, 0.12);
    box-shadow: 0 2px 12px rgba(244, 63, 127, 0.06);
}

.messages-conversation-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 28px;
    background: linear-gradient(180deg, var(--accent-sakura, #f43f5e), #e11d48);
    border-radius: 0 4px 4px 0;
}

/* Avatar */
.messages-conv-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #fce4ec, #f8bbd0);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: var(--accent-sakura, #e11d48);
    font-size: 1.15rem;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
    box-shadow: 0 2px 8px rgba(244, 63, 94, 0.12);
}

.messages-conv-avatar span {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.messages-conv-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    position: relative;
    z-index: 2;
}

/* Info */
.messages-conv-info {
    flex: 1;
    min-width: 0;
}

.messages-conv-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-main, #1e293b);
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.messages-conv-preview {
    font-size: 0.82rem;
    color: var(--text-muted, #64748b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

/* Meta (time + badge) */
.messages-conv-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    flex-shrink: 0;
    margin-left: 4px;
}

.messages-conv-time {
    font-size: 0.7rem;
    color: var(--text-disabled, #94a3b8);
    font-weight: 600;
    white-space: nowrap;
}

.messages-unread-badge {
    background: linear-gradient(135deg, #f43f5e, #e11d48);
    color: white;
    font-size: 0.65rem;
    font-weight: 800;
    padding: 2px 7px;
    border-radius: 99px;
    min-width: 20px;
    text-align: center;
    line-height: 1.4;
    box-shadow: 0 2px 6px rgba(244, 63, 94, 0.25);
    animation: badgePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes badgePop {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Empty Sidebar */
.messages-empty-sidebar {
    padding: 30px 20px;
    text-align: center;
}

.messages-empty-sidebar .empty-icon {
    font-size: 2.5rem;
    opacity: 0.6;
    margin-bottom: 12px;
}

.messages-empty-sidebar p {
    font-size: 0.88rem;
    color: var(--text-muted, #64748b);
    margin-bottom: 16px;
}

/* ================================================================
   CHAT AREA
   ================================================================ */
.messages-chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-page, rgba(248, 250, 252, 0.3));
}

/* --- No Chat Selected (Empty State) --- */
.messages-no-chat {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    position: relative;
}

.messages-empty-chat {
    text-align: center;
    max-width: 400px;
    position: relative;
    animation: fadeInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.messages-empty-icon {
    font-size: 4rem;
    opacity: 0.7;
    margin-bottom: 8px;
    display: block;
    animation: gentleFloat 4s ease-in-out infinite;
}

@keyframes gentleFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.messages-empty-chat h4 {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-main, #1e293b);
    margin: 16px 0 8px;
}

.messages-empty-chat p {
    font-size: 0.9rem;
    color: var(--text-muted, #64748b);
    line-height: 1.6;
    max-width: 320px;
    margin: 0 auto 20px;
}

/* Sakura petals decoration (empty state) */
.sakura-petals {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.sakura-petals span {
    position: absolute;
    font-size: 1.2rem;
    opacity: 0.25;
    animation: petalFall 8s ease-in-out infinite;
}

.sakura-petals span:nth-child(1) {
    top: -10%;
    left: 10%;
    animation-delay: 0s;
    animation-duration: 9s;
    font-size: 1rem;
}

.sakura-petals span:nth-child(2) {
    top: -10%;
    left: 45%;
    animation-delay: 2.5s;
    animation-duration: 11s;
    font-size: 1.4rem;
}

.sakura-petals span:nth-child(3) {
    top: -10%;
    right: 15%;
    animation-delay: 5s;
    animation-duration: 10s;
    font-size: 0.9rem;
}

@keyframes petalFall {
    0% {
        transform: translateY(-20px) rotate(0deg) translateX(0);
        opacity: 0;
    }
    10% {
        opacity: 0.25;
    }
    90% {
        opacity: 0.15;
    }
    100% {
        transform: translateY(400px) rotate(720deg) translateX(60px);
        opacity: 0;
    }
}

/* --- Chat Content (Active conversation) --- */
.messages-chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    animation: fadeIn 0.3s ease;
}

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

/* --- Chat Header --- */
.messages-chat-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-soft, rgba(255, 182, 193, 0.15));
    background: var(--bg-card, rgba(255, 255, 255, 0.55));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: relative;
    z-index: 2;
}

.messages-chat-header-left {
    display: flex;
    align-items: center;
}

.messages-chat-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 20px;
    right: 20px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(244, 63, 94, 0.15), transparent);
}

.messages-chat-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #fce4ec, #f8bbd0);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: var(--accent-sakura, #e11d48);
    font-size: 1rem;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
    box-shadow: 0 2px 8px rgba(244, 63, 94, 0.1);
}

.messages-chat-header-avatar span {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.messages-chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    position: relative;
    z-index: 2;
}

.messages-chat-header .fw-bold {
    font-size: 0.98rem;
    color: var(--text-main, #1e293b);
}

.messages-back-btn {
    background: none;
    border: none;
    color: var(--text-muted, #64748b);
    padding: 6px 8px;
    border-radius: 10px;
    transition: all 0.2s ease;
    cursor: pointer;
    display: none;
    align-items: center;
    gap: 4px;
    font-family: 'Nunito', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
}

.messages-back-btn:hover {
    background: var(--accent-sakura-soft, rgba(244, 63, 127, 0.08));
    color: var(--accent-sakura, #f43f5e);
}

.messages-back-label {
    display: none;
}

/* --- Messages List (scrollable) --- */
.messages-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(244, 63, 127, 0.02) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(244, 63, 127, 0.015) 0%, transparent 50%);
}

/* Scrollbar */
.messages-list::-webkit-scrollbar {
    width: 5px;
}
.messages-list::-webkit-scrollbar-track {
    background: transparent;
}
.messages-list::-webkit-scrollbar-thumb {
    background: rgba(244, 63, 94, 0.12);
    border-radius: 99px;
}
.messages-list::-webkit-scrollbar-thumb:hover {
    background: rgba(244, 63, 94, 0.25);
}

/* ================================================================
   DATE SEPARATOR
   ================================================================ */
.messages-date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 12px 0 8px;
    gap: 12px;
}

.messages-date-separator::before,
.messages-date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-soft, rgba(0, 0, 0, 0.06)), transparent);
}

.messages-date-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-disabled, #94a3b8);
    background: var(--bg-card-hover, #f1f5f9);
    padding: 4px 14px;
    border-radius: 99px;
    white-space: nowrap;
    letter-spacing: 0.3px;
    border: 1px solid var(--border-soft, rgba(0, 0, 0, 0.04));
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

/* ================================================================
   MESSAGE BUBBLES — Facebook Messenger Style
   ================================================================ */
.messages-bubble-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    max-width: 72%;
    animation: messageSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    margin-bottom: 2px;
}

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

.messages-bubble-wrapper.mine {
    display: flex !important;
    flex-direction: row !important;
    justify-content: flex-end !important;
    margin-left: auto !important;
    width: 100% !important;
}

.messages-bubble-wrapper.mine .messages-bubble {
    margin-left: auto !important;
}

.messages-bubble-wrapper.theirs {
    display: flex !important;
    flex-direction: row !important;
    justify-content: flex-start !important;
    margin-right: auto !important;
    width: 100% !important;
}

.messages-bubble-wrapper.theirs .messages-bubble {
    margin-right: auto !important;
}

/* Avatar next to bubble — only for first message in a group */
.messages-bubble-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e0f2fe, #bae6fd);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #0284c7;
    font-size: 0.68rem;
    flex-shrink: 0;
    overflow: hidden;
    align-self: flex-end;
    margin-bottom: 2px;
    position: relative;
    box-shadow: 0 1px 4px rgba(2, 132, 199, 0.08);
    visibility: hidden; /* Hidden by default, shown on first message in group */
}

/* Show avatar only on the first message of a consecutive group */
.messages-bubble-wrapper.theirs:not(.consecutive) .messages-bubble-avatar {
    visibility: visible;
}

/* Consecutive messages from same sender — smaller gap, no avatar */
.messages-bubble-wrapper.consecutive {
    margin-top: -4px;
}

.messages-bubble-wrapper.consecutive .messages-bubble-avatar {
    visibility: hidden;
}

.messages-bubble-avatar span {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.messages-bubble-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    position: relative;
    z-index: 2;
}

/* The bubble itself */
.messages-bubble {
    padding: 8px 16px;
    border-radius: 20px;
    position: relative;
    word-wrap: break-word;
    max-width: 100%;
    transition: box-shadow 0.2s ease;
    line-height: 1.45;
}

/* ================================================================
   BUBBLE TRIANGLE TAIL — Pointer tip like Messenger
   ================================================================ */
/* Mine: tail on right */
.bubble-mine,
.messages-bubble.mine {
    background: linear-gradient(135deg, #10b981, #059669) !important;
    color: #ffffff !important;
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
    position: relative;
}

.bubble-mine::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -7px;
    width: 0;
    height: 0;
    border-left: 8px solid #059669;
    border-top: 0 solid transparent;
    border-bottom: 8px solid transparent;
}

/* Theirs: tail on left */
.bubble-theirs,
.messages-bubble.theirs {
    background: #e2e8f0 !important;
    color: #0f172a !important;
    border: 1px solid #cbd5e1 !important;
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
    position: relative;
}

.bubble-theirs::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: -7px;
    width: 0;
    height: 0;
    border-right: 8px solid #ffffff;
    border-top: 0 solid transparent;
    border-bottom: 8px solid transparent;
    z-index: 1;
}

/* Hide tail on consecutive messages */
.messages-bubble-wrapper.consecutive .bubble-mine::after,
.messages-bubble-wrapper.consecutive .bubble-theirs::before {
    display: none;
}

.messages-bubble-wrapper.consecutive .bubble-mine {
    border-bottom-right-radius: 20px;
}

.messages-bubble-wrapper.consecutive .bubble-theirs {
    border-bottom-left-radius: 20px;
}

/* Hover effect — slight lift */
.messages-bubble-wrapper.mine:hover .messages-bubble {
    transform: translateY(-1px);
    box-shadow:
        0 4px 12px rgba(244, 63, 94, 0.3),
        0 2px 6px rgba(244, 63, 94, 0.18);
}

.messages-bubble-wrapper.theirs:hover .messages-bubble {
    transform: translateY(-1px);
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.06),
        0 2px 6px rgba(0, 0, 0, 0.04);
}

.messages-bubble {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* ================================================================
   BUBBLE CONTENT & TIME
   ================================================================ */
.messages-bubble-content {
    font-size: 0.92rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.messages-bubble-time {
    font-size: 0.62rem;
    margin-top: 3px;
    text-align: right;
    letter-spacing: 0.2px;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}

.bubble-mine .messages-bubble-time {
    color: rgba(255, 255, 255, 0.70);
}

.bubble-theirs .messages-bubble-time {
    color: var(--text-disabled, #94a3b8);
}

/* Read status indicator (like Messenger's tiny check) */
.bubble-mine .messages-bubble-time::after {
    content: '✓✓';
    font-size: 0.55rem;
    letter-spacing: -1px;
    color: rgba(255, 255, 255, 0.45);
    margin-left: 2px;
}

/* ================================================================
   TYPING INDICATOR
   ================================================================ */
#typingIndicator {
    font-size: 0.78rem;
    color: var(--accent-sakura, #f43f5e);
    font-weight: 600;
    display: none;
    align-items: center;
    gap: 4px;
    animation: typingPulse 1.5s ease-in-out infinite;
}

#typingIndicator::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-sakura, #f43f5e);
    animation: typingDot 1.4s ease-in-out infinite;
    box-shadow:
        10px 0 0 rgba(244, 63, 94, 0.4),
        20px 0 0 rgba(244, 63, 94, 0.2);
}

@keyframes typingDot {
    0%, 60%, 100% { opacity: 0.3; }
    30% { opacity: 1; }
}

@keyframes typingPulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* ================================================================
   INPUT AREA
   ================================================================ */
.messages-input-area {
    padding: 14px 20px 16px;
    border-top: 1px solid var(--border-soft, rgba(255, 182, 193, 0.15));
    background: var(--bg-card, rgba(255, 255, 255, 0.55));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.messages-input-form {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-card, rgba(255, 255, 255, 0.85));
    border: 1.5px solid var(--border-soft, rgba(255, 182, 193, 0.25));
    border-radius: 28px;
    padding: 4px 4px 4px 18px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}

.messages-input-form:focus-within {
    border-color: var(--accent-sakura, #f43f5e);
    box-shadow: 0 0 0 4px rgba(244, 63, 94, 0.08);
    background: rgba(255, 255, 255, 0.96);
}

.messages-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 0.92rem;
    font-family: 'Nunito', sans-serif;
    background: transparent;
    color: var(--input-text, #1e293b);
    max-height: 120px;
    padding: 8px 0;
    line-height: 1.5;
}

.messages-input::placeholder {
    color: var(--input-placeholder, #94a3b8);
    font-weight: 500;
}

.messages-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #f43f5e, #e11d48);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(244, 63, 94, 0.25);
}

.messages-send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 16px rgba(244, 63, 94, 0.35);
}

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

.messages-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.messages-send-btn svg {
    width: 18px;
    height: 18px;
    transition: transform 0.2s ease;
}

.messages-send-btn:hover svg {
    transform: translateX(1px);
}

/* ================================================================
   FLOATING NOTIFICATION
   ================================================================ */
.message-float-notification {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    background: var(--bg-card, #ffffff);
    border: 1px solid var(--border-soft, rgba(0, 0, 0, 0.06));
    border-radius: 18px;
    padding: 14px 18px;
    box-shadow:
        0 12px 40px rgba(0, 0, 0, 0.12),
        0 2px 8px rgba(0, 0, 0, 0.04);
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 360px;
    animation: floatNotifIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    cursor: pointer;
    transition: all 0.3s ease;
}

.message-float-notification:hover {
    transform: translateY(-3px);
    box-shadow:
        0 20px 48px rgba(0, 0, 0, 0.16),
        0 4px 12px rgba(0, 0, 0, 0.06);
}

@keyframes floatNotifIn {
    from {
        opacity: 0;
        transform: translateX(60px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

.message-float-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #fce4ec, #f8bbd0);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: var(--accent-sakura, #e11d48);
    font-size: 0.95rem;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
}

.message-float-avatar span {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.message-float-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    position: relative;
    z-index: 2;
}

.message-float-content {
    flex: 1;
    min-width: 0;
}

.message-float-name {
    font-weight: 700;
    font-size: 0.88rem;
    color: var(--text-main, #1e293b);
    margin-bottom: 2px;
}

.message-float-text {
    font-size: 0.82rem;
    color: var(--text-muted, #64748b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-float-time {
    font-size: 0.68rem;
    color: var(--text-disabled, #94a3b8);
    flex-shrink: 0;
    align-self: flex-start;
    padding-top: 2px;
}

/* ================================================================
   ONLINE / OFFLINE INDICATOR (dự trữ)
   ================================================================ */
.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    border: 2px solid var(--bg-card, #fff);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.status-indicator.online {
    background: #22c55e;
}

.status-indicator.offline {
    background: #cbd5e1;
}

/* ================================================================
   MESSAGE INPUT CHARACTER COUNTER (dự trữ)
   ================================================================ */
.char-counter {
    font-size: 0.65rem;
    color: var(--text-disabled, #94a3b8);
    text-align: right;
    padding: 2px 8px 0 0;
    user-select: none;
}

.char-counter.warning {
    color: #f59e0b;
}

.char-counter.danger {
    color: #ef4444;
}

/* ================================================================
   CUSTOM BUTTON STYLES
   ================================================================ */
.btn-community-primary {
    background: linear-gradient(135deg, #f43f5e, #e11d48);
    color: white;
    font-size: 0.88rem;
    border: none;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 4px 12px rgba(244, 63, 94, 0.2);
}

.btn-community-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(244, 63, 94, 0.3);
    color: white;
}

.btn-community-secondary {
    background: var(--bg-card, rgba(255, 255, 255, 0.9));
    color: var(--text-main, #1e293b);
    font-size: 0.88rem;
    border: 1px solid rgba(244, 63, 127, 0.2);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-community-secondary:hover {
    border-color: var(--accent-sakura, #f43f5e);
    background: rgba(244, 63, 127, 0.05);
    color: var(--accent-sakura, #e11d48);
}

.btn-empty-community {
    background: linear-gradient(135deg, #f43f5e, #e11d48);
    color: white;
    font-weight: 600;
    font-size: 0.82rem;
    border: none;
    transition: all 0.3s ease;
    box-shadow: 0 3px 10px rgba(244, 63, 94, 0.15);
}

.btn-empty-community:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(244, 63, 94, 0.25);
    color: white;
}

/* ================================================================
   SMOOTH SCROLLBAR (chung)
   ================================================================ */
.messages-list,
.messages-sidebar-list {
    scroll-behavior: smooth;
}

/* ================================================================
   RESPONSIVE — Tablet & Mobile
   ================================================================ */
@media (max-width: 991.98px) {
    .messages-container {
        width: 100%;
        max-width: none;
        margin: 0;
        padding: 0;
        height: calc(100vh - 60px - 24px);
    }

    .messages-layout {
        border: none;
        border-radius: 0;
    }

    .messages-sidebar {
        width: 100%;
        min-width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 10;
        background: var(--bg-card, rgba(255, 255, 255, 0.96));
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        display: none;
    }

    .messages-sidebar.show {
        display: flex;
        animation: sidebarIn 0.3s ease;
    }

    @keyframes sidebarIn {
        from { opacity: 0; transform: translateX(-20px); }
        to { opacity: 1; transform: translateX(0); }
    }

    .messages-chat-area {
        width: 100%;
        display: none;
    }

    .messages-chat-area.show {
        display: flex;
        animation: chatIn 0.3s ease;
    }

    @keyframes chatIn {
        from { opacity: 0; transform: translateX(20px); }
        to { opacity: 1; transform: translateX(0); }
    }

    .messages-back-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .messages-back-label {
        display: inline;
    }

    .messages-bubble-wrapper {
        max-width: 85%;
    }

    .messages-list {
        padding: 16px;
    }

    .messages-sidebar {
        border-right: none;
    }
}

@media (max-width: 575.98px) {
    .messages-container {
        width: 100%;
        max-width: none;
        margin: 0;
        padding: 0;
        height: calc(100vh - 56px - 16px);
    }

    .messages-layout {
        border: none;
        border-radius: 0;
    }

    .messages-sidebar {
        width: 100%;
        min-width: 100%;
    }

    .messages-bubble-wrapper {
        max-width: 92%;
    }

    .messages-bubble {
        padding: 8px 14px;
        border-radius: 16px;
    }

    .messages-bubble-content {
        font-size: 0.88rem;
    }

    .messages-list {
        padding: 12px;
        gap: 4px;
    }

    .messages-chat-header {
        padding: 10px 14px;
    }

    .messages-input-area {
        padding: 10px 12px 12px;
    }

    .messages-input-form {
        padding: 2px 2px 2px 14px;
        border-radius: 24px;
    }

    .messages-conversation-item {
        padding: 10px 14px;
        margin: 1px 4px;
    }

    .messages-conv-avatar {
        width: 44px;
        height: 44px;
        font-size: 1rem;
    }

    .messages-empty-chat h4 {
        font-size: 1.1rem;
    }

    .messages-empty-icon {
        font-size: 3rem;
    }

    .messages-sidebar-header {
        padding: 16px 16px 12px;
    }

    .message-float-notification {
        left: 12px;
        right: 12px;
        bottom: 12px;
        max-width: none;
    }
}

/* ================================================================
   PRINT
   ================================================================ */
@media print {
    .messages-container {
        height: auto;
        margin: 0;
        padding: 0;
    }
    .messages-input-area,
    .messages-sidebar {
        display: none;
    }
    .messages-chat-area {
        display: block;
        width: 100%;
    }
}

/* ══════════════════════════════════════════════════════════════════════════
   EXPLICIT LIGHT & DARK MODE OVERRIDES (MESSAGES PAGE)
   ══════════════════════════════════════════════════════════════════════════ */

/* ─── Light Mode ─── */
[data-theme="light"] .messages-container,
:root:not([data-theme="dark"]) .messages-container,
[data-theme="light"] .messages-layout,
:root:not([data-theme="dark"]) .messages-layout {
    background: #f8fafc !important;
}

[data-theme="light"] .messages-sidebar,
:root:not([data-theme="dark"]) .messages-sidebar {
    background: #ffffff !important;
    border-right: 1px solid rgba(15, 23, 42, 0.08) !important;
}

[data-theme="light"] .messages-conversation-item,
:root:not([data-theme="dark"]) .messages-conversation-item {
    color: #0f172a !important;
}

[data-theme="light"] .messages-conversation-item:hover,
:root:not([data-theme="dark"]) .messages-conversation-item:hover {
    background: #f1f5f9 !important;
}

[data-theme="light"] .messages-conversation-item.active,
:root:not([data-theme="dark"]) .messages-conversation-item.active {
    background: rgba(16, 185, 129, 0.12) !important;
}

[data-theme="light"] .messages-conv-name,
:root:not([data-theme="dark"]) .messages-conv-name {
    color: #0f172a !important;
}

[data-theme="light"] .messages-conv-preview,
:root:not([data-theme="dark"]) .messages-conv-preview {
    color: #64748b !important;
}

[data-theme="light"] .messages-chat-area,
:root:not([data-theme="dark"]) .messages-chat-area {
    background: #f8fafc !important;
}

[data-theme="light"] .messages-chat-header,
:root:not([data-theme="dark"]) .messages-chat-header {
    background: #ffffff !important;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08) !important;
    color: #0f172a !important;
}

[data-theme="light"] .messages-bubble.bubble-theirs,
:root:not([data-theme="dark"]) .messages-bubble.bubble-theirs {
    background: #ffffff !important;
    color: #0f172a !important;
    border: 1px solid rgba(15, 23, 42, 0.09) !important;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.03) !important;
}

[data-theme="light"] .messages-input-area,
:root:not([data-theme="dark"]) .messages-input-area {
    background: #ffffff !important;
    border-top: 1px solid rgba(15, 23, 42, 0.08) !important;
}

[data-theme="light"] .messages-input-form,
:root:not([data-theme="dark"]) .messages-input-form {
    background: #f1f5f9 !important;
    border: 1.5px solid rgba(15, 23, 42, 0.1) !important;
}

[data-theme="light"] .messages-input,
:root:not([data-theme="dark"]) .messages-input {
    color: #0f172a !important;
}

/* ─── Dark Mode ─── */
[data-theme="dark"] .messages-container,
html.dark .messages-container,
[data-theme="dark"] .messages-layout,
html.dark .messages-layout {
    background: #0b0f17 !important;
}

[data-theme="dark"] .messages-sidebar,
html.dark .messages-sidebar {
    background: #111827 !important;
    border-right: 1px solid rgba(255, 255, 255, 0.08) !important;
}

[data-theme="dark"] .messages-conversation-item,
html.dark .messages-conversation-item {
    color: #cbd5e1 !important;
}

[data-theme="dark"] .messages-conversation-item:hover,
html.dark .messages-conversation-item:hover {
    background: #1f2937 !important;
}

[data-theme="dark"] .messages-conversation-item.active,
html.dark .messages-conversation-item.active {
    background: rgba(16, 185, 129, 0.18) !important;
}

[data-theme="dark"] .messages-conv-name,
html.dark .messages-conv-name {
    color: #f8fafc !important;
}

[data-theme="dark"] .messages-conv-preview,
html.dark .messages-conv-preview {
    color: #cbd5e1 !important;
}

[data-theme="dark"] .messages-chat-area,
html.dark .messages-chat-area {
    background: #0b0f17 !important;
}

[data-theme="dark"] .messages-chat-header,
html.dark .messages-chat-header {
    background: #111827 !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
    color: #f8fafc !important;
}

[data-theme="dark"] .messages-bubble.theirs,
[data-theme="dark"] .messages-bubble.bubble-theirs,
[data-theme="dark"] .bubble-theirs,
html.dark .messages-bubble.theirs,
html.dark .messages-bubble.bubble-theirs,
html.dark .bubble-theirs {
    background: #334155 !important;
    color: #f8fafc !important;
    border: 1px solid #475569 !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25) !important;
}

[data-theme="dark"] .messages-input-area,
html.dark .messages-input-area {
    background: #111827 !important;
    border-top: 1px solid rgba(255, 255, 255, 0.08) !important;
}

[data-theme="dark"] .messages-input-form,
html.dark .messages-input-form {
    background: #161d2b !important;
    border: 1.5px solid rgba(255, 255, 255, 0.12) !important;
}

[data-theme="dark"] .messages-input,
html.dark .messages-input {
    color: #f8fafc !important;
}
