/**
 * Ave AI Widget CSS — By AVENILE Thailand
 * Premium Chat Widget Styling
 */

/* ─── Reset & Variables ──────────────────────────── */
.ave-widget,
.ave-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Noto Sans Thai', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.ave-widget {
    --ave-primary: #E94788;
    --ave-secondary: #0D3D35;
    --ave-accent: #00A8A8;
    --ave-bg: #f8fafc;
    --ave-bubble-bot: #ffffff;
    --ave-bubble-user: var(--ave-primary);
    --ave-text: #1e293b;
    --ave-text-light: #64748b;
    --ave-border: #e2e8f0;
    --ave-radius: 16px;
    --ave-radius-sm: 12px;
    --ave-shadow: 0 8px 32px rgba(0, 0, 0, .12);
    --ave-shadow-lg: 0 12px 48px rgba(0, 0, 0, .18);

    position: fixed;
    z-index: 999999;
    bottom: 24px;
}

.ave-widget.ave-pos-right {
    right: 24px;
}

.ave-widget.ave-pos-left {
    left: 24px;
}

/* ─── Toggle Button ──────────────────────────────── */
.ave-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    position: absolute;
    bottom: 0;
    background: linear-gradient(135deg, var(--ave-secondary), var(--ave-accent));
    color: #fff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, .2);
    transition: all .35s cubic-bezier(.4, 0, .2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.ave-pos-right .ave-toggle {
    right: 0;
}

.ave-pos-left .ave-toggle {
    left: 0;
}

.ave-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0, 0, 0, .25);
}

.ave-toggle:active {
    transform: scale(.95);
}

.ave-toggle-icon,
.ave-toggle-close {
    position: absolute;
    font-size: 26px;
    transition: all .35s cubic-bezier(.4, 0, .2, 1);
}

.ave-toggle-close {
    opacity: 0;
    transform: rotate(-90deg) scale(.5);
    font-size: 22px;
    font-style: normal;
}

.ave-widget.open .ave-toggle-icon {
    opacity: 0;
    transform: rotate(90deg) scale(.5);
}

.ave-widget.open .ave-toggle-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Pulse animation */
.ave-toggle-pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--ave-accent);
    animation: avePulse 2.5s ease-in-out infinite;
    pointer-events: none;
}

.ave-widget.open .ave-toggle-pulse {
    display: none;
}

@keyframes avePulse {

    0%,
    100% {
        opacity: 0;
        transform: scale(.8);
    }

    50% {
        opacity: .5;
        transform: scale(1.15);
    }
}

/* ─── Chat Window ────────────────────────────────── */
.ave-window {
    position: absolute;
    bottom: 74px;
    width: 380px;
    max-height: 580px;
    height: 580px;
    border-radius: var(--ave-radius);
    background: var(--ave-bg);
    box-shadow: var(--ave-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(.96);
    pointer-events: none;
    transition: all .35s cubic-bezier(.4, 0, .2, 1);
    border: 1px solid rgba(0, 0, 0, .06);
}

.ave-pos-right .ave-window {
    right: 0;
}

.ave-pos-left .ave-window {
    left: 0;
}

.ave-widget.open .ave-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ─── Header ─────────────────────────────────────── */
.ave-header {
    background: linear-gradient(135deg, var(--ave-secondary), var(--ave-accent));
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.ave-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ave-agent-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.ave-agent-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, .3);
}

.ave-agent-avatar span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, .15);
    border-radius: 50%;
    font-size: 20px;
}

.ave-status-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid var(--ave-secondary);
    animation: aveGlow 2s ease-in-out infinite;
}

@keyframes aveGlow {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, .4);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(34, 197, 94, 0);
    }
}

.ave-agent-info {
    color: #fff;
}

.ave-agent-info strong {
    display: block;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -.2px;
}

.ave-agent-info small {
    opacity: .8;
    font-size: 11px;
}

.ave-header-actions {
    display: flex;
    gap: 4px;
}

.ave-header-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, .12);
    border-radius: 8px;
    cursor: pointer;
    color: #fff;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s;
}

.ave-header-btn:hover {
    background: rgba(255, 255, 255, .25);
}

/* ─── Messages Area ──────────────────────────────── */
.ave-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.ave-messages::-webkit-scrollbar {
    width: 4px;
}

.ave-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, .1);
    border-radius: 4px;
}

/* ─── Message Bubbles ────────────────────────────── */
.ave-msg {
    display: flex;
    gap: 8px;
    animation: aveMsgIn .35s cubic-bezier(.4, 0, .2, 1);
    max-width: 88%;
}

.ave-msg-bot {
    align-self: flex-start;
}

.ave-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ave-msg-avatar {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
}

.ave-msg-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.ave-msg-avatar span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: var(--ave-accent);
    border-radius: 50%;
    font-size: 14px;
}

