/* Shared chat (direct messages) UI — used by the admin, teacher and student
   dashboards. Colours come from each dashboard's theme variables, with
   fallbacks so it still looks right where a variable is not defined. */

.dm-root {
    display: flex;
    height: 70vh;
    min-height: 420px;
    border: 1px solid var(--border-color, rgba(128, 128, 128, 0.3));
    border-radius: var(--border-radius, 8px);
    overflow: hidden;
    background: var(--background-white, #fff);
    color: var(--text-color, #333);
}

/* ---------- Sidebar: conversation list ---------- */
.dm-sidebar {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color, rgba(128, 128, 128, 0.3));
    background: var(--background-light, #f6f6f6);
}

.dm-sidebar-head {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-bottom: 1px solid var(--border-color, rgba(128, 128, 128, 0.3));
}

.dm-search {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--border-color, rgba(128, 128, 128, 0.35));
    border-radius: 20px;
    background: var(--background-white, #fff);
    color: var(--text-color, #333);
    font-size: 0.9rem;
}

.dm-new-chat {
    flex-shrink: 0;
    width: 38px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    background: var(--primary-color, #444);
    color: #fff;
    font-size: 1rem;
}

.dm-conversations {
    flex: 1;
    overflow-y: auto;
}

.dm-conv {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color, rgba(128, 128, 128, 0.18));
    transition: background 0.15s ease;
}

.dm-conv:hover { background: rgba(128, 128, 128, 0.12); }

.dm-conv.active {
    background: var(--primary-color, #444);
    color: #fff;
}

.dm-conv.active .dm-conv-preview,
.dm-conv.active .dm-conv-time { color: rgba(255, 255, 255, 0.75); }

.dm-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--secondary-color, #999);
}

.dm-conv-main { flex: 1; min-width: 0; }

.dm-conv-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Distinguishes people who share a name (e.g. a teacher and a student). */
.dm-conv-role {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    border-radius: 9px;
    background: var(--secondary-color, #999);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    vertical-align: middle;
}

.dm-conv-preview {
    font-size: 0.85rem;
    color: var(--text-muted, #888);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dm-conv-side {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.dm-conv-time {
    font-size: 0.7rem;
    color: var(--text-muted, #888);
    white-space: nowrap;
}

.dm-badge {
    min-width: 20px;
    padding: 1px 6px;
    border-radius: 10px;
    background: #e0245e;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    text-align: center;
}

/* ---------- Thread pane ---------- */
.dm-thread-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.dm-thread-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color, rgba(128, 128, 128, 0.3));
    font-weight: 600;
}

/* Back to the conversation list — only needed on mobile, where the sidebar
   is hidden while a thread is open. */
.dm-back {
    display: none;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color, rgba(128, 128, 128, 0.3));
    border-radius: 50%;
    background: var(--background-light, #eee);
    color: var(--text-color, #333);
    cursor: pointer;
    font-size: 1.05rem;
    line-height: 1;
}

/* Right-click / long-press menu on a conversation row. */
.dm-ctx-menu {
    position: fixed;
    z-index: 10002;
    padding: 6px;
    border-radius: 10px;
    background: var(--background-white, #fff);
    border: 1px solid var(--border-color, rgba(128, 128, 128, 0.3));
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
}

.dm-ctx-menu button {
    display: block;
    width: 100%;
    padding: 9px 14px;
    border: none;
    border-radius: 7px;
    background: none;
    color: #c62828;
    font-size: 0.88rem;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
}

.dm-ctx-menu button:hover { background: rgba(198, 40, 40, 0.12); }

.dm-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--background-light, #f6f6f6);
}

.dm-msg { display: flex; flex-direction: column; max-width: 70%; }
.dm-msg.mine { align-self: flex-end; align-items: flex-end; }

.dm-bubble {
    padding: 9px 13px;
    border-radius: 16px;
    background: var(--background-white, #fff);
    border: 1px solid var(--border-color, rgba(128, 128, 128, 0.25));
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.dm-msg.mine .dm-bubble {
    background: var(--primary-color, #444);
    border-color: var(--primary-color, #444);
    color: #fff;
}

.dm-meta {
    font-size: 0.7rem;
    color: var(--text-muted, #888);
    margin-top: 3px;
}

.dm-msg-image {
    max-width: 220px;
    max-height: 220px;
    border-radius: 12px;
    margin-top: 5px;
    display: block;
    cursor: pointer;
}

.dm-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 5px;
    padding: 8px 12px;
    border-radius: 10px;
    background: var(--background-white, #fff);
    border: 1px solid var(--border-color, rgba(128, 128, 128, 0.3));
    color: var(--text-color, #333);
    text-decoration: none;
    font-size: 0.85rem;
}

.dm-file-chip:hover { border-color: var(--primary-color, #444); }

/* ---------- Composer ---------- */
.dm-composer {
    border-top: 1px solid var(--border-color, rgba(128, 128, 128, 0.3));
    padding: 10px 12px;
    background: var(--background-white, #fff);
}

.dm-pending {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.dm-pending-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 8px;
    background: var(--background-light, #eee);
    font-size: 0.78rem;
}

.dm-pending-chip button {
    border: none;
    background: none;
    cursor: pointer;
    color: #e0245e;
    font-weight: 700;
}

.dm-composer-row { display: flex; align-items: flex-end; gap: 8px; }

.dm-composer textarea {
    flex: 1;
    resize: none;
    max-height: 120px;
    padding: 10px 12px;
    border-radius: 18px;
    border: 1px solid var(--border-color, rgba(128, 128, 128, 0.35));
    background: var(--background-light, #f6f6f6);
    color: var(--text-color, #333);
    font-family: inherit;
    font-size: 0.92rem;
    line-height: 1.4;
}

.dm-attach, .dm-send {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
}

.dm-attach {
    background: var(--background-light, #eee);
    color: var(--text-color, #333);
    border: 1px solid var(--border-color, rgba(128, 128, 128, 0.3));
}

.dm-send { background: var(--primary-color, #444); color: #fff; }
.dm-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Empty state & contact picker ---------- */
.dm-empty {
    margin: auto;
    padding: 24px;
    text-align: center;
    color: var(--text-muted, #888);
    font-style: italic;
}

.dm-picker-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.dm-picker {
    width: min(420px, 92vw);
    max-height: 74vh;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    overflow: hidden;
    background: var(--background-white, #fff);
    color: var(--text-color, #333);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

.dm-picker-head {
    display: flex;
    gap: 8px;
    padding: 14px;
    border-bottom: 1px solid var(--border-color, rgba(128, 128, 128, 0.3));
}

.dm-picker-list { overflow-y: auto; }

.dm-contact {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color, rgba(128, 128, 128, 0.15));
}

.dm-contact:hover { background: rgba(128, 128, 128, 0.12); }
.dm-contact-sub { font-size: 0.78rem; color: var(--text-muted, #888); }

.dm-role-tag {
    margin-left: auto;
    font-size: 0.68rem;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--secondary-color, #999);
    color: #fff;
    text-transform: uppercase;
}

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
    .dm-root { height: 78vh; }
    .dm-sidebar { width: 100%; }
    .dm-root.dm-thread-open .dm-sidebar { display: none; }
    .dm-root:not(.dm-thread-open) .dm-thread-pane { display: none; }
    .dm-root.dm-thread-open .dm-back { display: inline-flex; }
    .dm-msg { max-width: 85%; }
}
