/* ============================================================
   chat.css - Estilos para chats en los cuentos
   Versión: 2.0 (limpiada y optimizada)
   ============================================================ */

/* ============================================================
   SISTEMA 1: CHAT ESTILO CÓMIC / RED SOCIAL
   Clases: .chat-container, .chat-question, .chat-answer
   ============================================================ */

.chat-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: 'Segoe UI', Arial, sans-serif;
}

/* ---- Diálogo pregunta (verde) ---- */
.chat-question {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 20px;
}

.chat-question .name {
    font-weight: bold;
    color: #2e7d32;
    font-size: 0.85rem;
    margin-bottom: 4px;
    padding-left: 4px;
}

.chat-question .bubble-comic {
    background: #2e7d32;
    color: white;
    padding: 12px 18px 12px 48px;
    border-radius: 12px 12px 12px 4px;
    border: 4px solid white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    max-width: 75%;
    position: relative;
}

.chat-question .bubble-comic::before {
    content: '';
    position: absolute;
    left: -12px;
    bottom: 8px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 10px 12px 10px 0;
    border-color: transparent #2e7d32 transparent transparent;
}

.chat-question .bubble-comic::after {
    content: '';
    position: absolute;
    left: -16px;
    bottom: 6px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 12px 14px 12px 0;
    border-color: transparent white transparent transparent;
    z-index: -1;
}

.chat-question .bubble-comic .icon-bg {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 35px;
    height: 35px;
    background-image: url('../img/icon-fung.png');
    background-size: contain;
    background-repeat: no-repeat;
    pointer-events: none;
    z-index: 1;
}

/* ---- Diálogo respuesta (gris) ---- */
.chat-answer {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin-bottom: 20px;
}

.chat-answer .name {
    font-weight: bold;
    color: #616161;
    font-size: 0.85rem;
    margin-bottom: 4px;
    padding-right: 4px;
}

.chat-answer .bubble-comic {
    background: #e0e0e0;
    color: #222;
    padding: 12px 18px 12px 48px;
    border-radius: 12px 12px 4px 12px;
    border: 4px solid white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    max-width: 75%;
    position: relative;
}

.chat-answer .bubble-comic::before {
    content: '';
    position: absolute;
    right: -12px;
    bottom: 8px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 10px 0 10px 12px;
    border-color: transparent transparent transparent #e0e0e0;
}

.chat-answer .bubble-comic::after {
    content: '';
    position: absolute;
    right: -16px;
    bottom: 6px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 12px 0 12px 14px;
    border-color: transparent transparent transparent white;
    z-index: -1;
}

.chat-answer .bubble-comic .icon-bg {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 30px;
    height: 32px;
    background-image: url('../img/icon-ico.png');
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 0.5;
    pointer-events: none;
    z-index: 1;
}

/* ---- Responsive Sistema 1 ---- */
@media (max-width: 768px) {
    .chat-container {
        padding: 12px;
    }
    .chat-question .bubble-comic,
    .chat-answer .bubble-comic {
        max-width: 85%;
        padding: 10px 14px 10px 38px;
        border-radius: 10px 10px 10px 4px;
    }
    .chat-answer .bubble-comic {
        border-radius: 10px 10px 4px 10px;
    }
    .chat-question .name,
    .chat-answer .name {
        font-size: 0.8rem;
    }
    .chat-question .bubble-comic .icon-bg {
        width: 28px;
        height: 28px;
        top: 6px;
        left: 6px;
    }
    .chat-answer .bubble-comic .icon-bg {
        width: 24px;
        height: 26px;
        top: 6px;
        left: 6px;
    }
    .chat-question .bubble-comic::before,
    .chat-answer .bubble-comic::before {
        border-width: 8px 10px 8px 0;
    }
    .chat-answer .bubble-comic::before {
        border-width: 8px 0 8px 10px;
    }
    .chat-question .bubble-comic::after,
    .chat-answer .bubble-comic::after {
        border-width: 10px 12px 10px 0;
    }
    .chat-answer .bubble-comic::after {
        border-width: 10px 0 10px 12px;
    }
}

