/* ==========================================================================
   AI Wheel Expert — Chat Styles (widget + dedicated page)
   ========================================================================== */

/* ---------------------------------------------------------------------------
   CSS Variables
   --------------------------------------------------------------------------- */
:root {
    --ai-primary: #3688fc;
    --ai-primary-light: #5a9ffd;
    --ai-primary-dark: #2a6fd4;
    --ai-bg: #f8f9fa;
    --ai-msg-user: #3688fc;
    --ai-msg-user-text: #fff;
    --ai-msg-assistant: #fff;
    --ai-msg-assistant-text: #212529;
    --ai-border: #dee2e6;
    --ai-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    --ai-radius: 12px;
    --ai-widget-width: 400px;
    --ai-widget-z: 1050;
}

[data-bs-theme="dark"] {
    --ai-bg: #1a1d21;
    --ai-msg-user: #3688fc;
    --ai-msg-user-text: #fff;
    --ai-msg-assistant: #2b2f33;
    --ai-msg-assistant-text: #e0e0e0;
    --ai-border: #3a3f44;
    --ai-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

/* ---------------------------------------------------------------------------
   Shared Chat Components
   --------------------------------------------------------------------------- */

/* Message bubbles */
.ai-message {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    animation: ai-fade-in 0.3s ease;
}

@keyframes ai-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.ai-message--user {
    flex-direction: row-reverse;
}

.ai-message__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

.ai-message--assistant .ai-message__avatar {
    background: var(--ai-primary);
    color: #fff;
}

.ai-message--user .ai-message__avatar {
    background: #6c757d;
    color: #fff;
}

.ai-message__bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: var(--ai-radius);
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
}

.ai-message--user .ai-message__bubble {
    background: var(--ai-msg-user);
    color: var(--ai-msg-user-text);
    border-bottom-right-radius: 4px;
}

.ai-message--assistant .ai-message__bubble {
    background: var(--ai-msg-assistant);
    color: var(--ai-msg-assistant-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--ai-border);
}

/* Typing indicator */
.ai-typing {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.ai-typing__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ai-primary-light);
    animation: ai-typing-bounce 1.2s infinite ease-in-out;
}

.ai-typing__dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing__dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-typing-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Product cards in chat */
.ai-products {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
}

.ai-product-card {
    flex: 0 0 180px;
    background: var(--ai-msg-assistant);
    border: 1px solid var(--ai-border);
    border-radius: 8px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.2s, transform 0.2s;
}

.ai-product-card:hover {
    box-shadow: var(--ai-shadow);
    transform: translateY(-2px);
    color: inherit;
    text-decoration: none;
}

.ai-product-card__img {
    width: 100%;
    height: 120px;
    object-fit: contain;
    background: #f5f5f5;
    padding: 8px;
}

[data-bs-theme="dark"] .ai-product-card__img {
    background: #2b2f33;
}

.ai-product-card__body {
    padding: 8px 10px;
}

.ai-product-card__sku {
    font-size: 12px;
    font-weight: 600;
    color: var(--ai-primary);
    margin-bottom: 2px;
}

.ai-product-card__specs {
    font-size: 11px;
    color: #6c757d;
    margin-bottom: 4px;
}

.ai-product-card__price {
    font-size: 14px;
    font-weight: 700;
    color: var(--ai-primary-dark);
}

.ai-product-card__stock {
    font-size: 11px;
    margin-left: 6px;
}