.ave-msg-user .ave-msg-avatar {
    display: none;
}

.ave-msg-bubble {
    padding: 10px 14px;
    font-size: 13.5px;
    line-height: 1.65;
    color: var(--ave-text);
    word-break: break-word;
    white-space: pre-line;
}

.ave-msg-bot .ave-msg-bubble {
    background: var(--ave-bubble-bot);
    border-radius: 4px 14px 14px 14px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .05);
    border: 1px solid var(--ave-border);
}

.ave-msg-user .ave-msg-bubble {
    background: linear-gradient(135deg, var(--ave-primary), #ff6b9d);
    color: #fff;
    border-radius: 14px 4px 14px 14px;
    box-shadow: 0 2px 8px rgba(233, 71, 136, .25);
}

/* Markdown-like styling */
.ave-msg-bubble strong {
    font-weight: 700;
}

.ave-msg-bubble em {
    font-style: italic;
}

.ave-msg-time {
    font-size: 10px;
    color: var(--ave-text-light);
    margin-top: 4px;
    padding: 0 4px;
}

.ave-msg-user .ave-msg-time {
    text-align: right;
}

@keyframes aveMsgIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Quick Actions ──────────────────────────────── */
.ave-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0 4px 38px;
    animation: aveMsgIn .4s cubic-bezier(.4, 0, .2, 1);
}

.ave-quick-btn {
    padding: 6px 14px;
    font-size: 12px;
    border: 1.5px solid var(--ave-border);
    border-radius: 20px;
    background: #fff;
    color: var(--ave-text);
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
    font-family: inherit;
}

.ave-quick-btn:hover {
    border-color: var(--ave-primary);
    color: var(--ave-primary);
    background: #fdf2f8;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(233, 71, 136, .15);
}

.ave-quick-btn:active {
    transform: scale(.96);
}

/* ─── Typing Indicator ──────────────────────────── */
.ave-typing {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    padding: 0 16px 6px;
    flex-shrink: 0;
}

.ave-typing-dots {
    background: var(--ave-bubble-bot);
    border: 1px solid var(--ave-border);
    border-radius: 4px 14px 14px 14px;
    padding: 10px 16px;
    display: flex;
    gap: 4px;
    align-items: center;
}

.ave-typing-dots span {
    width: 7px;
    height: 7px;
    background: var(--ave-text-light);
    border-radius: 50%;
    animation: aveTypeDot 1.4s infinite ease-in-out;
}

.ave-typing-dots span:nth-child(2) {
    animation-delay: .15s;
}

.ave-typing-dots span:nth-child(3) {
    animation-delay: .3s;
}

@keyframes aveTypeDot {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: .4;
    }

    30% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

/* ─── Input Area ─────────────────────────────────── */
.ave-input-area {
    padding: 10px 14px 8px;
    border-top: 1px solid var(--ave-border);
    background: #fff;
    flex-shrink: 0;
}

.ave-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--ave-bg);
    border: 1.5px solid var(--ave-border);
    border-radius: var(--ave-radius-sm);
    padding: 6px 8px 6px 14px;
    transition: border-color .2s, box-shadow .2s;
}

.ave-input-wrapper:focus-within {
    border-color: var(--ave-accent);
    box-shadow: 0 0 0 3px rgba(0, 168, 168, .08);
}

.ave-input-wrapper textarea {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 13.5px;
    line-height: 1.5;
    resize: none;
    max-height: 100px;
    min-height: 22px;
    color: var(--ave-text);
    font-family: inherit;
    padding: 4px 0;
}

.ave-input-wrapper textarea::placeholder {
    color: var(--ave-text-light);
}

.ave-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--ave-primary), #ff6b9d);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all .25s;
    opacity: .4;
    transform: scale(.9);
}

.ave-send-btn:not(:disabled) {
    opacity: 1;
    transform: scale(1);
}

.ave-send-btn:not(:disabled):hover {
    transform: scale(1.08);
    box-shadow: 0 3px 12px rgba(233, 71, 136, .35);
}

.ave-send-btn:not(:disabled):active {
    transform: scale(.92);
}

.ave-send-btn svg {
    width: 16px;
    height: 16px;
}

/* ─── Footer ─────────────────────────────────────── */
.ave-footer {
    text-align: center;
    padding: 6px 0 2px;
}

.ave-footer small {
    font-size: 10px;
    color: var(--ave-text-light);
    opacity: .6;
    letter-spacing: .3px;
}

.ave-footer strong {
    color: var(--ave-primary);
    font-weight: 700;
}

/* ─── Error State ────────────────────────────────── */
.ave-msg-error .ave-msg-bubble {
    background: #fef2f2 !important;
    border-color: #fecaca !important;
    color: #991b1b !important;
}

