/**
 * Pricu Smart Chatbot - Frontend Styles
 * 
 * @package Pricu_Smart_Chatbot
 * @version 1.0.0
 */

/* CSS Variables */
:root {
    --psc-primary-color: #2563eb;
    --psc-primary-dark: #1d4ed8;
    --psc-primary-light: #93c5fd;
    --psc-secondary-color: #64748b;
    --psc-success-color: #22c55e;
    --psc-error-color: #ef4444;
    --psc-warning-color: #f59e0b;
    --psc-bg-color: #ffffff;
    --psc-bg-secondary: #f8fafc;
    --psc-text-color: #1e293b;
    --psc-text-secondary: #64748b;
    --psc-border-color: #e2e8f0;
    --psc-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --psc-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --psc-radius: 16px;
    --psc-radius-sm: 8px;
    --psc-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --psc-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* Container */
.psc-chatbot-container {
    position: fixed;
    bottom: 20px;
    z-index: 999999;
    font-family: var(--psc-font-family);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.psc-chatbot-container * {
    box-sizing: border-box;
}

.psc-position-right {
    right: 20px;
}

.psc-position-left {
    left: 20px;
}

/* Toggle Button */
.psc-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--psc-primary-color), var(--psc-primary-dark));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--psc-shadow);
    transition: var(--psc-transition);
    position: relative;
    color: white;
}

.psc-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 45px rgba(37, 99, 235, 0.4);
}

.psc-chat-toggle:active {
    transform: scale(0.95);
}

.psc-toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--psc-transition);
}

.psc-notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--psc-error-color);
    color: white;
    font-size: 12px;
    font-weight: 600;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: psc-pulse 2s infinite;
}

@keyframes psc-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Chat Window */
.psc-chat-window {
    position: absolute;
    bottom: 75px;
    width: 380px;
    height: 550px;
    max-height: calc(100vh - 120px);
    background: var(--psc-bg-color);
    border-radius: var(--psc-radius);
    box-shadow: var(--psc-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: psc-slide-up 0.3s ease-out;
    border: 1px solid var(--psc-border-color);
}

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

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

@keyframes psc-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

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

.psc-header-text {
    display: flex;
    flex-direction: column;
}

.psc-bot-name {
    font-weight: 600;
    font-size: 16px;
}

.psc-bot-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.psc-status-dot {
    width: 8px;
    height: 8px;
    background: var(--psc-success-color);
    border-radius: 50%;
    animation: psc-status-blink 2s infinite;
}

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

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

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

.psc-header-btn svg {
    width: 20px;
    height: 20px;
    stroke: white;
    display: block;
}

.psc-header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Chat Messages */
.psc-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--psc-bg-secondary);
    scroll-behavior: smooth;
}

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

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

.psc-chat-messages::-webkit-scrollbar-thumb {
    background: var(--psc-border-color);
    border-radius: 3px;
}

.psc-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--psc-secondary-color);
}

/* Message Styles */
.psc-message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: psc-message-in 0.3s ease-out;
}

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

.psc-message.psc-message-user {
    flex-direction: row-reverse;
    align-self: flex-end;
}

.psc-message.psc-message-bot {
    align-self: flex-start;
}

.psc-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--psc-primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.psc-message-user .psc-message-avatar {
    background: var(--psc-secondary-color);
    color: white;
}

.psc-message-bot .psc-message-avatar {
    background: var(--psc-primary-color);
    color: white;
}

.psc-message-avatar svg {
    width: 18px;
    height: 18px;
}

.psc-message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.psc-message-text {
    padding: 12px 16px;
    border-radius: var(--psc-radius-sm);
    word-wrap: break-word;
    white-space: pre-wrap;
}

.psc-message-user .psc-message-text {
    background: var(--psc-primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

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

.psc-message-text a {
    color: inherit;
    text-decoration: underline;
}

.psc-message-user .psc-message-text a {
    color: var(--psc-primary-light);
}

.psc-message-bot .psc-message-text a {
    color: var(--psc-primary-color);
}

.psc-message-time {
    font-size: 11px;
    color: var(--psc-text-secondary);
    padding: 0 4px;
}

.psc-message-user .psc-message-time {
    text-align: right;
}

/* Quick Actions */
.psc-quick-actions {
    padding: 12px 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    background: var(--psc-bg-color);
    border-top: 1px solid var(--psc-border-color);
}

.psc-quick-btn {
    background: var(--psc-bg-secondary);
    border: 1px solid var(--psc-border-color);
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: var(--psc-transition);
    color: var(--psc-text-color);
    white-space: nowrap;
}

.psc-quick-btn:hover {
    background: var(--psc-primary-color);
    color: white;
    border-color: var(--psc-primary-color);
}

/* Typing Indicator */
.psc-typing-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 10px;
}

.psc-typing-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--psc-primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.psc-typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: var(--psc-radius-sm);
    box-shadow: var(--psc-shadow-sm);
}

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

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

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

