/* ============================================================
   CREAMY V2 — Widget (namespace: #creamy-v2)
   Laboratorio Genus — native premium assistant
   ============================================================ */

#creamy-v2 {
    --cv2-primary: #169ab0;
    --cv2-primary-dark: #0e7a8c;
    --cv2-primary-light: #dff0f5;
    --cv2-navy: #07172f;
    --cv2-text: #2c3e50;
    --cv2-text-muted: #5a6c7d;
    --cv2-white: #ffffff;
    --cv2-gray-50: #f8fafb;
    --cv2-gray-100: #f0f4f6;
    --cv2-gray-200: #e4eaed;
    --cv2-green: #22c55e;
    --cv2-shadow: rgba(7, 23, 47, 0.12);
    --cv2-shadow-lg: rgba(7, 23, 47, 0.2);
    --cv2-z: 99999;
    --cv2-font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --cv2-radius: 20px;
    position: fixed;
    inset: 0;
    width: 0;
    height: 0;
    overflow: visible;
    pointer-events: none;
    z-index: var(--cv2-z);
}

#creamy-v2,
#creamy-v2 * {
    box-sizing: border-box;
}

#creamy-v2 button,
#creamy-v2 textarea,
#creamy-v2 a {
    font: inherit;
}

/* ── Keyframes (micro-animaciones) ── */
@keyframes cv2-breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.025); }
}

@keyframes cv2-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

@keyframes cv2-fab-in {
    from { opacity: 0; transform: translateY(20px) scale(0.88); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes cv2-tilt {
    0%, 100% { transform: rotate(0deg); }
    30% { transform: rotate(-4deg); }
    70% { transform: rotate(3deg); }
}

@keyframes cv2-greeting-in {
    from { opacity: 0; transform: translateY(8px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes cv2-window-in {
    from { opacity: 0; transform: translateY(14px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes cv2-msg-in {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes cv2-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

@keyframes cv2-pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.88); }
}

@keyframes cv2-blink {
    0%, 92%, 100% { opacity: 1; }
    96% { opacity: 0.15; }
}

/* ── Utilities ── */
#creamy-v2 .cv2-hidden {
    display: none !important;
}

/* ── Backdrop (mobile) ── */
#creamy-v2 .cv2-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(7, 23, 47, 0.38);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: calc(var(--cv2-z) + 1);
}

/* ── FAB ── */
#creamy-v2 .cv2-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: calc(var(--cv2-z) + 3);
    width: 72px;
    height: 72px;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--cv2-primary), var(--cv2-primary-dark));
    box-shadow:
        0 6px 20px rgba(22, 154, 176, 0.28),
        0 2px 8px rgba(7, 23, 47, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    pointer-events: auto;
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    animation: cv2-fab-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.8s both;
    transition: box-shadow 0.25s ease, transform 0.25s ease;
    -webkit-tap-highlight-color: transparent;
}

#creamy-v2 .cv2-fab:hover {
    transform: scale(1.04) translateY(-2px);
    box-shadow:
        0 10px 28px rgba(22, 154, 176, 0.32),
        0 4px 12px rgba(7, 23, 47, 0.1);
}

#creamy-v2 .cv2-fab--hidden {
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    transform: scale(0.85) translateY(12px) !important;
}

#creamy-v2 .cv2-fab--tilt .cv2-fab-avatar {
    animation: cv2-tilt 0.6s ease-in-out;
}

#creamy-v2 .cv2-fab-avatar {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--cv2-white);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    animation: cv2-breathe 4.5s ease-in-out infinite, cv2-float 6s ease-in-out 2s infinite;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.6);
}

#creamy-v2 .cv2-fab-avatar svg {
    width: 44px;
    height: 44px;
    display: block;
}

#creamy-v2 .cv2-fab-avatar .cv2-eye {
    animation: cv2-blink 5s ease-in-out infinite;
}

#creamy-v2 .cv2-fab-badge {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--cv2-green);
    border: 2.5px solid var(--cv2-white);
    animation: cv2-pulse-dot 2.8s ease-in-out infinite;
}

