/**
 * Live AI Presta - Chat Widget Styles v2.1.0
 */

/* CSS Variables */
:root {
    --ai-chat-primary: #2196F3;
    --ai-chat-text: #333333;
    --ai-chat-text-light: #666666;
    --ai-chat-bg: #ffffff;
    --ai-chat-bg-light: #f5f5f5;
    --ai-chat-border: #e0e0e0;
    --ai-chat-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    --ai-chat-radius: 12px;
    --ai-chat-window-width: 380px;
    --ai-chat-window-height: 520px;
    --ai-chat-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --ai-chat-font-size: 14px;
}

/* Reset for widget */
.ai-chat-widget,
.ai-chat-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--ai-chat-font-family);
    font-size: var(--ai-chat-font-size);
}

/* Widget Container */
.ai-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
}

/* Position variant: bottom-left */
.ai-chat-widget.ai-chat-position-left {
    right: auto;
    left: 20px;
}

.ai-chat-widget.ai-chat-position-left .ai-chat-window {
    right: auto;
    left: 0;
}

/* Toggle Button */
.ai-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    box-shadow: var(--ai-chat-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.ai-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

.ai-chat-toggle:active {
    transform: scale(0.95);
}

.ai-chat-icon-close {
    display: none;
}

.ai-chat-widget.open .ai-chat-icon-open {
    display: none;
}

.ai-chat-widget.open .ai-chat-icon-close {
    display: block;
}

/* Chat Window */
.ai-chat-window {
    position: absolute;
    bottom: 75px;
    right: 0;
    width: var(--ai-chat-window-width);
    height: var(--ai-chat-window-height);
    background: var(--ai-chat-bg);
    border-radius: var(--ai-chat-radius);
    box-shadow: var(--ai-chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
}

.ai-chat-widget.open .ai-chat-window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    color: #ffffff;
    flex-shrink: 0;
}

.ai-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.ai-chat-avatar-img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.ai-chat-title {
    font-size: 16px;
    font-weight: 600;
}

.ai-chat-minimize {
    background: transparent;
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.ai-chat-minimize:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Messages Container */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--ai-chat-bg-light);
    position: relative;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: var(--ai-chat-border);
    border-radius: 3px;
}

/* Message Wrapper (holds bubble + timestamp + feedback) */
.ai-chat-message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    gap: 3px;
}

.ai-chat-message-wrapper.user {
    align-self: flex-end;
}

.ai-chat-message-wrapper.assistant {
    align-self: flex-start;
}

/* Message Bubble */
.ai-chat-message {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: var(--ai-chat-font-size);
    line-height: 1.5;
    word-wrap: break-word;
}