.ai-product-card__stock--in { color: #2e7d32; }
.ai-product-card__stock--out { color: #dc3545; }

/* Input area */
.ai-input {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--ai-border);
    background: var(--ai-bg);
}

.ai-input__field {
    flex: 1;
    border: 1px solid var(--ai-border);
    border-radius: 24px;
    padding: 8px 16px;
    font-size: 14px;
    outline: none;
    background: var(--ai-msg-assistant);
    color: var(--ai-msg-assistant-text);
    transition: border-color 0.2s;
}

.ai-input__field:focus {
    border-color: var(--ai-primary);
}

.ai-input__field:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-input__send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--ai-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.ai-input__send:hover { background: var(--ai-primary-dark); }
.ai-input__send:disabled { opacity: 0.4; cursor: not-allowed; }

/* Remaining count */
.ai-remaining {
    text-align: center;
    font-size: 12px;
    color: #6c757d;
    padding: 4px 12px;
    border-top: 1px solid var(--ai-border);
}

.ai-remaining--low { color: #e65100; }
.ai-remaining--zero { color: #dc3545; font-weight: 600; }

/* Error state */
.ai-error {
    background: #fff3e0;
    color: #e65100;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin: 8px 0;
}

[data-bs-theme="dark"] .ai-error {
    background: #3e2723;
    color: #ffab91;
}

/* Welcome message */
.ai-welcome {
    text-align: center;
    padding: 32px 20px;
    color: #6c757d;
}

.ai-welcome__icon {
    font-size: 48px;
    color: var(--ai-primary);
    margin-bottom: 12px;
}

.ai-welcome__title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--ai-msg-assistant-text);
}

.ai-welcome__subtitle {
    font-size: 14px;
    line-height: 1.5;
}

.ai-welcome__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 16px;
}

.ai-welcome__suggestion {
    padding: 6px 14px;
    border: 1px solid var(--ai-border);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    background: var(--ai-msg-assistant);
    color: var(--ai-msg-assistant-text);
    transition: border-color 0.2s, background 0.2s;
}

.ai-welcome__suggestion:hover {
    border-color: var(--ai-primary);
    background: rgba(46, 125, 50, 0.05);
}

/* ---------------------------------------------------------------------------
   Floating Widget
   --------------------------------------------------------------------------- */

/* Widget trigger button */
.ai-widget-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--ai-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: var(--ai-widget-z);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.ai-widget-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.ai-widget-btn--active {
    background: #6c757d;
}

/* Widget panel */
.ai-widget-panel {
    position: fixed;
    bottom: 0;
    right: 0;
    width: var(--ai-widget-width);
    height: 70vh;
    max-height: 600px;
    background: var(--ai-bg);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    z-index: var(--ai-widget-z);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    pointer-events: none;
}

.ai-widget-panel--open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* Widget header */
.ai-widget-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--ai-border);
    background: var(--ai-primary);
    color: #fff;
    border-radius: 16px 16px 0 0;
}

.ai-widget-header__title {
    flex: 1;
    font-weight: 600;
    font-size: 15px;
}

.ai-widget-header__actions {
    display: flex;
    gap: 8px;
}

.ai-widget-header__btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 18px;
    opacity: 0.8;
    padding: 4px;
    line-height: 1;
}

.ai-widget-header__btn:hover {
    opacity: 1;
}

/* Widget messages area */
.ai-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* Widget full-page link */
.ai-widget-expand {
    display: block;
    text-align: center;
    padding: 6px;
    font-size: 12px;
    color: var(--ai-primary);
    text-decoration: none;
    border-top: 1px solid var(--ai-border);
}

.ai-widget-expand:hover {
    text-decoration: underline;
}

/* ---------------------------------------------------------------------------
   Dedicated Chat Page
   --------------------------------------------------------------------------- */

.ai-page {
    display: flex;
    height: calc(100vh - 140px);
    min-height: 500px;
}

.ai-page__chat {
    flex: 3;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--ai-border);
    min-width: 0;
}

.ai-page__chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--ai-border);
}

.ai-page__chat-title {
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ai-msg-assistant-text);
}

.ai-page__chat-title i {
    color: var(--ai-primary);
    font-size: 20px;
}

.ai-page__new-chat-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ai-primary);
    background: transparent;
    border: 1px solid var(--ai-border);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.ai-page__new-chat-btn:hover {
    background: rgba(54, 136, 252, 0.08);
    border-color: var(--ai-primary);
}

