/* AI Chat Widget — JTL AI Connect */
:root {
    --ai-chat-primary: #000000;
    --ai-chat-accent: #F8BF00;
    --ai-chat-bg: #ffffff;
    --ai-chat-msg-user-bg: var(--ai-chat-primary);
    --ai-chat-msg-user-text: #ffffff;
    --ai-chat-msg-bot-bg: #f1f3f5;
    --ai-chat-msg-bot-text: #212529;
    --ai-chat-text: #212529;
    --ai-chat-border: #dee2e6;
    --ai-chat-radius: 12px;
    --ai-chat-shadow: 0 8px 32px rgba(0,0,0,0.15);
    --ai-chat-font: inherit;
    --ai-chat-z: 1019;
    --ai-chat-sidebar-width: 380px;
}

/* Floating Button */
.ai-chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--ai-chat-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: var(--ai-chat-z);
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    padding: 0;
}
.ai-chat-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0,0,0,0.25);
}
.ai-chat-btn svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}
.ai-chat-btn .ai-chat-close-icon { display: none; }
.ai-chat-btn.open { display: none; }

.ai-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #dc3545;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}
.ai-chat-badge:empty { display: none; }

@keyframes ai-chat-pulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(0,0,0,0.2); }
    50% { box-shadow: 0 4px 16px rgba(0,0,0,0.2), 0 0 0 8px rgba(0,123,255,0.2); }
}
.ai-chat-btn.pulse { animation: ai-chat-pulse 2s ease-in-out infinite; }

/* ===== Chat Window (shared) ===== */
.ai-chat-window {
    position: fixed;
    background: var(--ai-chat-bg);
    z-index: var(--ai-chat-z);
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--ai-chat-font);
    color: var(--ai-chat-text);
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.ai-chat-window.open { display: flex; }

/* ===== Floating Mode ===== */
.ai-chat-window.mode-floating {
    bottom: 92px;
    right: 24px;
    top: auto;
    left: auto;
    width: 380px;
    height: 520px;
    max-height: calc(100vh - 120px);
    border-radius: var(--ai-chat-radius);
    box-shadow: var(--ai-chat-shadow);
}

/* ===== Sidebar Mode ===== */
.ai-chat-window.mode-sidebar {
    top: var(--ai-chat-sidebar-top, 0px);
    right: 0;
    bottom: 0;
    left: auto;
    width: var(--ai-chat-sidebar-width);
    height: auto;
    border-radius: 0;
    box-shadow: -4px 0 24px rgba(0,0,0,0.1);
    border-left: 1px solid var(--ai-chat-border);
}

/* Header */
.ai-chat-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--ai-chat-primary);
    color: #fff;
    flex-shrink: 0;
    gap: 10px;
}
.ai-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}
.ai-chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.ai-chat-avatar svg {
    width: 20px;
    height: 20px;
    fill: #fff;
}
.ai-chat-header-info {
    flex: 1;
    min-width: 0;
}
.ai-chat-header-name {
    font-weight: 600;
    font-size: 14px;
    line-height: 1.2;
}
.ai-chat-header-status {
    font-size: 11px;
    opacity: 0.8;
}
.ai-chat-header-actions {
    display: flex;
    gap: 4px;
}
.ai-chat-header-actions button {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ai-chat-header-actions button:hover { opacity: 1; background: rgba(255,255,255,0.15); }
.ai-chat-header-actions button svg { width: 18px; height: 18px; fill: currentColor; }

/* Messages */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}
.ai-chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--ai-chat-radius);
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    flex-shrink: 0;
}
.ai-chat-msg.user {
    align-self: flex-end;
    background: var(--ai-chat-msg-user-bg);
    color: var(--ai-chat-msg-user-text);
    border-bottom-right-radius: 4px;
}
.ai-chat-msg.assistant {
    align-self: flex-start;
    background: var(--ai-chat-msg-bot-bg);
    color: var(--ai-chat-msg-bot-text);
    border-bottom-left-radius: 4px;
}
.ai-chat-msg.tool {
    align-self: flex-start;
    background: #e8f4fd;
    color: #495057;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 8px;
    font-style: italic;
}
.ai-chat-msg-time {
    font-size: 10px;
    opacity: 0;
    position: absolute;
    bottom: -16px;
    transition: opacity 0.2s;
    white-space: nowrap;
}
.ai-chat-msg:hover .ai-chat-msg-time { opacity: 0.6; }
.ai-chat-msg.user .ai-chat-msg-time { right: 0; }
.ai-chat-msg.assistant .ai-chat-msg-time { left: 0; }

