/* ============================================
   WEBZILLA AI - WIDGET FLOTANTE DEL CHATBOT
   assets/css/chatbot-widget.css
   Personaje: MechaWebzilla
   Requiere: variables.css cargado antes de este archivo
   ============================================ */

/* ------------ Contenedor raíz (siempre fijo, en todas las páginas) ------------ */
#mecha-widget-root {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 999999;
    font-family: var(--fuente-base);
}

/* ------------ Globo de saludo (tooltip) ------------ */
.mecha-greeting-bubble {
    position: absolute;
    right: 4px;
    bottom: 168px;
    max-width: 240px;
    background: var(--blanco);
    color: var(--verde-oscuro);
    padding: 12px 16px;
    border-radius: 16px 16px 4px 16px;
    box-shadow: var(--sombra-suave);
    font-size: 14px;
    line-height: 1.4;
    opacity: 0;
    transform: translateY(10px) scale(0.9);
    pointer-events: none;
    transition: all 0.35s ease;
}
.mecha-greeting-bubble.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
.mecha-greeting-bubble .mecha-greeting-close {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    background: var(--gris-oscuro);
    color: var(--blanco);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    cursor: pointer;
    border: 2px solid var(--blanco);
}

/* ------------ Personaje flotante (estilo Asistente de Office / Clippy) ------------ */
.mecha-character-wrap {
    position: relative;
    width: 150px;
    max-width: 150px;
    cursor: pointer;
    filter: drop-shadow(0 12px 16px rgba(14, 33, 24, 0.38));
    animation: mecha-float 3.4s ease-in-out infinite;
    transform-origin: bottom center;
    background: transparent;
    border: none;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    display: block;
}
.mecha-character-wrap img {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    display: block;
    pointer-events: none;
    user-select: none;
}

@keyframes mecha-float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50%      { transform: translateY(-10px) rotate(-2deg); }
}

/* Animación de "hablando" (se activa al recibir/leer un mensaje del bot) */
.mecha-character-wrap.talking {
    animation: mecha-talk 0.32s ease-in-out infinite;
    filter:
        drop-shadow(0 12px 18px rgba(14, 33, 24, 0.38))
        drop-shadow(0 0 16px rgba(220, 53, 69, 0.55));
}
@keyframes mecha-talk {
    0%, 100% { transform: scale(1) rotate(-1.5deg); }
    50%      { transform: scale(1.045) rotate(1.5deg); }
}

/* Anillo de pulso alrededor del personaje (llama la atención cuando está cerrado) */
.mecha-character-wrap::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 6%;
    width: 60%;
    height: 14%;
    transform: translateX(-50%);
    background: radial-gradient(ellipse, rgba(241,220,164,0.55) 0%, transparent 70%);
    border-radius: 50%;
    opacity: 0;
    animation: mecha-glow-pulse 2.6s ease-in-out infinite;
}
#mecha-widget-root.open .mecha-character-wrap::after { display: none; }
@keyframes mecha-glow-pulse {
    0%, 100% { opacity: 0; transform: translateX(-50%) scale(0.85); }
    50%      { opacity: 1; transform: translateX(-50%) scale(1.15); }
}

/* Insignia de mensaje no leído (sobre el personaje) */
.mecha-badge {
    position: absolute;
    top: -2px;
    right: 4px;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    background: var(--error);
    color: var(--blanco);
    border-radius: 50%;
    font-size: 12.5px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--blanco);
    z-index: 2;
}
.mecha-badge.hidden { display: none; }

/* ------------ Ventana emergente del chat (estilo WhatsApp) ------------ */
.mecha-window {
    position: absolute;
    right: 0;
    bottom: 168px;
    width: 380px;
    height: 600px;
    max-height: 75vh;
    background: var(--gris-claro);
    border-radius: 18px;
    box-shadow: var(--sombra-suave);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.96);
    pointer-events: none;
    transform-origin: bottom right;
    transition: all 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}
