/* Chat Widget Styles */

/* Force Font Awesome icons - override theme's icon font (e.g., avenue-icons) */
.chat-floating-button .fa,
.chat-floating-button .fa:before,
.chat-container .fa,
.chat-container .fa:before,
.chat-widget-container .fa,
.chat-widget-container .fa:before {
    font-family: 'FontAwesome' !important;
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Explicit icon content definitions for common chat icons */
.chat-floating-button .fa-comment:before { content: "\f075" !important; }
.chat-floating-button .fa-comments:before { content: "\f086" !important; }
.chat-container .fa-minus:before,
.chat-widget-container .fa-minus:before { content: "\f068" !important; }
.chat-container .fa-times:before,
.chat-widget-container .fa-times:before { content: "\f00d" !important; }
.chat-container .fa-paper-plane:before,
.chat-widget-container .fa-paper-plane:before { content: "\f1d8" !important; }
.chat-container .fa-expand:before,
.chat-widget-container .fa-expand:before { content: "\f065" !important; }
.chat-container .fa-robot:before,
.chat-widget-container .fa-robot:before { content: "\f544" !important; }
.chat-container .fa-user:before,
.chat-widget-container .fa-user:before { content: "\f007" !important; }
.chat-container .fa-box:before,
.chat-widget-container .fa-box:before { content: "\f466" !important; }
.chat-container .fa-plus:before,
.chat-widget-container .fa-plus:before { content: "\f067" !important; }

.chat-floating-button {
    position: fixed;
    bottom: 74px;
    right: 20px;
    z-index: 9999;
}

.btn-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chat-accent-color, #007bff);
    border: none;
    color: white;
    font-size: 24px;
    box-shadow: 0 4px 12px var(--chat-accent-color-shadow, rgba(0, 123, 255, 0.4));
    transition: all 0.3s ease;
    cursor: pointer;
}

.btn-chat-toggle:hover {
    background: var(--chat-accent-color-dark, #0056b3);
    transform: scale(1.1);
    box-shadow: 0 6px 16px var(--chat-accent-color-shadow-hover, rgba(0, 123, 255, 0.6));
}

/* Notification Badge on Chat Button */
.chat-notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: #dc3545;
    color: white;
    border-radius: 11px;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(220, 53, 69, 0.5);
    border: 2px solid white;
}

.btn-chat-toggle {
    position: relative;
}

/* Pulse animation for notification */
.chat-floating-button.has-notification .btn-chat-toggle {
    animation: pulse-notification 2s infinite;
}

@@keyframes pulse-notification {
    0% {
        box-shadow: 0 4px 12px var(--chat-accent-color-shadow, rgba(0, 123, 255, 0.4));
    }
    50% {
        box-shadow: 0 4px 20px rgba(220, 53, 69, 0.6), 0 0 0 10px rgba(220, 53, 69, 0.1);
    }
    100% {
        box-shadow: 0 4px 12px var(--chat-accent-color-shadow, rgba(0, 123, 255, 0.4));
    }
}

.chat-container {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    height: calc(100vh - 120px);
    min-height: 400px;
    max-height: 700px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    transition: height 0.3s ease, bottom 0.3s ease;
}

/* Minimized state - shows only header bar */
.chat-container.minimized {
    height: 60px;
    min-height: 60px;
    bottom: 20px;
}

.chat-container.minimized .chat-messages,
.chat-container.minimized .chat-typing-indicator,
.chat-container.minimized .chat-input-container {
    display: none;
}

.chat-container.minimized .chat-header {
    cursor: pointer;
    border-radius: 12px;
}

.chat-container.minimized .btn-minimize i::before {
    content: "\f065"; /* fa-expand */
}

/* Hide return prompt and confirmation when minimized */
.chat-container.minimized .chat-return-prompt,
.chat-container.minimized .chat-confirm-modal {
    display: none !important;
}

/* Return prompt - shown after inactivity */
.chat-return-prompt {
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    padding: 16px;
    text-align: center;
}

.chat-return-prompt p {
    margin: 0 0 12px 0;
    font-size: 13px;
    color: #495057;
    line-height: 1.4;
}

