/**
 * SitePro Chat N8N - Estilos Modernos
 * Versión: 2.2.2 - Fix: Forzar colores con !important
 */

/* ===== FIX PARA WORDPRESS ===== */
#sitepro-chat-widget * {
    box-sizing: border-box;
}

#sitepro-chat-widget button {
    font-family: inherit !important;
    line-height: inherit !important;
}

#sitepro-chat-widget .quick-action-btn,
#sitepro-chat-widget .quick-action-btn * {
    color: #1a1a2e !important;
}

#sitepro-chat-widget .quick-action-btn .dashicons {
    color: #0066ff !important;
}

/* ===== VARIABLES CSS ===== */
:root {
    --sitepro-primary: #0066ff;
    --sitepro-primary-dark: #0047cc;
    --sitepro-primary-light: #3385ff;
    --sitepro-secondary: #00d4ff;
    --sitepro-danger: #dc3545;
    --sitepro-warning: #ffc107;
    --sitepro-light: #f0f7ff;
    --sitepro-dark: #1a1a2e;
    --sitepro-gray: #6c757d;
    --sitepro-border: #d0e4ff;
    --sitepro-shadow: rgba(0, 102, 255, 0.15);
    --sitepro-shadow-lg: rgba(0, 71, 204, 0.25);
}

/* ===== CONTENEDOR PRINCIPAL ===== */
#sitepro-chat-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

/* Posiciones */
#sitepro-chat-widget.position-bottom-right {
    bottom: 20px;
    right: 20px;
}

#sitepro-chat-widget.position-bottom-left {
    bottom: 20px;
    left: 20px;
}

#sitepro-chat-widget.position-top-right {
    top: 20px;
    right: 20px;
}

#sitepro-chat-widget.position-top-left {
    top: 20px;
    left: 20px;
}

/* Widget expandido */
#sitepro-chat-widget .chat-section {
    width: 380px;
    height: 600px;
    max-height: 90vh;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 8px 32px var(--sitepro-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#sitepro-chat-widget.minimized .chat-section {
    display: none;
}

/* ===== BOTÓN FLOTANTE (FAB) ===== */
.chat-fab {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #0066ff 0%, #0047cc 50%, #003399 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 71, 204, 0.4);
    transition: all 0.3s ease;
    position: relative;
}

.chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(0, 71, 204, 0.5);
}

.chat-fab .dashicons {
    color: #ffffff;
    font-size: 28px;
    width: 28px;
    height: 28px;
}

.chat-fab .notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: linear-gradient(135deg, #ff0066, #ff3385);
    color: #ffffff;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    border: 2px solid #ffffff;
}

#sitepro-chat-widget:not(.minimized) .chat-fab {
    display: none;
}

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border-radius: 16px;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--sitepro-light);
    border-top-color: var(--sitepro-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-text {
    margin-top: 16px;
    color: var(--sitepro-gray);
    font-weight: 500;
}

/* ===== SECCIÓN DE CHAT ===== */
#chat-section {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, #0066ff 0%, #0047cc 50%, #003399 100%);
    color: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

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

.bot-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bot-avatar .dashicons {
    color: #ffffff;
    font-size: 24px;
}

.header-info h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #ffffff !important;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    opacity: 0.9;
    color: #ffffff !important;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #00ff88;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.header-actions {
    display: flex;
    gap: 8px;
}

