/* ============================================================================
   MISAC.chat - Messenger UI. Uses MISAC design tokens (--m-*) with fallbacks;
   dark mode inherits via [data-theme="dark"]. Class prefix: .mchat-
   ============================================================================ */

.mchat {
    display: flex;
    height: 100%;
    width: 100%;
    overflow: hidden;
    background: var(--m-bg, #fff);
    color: var(--m-text, #1f2430);
    font-size: 14px;
}

/* ── Left: conversation list ───────────────────────────────────────────── */
.mchat-list {
    width: 300px;
    min-width: 260px;
    border-right: 1px solid var(--m-border, #e6e8ec);
    display: flex;
    flex-direction: column;
    background: var(--m-bg-subtle, #f7f8fa);
}
.mchat-list-hd {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; font-weight: 600;
    border-bottom: 1px solid var(--m-border, #e6e8ec);
}
.mchat-list-title { font-size: 15px; }
.mchat-newbtn {
    width: 28px; height: 28px; border-radius: 50%;
    border: none; cursor: pointer; font-size: 13px; line-height: 1;
    background: var(--m-primary, #2272b5); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
}
.mchat-newbtn:hover { filter: brightness(1.08); }
.mchat-search { padding: 8px 12px; }
.mchat-search input {
    width: 100%; box-sizing: border-box; padding: 7px 10px;
    border: 1px solid var(--m-border, #e6e8ec); border-radius: 8px;
    background: var(--m-bg, #fff); color: inherit; font-size: 13px;
}
.mchat-convs { flex: 1; overflow-y: auto; }
.mchat-noconv, .mchat-empty, .mchat-loading {
    padding: 28px 16px; text-align: center; color: var(--m-text-muted, #6b7280); font-size: 13px;
}
.mchat-conv {
    display: flex; gap: 10px; align-items: center;
    padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--m-border-subtle, #f0f1f3);
}
.mchat-conv:hover { background: var(--m-hover, #eef1f5); }
.mchat-conv.is-active { background: var(--m-primary-soft, #e3eefb); }
.mchat-conv-main { flex: 1; min-width: 0; }
.mchat-conv-top { display: flex; justify-content: space-between; gap: 6px; }
.mchat-conv-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mchat-conv-time { font-size: 11px; color: var(--m-text-muted, #9aa1ad); flex-shrink: 0; }
.mchat-conv-bot { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.mchat-conv-prev { flex: 1; min-width: 0; font-size: 12.5px; color: var(--m-text-muted, #6b7280); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mchat-prev-ic { font-size: 11px; opacity: .85; }
.mchat-unread {
    background: var(--m-primary, #2272b5); color: #fff; font-size: 11px; font-weight: 600;
    min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px;
    display: inline-flex; align-items: center; justify-content: center;
}
.mchat-mute { font-size: 11px; opacity: .7; }

/* ── Avatar ────────────────────────────────────────────────────────────── */
.mchat-av {
    width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
    background: var(--m-primary, #2272b5); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 14px;
}
.mchat-av.is-group { background: var(--m-accent, #ab217f); }
.mchat-av.small { width: 28px; height: 28px; font-size: 11px; }

/* ── Right: thread ─────────────────────────────────────────────────────── */
.mchat-thread { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.mchat-thd-hd {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-bottom: 1px solid var(--m-border, #e6e8ec);
    background: var(--m-bg, #fff);
}
.mchat-back { display: none; border: none; background: none; font-size: 24px; cursor: pointer; color: inherit; line-height: 1; padding: 0 4px; }
.mchat-thd-meta { flex: 1; min-width: 0; }
.mchat-thd-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mchat-thd-sub { font-size: 12px; color: var(--m-text-muted, #6b7280); }
.mchat-thd-actions button {
    border: none; background: none; font-size: 16px; cursor: pointer; color: inherit;
    padding: 4px 6px; border-radius: 6px;
}
.mchat-thd-actions button:hover { background: var(--m-hover, #eef1f5); }

.mchat-msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.mchat-more { align-self: center; font-size: 12px; color: var(--m-primary, #2272b5); cursor: pointer; padding: 6px; }
.mchat-sys { align-self: center; font-size: 11.5px; color: var(--m-text-muted, #8a93a0); background: var(--m-bg-subtle, #f0f1f3); padding: 3px 10px; border-radius: 10px; margin: 4px 0; }

.mchat-msg { display: flex; max-width: 76%; }
.mchat-msg.is-mine { align-self: flex-end; justify-content: flex-end; }
.mchat-bubble {
    background: var(--m-bg-subtle, #f0f1f3); border-radius: 12px;
    padding: 7px 11px; position: relative; word-wrap: break-word; overflow-wrap: anywhere;
}
.mchat-msg.is-mine .mchat-bubble { background: var(--m-primary, #2272b5); color: #fff; }
.mchat-msg-author { font-size: 11.5px; font-weight: 600; color: var(--m-accent, #ab217f); margin-bottom: 2px; }
.mchat-bubble-text { white-space: pre-wrap; line-height: 1.4; }
.mchat-meta { display: flex; align-items: center; gap: 5px; justify-content: flex-end; margin-top: 3px; }
.mchat-time { font-size: 10.5px; opacity: .65; }
.mchat-ticks { font-size: 11px; opacity: .8; }
.mchat-ticks.is-read { color: #5dd0ff; opacity: 1; }
.mchat-del { border: none; background: none; cursor: pointer; color: inherit; opacity: .5; font-size: 14px; line-height: 1; padding: 0 2px; }
.mchat-del:hover { opacity: 1; }

/* tags + attachments */
.mchat-tag {
    display: inline-flex; align-items: center; gap: 4px; margin-top: 5px; margin-right: 4px;
    font-size: 12px; padding: 3px 8px; border-radius: 8px; cursor: pointer;
    background: rgba(34,114,181,.12); color: var(--m-primary, #2272b5); border: 1px solid rgba(34,114,181,.25);
}
.mchat-msg.is-mine .mchat-tag { background: rgba(255,255,255,.2); color: #fff; border-color: rgba(255,255,255,.35); }
.mchat-tag.is-locked { opacity: .6; cursor: not-allowed; text-decoration: line-through; }
.mchat-att-img { display: block; margin-top: 5px; }
.mchat-att-img img { max-width: 220px; max-height: 220px; border-radius: 8px; display: block; }
.mchat-att-file { display: inline-block; margin-top: 5px; font-size: 12.5px; color: inherit; text-decoration: underline; }

.mchat-typing { height: 16px; padding: 0 16px; font-size: 12px; color: var(--m-text-muted, #8a93a0); font-style: italic; }

/* compose */
.mchat-compose {
    display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px;
    border-top: 1px solid var(--m-border, #e6e8ec); background: var(--m-bg, #fff);
}
.mchat-attach { border: none; background: none; font-size: 18px; cursor: pointer; padding: 6px; color: var(--m-text-muted, #6b7280); }
.mchat-compose textarea {
    flex: 1; resize: none; border: 1px solid var(--m-border, #e6e8ec); border-radius: 18px;
    padding: 9px 14px; font-size: 14px; font-family: inherit; line-height: 1.4; max-height: 120px;
    background: var(--m-bg, #fff); color: inherit; box-sizing: border-box;
}
.mchat-sendbtn {
    border: none; background: var(--m-primary, #2272b5); color: #fff; cursor: pointer;
    border-radius: 18px; padding: 9px 16px; font-weight: 600; font-size: 13px;
}
.mchat-sendbtn:hover { filter: brightness(1.08); }

/* ── New conversation / group info panels ──────────────────────────────── */
.mchat-new, .mchat-ginfo { display: flex; flex-direction: column; gap: 8px; padding: 4px; }
.mchat-new input, .mchat-ginfo input {
    padding: 8px 10px; border: 1px solid var(--m-border, #e6e8ec); border-radius: 8px;
    background: var(--m-bg, #fff); color: inherit; font-size: 14px; box-sizing: border-box; width: 100%;
}
.mchat-ginfo label { font-size: 12px; color: var(--m-text-muted, #6b7280); margin-top: 4px; }
.mchat-picked { display: flex; flex-wrap: wrap; gap: 6px; }
.mchat-chip { background: var(--m-primary-soft, #e3eefb); color: var(--m-primary, #2272b5); padding: 3px 9px; border-radius: 12px; font-size: 12.5px; cursor: pointer; }
.mchat-results, .mchat-addres { max-height: 260px; overflow-y: auto; border: 1px solid var(--m-border-subtle, #f0f1f3); border-radius: 8px; }
.mchat-addrow {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px; cursor: pointer; font-size: 13.5px;
    border-bottom: 1px solid var(--m-border-subtle, #f0f1f3);
}
.mchat-addrow:hover { background: var(--m-hover, #eef1f5); }
.mchat-addrow.is-picked { background: var(--m-primary-soft, #e3eefb); }
.mchat-email { margin-left: auto; font-size: 11.5px; color: var(--m-text-muted, #9aa1ad); }
.mchat-grouprow { display: flex; flex-direction: column; gap: 4px; }
.mchat-grouprow span { font-size: 12px; color: var(--m-text-muted, #6b7280); }
.mchat-primary {
    border: none; background: var(--m-primary, #2272b5); color: #fff; cursor: pointer;
    border-radius: 8px; padding: 9px 14px; font-weight: 600; font-size: 13.5px; margin-top: 4px;
}
.mchat-primary:disabled { opacity: .5; cursor: not-allowed; }
.mchat-members-hd { font-weight: 600; margin-top: 10px; font-size: 13px; }
.mchat-members { display: flex; flex-direction: column; gap: 4px; }
.mchat-member { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.mchat-member-name { flex: 1; }
.mchat-role { font-size: 11px; color: var(--m-text-muted, #9aa1ad); text-transform: capitalize; }
.mchat-member button { border: none; background: none; cursor: pointer; color: var(--m-danger, #d33); font-size: 16px; }

/* ── Hosted inside the slide-in sidebar (MISAC.sidebar content area) ─────── */
/* .msb-content is flex:1 of a full-height column, so the shell fills it. */
.msb-content > .mchat { height: 100%; overflow: hidden; }

/* ── Responsive: narrow -> single pane (thread overlays list) ───────────── */
@media (max-width: 640px) {
    .mchat-list { width: 100%; }
    .mchat-thread { display: none; }
    .mchat--thread .mchat-list { display: none; }
    .mchat--thread .mchat-thread { display: flex; }
    .mchat-back { display: inline-block; }
}
