/* ===============================
   RESET Y GLOBALS
   =============================== */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #e5ddd5;
    height: 100dvh; /* dynamic viewport height */
    overflow: auto;
    padding-bottom: env(safe-area-inset-bottom);
}

/* ===============================
   CHAT SHELL Y CONTENEDOR
   =============================== */
.chat-shell {
    width: 100%;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: stretch;
    background: #d1d7db;
}

.chat-container {
    width: 100%;
    max-width: 760px;
    height: 100dvh;
    background: #efeae2;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* ===============================
   HEADER ESTILO WHATSAPP
   =============================== */
.chat-header {
    height: 64px;
    background: #075e54; /* verde WhatsApp */
    color: #ffffff;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.chat-avatar {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.15);
}

.chat-avatar img {
    width: 42px;
    height: 42px;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

.chat-title-block {
    flex: 1;
    min-width: 0;
}

.chat-title {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-status {
    margin-top: 3px;
    font-size: 13px;
    color: rgba(255,255,255,0.9);
}

.chat-status.online {
    color: rgba(255,255,255,0.9);
}

/* ===============================
   CHAT BODY
   =============================== */
.chat-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 18px 12px;
    background-color: #fff2d8;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
    background-image:
        radial-gradient(circle at 42px 52px, rgba(255, 193, 7, 0.24) 0 28px, transparent 29px),
        radial-gradient(circle at 46px 92px, rgba(255, 193, 7, 0.16) 0 3px, transparent 4px),
        radial-gradient(circle at 220px 120px, rgba(0, 168, 132, 0.20) 0 34px, transparent 35px),
        radial-gradient(circle at 224px 166px, rgba(0, 168, 132, 0.14) 0 3px, transparent 4px),
        radial-gradient(circle at 390px 70px, rgba(233, 30, 99, 0.16) 0 24px, transparent 25px),
        radial-gradient(circle at 393px 105px, rgba(233, 30, 99, 0.12) 0 3px, transparent 4px),
        radial-gradient(circle at 130px 300px, rgba(33, 150, 243, 0.15) 0 30px, transparent 31px),
        radial-gradient(circle at 134px 342px, rgba(33, 150, 243, 0.10) 0 3px, transparent 4px),
        radial-gradient(circle at 80px 180px, rgba(255, 112, 67, 0.22) 0 3px, transparent 4px),
        radial-gradient(circle at 310px 250px, rgba(156, 39, 176, 0.16) 0 3px, transparent 4px),
        radial-gradient(circle at 460px 210px, rgba(0, 168, 132, 0.14) 0 3px, transparent 4px),
        radial-gradient(circle at 180px 430px, rgba(255, 193, 7, 0.20) 0 3px, transparent 4px),
        radial-gradient(circle at 410px 440px, rgba(233, 30, 99, 0.13) 0 3px, transparent 4px),
        linear-gradient(135deg, transparent 0 46%, rgba(255, 255, 255, 0.35) 47% 53%, transparent 54% 100%),
        linear-gradient(45deg, transparent 0 46%, rgba(255, 255, 255, 0.25) 47% 53%, transparent 54% 100%);
    background-size:
        520px 520px, 520px 520px, 620px 620px, 620px 620px, 560px 560px, 560px 560,
        650px 650px, 650px 650px, 220px 220px, 260px 260px, 300px 300px, 280px 280,
        340px 340px, 180px 180px, 220px 220px;
    background-position:
        0 0, 0 0, 40px 10px, 40px 10px, 20px 30px, 20px 30px,
        -10px 60px, -10px 60px, 0 0, 20px 30px, 10px 40px, 40px 20px,
        60px 50px, 0 0, 30px 50px;
}

/* ===============================
   DAY SEPARATOR
   =============================== */
.chat-day {
    text-align: center;
    margin: 8px 0 18px;
}

.chat-day span {
    display: inline-block;
    background: rgba(255,255,255,0.9);
    color: #667781;
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 8px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.05);
}

/* ===============================
   MENSAJES
   =============================== */
.message-row {
    display: flex;
    margin-bottom: 8px;
    width: 100%;
}

.message-row.user,
.message-row.cliente {
    justify-content: flex-end;
}

.message-row.bot,
.message-row.ia {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 78%;
    padding: 8px 9px 5px;
    border-radius: 8px;
    color: #111b21;
    font-size: 15px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
    position: relative;
    box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

.message-row.user .message-bubble,
.message-row.cliente .message-bubble {
    background: #d9fdd3;
    border-top-right-radius: 2px;
}

.message-row.bot .message-bubble,
.message-row.ia .message-bubble {
    background: #ffffff;
    border-top-left-radius: 2px;
}

.message-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    margin-top: 3px;
    padding-left: 28px;
    min-height: 14px;
}

.message-time {
    font-size: 11px;
    line-height: 12px;
    color: #667781;
    text-align: right;
}

.message-checks {
    position: relative;
    width: 16px;
    height: 10px;
    flex: 0 0 16px;
    margin-left: 1px;
    transform: translateY(0px);
}

.message-checks::before,
.message-checks::after {
    content: '';
    position: absolute;
    width: 4px;
    height: 8px;
    border-right: 1.7px solid #34b7f1;
    border-bottom: 1.7px solid #34b7f1;
    transform: rotate(45deg);
    border-radius: 0.5px;
}

.message-checks::before {
    left: 2px;
    top: 0;
}

.message-checks::after {
    left: 7px;
    top: 0;
}

.message-error {
    background: #ffe5e5 !important;
    color: #7a1c1c;
}

/* ===============================
   TYPING INDICATOR
   =============================== */
.typing-row {
    display: none;
    justify-content: flex-start;
    margin-bottom: 8px;
}

.typing-bubble {
    background: #ffffff;
    color: #667781;
    padding: 10px 14px;
    border-radius: 8px;
    border-top-left-radius: 2px;
    font-size: 14px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

.typing-dots span {
    display: inline-block;
    animation: blink 1.4s infinite both;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes blink {
    0% { opacity: 0.2; }
    20% { opacity: 1; }
    100% { opacity: 0.2; }
}

/* ===============================
   PANEL USUARIO Y FOOTER ESTILO WHATSAPP
   =============================== */
.chat-user-panel {
    background: #f0f2f5;
    border-top: 1px solid #d1d7db;
    padding: 12px 12px 0px 12px;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.chat-user-panel input {
    width: 50%;
    background: #ffffff;
    color: #111b21;
    border: 1px solid #d1d7db;
    border-radius: 21px;
    padding: 11px 14px;
    font-size: 15px;
    outline: none;
}

.chat-user-panel input:focus {
    border-color: #00a884;
}

.chat-footer {
    min-height: 62px;
    background: #f0f2f5;
    display: flex;
    align-items: flex-end;
    padding: 10px 12px;
    gap: 8px;
    flex-shrink: 0;
}

.message-input {
    flex: 1;
    min-height: 42px;
    max-height: 120px;
    resize: none;
    overflow-y: auto;
    background: #ffffff;
    color: #111b21;
    border: 1px solid #d1d7db;
    outline: none;
    border-radius: 21px;
    padding: 11px 14px;
    font-size: 15px;
    line-height: 1.35;
    font-family: inherit;
}

.message-input::placeholder,
.chat-user-panel input::placeholder {
    color: #667781;
}

.send-button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: #25d366;
    color: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.send-button:hover {
    opacity: 0.92;
}

.send-button:active {
    transform: scale(0.96);
}

.send-button:disabled {
    background: #9aa6ad;
    cursor: not-allowed;
    opacity: 0.75;
}

.send-button svg {
    width: 21px;
    height: 21px;
    fill: currentColor;
}

/* ===============================
   WELCOME CARD
   =============================== */
.welcome-card {
    max-width: 88%;
    margin: 10px auto 18px;
    background: rgba(255,255,255,0.92);
    color: #54656f;
    border-radius: 10px;
    padding: 14px 16px;
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
    box-shadow: 0 1px 1px rgba(0,0,0,0.06);
}

/* ===============================
   MOBILE ULTRA-GRANDE 3X FUENTES Y WHATSAPP HEADER/FOOTER
   =============================== */
@media (max-width: 680px) {

    /* Header estilo WhatsApp */
    .chat-header {
        height: 64px;
        background: #075e54;
        padding: 0 12px;
    }

    .chat-title {
        font-size: 22px;
    }

    .chat-status {
        font-size: 16px;
    }

    /* Día y welcome card */
    .chat-day span {
        font-size: 16px;
        padding: 10px 16px;
    }

    .welcome-card {
        font-size: 18px;
        line-height: 1.4;
        padding: 15px 15px;
    }

    /* Mensajes */
    .message-bubble {
        font-size: 22px;
        line-height: 1.5;
        padding: 18px 20px 14px;
        max-width: 95%;
    }

    .message-time {
        font-size: 16px;
    }

    .typing-bubble {
        font-size: 20px;
        padding: 15px 18px;
    }

    

   .chat-footer {
        flex-direction: row; /* mantener fila: input + botón */
        align-items: center; /* centrar verticalmente */
        padding: 6px 8px; /* menos padding arriba/abajo */
        gap: 6px;
        min-height: 50px; /* altura más reducida */
    }
    
   

    .message-input {
        flex: 1; /* ocupa todo el espacio disponible */
        min-height: 70px;
        max-height: 180px;
        font-size: 22px;
        padding: 18px 22px;
        border-radius: 28px;
        margin: 10px;
    }

    .send-button {
        width: 60px;
        height: 60px;
        flex-shrink: 0;
    }


    /* Ocultar campos opcionales */
    #nombre,
    #telefono {
        display: none;
    }

    /* Input de mensaje ocupa todo el ancho */
    .chat-user-panel {
        width: 100%;
        display: none;
    }

    /* ===============================
   Avatar más pequeño en móvil
   =============================== */
@media (max-width: 680px) {

    .chat-avatar {
        width: 34px;
        height: 34px;
        min-width: 34px;
        min-height: 34px;
    }

    .chat-avatar img {
        width: 34px;
        height: 34px;
    }

}
}