.ai-chat-message.user {
    background: var(--ai-chat-primary);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.ai-chat-message.assistant {
    background: var(--ai-chat-bg);
    color: var(--ai-chat-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Formatted message content */
.ai-chat-message .ai-msg-p {
    margin: 0 0 6px 0;
}

.ai-chat-message .ai-msg-p:last-child {
    margin-bottom: 0;
}

.ai-chat-message .ai-msg-list {
    margin: 6px 0;
    padding-left: 0;
    list-style: none;
}

.ai-chat-message .ai-msg-list li {
    position: relative;
    padding: 3px 0 3px 16px;
    font-size: 13px;
    line-height: 1.45;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.ai-chat-message .ai-msg-list li:last-child {
    border-bottom: none;
}

.ai-chat-message .ai-msg-list li::before {
    content: '•';
    position: absolute;
    left: 2px;
    top: 3px;
    color: var(--ai-chat-primary);
    font-weight: 700;
    font-size: 14px;
    line-height: 1.45;
}

.ai-chat-message .ai-msg-price {
    font-weight: 700;
    color: var(--ai-chat-primary);
    white-space: nowrap;
}

.ai-chat-message strong {
    font-weight: 700;
}

/* Products List */
.ai-chat-products {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

.ai-chat-product {
    background: var(--ai-chat-bg);
    border: 1px solid var(--ai-chat-border);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.ai-chat-product:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border-color: var(--ai-chat-primary);
}

.ai-chat-product-image {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    background: var(--ai-chat-bg-light);
    flex-shrink: 0;
}

.ai-chat-product-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.ai-chat-product-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--ai-chat-text);
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ai-chat-product-price {
    font-size: 14px;
    font-weight: 700;
    color: var(--ai-chat-primary);
}

.ai-chat-product-actions {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.ai-chat-product-cart-btn {
    background: var(--ai-chat-primary);
    color: #ffffff;
    border: none;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.2s ease;
}

.ai-chat-product-cart-btn:hover {
    opacity: 0.9;
}

.ai-chat-product-cart-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-chat-product-cart-btn--disabled {
    background: #9e9e9e !important;
    opacity: 0.6;
}

.ai-chat-clear-btn {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
    margin-left: auto;
    margin-right: 4px;
    line-height: 1;
    transition: color 0.2s;
}

.ai-chat-clear-btn:hover {
    color: #ffffff;
}

.ai-chat-product-category {
    font-size: 12px;
    font-weight: 700;
    color: var(--ai-chat-primary, #2196F3);
    padding: 6px 10px 3px;
    margin-top: 4px;
    border-top: 1px solid var(--ai-chat-border, #e0e0e0);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.ai-chat-product-category:first-child {
    border-top: none;
    margin-top: 0;
}

.ai-chat-product-stock-unavailable {
    font-size: 11px;
    color: #c62828;
    font-weight: 600;
    margin-top: 2px;
}

.ai-chat-product-view-btn {
    background: transparent;
    color: var(--ai-chat-text-light);
    border: 1px solid var(--ai-chat-border);
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: border-color 0.2s ease;
}

.ai-chat-product-view-btn:hover {
    border-color: var(--ai-chat-primary);
    color: var(--ai-chat-primary);
}

/* Typing Indicator */
.ai-chat-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--ai-chat-bg);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.ai-chat-typing span {
    width: 8px;
    height: 8px;
    background: var(--ai-chat-border);
    border-radius: 50%;
    animation: typingPulse 1.4s ease-in-out infinite;
}

.ai-chat-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-chat-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingPulse {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Input Container */
.ai-chat-input-container {
    padding: 12px 16px;
    background: var(--ai-chat-bg);
    border-top: 1px solid var(--ai-chat-border);
    flex-shrink: 0;
}

.ai-chat-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.ai-chat-input {
    flex: 1;
    border: 1px solid var(--ai-chat-border);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.2s ease;
}

.ai-chat-input:focus {
    border-color: var(--ai-chat-primary);
}

.ai-chat-input::placeholder {
    color: var(--ai-chat-text-light);
}

.ai-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    flex-shrink: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.ai-chat-send:hover {
    opacity: 0.9;
}

.ai-chat-send:active {
    transform: scale(0.95);
}

.ai-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-chat-footer {
    text-align: center;
    margin-top: 8px;
}

.ai-chat-powered {
    font-size: 11px;
    color: var(--ai-chat-text-light);
    opacity: 0.7;
}

/* Comparison Table */
.ai-chat-table-wrap {
    overflow-x: auto;
    margin: 8px 0;
    -webkit-overflow-scrolling: touch;
}

.ai-chat-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    line-height: 1.4;
    border: 1px solid var(--ai-chat-border);
    border-radius: 6px;
    overflow: hidden;
}

.ai-chat-table th,
.ai-chat-table td {
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid var(--ai-chat-border);
    white-space: nowrap;
}

.ai-chat-table th {
    background: var(--ai-chat-primary);
    color: #ffffff;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.ai-chat-table tbody tr:nth-child(even) {
    background: var(--ai-chat-bg-light);
}

.ai-chat-table tbody tr:hover {
    background: rgba(33, 150, 243, 0.06);
}

.ai-chat-table td .ai-msg-price {
    font-weight: 700;
}

/* Timestamp */
.ai-chat-timestamp {
    font-size: 10px;
    color: var(--ai-chat-text-light);
    opacity: 0.6;
    padding: 0 4px;
}

.ai-chat-message-wrapper.user .ai-chat-timestamp {
    text-align: right;
}

/* Feedback Buttons */
.ai-chat-feedback {
    display: flex;
    gap: 4px;
    padding: 2px 0;
}

.ai-chat-feedback-btn {
    background: transparent;
    border: 1px solid var(--ai-chat-border);
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    line-height: 1.4;
}

.ai-chat-feedback-btn:hover {
    background: var(--ai-chat-bg-light);
    border-color: var(--ai-chat-primary);
}

.ai-chat-feedback-thanks {
    font-size: 11px;
    color: var(--ai-chat-text-light);
    font-style: italic;
}

/* Product link in message text */
.ai-chat-message .ai-product-link {
    color: var(--ai-chat-primary);
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px dashed var(--ai-chat-primary);
    cursor: pointer;
    position: relative;
}

.ai-chat-message .ai-product-link:hover {
    opacity: 0.85;
}

/* Product Popover */
.ai-product-popover {
    position: absolute;
    z-index: 10;
    width: 240px;
    background: var(--ai-chat-bg);
    border-radius: 10px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
    border: 1px solid var(--ai-chat-border);
    overflow: hidden;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

.ai-product-popover.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.ai-product-popover-img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
    background: var(--ai-chat-bg-light);
}

.ai-product-popover-body {
    padding: 10px 12px;
}

.ai-product-popover-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--ai-chat-text);
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ai-product-popover-price {
    font-size: 15px;
    font-weight: 700;
    color: var(--ai-chat-primary);
    margin-bottom: 8px;
}

.ai-product-popover-stock {
    font-size: 11px;
    color: #c62828;
    font-weight: 600;
    margin-bottom: 6px;
}

.ai-product-popover-actions {
    display: flex;
    gap: 6px;
}

.ai-product-popover-actions .ai-popover-btn {
    flex: 1;
    padding: 7px 0;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    border: none;
    transition: opacity 0.15s;
}

.ai-product-popover-actions .ai-popover-btn:hover {
    opacity: 0.85;
}

.ai-popover-btn-cart {
    background: var(--ai-chat-primary);
    color: #ffffff;
}

.ai-popover-btn-cart:disabled {
    background: #9e9e9e;
    opacity: 0.6;
    cursor: not-allowed;
}

.ai-popover-btn-view {
    background: transparent;
    color: var(--ai-chat-text);
    border: 1px solid var(--ai-chat-border) !important;
}

.ai-popover-btn-view:hover {
    border-color: var(--ai-chat-primary) !important;
    color: var(--ai-chat-primary);
}

/* Mobile: popover takes more width and positions from bottom */
@media (max-width: 480px) {
    .ai-product-popover {
        width: calc(100% - 24px);
        left: 12px !important;
        right: 12px !important;
    }
}

/* Footer link */
.ai-chat-footer a.ai-chat-powered {
    text-decoration: none;
    color: var(--ai-chat-text-light);
    transition: color 0.2s;
}

.ai-chat-footer a.ai-chat-powered:hover {
    color: var(--ai-chat-primary);
}

/* Error Message */
.ai-chat-error {
    background: #fff3f3;
    border: 1px solid #ffcdd2;
    color: #c62828;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 13px;
    align-self: center;
    text-align: center;
}

/* Success Toast */
.ai-chat-toast {
    position: fixed;
    bottom: 100px;
    right: 30px;
    background: #4caf50;
    color: #ffffff;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 9999999;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.ai-chat-toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .ai-chat-widget {
        bottom: 10px;
        right: 10px;
    }

    .ai-chat-toggle {
        width: 54px;
        height: 54px;
    }

    .ai-chat-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        max-height: 500px;
        bottom: 70px;
        right: 0;
        left: auto !important;
        border-radius: 16px;
    }

    .ai-chat-product {
        flex-direction: column;
    }

    .ai-chat-product-image {
        width: 100%;
        height: 100px;
    }

    .ai-chat-product-actions {
        flex-direction: row;
    }
}

/* Print - Hide widget */
@media print {
    .ai-chat-widget {
        display: none !important;
    }
}
