/* =========================
PORTAL
========================= */

#whatsapp-portal {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 2147483647;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu;
}

/* =========================
BURBUJA FLOAT
========================= */

#whatsapp-bubble {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 62px;
    height: 62px;
    background: #25D366;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0,0,0,.28);
}

#whatsapp-bubble img {
    width: 50px;
    height: 50px;
}

/* =========================
CHAT WINDOW
========================= */

#whatsapp-modal {
    position: fixed;
    bottom: 96px;
    right: 20px;
    width: 360px;
    height: 560px;
    background: #E5DDD5;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    pointer-events: auto;
    overflow: hidden;
    box-shadow: 0 18px 40px rgba(0,0,0,.4);
}

.hidden {
    display: none !important;
}

/* =========================
HEADER (WhatsApp App)
========================= */

.whatsapp-header {
    background: #075E54;
    color: #fff;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.whatsapp-header span {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
}

.whatsapp-header img {
    width: 20px;
    height: 20px;
}

.whatsapp-header button {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    opacity: .85;
}

/* =========================
PHONE STEP
========================= */

.chat-step {
    padding: 18px;
    flex: 1;
}

.chat-intro {
    font-size: 14px;
    color: #303030;
    margin-bottom: 14px;
}

#chat-phone-input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid #ccc;
    font-size: 15px;
    margin-bottom: 14px;
}

.chat-start-btn {
    width: 100%;
    background: #25D366;
    color: #fff;
    padding: 12px;
    border-radius: 24px;
    border: none;
    font-weight: 600;
    cursor: pointer;
}

/* =========================
MESSAGES AREA
========================= */

#whatsapp-messages {
    flex: 1;
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    background: linear-gradient(rgba(229,221,213,.95), rgba(229,221,213,.95)),
    url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23d7cec7' fill-opacity='0.35'%3E%3Ccircle cx='50' cy='50' r='1'/%3E%3C/g%3E%3C/svg%3E");
}

/* =========================
MESSAGE BUBBLES
========================= */

.message {
    max-width: 78%;
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.message.in {
    background: #fff;
    align-self: flex-start;
    border-radius: 0 8px 8px 8px;
}

.message.out {
    background: #DCF8C6;
    align-self: flex-end;
    border-radius: 8px 0 8px 8px;
}

/* =========================
INPUT BAR
========================= */

.whatsapp-input {
    display: flex;
    gap: 8px;
    padding: 10px;
    background: #F0F0F0;
    border-top: 1px solid #ddd;
}

.whatsapp-input input {
    flex: 1;
    padding: 10px 14px;
    border-radius: 24px;
    border: 1px solid #ccc;
    font-size: 14px;
    outline: none;
}

.whatsapp-input button {
    background: #25D366;
    border: none;
    color: #fff;
    padding: 0 18px;
    border-radius: 24px;
    font-weight: 600;
    cursor: pointer;
}

/* =========================
MOBILE RESPONSIVE
========================= */

@media (max-width: 480px) {
    #whatsapp-modal {
        width: calc(100vw - 16px);
        height: 78vh;
        right: 8px;
        bottom: 88px;
    }
}

.chat-input {
    position: sticky;
    bottom: 0;
    z-index: 10;
}

/* =========================
FIX SCROLL + INPUT (NO DELETE)
========================= */

#chat-messages-step {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

#whatsapp-messages {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 12px;
}

.whatsapp-input {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    background: #F0F0F0;
    z-index: 20;
}

#whatsapp-modal {
    max-height: calc(100vh - 140px);
}

/* =========================
NEW: ALIGNMENT CLEANUP (SAFE ADD)
========================= */

/* Fuerza alineación correcta independientemente del orden DOM */
#whatsapp-messages .message.in {
    align-self: flex-start;
    text-align: left;
}

#whatsapp-messages .message.out {
    align-self: flex-end;
    text-align: left;
}

/* =========================
CHECKS (PALOMITAS)
========================= */

.message-text {
    white-space: pre-wrap;
  }
  
/* =========================
   META (HORA + PALOMITAS)
========================= */
.message-meta {
    font-size: 11px;
    margin-top: 4px;
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    color: #667781; /* gris WhatsApp */
  }
  
  /* =========================
     PALOMITAS
  ========================= */
  .message.out .message-meta {
    color: #999;
  }
  
  .message.out .status-read {
    color: #34b7f1; /* azul WhatsApp */
    font-weight: 600;
  }  
  
  .status-read {
    color: #34b7f1;
  }
  