/* ─── Clear Confirmation ─────────────────────────── */
.ave-clear-confirm {
    background: rgba(0, 0, 0, .5);
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    animation: aveFadeIn .2s ease;
}

.ave-clear-dialog {
    background: #fff;
    border-radius: var(--ave-radius-sm);
    padding: 24px;
    text-align: center;
    box-shadow: var(--ave-shadow-lg);
    max-width: 280px;
}

.ave-clear-dialog p {
    margin: 0 0 16px;
    font-size: 14px;
    color: var(--ave-text);
}

.ave-clear-dialog button {
    padding: 8px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    margin: 0 4px;
    transition: all .2s;
}

.ave-clear-yes {
    background: #ef4444;
    color: #fff;
}

.ave-clear-yes:hover {
    background: #dc2626;
}

.ave-clear-no {
    background: var(--ave-bg);
    color: var(--ave-text);
    border: 1px solid var(--ave-border) !important;
}

@keyframes aveFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* ─── Product Cards in Chat ──────────────────────── */
.ave-products-wrap {
    max-width: 100%;
    overflow: hidden;
    padding: 4px 0;
}

.ave-products-scroll {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding: 4px 2px 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, .12) transparent;
}

.ave-products-scroll::-webkit-scrollbar {
    height: 4px;
}

.ave-products-scroll::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, .12);
    border-radius: 4px;
}

.ave-product-card {
    flex: 0 0 180px;
    background: #fff;
    border: 1.5px solid var(--ave-border);
    border-radius: 12px;
    overflow: hidden;
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    transition: all .25s;
    animation: aveMsgIn .4s cubic-bezier(.4, 0, .2, 1);
}

.ave-product-card:hover {
    border-color: var(--ave-primary);
    box-shadow: 0 4px 16px rgba(233, 71, 136, .12);
    transform: translateY(-2px);
}

/* Product Image */
.ave-p-img {
    width: 100%;
    height: 140px;
    overflow: hidden;
    background: #f8fafc;
    position: relative;
}

.ave-p-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .3s;
}

.ave-product-card:hover .ave-p-img img {
    transform: scale(1.05);
}

/* Product Info */
.ave-p-info {
    padding: 10px 10px 6px;
    flex: 1;
}

.ave-p-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--ave-text);
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 4px;
}

.ave-p-desc {
    font-size: 10px;
    color: var(--ave-text-light);
    line-height: 1.4;
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Price */
.ave-p-price {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.ave-p-price-current {
    font-size: 14px;
    font-weight: 700;
    color: var(--ave-primary);
}

.ave-p-price-sale {
    font-size: 14px;
    font-weight: 700;
    color: #dc2626;
}

.ave-p-price-old {
    font-size: 11px;
    color: #94a3b8;
    text-decoration: line-through;
}

/* Stock Badge */
.ave-p-stock {
    font-size: 9px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 8px;
    text-transform: uppercase;
    letter-spacing: .3px;
}

.ave-p-stock.in {
    background: #dcfce7;
    color: #15803d;
}

.ave-p-stock.out {
    background: #fee2e2;
    color: #991b1b;
}

/* Action Buttons */
.ave-p-actions {
    padding: 6px 10px 10px;
    display: flex;
    gap: 6px;
}

.ave-p-btn {
    flex: 1;
    padding: 6px 4px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: all .2s;
    border: none;
    font-family: inherit;
    display: block;
    line-height: 1.3;
}

.ave-p-btn-view {
    background: #f1f5f9;
    color: var(--ave-text);
    border: 1px solid var(--ave-border);
}

.ave-p-btn-view:hover {
    background: #e2e8f0;
    color: var(--ave-text);
}

.ave-p-btn-buy {
    background: linear-gradient(135deg, var(--ave-primary), #ff6b9d);
    color: #fff;
    box-shadow: 0 2px 8px rgba(233, 71, 136, .2);
}

.ave-p-btn-buy:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(233, 71, 136, .35);
    color: #fff;
}

/* ─── Mobile ─────────────────────────────────────── */
@media (max-width: 480px) {
    .ave-widget {
        bottom: 16px;
    }

    .ave-pos-right {
        right: 16px;
    }

    .ave-pos-left {
        left: 16px;
    }

    .ave-window {
        position: fixed;
        inset: 0;
        width: 100%;
        max-height: 100%;
        height: 100%;
        border-radius: 0;
        bottom: 0;
    }

    .ave-toggle {
        width: 54px;
        height: 54px;
    }

    .ave-product-card {
        flex: 0 0 160px;
    }

    .ave-p-img {
        height: 120px;
    }

    .ave-msg.ave-msg-bot {
        max-width: 95%;
    }
}

/* ─── Reduced Motion ─────────────────────────────── */
@media (prefers-reduced-motion: reduce) {

    .ave-widget *,
    .ave-widget *::before,
    .ave-widget *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}