#mecha-widget-root.open .mecha-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Encabezado tipo WhatsApp Business */
.mecha-header {
    background: linear-gradient(120deg, var(--verde-principal), var(--verde-oscuro));
    color: var(--blanco);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.mecha-header .mecha-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--dorado-acento);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    border: 2px solid var(--dorado-acento);
}
.mecha-header .mecha-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.mecha-header .mecha-info { flex: 1; min-width: 0; }
.mecha-header .mecha-name {
    font-weight: 700;
    font-size: 15px;
    line-height: 1.2;
}
.mecha-header .mecha-status {
    font-size: 12px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 5px;
}
.mecha-header .mecha-status-dot {
    width: 7px;
    height: 7px;
    background: var(--success);
    border-radius: 50%;
    display: inline-block;
}
.mecha-header .mecha-close-btn,
.mecha-header .mecha-minimize-btn {
    background: transparent;
    border: none;
    color: var(--blanco);
    font-size: 18px;
    cursor: pointer;
    padding: 6px;
    opacity: 0.85;
    line-height: 1;
}
.mecha-header .mecha-close-btn:hover,
.mecha-header .mecha-minimize-btn:hover { opacity: 1; }

/* Área de mensajes (fondo tipo WhatsApp con patrón sutil) */
.mecha-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background-color: #ECE5DD;
    background-image:
        radial-gradient(circle at 20px 20px, rgba(0,61,27,0.035) 2px, transparent 2px),
        radial-gradient(circle at 60px 60px, rgba(0,61,27,0.035) 2px, transparent 2px);
    background-size: 80px 80px;
}
.mecha-messages::-webkit-scrollbar { width: 6px; }
.mecha-messages::-webkit-scrollbar-thumb {
    background: rgba(14,33,24,0.25);
    border-radius: 10px;
}

/* Burbujas de mensaje */
.mecha-msg-row {
    display: flex;
    gap: 8px;
    max-width: 88%;
}
.mecha-msg-row.bot { align-self: flex-start; }
.mecha-msg-row.user { align-self: flex-end; flex-direction: row-reverse; }

.mecha-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--verde-principal);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.mecha-msg-avatar img { width: 100%; height: 100%; object-fit: cover; }

.mecha-bubble {
    padding: 9px 13px;
    border-radius: var(--radio-base);
    font-size: 14px;
    line-height: 1.45;
    box-shadow: 0 1px 2px rgba(0,0,0,0.12);
    position: relative;
    word-wrap: break-word;
    white-space: pre-line;
}
.mecha-msg-row.bot .mecha-bubble {
    background: var(--blanco);
    color: var(--gris-oscuro);
    border-bottom-left-radius: 4px;
}
.mecha-msg-row.user .mecha-bubble {
    background: #D9FDD3;
    color: var(--verde-oscuro);
    border-bottom-right-radius: 4px;
}
.mecha-bubble .mecha-time {
    display: block;
    font-size: 10px;
    color: var(--gris-medio);
    margin-top: 4px;
    text-align: right;
}

/* Botón de altavoz dentro de la burbuja del bot (definido también en voice-chatbot.css) */
.mecha-bubble .mecha-speaker-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 2px 4px;
    margin-left: 4px;
    opacity: 0.55;
    vertical-align: middle;
    display: inline-flex;
    align-items: center;
}
.mecha-bubble .mecha-speaker-btn svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: var(--verde-principal);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.mecha-bubble .mecha-speaker-btn:hover { opacity: 1; }
.mecha-bubble .mecha-speaker-btn.speaking { opacity: 1; }
.mecha-bubble .mecha-speaker-btn.speaking svg { stroke: var(--error); }