/* Markdown-lite */
.ai-chat-msg strong { font-weight: 700; }
.ai-chat-msg em { font-style: italic; }
.ai-chat-msg code {
    background: rgba(0,0,0,0.06);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.9em;
    font-family: monospace;
}
.ai-chat-msg a {
    color: inherit;
    text-decoration: underline;
}
.ai-chat-msg.user a { color: #fff; }

/* Markdown Lists */
.ai-chat-list {
    margin: 2px 0;
    padding-left: 18px;
}
.ai-chat-list > li {
    margin: 6px 0 0;
    padding: 0;
    line-height: 1.35;
}
.ai-chat-list > li:first-child {
    margin-top: 0;
}
.ai-chat-list .ai-chat-list {
    margin: 1px 0 0;
    padding-left: 14px;
    font-size: 0.92em;
}
.ai-chat-list .ai-chat-list > li {
    margin: 0;
}

/* Markdown Tables */
.ai-chat-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin: 6px 0;
}
.ai-chat-table th,
.ai-chat-table td {
    padding: 5px 8px;
    border: 1px solid var(--ai-chat-border);
    text-align: left;
}
.ai-chat-table th {
    background: rgba(0,0,0,0.04);
    font-weight: 600;
    font-size: 11px;
}
.ai-chat-table tr:hover td {
    background: rgba(0,0,0,0.02);
}

