:root {
    --chat-sidebar-width: 380px;
    --chat-bg: #f0f2f5;
    --message-sent-bg: #d9fdd3;
    --message-received-bg: #ffffff;
    --chat-header-bg: #f0f2f5;
}

.messages-wrapper {
    display: flex;
    height: calc(100vh - var(--header-height) - 40px);
    margin: 20px auto;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
    max-width: 1400px;
    max-height: 900px;
    position: relative;
}

/* Sidebar */
.chat-sidebar {
    width: var(--chat-sidebar-width);
    border-right: 1px solid #e9edef;
    display: flex;
    flex-direction: column;
    background: #fff;
    z-index: 10;
}

.sidebar-header {
    padding: 16px;
    background: #fff;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: var(--text-main);
}

.header-action-btn {
    color: #667781;
    font-size: 18px;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-action-btn:hover {
    background: #f0f2f5;
    color: var(--primary);
}

.search-container {
    position: relative;
    margin-bottom: 8px;
}

.search-input {
    width: 100%;
    padding: 10px 16px 10px 48px !important;
    background: #f0f2f5;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #667781;
    font-size: 14px;
}

.chat-list-container {
    flex: 1;
    overflow-y: auto;
}

.section-title {
    padding: 10px 16px;
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #fafafa;
}

/* Sidebar Footer Toolbar */
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid #e9edef;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
}

.footer-actions {
    display: flex;
    gap: 8px;
}

.footer-btn {
    background: none;
    border: none;
    padding: 8px;
    color: #667781;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.footer-btn:hover {
    background: #f0f2f5;
    color: var(--primary);
}

.footer-btn.action-danger:hover {
    color: #ef4444;
    background: #fee2e2;
}

.selection-count {
    font-size: 14px;
    color: #667781;
    font-weight: 600;
}

/* Checkbox styling for selection */
.chat-item .selection-wrap {
    margin-right: 12px;
    display: none;
}

.chat-item.selection-mode .selection-wrap {
    display: block;
}

.custom-checkbox {
    width: 18px;
    height: 18px;
    border: 2px solid #cbd5e1;
    border-radius: 4px;
    position: relative;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-item.selected .custom-checkbox {
    background: var(--primary);
    border-color: var(--primary);
}

.chat-item.selected .custom-checkbox::after {
    content: "\f00c";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    font-size: 10px;
    color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid #f8f9fa;
    position: relative;
}

.chat-item:hover {
    background: #f5f6f6;
}

.chat-item.active {
    background: #f0f2f5;
}

.chat-item .avatar-wrap {
    position: relative;
    margin-right: 12px;
}

.chat-item img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

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

.info-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.chat-name {
    font-weight: 600;
    font-size: 15px;
    color: #111b21;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 12px;
    color: #667781;
}

.info-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-preview {
    font-size: 13px;
    color: #667781;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.unread-badge {
    background: #25d366;
    color: white;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-main::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('../chat-bg.webp');
    opacity: 0.06;
    pointer-events: none;
}

.chat-header {
    height: 64px;
    padding: 0 16px;
    background: #f0f2f5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 5;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-user img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.header-user h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 16px;
    color: #54656f;
}

.header-actions i {
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
}

.header-actions i:hover {
    background: rgba(0, 0, 0, 0.05);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 5% 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 2;
}

.msg-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 8px;
}

.msg-bubble {
    max-width: 65%;
    padding: 6px 10px 8px;
    border-radius: 8px;
    font-size: 14.5px;
    position: relative;
    box-shadow: 0 1px 0.5px rgba(11, 20, 26, .13);
    margin-bottom: 2px;
}

.msg-bubble.sent {
    align-self: flex-end;
    background: #d9fdd3;
}

.msg-bubble.received {
    align-self: flex-start;
    background: #fff;
}

.msg-text {
    color: #111b21;
    white-space: pre-wrap;
}

.msg-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    margin-top: -4px;
    margin-left: 8px;
    float: right;
}

.msg-time {
    font-size: 11px;
    color: #667781;
}

.msg-status {
    font-size: 13px;
    color: #53bdeb;
}

.msg-status.sent {
    color: #8696a0;
}

/* Input Area */
.chat-footer {
    padding: 8px 16px;
    background: #f0f2f5;
    display: flex;
    align-items: center;
    gap: 4px;
    z-index: 5;
}

.input-wrap {
    flex: 1;
    background: #fff;
    border-radius: 8px;
    padding: 9px 12px;
}

.message-input {
    width: 100%;
    border: none;
    outline: none;
    font-size: 15px;
    max-height: 120px;
    resize: none;
    font-family: inherit;
}

.send-button {
    background: none;
    border: none;
    color: #54656f;
    padding: 10px;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.send-button:disabled {
    opacity: 0.5;
    cursor: default;
}

/* Mobile */
@media (max-width: 768px) {
    .messages-wrapper {
        margin: 0;
        height: calc(100vh - var(--header-height));
        border-radius: 0;
    }

    .chat-sidebar {
        width: 100%;
    }

    .chat-sidebar.mobile-hidden {
        display: none;
    }

    .chat-main {
        display: none;
    }

    .chat-main.mobile-visible {
        display: flex;
        position: absolute;
        inset: 0;
    }

    .chat-header .back-btn {
        display: block !important;
    }
}

.back-btn {
    display: none;
    margin-right: 12px;
    cursor: pointer;
}

/* Empty states */
.empty-chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #667781;
    text-align: center;
}

.empty-chat-welcome i {
    font-size: 80px;
    margin-bottom: 20px;
    opacity: 0.2;
}