/* Botones de respuesta rápida */
.mecha-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-self: flex-start;
    max-width: 92%;
    margin-top: -2px;
}
.mecha-quick-btn {
    background: var(--blanco);
    border: 1.5px solid var(--verde-principal);
    color: var(--verde-principal);
    font-size: 12.5px;
    font-weight: 600;
    padding: 7px 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.mecha-quick-btn:hover {
    background: var(--verde-principal);
    color: var(--blanco);
}

/* Indicador "escribiendo..." */
.mecha-typing {
    align-self: flex-start;
    background: var(--blanco);
    padding: 10px 14px;
    border-radius: var(--radio-base);
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}
.mecha-typing span {
    width: 6px;
    height: 6px;
    background: var(--gris-medio);
    border-radius: 50%;
    animation: mecha-typing-bounce 1.1s infinite;
}
.mecha-typing span:nth-child(2) { animation-delay: 0.15s; }
.mecha-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes mecha-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ------------ Barra de entrada (input) ------------ */
.mecha-input-area {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--gris-claro);
    border-top: 1px solid #E2DED8;
}
.mecha-mic-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--dorado-acento);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.25s;
    position: relative;
}
.mecha-mic-btn svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: var(--verde-principal);
    stroke-width: 2.1;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.mecha-mic-btn:hover {
    background: var(--verde-principal);
    transform: scale(1.07);
}
.mecha-mic-btn:hover svg {
    stroke: var(--dorado-acento);
}
.mecha-mic-btn.recording {
    background: var(--error);
    animation: mecha-mic-pulse 1s infinite;
}
.mecha-mic-btn.recording svg {
    stroke: var(--blanco);
}
.mecha-mic-btn.recording::after {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid var(--error);
    animation: mecha-mic-ring 1.2s ease-out infinite;
}
@keyframes mecha-mic-ring {
    0%   { opacity: 0.9; transform: scale(0.9); }
    100% { opacity: 0; transform: scale(1.5); }
}
@keyframes mecha-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.45); }
    50% { box-shadow: 0 0 0 9px rgba(220, 53, 69, 0); }
}
.mecha-recording-label {
    font-size: 12px;
    color: var(--error);
    font-weight: 600;
    padding: 0 4px;
    white-space: nowrap;
    display: none;
    align-items: center;
    gap: 4px;
}
.mecha-recording-label.show { display: flex; }
.mecha-recording-label .mecha-rec-dot {
    width: 7px;
    height: 7px;
    background: var(--error);
    border-radius: 50%;
    animation: mecha-rec-dot-blink 1s infinite;
}
@keyframes mecha-rec-dot-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}

.mecha-input-area textarea {
    flex: 1;
    resize: none;
    border: none;
    border-radius: 22px;
    padding: 11px 16px;
    font-size: 14px;
    font-family: var(--fuente-base);
    max-height: 90px;
    background: var(--blanco);
    box-shadow: inset 0 0 0 1px #E2DED8;
    outline: none;
}
.mecha-input-area textarea:focus {
    box-shadow: inset 0 0 0 1.5px var(--verde-principal);
}
.mecha-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--verde-principal);
    color: var(--dorado-acento);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    flex-shrink: 0;
    transition: transform 0.15s;
}
.mecha-send-btn:hover { transform: scale(1.08); }
.mecha-send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* Pie de marca */
.mecha-footer-brand {
    text-align: center;
    font-size: 10.5px;
    color: var(--gris-medio);
    padding: 5px 0 8px;
    background: var(--gris-claro);
    flex-shrink: 0;
}
.mecha-footer-brand strong { color: var(--verde-principal); }

/* ------------ Responsive: pantalla completa en móvil ------------ */
@media (max-width: 480px) {
    #mecha-widget-root {
        right: 12px;
        bottom: 12px;
    }
    .mecha-character-wrap {
        width: 96px;
    }
    .mecha-window {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        bottom: 0;
        right: 0;
    }
    .mecha-greeting-bubble {
        right: 4px;
        bottom: 168px;
        max-width: calc(100vw - 100px);
    }
}
