/**
 * WP Smart Chatbot - Estilos
 * Diseño moderno, accesible y responsive
 */

/* Variables CSS - se sobreescriben dinámicamente desde PHP */
:root {
    --wpsc-primary: #0073aa;
    --wpsc-secondary: #005177;
    --wpsc-text: #1a1a1a;
    --wpsc-text-light: #6b7280;
    --wpsc-bg: #ffffff;
    --wpsc-bg-alt: #f9fafb;
    --wpsc-border: #e5e7eb;
    --wpsc-success: #10b981;
    --wpsc-error: #ef4444;
    --wpsc-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --wpsc-shadow-md: 0 4px 20px rgba(0, 0, 0, 0.12);
    --wpsc-shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.15);
    --wpsc-radius: 16px;
    --wpsc-radius-sm: 10px;
    --wpsc-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

/* Wrapper principal */
#wpsc-chatbot-wrapper {
    position: fixed;
    z-index: 999999;
    font-family: var(--wpsc-font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--wpsc-text);
}

#wpsc-chatbot-wrapper *,
#wpsc-chatbot-wrapper *::before,
#wpsc-chatbot-wrapper *::after {
    box-sizing: border-box;
}

/* Posiciones */
.wpsc-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.wpsc-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Botón flotante para abrir/cerrar */
.wpsc-toggle-button {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--wpsc-primary) 0%, var(--wpsc-secondary) 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: var(--wpsc-shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s;
    animation: wpsc-pulse 2s infinite;
}

.wpsc-toggle-button:hover {
    transform: scale(1.08);
    box-shadow: var(--wpsc-shadow-lg);
    animation: none;
}

.wpsc-toggle-button:active {
    transform: scale(0.95);
}

.wpsc-toggle-button svg {
    transition: transform 0.3s ease, opacity 0.2s ease;
    position: absolute;
}

.wpsc-toggle-button .wpsc-icon-close {
    opacity: 0;
    transform: rotate(-90deg);
}

.wpsc-toggle-button.wpsc-active .wpsc-icon-chat {
    opacity: 0;
    transform: rotate(90deg);
}

.wpsc-toggle-button.wpsc-active .wpsc-icon-close {
    opacity: 1;
    transform: rotate(0);
}

.wpsc-toggle-button.wpsc-active {
    animation: none;
}

/* Animación de pulso */
@keyframes wpsc-pulse {
    0%, 100% {
        box-shadow: var(--wpsc-shadow-md), 0 0 0 0 rgba(0, 115, 170, 0.4);
    }
    50% {
        box-shadow: var(--wpsc-shadow-md), 0 0 0 12px rgba(0, 115, 170, 0);
    }
}

/* Badge de notificación */
.wpsc-notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--wpsc-error);
    color: white;
    font-size: 11px;
    font-weight: 700;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    animation: wpsc-bounce 1s ease infinite;
}

.wpsc-notification-badge.wpsc-hidden {
    display: none;
}

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

/* Ventana del chat */
.wpsc-chat-window {
    position: absolute;
    bottom: 80px;
    width: 380px;
    height: 580px;
    max-height: calc(100vh - 120px);
    background: var(--wpsc-bg);
    border-radius: var(--wpsc-radius);
    box-shadow: var(--wpsc-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.85) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s;
    transform-origin: bottom right;
}

.wpsc-position-bottom-left .wpsc-chat-window {
    transform-origin: bottom left;
    left: 0;
}

.wpsc-position-bottom-right .wpsc-chat-window {
    right: 0;
}

.wpsc-chat-window.wpsc-open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* Header del chat */
.wpsc-chat-header {
    background: linear-gradient(135deg, var(--wpsc-primary) 0%, var(--wpsc-secondary) 100%);
    color: white;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.wpsc-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.wpsc-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

.wpsc-bot-name {
    font-weight: 600;
    font-size: 16px;
    line-height: 1.2;
}

.wpsc-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.wpsc-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 6px #4ade80;
    animation: wpsc-blink 2s ease infinite;
}

