/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   MENSAGENS PRIVADAS — Confia no Pai  |  Premium Edition
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */

/* ── Animações ───────────────────────────────────────────────────────── */
@keyframes cm-fadeInUp {
    from { opacity:0; transform:translateY(10px) scale(.97); }
    to   { opacity:1; transform:translateY(0)    scale(1); }
}
@keyframes cm-slideIn {
    from { opacity:0; transform:translateX(-16px); }
    to   { opacity:1; transform:translateX(0); }
}
@keyframes cm-popIn {
    0%   { transform:scale(.5); opacity:0; }
    70%  { transform:scale(1.12); }
    100% { transform:scale(1); opacity:1; }
}
@keyframes cm-pulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(16,185,129,.5); }
    50%      { box-shadow: 0 0 0 6px rgba(16,185,129,0); }
}
@keyframes cm-dot-bounce {
    0%,80%,100% { transform: translateY(0); }
    40%          { transform: translateY(-6px); }
}
@keyframes cm-shimmer {
    0%   { background-position: -200% center; }
    100% { background-position:  200% center; }
}
@keyframes cm-badge-pop {
    0%   { transform:scale(0); }
    70%  { transform:scale(1.25); }
    100% { transform:scale(1); }
}

/* ── Container principal ─────────────────────────────────────────────── */
#chatMensagensPanel {
    display: flex;
    flex-direction: row;
    height: calc(100vh - 120px);
    min-height: 480px;
    background: #fff;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 4px 32px rgba(108,92,231,.12), 0 1px 4px rgba(0,0,0,.06);
    font-family: 'Roboto', sans-serif;
    animation: cm-fadeInUp .35s cubic-bezier(.34,1.56,.64,1) both;
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.cm-sidebar {
    width: 320px;
    min-width: 260px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #ede9fe;
    background: #fff;
}

.cm-sidebar-header {
    background: linear-gradient(135deg, #6c3ce1 0%, #9b59b6 100%);
    color: #fff;
    padding: 16px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 58px;
    position: relative;
    overflow: hidden;
}
.cm-sidebar-header::before {
    content:'';
    position:absolute; inset:0;
    background: linear-gradient(90deg,transparent 0%,rgba(255,255,255,.08) 50%,transparent 100%);
    background-size: 200% 100%;
    animation: cm-shimmer 3s linear infinite;
}
.cm-sidebar-title {
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: .3px;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
}
.cm-new-btn {
    background: rgba(255,255,255,.2);
    border: 1.5px solid rgba(255,255,255,.35);
    color: #fff;
    width: 34px; height: 34px;
    border-radius: 10px;
    font-size: .9rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, transform .15s;
    position: relative;
}
.cm-new-btn:hover { background: rgba(255,255,255,.35); transform: rotate(12deg) scale(1.1); }

/* Tabs */
.cm-tabs {
    display: flex;
    border-bottom: 1px solid #ede9fe;
    background: #fafbff;
    padding: 0 4px;
    gap: 2px;
}
.cm-tab {
    flex: 1;
    padding: 10px 0;
    font-size: .78rem;
    font-weight: 700;
    color: #94a3b8;
    cursor: pointer;
    border: none;
    background: none;
    border-bottom: 2.5px solid transparent;
    transition: color .15s, border-color .15s;
    letter-spacing: .2px;
}
.cm-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.cm-tab:hover:not(.active) { color: #475569; }

/* Busca */
.cm-search {
    position: relative;
    padding: 10px 12px;
    background: #fafbff;
    border-bottom: 1px solid #f0f0fa;
}
.cm-search-icon {
    position: absolute; left: 22px; top: 50%; transform: translateY(-50%);
    color: #a29bfe; font-size: .82rem;
}
.cm-search input {
    width: 100%; padding: 8px 12px 8px 32px;
    border: 1.5px solid #ede9fe; border-radius: 20px;
    background: #fff; font-size: .83rem; font-family: 'Roboto', sans-serif;
    outline: none; box-sizing: border-box; color: #1e293b;
    transition: border-color .2s, box-shadow .2s;
}
.cm-search input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108,92,231,.12);
}

