/**
 * WooCommerce AI Vector Assistant - Chat Widget Styles
 * 
 * Responsive, themeable chat widget with self-contained CSS
 * to avoid conflicts with site themes.
 * 
 * @package WCAIVector
 * @since 2.0.0
 */

/* ===== CSS VARIABLES ===== */
.wcai-widget-container {
    /* Default colors - overridden by JavaScript with admin settings */
    --wcai-primary-color: #2271b1;
    --wcai-secondary-color: #f0f0f1;
    --wcai-text-color: #1d2327;
    --wcai-bg-color: #ffffff;
    --wcai-border-color: #e0e0e0;
    --wcai-shadow-color: rgba(0, 0, 0, 0.1);
    --wcai-success-color: #28a745;
    --wcai-error-color: #dc3545;
    --wcai-warning-color: #ffc107;
    
    /* Widget dimensions */
    --wcai-bubble-size: 60px;
    --wcai-chat-width: 380px;
    --wcai-chat-height: 500px;
    --wcai-border-radius: 12px;
    --wcai-shadow: 0 8px 32px var(--wcai-shadow-color);
    
    /* Z-index to stay above site elements */
    --wcai-z-index: 9999;
}

/* ===== THEME VARIATIONS ===== */
.wcai-theme-dark {
    --wcai-bg-color: #1a1a1a;
    --wcai-text-color: #ffffff;
    --wcai-border-color: #333333;
    --wcai-secondary-color: #2a2a2a;
    --wcai-shadow-color: rgba(255, 255, 255, 0.1);
}

/* ===== CONTAINER & POSITIONING ===== */
.wcai-widget-container {
    position: fixed;
    z-index: var(--wcai-z-index);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: var(--wcai-text-color);
    box-sizing: border-box;
}

.wcai-widget-container *,
.wcai-widget-container *::before,
.wcai-widget-container *::after {
    box-sizing: border-box;
}

/* Position variants */
.wcai-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

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

.wcai-position-top-right {
    top: 20px;
    right: 20px;
}

.wcai-position-top-left {
    top: 20px;
    left: 20px;
}

.wcai-position-embedded {
    position: relative;
    width: 100%;
    max-width: var(--wcai-chat-width);
    margin: 0 auto;
}

/* ===== CHAT BUBBLE (LAUNCHER) ===== */
.wcai-chat-bubble {
    position: relative;
    width: var(--wcai-bubble-size);
    height: var(--wcai-bubble-size);
    background: var(--wcai-primary-color);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--wcai-shadow);
    transition: all 0.3s ease;
    overflow: hidden;
}

.wcai-chat-bubble:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 40px var(--wcai-shadow-color);
}

.wcai-bubble-content {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wcai-bubble-icon {
    width: 28px;
    height: 28px;
    color: white;
    transition: transform 0.3s ease;
}

.wcai-chat-open .wcai-bubble-icon {
    transform: rotate(180deg);
}

.wcai-bubble-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--wcai-error-color);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

.wcai-bubble-pulse {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--wcai-primary-color);
    opacity: 0;
    z-index: 1;
}

/* Attention animation */
.wcai-animate-attention .wcai-bubble-pulse {
    animation: wcai-pulse 2s infinite;
}

@keyframes wcai-pulse {
    0% {
        transform: scale(1);
        opacity: 0.7;
    }
    70% {
        transform: scale(1.4);
        opacity: 0;
    }
    100% {
        transform: scale(1.4);
        opacity: 0;
    }
}

/* ===== CHAT WINDOW ===== */
.wcai-chat-window {
    position: absolute;
    bottom: calc(var(--wcai-bubble-size) + 10px);
    right: 0;
    width: var(--wcai-chat-width);
    height: var(--wcai-chat-height);
    background: var(--wcai-bg-color);
    border-radius: var(--wcai-border-radius);
    box-shadow: var(--wcai-shadow);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.9);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--wcai-border-color);
    overflow: hidden;
}

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

.wcai-chat-minimized .wcai-chat-window {
    display: none;
}