@keyframes psc-typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Chat Input */
.psc-chat-input-container {
    padding: 16px 20px;
    background: var(--psc-bg-color);
    border-top: 1px solid var(--psc-border-color);
}

.psc-chat-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.psc-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--psc-bg-secondary);
    border-radius: var(--psc-radius-sm);
    padding: 8px 12px;
    border: 1px solid var(--psc-border-color);
    transition: var(--psc-transition);
}

.psc-input-wrapper:focus-within {
    border-color: var(--psc-primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.psc-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    color: var(--psc-text-color);
    min-height: 24px;
    max-height: 120px;
    outline: none;
}

.psc-chat-input::placeholder {
    color: var(--psc-text-secondary);
}

.psc-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--psc-primary-color);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--psc-transition);
    flex-shrink: 0;
}

.psc-send-btn svg {
    width: 20px;
    height: 20px;
    stroke: white;
    fill: none;
    display: block;
}

.psc-send-btn:hover:not(:disabled) {
    background: var(--psc-primary-dark);
    transform: scale(1.05);
}

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

.psc-input-info {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--psc-text-secondary);
    padding: 0 4px;
}

.psc-powered-by strong {
    color: var(--psc-primary-color);
}

/* Product Cards */
.psc-product-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
}

.psc-product-card {
    display: flex;
    gap: 12px;
    background: white;
    border-radius: var(--psc-radius-sm);
    padding: 12px;
    box-shadow: var(--psc-shadow-sm);
    border: 1px solid var(--psc-border-color);
}

.psc-product-image {
    width: 60px;
    height: 60px;
    border-radius: var(--psc-radius-sm);
    overflow: hidden;
    flex-shrink: 0;
}

.psc-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.psc-product-info {
    flex: 1;
    min-width: 0;
}

.psc-product-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--psc-text-color);
    margin: 0 0 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.psc-product-price {
    font-size: 14px;
    font-weight: 700;
    color: var(--psc-primary-color);
    margin: 0 0 6px;
}

.psc-product-link {
    font-size: 12px;
    color: var(--psc-primary-color);
    text-decoration: none;
}

.psc-product-link:hover {
    text-decoration: underline;
}

/* Error Message */
.psc-error-message {
    background: #fef2f2;
    color: var(--psc-error-color);
    padding: 12px 16px;
    border-radius: var(--psc-radius-sm);
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0;
}

/* Welcome Message */
.psc-welcome-message .psc-message-text {
    background: linear-gradient(135deg, var(--psc-primary-color), var(--psc-primary-dark));
    color: white;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .psc-chatbot-container {
        bottom: 80px; /* Más arriba para no pisar botones del footer móvil */
    }
    
    .psc-position-right {
        right: 15px;
    }
    
    .psc-position-left {
        left: 15px;
    }
    
    .psc-chat-window {
        /* Centrar ventana en la pantalla */
        position: fixed;
        width: calc(100vw - 30px);
        height: calc(100vh - 120px);
        max-height: 600px;
        min-height: 400px;
        bottom: auto;
        top: 50%;
        left: 50% !important;
        right: auto !important;
        transform: translate(-50%, -50%);
        border-radius: 16px;
    }
    
    .psc-position-right .psc-chat-window,
    .psc-position-left .psc-chat-window {
        right: auto !important;
        left: 50% !important;
        transform: translate(-50%, -50%);
    }
    
    .psc-chat-toggle {
        width: 56px;
        height: 56px;
    }
    
    .psc-quick-actions {
        padding: 10px 15px;
    }
    
    .psc-quick-btn {
        font-size: 12px;
        padding: 6px 12px;
    }
    
    .psc-chat-header {
        border-radius: 16px 16px 0 0;
    }
    
    .psc-chat-input-container {
        border-radius: 0 0 16px 16px;
    }
}

/* Tablets */
@media (max-width: 768px) and (min-width: 481px) {
    .psc-chatbot-container {
        bottom: 70px;
    }
    
    .psc-chat-window {
        width: 380px;
        max-height: calc(100vh - 150px);
    }
}

/* Hide on mobile option */
@media (max-width: 768px) {
    .psc-chatbot-container[data-mobile="0"] {
        display: none;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .psc-chatbot-container.psc-dark-mode {
        --psc-bg-color: #1e293b;
        --psc-bg-secondary: #0f172a;
        --psc-text-color: #f1f5f9;
        --psc-text-secondary: #94a3b8;
        --psc-border-color: #334155;
    }
}

/* Print - hide chatbot */
@media print {
    .psc-chatbot-container {
        display: none !important;
    }
}

/* Accessibility */
.psc-chat-toggle:focus,
.psc-send-btn:focus,
.psc-quick-btn:focus,
.psc-header-btn:focus {
    outline: 2px solid var(--psc-primary-color);
    outline-offset: 2px;
}

.psc-chat-input:focus {
    outline: none;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .psc-chatbot-container,
    .psc-chatbot-container * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
