/* AI Chatbot Styles */
[v-cloak] {
    display: none;
}

.ai-chatbot {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Toggle Button */
.chatbot-toggle {
    position: fixed;
    top: calc(var(--app-visual-viewport-center-y, 50vh) - 58px);
    right: -18px;
    width: 52px;
    height: 54px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-right: 0;
    border-radius: 18px 0 0 18px;
    background: linear-gradient(135deg, var(--voice-red, #e72c37), var(--voice-red-dark, #bd131f));
    color: white;
    font-size: 1.15rem;
    cursor: pointer;
    box-shadow: 0 12px 28px rgba(153, 16, 27, 0.28);
    transition: transform 180ms ease, box-shadow 180ms ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-toggle:hover,
.chatbot-toggle:focus-visible {
    color: #fff;
    transform: translateX(-3px);
    box-shadow: 0 16px 34px rgba(153, 16, 27, 0.35);
}

.chatbot-toggle:active {
    transform: translateX(-1px) scale(0.96);
}

.chatbot-toggle > i {
    line-height: 1;
    text-shadow: 0 2px 8px rgba(96, 8, 15, 0.28);
}

.chatbot-badge {
    position: absolute;
    top: -5px;
    right: auto;
    left: -5px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    border: 2px solid white;
}

/* Chat Window */
.chatbot-window {
    width: 450px;
    height: 600px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

.chatbot-window:not(.chatbot-open) {
    display: none !important;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.chatbot-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chatbot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.chatbot-header h6 {
    color: white;
    font-weight: 600;
}

.chatbot-header small {
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
}

.chatbot-actions {
    display: flex;
    gap: 8px;
}

.chatbot-actions .btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}

.chatbot-actions .btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chatbot-actions .chatbot-close-btn {
    border: 1px solid rgba(255, 255, 255, 0.32);
    background: rgba(31, 24, 87, 0.22);
}

.chatbot-actions .chatbot-close-btn:hover,
.chatbot-actions .chatbot-close-btn:focus-visible {
    background: rgba(180, 24, 48, 0.72);
}

/* Messages */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8f9fa;
    scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Message */
.message {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
}

.bot-message .message-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.user-message {
    flex-direction: row-reverse;
}

.user-message .message-avatar {
    background: #e2e8f0;
    color: #4a5568;
}

.message-content {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 12px;
    position: relative;
}

.bot-message .message-content {
    background: white;
    border: 1px solid #e2e8f0;
}

.user-message .message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.message-content p {
    margin: 0 0 8px 0;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin: 4px 0;
}

.message-time {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    opacity: 0.6;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #cbd5e0;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

.typing-label {
    display: block;
    margin-top: 4px;
    color: #66717f;
    font-size: 11px;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Product Cards */
.product-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-chatbot .product-card {
    background: #f8f9fa;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px;
    transition: all 0.2s;
}

.ai-chatbot .product-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

/* Header: Image + Name side by side */
.product-header {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.product-image {
    width: 60px;
    height: 60px;
    border-radius: 6px;
    flex-shrink: 0;
    overflow: hidden;
    background: #f0f0f0;
}

.product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.product-title {
    flex: 1;
    min-width: 0;
}

.product-name {
    font-size: 12px;
    font-weight: 600;
    color: #2d3748;
    line-height: 1.3;
}

.product-source-label {
    display: inline-flex;
    align-items: center;
    margin-top: 5px;
    padding: 2px 7px;
    border-radius: 999px;
    background: #edf7f1;
    color: #18794e;
    font-size: 10px;
    font-weight: 600;
    line-height: 1.4;
}

/* Details section below header */
.product-details {
    width: 100%;
}

.product-sku {
    font-size: 10px;
    color: #718096;
    margin: 0 0 4px 0;
}

.product-price {
    font-size: 13px;
    font-weight: 700;
    color: #667eea;
    margin: 0 0 4px 0;
}

.product-stock {
    font-size: 10px;
    margin: 0 0 6px 0;
}

.product-quantity-recommendation {
    display: flex;
    align-items: flex-start;
    gap: 5px;
    padding: 5px 7px;
    border-left: 2px solid var(--voice-red, #e72c37);
    border-radius: 0 7px 7px 0;
    background: #fff3f4;
    color: #7f1d24;
    font-size: 10px;
    font-weight: 650;
    line-height: 1.35;
}

.product-quantity-recommendation i {
    flex: 0 0 auto;
    margin-top: 1px;
    color: var(--voice-red, #e72c37);
}

/* Actions row: Quantity + Buttons */
.product-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

.product-actions .input-group {
    flex: 1;
    min-width: 0;
}

.product-actions .btn {
    font-size: 11px;
    padding: 4px 8px;
    flex-shrink: 0;
}

.ai-chatbot .product-card .input-group-sm .form-control,
.ai-chatbot .product-card .input-group-sm .btn {
    font-size: 11px;
    padding: 3px 6px;
}

.ai-chatbot .product-card .input-group-sm .input-group-text {
    font-size: 10px;
    padding: 3px 6px;
}

/* Quick Actions */
.chatbot-quick-actions {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-action-btn {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    color: #4a5568;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.quick-action-btn:hover {
    background: #edf2f7;
    border-color: #cbd5e0;
    transform: translateY(-1px);
}

.quick-action-btn i {
    font-size: 14px;
}

/* Input */
.chatbot-input {
    padding: 16px;
    background: white;
    border-top: 1px solid #e2e8f0;
}

.chatbot-input .input-group {
    display: flex;
    gap: 8px;
}

.chatbot-input input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.chatbot-input input:focus {
    border-color: #667eea;
}

.chatbot-input input:disabled {
    background: #f7fafc;
    cursor: not-allowed;
}

.chatbot-input .btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.chatbot-input .btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.chatbot-input .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chatbot-cart-confirmation {
    padding: 12px;
    border: 1px solid #f0b5ba;
    border-radius: 12px;
    background: #fff8f8;
}

.chatbot-cart-confirmation-title,
.chatbot-cart-confirmation-item,
.chatbot-cart-confirmation-actions,
.chatbot-cart-confirmation-status {
    display: flex;
    align-items: center;
}

.chatbot-cart-confirmation-title {
    gap: 7px;
    color: #b5121b;
}

.chatbot-cart-confirmation-items {
    margin: 9px 0;
    border-top: 1px solid #f2d7d9;
    border-bottom: 1px solid #f2d7d9;
}

.chatbot-cart-confirmation-item {
    justify-content: space-between;
    gap: 12px;
    padding: 7px 0;
    font-size: 0.84rem;
}

.chatbot-cart-confirmation-item + .chatbot-cart-confirmation-item {
    border-top: 1px solid #f6e5e6;
}

.chatbot-cart-confirmation-item span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.chatbot-cart-confirmation-item strong {
    white-space: nowrap;
}

.chatbot-cart-confirmation-actions {
    justify-content: flex-end;
    gap: 8px;
}

.chatbot-cart-confirmation-status {
    gap: 6px;
    font-weight: 600;
}

.chatbot-cart-confirmation-status.is-confirmed {
    color: #16804a;
}

.chatbot-cart-confirmation-status.is-cancelled,
.chatbot-cart-confirmation-status.is-failed {
    color: #6b7280;
}

/* Responsive */
@media (max-width: 480px) {
    .chatbot-window {
        width: calc(100vw - 40px);
        height: calc(var(--app-visual-viewport-height, 100dvh) - 40px);
        max-height: 600px;
    }
    
    .message-content {
        max-width: 80%;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .chatbot-window {
        background: #1a202c;
    }
    
    .chatbot-messages {
        background: #2d3748;
    }
    
    .bot-message .message-content {
        background: #374151;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .ai-chatbot .product-card {
        background: #374151;
        border-color: #4a5568;
    }

    .chatbot-cart-confirmation {
        background: #2f2427;
        border-color: #75434a;
    }

    .chatbot-cart-confirmation-items,
    .chatbot-cart-confirmation-item + .chatbot-cart-confirmation-item {
        border-color: #5a3a40;
    }
    
    .product-name {
        color: #e2e8f0;
    }
    
    .chatbot-input {
        background: #1a202c;
        border-top-color: #4a5568;
    }
    
    .chatbot-input input {
        background: #374151;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .quick-action-btn {
        background: #374151;
        border-color: #4a5568;
        color: #e2e8f0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chatbot-toggle,
    .chatbot-toggle > i,
    .chatbot-window,
    .message {
        animation: none !important;
        transition: none !important;
    }
}
