:root {
    --ai-primary-color: #4f46e5;
    --ai-text-color: #1e293b;
    --ai-bg-color: #ffffff;
    --ai-bubble-size: 60px;
    --ai-offset-x: 24px;
    --ai-offset-y: 24px;
    --ai-radius: 28px;
    --ai-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

/* Chat Bubble */
#ai-chat-bubble {
    position: fixed;
    bottom: var(--ai-offset-y);
    right: var(--ai-offset-x);
    width: var(--ai-bubble-size);
    height: var(--ai-bubble-size);
    background: var(--ai-primary-color);
    border-radius: 50%;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05), inset 0 2px 4px rgba(255, 255, 255, 0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 9999;
    color: white;
    border: none;
    outline: none;
    animation: ai-bubble-in 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

@keyframes ai-bubble-in {
    from { transform: scale(0) rotate(-45deg); opacity: 0; }
    to { transform: scale(1) rotate(0); opacity: 1; }
}

/* Pulse Animation (Radio Signal Wave) */
.ai-pulse-wave {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--ai-primary-color);
    opacity: 0.6;
    z-index: -1;
    pointer-events: none;
    animation: ai-pulse-wave 2.5s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}

.ai-pulse-wave:nth-child(2) {
    animation-delay: 0.8s;
}

.ai-pulse-wave:nth-child(3) {
    animation-delay: 1.6s;
}

@keyframes ai-pulse-wave {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }
    100% {
        transform: scale(2.2);
        opacity: 0;
    }
}

/* Waving Hand Animation */
.ai-wave {
    display: inline-block;
    animation: ai-wave-animation 2.5s infinite;
    transform-origin: 70% 70%;
}

@keyframes ai-wave-animation {
    0% { transform: rotate( 0.0deg) }
    10% { transform: rotate(14.0deg) }
    20% { transform: rotate(-8.0deg) }
    30% { transform: rotate(14.0deg) }
    40% { transform: rotate(-4.0deg) }
    50% { transform: rotate(10.0deg) }
    60% { transform: rotate( 0.0deg) }
    100% { transform: rotate( 0.0deg) }
}

#ai-chat-bubble:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
}

#ai-chat-bubble svg {
    width: 28px;
    height: 28px;
    transition: transform 0.3s ease;
}

#ai-chat-bubble:hover svg {
    transform: scale(1.1);
}

/* Proactive Welcome Message */
.ai-proactive-msg {
    position: absolute;
    bottom: calc(100% + 15px);
    right: 0;
    background: white;
    padding: 12px 16px;
    border-radius: 18px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    width: 220px;
    color: #1e293b;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
    pointer-events: none;
    opacity: 0;
    transform: translateY(10px) scale(0.9);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 9998;
    border: 1px solid #f1f5f9;
}

.ai-proactive-header {
    font-weight: 700;
    color: var(--ai-primary-color);
    margin-bottom: 4px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.ai-proactive-text {
    line-height: 1.5;
}

.ai-proactive-msg.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

.ai-proactive-msg::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 24px;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid white;
}

.ai-proactive-close {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: #f1f5f9;
    color: #64748b;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 10px;
    border: 2px solid white;
    transition: all 0.2s;
    pointer-events: all;
}

.ai-proactive-close:hover {
    background: #ef4444;
    color: white;
}

.ai-bubble-dismiss {
    position: absolute;
    top: -8px;
    left: -8px;
    width: 24px;
    height: 24px;
    background: #f1f5f9;
    color: #64748b;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border: 2px solid #ffffff;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.2s ease;
    z-index: 20;
}

#ai-chat-bubble:hover .ai-bubble-dismiss {
    opacity: 1;
    transform: scale(1);
}

.ai-bubble-dismiss:hover {
    background: #ef4444;
    color: #ffffff;
}

.ai-chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    background-color: #ef4444;
    color: #ffffff;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    border: 2px solid #ffffff;
    z-index: 10;
}

.ai-chat-badge.ai-chat-badge-hidden {
    display: none;
}

/* Chat Window */
#ai-chat-window {
    position: fixed;
    bottom: var(--ai-offset-y);
    right: var(--ai-offset-x);
    width: 380px;
    height: 700px;
    height: min(700px, calc(100vh - var(--ai-offset-y) - 40px));
    max-height: calc(100vh - var(--ai-offset-y) - 40px);
    background-color: var(--ai-bg-color);
    border-radius: var(--ai-radius);
    box-shadow: var(--ai-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    z-index: 9999;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

@media (max-width: 480px) {
    #ai-chat-window {
        width: calc(100% - 40px);
        right: 20px;
        left: 20px;
        bottom: var(--ai-offset-y);
        max-height: calc(100vh - var(--ai-offset-y) - 40px);
    }
}

#ai-chat-window.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
    z-index: 10000;
}