@media (max-width: 480px) {
    .chat-container {
        padding: 8px;
    }
    .chat-question .bubble-comic,
    .chat-answer .bubble-comic {
        max-width: 92%;
        padding: 8px 10px 8px 32px;
        border-width: 3px;
        border-radius: 8px 8px 8px 3px;
        font-size: 0.9rem;
    }
    .chat-answer .bubble-comic {
        border-radius: 8px 8px 3px 8px;
    }
    .chat-question .name,
    .chat-answer .name {
        font-size: 0.7rem;
    }
    .chat-question .bubble-comic .icon-bg {
        width: 22px;
        height: 22px;
        top: 4px;
        left: 4px;
    }
    .chat-answer .bubble-comic .icon-bg {
        width: 18px;
        height: 20px;
        top: 4px;
        left: 4px;
    }
    .chat-question .bubble-comic::before,
    .chat-answer .bubble-comic::before {
        border-width: 6px 8px 6px 0;
    }
    .chat-answer .bubble-comic::before {
        border-width: 6px 0 6px 8px;
    }
    .chat-question .bubble-comic::after,
    .chat-answer .bubble-comic::after {
        border-width: 8px 10px 8px 0;
    }
    .chat-answer .bubble-comic::after {
        border-width: 8px 0 8px 10px;
    }
}


/* ============================================================
   SISTEMA 2: CHAT ESTILO WHATSAPP / TELEGRAM
   Clases: .chat-whatsapp, .msg-whatsapp, .own, .other
   ============================================================ */

.chat-whatsapp {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---- Estilo base para mensajes ---- */
.msg-whatsapp {
    display: flex;
    flex-direction: column;
    padding: 10px 14px;
    max-width: 85%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 1rem;
    line-height: 1.6;
    position: relative;
    border-radius: 18px;
    background-color: #ffffff;
}

/* Mensaje propio (derecha) */
.msg-whatsapp.own {
    align-self: flex-end;
    background-color: #dcf8c6;
    border-radius: 18px 18px 4px 18px;
    margin-left: auto;
    margin-right: 0;
}

/* Mensaje de otro (izquierda) */
.msg-whatsapp.other {
    align-self: flex-start;
    background-color: #e4e6eb;
    border-radius: 18px 18px 18px 4px;
    margin-right: auto;
    margin-left: 0;
}

/* ---- Header del mensaje (nombre + hora) ---- */
.msg-whatsapp .header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 8px;
    width: 100%;
    margin-bottom: 4px;
}

.msg-whatsapp .header .name {
    font-size: 0.75rem;
    font-weight: bold;
    color: #4a7a3a;
}

.msg-whatsapp .header .time {
    font-size: 0.65rem;
    color: #888;
}

.msg-whatsapp.other .header .name {
    color: #075e54;
}

/* ---- Texto del mensaje ---- */
.msg-whatsapp .text {
    display: block;
    width: 100%;
    font-size: 1rem;
    color: #1a1a1a;
    line-height: 1.5;
}

/* ---- Notas al pie (referencias) ---- */
.msg-whatsapp .text .nota-ref {
    color: #075e54;
    text-decoration: none;
    font-size: 0.7rem;
    vertical-align: super;
    font-weight: 600;
    margin: 0 1px;
    transition: color 0.2s;
}

.msg-whatsapp .text .nota-ref:hover {
    color: #128c7e;
    text-decoration: underline;
}

/* ---- Listas de definición dentro de mensajes ---- */
.msg-whatsapp .text dl {
    margin: 8px 0 4px 0;
    padding-left: 8px;
    border-left: 3px solid rgba(0, 0, 0, 0.1);
}

.msg-whatsapp .text dt {
    font-weight: bold;
    margin-top: 10px;
    color: #075e54;
}

.msg-whatsapp .text dd {
    margin-left: 16px;
    margin-bottom: 8px;
    color: #333;
}

.msg-whatsapp .text ol {
    margin: 6px 0 6px 20px;
    padding-left: 4px;
}

.msg-whatsapp .text ol li {
    margin-bottom: 4px;
    line-height: 1.5;
}

.msg-whatsapp .text strong {
    color: #075e54;
}

/* ---- Espaciado entre mensajes ---- */
.msg-whatsapp.other + .msg-whatsapp.other,
.msg-whatsapp.own + .msg-whatsapp.own {
    margin-top: 2px;
}

.msg-whatsapp.other + .msg-whatsapp.own,
.msg-whatsapp.own + .msg-whatsapp.other {
    margin-top: 8px;
}

/* ---- Responsive Sistema 2 ---- */
@media (max-width: 768px) {
    .chat-whatsapp {
        padding: 12px;
        gap: 5px;
    }
    .msg-whatsapp {
        max-width: 88%;
        padding: 8px 12px;
        font-size: 0.95rem;
        border-radius: 16px;
    }
    .msg-whatsapp.own {
        border-radius: 16px 16px 4px 16px;
    }
    .msg-whatsapp.other {
        border-radius: 16px 16px 16px 4px;
    }
    .msg-whatsapp .header .name {
        font-size: 0.7rem;
    }
    .msg-whatsapp .header .time {
        font-size: 0.6rem;
    }
    .msg-whatsapp .text {
        font-size: 0.95rem;
    }
    .msg-whatsapp .text .nota-ref {
        font-size: 0.6rem;
    }
}

