/**
 * Popup WhatsApp PRO - Frontend Styles
 * Desarrollado por RANKORA.ES
 */

/* Variables CSS */
:root {
    --pwp-primary: #25D366;
    --pwp-secondary: #128C7E;
    --pwp-dark: #075E54;
    --pwp-light: #DCF8C6;
    --pwp-bg-chat: #ECE5DD;
    --pwp-text-dark: #111B21;
    --pwp-text-light: #667781;
    --pwp-white: #ffffff;
    --pwp-shadow: 0 2px 16px rgba(0, 0, 0, 0.15);
    --pwp-shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.25);
    --pwp-radius: 16px;
    --pwp-radius-sm: 8px;
    --pwp-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --pwp-z-index: 999999;
}

/* Reset y Base */
.pwp-widget,
.pwp-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Widget Container */
.pwp-widget {
    position: fixed;
    bottom: 24px;
    z-index: var(--pwp-z-index);
}

.pwp-widget.pwp-position-right {
    right: 24px;
}

.pwp-widget.pwp-position-left {
    left: 24px;
}

/* Botón Principal Flotante */
.pwp-button-container {
    position: relative;
}

.pwp-main-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--pwp-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--pwp-white);
    box-shadow: var(--pwp-shadow-lg);
    transition: var(--pwp-transition);
    position: relative;
    overflow: hidden;
}

.pwp-main-button:hover {
    transform: scale(1.1);
    background: var(--pwp-secondary);
}

.pwp-main-button:focus {
    outline: 3px solid rgba(37, 211, 102, 0.5);
    outline-offset: 2px;
}

.pwp-main-button::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.2));
    border-radius: 50%;
}

.pwp-icon-whatsapp,
.pwp-icon-close {
    transition: var(--pwp-transition);
    position: absolute;
}

.pwp-icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.pwp-widget.pwp-open .pwp-icon-whatsapp {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

.pwp-widget.pwp-open .pwp-icon-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Badge de Notificación */
.pwp-notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    background: #E53935;
    color: var(--pwp-white);
    border-radius: 50%;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(229, 57, 53, 0.4);
    animation: pwp-badge-bounce 2s ease infinite;
}

.pwp-widget.pwp-open .pwp-notification-badge,
.pwp-widget.pwp-badge-hidden .pwp-notification-badge {
    display: none;
}

@keyframes pwp-badge-bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* Animaciones del Botón */
.pwp-widget.pwp-animation-pulse .pwp-main-button {
    animation: pwp-pulse 2s ease infinite;
}

.pwp-widget.pwp-animation-bounce .pwp-main-button {
    animation: pwp-bounce 2s ease infinite;
}

.pwp-widget.pwp-animation-shake .pwp-main-button {
    animation: pwp-shake 3s ease infinite;
}

.pwp-widget.pwp-open .pwp-main-button {
    animation: none !important;
}

@keyframes pwp-pulse {
    0%, 100% { box-shadow: var(--pwp-shadow-lg), 0 0 0 0 rgba(37, 211, 102, 0.4); }
    50% { box-shadow: var(--pwp-shadow-lg), 0 0 0 15px rgba(37, 211, 102, 0); }
}

@keyframes pwp-bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-15px); }
    60% { transform: translateY(-7px); }
}

@keyframes pwp-shake {
    0%, 100% { transform: rotate(0); }
    10%, 30% { transform: rotate(-10deg); }
    20%, 40% { transform: rotate(10deg); }
    50% { transform: rotate(0); }
}

/* Ventana de Chat */
.pwp-chat-window {
    position: absolute;
    bottom: 80px;
    width: 370px;
    max-width: calc(100vw - 48px);
    height: 520px;
    max-height: calc(100vh - 140px);
    background: var(--pwp-white);
    border-radius: var(--pwp-radius);
    box-shadow: var(--pwp-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: var(--pwp-transition);
    transform-origin: bottom right;
}

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

.pwp-widget.pwp-open .pwp-chat-window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.pwp-position-right .pwp-chat-window {
    right: 0;
}

.pwp-position-left .pwp-chat-window {
    left: 0;
}

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

.pwp-header-content {
    flex: 1;
}

.pwp-header-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

.pwp-header-subtitle {
    font-size: 13px;
    opacity: 0.9;
}

.pwp-close-button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: var(--pwp-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--pwp-transition);
}

.pwp-close-button:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: rotate(90deg);
}

/* Cuerpo del Chat */
.pwp-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--pwp-bg-chat);
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23b5bfb5' fill-opacity='0.15'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

/* Vistas */
.pwp-view {
    display: none;
}

.pwp-view.pwp-view-active {
    display: block;
}

/* Mensaje de Bienvenida */
.pwp-welcome-message {
    background: var(--pwp-white);
    padding: 12px 16px;
    border-radius: var(--pwp-radius-sm);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    margin-bottom: 8px;
    font-size: 15px;
    color: var(--pwp-text-dark);
    position: relative;
}

