/* ============================================
   GyG Comercial - Chat Widget Styles
   Con peek proactivo, quick replies, nudge,
   animaciones de entrada, scroll to bottom,
   mobile fullscreen, product cards mejorados
   ============================================ */

/* === Toggle Button === */
.gyg-chat-toggle {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0096D6 0%, #0047AB 100%);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    box-shadow: 0 4px 20px rgba(0, 71, 171, 0.4);
    z-index: 9998;
    transition: transform 0.3s, box-shadow 0.3s, opacity 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: gygChatPulse 2s ease-in-out infinite;
}
.gyg-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(0, 71, 171, 0.5);
    animation: none;
}
.gyg-chat-toggle.open { animation: none; }
.gyg-chat-toggle.gyg-chat-hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.5);
}

@keyframes gygChatPulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(0, 71, 171, 0.4); }
    50% { box-shadow: 0 4px 20px rgba(0, 71, 171, 0.4), 0 0 0 8px rgba(0, 150, 214, 0.2); }
}

/* Badge */
.gyg-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    background: #FF3B30;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid #f8f9fa;
}
.gyg-chat-badge.visible { display: flex; }

/* === Chat Window === */
.gyg-chat-window {
    position: fixed;
    bottom: 100px;
    right: 25px;
    width: 380px;
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #f8f9fa;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
                transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.gyg-chat-window.gyg-chat-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
.gyg-chat-header {
    background: linear-gradient(135deg, #0047AB 0%, #0096D6 100%);
    color: white;
    padding: 15px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.gyg-chat-header-info { display: flex; align-items: center; gap: 12px; }
.gyg-chat-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
}
.gyg-chat-header-name { font-weight: 700; font-size: 0.95rem; }
.gyg-chat-header-status { font-size: 0.75rem; opacity: 0.85; display: flex; align-items: center; gap: 5px; }
.gyg-chat-close {
    background: rgba(255,255,255,0.15); border: none; color: white;
    cursor: pointer; padding: 8px; border-radius: 8px; font-size: 0.9rem;
    transition: background 0.2s;
}
.gyg-chat-close:hover { background: rgba(255,255,255,0.3); }

/* Online dot */
.gyg-chat-online-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #22c55e; display: inline-block; flex-shrink: 0;
    animation: gygOnlinePulse 2s ease-in-out infinite;
}
@keyframes gygOnlinePulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* System message */
.gyg-chat-system-msg {
    align-self: center;
    font-size: 11px; color: #888;
    background: #eee; border: 1px solid #ddd;
    padding: 4px 12px; border-radius: 12px;
    display: flex; align-items: center; gap: 6px;
    animation: gygMsgFade 0.4s ease;
}

/* Messages area */
.gyg-chat-messages {
    flex: 1; overflow-y: auto; padding: 15px;
    display: flex; flex-direction: column; gap: 10px;
    scroll-behavior: smooth;
    position: relative;
}
.gyg-chat-messages::-webkit-scrollbar { width: 5px; }
.gyg-chat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 5px; }

/* Message bubbles */
.gyg-chat-msg {
    max-width: 85%; padding: 10px 14px; border-radius: 14px;
    font-size: 0.9rem; line-height: 1.5; word-wrap: break-word;
}

/* Animacion de entrada desde la izquierda (bot) */
.gyg-chat-slide-left {
    animation: gygSlideLeft 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}
@keyframes gygSlideLeft {
    from { opacity: 0; transform: translateX(-16px) translateY(4px); }
    to { opacity: 1; transform: translateX(0) translateY(0); }
}

/* Animacion de entrada desde la derecha (usuario) */
.gyg-chat-slide-right {
    animation: gygSlideRight 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}
@keyframes gygSlideRight {
    from { opacity: 0; transform: translateX(16px) translateY(4px); }
    to { opacity: 1; transform: translateX(0) translateY(0); }
}