/* ===== CHAT HEADER ===== */
.wcai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--wcai-primary-color);
    color: white;
    border-radius: var(--wcai-border-radius) var(--wcai-border-radius) 0 0;
}

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

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

.wcai-store-avatar svg {
    width: 20px;
    height: 20px;
    color: white;
}

.wcai-store-details {
    flex: 1;
}

.wcai-store-name {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 2px;
}

.wcai-store-status {
    font-size: 12px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 6px;
}

.wcai-status-indicator {
    width: 8px;
    height: 8px;
    background: #4caf50;
    border-radius: 50%;
    display: inline-block;
}

.wcai-status-indicator.wcai-typing {
    background: #ff9800;
    animation: wcai-typing-pulse 1.5s infinite;
}

@keyframes wcai-typing-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

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

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

.wcai-minimize-btn:hover,
.wcai-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.wcai-minimize-btn svg,
.wcai-close-btn svg {
    width: 16px;
    height: 16px;
}

/* ===== MESSAGES CONTAINER ===== */
.wcai-messages-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.wcai-messages-list {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    scroll-behavior: smooth;
}

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

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

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

.wcai-messages-list::-webkit-scrollbar-thumb:hover {
    background: var(--wcai-primary-color);
}

/* ===== MESSAGES ===== */
.wcai-message {
    margin-bottom: 16px;
    display: flex;
    gap: 12px;
    animation: wcai-fade-in 0.3s ease;
}

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

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

.wcai-message-user .wcai-message-content {
    background: var(--wcai-primary-color);
    color: white;
    border-radius: 18px 18px 4px 18px;
    max-width: 80%;
}

.wcai-message-assistant {
    justify-content: flex-start;
}

.wcai-message-assistant .wcai-message-content {
    background: var(--wcai-secondary-color);
    color: var(--wcai-text-color);
    border-radius: 18px 18px 18px 4px;
    max-width: 85%;
}

.wcai-message-system .wcai-message-content {
    background: var(--wcai-warning-color);
    color: #856404;
    border-radius: 12px;
    text-align: center;
    margin: 0 auto;
    max-width: 90%;
}

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

.wcai-message-avatar svg {
    width: 16px;
    height: 16px;
    color: white;
}

.wcai-message-content {
    padding: 12px 16px;
    position: relative;
}

.wcai-message-text {
    word-wrap: break-word;
    line-height: 1.4;
}

.wcai-message-text h2,
.wcai-message-text h3 {
    margin: 8px 0 12px 0;
    color: inherit;
    font-size: 16px;
    font-weight: 600;
}

.wcai-message-text strong {
    font-weight: 600;
}

.wcai-message-text em {
    font-style: italic;
}

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

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

.wcai-message-text a {
    color: var(--wcai-primary-color);
    text-decoration: none;
}

.wcai-message-text a:hover {
    text-decoration: underline;
}

.wcai-message-image {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 8px 0;
}

.wcai-message-time {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
}

/* ===== PRODUCT DISPLAY ===== */
.wcai-product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin: 12px 0;
}

.wcai-product-card {
    border: 1px solid var(--wcai-border-color);
    border-radius: 8px;
    padding: 12px;
    background: var(--wcai-bg-color);
}

/* ===== ACTION BUTTONS ===== */
.wcai-action-button {
    background: var(--wcai-primary-color);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    margin: 2px 4px 2px 0;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.wcai-action-button:hover {
    background: var(--wcai-primary-color);
    opacity: 0.9;
    transform: translateY(-1px);
}

.wcai-action-button:active {
    transform: translateY(0);
}

/* ===== TOOL ACTIONS ===== */
.wcai-tool-actions {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--wcai-border-color);
}

.wcai-add-to-cart-btn {
    background: var(--wcai-success-color);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.wcai-add-to-cart-btn:hover:not(:disabled) {
    background: #218838;
    transform: translateY(-1px);
}

.wcai-add-to-cart-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.wcai-add-to-cart-btn.wcai-btn-success {
    background: var(--wcai-success-color);
}

.wcai-add-to-cart-btn.wcai-btn-error {
    background: var(--wcai-error-color);
}

.wcai-add-to-cart-btn svg {
    width: 16px;
    height: 16px;
}

/* ===== TYPING INDICATOR ===== */
.wcai-typing-indicator {
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--wcai-secondary-color);
    border-top: 1px solid var(--wcai-border-color);
}

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

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

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

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