#creamy-v2 .cv2-fab-tooltip {
    position: absolute;
    top: 50%;
    right: calc(100% + 14px);
    transform: translateY(-50%) translateX(8px);
    padding: 9px 16px;
    border-radius: 12px;
    background: var(--cv2-white);
    color: var(--cv2-navy);
    font-family: var(--cv2-font);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 6px 20px var(--cv2-shadow);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease;
}

#creamy-v2 .cv2-fab-tooltip::after {
    content: '';
    position: absolute;
    top: 50%;
    right: -5px;
    width: 10px;
    height: 10px;
    background: var(--cv2-white);
    transform: translateY(-50%) rotate(45deg);
}

#creamy-v2 .cv2-fab:hover .cv2-fab-tooltip {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

/* ── Greeting bubble ── */
#creamy-v2 .cv2-greeting {
    position: fixed;
    bottom: 108px;
    right: 24px;
    z-index: calc(var(--cv2-z) + 2);
    max-width: 280px;
    padding: 14px 18px;
    border-radius: 16px 16px 4px 16px;
    background: var(--cv2-white);
    color: var(--cv2-text);
    font-family: var(--cv2-font);
    font-size: 13.5px;
    line-height: 1.5;
    box-shadow: 0 10px 36px var(--cv2-shadow-lg);
    border: 1px solid rgba(22, 154, 176, 0.12);
    cursor: pointer;
    pointer-events: none;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.35s ease, transform 0.35s ease;
}

#creamy-v2 .cv2-greeting--visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
    animation: cv2-greeting-in 0.4s ease-out;
}

/* ── Window ── */
#creamy-v2 .cv2-window {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: calc(var(--cv2-z) + 2);
    width: 390px;
    max-width: calc(100vw - 40px);
    height: 580px;
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    border-radius: var(--cv2-radius);
    background: var(--cv2-white);
    box-shadow:
        0 12px 40px rgba(7, 23, 47, 0.12),
        0 4px 14px rgba(7, 23, 47, 0.06);
    overflow: hidden;
    pointer-events: auto;
    font-family: var(--cv2-font);
    font-size: 14px;
    color: var(--cv2-text);
    transform-origin: bottom right;
    animation: cv2-window-in 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ── Header ── */
#creamy-v2 .cv2-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px;
    background: linear-gradient(135deg, var(--cv2-primary), var(--cv2-primary-dark));
    border-radius: var(--cv2-radius) var(--cv2-radius) 0 0;
}

#creamy-v2 .cv2-header-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.4);
}

#creamy-v2 .cv2-header-avatar svg {
    width: 30px;
    height: 30px;
}

#creamy-v2 .cv2-header-info {
    flex: 1;
    min-width: 0;
}

#creamy-v2 .cv2-header-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--cv2-white);
    line-height: 1.25;
}

#creamy-v2 .cv2-header-subtitle {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.85);
    margin-top: 2px;
    line-height: 1.3;
}

#creamy-v2 .cv2-header-status {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 4px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.9);
}

#creamy-v2 .cv2-header-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--cv2-green);
}

#creamy-v2 .cv2-header-actions {
    display: flex;
    gap: 6px;
}

#creamy-v2 .cv2-header-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    color: var(--cv2-white);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

#creamy-v2 .cv2-header-btn:hover {
    background: rgba(255, 255, 255, 0.32);
}

/* ── Chat body (messages + input) ── */
#creamy-v2 .cv2-chat-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

@keyframes cv2-onboard-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Onboard (bienvenida premium) ── */
#creamy-v2 .cv2-onboard {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 28px 24px 24px;
    background: var(--cv2-white);
}

#creamy-v2 .cv2-onboard--visible .cv2-onboard-inner {
    animation: cv2-onboard-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

#creamy-v2 .cv2-onboard-inner {
    max-width: 300px;
    margin: 0 auto;
    text-align: center;
}

#creamy-v2 .cv2-onboard-avatar {
    width: 96px;
    height: 96px;
    margin: 0 auto 24px;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--cv2-primary-light), #fff);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(22, 154, 176, 0.18);
    box-shadow: 0 8px 24px rgba(22, 154, 176, 0.1);
}

#creamy-v2 .cv2-onboard-avatar svg {
    width: 64px;
    height: 64px;
}

#creamy-v2 .cv2-onboard-title {
    margin: 0 0 16px;
    font-size: 26px;
    font-weight: 700;
    color: var(--cv2-navy);
    letter-spacing: -0.03em;
}

