/**
 * WP AI Advisor Frontend Styles
 *
 * Bootstrap-enhanced frontend styling for the chat widget.
 * Fully responsive for desktop and mobile devices.
 *
 * @package WP_AI_Advisor
 */

/* ==========================================================================
   CSS Variables (set via PHP)
   ========================================================================== */

:root {
    --wpai-header-color: #6366f1;
    --wpai-bubble-bg: #6366f1;
    --wpai-user-bubble: #6366f1;
    --wpai-bot-bubble: #f3f4f6;
    --wpai-user-text: #ffffff;
    --wpai-bot-text: #1f2937;
}

/* ==========================================================================
   Floating Bubble Widget
   ========================================================================== */

.wpai-widget-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
}

.wpai-bubble-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--wpai-bubble-bg);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.wpai-bubble-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 25px rgba(99, 102, 241, 0.5);
}

.wpai-bubble-button svg {
    width: 28px;
    height: 28px;
    fill: white;
}

.wpai-bubble-button .wpai-close-icon {
    display: none;
}

.wpai-widget-bubble.open .wpai-bubble-button .wpai-chat-icon {
    display: none;
}

.wpai-widget-bubble.open .wpai-bubble-button .wpai-close-icon {
    display: block;
}

/* Notification badge */
.wpai-bubble-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    border-radius: 50%;
    color: white;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    display: none;
}

/* ==========================================================================
   Slider Panel Widget
   ========================================================================== */

.wpai-widget-slider {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100vh;
    z-index: 9999;
    transition: right 0.3s ease;
    box-shadow: -5px 0 30px rgba(0, 0, 0, 0.15);
}

.wpai-widget-slider.open {
    right: 0;
}

.wpai-slider-toggle {
    position: absolute;
    left: -50px;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 100px;
    background: var(--wpai-bubble-bg);
    border-radius: 10px 0 0 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: -4px 0 15px rgba(99, 102, 241, 0.3);
}

.wpai-slider-toggle svg {
    width: 24px;
    height: 24px;
    fill: white;
}

/* ==========================================================================
   Chat Container
   ========================================================================== */

.wpai-chat-container {
    display: none;
    flex-direction: column;
    width: 380px;
    height: 550px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    position: fixed;
    bottom: 100px;
    right: 24px;
    z-index: 9998;
}

.wpai-widget-bubble.open .wpai-chat-container,
.wpai-widget-slider .wpai-chat-container {
    display: flex;
}

.wpai-widget-slider .wpai-chat-container {
    position: static;
    width: 100%;
    height: 100%;
    border-radius: 0;
    box-shadow: none;
}

/* ==========================================================================
   Chat Header
   ========================================================================== */

.wpai-chat-header {
    background: var(--wpai-header-color);
    color: #ffffff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

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

.wpai-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.wpai-header-avatar svg {
    width: 24px;
    height: 24px;
    fill: white;
}

.wpai-header-info {
    flex: 1;
}

.wpai-header-title {
    font-weight: 600;
    font-size: 16px;
    margin: 0;
}

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

.wpai-header-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
}

.wpai-header-close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.wpai-header-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   Chat Messages
   ========================================================================== */

.wpai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f9fafb;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Scrollbar styling */
.wpai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

.wpai-chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

/* Message wrapper */
.wpai-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: wpai-slideIn 0.3s ease;
}

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

.wpai-message.user {
    flex-direction: row-reverse;
}

/* Message avatar */
.wpai-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.wpai-message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.wpai-message-avatar svg {
    width: 18px;
    height: 18px;
    fill: #6b7280;
}

.wpai-message.user .wpai-message-avatar {
    background: var(--wpai-user-bubble);
}

.wpai-message.user .wpai-message-avatar svg {
    fill: white;
}

/* Message content */
.wpai-message-content {
    max-width: 75%;
}

.wpai-message-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.wpai-message.bot .wpai-message-bubble {
    background: var(--wpai-bot-bubble);
    color: var(--wpai-bot-text);
    border-bottom-left-radius: 4px;
}

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

/* Message time */
.wpai-message-time {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
    text-align: right;
}

.wpai-message.bot .wpai-message-time {
    text-align: left;
}

/* ==========================================================================
   Typing Indicator
   ========================================================================== */

.wpai-typing {
    display: flex;
    align-items: center;
    gap: 10px;
}

.wpai-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--wpai-bot-bubble);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.wpai-typing-indicator span {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: wpai-typing 1.4s infinite;
}

