/* ── Messaging UI ─────────────────────────────────────────────────────────── */
.msg-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 0;
    height: calc(100vh - 120px);
    min-height: 500px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
}
@media (max-width: 768px) {
    .msg-layout { grid-template-columns: 1fr; height: auto; }
    .msg-list-pane { border-right: none; border-bottom: 1px solid var(--border-color); max-height: 320px; }
}

/* ── Left pane ── */
.msg-list-pane {
    display: flex; flex-direction: column;
    border-right: 1px solid var(--border-color);
    overflow: hidden;
}
.msg-pane-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: .85rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    flex-shrink: 0;
}
.msg-pane-header h3 { margin: 0; font-size: .9rem; font-weight: 700; }
.msg-tab-row {
    display: flex; border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.msg-tab {
    flex: 1; padding: .6rem; text-align: center; font-size: .82rem; font-weight: 600;
    color: var(--text-muted); cursor: pointer; border: none; background: none;
    border-bottom: 2px solid transparent; transition: all .15s;
}
.msg-tab.active { color: var(--primary-accent); border-bottom-color: var(--primary-accent); }
.msg-list { flex: 1; overflow-y: auto; }
.msg-item {
    display: flex; align-items: flex-start; gap: .75rem;
    padding: .85rem 1rem; cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,.04);
    transition: background .15s;
}
.msg-item:hover { background: rgba(168,85,247,.07); }
.msg-item.active { background: rgba(168,85,247,.12); }
.msg-item.unread .msg-item-subject { font-weight: 700; color: #fff; }
.msg-avatar {
    width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
    background: linear-gradient(135deg,#a855f7,#ec4899);
    display: flex; align-items: center; justify-content: center;
    font-size: .85rem; font-weight: 700; color: #fff;
}
.msg-item-body { flex: 1; min-width: 0; }
.msg-item-from { font-size: .8rem; color: var(--text-muted); margin-bottom: 1px; }
.msg-item-subject { font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-item-preview { font-size: .75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.msg-item-time { font-size: .72rem; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.msg-unread-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--primary-accent); flex-shrink: 0; margin-top: 6px;
}

/* ── Right pane ── */
.msg-detail-pane {
    display: flex; flex-direction: column; overflow: hidden;
}
.msg-detail-empty {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: var(--text-muted); gap: .75rem;
}
.msg-detail-empty i { font-size: 3rem; opacity: .3; }
.msg-detail-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    flex-shrink: 0;
}
.msg-detail-subject { font-size: 1.05rem; font-weight: 700; margin-bottom: .3rem; }
.msg-detail-meta { font-size: .8rem; color: var(--text-muted); display: flex; gap: 1rem; flex-wrap: wrap; }
.msg-detail-body { flex: 1; overflow-y: auto; padding: 1.25rem; line-height: 1.65; font-size: .92rem; white-space: pre-wrap; }
.msg-attachments { padding: .75rem 1.25rem; border-top: 1px solid var(--border-color); display: flex; flex-wrap: wrap; gap: .5rem; }
.msg-att-chip {
    display: flex; align-items: center; gap: .4rem;
    background: var(--bg-tertiary); border: 1px solid var(--border-color);
    border-radius: 6px; padding: .3rem .7rem; font-size: .78rem;
    text-decoration: none; color: var(--text-primary); transition: border-color .15s;
}
.msg-att-chip:hover { border-color: var(--primary-accent); color: var(--primary-accent); }
.msg-att-chip i { color: var(--primary-accent); }

/* ── Compose ── */
.msg-compose-pane {
    display: flex; flex-direction: column; overflow: hidden;
}
.msg-compose-form { flex: 1; overflow-y: auto; padding: 1.25rem; display: flex; flex-direction: column; gap: .85rem; }
.msg-compose-form label { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; display: block; margin-bottom: .25rem; }
.msg-compose-form input,
.msg-compose-form select,
.msg-compose-form textarea {
    width: 100%; background: var(--bg-tertiary); border: 1px solid var(--border-color);
    border-radius: 8px; color: var(--text-primary); padding: .6rem .85rem;
    font-size: .9rem; font-family: inherit; outline: none; transition: border-color .2s;
}
.msg-compose-form input:focus,
.msg-compose-form select:focus,
.msg-compose-form textarea:focus { border-color: var(--primary-accent); }
.msg-compose-form textarea { min-height: 140px; resize: vertical; }
.msg-compose-footer {
    padding: .85rem 1.25rem; border-top: 1px solid var(--border-color);
    display: flex; gap: .75rem; align-items: center; flex-shrink: 0;
}
.msg-att-preview { display: flex; flex-wrap: wrap; gap: .4rem; }
.msg-att-tag {
    background: rgba(168,85,247,.15); color: #a855f7;
    border-radius: 4px; padding: 2px 8px; font-size: .75rem;
    display: flex; align-items: center; gap: .3rem;
}
.msg-att-tag button { background: none; border: none; color: #a855f7; cursor: pointer; padding: 0; font-size: .8rem; }

/* ── Notification badge ── */
.msg-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 18px; height: 18px; padding: 0 4px;
    background: #ef4444; color: #fff;
    border-radius: 9px; font-size: .68rem; font-weight: 700;
    margin-left: auto; line-height: 1;
}
.msg-badge.hidden { display: none; }

/* ── Sidebar nav badge positioning ── */
.lib-nav-item .msg-badge,
.admin-nav a .msg-badge { margin-left: auto; }
