/*
 * WooCommerce AI Salesman — Chat Widget Styles
 *
 * All rules scoped under #wais-chat-root to prevent conflicts with Flatsome theme.
 * All classes prefixed with wais- for namespace isolation.
 */

#wais-chat-root {
    /* Reset inherited styles from Flatsome */
    all: initial;
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #1f2937;
    box-sizing: border-box;
}

#wais-chat-root *,
#wais-chat-root *::before,
#wais-chat-root *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ---- Position ---- */
#wais-chat-root.wais-pos-bottom-right {
    bottom: 20px;
    right: 20px;
}

#wais-chat-root.wais-pos-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* ---- Toggle Button ---- */
#wais-chat-root .wais-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    background: var(--wais-primary, #2563eb);
    color: #ffffff;
}

#wais-chat-root .wais-toggle-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

#wais-chat-root .wais-toggle-btn svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

#wais-chat-root .wais-toggle-btn .wais-icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg);
}

#wais-chat-root.wais-open .wais-toggle-btn .wais-icon-chat {
    opacity: 0;
    transform: rotate(90deg);
}

#wais-chat-root.wais-open .wais-toggle-btn .wais-icon-close {
    opacity: 1;
    transform: rotate(0deg);
}

/* ---- Chat Window ---- */
#wais-chat-root .wais-chat-window {
    display: none;
    flex-direction: column;
    position: absolute;
    bottom: 72px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    overflow: hidden;
    animation: wais-slide-up 0.3s ease;
}

#wais-chat-root.wais-pos-bottom-right .wais-chat-window {
    right: 0;
}

#wais-chat-root.wais-pos-bottom-left .wais-chat-window {
    left: 0;
}

#wais-chat-root.wais-open .wais-chat-window {
    display: flex;
}

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

/* ---- Header ---- */
#wais-chat-root .wais-chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--wais-primary, #2563eb);
    color: #ffffff;
    flex-shrink: 0;
}

#wais-chat-root .wais-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#wais-chat-root .wais-header-avatar svg {
    width: 22px;
    height: 22px;
    fill: #ffffff;
}

#wais-chat-root .wais-header-info {
    flex: 1;
    min-width: 0;
}

#wais-chat-root .wais-header-title {
    display: block;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
}

#wais-chat-root .wais-header-subtitle {
    display: block;
    font-size: 12px;
    opacity: 0.85;
    line-height: 1.3;
}

#wais-chat-root .wais-close-btn {
    background: none;
    border: none;
    color: #ffffff;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 20px;
    line-height: 1;
    flex-shrink: 0;
    transition: background 0.15s;
}

#wais-chat-root .wais-close-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ---- Messages Area ---- */
#wais-chat-root .wais-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f9fafb;
}

#wais-chat-root .wais-messages::-webkit-scrollbar {
    width: 5px;
}

#wais-chat-root .wais-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

/* ---- Message Bubbles ---- */
#wais-chat-root .wais-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 14px;
    line-height: 1.5;
}

#wais-chat-root .wais-msg--bot {
    align-self: flex-start;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
    color: #1f2937;
}

#wais-chat-root .wais-msg--user {
    align-self: flex-end;
    background: var(--wais-primary, #2563eb);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

#wais-chat-root .wais-msg p {
    margin: 0 0 8px 0;
}

#wais-chat-root .wais-msg p:last-child {
    margin-bottom: 0;
}

/* ---- Product Cards ---- */
#wais-chat-root .wais-product-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

#wais-chat-root .wais-product-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    text-decoration: none;
    color: #1f2937;
    transition: border-color 0.15s, box-shadow 0.15s;
    cursor: pointer;
}

#wais-chat-root .wais-product-card:hover {
    border-color: var(--wais-primary, #2563eb);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
}

#wais-chat-root .wais-product-card-img {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    background: #e5e7eb;
}

#wais-chat-root .wais-product-card-info {
    flex: 1;
    min-width: 0;
}

#wais-chat-root .wais-product-card-name {
    display: block;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#wais-chat-root .wais-product-card-price {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--wais-primary, #2563eb);
    margin-top: 2px;
}

#wais-chat-root .wais-product-card-arrow {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    fill: #9ca3af;
}

/* ---- Typing Indicator ---- */
#wais-chat-root .wais-typing {
    align-self: flex-start;
    display: flex;
    gap: 5px;
    padding: 12px 16px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

#wais-chat-root .wais-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
    animation: wais-bounce 1.2s infinite;
}

#wais-chat-root .wais-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

#wais-chat-root .wais-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* ---- Input Area ---- */
#wais-chat-root .wais-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
    flex-shrink: 0;
}

#wais-chat-root .wais-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
    background: #ffffff;
    color: #1f2937;
    line-height: 1.5;
}

#wais-chat-root .wais-input::placeholder {
    color: #9ca3af;
}

#wais-chat-root .wais-input:focus {
    border-color: var(--wais-primary, #2563eb);
}

#wais-chat-root .wais-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--wais-primary, #2563eb);
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, opacity 0.15s;
}

#wais-chat-root .wais-send-btn:hover {
    filter: brightness(0.9);
}

#wais-chat-root .wais-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#wais-chat-root .wais-send-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* ---- Error Message ---- */
#wais-chat-root .wais-error {
    align-self: center;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
}

/* ---- Responsive ---- */

/* Desktop */
@media (min-width: 481px) {
    #wais-chat-root .wais-chat-window {
        width: 380px;
        height: 560px;
    }
}

/* Mobile */
@media (max-width: 480px) {
    #wais-chat-root {
        bottom: 12px !important;
        right: 12px !important;
        left: auto !important;
    }

    #wais-chat-root .wais-toggle-btn {
        width: 52px;
        height: 52px;
    }

    #wais-chat-root .wais-chat-window {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100vw;
        height: 75vh;
        border-radius: 16px 16px 0 0;
    }
}