.ai-page__results {
    flex: 2;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.ai-page__results-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--ai-border);
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-page__results-count {
    background: var(--ai-primary);
    color: #fff;
    border-radius: 12px;
    padding: 1px 8px;
    font-size: 12px;
    font-weight: 600;
}

.ai-page__results-grid {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ai-page__results-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: #6c757d;
    font-size: 14px;
    text-align: center;
    padding: 32px;
}

.ai-page__messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Page product cards — horizontal layout for dense list */
.ai-page-product {
    background: var(--ai-msg-assistant);
    border: 1px solid var(--ai-border);
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.2s, border-color 0.2s;
    display: flex;
    align-items: center;
    padding: 10px;
    gap: 12px;
}

.ai-page-product:hover {
    box-shadow: var(--ai-shadow);
    border-color: var(--ai-primary);
    color: inherit;
    text-decoration: none;
}

.ai-page-product__img {
    width: 80px;
    height: 80px;
    min-width: 80px;
    object-fit: contain;
    background: #f5f5f5;
    border-radius: 6px;
    padding: 6px;
    flex-shrink: 0;
}

[data-bs-theme="dark"] .ai-page-product__img {
    background: #2b2f33;
}

.ai-page-product__body {
    flex: 1 1 0%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    line-height: 1.3;
}

.ai-page-product__sku {
    font-size: 13px;
    font-weight: 700;
    color: var(--ai-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-page-product__desc {
    font-size: 12px;
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-transform: capitalize;
}

.ai-page-product__specs {
    font-size: 12px;
    color: #495057;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-page-product__row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 2px;
}

.ai-page-product__price {
    font-size: 15px;
    font-weight: 700;
    color: var(--ai-primary-dark);
}

.ai-page-product__stock {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

.ai-page-product__stock--in {
    background: rgba(46, 125, 50, 0.1);
    color: #2e7d32;
}

.ai-page-product__stock--out {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
}

/* ---------------------------------------------------------------------------
   Mobile Tab Toggle (dedicated page)
   --------------------------------------------------------------------------- */

.ai-page__tabs {
    display: none;
    border-bottom: 1px solid var(--ai-border);
}

.ai-page__tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    color: #6c757d;
}

.ai-page__tab--active {
    color: var(--ai-primary);
    border-bottom-color: var(--ai-primary);
}

/* ---------------------------------------------------------------------------
   Mobile Responsive
   --------------------------------------------------------------------------- */

/* Widget: hide floating button on mobile (Ask AI is in bottom nav) */
@media (max-width: 767.98px) {
    .ai-widget-btn,
    .ai-widget-panel {
        display: none !important;
    }
}

/* Tablet: show widget panel full-width when opened */
@media (max-width: 991px) and (min-width: 768px) {
    .ai-widget-panel {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .ai-widget-header {
        border-radius: 0;
    }
}

/* Dedicated page: single column with tab toggle on mobile */
@media (max-width: 991px) {
    .ai-page {
        flex-direction: column;
        height: calc(100vh - 200px);
    }

    .ai-page__chat {
        border-right: none;
    }

    .ai-page__tabs {
        display: flex;
    }

    .ai-page__results {
        display: none;
    }

    .ai-page__results--visible {
        display: flex;
    }

    .ai-page__chat--hidden {
        display: none;
    }
}

/* Hide widget on the dedicated AI page */
body.ai-chat-page .ai-widget-btn,
body.ai-chat-page .ai-widget-panel {
    display: none !important;
}

/* ==========================================================================
   AI Landing Page (anonymous / unverified users)
   ========================================================================== */

.ai-landing {
    max-width: 1100px;
    margin: 0 auto;
    padding: 40px 20px 60px;
}

.ai-landing__hero {
    text-align: center;
    padding: 40px 20px 50px;
}

.ai-landing__hero-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--ai-primary), var(--ai-primary-dark));
    color: #fff;
    border-radius: 50%;
    font-size: 40px;
    margin-bottom: 20px;
    box-shadow: 0 8px 24px rgba(54, 136, 252, 0.3);
}