.action-button {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.action-button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.action-button .dashicons {
    color: #ffffff;
    font-size: 18px;
}

/* Área de Mensajes */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: linear-gradient(135deg, #f8fbff 0%, #ffffff 100%);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 102, 255, 0.2);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 102, 255, 0.3);
}

.message {
    display: flex;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-content {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.user-message {
    justify-content: flex-end;
}

.user-message .message-content {
    background: linear-gradient(135deg, #0066ff 0%, #0047cc 100%);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.bot-message {
    justify-content: flex-start;
}

.bot-message .message-content {
    background: #ffffff;
    color: var(--sitepro-dark);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 102, 255, 0.1);
    border: 1px solid var(--sitepro-border);
}

.message-content p {
    margin: 0 0 8px 0;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin: 4px 0;
}

/* Typing Indicator */
.typing-indicator .message-content {
    padding: 16px;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

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

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ===== INPUT DE MENSAJE - CORREGIDO ===== */
.chat-input-container {
    padding: 16px;
    padding-bottom: 28px;
    background: #ffffff;
    border-top: 1px solid var(--sitepro-border);
    display: flex;
    gap: 12px;
    align-items: flex-start;
    flex-shrink: 0;
}

.input-wrapper {
    flex: 1;
    position: relative;
}

#message-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--sitepro-border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

#message-input:focus {
    outline: none;
    border-color: var(--sitepro-primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.1);
}

.character-count {
    position: absolute;
    bottom: -20px;
    right: 4px;
    font-size: 11px;
    color: var(--sitepro-gray);
}

.btn-send {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #0066ff 0%, #0047cc 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
    background: linear-gradient(135deg, #0066ff 0%, #003399 100%);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 71, 204, 0.3);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-send .dashicons {
    color: #ffffff;
    font-size: 24px;
    width: 24px;
    height: 24px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== MENSAJE INICIAL DE PRESENTACIÓN ===== */
.initial-presentation {
    padding: 24px;
    text-align: center;
    animation: fadeIn 0.5s ease;
}

.initial-presentation .presentation-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #0066ff 0%, #0047cc 50%, #003399 100%);
    border-radius: 50%;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(0, 71, 204, 0.3);
}

.initial-presentation .presentation-icon .dashicons {
    color: #ffffff;
    font-size: 40px;
    width: 40px;
    height: 40px;
}

.initial-presentation h3 {
    color: var(--sitepro-dark);
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 12px 0;
}

.initial-presentation p {
    color: var(--sitepro-gray);
    font-size: 14px;
    line-height: 1.6;
    margin: 0 0 24px 0;
}

.quick-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.quick-action-btn {
    padding: 14px 20px !important;
    background: linear-gradient(135deg, #f0f7ff 0%, #ffffff 100%) !important;
    border: 2px solid var(--sitepro-border) !important;
    border-radius: 10px !important;
    color: #1a1a2e !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    text-align: left !important;
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
}

.quick-action-btn span {
    color: #1a1a2e !important;
}

.quick-action-btn:hover {
    background: linear-gradient(135deg, #ffffff 0%, #e6f2ff 100%) !important;
    border-color: var(--sitepro-primary) !important;
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(0, 102, 255, 0.15) !important;
}

.quick-action-btn:hover span {
    color: #1a1a2e !important;
}

.quick-action-btn:active {
    transform: translateX(2px);
}

.quick-action-btn .dashicons {
    color: #0066ff !important;
    flex-shrink: 0;
    font-size: 20px !important;
    width: 20px !important;
    height: 20px !important;
}

/* ===== TÉRMINOS INLINE (DENTRO DEL CHAT) ===== */
.terms-inline-container {
    background: linear-gradient(135deg, #fff9e6 0%, #ffffff 100%);
    border: 2px solid #ffc107;
    border-radius: 12px;
    padding: 16px;
    margin: 8px 0;
    animation: slideIn 0.4s ease;
}

.terms-brief {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.terms-icon {
    font-size: 24px;
    flex-shrink: 0;
    line-height: 1;
}

.terms-intro {
    flex: 1;
    margin: 0;
    font-size: 13px;
    color: var(--sitepro-dark);
    line-height: 1.6;
}

/* ===== FIX BOTÓN VER TÉRMINOS - SIEMPRE VISIBLE ===== */
.terms-expand-btn {
    display: inline-flex !important;
    align-items: center !important;
    gap: 4px !important;
    background: #e6f0ff !important;
    border: 1px solid #0066ff !important;
    border-radius: 6px !important;
    color: #0066ff !important;
    font-weight: 600 !important;
    font-size: 13px !important;
    cursor: pointer !important;
    padding: 6px 12px !important;
    margin-top: 8px !important;
    transition: all 0.2s ease !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.terms-expand-btn:hover {
    background: #cce0ff !important;
    color: #0047cc !important;
    transform: translateX(2px);
}

.terms-expand-btn .dashicons {
    font-size: 16px !important;
    width: 16px !important;
    height: 16px !important;
    transition: transform 0.3s ease;
    color: #0066ff !important;
}

.terms-expand-btn.expanded .dashicons {
    transform: rotate(180deg);
}

.terms-full-content {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 193, 7, 0.3);
    animation: expandDown 0.3s ease;
}

@keyframes expandDown {
    from {
        opacity: 0;
        max-height: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        max-height: 1000px;
        transform: translateY(0);
    }
}

.terms-scroll {
    max-height: 200px;
    overflow-y: auto;
    padding-right: 8px;
}

.terms-scroll::-webkit-scrollbar {
    width: 4px;
}

.terms-scroll::-webkit-scrollbar-track {
    background: rgba(255, 193, 7, 0.1);
    border-radius: 2px;
}

.terms-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 193, 7, 0.4);
    border-radius: 2px;
}

.terms-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 193, 7, 0.6);
}

.terms-full-content h4 {
    color: var(--sitepro-primary);
    margin: 12px 0 8px 0;
    font-size: 14px;
    font-weight: 600;
}

.terms-full-content h4:first-child {
    margin-top: 0;
}

.terms-full-content p {
    color: var(--sitepro-dark);
    font-size: 12px;
    line-height: 1.6;
    margin: 8px 0;
}

.terms-full-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

.terms-full-content li {
    color: var(--sitepro-dark);
    font-size: 12px;
    margin: 4px 0;
}

.terms-collapse-btn {
    width: 100%;
    padding: 8px 12px;
    margin-top: 12px;
    background: #f0f0f0 !important;
    border: 1px solid #333333 !important;
    border-radius: 6px;
    color: #1a1a2e !important;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.terms-collapse-btn:hover {
    background: #e0e0e0 !important;
    border-color: #000000 !important;
}

.terms-collapse-btn .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
    color: #1a1a2e !important;
}

.terms-acceptance-inline {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 193, 7, 0.3);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.checkbox-label-inline {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 13px;
    color: var(--sitepro-dark);
}

.checkbox-label-inline input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

.checkbox-text {
    line-height: 1.4;
}

.btn-accept-inline {
    width: 100%;
    padding: 12px 20px;
    background: linear-gradient(135deg, #0066ff 0%, #0047cc 100%);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-accept-inline:hover:not(:disabled) {
    background: linear-gradient(135deg, #0066ff 0%, #003399 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 71, 204, 0.3);
}

.btn-accept-inline:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
    #sitepro-chat-widget .chat-section {
        width: 100vw;
        width: 100dvw; /* Dynamic viewport width - mejor soporte móvil */
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height - considera la barra del navegador */
        max-height: -webkit-fill-available; /* Fallback para Safari iOS */
        border-radius: 0;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        position: fixed;
    }
    
    /* Header más compacto en móvil */
    #sitepro-chat-widget .chat-header {
        padding: 12px 16px;
        min-height: 56px;
    }
    
    #sitepro-chat-widget .header-info h3 {
        font-size: 15px;
    }
    
    #sitepro-chat-widget .bot-avatar {
        width: 36px;
        height: 36px;
    }
    
    /* Área de mensajes ocupa todo el espacio disponible */
    #sitepro-chat-widget .chat-messages {
        flex: 1;
        min-height: 0; /* Importante para que flex funcione bien */
        padding: 12px;
    }
    
    /* Input más compacto */
    #sitepro-chat-widget .chat-input-container {
        padding: 10px 12px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom)); /* Para iPhone con notch */
    }
    
    #sitepro-chat-widget #message-input {
        font-size: 16px; /* Evita zoom en iOS */
        min-height: 40px;
    }
    
    #sitepro-chat-widget .btn-send {
        width: 40px;
        height: 40px;
    }
    
    /* FAB más pequeño en móvil */
    .chat-fab {
        width: 56px;
        height: 56px;
        bottom: 16px;
        right: 16px;
    }
    
    /* Términos más compactos */
    .terms-inline-container {
        padding: 12px;
    }
    
    .terms-scroll {
        max-height: 150px;
    }
    
    /* Mensajes más pequeños */
    #sitepro-chat-widget .message-content {
        max-width: 90%;
        padding: 10px 14px;
        font-size: 14px;
    }
    
    /* Quick actions en columna */
    #sitepro-chat-widget .quick-actions {
        flex-direction: column;
        gap: 8px;
    }
    
    #sitepro-chat-widget .quick-action-btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Presentación inicial más compacta */
    #sitepro-chat-widget .initial-presentation {
        padding: 20px 16px;
    }
    
    #sitepro-chat-widget .initial-presentation h3 {
        font-size: 18px;
    }
    
    #sitepro-chat-widget .presentation-icon {
        width: 60px;
        height: 60px;
    }
    
    #sitepro-chat-widget .presentation-icon .dashicons {
        font-size: 30px;
    }
}

/* Tablets */
@media (max-width: 768px) and (min-width: 481px) {
    #sitepro-chat-widget .chat-section {
        width: 360px;
        height: 70vh;
        max-height: 600px;
        right: 16px;
        bottom: 16px;
    }
}

/* ===== UTILIDADES ===== */
.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== FIX PARA DASHICONS ===== */
.dashicons {
    display: inline-block;
    width: 20px;
    height: 20px;
    font-size: 20px;
    line-height: 1;
    font-family: dashicons;
    text-decoration: inherit;
    font-weight: normal;
    font-style: normal;
    vertical-align: middle;
    text-align: center;
    transition: color .1s ease-in;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