#ai-chat-bubble.ai-hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0);
}

/* Position Overrides */
#ai-chat-bubble.ai-pos-bottom-left {
    right: auto;
    left: var(--ai-offset-x);
}
#ai-chat-window.ai-pos-bottom-left {
    right: auto;
    left: var(--ai-offset-x);
    transform-origin: bottom left;
}

#ai-chat-bubble.ai-pos-right-middle {
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
}
#ai-chat-window.ai-pos-right-middle {
    bottom: auto;
    top: 50%;
    transform: translateY(-50%) scale(0.95);
    transform-origin: center right;
    max-height: calc(100vh - 40px);
}
#ai-chat-window.ai-pos-right-middle.open {
    transform: translateY(-50%) scale(1);
}

/* Typing / Processing Indicator */
.ai-typing-indicator {
    align-self: flex-start;
    background-color: white;
    padding: 12px 16px;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    animation: ai-msg-pop 0.3s ease-out;
}

.ai-typing-text {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ai-typing-dots {
    display: flex;
    gap: 4px;
}

.ai-typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--ai-primary-color);
    border-radius: 50%;
    opacity: 0.4;
    animation: ai-typing-dot 1.4s infinite ease-in-out both;
}

.ai-typing-dot:nth-child(1) { animation-delay: -0.32s; }

.ai-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes ai-typing-dot {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

@keyframes ai-msg-pop {
    from { opacity: 0; transform: translateY(10px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Header and Window Controls */
#ai-chat-window.minimized {
    transform: translateY(calc(100% - 60px));
}

#ai-chat-window.wide {
    width: 650px;
}

@media (max-width: 700px) {
    #ai-chat-window.wide {
        width: calc(100% - 40px);
        right: 20px;
        left: 20px;
    }
    .ai-hidden-mobile {
        display: none !important;
    }
}

.ai-chat-header {
    background: var(--ai-primary-color);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
    min-height: 64px;
    box-sizing: border-box;
}

.ai-chat-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 16px;
    flex: 1;
    min-width: 0;
}

.ai-chat-title span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-chat-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    object-fit: cover;
    background-color: white;
    padding: 2px;
    flex-shrink: 0;
}

.ai-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.ai-chat-header-actions button {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    padding: 6px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    box-sizing: border-box;
}

.ai-chat-header-actions button:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
}

.ai-chat-header-actions svg {
    width: 16px;
    height: 16px;
}

/* Modal Styling */
.ai-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    padding: 20px;
}

.ai-modal-overlay.active {
    display: flex;
}

