.messages-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    height: 100%;
    overflow: hidden;
}

/* --- SIDEBAR --- */
.msg-sidebar {
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.msg-sidebar-header {
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--divider-color);
}

.msg-sidebar-header h3 {
    margin: 0;
    color: var(--header-text);
}

.theme-toggle {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1.2rem;
    transition: 0.3s;
}
.theme-toggle:hover { color: var(--accent-color); }

/* Tabs */
.msg-tabs {
    display: flex;
    border-bottom: 1px solid var(--divider-color);
}

.msg-tab {
    flex: 1;
    background: transparent;
    border: none;
    padding: 10px;
    color: var(--text-muted);
    font-family: 'Starcraft Regular';
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.msg-tab.active {
    color: var(--accent-color);
    border-bottom: 2px solid var(--accent-color);
    background: var(--hover-bg);
}

/* Contact List */
.contact-list-wrapper {
    flex: 1;
    overflow-y: auto;
}

.contact-list {
    display: none;
}
.contact-list.active { display: block; }

.contact-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--divider-color);
    cursor: pointer;
    transition: background 0.2s;
}

.contact-item:hover {
    background: var(--hover-bg);
}

.contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #333;
    margin-right: 12px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
}

.contact-avatar img { width: 100%; height: 100%; object-fit: cover; }
.group-avatar { background: var(--info-color-faded); }

.contact-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.contact-name {
    font-weight: bold;
    color: var(--text-color);
    font-size: 0.9rem;
}

.contact-last {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- CHAT AREA --- */
.msg-chat-area {
    position: relative;
    background: var(--page-bg); /* Differs from card bg for depth */
    display: flex;
    flex-direction: column;
}

.chat-empty-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-muted);
}

.chat-interface {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    padding: 10px 20px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Bubbles */
.msg-bubble {
    max-width: 70%;
    padding: 10px 15px;
    border-radius: 15px;
    font-size: 0.9rem;
    line-height: 1.4;
    position: relative;
}

.msg-in {
    align-self: flex-start;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-bottom-left-radius: 2px;
}

.msg-out {
    align-self: flex-end;
    background: var(--info-color-faded); /* WhatsApp-ish style */
    color: white;
    border-bottom-right-radius: 2px;
}

.chat-input-bar {
    padding: 15px;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
}

#msg-input {
    flex: 1;
    padding: 10px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: var(--page-bg);
    color: var(--text-color);
}

.btn-send {
    background: var(--accent-color);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Ephemeral Switch */
.ephemeral-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    color: var(--text-muted);
}

.ephemeral-switch input { display: none; }
.ephemeral-switch i { font-size: 1.2rem; transition: 0.3s; }
.ephemeral-switch input:checked ~ i { color: var(--high-demand-color); text-shadow: 0 0 5px red; }

/* Responsive Mobile: Show sidebar first, overlay chat on selection */
@media (max-width: 768px) {
    .messages-layout { grid-template-columns: 1fr; }
    .msg-chat-area { display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 100; }
    .msg-chat-area.open { display: flex; }
}