.wcai-typing-text {
    font-size: 12px;
    color: var(--wcai-text-color);
    opacity: 0.7;
}

/* ===== INPUT CONTAINER ===== */
.wcai-input-container {
    border-top: 1px solid var(--wcai-border-color);
    background: var(--wcai-bg-color);
}

.wcai-input-wrapper {
    display: flex;
    align-items: end;
    padding: 16px 20px 12px;
    gap: 12px;
}

.wcai-message-input {
    flex: 1;
    border: 1px solid var(--wcai-border-color);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    background: var(--wcai-bg-color);
    color: var(--wcai-text-color);
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    min-height: 20px;
    max-height: 100px;
}

.wcai-message-input:focus {
    border-color: var(--wcai-primary-color);
}

.wcai-message-input::placeholder {
    color: #999;
}

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

.wcai-send-button:hover {
    background: var(--wcai-primary-color);
    opacity: 0.9;
    transform: scale(1.05);
}

.wcai-send-button:active {
    transform: scale(0.95);
}

.wcai-send-button svg {
    width: 18px;
    height: 18px;
}

.wcai-input-footer {
    padding: 8px 20px 12px;
    text-align: center;
}

.wcai-input-footer small {
    font-size: 11px;
    color: #999;
}

/* ===== SPINNER ===== */
.wcai-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: wcai-spin 1s linear infinite;
    display: inline-block;
}

@keyframes wcai-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== TOAST NOTIFICATIONS ===== */
.wcai-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--wcai-bg-color);
    color: var(--wcai-text-color);
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: var(--wcai-shadow);
    border: 1px solid var(--wcai-border-color);
    z-index: calc(var(--wcai-z-index) + 1);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    max-width: 300px;
    font-size: 14px;
}

.wcai-toast-show {
    transform: translateX(0);
}

.wcai-toast-success {
    border-left: 4px solid var(--wcai-success-color);
}

.wcai-toast-error {
    border-left: 4px solid var(--wcai-error-color);
}

.wcai-toast-warning {
    border-left: 4px solid var(--wcai-warning-color);
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    .wcai-widget-container {
        --wcai-chat-width: 100vw;
        --wcai-chat-height: 100vh;
    }
    
    .wcai-position-bottom-right,
    .wcai-position-bottom-left,
    .wcai-position-top-right,
    .wcai-position-top-left {
        bottom: 0;
        right: 0;
        left: 0;
        top: auto;
    }
    
    .wcai-chat-bubble {
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: var(--wcai-z-index);
    }
    
    .wcai-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        border: none;
    }
    
    .wcai-chat-header {
        border-radius: 0;
        padding: 16px 20px;
        padding-top: calc(16px + env(safe-area-inset-top));
    }
    
    .wcai-input-wrapper {
        padding: 16px 20px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
    
    .wcai-product-grid {
        grid-template-columns: 1fr;
    }
    
    .wcai-toast {
        right: 10px;
        left: 10px;
        max-width: none;
    }
}

@media (max-width: 480px) {
    .wcai-widget-container {
        --wcai-bubble-size: 56px;
    }
    
    .wcai-bubble-icon {
        width: 24px;
        height: 24px;
    }
    
    .wcai-store-name {
        font-size: 15px;
    }
    
    .wcai-input-wrapper {
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    
    .wcai-messages-list {
        padding: 16px;
    }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
    .wcai-widget-container *,
    .wcai-widget-container *::before,
    .wcai-widget-container *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== HIGH CONTRAST MODE ===== */
@media (prefers-contrast: high) {
    .wcai-widget-container {
        --wcai-border-color: #000000;
        --wcai-shadow-color: rgba(0, 0, 0, 0.5);
    }
    
    .wcai-theme-dark {
        --wcai-border-color: #ffffff;
        --wcai-shadow-color: rgba(255, 255, 255, 0.5);
    }
}

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