/* Axmobiles AI Chat Widget - uses site primary color */
#axmobiles-chat-root {
    --chat-primary: rgb(var(--primary, 234 88 12));
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 14px;
}

/* Mobile: position above bottom nav bar to avoid overlap */
@media (max-width: 1024px) {
    #axmobiles-chat-root {
        bottom: 85px;
        right: 16px;
    }
    /* Hide toggle when chat full-screen is open */
    #axmobiles-chat-root:has(#axmobiles-chat-panel.open) #axmobiles-chat-toggle {
        display: none;
    }
}

#axmobiles-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--chat-primary);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(var(--primary, 234 88 12) / 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

#axmobiles-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(var(--primary, 234 88 12) / 0.5);
}

#axmobiles-chat-toggle svg {
    width: 28px;
    height: 28px;
}

#axmobiles-chat-panel {
    display: none;
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    flex-direction: column;
    overflow: hidden;
}

@media (max-width: 1024px) {
    #axmobiles-chat-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        transform: none;
        border-radius: 0;
        z-index: 99998;
    }
}

#axmobiles-chat-panel.open {
    display: flex;
}

#axmobiles-chat-header {
    padding: 14px 16px;
    background: var(--chat-primary);
    color: #fff;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#axmobiles-chat-header-close {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    opacity: 0.9;
}

#axmobiles-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f7f7f8;
}

#axmobiles-chat-messages .msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    line-height: 1.45;
    word-wrap: break-word;
}

#axmobiles-chat-messages .msg.user {
    align-self: flex-end;
    background: var(--chat-primary);
    color: #fff;
}

#axmobiles-chat-messages .msg.assistant {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e5e5ea;
}

#axmobiles-chat-messages .msg.assistant a {
    color: var(--chat-primary);
    text-decoration: none;
}

#axmobiles-chat-messages .msg.assistant a:hover {
    text-decoration: underline;
}

#axmobiles-chat-messages .msg.assistant .chat-product-img-wrap {
    cursor: pointer;
    display: inline-block;
    margin: 6px 0;
    border-radius: 8px;
    overflow: hidden;
    outline: none;
}
#axmobiles-chat-messages .msg.assistant .chat-product-img-wrap:focus {
    box-shadow: 0 0 0 2px var(--chat-primary);
}
#axmobiles-chat-messages .msg.assistant .chat-product-img {
    max-width: 100%;
    width: 180px;
    height: auto;
    border-radius: 8px;
    display: block;
    vertical-align: middle;
}
/* Image zoom modal */
.chat-image-modal {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}
.chat-image-modal.open {
    display: flex;
}
.chat-image-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    cursor: pointer;
}
.chat-image-modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-image-modal-close {
    position: absolute;
    top: -44px;
    right: 0;
    width: 36px;
    height: 36px;
    border: none;
    background: #fff;
    color: #333;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.chat-image-modal-close:hover {
    background: #f0f0f0;
}
.chat-image-modal-img {
    max-width: 90vw;
    max-height: 85vh;
    width: auto;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

#axmobiles-chat-messages .msg.typing::after {
    content: '';
    animation: axmobiles-dots 1.2s steps(4, end) infinite;
}

@keyframes axmobiles-dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}

#axmobiles-chat-form {
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid #e5e5ea;
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#axmobiles-chat-input {
    flex: 1;
    min-height: 44px;
    max-height: 100px;
    padding: 10px 14px;
    border: 1px solid #e5e5ea;
    border-radius: 22px;
    resize: none;
    font: inherit;
    outline: none;
}

#axmobiles-chat-input:focus {
    border-color: var(--chat-primary);
}

#axmobiles-chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--chat-primary);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#axmobiles-chat-send:hover:not(:disabled) {
    filter: brightness(0.92);
}

#axmobiles-chat-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#axmobiles-chat-clear {
    margin-top: 4px;
    font-size: 12px;
    color: #666;
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
}

#axmobiles-chat-clear:hover {
    color: var(--chat-primary);
}

/* In-chat order form */
.chat-order-form {
    padding: 12px 16px;
    background: rgba(var(--primary, 234 88 12) / 0.08);
    border-top: 1px solid rgba(var(--primary, 234 88 12) / 0.25);
    max-height: 280px;
    overflow-y: auto;
}
.chat-order-form-inner {
    font-size: 13px;
}
.chat-order-form-title {
    font-weight: 600;
    margin: 0 0 4px 0;
    color: rgb(var(--primary, 234 88 12));
}
.chat-order-form-meta {
    margin: 0 0 10px 0;
    color: rgb(var(--primary, 234 88 12) / 0.9);
    font-size: 12px;
}
.chat-order-form-fields {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.chat-order-form-label {
    display: block;
    font-weight: 500;
    color: #333;
    margin: 0;
}
.chat-order-form-input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid rgba(var(--primary, 234 88 12) / 0.35);
    border-radius: 8px;
    font-size: 13px;
    box-sizing: border-box;
}
.chat-order-form-input:focus {
    outline: none;
    border-color: var(--chat-primary);
}
.chat-order-form-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}
.chat-order-form-submit {
    padding: 8px 14px;
    background: var(--chat-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
}
.chat-order-form-submit:hover:not(:disabled) {
    filter: brightness(0.92);
}
.chat-order-form-submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}
.chat-order-form-cancel {
    padding: 8px 14px;
    background: #fff;
    color: #666;
    border: 1px solid #e5e5ea;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
}
.chat-order-form-cancel:hover {
    background: #f5f5f5;
    color: #333;
}

[dir="rtl"] #axmobiles-chat-root {
    right: auto;
    left: 20px;
}

@media (max-width: 1024px) {
    [dir="rtl"] #axmobiles-chat-root {
        right: auto;
        left: 16px;
    }
}

[dir="rtl"] #axmobiles-chat-panel {
    right: auto;
    left: 0;
}

@media (max-width: 1024px) {
    [dir="rtl"] #axmobiles-chat-panel {
        left: 0;
        right: 0;
    }
}

[dir="rtl"] #axmobiles-chat-messages .msg.user {
    align-self: flex-start;
}

[dir="rtl"] #axmobiles-chat-messages .msg.assistant {
    align-self: flex-end;
}