#creamy-v2 .cv2-onboard-lead {
    margin: 0 0 12px;
    font-size: 15px;
    line-height: 1.55;
    color: var(--cv2-text);
}

#creamy-v2 .cv2-onboard-lead strong {
    color: var(--cv2-primary-dark);
    font-weight: 600;
}

#creamy-v2 .cv2-onboard-text {
    margin: 0 0 28px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--cv2-text-muted);
}

#creamy-v2 .cv2-onboard-ask {
    margin: 0 0 20px;
    font-size: 15px;
    line-height: 1.5;
    font-weight: 600;
    color: var(--cv2-navy);
}

#creamy-v2 .cv2-onboard-form {
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

#creamy-v2 .cv2-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#creamy-v2 .cv2-field-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--cv2-text-muted);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

#creamy-v2 .cv2-field-input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--cv2-gray-200);
    border-radius: 14px;
    background: var(--cv2-gray-50);
    color: var(--cv2-text);
    font-size: 16px;
    line-height: 1.3;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    outline: none;
}

#creamy-v2 .cv2-field-input::placeholder {
    color: #a8b4be;
}

#creamy-v2 .cv2-field-input:focus {
    border-color: var(--cv2-primary);
    background: var(--cv2-white);
    box-shadow: 0 0 0 4px rgba(22, 154, 176, 0.12);
}

#creamy-v2 .cv2-onboard-error {
    margin: 0;
    font-size: 13px;
    color: #dc2626;
    text-align: center;
    line-height: 1.4;
}

#creamy-v2 .cv2-onboard-btn {
    margin-top: 8px;
    width: 100%;
    padding: 16px 20px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--cv2-primary), var(--cv2-primary-dark));
    color: var(--cv2-white);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 0.01em;
    box-shadow: 0 6px 18px rgba(22, 154, 176, 0.24);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#creamy-v2 .cv2-onboard-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(22, 154, 176, 0.28);
}

#creamy-v2 .cv2-onboard-btn:active {
    transform: translateY(0);
}

/* ── Messages ── */
#creamy-v2 .cv2-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 18px 18px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--cv2-gray-50);
    scroll-behavior: smooth;
}

#creamy-v2 .cv2-message {
    display: flex;
    flex-direction: column;
    max-width: 88%;
    animation: cv2-msg-in 0.22s ease-out;
}

#creamy-v2 .cv2-message--user {
    align-self: flex-end;
    align-items: flex-end;
}

#creamy-v2 .cv2-message--bot {
    align-self: flex-start;
}

#creamy-v2 .cv2-bubble {
    padding: 11px 15px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
}

#creamy-v2 .cv2-message--user .cv2-bubble {
    background: var(--cv2-primary);
    color: var(--cv2-white);
    border-radius: 18px 18px 4px 18px;
    box-shadow: 0 2px 8px rgba(22, 154, 176, 0.25);
}

#creamy-v2 .cv2-message--bot .cv2-bubble {
    background: var(--cv2-white);
    color: var(--cv2-text);
    border-radius: 4px 18px 18px 18px;
    border: 1px solid var(--cv2-gray-200);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

#creamy-v2 .cv2-bubble strong {
    font-weight: 600;
}

#creamy-v2 .cv2-bubble ul {
    margin: 8px 0 0;
    padding-left: 18px;
}

#creamy-v2 .cv2-bubble li {
    margin: 4px 0;
}

/* ── Typing ── */
#creamy-v2 .cv2-typing {
    display: flex;
    gap: 5px;
    align-self: flex-start;
    padding: 12px 16px;
    background: var(--cv2-white);
    border: 1px solid var(--cv2-gray-200);
    border-radius: 4px 18px 18px 18px;
}

#creamy-v2 .cv2-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--cv2-primary);
    animation: cv2-typing 1.2s ease-in-out infinite;
}

#creamy-v2 .cv2-typing-dot:nth-child(2) { animation-delay: 0.15s; }
#creamy-v2 .cv2-typing-dot:nth-child(3) { animation-delay: 0.3s; }

/* ── Action buttons ── */
#creamy-v2 .cv2-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
    width: 100%;
}

#creamy-v2 .cv2-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.18s ease;
    border: 1.5px solid transparent;
}

