:root {
    --ai-chat-primary: #4F46E5;
    --ai-chat-primary-hover: #4338CA;
    --ai-chat-bg: #FFFFFF;
    --ai-chat-text: #000000;
    --ai-chat-bot-bg: #F3F4F6;
    --ai-chat-bot-text: #000000;
    --ai-chat-user-bg: #4F46E5;
    --ai-chat-user-text: #FFFFFF;
    --ai-chat-border-radius: 12px;
    --ai-chat-font-size: 14px;
    --ai-chat-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
    --ai-chat-z-index: 10000;
}

.ai-chat-container {
    position: fixed;
    z-index: var(--ai-chat-z-index);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: var(--ai-chat-font-size);
    line-height: 1.5;
}

.ai-chat-container.bottom-right {
    right: 20px;
    bottom: 20px;
}

.ai-chat-container.bottom-left {
    left: 20px;
    bottom: 20px;
}

.ai-chat-button {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--ai-chat-primary);
    border: none;
    cursor: pointer;
    box-shadow: var(--ai-chat-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background-color 0.2s;
    position: relative;
    z-index: 10001;
}

.ai-chat-button:hover {
    transform: scale(1.08);
    background: var(--ai-chat-primary-hover);
}

.ai-chat-button svg {
    width: 24px;
    height: 24px;
    fill: #FFFFFF;
}

.ai-chat-button .ai-chat-close-icon {
    display: none;
}

.ai-chat-widget.ai-open ~ .ai-chat-button .ai-chat-chat-icon {
    display: none;
}

.ai-chat-widget.ai-open ~ .ai-chat-button .ai-chat-close-icon {
    display: block;
}

.ai-chat-button-text {
    position: absolute;
    right: 64px;
    white-space: nowrap;
    background: var(--ai-chat-primary);
    color: #FFFFFF;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.ai-chat-button:hover .ai-chat-button-text {
    opacity: 1;
}

.ai-chat-widget {
    display: none;
    width: 370px;
    height: 560px;
    max-height: calc(100vh - 120px);
    background: var(--ai-chat-bg);
    border-radius: var(--ai-chat-border-radius);
    box-shadow: var(--ai-chat-shadow);
    overflow: hidden;
    flex-direction: column;
    position: fixed;
    right: 20px;
    bottom: 90px;
    animation: ai-chat-slide-up 0.3s ease;
}

.ai-chat-container.bottom-left .ai-chat-widget {
    right: auto;
    left: 20px;
}

.ai-chat-widget.ai-open {
    display: flex;
}

@keyframes ai-chat-slide-up {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-chat-header {
    background: var(--ai-chat-primary);
    color: #FFFFFF;
    padding: 14px 18px;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.ai-chat-header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-header-avatar svg {
    width: 18px;
    height: 18px;
    fill: #FFFFFF;
}

.ai-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-chat-body::-webkit-scrollbar {
    width: 5px;
}

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

.ai-chat-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-chat-form-title {
    font-weight: 600;
    font-size: 15px;
    color: #000000;
    margin-bottom: 4px;
}

.ai-chat-form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-chat-form-group label {
    font-size: 12px;
    font-weight: 500;
    color: #000000;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-chat-form-group input {
    padding: 10px 12px;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
    color: #000000;
}

.ai-chat-form-group input:focus {
    border-color: var(--ai-chat-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.ai-chat-form-submit {
    padding: 10px 20px;
    background: var(--ai-chat-primary);
    color: #FFFFFF;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    transition: background-color 0.2s;
}

.ai-chat-form-submit:hover {
    background: var(--ai-chat-primary-hover);
}

.ai-chat-form-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 8px;
}

.ai-chat-message {
    margin-bottom: 12px;
    animation: ai-chat-fade-in 0.3s ease;
}

@keyframes ai-chat-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

.ai-chat-message-bubble {
    display: inline-block;
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    text-align: left;
    color: #000000;
}

.ai-chat-message-user .ai-chat-message-bubble {
    background: var(--ai-chat-user-bg);
    color: var(--ai-chat-user-text);
    border-bottom-right-radius: 4px;
}

.ai-chat-message-bot .ai-chat-message-bubble {
    background: var(--ai-chat-bot-bg);
    color: #000000;
    border-bottom-left-radius: 4px;
}

.ai-chat-message-time {
    font-size: 10px;
    color: #9CA3AF;
    margin-top: 4px;
    padding: 0 4px;
}

.ai-chat-typing {
    padding: 10px 14px;
    background: var(--ai-chat-bot-bg);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    animation: ai-chat-fade-in 0.2s ease;
}

.ai-chat-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9CA3AF;
    animation: ai-chat-typing-bounce 1.2s infinite;
}

.ai-chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-chat-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

.ai-chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid #E5E7EB;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
    background: #FFFFFF;
}

.ai-chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #D1D5DB;
    border-radius: 20px;
    font-size: 16px;
    outline: none;
    font-family: inherit;
    color: #000000;
    transition: border-color 0.2s;
}

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

