/* Widget de chat del paciente en web (FAB + bandeja + hilo).
   Inyectado por js-routes/chat-publico.js. Usa variables del tema con
   fallbacks oscuros para servir en explorar y mi-espacio. */

.cp-fab {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    z-index: 1400;
    background: var(--accent, #1f8a70);
    color: #06111e;
    box-shadow: 0 8px 24px -6px rgba(0, 0, 0, .5);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .12s ease, filter .15s ease;
}
.cp-fab:hover { filter: brightness(1.08); }
.cp-fab:active { transform: scale(.94); }
.cp-fab-ico { font-size: 24px; line-height: 1; }
.cp-fab-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #e05656;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bg, #070c18);
}

/* Popup anclado abajo-derecha (donde está el FAB). Sin overlay: no es modal. */
.cp-panel[hidden] { display: none; }
/* El atributo [hidden] NO oculta elementos con display:flex explícito (misma
   especificidad que la regla del navegador). Forzamos el ocultado en los del
   widget que togglean por .hidden (badge, avatar del head, hilo, composer…). */
.cp-fab-badge[hidden], .cp-head-av[hidden], .cp-back[hidden],
.cp-inbox[hidden], .cp-thread[hidden], .cp-composer[hidden],
.cp-previews[hidden] { display: none !important; }
.cp-dialog {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 1401;
    width: 380px;
    height: min(70vh, 560px);
    display: flex;
    flex-direction: column;
    background: var(--card, #0e1424);
    color: var(--text, #e6eefc);
    border: 1px solid var(--border, rgba(255, 255, 255, .14));
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 16px 48px -12px rgba(0, 0, 0, .6);
}
/* Al abrir el chat, el FAB cede su lugar al panel. */
body.cp-open .cp-fab { display: none; }
@media (max-width: 560px) {
    .cp-dialog { right: 10px; left: 10px; bottom: 10px; width: auto; height: min(78vh, 600px); }
}

.cp-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border, rgba(255, 255, 255, .1));
    flex: 0 0 auto;
}
.cp-back, .cp-close {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 18px;
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
}
.cp-head-av {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--accent, #1f8a70) center/cover no-repeat;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; color: #06111e; flex: 0 0 auto;
}
.cp-head-title { font-weight: 600; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cp-inbox, .cp-thread { flex: 1; overflow-y: auto; }
.cp-loading, .cp-empty { color: var(--muted, #8a93a6); font-size: 13px; text-align: center; padding: 28px 20px; line-height: 1.5; }

/* Bandeja */
.cp-conv {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 14px; cursor: pointer;
    border-bottom: 1px solid var(--border, rgba(255, 255, 255, .06));
}
.cp-conv:hover { background: var(--panel, rgba(255, 255, 255, .04)); }
.cp-conv-av {
    width: 42px; height: 42px; border-radius: 50%; flex: 0 0 auto;
    background: var(--accent, #1f8a70) center/cover no-repeat;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: #06111e;
}
.cp-conv-mid { flex: 1; min-width: 0; }
.cp-conv-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cp-conv-prev { font-size: 12px; color: var(--muted, #8a93a6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.cp-conv-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: 0 0 auto; }
.cp-conv-time { font-size: 11px; color: var(--muted, #8a93a6); }
.cp-conv-unread { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent, #1f8a70); color: #06111e; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

/* Hilo */
.cp-thread { padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.cp-msg { max-width: 80%; padding: 8px 12px; border-radius: 14px; font-size: 14px; line-height: 1.35; white-space: pre-wrap; word-break: break-word; }
.cp-msg.is-mine { align-self: flex-end; background: var(--accent, #1f8a70); color: #06111e; border-bottom-right-radius: 4px; }
.cp-msg.is-other { align-self: flex-start; background: var(--panel, rgba(255, 255, 255, .06)); border-bottom-left-radius: 4px; }
.cp-msg-time { display: block; font-size: 10px; opacity: .65; margin-top: 3px; text-align: right; }

/* Composer */
.cp-composer { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border, rgba(255, 255, 255, .1)); flex: 0 0 auto; }
.cp-attach { border: none; background: transparent; color: var(--muted, #8a93a6); font-size: 20px; cursor: pointer; padding: 6px 2px; flex: 0 0 auto; }
.cp-composer textarea {
    flex: 1; resize: none; border-radius: 10px; max-height: 120px;
    border: 1px solid var(--border, rgba(255, 255, 255, .14));
    background: var(--panel, rgba(255, 255, 255, .04)); color: inherit;
    padding: 8px 10px; font-family: inherit; font-size: 14px;
}
.cp-send { border: none; border-radius: 10px; padding: 0 16px; font-weight: 600; cursor: pointer; background: var(--accent, #1f8a70); color: #06111e; }
.cp-send:disabled { opacity: .5; cursor: default; }

/* Previews de imágenes por subir */
.cp-previews { display: flex; gap: 8px; padding: 8px 12px 0; flex-wrap: wrap; flex: 0 0 auto; }
.cp-prev { position: relative; width: 56px; height: 56px; border-radius: 8px; overflow: hidden; flex: 0 0 auto; }
.cp-prev img { width: 100%; height: 100%; object-fit: cover; }
.cp-prev-ov { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .45); color: #fff; font-size: 11px; font-weight: 700; }
.cp-prev-x { position: absolute; top: 1px; right: 1px; width: 18px; height: 18px; border: none; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #fff; font-size: 11px; line-height: 1; cursor: pointer; padding: 0; }

/* Imágenes dentro de las burbujas */
.cp-msg-imgs { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; margin-bottom: 4px; max-width: 220px; }
.cp-msg-imgs.n1 { grid-template-columns: 1fr; }
.cp-msg-imgs img { width: 100%; object-fit: cover; cursor: pointer; display: block; border-radius: 6px; aspect-ratio: 1 / 1; }
.cp-msg-imgs.n1 img { aspect-ratio: auto; max-height: 240px; }
.cp-msg.is-img { padding: 4px; }