@media (max-width: 480px) {
    .chat-whatsapp {
        padding: 8px;
        gap: 4px;
    }
    .msg-whatsapp {
        max-width: 92%;
        padding: 6px 10px;
        font-size: 0.9rem;
        border-radius: 14px;
    }
    .msg-whatsapp.own {
        border-radius: 14px 14px 3px 14px;
    }
    .msg-whatsapp.other {
        border-radius: 14px 14px 14px 3px;
    }
    .msg-whatsapp .header .name {
        font-size: 0.65rem;
    }
    .msg-whatsapp .header .time {
        font-size: 0.55rem;
    }
    .msg-whatsapp .text {
        font-size: 0.9rem;
        margin-top: 2px;
    }
    .msg-whatsapp .text .nota-ref {
        font-size: 0.55rem;
    }
}

@media (min-width: 1200px) {
    .chat-whatsapp {
        max-width: 800px;
        padding: 20px;
    }
    .msg-whatsapp {
        max-width: 70%;
        padding: 12px 18px;
        font-size: 1.05rem;
    }
    .msg-whatsapp .header .name {
        font-size: 0.8rem;
    }
    .msg-whatsapp .header .time {
        font-size: 0.7rem;
    }
    .msg-whatsapp .text {
        font-size: 1.05rem;
    }
}


/* ============================================================
   SISTEMA 3: BURBUJAS CON AVATARES
   Clases: .bubble-avatar, .avatar, .message, .even, .odd
   NOTA: Renombrado de .bubble a .bubble-avatar para evitar conflicto
   ============================================================ */

.bubble-avatar {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin: 12px 0;
    color: #fff;
}

.bubble-avatar .avatar {
    flex-shrink: 0;
    width: 47px;
    height: 47px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    background-color: #2a2a2a;
    border: 4px solid #fff;
    display: block;
    text-indent: -9999px;
    overflow: hidden;
}

.bubble-avatar .message {
    position: relative;
    padding: 10px 16px;
    background: #737373;
    border-radius: 16px 16px 16px 0;
    border: 6px solid #ffffff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    font-size: 0.95rem;
    line-height: 1.5;
    word-break: break-word;
    max-width: 80%;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.bubble-avatar .name {
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    opacity: 0.85;
    display: block;
    text-transform: uppercase;
}

.bubble-avatar .dialog-text {
    display: block;
    font-weight: 400;
}

/* ---- Variante even (avatar a la derecha) ---- */
.bubble-avatar.even {
    flex-direction: row-reverse;
}

.bubble-avatar.even .message {
    background: #7a5030;
    border-radius: 16px 16px 0 16px;
}

/* ---- Rabillo (triángulo) ---- */
.bubble-avatar .message::before,
.bubble-avatar .message::after {
    content: '';
    position: absolute;
    top: 16px;
    width: 0;
    height: 0;
    border: 10px solid transparent;
}

.bubble-avatar.odd .message::before {
    right: 100%;
    border-left: 0;
    margin-right: 4px;
}

.bubble-avatar.odd .message::after {
    right: calc(100% - 2px);
    border-right-color: #ffffff;
    border-left: 0;
    margin-right: 4px;
}

.bubble-avatar.even .message::before {
    left: 100%;
    border-right: 0;
    margin-left: 4px;
}

.bubble-avatar.even .message::after {
    left: calc(100% - 2px);
    border-left-color: #ffffff;
    border-right: 0;
    margin-left: 4px;
}

/* ---- Imágenes dentro de burbujas ---- */
.bubble-avatar .message img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 6px 0;
    border-radius: 8px;
    border: 2px solid rgba(255,255,255,0.15);
}

/* ---- Responsive Sistema 3 ---- */
@media (max-width: 768px) {
    .bubble-avatar {
        gap: 8px;
        margin: 8px 0;
    }
    .bubble-avatar .avatar {
        width: 38px;
        height: 38px;
        border-width: 3px;
    }
    .bubble-avatar .message {
        padding: 8px 12px;
        font-size: 0.9rem;
        border-width: 4px;
        max-width: 85%;
    }
    .bubble-avatar .name {
        font-size: 0.7rem;
    }
}

@media (max-width: 480px) {
    .bubble-avatar {
        gap: 6px;
        margin: 6px 0;
    }
    .bubble-avatar .avatar {
        width: 32px;
        height: 32px;
        border-width: 2px;
    }
    .bubble-avatar .message {
        padding: 6px 10px;
        font-size: 0.85rem;
        border-width: 3px;
        max-width: 90%;
        border-radius: 12px 12px 12px 0;
    }
    .bubble-avatar.even .message {
        border-radius: 12px 12px 0 12px;
    }
    .bubble-avatar .name {
        font-size: 0.65rem;
    }
}