/* Tarjeta de cápsula compartida por las dos vistas del grupo de lectura. */
.chat-message__capsule {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: min(310px, 70vw);
    margin-top: 9px;
    padding: 12px;
    border: 1px solid rgba(245, 125, 118, 0.35);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.78);
    color: #363636;
    text-decoration: none;
    transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.chat-message__capsule:hover,
.chat-message__capsule:focus-visible {
    transform: translateY(-1px);
    border-color: #f57d76;
    box-shadow: 0 6px 18px rgba(68, 34, 32, 0.12);
    outline: none;
}

.chat-message__capsule-icon {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border-radius: 12px;
    background: rgba(168, 169, 176, 0.12);
    color: #a8a9b0;
    font-size: 21px;
}

.chat-message__capsule-copy {
    min-width: 0;
    flex: 1;
}

.chat-message__capsule-kind {
    display: block;
    margin-bottom: 2px;
    color: #c75f5a;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.chat-message__capsule-title {
    display: -webkit-box;
    overflow: hidden;
    color: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.25;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.chat-message__capsule-action {
    flex: 0 0 auto;
    color: #f57d76;
    font-size: 1.1rem;
    font-weight: 800;
}

/* Tarjeta enriquecida para enlaces internos compartidos */
.chat-message__bubble:has(.chat-message__capsule),
.chat-message__bubble--capsule {
    padding: 0 !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
}

/* El tema oscuro define las burbujas propias con mayor especificidad. */
.dark .chat-message__bubble--capsule,
.dark .chat-message--mine .chat-message__bubble--capsule {
    padding: 0 !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
}

/* El texto opcional y la cápsula son dos piezas visuales independientes. */
.chat-message__bubble:has(.chat-message__capsule) > .chat-message__body,
.chat-message__bubble--capsule > .chat-message__body {
    display: block;
    width: fit-content;
    max-width: 100%;
    margin-bottom: 9px;
    padding: 10px 14px;
    border-radius: 16px 16px 16px 4px;
    background: #ffffff;
    color: #1c1c1e;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.04);
    white-space: pre-wrap;
}

.chat-message--mine .chat-message__bubble:has(.chat-message__capsule) > .chat-message__body,
.chat-message--mine .chat-message__bubble--capsule > .chat-message__body {
    margin-left: auto;
    border-radius: 16px 16px 4px 16px;
    background: #f57d76;
    color: #ffffff;
}

.dark .chat-message__bubble--capsule > .chat-message__body {
    background: #2a2a2c !important;
    color: #f5f5f7 !important;
}

.dark .chat-message--mine .chat-message__bubble--capsule > .chat-message__body {
    background: #f57d76 !important;
    color: #ffffff !important;
}

.chat-message__bubble:has(.chat-message__capsule) > .chat-message__capsule,
.chat-message__bubble--capsule > .chat-message__capsule {
    margin-top: 0;
}

.chat-message__capsule {
    display: block;
    width: min(470px, 62vw);
    padding: 0;
    overflow: hidden;
    border: 1px solid rgba(247, 162, 157, 0.35);
    border-radius: 20px;
    background: #FAF6E3;
    color: #1c1c1e;
    white-space: normal;
}

/* La entrada de Chats conserva el mismo ancho y fondo que la del grupo. */
.chat__conversation-messages .message-bubble:has(.chat-message__capsule) {
    box-sizing: border-box;
    width: min(470px, calc(100% - 48px));
    max-width: min(470px, calc(100% - 48px));
    padding: 0 !important;
    background: transparent !important;
    color: inherit;
}

.chat__conversation-messages .message-bubble:has(.chat-message__capsule) .chat-reading-content,
.chat__conversation-messages .message-bubble:has(.chat-message__capsule) .chat-message__capsule {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}

.chat__conversation-messages .message-bubble:has(.chat-message__capsule) .message-sender,
.chat__conversation-messages .message-bubble:has(.chat-message__capsule) .chat-reading-pin-button,
.chat__conversation-messages .message-bubble:has(.chat-message__capsule) .message-time {
    margin: 4px 8px !important;
}

.chat-message__capsule-hero {
    display: flex;
    align-items: flex-start;
    min-height: 130px;
    padding: 14px;
    background-position: center;
    background-size: cover;
}

.chat-message__capsule-content {
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 17px 20px;
}

.chat-message__capsule-kind {
    align-self: flex-start;
    padding: 4px 9px;
    border-radius: 999px;
    background: rgba(245, 125, 118, .14);
    color: #c75f5a;
    font-size: .66rem;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.chat-message__capsule-title {
    color: #1c1c1e;
    font-size: 1rem;
    font-weight: 800;
}

.chat-message__capsule-description {
    display: -webkit-box;
    overflow: hidden;
    color: #565858;
    font-size: .84rem;
    line-height: 1.5;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.chat-message__capsule-meta {
    color: #6b6b6b;
    font-size: .76rem;
}

.chat-message__capsule-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-top: 1px solid rgba(247, 162, 157, .35);
    color: #c75f5a;
    font-size: .82rem;
}

.chat-message__capsule-profile-head {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-message__capsule-profile-avatar {
    width: 58px;
    height: 58px;
    flex: 0 0 58px;
    border: 2px solid rgba(245, 125, 118, .65);
    border-radius: 50%;
    object-fit: cover;
}

.chat-message__capsule-profile-copy {
    display: flex;
    min-width: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
}

.chat-message__capsule-profile-copy .chat-message__capsule-kind {
    margin-bottom: 1px;
}

.chat-message__capsule-username {
    color: #6b6b6b;
    font-size: .8rem;
}

.chat-message__capsule-author-row {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-top: 5px;
    color: #565858;
    font-size: .78rem;
}

.chat-message__capsule-author-avatar {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-message__capsule-author-row strong {
    overflow: hidden;
    min-width: 0;
    color: #1c1c1e;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-message__capsule-reading-time {
    margin-left: auto;
    color: #6b6b6b;
    white-space: nowrap;
}

/* El chip de tipo va sobre la imagen del hero: necesita fondo opaco en claro. */
.chat-message__capsule-hero .chat-message__capsule-kind {
    background: rgba(250, 246, 227, 0.92);
}

@media (max-width: 600px) {
    .chat-message__capsule {
        width: min(78vw, 390px);
    }

    .chat__conversation-messages .message-bubble:has(.chat-message__capsule) {
        width: min(78vw, 390px);
        max-width: min(78vw, 390px);
    }
}

.dark .chat-message__capsule {
    background: #1f1f21f0;
    color: #f5f5f7;
    border-color: #414248;
}

.dark .chat-message--mine .chat-message__capsule {
    background: #1f1f21f0;
    color: #ffffff;
}

/* Modo oscuro: se conserva intacto el aspecto gris de la tarjeta. */
.dark .chat-message__capsule-kind {
    background: rgba(245, 125, 118, 0.17);
    color: #f58b91;
}

.dark .chat-message__capsule-hero .chat-message__capsule-kind {
    background: rgba(245, 125, 118, 0.17);
}

.dark .chat-message__capsule-title {
    color: #f5f5f6;
}

.dark .chat-message__capsule-description {
    color: #a9aab0;
}

.dark .chat-message__capsule-meta {
    color: #96979d;
}

.dark .chat-message__capsule-footer {
    border-top-color: #414248;
    color: #f58b91;
}

.dark .chat-message__capsule-username {
    color: #999aa1;
}

.dark .chat-message__capsule-author-row {
    color: #b8b9be;
}

.dark .chat-message__capsule-author-row strong {
    color: #c4c5c9;
}

.dark .chat-message__capsule-reading-time {
    color: #a0a1a7;
}