/* Product Card */
.ai-chat-product {
    display: flex;
    background: #fff;
    border: 1px solid var(--ai-chat-border);
    border-radius: 8px;
    overflow: hidden;
    margin: 6px 0;
    width: 100%;
    align-self: stretch;
    flex-shrink: 0;
    min-height: 80px;
}
.ai-chat-product-img {
    width: 80px;
    min-height: 80px;
    flex-shrink: 0;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.ai-chat-product-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.ai-chat-product-info {
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    flex: 1;
}
.ai-chat-product-name {
    font-weight: 600;
    font-size: 13px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.ai-chat-product-price {
    font-weight: 700;
    font-size: 14px;
    color: var(--ai-chat-accent);
}
.ai-chat-product-actions {
    display: flex;
    gap: 6px;
    margin-top: 2px;
}
.ai-chat-product-actions button,
.ai-chat-product-actions a {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid var(--ai-chat-border);
    background: #fff;
    color: var(--ai-chat-text);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
    transition: background 0.15s;
}
.ai-chat-product-actions button:hover,
.ai-chat-product-actions a:hover {
    background: #f1f3f5;
}
.ai-chat-product-actions .ai-cart-btn {
    background: var(--ai-chat-accent);
    color: #fff;
    border-color: var(--ai-chat-accent);
}
.ai-chat-product-actions .ai-cart-btn:hover {
    opacity: 0.9;
}
.ai-chat-product-actions .ai-cart-btn.added {
    background: #28a745;
    border-color: #28a745;
}
.ai-chat-product-actions .ai-cart-btn svg {
    width: 12px;
    height: 12px;
    fill: currentColor;
}

/* Condensed Product Card */
.ai-chat-product-condensed {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px 5px 5px;
    background: #fff;
    border: 1px solid var(--ai-chat-border);
    border-radius: 8px;
    font-size: 13px;
    width: 100%;
    align-self: stretch;
    flex-shrink: 0;
}
.ai-chat-product-condensed-thumb {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    background: #f8f9fa;
}
.ai-chat-product-condensed-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.ai-chat-product-condensed-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ai-chat-text);
    text-decoration: none;
}
.ai-chat-product-condensed-name:hover {
    text-decoration: underline;
}
.ai-chat-product-condensed-price {
    font-weight: 700;
    color: var(--ai-chat-accent);
    white-space: nowrap;
    font-size: 13px;
}
.ai-cart-btn-sm {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: var(--ai-chat-accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
    transition: opacity 0.15s;
}
.ai-cart-btn-sm:hover { opacity: 0.85; }
.ai-cart-btn-sm.added { background: #28a745; }
.ai-cart-btn-sm svg { width: 14px; height: 14px; fill: currentColor; }

/* Sale Price */
.ai-chat-price-sale {
    color: #dc3545;
    font-weight: 700;
}
.ai-chat-price-original {
    text-decoration: line-through;
    color: #6c757d;
    font-weight: 400;
    font-size: 0.85em;
}
.ai-chat-price-discount {
    background: #dc3545;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 3px;
    vertical-align: middle;
}

/* Product Availability Status */
.ai-chat-product-unavailable {
    font-size: 11px;
    color: #dc3545;
    font-weight: 600;
    padding: 3px 8px;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
}
.ai-chat-product-variants {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid var(--ai-chat-accent);
    background: #fff;
    color: var(--ai-chat-accent);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
}
.ai-chat-product-variants:hover {
    background: var(--ai-chat-accent);
    color: #fff;
}
/* Condensed card status labels */
.ai-chat-product-condensed-status {
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
    padding: 2px 6px;
    border-radius: 4px;
    text-decoration: none;
}
.ai-chat-product-condensed-status.out-of-stock {
    color: #dc3545;
}
.ai-chat-product-condensed-status.has-variants {
    color: var(--ai-chat-accent);
    border: 1px solid var(--ai-chat-accent);
}
.ai-chat-product-condensed-status.has-variants:hover {
    background: var(--ai-chat-accent);
    color: #fff;
}

/* Show More Products Button */
.ai-chat-show-more {
    display: block;
    width: 100%;
    padding: 8px;
    background: none;
    border: 1px dashed var(--ai-chat-border);
    border-radius: 8px;
    color: var(--ai-chat-accent);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    flex-shrink: 0;
    transition: background 0.15s;
}
.ai-chat-show-more:hover {
    background: #f1f3f5;
}

/* Product Modal */
.ai-chat-modal {
    position: fixed;
    inset: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ai-chat-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
}
.ai-chat-modal-content {
    position: relative;
    background: var(--ai-chat-bg);
    border-radius: 16px;
    width: 94vw;
    max-width: 1100px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 16px 48px rgba(0,0,0,0.2);
    overflow: hidden;
}
.ai-chat-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--ai-chat-border);
    font-size: 15px;
}
.ai-chat-modal-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--ai-chat-text);
    opacity: 0.6;
    display: flex;
}
.ai-chat-modal-close:hover { opacity: 1; }
.ai-chat-modal-close svg { width: 20px; height: 20px; fill: currentColor; }
.ai-chat-modal-grid {
    padding: 16px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    grid-auto-rows: max-content;
    gap: 12px;
    flex: 1;
    min-height: 0;
}
.ai-chat-modal-card {
    background: #fff;
    border: 1px solid var(--ai-chat-border);
    border-radius: 8px;
    overflow: hidden;
}
.ai-chat-modal-card-img {
    width: 100%;
    height: 140px;
    background: #f8f9fa;
    overflow: hidden;
}
.ai-chat-modal-card-img img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    display: block;
}
.ai-chat-modal-card-name {
    font-weight: 600;
    font-size: 12px;
    line-height: 1.3;
    padding: 8px 10px 2px;
    min-height: 32px;
    color: #212529;
    overflow: hidden;
    text-overflow: ellipsis;
    line-clamp: 2;
    -webkit-line-clamp: 2;
}
.ai-chat-modal-card-price {
    font-weight: 700;
    font-size: 14px;
    color: var(--ai-chat-accent);
    padding: 2px 10px;
}
.ai-chat-modal-card-actions {
    padding: 6px 10px 8px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.ai-chat-modal-card-actions button,
.ai-chat-modal-card-actions a {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid var(--ai-chat-border);
    background: #fff;
    color: var(--ai-chat-text);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
}
.ai-chat-modal-card-actions .ai-cart-btn {
    background: var(--ai-chat-accent);
    color: #fff;
    border-color: var(--ai-chat-accent);
}
.ai-chat-modal-card-actions .ai-cart-btn:hover { opacity: 0.9; }
.ai-chat-modal-card-actions .ai-cart-btn.added {
    background: #28a745;
    border-color: #28a745;
}
.ai-chat-modal-card-actions .ai-cart-btn svg {
    width: 12px;
    height: 12px;
    fill: currentColor;
}

/* Typing Indicator */
.ai-chat-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    align-self: flex-start;
    background: var(--ai-chat-msg-bot-bg);
    border-radius: var(--ai-chat-radius);
    border-bottom-left-radius: 4px;
    flex-shrink: 0;
}
.ai-chat-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #adb5bd;
    animation: ai-chat-bounce 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 ai-chat-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Tool Status */