.ai-landing__title {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 16px;
    color: var(--ai-msg-assistant-text);
    line-height: 1.2;
}

.ai-landing__subtitle {
    font-size: 1.125rem;
    color: #6c757d;
    max-width: 680px;
    margin: 0 auto 32px;
    line-height: 1.6;
}

.ai-landing__cta {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.ai-landing__btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 14px 28px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.ai-landing__btn--primary {
    background: var(--ai-primary);
    color: #fff;
}

.ai-landing__btn--primary:hover {
    background: var(--ai-primary-dark);
    color: #fff;
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(54, 136, 252, 0.3);
}

.ai-landing__btn--secondary {
    background: transparent;
    color: var(--ai-primary);
    border-color: var(--ai-primary);
}

.ai-landing__btn--secondary:hover {
    background: var(--ai-primary);
    color: #fff;
    text-decoration: none;
}

.ai-landing__note {
    font-size: 0.875rem;
    color: #6c757d;
    margin: 0;
}

.ai-landing__notice {
    background: #fff3e0;
    color: #e65100;
    padding: 14px 20px;
    border-radius: 8px;
    font-size: 0.95rem;
    margin-bottom: 16px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

[data-bs-theme="dark"] .ai-landing__notice {
    background: #3e2723;
    color: #ffab91;
}

/* Features grid */
.ai-landing__features {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    margin: 40px 0 60px;
}

.ai-landing__feature {
    text-align: center;
    padding: 28px 20px;
    background: var(--ai-msg-assistant);
    border: 1px solid var(--ai-border);
    border-radius: 12px;
    transition: box-shadow 0.2s, transform 0.2s;
}

.ai-landing__feature:hover {
    box-shadow: var(--ai-shadow);
    transform: translateY(-4px);
}

.ai-landing__feature-icon {
    font-size: 40px;
    color: var(--ai-primary);
    margin-bottom: 14px;
    display: block;
}

.ai-landing__feature h3 {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--ai-msg-assistant-text);
}

.ai-landing__feature p {
    font-size: 0.9375rem;
    color: #6c757d;
    line-height: 1.5;
    margin: 0;
}

/* Example questions */
.ai-landing__examples {
    margin: 60px 0;
}

.ai-landing__examples h2 {
    text-align: center;
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 32px;
    color: var(--ai-msg-assistant-text);
}

.ai-landing__example-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.ai-landing__example {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--ai-msg-assistant);
    border: 1px solid var(--ai-border);
    border-radius: 8px;
    font-size: 0.9375rem;
    color: var(--ai-msg-assistant-text);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ai-landing__example:hover {
    border-color: var(--ai-primary);
    box-shadow: var(--ai-shadow);
}

.ai-landing__example i {
    color: var(--ai-primary);
    font-size: 20px;
    flex-shrink: 0;
}

/* Bottom CTA */
.ai-landing__cta-bottom {
    text-align: center;
    padding: 40px 20px;
    background: linear-gradient(135deg, rgba(54, 136, 252, 0.05), rgba(54, 136, 252, 0.1));
    border-radius: 16px;
    margin-top: 40px;
}

.ai-landing__cta-bottom h2 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--ai-msg-assistant-text);
}

.ai-landing__cta-bottom p {
    font-size: 1rem;
    color: #6c757d;
    margin-bottom: 24px;
    max-width: 540px;
    margin-left: auto;
    margin-right: auto;
}

/* Mobile responsive */
@media (max-width: 767.98px) {
    .ai-landing {
        padding: 20px 16px 40px;
    }

    .ai-landing__hero {
        padding: 20px 10px 30px;
    }

    .ai-landing__title {
        font-size: 1.875rem;
    }

    .ai-landing__subtitle {
        font-size: 1rem;
    }

    .ai-landing__features {
        grid-template-columns: 1fr;
        gap: 16px;
        margin: 30px 0 40px;
    }

    .ai-landing__example-grid {
        grid-template-columns: 1fr;
    }

    .ai-landing__btn {
        width: 100%;
        justify-content: center;
    }
}
