/* ─── AEA Ecom Chat Widget ───────────────────────────────────────── */
:root {
    /* Palette */
    --aea-granite: #536658;
    --aea-deep-teal: #59726D;
    --aea-khaki: #BCA986;
    --aea-grey-olive: #87836C;
    --aea-bone: #D2D5C5;
    --aea-linen: #F6F0E6;
    --aea-old-lace: #FBF1E0;
    --aea-dust: #D3D8D1;
    --aea-white: #ffffff;

    /* Configurable (overridden by inline CSS from WP admin) */
    --aea-header-bg: var(--aea-granite);
    --aea-header-text: var(--aea-linen);
    --aea-user-msg-bg: var(--aea-dust);
    --aea-user-msg-text: var(--aea-granite);
    --aea-assistant-msg-bg: var(--aea-linen);
    --aea-assistant-msg-text: var(--aea-granite);
    --aea-chat-bg: var(--aea-white);
    --aea-accent: var(--aea-deep-teal);
    --aea-input-area-bg: var(--aea-linen);

    /* Fixed */
    --aea-shadow: 0 8px 32px rgba(83, 102, 88, 0.22);
    --aea-radius: 16px;
}

/* ─── Toggle Button ──────────────────────────────────────────────── */
#aea-chat-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--aea-header-bg);
    border: none;
    cursor: pointer;
    box-shadow: var(--aea-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background 0.2s ease;
}

#aea-chat-toggle:hover {
    transform: scale(1.08);
    background: var(--aea-accent);
}

#aea-chat-toggle svg {
    width: 28px;
    height: 28px;
    fill: var(--aea-header-text);
    transition: opacity 0.2s ease;
}

#aea-chat-toggle .aea-icon-close {
    display: none;
}

#aea-chat-toggle.aea-open .aea-icon-chat {
    display: none;
}

#aea-chat-toggle.aea-open .aea-icon-close {
    display: block;
}

/* ─── Chat Window ────────────────────────────────────────────────── */
#aea-chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    z-index: 99998;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 140px);
    background: var(--aea-linen);
    border-radius: var(--aea-radius);
    box-shadow: var(--aea-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.96);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
}

#aea-chat-window.aea-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ─── Header ─────────────────────────────────────────────────────── */
.aea-chat-header {
    background: var(--aea-header-bg);
    color: var(--aea-header-text);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.aea-chat-header-dot {
    width: 10px;
    height: 10px;
    background: var(--aea-khaki);
    border-radius: 50%;
    flex-shrink: 0;
    animation: aea-pulse 2s infinite;
}

@keyframes aea-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.aea-chat-header-text h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: inherit;
}

.aea-chat-header-text p {
    margin: 2px 0 0;
    font-size: 12px;
    opacity: 0.7;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ─── Messages ───────────────────────────────────────────────────── */
.aea-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--aea-chat-bg);
}

.aea-chat-messages::-webkit-scrollbar {
    width: 5px;
}

.aea-chat-messages::-webkit-scrollbar-thumb {
    background: var(--aea-bone);
    border-radius: 3px;
}

.aea-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.aea-msg-assistant {
    align-self: flex-start;
    background: var(--aea-assistant-msg-bg);
    color: var(--aea-assistant-msg-text);
    border-bottom-left-radius: 4px;
}

.aea-msg-user {
    align-self: flex-end;
    background: var(--aea-user-msg-bg);
    color: var(--aea-user-msg-text);
    border-bottom-right-radius: 4px;
}

.aea-msg-error {
    align-self: center;
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    font-size: 13px;
    text-align: center;
}

/* ─── Typing Indicator ───────────────────────────────────────────── */
.aea-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-start;
    background: var(--aea-assistant-msg-bg);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

.aea-typing span {
    width: 7px;
    height: 7px;
    background: var(--aea-grey-olive);
    border-radius: 50%;
    animation: aea-bounce 1.4s infinite ease-in-out;
}

.aea-typing span:nth-child(2) { animation-delay: 0.16s; }
.aea-typing span:nth-child(3) { animation-delay: 0.32s; }

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

/* ─── Input Area ─────────────────────────────────────────────────── */
.aea-chat-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--aea-bone);
    background: var(--aea-input-area-bg);
    flex-shrink: 0;
}

.aea-chat-input textarea {
    flex: 1;
    border: 1px solid var(--aea-dust);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    resize: none;
    outline: none;
    max-height: 100px;
    line-height: 1.4;
    color: var(--aea-granite);
    background: var(--aea-white);
    transition: border-color 0.15s ease;
}

.aea-chat-input textarea::placeholder {
    color: var(--aea-grey-olive);
}

.aea-chat-input textarea:focus {
    border-color: var(--aea-accent);
}

.aea-chat-input button {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background: var(--aea-header-bg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease;
}

.aea-chat-input button:hover {
    background: var(--aea-accent);
}

.aea-chat-input button:disabled {
    background: var(--aea-bone);
    cursor: not-allowed;
}

.aea-chat-input button svg {
    width: 18px;
    height: 18px;
    fill: var(--aea-header-text);
}

/* ─── Powered By ─────────────────────────────────────────────────── */
.aea-chat-footer {
    text-align: center;
    padding: 6px;
    font-size: 11px;
    color: var(--aea-grey-olive);
    background: var(--aea-input-area-bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.aea-chat-footer a {
    color: inherit;
    text-decoration: underline;
}

.aea-chat-footer a:hover {
    color: var(--aea-accent);
}

.aea-msg-assistant a {
    color: var(--aea-accent);
    text-decoration: underline;
}

.aea-msg-assistant a:hover {
    text-decoration: none;
}

/* ─── Mobile ─────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    #aea-chat-window {
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    #aea-chat-toggle {
        bottom: 16px;
        right: 16px;
    }
}