#creamy-v2 .cv2-action-btn--primary {
    background: var(--cv2-primary);
    color: var(--cv2-white);
}

#creamy-v2 .cv2-action-btn--primary:hover {
    background: var(--cv2-primary-dark);
}

#creamy-v2 .cv2-action-btn--secondary {
    background: transparent;
    color: var(--cv2-primary);
    border-color: var(--cv2-primary);
}

#creamy-v2 .cv2-action-btn--secondary:hover {
    background: var(--cv2-primary-light);
}

#creamy-v2 .cv2-action-btn--whatsapp {
    background: #25d366;
    color: #fff;
}

#creamy-v2 .cv2-action-btn--whatsapp:hover {
    background: #1da851;
}

/* ── Input ── */
#creamy-v2 .cv2-input-area {
    flex-shrink: 0;
    padding: 12px 14px 10px;
    border-top: 1px solid var(--cv2-gray-200);
    background: var(--cv2-white);
}

#creamy-v2 .cv2-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 6px 6px 6px 16px;
    border-radius: 24px;
    background: var(--cv2-gray-100);
    border: 1.5px solid transparent;
    transition: border-color 0.2s ease, background 0.2s ease;
}

#creamy-v2 .cv2-input-row:focus-within {
    border-color: var(--cv2-primary);
    background: var(--cv2-white);
}

#creamy-v2 .cv2-textarea {
    flex: 1;
    min-width: 0;
    min-height: 22px;
    max-height: 80px;
    border: none;
    outline: none;
    background: transparent;
    resize: none;
    font-family: var(--cv2-font);
    font-size: 13.5px;
    line-height: 1.5;
    color: var(--cv2-text);
    padding: 4px 0;
}

#creamy-v2 .cv2-textarea::placeholder {
    color: var(--cv2-text-muted);
}

#creamy-v2 .cv2-send-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border: none;
    border-radius: 50%;
    background: var(--cv2-primary);
    color: var(--cv2-white);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

#creamy-v2 .cv2-send-btn:hover {
    background: var(--cv2-primary-dark);
    transform: scale(1.03);
    box-shadow: 0 4px 12px rgba(22, 154, 176, 0.22);
}

#creamy-v2 .cv2-send-btn:disabled {
    background: var(--cv2-gray-200);
    cursor: not-allowed;
    transform: none;
}

/* ── Footer ── */
#creamy-v2 .cv2-footer {
    padding: 4px 12px 10px;
    text-align: center;
    font-size: 10px;
    color: var(--cv2-text-muted);
    background: var(--cv2-white);
}

/* ── Focus ── */
#creamy-v2 .cv2-fab:focus-visible,
#creamy-v2 .cv2-send-btn:focus-visible,
#creamy-v2 .cv2-header-btn:focus-visible {
    outline: 2px solid var(--cv2-primary);
    outline-offset: 2px;
}

/* ── Mobile ── */
@media (max-width: 768px) {
    #creamy-v2 .cv2-backdrop {
        display: block;
    }

    #creamy-v2.creamy-v2--open .cv2-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    #creamy-v2 .cv2-fab {
        bottom: 20px;
        right: 20px;
        width: 64px;
        height: 64px;
    }

    #creamy-v2 .cv2-fab-avatar {
        width: 52px;
        height: 52px;
    }

    #creamy-v2 .cv2-fab-tooltip {
        display: none;
    }

    #creamy-v2 .cv2-greeting {
        bottom: 96px;
        right: 20px;
        max-width: calc(100vw - 100px);
    }

    #creamy-v2 .cv2-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 85vh;
        max-height: 85vh;
        border-radius: 20px 20px 0 0;
    }

    #creamy-v2 .cv2-header {
        border-radius: 20px 20px 0 0;
    }
}

@media (min-width: 769px) {
    #creamy-v2 .cv2-window:not(.cv2-hidden) {
        width: 390px !important;
        max-width: 390px !important;
        left: auto !important;
        right: 24px !important;
        bottom: 24px !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    #creamy-v2 .cv2-fab,
    #creamy-v2 .cv2-fab-avatar,
    #creamy-v2 .cv2-fab-badge,
    #creamy-v2 .cv2-fab-avatar .cv2-eye {
        animation: none !important;
    }
}