.ai-chat-tool-status {
    font-size: 12px;
    color: #6c757d;
    padding: 4px 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    align-self: flex-start;
    flex-shrink: 0;
}
.ai-chat-tool-status .spinner,
.spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #dee2e6;
    border-top-color: var(--ai-chat-accent);
    border-radius: 50%;
    animation: ai-chat-spin 0.8s linear infinite;
}
@keyframes ai-chat-spin {
    to { transform: rotate(360deg); }
}

/* Input Area */
.ai-chat-input {
    padding: 12px 16px;
    border-top: 1px solid var(--ai-chat-border);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
    background: var(--ai-chat-bg);
}
.ai-chat-input textarea {
    flex: 1;
    border: 1px solid var(--ai-chat-border);
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 16px; /* >= 16px prevents iOS zoom on focus */
    font-family: var(--ai-chat-font);
    resize: none;
    outline: none;
    max-height: 100px;
    line-height: 1.4;
    color: var(--ai-chat-text);
    background: var(--ai-chat-bg);
}
.ai-chat-input textarea:focus {
    border-color: var(--ai-chat-accent);
}
.ai-chat-input textarea::placeholder { color: #adb5bd; }
.ai-chat-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--ai-chat-accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s;
}
.ai-chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
.ai-chat-send svg { width: 18px; height: 18px; fill: currentColor; }

/* Powered by */
.ai-chat-powered {
    text-align: center;
    font-size: 10px;
    color: #adb5bd;
    padding: 4px;
    flex-shrink: 0;
}

/* Error state */
.ai-chat-error {
    background: #fff3cd;
    color: #856404;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    align-self: center;
    text-align: center;
    border: 1px solid #ffc107;
    flex-shrink: 0;
}

/* Quick Reply Buttons */
.ai-chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0;
    align-self: flex-start;
    flex-shrink: 0;
}
.ai-chat-quick-reply {
    background: var(--ai-chat-bg);
    border: 1.5px solid var(--ai-chat-accent);
    color: var(--ai-chat-text);
    font-size: 13px;
    padding: 6px 12px;
    border-radius: 16px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}
.ai-chat-quick-reply:hover {
    background: var(--ai-chat-accent);
    color: #fff;
}

/* ===== Sidebar open — overlay below header ===== */

/* Force cookie consent below chat */
div.ws5_oss_wrapper,
div.ws5_oss_wrapper.stickyTop,
div.ws5_oss_wrapper.stickyBottom,
body div.ws5_oss_wrapper,
#consent-settings-btn,
#consent-manager {
    z-index: 1018 !important;
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
    /* Always floating on mobile, fullscreen below header */
    .ai-chat-window.mode-sidebar,
    .ai-chat-window.mode-floating {
        /* top/height set dynamically via JS (visualViewport) */
        top: var(--ai-chat-sidebar-top, 0px);
        left: 0;
        right: 0;
        bottom: auto;
        width: 100vw;
        height: calc(100vh - var(--ai-chat-sidebar-top, 0px)); /* fallback, overridden by JS */
        max-height: none;
        border-radius: 0;
        border-left: none;
        box-shadow: none;
        z-index: 1019;
    }
    .ai-chat-btn {
        bottom: 16px;
        right: 16px;
        z-index: 1019; /* below mini cart dropdown */
    }
    /* Hide mode toggle on mobile */
    .ai-chat-mode-btn { display: none !important; }

    /* Lock body scroll when chat is open on mobile */
    html.ai-chat-mobile-open,
    html.ai-chat-mobile-open body {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
        height: 100% !important;
    }
}