/* Lista */
.cm-list {
    flex: 1; overflow-y: auto;
    scrollbar-width: thin; scrollbar-color: #ede9fe transparent;
}
.cm-list-empty {
    text-align: center; padding: 40px 20px;
    color: #94a3b8; font-size: .85rem; line-height: 1.7;
}
.cm-list-item {
    display: flex; align-items: center;
    padding: 12px 14px; cursor: pointer;
    border-bottom: 1px solid #f8f6ff;
    transition: background .12s, transform .1s;
    gap: 10px;
    animation: cm-slideIn .25s ease both;
}
.cm-list-item:hover { background: #f8f6ff; }
.cm-list-item.active { background: #ede9fe; }
.cm-list-item:hover { transform: translateX(2px); }

/* Avatar */
.cm-avatar {
    width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 800; color: #fff; overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
    transition: transform .15s;
}
.cm-list-item:hover .cm-avatar { transform: scale(1.08); }
.cm-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Online dot */
.cm-online-wrap { position: relative; flex-shrink: 0; }
.cm-online-dot {
    position: absolute; bottom: 1px; right: 1px;
    width: 11px; height: 11px; border-radius: 50%;
    background: #10b981; border: 2px solid #fff;
    animation: cm-pulse 2s infinite;
}

.cm-item-info { flex: 1; min-width: 0; }
.cm-item-name {
    font-weight: 700; font-size: .88rem; color: #1e293b;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    display: flex; align-items: center; gap: 6px;
}
.cm-item-preview {
    font-size: .76rem; color: #94a3b8;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 2px;
}
.cm-item-meta {
    display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0;
}
.cm-item-time { font-size: .68rem; color: #c4b5fd; font-weight: 500; }
.cm-unread {
    background: linear-gradient(135deg, var(--primary), #a855f7);
    color: #fff; font-size: .68rem; font-weight: 800;
    min-width: 20px; height: 20px; line-height: 20px;
    border-radius: 10px; text-align: center; padding: 0 6px;
    animation: cm-badge-pop .35s cubic-bezier(.34,1.56,.64,1) both;
    box-shadow: 0 2px 8px rgba(108,92,231,.35);
}

/* Tags de grupo */
.cm-tag {
    font-size: .62rem; font-weight: 800; padding: 2px 7px;
    border-radius: 20px; letter-spacing: .3px;
}
.cm-tag-public  { background: #dcfce7; color: #166534; }
.cm-tag-private { background: #fef3c7; color: #92400e; }

.cm-group-create-bar { padding: 10px 12px; border-bottom: 1px solid #f0f0fa; }

/* Group cards premium */
.cm-group-card {
    display: flex; align-items: flex-start;
    padding: 12px 14px; cursor: pointer;
    border-bottom: 1px solid #f8f6ff;
    transition: background .12s;
    gap: 10px; flex-wrap: wrap;
}
.cm-group-card:hover { background: #f8f6ff; }
.cm-group-meta { flex: 1; min-width: 0; }
.cm-group-name {
    font-weight: 700; font-size: .88rem; color: #1e293b;
    display: flex; align-items: center; gap: 6px;
}
.cm-group-desc { font-size: .76rem; color: #94a3b8; margin-top: 2px; }
.cm-group-members { font-size: .7rem; color: #a29bfe; font-weight: 600; margin-top: 3px; }

.cm-btn-sm {
    font-size: .72rem; font-weight: 700;
    padding: 5px 12px; border-radius: 20px;
    border: none; cursor: pointer; transition: transform .12s, opacity .12s;
    white-space: nowrap;
}
.cm-btn-sm:disabled { opacity: .5; cursor: not-allowed; background: #e2e8f0; color: #94a3b8; }
.cm-btn-primary {
    background: linear-gradient(135deg, var(--primary), #a855f7);
    color: #fff; box-shadow: 0 2px 8px rgba(108,92,231,.3);
}
.cm-btn-primary:hover:not(:disabled) { transform: translateY(-1px); opacity: .9; }
.cm-btn-secondary { background: #ede9fe; color: var(--primary); }
.cm-btn-secondary:hover:not(:disabled) { background: #ddd6fe; transform: translateY(-1px); }

/* ── Área de mensagens ───────────────────────────────────────────────── */
.cm-main {
    flex: 1; display: flex; flex-direction: column;
    background: linear-gradient(180deg, #faf8ff 0%, #f8f6ff 100%);
    min-width: 0;
}

/* Welcome screen */
.cm-welcome {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center; padding: 40px; color: #64748b;
}
.cm-welcome-icon {
    width: 84px; height: 84px;
    background: linear-gradient(135deg, #ede9fe, #ddd6fe);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem; color: var(--primary); margin-bottom: 20px;
    animation: cm-popIn .5s cubic-bezier(.34,1.56,.64,1) both .1s;
    box-shadow: 0 8px 24px rgba(108,92,231,.2);
}
.cm-welcome h3 { margin: 0 0 10px; color: #1e293b; font-size: 1.15rem; font-weight: 800; }
.cm-welcome p { font-size: .88rem; line-height: 1.6; max-width: 320px; }

/* Header da conversa */
.cm-conv-header {
    background: #fff; padding: 10px 16px;
    display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid #ede9fe; min-height: 58px;
    box-shadow: 0 1px 8px rgba(108,92,231,.06);
}
.cm-back {
    background: none; border: none; color: var(--primary); font-size: 1rem;
    cursor: pointer; padding: 6px; border-radius: 8px; display: none;
    transition: background .12s, transform .12s;
}
.cm-back:hover { background: #ede9fe; transform: translateX(-2px); }
.cm-conv-info { flex: 1; }
.cm-conv-name { font-weight: 800; font-size: .95rem; color: #1e293b; }
.cm-conv-status { font-size: .74rem; color: #10b981; min-height: 16px; font-weight: 600; }

/* Mensagens */
.cm-messages {
    flex: 1; overflow-y: auto; padding: 16px 20px;
    display: flex; flex-direction: column; gap: 3px;
    scrollbar-width: thin; scrollbar-color: #ede9fe transparent;
}

/* Date divider */
.cm-date-divider { text-align: center; padding: 8px 0; margin: 6px 0; }
.cm-date-divider span {
    background: rgba(108,92,231,.08); padding: 4px 16px;
    border-radius: 20px; font-size: .7rem; color: #7c3aed; font-weight: 700;
    letter-spacing: .3px;
}

/* Balões */
.cm-msg {
    max-width: 68%; padding: 9px 13px 5px;
    border-radius: 14px; position: relative;
    font-size: .87rem; line-height: 1.48; word-wrap: break-word;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
    animation: cm-fadeInUp .22s ease both;
}
.cm-msg.me {
    background: linear-gradient(135deg, #ede9fe, #ddd6fe);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    border-left: 3px solid var(--primary);
}
.cm-msg.other {
    background: #fff;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border-left: 3px solid #e2e8f0;
}
.cm-msg-text { color: #1e293b; white-space: pre-wrap; }
.cm-msg-meta {
    display: flex; justify-content: flex-end;
    align-items: center; gap: 4px; margin-top: 4px;
}
.cm-msg-time { font-size: .66rem; color: #a29bfe; }
.cm-msg-check { font-size: .7rem; color: var(--primary); }

/* Imagem/arquivo no balão */
.cm-msg-image img {
    max-width: 100%; max-height: 220px;
    border-radius: 10px; display: block; cursor: pointer;
    margin-bottom: 4px; transition: transform .2s;
}
.cm-msg-image img:hover { transform: scale(1.02); }
.cm-msg-file {
    display: flex; align-items: center; gap: 10px;
    background: rgba(108,92,231,.07); padding: 10px 12px;
    border-radius: 10px; margin-bottom: 4px;
    text-decoration: none; color: inherit; cursor: pointer;
    border: 1px solid rgba(108,92,231,.15);
    transition: background .15s;
}
.cm-msg-file:hover { background: rgba(108,92,231,.12); }

/* Typing indicator */
.cm-typing {
    padding: 6px 20px; min-height: 28px; background: transparent;
    display: flex; align-items: center;
}
.cm-typing-bubble {
    display: inline-flex; align-items: center; gap: 4px;
    background: #fff; padding: 8px 14px; border-radius: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    font-size: .76rem; color: #7c3aed; font-weight: 600;
}
.cm-typing-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--primary); display: inline-block;
}
.cm-typing-dot:nth-child(1) { animation: cm-dot-bounce 1.2s ease infinite 0s; }
.cm-typing-dot:nth-child(2) { animation: cm-dot-bounce 1.2s ease infinite .2s; }
.cm-typing-dot:nth-child(3) { animation: cm-dot-bounce 1.2s ease infinite .4s; }

/* Barra de envio */
.cm-inputbar {
    display: flex; align-items: flex-end; padding: 10px 14px;
    background: #fff; gap: 8px;
    border-top: 1px solid #ede9fe;
}
.cm-attach {
    background: none; border: none; font-size: 1rem; color: #a29bfe;
    cursor: pointer; padding: 8px; border-radius: 10px; flex-shrink: 0;
    transition: color .12s, background .12s, transform .12s;
}
.cm-attach:hover { color: var(--primary); background: #ede9fe; transform: rotate(-15deg); }
.cm-input-wrap {
    flex: 1; background: #f8f6ff;
    border: 1.5px solid #ede9fe; border-radius: 22px;
    padding: 8px 14px; display: flex; align-items: center;
    transition: border-color .2s, box-shadow .2s;
}
.cm-input-wrap:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108,92,231,.1);
}
.cm-input-wrap textarea {
    flex: 1; border: none; outline: none; resize: none;
    font-size: .87rem; max-height: 100px; min-height: 20px;
    line-height: 1.45; font-family: 'Roboto', sans-serif;
    background: transparent; color: #1e293b;
}
.cm-send {
    width: 40px; height: 40px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #a855f7);
    color: #fff; border: none; cursor: pointer; font-size: .9rem;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    transition: transform .15s, box-shadow .15s;
    box-shadow: 0 3px 12px rgba(108,92,231,.4);
}
.cm-send:hover { transform: scale(1.12) rotate(-10deg); box-shadow: 0 5px 16px rgba(108,92,231,.5); }
.cm-send:active { transform: scale(.95); }
.cm-send:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; }

/* Preview de upload */
.cm-upload-preview {
    display: none; padding: 10px 14px;
    background: #ede9fe; border-top: 1px solid #ddd6fe;
    align-items: center; gap: 10px; font-size: .82rem; color: #5b21b6;
    animation: cm-fadeInUp .2s ease both;
}
.cm-upload-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

/* ── Modal de Criar Grupo ─────────────────────────────────────────────── */
#cmGroupModal {
    position: fixed; inset: 0; background: rgba(15,23,42,.65);
    backdrop-filter: blur(5px); z-index: 9999;
    display: none; align-items: center; justify-content: center;
    opacity: 0; transition: opacity .25s ease;
}
#cmGroupModal.open { display: flex; opacity: 1; }
#cmGroupModal .cm-gm-box {
    background: #fff; border-radius: 24px; padding: 28px 28px 24px;
    width: 92%; max-width: 420px;
    box-shadow: 0 32px 64px -12px rgba(108,92,231,.25);
    transform: translateY(24px) scale(.96);
    transition: transform .3s cubic-bezier(.34,1.56,.64,1);
}
#cmGroupModal.open .cm-gm-box { transform: translateY(0) scale(1); }
.cm-gm-header {
    display: flex; align-items: center; gap: 12px; margin-bottom: 20px;
}
.cm-gm-icon {
    width: 48px; height: 48px; border-radius: 14px;
    background: linear-gradient(135deg,#ede9fe,#ddd6fe);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem;
}
.cm-gm-title { font-size: 1.1rem; font-weight: 800; color: #1e293b; margin: 0; }
.cm-gm-sub   { font-size: .8rem; color: #94a3b8; margin: 2px 0 0; }
.cm-gm-field { margin-bottom: 16px; }
.cm-gm-label { font-size: .8rem; font-weight: 700; color: #475569; margin-bottom: 6px; display: block; }
.cm-gm-input {
    width: 100%; padding: 11px 14px;
    border: 1.5px solid #e2e8f0; border-radius: 12px;
    font-size: .9rem; font-family: 'Roboto', sans-serif;
    outline: none; box-sizing: border-box; color: #1e293b;
    transition: border-color .2s, box-shadow .2s;
}
.cm-gm-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108,92,231,.1); }
.cm-gm-visib { display: flex; gap: 10px; }
.cm-gm-vis-opt {
    flex: 1; padding: 10px; border-radius: 12px;
    border: 2px solid #e2e8f0; cursor: pointer;
    text-align: center; transition: all .2s; background: #f8fafc;
}
.cm-gm-vis-opt.selected { border-color: var(--primary); background: #ede9fe; }
.cm-gm-vis-opt .cm-gm-vis-icon { font-size: 1.4rem; margin-bottom: 4px; }
.cm-gm-vis-opt .cm-gm-vis-label { font-size: .75rem; font-weight: 700; color: #475569; }
.cm-gm-vis-opt.selected .cm-gm-vis-label { color: var(--primary); }
.cm-gm-actions { display: flex; gap: 10px; margin-top: 20px; }
.cm-gm-cancel {
    flex: 1; padding: 11px; border-radius: 12px;
    background: #f1f5f9; color: #475569; border: none;
    font-weight: 700; cursor: pointer; font-family: 'Roboto',sans-serif;
    transition: background .15s;
}
.cm-gm-cancel:hover { background: #e2e8f0; }
.cm-gm-submit {
    flex: 2; padding: 11px; border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), #a855f7);
    color: #fff; border: none; font-weight: 800;
    cursor: pointer; font-family: 'Roboto',sans-serif; font-size: .9rem;
    box-shadow: 0 4px 12px rgba(108,92,231,.35);
    transition: transform .15s, box-shadow .15s;
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.cm-gm-submit:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(108,92,231,.45); }
.cm-gm-submit:disabled { opacity: .5; transform: none; cursor: not-allowed; }

/* ── Responsividade mobile ───────────────────────────────────────────── */
@media (max-width: 680px) {
    #chatMensagensPanel { flex-direction: column; border-radius: 12px; }
    .cm-sidebar { width: 100%; border-right: none; border-bottom: 1px solid #ede9fe; max-height: 50vh; }
    #cmConv { height: 50vh; }
    .cm-back { display: flex !important; }
}

/* ── Botão "Conversar" no fórum ──────────────────────────────────────── */
.forum-dm-btn {
    background: none; border: 1.5px solid var(--primary); color: var(--primary);
    padding: 4px 11px; border-radius: 20px; font-size: .75rem; font-weight: 700;
    cursor: pointer; transition: background .15s, color .15s, transform .12s;
    display: inline-flex; align-items: center; gap: 5px;
}
.forum-dm-btn:hover { background: var(--primary); color: #fff; transform: translateY(-1px); }

/* ── View Grupos de Estudo — cards premium ───────────────────────────── */
.grupo-card {
    background: #fff; border-radius: 16px;
    border: 1.5px solid #ede9fe; padding: 20px;
    display: flex; flex-direction: column; gap: 10px;
    transition: transform .2s, box-shadow .2s, border-color .2s;
    animation: cm-fadeInUp .3s ease both;
    cursor: pointer;
}
.grupo-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 32px rgba(108,92,231,.14);
    border-color: var(--primary);
}
.grupo-card-icon {
    width: 52px; height: 52px; border-radius: 14px;
    background: linear-gradient(135deg,#ede9fe,#ddd6fe);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; flex-shrink: 0;
}
.grupo-card-name { font-weight: 800; font-size: .95rem; color: #1e293b; }
.grupo-card-desc { font-size: .8rem; color: #64748b; line-height: 1.4; }
.grupo-card-footer {
    display: flex; align-items: center; justify-content: space-between;
    margin-top: 4px;
}
.grupo-card-members { font-size: .74rem; color: #a29bfe; font-weight: 600; }
.grupo-card-btn {
    padding: 7px 16px; border-radius: 20px; border: none;
    font-weight: 700; font-size: .78rem; cursor: pointer;
    font-family: 'Roboto',sans-serif; transition: transform .15s, box-shadow .15s;
}
.grupo-card-btn.join {
    background: linear-gradient(135deg,var(--primary),#a855f7);
    color: #fff; box-shadow: 0 3px 10px rgba(108,92,231,.3);
}
.grupo-card-btn.join:hover { transform: translateY(-1px); box-shadow: 0 5px 14px rgba(108,92,231,.4); }
.grupo-card-btn.open { background: #ede9fe; color: var(--primary); }
.grupo-card-btn.pending { background: #fef3c7; color: #92400e; cursor: default; }