.pwp-welcome-message::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 12px;
    border: 8px solid transparent;
    border-right-color: var(--pwp-white);
}

.pwp-response-time {
    font-size: 12px;
    color: var(--pwp-text-light);
    margin-bottom: 20px;
    padding-left: 8px;
}

/* Lista de Agentes */
.pwp-agents-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pwp-agent-card {
    background: var(--pwp-white);
    border-radius: var(--pwp-radius-sm);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: var(--pwp-transition);
    border: 2px solid transparent;
}

.pwp-agent-card:hover {
    border-color: var(--pwp-primary);
    transform: translateX(4px);
}

.pwp-agent-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--pwp-primary), var(--pwp-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--pwp-white);
    font-size: 20px;
    font-weight: 600;
}

.pwp-agent-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.pwp-agent-info {
    flex: 1;
    min-width: 0;
}

.pwp-agent-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--pwp-text-dark);
    margin-bottom: 2px;
}

.pwp-agent-title {
    font-size: 13px;
    color: var(--pwp-text-light);
    margin-bottom: 4px;
}

.pwp-agent-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.pwp-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.pwp-status-dot.pwp-online {
    background: var(--pwp-primary);
    animation: pwp-status-pulse 2s ease infinite;
}

.pwp-status-dot.pwp-offline {
    background: #9E9E9E;
}

@keyframes pwp-status-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.4); }
    50% { box-shadow: 0 0 0 6px rgba(37, 211, 102, 0); }
}

.pwp-agent-arrow {
    color: var(--pwp-text-light);
    transition: var(--pwp-transition);
}

.pwp-agent-card:hover .pwp-agent-arrow {
    color: var(--pwp-primary);
    transform: translateX(4px);
}

/* Vista de Canales */
.pwp-selected-agent {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--pwp-white);
    border-radius: var(--pwp-radius-sm);
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.pwp-selected-agent .pwp-agent-avatar {
    width: 40px;
    height: 40px;
    font-size: 16px;
}

.pwp-channels-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.pwp-channel-button {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    border-radius: var(--pwp-radius-sm);
    border: none;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    color: var(--pwp-white);
    transition: var(--pwp-transition);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.pwp-channel-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.pwp-channel-button svg {
    flex-shrink: 0;
}

.pwp-channel-button.pwp-channel-whatsapp {
    background: linear-gradient(135deg, #25D366, #128C7E);
}

.pwp-channel-button.pwp-channel-telegram {
    background: linear-gradient(135deg, #2AABEE, #1B95D7);
}

.pwp-channel-button.pwp-channel-messenger {
    background: linear-gradient(135deg, #006AFF, #0052CC);
}

.pwp-channel-button.pwp-channel-phone {
    background: linear-gradient(135deg, #4CAF50, #388E3C);
}

.pwp-channel-button.pwp-channel-email {
    background: linear-gradient(135deg, #FF5722, #E64A19);
}

.pwp-back-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--pwp-white);
    border: 1px solid #E0E0E0;
    border-radius: var(--pwp-radius-sm);
    color: var(--pwp-text-dark);
    font-size: 14px;
    cursor: pointer;
    transition: var(--pwp-transition);
    width: 100%;
}

.pwp-back-button:hover {
    background: #F5F5F5;
}

/* Formulario de Leads */
.pwp-lead-form {
    background: var(--pwp-white);
    border-radius: var(--pwp-radius-sm);
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.pwp-form-fields {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 16px;
}

.pwp-form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pwp-form-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--pwp-text-dark);
}

.pwp-form-label .pwp-required {
    color: #E53935;
    margin-left: 2px;
}

.pwp-form-input,
.pwp-form-textarea {
    padding: 12px 14px;
    border: 1px solid #E0E0E0;
    border-radius: var(--pwp-radius-sm);
    font-size: 14px;
    color: var(--pwp-text-dark);
    transition: var(--pwp-transition);
    background: #FAFAFA;
}

.pwp-form-input:focus,
.pwp-form-textarea:focus {
    outline: none;
    border-color: var(--pwp-primary);
    background: var(--pwp-white);
    box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1);
}

.pwp-form-textarea {
    min-height: 80px;
    resize: vertical;
}

.pwp-form-input.pwp-error,
.pwp-form-textarea.pwp-error {
    border-color: #E53935;
}

.pwp-error-message {
    font-size: 12px;
    color: #E53935;
    margin-top: 4px;
}

.pwp-submit-button {
    width: 100%;
    padding: 14px 20px;
    background: var(--pwp-primary);
    color: var(--pwp-white);
    border: none;
    border-radius: var(--pwp-radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--pwp-transition);
}

.pwp-submit-button:hover {
    background: var(--pwp-secondary);
}

.pwp-submit-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Footer */
.pwp-chat-footer {
    padding: 12px 20px;
    background: var(--pwp-white);
    border-top: 1px solid #E0E0E0;
    text-align: center;
    flex-shrink: 0;
}

.pwp-powered-by {
    font-size: 11px;
    color: var(--pwp-text-light);
}

.pwp-powered-by a {
    color: var(--pwp-secondary);
    text-decoration: none;
    font-weight: 600;
}

.pwp-powered-by a:hover {
    text-decoration: underline;
}

/* ========================================
   BARRA MÓVIL
   ======================================== */
.pwp-mobile-bar {
    display: none;
}

/* ========================================
   RESPONSIVE - MÓVIL
   ======================================== */
@media (max-width: 768px) {
    /* Ocultar botón flotante en móvil */
    .pwp-button-container {
        display: none;
    }
    
    /* Mostrar barra móvil */
    .pwp-mobile-bar {
        display: block;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: var(--pwp-z-index);
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
        background: var(--pwp-white);
        box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.1);
    }
    
    .pwp-widget.pwp-open .pwp-mobile-bar {
        display: none;
    }
    
    .pwp-mobile-button {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        padding: 14px 24px;
        background: linear-gradient(135deg, var(--pwp-primary), var(--pwp-secondary));
        border: none;
        border-radius: 30px;
        color: var(--pwp-white);
        font-size: 16px;
        font-weight: 600;
        cursor: pointer;
        transition: var(--pwp-transition);
        box-shadow: 0 4px 16px rgba(37, 211, 102, 0.3);
    }
    
    .pwp-mobile-button:hover,
    .pwp-mobile-button:active {
        transform: scale(0.98);
    }
    
    .pwp-mobile-text {
        white-space: nowrap;
    }
    
    /* Ventana de chat en móvil */
    .pwp-widget {
        bottom: 0;
        left: 0;
        right: 0;
    }
    
    .pwp-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        transform: translateY(100%);
    }
    
    .pwp-widget.pwp-open .pwp-chat-window {
        transform: translateY(0);
    }
    
    /* Header más compacto en móvil */
    .pwp-chat-header {
        padding: 16px;
        padding-top: calc(16px + env(safe-area-inset-top, 0));
    }
    
    .pwp-header-title {
        font-size: 16px;
    }
    
    .pwp-header-subtitle {
        font-size: 12px;
    }
    
    /* Cuerpo del chat */
    .pwp-chat-body {
        padding: 16px;
    }
    
    /* Footer */
    .pwp-chat-footer {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
    }
}