.wpai-typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.wpai-typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes wpai-typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-6px);
    }
}

/* ==========================================================================
   Product Cards
   ========================================================================== */

.wpai-product-card {
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    transition: box-shadow 0.2s ease;
    background: white;
    margin-top: 12px;
}

.wpai-product-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.wpai-product-card .card-body {
    padding: 8px 12px;
}

.wpai-product-image {
    width: 100%;
    height: 80px;
    object-fit: cover;
    border-radius: 8px 0 0 8px;
}

.wpai-product-name {
    font-size: 13px;
    font-weight: 600;
    color: #1f2937;
    margin: 0;
}

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

.wpai-product-stock {
    font-size: 11px;
    font-weight: 500;
}

.wpai-product-card .btn {
    font-size: 12px;
    padding: 4px 12px;
}

/* ==========================================================================
   Chat Input
   ========================================================================== */

.wpai-chat-input {
    padding: 16px 20px;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 12px;
    flex-shrink: 0;
}

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

.wpai-chat-input input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    font-size: 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.wpai-chat-input input:focus {
    outline: none;
    border-color: var(--wpai-header-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.wpai-chat-input input::placeholder {
    color: #9ca3af;
}

.wpai-send-button {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--wpai-header-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background 0.2s ease;
    flex-shrink: 0;
}

.wpai-send-button:hover {
    transform: scale(1.05);
}

.wpai-send-button:disabled {
    background: #d1d5db;
    cursor: not-allowed;
    transform: none;
}

.wpai-send-button svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* ==========================================================================
   Inline Chat Widget (Shortcode)
   ========================================================================== */

.wpai-inline-widget {
    width: 100%;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.wpai-inline-widget .wpai-chat-container {
    position: static;
    width: 100%;
    height: 100%;
    border-radius: 0;
    box-shadow: none;
    display: flex;
}

/* ==========================================================================
   Quick Actions
   ========================================================================== */

.wpai-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.wpai-quick-action {
    padding: 8px 16px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 20px;
    font-size: 13px;
    color: #4b5563;
    cursor: pointer;
    transition: all 0.2s ease;
}

.wpai-quick-action:hover {
    background: var(--wpai-header-color);
    color: white;
    border-color: var(--wpai-header-color);
}

/* ==========================================================================
   Error Message
   ========================================================================== */

.wpai-error-message {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ==========================================================================
   Greeting Message
   ========================================================================== */

.wpai-greeting {
    text-align: center;
    padding: 40px 20px;
}

.wpai-greeting-icon {
    width: 60px;
    height: 60px;
    background: var(--wpai-header-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.wpai-greeting-icon svg {
    width: 32px;
    height: 32px;
    fill: white;
}

.wpai-greeting h3 {
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
    margin: 0 0 8px;
}

.wpai-greeting p {
    font-size: 14px;
    color: #6b7280;
    margin: 0 0 20px;
}

/* ==========================================================================
   Overlay
   ========================================================================== */

.wpai-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9997;
    display: none;
}

.wpai-overlay.active {
    display: block;
}

/* ==========================================================================
   Mobile Responsive
   ========================================================================== */

@media (max-width: 480px) {
    .wpai-widget-bubble {
        bottom: 16px;
        right: 16px;
    }

    .wpai-bubble-button {
        width: 56px;
        height: 56px;
    }

    .wpai-chat-container {
        width: calc(100vw - 32px);
        height: calc(100vh - 120px);
        max-height: 600px;
        bottom: 88px;
        right: 16px;
    }

    .wpai-widget-slider {
        width: 100%;
        right: -100%;
    }

    .wpai-slider-toggle {
        display: none;
    }

    /* Full screen on mobile */
    .wpai-widget-slider.open {
        right: 0;
    }

    .wpai-widget-slider .wpai-chat-container {
        height: 100vh;
    }

    .wpai-message-content {
        max-width: 85%;
    }

    .wpai-product-card .row {
        flex-direction: column;
    }

    .wpai-product-card .col-4,
    .wpai-product-card .col-8 {
        width: 100%;
    }

    .wpai-product-image {
        height: 120px;
        border-radius: 8px 8px 0 0;
    }
}

/* ==========================================================================
   Animations
   ========================================================================== */

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

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

/* Pulse animation for new messages */
.wpai-pulse {
    animation: wpai-pulse 2s infinite;
}

@keyframes wpai-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(99, 102, 241, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
    }
}
