/* ============================================
   AI Chat Widget Styles
   ============================================ */

.ai-chat-widget {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 10000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    transition: bottom 0.3s ease;
}

/* Floating Toggle Button */
.ai-chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(34, 197, 94, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    color: white;
    position: relative;
}

.ai-chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.5);
}

.ai-chat-toggle-btn:active {
    transform: scale(0.95);
}

.ai-chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #fff;
    color: #22c55e;
    font-size: 10px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Chat Popup */
.ai-chat-popup {
    position: absolute;
    bottom: 80px;
    left: 0;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 550px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
}

.ai-chat-popup.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.ai-chat-header {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
}

.ai-chat-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-chat-logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    object-fit: cover;
    background: white;
    padding: 2px;
}

.ai-chat-logo-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-header-text h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.ai-chat-header-text p {
    margin: 2px 0 0 0;
    font-size: 12px;
    opacity: 0.9;
}

.ai-chat-header-actions {
    display: flex;
    gap: 8px;
}

.ai-chat-clear-btn,
.ai-chat-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.ai-chat-clear-btn:hover,
.ai-chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Messages Area */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8fafc;
    scroll-behavior: smooth;
}

.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Message Styles */
.ai-chat-message {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-chat-message.user-message {
    flex-direction: row-reverse;
}

.ai-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-avatar {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: white;
}

.ai-chat-message.user-message .ai-chat-avatar {
    background: #6366f1;
}

.ai-chat-content {
    max-width: 75%;
}

.ai-chat-bubble {
    background: white;
    padding: 12px 16px;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    line-height: 1.5;
    font-size: 14px;
    color: #334155;
}

.ai-message .ai-chat-bubble {
    border-top-left-radius: 4px;
}

.ai-chat-message.user-message .ai-chat-bubble {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: white;
    border-top-right-radius: 4px;
}

.ai-chat-bubble p {
    margin: 0 0 8px 0;
}

.ai-chat-bubble p:last-child {
    margin: 0;
}

.ai-chat-bubble code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.ai-chat-message.user-message .ai-chat-bubble code {
    background: rgba(255, 255, 255, 0.2);
}

.ai-chat-bubble pre {
    background: rgba(0, 0, 0, 0.1);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.ai-chat-message.user-message .ai-chat-bubble pre {
    background: rgba(255, 255, 255, 0.2);
}

.ai-chat-bubble pre code {
    background: none;
    padding: 0;
}

.ai-chat-time {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 4px;
    display: block;
}

.ai-chat-message.user-message .ai-chat-time {
    text-align: right;
}

/* Typing Indicator */
.ai-chat-typing {
    display: flex;
    gap: 12px;
    padding: 0 20px 20px;
    animation: slideIn 0.3s ease;
}

.ai-chat-typing-dots {
    background: white;
    padding: 12px 20px;
    border-radius: 16px;
    border-top-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    gap: 4px;
    align-items: center;
}

.ai-chat-typing-dots span {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.ai-chat-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-chat-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* Input Area */
.ai-chat-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e2e8f0;
}

.ai-chat-form {
    margin-bottom: 8px;
}

.ai-chat-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
}

.ai-chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
}

.ai-chat-input:focus {
    border-color: #22c55e;
}

.ai-chat-input::placeholder {
    color: #94a3b8;
}

.ai-chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.ai-chat-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4);
}

.ai-chat-send-btn:active {
    transform: scale(0.95);
}

.ai-chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.ai-chat-send-btn.stopping {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    cursor: pointer;
}