.ai-chat-input:disabled {
    background: #F9FAFB;
}

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

.ai-chat-send-btn:hover {
    background: var(--ai-chat-primary-hover);
}

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

.ai-chat-send-btn svg {
    width: 16px;
    height: 16px;
    fill: #FFFFFF;
}

.ai-chat-error {
    color: #EF4444;
    font-size: 12px;
    text-align: center;
    padding: 8px;
    background: #FEF2F2;
    border-radius: 8px;
    margin: 8px 0;
}

.ai-chat-end-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 32px;
    gap: 12px;
}

.ai-chat-end-view svg {
    width: 48px;
    height: 48px;
    fill: #10B981;
}

.ai-chat-end-view h4 {
    margin: 0;
    font-size: 16px;
    color: #000000;
}

.ai-chat-end-view p {
    margin: 0;
    font-size: 13px;
    color: #6B7280;
}

/* ========================================
   Embedded Mode
   ======================================== */

.ai-sales-chat-root {
    width: 100%;
    max-width: 480px;
    margin: 0;
    padding: 0;
    line-height: 1;
}

.ai-chat-embedded {
    position: relative !important;
    right: auto !important;
    left: auto !important;
    bottom: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    z-index: 1;
}

.ai-chat-embedded .ai-chat-widget {
    display: block;
    position: relative;
    right: auto;
    left: auto;
    bottom: auto;
    width: 100%;
    height: auto;
    margin: 0;
    border: 1px solid #E5E7EB;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    background: #FFFFFF;
    animation: none;
    overflow: hidden;
}

.ai-chat-embedded .ai-chat-button {
    display: none !important;
}

/* Header — visible only in chat mode */
.ai-chat-embedded .ai-chat-header {
    display: none;
    background: var(--ai-chat-primary);
    color: #FFFFFF;
    padding: 14px 18px;
    font-weight: 600;
    font-size: 15px;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.ai-chat-embedded .ai-chat-widget.ai-chatting .ai-chat-header {
    display: flex;
}

.ai-chat-embedded .ai-chat-header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-embedded .ai-chat-header-avatar svg {
    width: 18px;
    height: 18px;
    fill: #FFFFFF;
}

/* Body — form mode: content-sized; chat mode: flex column filling widget */
.ai-chat-embedded .ai-chat-body {
    padding: 20px 20px 0 20px;
    display: block;
    gap: 0;
}

.ai-chat-embedded .ai-chat-widget.ai-chatting {
    display: flex;
    flex-direction: column;
    height: 520px;
    max-height: 75vh;
}

.ai-chat-embedded .ai-chat-widget.ai-chatting .ai-chat-body {
    flex: 1 1 0%;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Welcome message */
.ai-chat-embedded .ai-chat-message-bot {
    margin-bottom: 14px;
}

.ai-chat-embedded .ai-chat-message-bot .ai-chat-message-bubble {
    display: block;
    max-width: 100%;
    padding: 0;
    background: transparent;
    color: #000000;
    font-size: 14px;
    line-height: 1.6;
}

/* Form */
.ai-chat-embedded .ai-chat-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 0;
    padding: 0;
}

.ai-chat-embedded .ai-chat-form-submit {
    margin-bottom: 0 !important;
}

.ai-chat-embedded .ai-chat-form-title {
    display: none;
}

.ai-chat-embedded .ai-chat-form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    padding: 0;
}

.ai-chat-embedded .ai-chat-form-group label {
    font-size: 13px;
    font-weight: 600;
    color: #000000;
}