.ai-modal-content {
    background: white;
    border-radius: 20px;
    width: 100%;
    max-width: 400px;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: ai-modal-slide 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes ai-modal-slide {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.ai-modal-header {
    padding: 24px 24px 12px;
}

.ai-modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 800;
    color: #1e293b;
}

.ai-modal-body {
    padding: 0 24px 24px;
}

.ai-modal-body p {
    margin: 0;
    color: #64748b;
    line-height: 1.6;
}

.ai-modal-footer {
    padding: 16px 24px 24px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.ai-modal-footer button {
    padding: 10px 20px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.ai-btn-secondary {
    background: #f1f5f9;
    color: #475569;
}

.ai-btn-secondary:hover {
    background: #e2e8f0;
}

.ai-btn-danger {
    background: #ef4444;
    color: white;
}

.ai-btn-danger:hover {
    background: #dc2626;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.ai-hidden { display: none !important; }

.ai-chat-messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background-color: #f8fafc;
}

.ai-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
}

.ai-message.assistant {
    align-self: flex-start;
    background-color: white;
    color: var(--ai-text-color);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.ai-h1, .ai-h2, .ai-h3 {
    margin: 1em 0 0.5em 0;
    font-weight: 800;
    line-height: 1.2;
    color: var(--ai-text-color);
}

.ai-h1 { font-size: 1.5em; border-bottom: 2px solid #e2e8f0; padding-bottom: 0.3em; }
.ai-h2 { font-size: 1.3em; border-bottom: 1px solid #e2e8f0; padding-bottom: 0.2em; }
.ai-h3 { font-size: 1.15em; }

.ai-table-container {
    width: 100%;
    overflow-x: auto;
    margin: 1em 0;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.ai-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background-color: white;
}

.ai-th {
    background-color: #f8fafc;
    color: #475569;
    font-weight: 700;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 2px solid #e2e8f0;
}

.ai-td {
    padding: 8px 12px;
    border-bottom: 1px solid #f1f5f9;
    color: #64748b;
}

.ai-table tr:last-child .ai-td {
    border-bottom: none;
}

.ai-paragraph {
    margin-bottom: 1em;
}

.ai-paragraph:last-child {
    margin-bottom: 0;
}

.ai-list, .ai-list-ordered {
    margin: 0.5em 0 1em 1.5em;
    padding: 0;
}

.ai-list {
    list-style-type: disc;
}

.ai-list-ordered {
    list-style-type: decimal;
}

.ai-list li, .ai-list-ordered li {
    margin-bottom: 0.25em;
}

.ai-list li:last-child, .ai-list-ordered li:last-child {
    margin-bottom: 0;
}

.ai-inline-code {
    background-color: #f1f5f9;
    color: #475569;
    padding: 2px 4px;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.9em;
    word-break: break-all;
}

.ai-code-block {
    background-color: #1e293b;
    border-radius: 8px;
    margin: 1em 0;
    overflow: hidden;
    max-width: 100%;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.ai-code-header {
    background-color: #334155;
    color: #94a3b8;
    padding: 6px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
}

.ai-code-block pre {
    padding: 12px;
    margin: 0;
    overflow-x: auto;
    color: #e2e8f0;
    font-size: 13px;
    line-height: 1.5;
}

.ai-link {
    color: var(--ai-primary-color);
    text-decoration: underline;
    font-weight: 600;
}

/* Service/Product Result Cards */
.ai-result-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    margin: 16px 0;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    position: relative;
    border-left: 4px solid var(--ai-primary-color);
}

.ai-result-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.1), 0 8px 8px -5px rgba(0, 0, 0, 0.04);
    border-color: var(--ai-primary-color);
}

.ai-card-image-wrap {
    width: 100%;
    height: 140px;
    overflow: hidden;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.ai-card-icon-wrap {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    color: var(--ai-primary-color);
}

.ai-card-placeholder-icon {
    font-size: 48px;
    opacity: 0.8;
    transition: transform 0.3s ease;
}

.ai-result-card:hover .ai-card-placeholder-icon {
    transform: scale(1.1) rotate(-5deg);
}

.ai-result-card:hover .ai-card-img {
    transform: scale(1.1);
}

.ai-card-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-card-badge {
    display: inline-block;
    padding: 2px 8px;
    background: #f1f5f9;
    color: #64748b;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    width: fit-content;
}

.ai-card-sale-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    background: #ef4444;
    color: white;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 900;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
    letter-spacing: 0.05em;
    animation: ai-sale-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes ai-sale-pop {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.ai-card-title {
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
    line-height: 1.3;
}

.ai-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
    padding-top: 12px;
    border-top: 1px solid #f1f5f9;
}

.ai-card-pricing {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ai-card-price {
    font-size: 15px;
    font-weight: 800;
    color: var(--ai-primary-color);
}

.ai-card-price-sale {
    font-size: 16px;
    font-weight: 900;
    color: #ef4444;
}

.ai-card-price-old {
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
    text-decoration: line-through;
}

.ai-card-link {
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-result-card:hover .ai-card-link {
    color: var(--ai-primary-color);
}

.ai-hr {
    border: 0;
    border-top: 1px solid #e2e8f0;
    margin: 1.5em 0;
}

.ai-message.user {
    align-self: flex-end;
    background-color: var(--ai-primary-color);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Quick Questions */
.ai-quick-questions {
    padding: 12px 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    background-color: #f8fafc;
}

.ai-quick-question-btn {
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid #e2e8f0;
    background-color: white;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-quick-question-btn:hover {
    background-color: #f1f5f9;
    border-color: #cbd5e1;
    color: var(--ai-text-color);
}

/* Input Area */
.ai-chat-input-area {
    padding: 20px 24px;
    background: white;
    border-top: 1px solid #f1f5f9;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 12px;
    box-sizing: border-box;
}

.ai-chat-disclaimer {
    padding: 0 24px 12px;
    font-size: 10px;
    color: #94a3b8;
    text-align: center;
    background: white;
    font-weight: 500;
    letter-spacing: 0.01em;
}

.ai-chat-input {
    flex: 1;
    min-width: 0;
    width: 0; /* Let flex-grow handle it */
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    resize: none;
    max-height: 200px;
    overflow-y: hidden;
    transition: border-color 0.2s;
    outline: none;
    line-height: 1.5;
}

.ai-chat-input:focus {
    border-color: var(--ai-primary-color);
}

.ai-input-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ai-voice-btn, .ai-send-btn {
    background-color: var(--ai-primary-color);
    color: white;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ai-voice-btn {
    background-color: #f1f5f9;
    color: #64748b;
}

.ai-voice-btn:hover {
    background-color: #e2e8f0;
    color: var(--ai-primary-color);
}

.ai-voice-btn.recording {
    background-color: #ef4444;
    color: white;
    animation: ai-voice-pulse 1.5s infinite;
}

@keyframes ai-voice-pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

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

.ai-voice-btn svg, .ai-send-btn svg {
    width: 18px;
    height: 18px;
}