/* ========================================
   TEMAS OSCURO (modo automático según preferencias)
   ======================================== */
@media (prefers-color-scheme: dark) {
    .pwp-chat-body {
        background-color: #1F2C34;
        background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23374045' fill-opacity='0.2'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    }
    
    .pwp-welcome-message,
    .pwp-agent-card,
    .pwp-selected-agent,
    .pwp-lead-form {
        background: #202C33;
        color: #E9EDEF;
    }
    
    .pwp-agent-name {
        color: #E9EDEF;
    }
    
    .pwp-agent-title,
    .pwp-response-time {
        color: #8696A0;
    }
    
    .pwp-form-input,
    .pwp-form-textarea {
        background: #2A3942;
        border-color: #3B4A54;
        color: #E9EDEF;
    }
    
    .pwp-form-input:focus,
    .pwp-form-textarea:focus {
        background: #2A3942;
        border-color: var(--pwp-primary);
    }
    
    .pwp-chat-footer {
        background: #202C33;
        border-top-color: #3B4A54;
    }
    
    .pwp-back-button {
        background: #202C33;
        border-color: #3B4A54;
        color: #E9EDEF;
    }
    
    .pwp-back-button:hover {
        background: #2A3942;
    }
}

/* ========================================
   UTILIDADES Y ESTADOS
   ======================================== */
.pwp-hidden {
    display: none !important;
}

.pwp-loading {
    position: relative;
    pointer-events: none;
}

.pwp-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Spinner de carga */
.pwp-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #E0E0E0;
    border-top-color: var(--pwp-primary);
    border-radius: 50%;
    animation: pwp-spin 0.8s linear infinite;
}

@keyframes pwp-spin {
    to { transform: rotate(360deg); }
}

/* Mensaje de éxito */
.pwp-success-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.pwp-success-icon {
    width: 64px;
    height: 64px;
    background: var(--pwp-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    color: var(--pwp-primary);
}

.pwp-success-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--pwp-text-dark);
    margin-bottom: 8px;
}

.pwp-success-text {
    font-size: 14px;
    color: var(--pwp-text-light);
}

/* Animación de entrada */
@keyframes pwp-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.pwp-animate-in {
    animation: pwp-fade-in 0.3s ease forwards;
}

/* Accesibilidad */
@media (prefers-reduced-motion: reduce) {
    .pwp-widget,
    .pwp-widget * {
        animation: none !important;
        transition: none !important;
    }
}

/* Focus visible para accesibilidad */
.pwp-widget :focus-visible {
    outline: 2px solid var(--pwp-primary);
    outline-offset: 2px;
}

/* ========================================
   PRINT STYLES
   ======================================== */
@media print {
    .pwp-widget {
        display: none !important;
    }
}