.ai-chat-send-btn.stopping:hover {
    background: linear-gradient(135deg, #f87171 0%, #ef4444 100%);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.ai-chat-send-btn.stopping:active {
    transform: scale(0.95);
}

.ai-chat-footer {
    text-align: center;
}

.ai-chat-footer-text {
    font-size: 11px;
    color: #94a3b8;
}

/* Error Message */
.ai-chat-error {
    background: #fee2e2;
    color: #dc2626;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ============================================================
   MOBILE APP-LIKE RESPONSIVE
   ============================================================ */
@media (max-width: 640px) {
    .ai-chat-widget {
        bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
        left: auto;
        right: 0.75rem;
        z-index: 10001;
    }

    /* Move the AI toggle higher on product show pages to clear the mobile sticky bar */
    .page-product-show .ai-chat-widget {
        bottom: calc(7.5rem + env(safe-area-inset-bottom, 0px));
    }

    /* Move the AI toggle up when the cart side panel is open to clear the checkout bar */
    .cart-panel.open ~ .ai-chat-widget {
        bottom: calc(8rem + env(safe-area-inset-bottom, 0px));
    }

    .ai-chat-toggle-btn {
        width: 56px;
        height: 56px;
        box-shadow: 0 6px 22px rgba(34, 197, 94, 0.45);
    }

    .ai-chat-toggle-btn svg {
        width: 26px;
        height: 26px;
    }

    /* Floating conversation popup on small mobile */
    .ai-chat-popup {
        position: absolute;
        bottom: 80px;
        left: auto;
        right: 0;
        width: calc(100vw - 32px);
        max-width: 360px;
        height: 520px;
        max-height: calc(100vh - 220px);
        background: white;
        border-radius: 20px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
        opacity: 0;
        visibility: hidden;
        transform: translateY(20px) scale(0.95);
        transition: all 0.3s ease;
    }

    .ai-chat-popup.open {
        opacity: 1;
        visibility: visible;
        transform: translateY(0) scale(1);
    }

    /* No pull handle on floating popup */
    .ai-chat-popup::before {
        display: none;
    }

    .ai-chat-header {
        padding: 14px 16px 12px;
        border-radius: 20px 20px 0 0;
    }

    .ai-chat-header-content {
        gap: 10px;
    }

    .ai-chat-logo,
    .ai-chat-logo-placeholder {
        width: 42px;
        height: 42px;
        border-radius: 12px;
    }

    .ai-chat-header-text h3 {
        font-size: 16px;
        font-weight: 700;
    }

    .ai-chat-header-text p {
        font-size: 11px;
    }

    .ai-chat-header-actions {
        gap: 6px;
    }

    .ai-chat-clear-btn,
    .ai-chat-close-btn {
        width: 38px;
        height: 38px;
        border-radius: 10px;
    }

    .ai-chat-messages {
        flex: 1;
        padding: 16px;
    }

    .ai-chat-message {
        gap: 10px;
        margin-bottom: 14px;
    }

    .ai-chat-avatar {
        width: 34px;
        height: 34px;
        border-radius: 10px;
    }

    .ai-chat-content {
        max-width: 82%;
    }

    .ai-chat-bubble {
        padding: 12px 14px;
        font-size: 15px;
        border-radius: 18px;
        line-height: 1.45;
    }

    .ai-message .ai-chat-bubble {
        border-top-left-radius: 4px;
    }

    .ai-chat-message.user-message .ai-chat-bubble {
        border-top-right-radius: 4px;
    }

    .ai-chat-time {
        font-size: 10px;
    }

    .ai-chat-typing {
        padding: 0 16px 16px;
    }

    .ai-chat-input-area {
        flex-shrink: 0;
        padding: 12px 16px;
        background: white;
        border-top: 1px solid #e2e8f0;
        border-radius: 0 0 20px 20px;
    }

    .ai-chat-form {
        margin-bottom: 0;
    }

    .ai-chat-input-wrapper {
        gap: 8px;
    }

    .ai-chat-input {
        flex: 1;
        min-width: 0;
        padding: 12px 16px;
        font-size: 16px; /* prevents iOS auto-zoom */
        border-radius: 24px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .ai-chat-input::placeholder {
        font-size: 16px;
    }

    .ai-chat-send-btn {
        width: 46px;
        height: 46px;
        flex-shrink: 0;
    }

    .ai-chat-footer {
        display: none;
    }

    .ai-chat-error {
        margin: 0 16px 14px;
    }
}

/* Copy Button */
.ai-chat-copy-btn {
    background: rgba(0, 0, 0, 0.1);
    border: none;
    color: inherit;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    margin-top: 8px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background 0.2s ease;
}

.ai-chat-copy-btn:hover {
    background: rgba(0, 0, 0, 0.2);
}

.ai-chat-message.user-message .ai-chat-copy-btn {
    background: rgba(255, 255, 255, 0.2);
}

.ai-chat-message.user-message .ai-chat-copy-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Feedback Controls */
.ai-chat-feedback {
    font-size: 11px;
    color: #64748b;
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.ai-chat-feedback-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 13px;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.ai-chat-feedback-btn:hover {
    opacity: 1;
    background: rgba(34, 197, 94, 0.1);
}

.ai-chat-feedback-reason {
    font-size: 11px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 2px 4px;
    color: #334155;
    background: white;
}

.ai-chat-feedback-confirm {
    font-size: 11px;
    background: #22c55e;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 3px 8px;
    cursor: pointer;
}

.ai-chat-feedback-done {
    color: #16a34a;
    font-weight: 500;
}

/* Quick Reply Chips */
.ai-chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.ai-chat-chip {
    background: rgba(34, 197, 94, 0.1);
    color: #16a34a;
    border: 1px solid rgba(34, 197, 94, 0.25);
    border-radius: 16px;
    padding: 5px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-chat-chip:hover {
    background: rgba(34, 197, 94, 0.2);
}

/* ============================================================
   DARK MODE SUPPORT
   ============================================================ */
[data-theme="dark"] .ai-chat-popup {
    background: #152018;
    border: 1px solid #2a3d2c;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .ai-chat-messages {
    background: #0f1a11;
}

[data-theme="dark"] .ai-chat-messages::-webkit-scrollbar-track {
    background: #0f1a11;
}

[data-theme="dark"] .ai-chat-messages::-webkit-scrollbar-thumb {
    background: #2a3d2c;
}

[data-theme="dark"] .ai-chat-bubble {
    background: #1c2d1e;
    color: #e2ede2;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .ai-chat-time {
    color: #7da880;
}

[data-theme="dark"] .ai-chat-typing-dots {
    background: #1c2d1e;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .ai-chat-input-area {
    background: #152018;
    border-top-color: #2a3d2c;
}

[data-theme="dark"] .ai-chat-input {
    background: #172219;
    border-color: #2a3d2c;
    color: #e2ede2;
}

[data-theme="dark"] .ai-chat-input::placeholder {
    color: #5a7a5c;
}

[data-theme="dark"] .ai-chat-input:focus {
    border-color: #22c55e;
}

[data-theme="dark"] .ai-chat-footer-text {
    color: #7da880;
}

[data-theme="dark"] .ai-chat-error {
    background: rgba(239, 68, 68, 0.12);
    color: #f87171;
}

[data-theme="dark"] .ai-chat-chip {
    background: rgba(74, 222, 128, 0.1);
    color: #4ade80;
    border-color: rgba(74, 222, 128, 0.25);
}

[data-theme="dark"] .ai-chat-chip:hover {
    background: rgba(74, 222, 128, 0.2);
}

[data-theme="dark"] .ai-chat-send-btn.stopping {
    background: linear-gradient(135deg, #b91c1c 0%, #991b1b 100%);
}

[data-theme="dark"] .ai-chat-send-btn.stopping:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

[data-theme="dark"] .ai-chat-input:-webkit-autofill,
[data-theme="dark"] .ai-chat-input:-webkit-autofill:hover,
[data-theme="dark"] .ai-chat-input:-webkit-autofill:focus,
[data-theme="dark"] .ai-chat-input:autofill {
    -webkit-text-fill-color: #e2ede2 !important;
    -webkit-box-shadow: 0 0 0px 1000px #172219 inset !important;
    box-shadow: 0 0 0px 1000px #172219 inset !important;
    caret-color: #e2ede2 !important;
    color: #e2ede2 !important;
    background-color: #172219 !important;
    background-image: none !important;
    transition: background-color 5000s ease-in-out 0s;
}