.ai-chat-embedded .ai-chat-form-group input {
    padding: 12px 14px;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    font-size: 16px;
    outline: none;
    font-family: inherit;
    color: #000000;
    background: #FFFFFF;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.ai-chat-embedded .ai-chat-form-group input:focus {
    border-color: var(--ai-chat-primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.ai-chat-embedded .ai-chat-form-submit {
    padding: 12px 24px;
    background: var(--ai-chat-primary);
    color: #FFFFFF;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    transition: background-color 0.2s;
}

.ai-chat-embedded .ai-chat-form-submit:hover {
    background: var(--ai-chat-primary-hover);
}

.ai-chat-embedded .ai-chat-form-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Messages area — chat mode */
.ai-chat-embedded .ai-chat-messages {
    flex: 1;
    overflow-y: auto;
}

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

.ai-chat-embedded .ai-chat-messages::-webkit-scrollbar-thumb {
    background: #D1D5DB;
    border-radius: 2px;
}

/* Chat bubbles — chat mode */
.ai-chat-embedded .ai-chat-message {
    margin-bottom: 12px;
}

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

.ai-chat-embedded .ai-chat-message-bubble {
    display: inline-block;
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
    text-align: left;
    color: #000000;
}

.ai-chat-embedded .ai-chat-message-user .ai-chat-message-bubble {
    background: var(--ai-chat-user-bg);
    color: #FFFFFF;
    border-bottom-right-radius: 4px;
}

.ai-chat-embedded .ai-chat-message-bot .ai-chat-message-bubble {
    background: #F3F4F6;
    color: #000000;
    border-bottom-left-radius: 4px;
}

.ai-chat-embedded .ai-chat-message-time {
    font-size: 10px;
    color: #9CA3AF;
    margin-top: 3px;
    padding: 0 4px;
}

/* Typing indicator */
.ai-chat-embedded .ai-chat-typing {
    padding: 10px 14px;
    background: #F3F4F6;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.ai-chat-embedded .ai-chat-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9CA3AF;
    animation: ai-chat-typing-bounce 1.2s infinite;
}

.ai-chat-embedded .ai-chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-chat-embedded .ai-chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* Input area — chat mode */
.ai-chat-embedded .ai-chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid #E5E7EB;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
    background: #FFFFFF;
}

.ai-chat-embedded .ai-chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #D1D5DB;
    border-radius: 20px;
    font-size: 16px;
    outline: none;
    font-family: inherit;
    color: #000000;
    transition: border-color 0.2s;
}

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

.ai-chat-embedded .ai-chat-input:disabled {
    background: #F9FAFB;
}

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

.ai-chat-embedded .ai-chat-send-btn:hover {
    background: var(--ai-chat-primary-hover);
}

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

.ai-chat-embedded .ai-chat-send-btn svg {
    width: 16px;
    height: 16px;
    fill: #FFFFFF;
}

/* Error */
.ai-chat-embedded .ai-chat-error {
    color: #EF4444;
    font-size: 12px;
    text-align: center;
    padding: 8px;
    background: #FEF2F2;
    border-radius: 8px;
    margin: 8px 0;
}

/* End view */
.ai-chat-embedded .ai-chat-end-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 32px;
    gap: 12px;
}

.ai-chat-embedded .ai-chat-end-view svg {
    width: 48px;
    height: 48px;
    fill: #10B981;
}

.ai-chat-embedded .ai-chat-end-view h4 {
    margin: 0;
    font-size: 16px;
    color: #000000;
}

.ai-chat-embedded .ai-chat-end-view p {
    margin: 0;
    font-size: 13px;
    color: #6B7280;
}

/* Loading overlay */
.ai-chat-embedded.ai-chat-loading::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.7);
    z-index: 10;
    border-radius: 12px;
}

.ai-chat-embedded.ai-chat-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    margin: -16px 0 0 -16px;
    border: 3px solid #E5E7EB;
    border-top-color: var(--ai-chat-primary);
    border-radius: 50%;
    animation: ai-chat-spin 0.8s linear infinite;
    z-index: 11;
}

@keyframes ai-chat-spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   Mobile: embedded
   ======================================== */

@media (max-width: 480px) {
    .ai-sales-chat-root {
        max-width: 100%;
    }

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

    .ai-chat-embedded .ai-chat-widget.ai-chatting .ai-chat-body {
        padding: 14px;
    }

    .ai-chat-embedded .ai-chat-widget.ai-chatting {
        height: 70vh;
        max-height: 70vh;
    }

    .ai-chat-embedded .ai-chat-messages {
        -webkit-overflow-scrolling: touch;
    }
}

/* ========================================
   Mobile: floating widget — fullscreen overlay
   ======================================== */

@media (max-width: 480px) {
    .ai-chat-container:not(.ai-chat-embedded) .ai-chat-widget {
        width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        right: 0;
        bottom: 0;
        top: 0;
        left: 0;
        border-radius: 0;
    }

    .ai-chat-container:not(.ai-chat-embedded).bottom-right {
        right: 0;
        bottom: 0;
    }

    .ai-chat-container:not(.ai-chat-embedded).bottom-left {
        left: 0;
        bottom: 0;
    }

    .ai-chat-container:not(.ai-chat-embedded) .ai-chat-widget.ai-open {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
    }
}