.chat-return-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.chat-return-actions .btn-continue,
.chat-return-actions .btn-start-fresh {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-return-actions .btn-continue {
    background: var(--chat-accent-color, #007bff);
    color: white;
    border: none;
}

.chat-return-actions .btn-continue:hover {
    background: var(--chat-accent-color-dark, #0056b3);
}

.chat-return-actions .btn-start-fresh {
    background: white;
    color: var(--chat-accent-color, #007bff);
    border: 1px solid var(--chat-accent-color, #007bff);
}

.chat-return-actions .btn-start-fresh:hover {
    background: #f0f7ff;
}

/* Confirmation modal */
.chat-confirm-modal {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: 12px;
}

.chat-confirm-content {
    background: white;
    padding: 24px;
    border-radius: 12px;
    text-align: center;
    max-width: 280px;
    margin: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.chat-confirm-content p {
    margin: 0 0 20px 0;
    font-size: 14px;
    color: #495057;
    line-height: 1.5;
}

.chat-confirm-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.chat-confirm-actions .btn-cancel,
.chat-confirm-actions .btn-confirm {
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-confirm-actions .btn-cancel {
    background: #f8f9fa;
    color: #495057;
    border: 1px solid #dee2e6;
}

.chat-confirm-actions .btn-cancel:hover {
    background: #e9ecef;
}

.chat-confirm-actions .btn-confirm {
    background: var(--chat-accent-color, #007bff);
    color: white;
    border: none;
}

.chat-confirm-actions .btn-confirm:hover {
    background: var(--chat-accent-color-dark, #0056b3);
}

.chat-header {
    background: linear-gradient(135deg, var(--chat-accent-color, #007bff), var(--chat-accent-color-dark, #0056b3));
    color: white;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-title {
    display: flex;
    align-items: center;
    font-weight: 600;
    font-size: 16px;
}

.chat-title i {
    margin-right: 8px;
    font-size: 18px;
}

.chat-actions {
    display: flex;
    gap: 8px;
}

.btn-new-chat,
.btn-minimize,
.btn-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-new-chat:hover,
.btn-minimize:hover,
.btn-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8f9fa;
}

.message {
    display: flex;
    margin-bottom: 16px;
    animation: fadeInUp 0.3s ease;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    flex-shrink: 0;
}

.bot-message .message-avatar {
    background: var(--chat-accent-color-light, #e3f2fd);
    color: var(--chat-accent-color, #007bff);
}

.user-message {
    flex-direction: row-reverse;
}

.user-message .message-avatar {
    background: var(--chat-accent-color-light, #e3f2fd);
    color: var(--chat-accent-color, #007bff);
    margin-left: 12px;
    margin-right: 0;
}

.message-content {
    background: white;
    padding: 12px 16px;
    border-radius: 18px;
    max-width: 280px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.user-message .message-content {
    background: var(--chat-accent-color, #007bff);
    color: white;
}

/* Markdown formatting in chat messages */
.message-content p {
    margin: 0 0 8px 0;
    font-size: 14px;
    line-height: 1.4;
}
.message-content p:last-child {
    margin-bottom: 0;
}
.message-content strong {
    font-weight: 600;
}
.message-content em {
    font-style: italic;
}
.message-content code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
}
.message-content pre {
    background: #f4f4f4;
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}
.message-content pre code {
    background: none;
    padding: 0;
}
.message-content ul,
.message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}
.message-content li {
    margin: 4px 0;
}
.message-content a {
    color: var(--chat-accent-color, #007bff);
    text-decoration: underline;
}
.message-content a:hover {
    color: var(--chat-accent-color-dark, #0056b3);
}
/* User message markdown styles (inverted colors for contrast) */
.user-message .message-content code {
    background: rgba(255, 255, 255, 0.2);
}
.user-message .message-content pre {
    background: rgba(255, 255, 255, 0.1);
}
.user-message .message-content a {
    color: #fff;
}

.chat-input-container {
    padding: 16px;
    background: white;
    border-top: 1px solid #e9ecef;
}

.chat-input-wrapper {
    display: flex;
    align-items: center;
    background: #f8f9fa;
    border-radius: 24px;
    padding: 4px;
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    resize: none;
}

.chat-input::placeholder {
    color: #6c757d;
    opacity: 1;
}

.btn-send {
    background: var(--chat-accent-color, #007bff);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-send i,
.btn-send i::before {
    color: white !important;
}

.btn-send:hover:not(:disabled) {
    background: var(--chat-accent-color-dark, #0056b3);
}

.btn-send:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.chat-typing-indicator {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    font-size: 12px;
    color: #6c757d;
}

.typing-dots {
    display: flex;
    margin-right: 8px;
}

.typing-dots span {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #6c757d;
    margin: 0 1px;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@@keyframes typing {
    0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

@@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Product Cards */
.products-container {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 8px 0;
    animation: fadeInUp 0.3s ease;
}

.product-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    width: calc(50% - 6px);
    min-width: 140px;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s, box-shadow 0.2s;
}

.product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.product-card-image {
    height: 100px;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.product-card-image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.product-card-image i {
    font-size: 32px;
    color: #dee2e6;
}

.product-card-info {
    padding: 12px;
    flex: 1;
}

.product-card-name {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #212529;
    text-decoration: none;
    line-height: 1.3;
    max-height: 2.6em;
    overflow: hidden;
    margin-bottom: 6px;
}

.product-card-name:hover {
    color: var(--chat-accent-color, #007bff);
}

.product-card-price {
    font-size: 14px;
    font-weight: 700;
    color: #28a745;
    margin-bottom: 4px;
}

.product-card-stock {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
}

.product-card-stock.in-stock {
    background: #d4edda;
    color: #155724;
}

.product-card-stock.out-of-stock {
    background: #f8d7da;
    color: #721c24;
}

/* Button container for multiple buttons */
.product-card-buttons {
    display: flex;
    gap: 6px;
}

.product-card-btn {
    flex: 1;
    display: block;
    text-align: center;
    background: var(--chat-accent-color, #007bff);
    color: white;
    text-decoration: none;
    padding: 10px 8px;
    font-size: 11px;
    font-weight: 600;
    transition: all 0.2s ease;
    border: none;
    border-radius: 0;
    cursor: pointer;
    white-space: nowrap;
}

.product-card-btn:hover {
    background: var(--chat-accent-color-dark, #0056b3);
    color: white;
}

/* View product button - outline style */
.product-card-btn-view {
    background: transparent;
    color: var(--chat-accent-color, #007bff);
    border: 1px solid var(--chat-accent-color, #007bff);
}

.product-card-btn-view:hover {
    background: var(--chat-accent-color, #007bff);
    color: white;
}

/* Add to cart button - solid style */
.product-card-btn-cart {
    background: var(--chat-accent-color, #007bff);
    color: white;
}

.product-card-btn-cart:hover:not(:disabled) {
    background: var(--chat-accent-color-dark, #0056b3);
}

/* Button states */
.product-card-btn-cart.disabled,
.product-card-btn-cart:disabled {
    background: #ccc;
    color: #666;
    cursor: not-allowed;
    opacity: 0.7;
}

.product-card-btn-cart.loading {
    background: #6c757d;
    cursor: wait;
}

.product-card-btn-cart.success {
    background: #28a745;
}

.product-card-btn-cart.error {
    background: #dc3545;
}

/* Round corners for first and last buttons in container */
.product-card-buttons .product-card-btn:first-child {
    border-bottom-left-radius: 12px;
}

.product-card-buttons .product-card-btn:last-child {
    border-bottom-right-radius: 12px;
}

/* Topic Cards (for information queries - policies, FAQs, etc.) */
.topics-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 0;
    animation: fadeInUp 0.3s ease;
}

.topic-card {
    display: flex;
    align-items: center;
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 10px;
    padding: 12px;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
    cursor: pointer;
}

.topic-card:hover {
    border-color: var(--chat-accent-color, #007bff);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transform: translateX(2px);
}

.topic-card-icon {
    width: 40px;
    height: 40px;
    background: var(--chat-accent-color-light, #e3f2fd);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-right: 12px;
}

.topic-card-icon i {
    font-size: 18px;
    color: var(--chat-accent-color, #007bff);
}

.topic-card-content {
    flex: 1;
    min-width: 0;
}

.topic-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--chat-accent-color, #007bff);
    line-height: 1.3;
    margin-bottom: 2px;
}

.topic-card-summary {
    font-size: 12px;
    color: #6c757d;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.topic-card-arrow {
    flex-shrink: 0;
    margin-left: 12px;
    color: #adb5bd;
    transition: transform 0.2s ease, color 0.2s ease;
}

.topic-card:hover .topic-card-arrow {
    transform: translateX(3px);
    color: var(--chat-accent-color, #007bff);
}

/* Cart Items Preview (for cart abandonment message) */
.cart-items-preview {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 12px;
    margin-top: 8px;
    animation: fadeInUp 0.3s ease;
}

a.cart-preview-item {
    display: flex;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #e9ecef;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-radius: 6px;
    margin: 0 -4px;
    padding-left: 4px;
    padding-right: 4px;
}

a.cart-preview-item:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

a.cart-preview-item:last-of-type {
    border-bottom: none;
}

a.cart-preview-item:first-of-type {
    padding-top: 0;
}

.cart-preview-image {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    overflow: hidden;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.cart-preview-image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.cart-preview-image i {
    font-size: 20px;
    color: #dee2e6;
}

.cart-preview-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.cart-preview-name {
    font-size: 13px;
    font-weight: 600;
    color: #212529;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cart-preview-details {
    font-size: 12px;
    color: #6c757d;
    margin-top: 2px;
}

/* Cart Preview Actions (Go to Cart button) */
.cart-preview-actions {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e9ecef;
    text-align: center;
}

.cart-preview-button {
    display: inline-block;
    background: var(--chat-accent-color, #007bff);
    color: white;
    padding: 10px 24px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: background-color 0.2s ease, transform 0.2s ease;
    cursor: pointer;
}

.cart-preview-button:hover {
    background: var(--chat-accent-color-dark, #0056b3);
    transform: translateY(-1px);
    color: white;
    text-decoration: none;
}

.cart-preview-button:active {
    transform: translateY(0);
}

/* Mobile responsive */
@@media (max-width: 768px) {
    .chat-container {
        width: calc(100vw - 40px);
        /* Use dvh with vh fallback for mobile keyboard handling */
        height: calc(100vh - 140px);
        height: calc(100dvh - 140px);
        bottom: 90px;
        left: 20px;
        right: auto; /* Clear desktop right positioning */
        transition: height 0.2s ease, bottom 0.2s ease;
    }

    .chat-container.keyboard-open {
        /* When keyboard is open, container height is set dynamically via JS */
    }

    .chat-input-container {
        flex-shrink: 0;
    }

    .chat-floating-button {
        bottom: 20px;
        right: 20px;
    }

    .product-card {
        width: 100%;
        min-width: auto;
    }

    .product-card-image {
        height: 80px;
    }
}