/* Animacion generica fade-in */
@keyframes gygMsgFade {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.gyg-chat-msg-user {
    align-self: flex-end;
    background: #0047AB; color: white; border-bottom-right-radius: 4px;
}
.gyg-chat-msg-bot {
    align-self: flex-start;
    background: white; color: #333; border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.gyg-chat-msg-time {
    font-size: 10px; opacity: 0.6; margin-top: 2px; display: block;
}
.gyg-chat-msg-user .gyg-chat-msg-time { text-align: right; }

/* Typing indicator */
.gyg-chat-typing {
    align-self: flex-start;
    padding: 10px 16px; background: white; border-radius: 14px;
    border-bottom-left-radius: 4px;
    display: none; gap: 5px; align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.gyg-chat-typing.visible { display: flex; }
.gyg-chat-typing span {
    width: 7px; height: 7px; border-radius: 50%; background: #aaa;
    animation: gygTypingBounce 1.4s ease-in-out infinite;
}
.gyg-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.gyg-chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes gygTypingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* === Product cards inside chat (mejorado) === */
.gyg-chat-product {
    display: flex; align-items: center; justify-content: space-between;
    background: linear-gradient(135deg, #f0f7ff 0%, #e8f2fd 100%);
    border: 1px solid #d0e3f7; border-radius: 12px;
    padding: 12px 14px; margin: 8px 0; gap: 12px;
    box-shadow: 0 2px 8px rgba(0, 71, 171, 0.08);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.gyg-chat-product:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(0, 71, 171, 0.15);
}
.gyg-chat-product-info { flex: 1; min-width: 0; }
.gyg-chat-product-name {
    font-weight: 600; font-size: 0.85rem; color: #0047AB;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    line-height: 1.3;
}
.gyg-chat-product-price {
    font-size: 0.82rem; color: #28a745; font-weight: 700; margin-top: 4px;
    letter-spacing: 0.02em;
}
.gyg-chat-product-btn {
    background: linear-gradient(135deg, #0096D6 0%, #0077b6 100%);
    color: white; border: none; padding: 8px 16px;
    border-radius: 8px; font-size: 0.8rem; font-weight: 600; cursor: pointer;
    text-decoration: none; white-space: nowrap;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    display: inline-flex; align-items: center; gap: 6px;
    box-shadow: 0 2px 6px rgba(0, 150, 214, 0.3);
}
.gyg-chat-product-btn:hover {
    background: linear-gradient(135deg, #0077b6 0%, #005f8d 100%);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 150, 214, 0.4);
}
.gyg-chat-product-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(0, 150, 214, 0.3);
}

/* === Quick Replies === */
.gyg-chat-quick-replies {
    display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0;
    animation: gygMsgFade 0.3s ease;
}
.gyg-chat-qr-btn {
    background: transparent; border: 1.5px solid #0096D6; color: #0096D6;
    border-radius: 16px; padding: 6px 14px; font-size: 12px;
    font-family: 'Inter', sans-serif; font-weight: 500; cursor: pointer;
    transition: background 0.2s, color 0.2s, transform 0.15s, opacity 0.2s;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}
.gyg-chat-qr-btn:hover {
    background: #0096D6; color: white; transform: scale(1.04);
}
.gyg-chat-qr-btn:active,
.gyg-chat-qr-btn.gyg-chat-qr-selected {
    transform: scale(0.93);
    background: #0047AB; color: white; border-color: #0047AB;
}
.gyg-chat-qr-btn:disabled,
.gyg-chat-qr-btn.gyg-chat-qr-pressed {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* === Scroll to Bottom Button === */
.gyg-chat-scroll-bottom {
    position: absolute;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: white;
    color: #0047AB;
    border: 1px solid #ddd;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease, box-shadow 0.2s;
}
.gyg-chat-scroll-bottom.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}
.gyg-chat-scroll-bottom:hover {
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
    background: #f0f7ff;
}

/* === Loading overlay (restauracion de conversacion) === */
.gyg-chat-loading-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px 20px;
    gap: 12px;
    animation: gygMsgFade 0.3s ease;
}
.gyg-chat-loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #e0e0e0;
    border-top-color: #0096D6;
    border-radius: 50%;
    animation: gygSpin 0.7s linear infinite;
}
@keyframes gygSpin {
    to { transform: rotate(360deg); }
}
.gyg-chat-loading-text {
    font-size: 12px;
    color: #888;
    font-weight: 500;
}

/* === Peek Proactivo === */
.gyg-chat-peek {
    position: fixed; bottom: 100px; right: 25px;
    background: white; color: #333; border: 1px solid #0096D6;
    border-radius: 14px; box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    z-index: 9997; cursor: pointer; max-width: 320px; min-width: 200px;
    opacity: 0; transform: translateY(10px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}
.gyg-chat-peek.visible { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.gyg-chat-peek::after {
    content: ''; position: absolute; bottom: -8px; right: 22px;
    width: 14px; height: 14px; background: white;
    border-right: 1px solid #0096D6; border-bottom: 1px solid #0096D6;
    transform: rotate(45deg);
}
.gyg-chat-peek-typing {
    display: flex; gap: 4px; align-items: center; padding: 14px 20px;
}
.gyg-chat-peek-typing span {
    width: 8px; height: 8px; border-radius: 50%; background: #aaa;
    animation: gygTypingBounce 1.4s ease-in-out infinite;
}
.gyg-chat-peek-typing span:nth-child(2) { animation-delay: 0.2s; }
.gyg-chat-peek-typing span:nth-child(3) { animation-delay: 0.4s; }
.gyg-chat-peek-content {
    display: flex; align-items: flex-start; gap: 10px; padding: 14px 16px;
}
.gyg-chat-peek-dot { width: 10px; height: 10px; border-radius: 50%; background: #22c55e; flex-shrink: 0; margin-top: 4px; }
.gyg-chat-peek-text { font-size: 13px; font-weight: 500; line-height: 1.45; flex: 1; }
.gyg-chat-peek-close {
    background: none; border: none; color: #999; font-size: 20px;
    cursor: pointer; padding: 0; line-height: 1; flex-shrink: 0;
}
.gyg-chat-peek-close:hover { color: #333; }

/* === Nudge wobble === */
@keyframes gygChatNudge {
    0%, 100% { transform: rotate(0deg); }
    15% { transform: rotate(-12deg); }
    30% { transform: rotate(10deg); }
    45% { transform: rotate(-8deg); }
    60% { transform: rotate(5deg); }
    75% { transform: rotate(-2deg); }
}
.gyg-chat-nudge { animation: gygChatNudge 0.6s ease-in-out !important; }

/* Glow */
.gyg-chat-glow {
    animation: gygChatGlow 2s ease-in-out infinite !important;
}
@keyframes gygChatGlow {
    0%, 100% { box-shadow: 0 4px 20px rgba(0, 71, 171, 0.4); }
    50% { box-shadow: 0 4px 20px rgba(0, 71, 171, 0.4), 0 0 20px #0096D6, 0 0 40px rgba(0, 150, 214, 0.3); }
}

/* Input area */
.gyg-chat-input-area {
    display: flex; padding: 12px; background: white;
    border-top: 1px solid #eee; gap: 8px; flex-shrink: 0;
}
.gyg-chat-input {
    flex: 1; padding: 10px 14px; border: 1px solid #ddd; border-radius: 25px;
    font-size: 0.9rem; outline: none; font-family: inherit; transition: border-color 0.2s;
}
.gyg-chat-input:focus { border-color: #0096D6; }
.gyg-chat-send {
    width: 42px; height: 42px; border-radius: 50%;
    background: #0096D6; color: white; border: none; cursor: pointer;
    font-size: 0.95rem; display: flex; align-items: center; justify-content: center;
    transition: background 0.2s, transform 0.15s; flex-shrink: 0;
}
.gyg-chat-send:hover { background: #0047AB; }
.gyg-chat-send:active { transform: scale(0.92); }
.gyg-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* === Responsive - Mobile === */
@media (max-width: 480px) {
    .gyg-chat-window {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        max-height: none;
        transition: opacity 0.3s ease,
                    transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    }
    .gyg-chat-window:not(.gyg-chat-open) {
        transform: translateY(100%) scale(1);
        opacity: 0;
    }
    .gyg-chat-window.gyg-chat-open {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    .gyg-chat-toggle {
        bottom: 15px; right: 15px; width: 52px; height: 52px; font-size: 1.3rem;
    }
    .gyg-chat-peek { right: 12px; bottom: 80px; max-width: calc(100vw - 24px); }
    .gyg-chat-qr-btn { font-size: 11px; padding: 5px 10px; }
    .gyg-chat-scroll-bottom { bottom: 65px; }
    .gyg-chat-input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
    .gyg-chat-messages {
        padding: 12px;
    }
    .gyg-chat-product {
        padding: 10px 12px;
    }
    .gyg-chat-product-btn {
        padding: 7px 12px;
        font-size: 0.78rem;
    }
}