@keyframes wpsc-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.wpsc-minimize-button {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.wpsc-minimize-button:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Área de mensajes */
.wpsc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    background: var(--wpsc-bg-alt);
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.wpsc-messages::-webkit-scrollbar {
    width: 6px;
}

.wpsc-messages::-webkit-scrollbar-track {
    background: transparent;
}

.wpsc-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

/* Mensajes */
.wpsc-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: var(--wpsc-radius-sm);
    word-wrap: break-word;
    animation: wpsc-message-in 0.3s ease forwards;
    line-height: 1.4;
}

@keyframes wpsc-message-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.wpsc-message-bot {
    background: white;
    color: var(--wpsc-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: var(--wpsc-shadow-sm);
}

.wpsc-message-user {
    background: linear-gradient(135deg, var(--wpsc-primary) 0%, var(--wpsc-secondary) 100%);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Indicador de escritura */
.wpsc-typing {
    background: white;
    align-self: flex-start;
    padding: 14px 16px;
    border-radius: var(--wpsc-radius-sm);
    border-bottom-left-radius: 4px;
    box-shadow: var(--wpsc-shadow-sm);
    display: flex;
    gap: 4px;
    animation: wpsc-message-in 0.3s ease forwards;
}

.wpsc-typing span {
    width: 8px;
    height: 8px;
    background: var(--wpsc-text-light);
    border-radius: 50%;
    animation: wpsc-typing-bounce 1.4s infinite ease-in-out;
}

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

@keyframes wpsc-typing-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Botones de opciones */
.wpsc-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
    align-self: flex-start;
    width: 100%;
    max-width: 100%;
}

.wpsc-option-button {
    background: white;
    border: 1.5px solid var(--wpsc-border);
    color: var(--wpsc-text);
    padding: 12px 16px;
    border-radius: var(--wpsc-radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    text-align: left;
    transition: all 0.2s;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.wpsc-option-button:hover {
    border-color: var(--wpsc-primary);
    background: var(--wpsc-primary);
    color: white;
    transform: translateX(4px);
}

.wpsc-option-button.wpsc-back {
    background: transparent;
    border: none;
    color: var(--wpsc-text-light);
    font-size: 13px;
    padding: 8px 12px;
    align-self: flex-start;
    width: auto;
}

.wpsc-option-button.wpsc-back:hover {
    color: var(--wpsc-primary);
    background: transparent;
    transform: translateX(-2px);
}

/* WhatsApp button especial */
.wpsc-whatsapp-button {
    background: #25D366;
    color: white;
    border: none;
    padding: 14px 18px;
    border-radius: var(--wpsc-radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    transition: all 0.2s;
    font-family: inherit;
    width: 100%;
    justify-content: center;
}

.wpsc-whatsapp-button:hover {
    background: #128C7E;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

/* Resultados de búsqueda */
.wpsc-search-results {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.wpsc-search-result {
    background: white;
    border: 1px solid var(--wpsc-border);
    border-radius: var(--wpsc-radius-sm);
    padding: 12px;
    text-decoration: none;
    color: var(--wpsc-text);
    transition: all 0.2s;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.wpsc-search-result:hover {
    border-color: var(--wpsc-primary);
    transform: translateX(4px);
    box-shadow: var(--wpsc-shadow-sm);
}

.wpsc-search-result-thumb {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.wpsc-search-result-content {
    flex: 1;
    min-width: 0;
}

.wpsc-search-result-title {
    font-weight: 600;
    font-size: 14px;
    margin: 0 0 4px;
    color: var(--wpsc-primary);
    line-height: 1.3;
}

.wpsc-search-result-excerpt {
    font-size: 12px;
    color: var(--wpsc-text-light);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Formulario de contacto */
.wpsc-contact-form {
    background: white;
    padding: 16px;
    border-radius: var(--wpsc-radius-sm);
    box-shadow: var(--wpsc-shadow-sm);
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.wpsc-form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.wpsc-form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--wpsc-text);
}

.wpsc-form-group input,
.wpsc-form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--wpsc-border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    color: var(--wpsc-text);
    background: white;
    transition: border-color 0.2s;
    resize: vertical;
}

.wpsc-form-group input:focus,
.wpsc-form-group textarea:focus {
    outline: none;
    border-color: var(--wpsc-primary);
}

.wpsc-form-group input.wpsc-error-input,
.wpsc-form-group textarea.wpsc-error-input {
    border-color: var(--wpsc-error);
}

.wpsc-form-error {
    font-size: 11px;
    color: var(--wpsc-error);
    margin-top: 2px;
}

/* Honeypot */
.wpsc-honeypot {
    position: absolute;
    left: -9999px;
    opacity: 0;
    pointer-events: none;
}

.wpsc-form-submit {
    background: linear-gradient(135deg, var(--wpsc-primary) 0%, var(--wpsc-secondary) 100%);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.2s, box-shadow 0.2s;
    margin-top: 4px;
}

.wpsc-form-submit:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 115, 170, 0.3);
}

.wpsc-form-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Footer del chat */
.wpsc-chat-footer {
    background: white;
    border-top: 1px solid var(--wpsc-border);
    flex-shrink: 0;
}

.wpsc-input-area {
    display: flex;
    gap: 8px;
    padding: 12px;
    align-items: center;
}

.wpsc-input-area input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid var(--wpsc-border);
    border-radius: 24px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.wpsc-input-area input:focus {
    border-color: var(--wpsc-primary);
}

#wpsc-send-button {
    background: linear-gradient(135deg, var(--wpsc-primary) 0%, var(--wpsc-secondary) 100%);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s;
}

#wpsc-send-button:hover {
    transform: scale(1.08);
}

#wpsc-send-button:active {
    transform: scale(0.95);
}

.wpsc-powered {
    text-align: center;
    font-size: 11px;
    color: var(--wpsc-text-light);
    padding: 8px;
    border-top: 1px solid var(--wpsc-border);
}

/* Botón disparador externo (shortcode) */
.wpsc-trigger-button {
    background: linear-gradient(135deg, var(--wpsc-primary) 0%, var(--wpsc-secondary) 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--wpsc-radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.wpsc-trigger-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 115, 170, 0.3);
}

/* Estado de éxito en el formulario */
.wpsc-success-message {
    background: #ecfdf5;
    border: 1px solid var(--wpsc-success);
    color: #065f46;
    padding: 14px 16px;
    border-radius: var(--wpsc-radius-sm);
    text-align: center;
    font-weight: 500;
}

.wpsc-error-message {
    background: #fef2f2;
    border: 1px solid var(--wpsc-error);
    color: #991b1b;
    padding: 14px 16px;
    border-radius: var(--wpsc-radius-sm);
    text-align: center;
}

/* Responsive: móvil */
@media (max-width: 480px) {
    .wpsc-position-bottom-right,
    .wpsc-position-bottom-left {
        bottom: 16px;
        right: 16px;
        left: auto;
    }

    .wpsc-chat-window {
        width: calc(100vw - 32px);
        height: calc(100vh - 110px);
        max-height: calc(100vh - 110px);
        right: 0;
        bottom: 75px;
    }

    .wpsc-position-bottom-left .wpsc-chat-window {
        left: 0;
    }

    .wpsc-toggle-button {
        width: 56px;
        height: 56px;
    }
}

/* Accesibilidad: respetar preferencias de movimiento */
@media (prefers-reduced-motion: reduce) {
    .wpsc-toggle-button,
    .wpsc-notification-badge,
    .wpsc-status-dot {
        animation: none !important;
    }
    .wpsc-chat-window,
    .wpsc-message,
    .wpsc-typing,
    .wpsc-option-button:hover,
    .wpsc-search-result:hover {
        transition-duration: 0.01s !important;
        animation-duration: 0.01s !important;
    }
}
