/* WooCommerce AI Chat Widget */
:root {
    --wac-primary: #114989;
    --wac-primary-dark: #6D28D9;
    --wac-text-on-primary: #FFFFFF;
    --wac-bg: #FFFFFF;
    --wac-bg-secondary: #F9FAFB;
    --wac-text: #1F2937;
    --wac-text-secondary: #6B7280;
    --wac-border: #E5E7EB;
    --wac-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    --wac-radius: 16px;
    --wac-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    --wac-font-size: 14px;
    --wac-btn-size: 60px;
}

/* Reset */
#wac-chat-widget,
#wac-chat-widget * {
    box-sizing: border-box;
    font-family: var(--wac-font);
}

/* Widget Container */
#wac-chat-widget {
    position: fixed;
    z-index: 999999;
    bottom: 24px;
}

#wac-chat-widget.wac-position-bottom-right {
    right: 24px;
}

#wac-chat-widget.wac-position-bottom-left {
    left: 24px;
}

/* Toggle Button */
.wac-toggle-btn {
    width: var(--wac-btn-size);
    height: var(--wac-btn-size);
    border-radius: 50%;
    border: none;
    background: var(--wac-primary);
    color: var(--wac-text-on-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
}

.wac-toggle-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.wac-toggle-btn:active {
    transform: scale(0.95);
}

.wac-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #EF4444;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* Chat Window */
.wac-chat-window {
    position: absolute;
    bottom: calc(var(--wac-btn-size) + 16px);
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 580px;
    max-height: calc(100vh - 120px);
    background: var(--wac-bg);
    border-radius: var(--wac-radius);
    box-shadow: var(--wac-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: wacSlideUp 0.3s ease;
    border: 1px solid var(--wac-border);
}

.wac-position-bottom-right .wac-chat-window {
    right: 0;
}

.wac-position-bottom-left .wac-chat-window {
    left: 0;
}

@keyframes wacSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
.wac-chat-header {
    background: var(--wac-primary);
    color: var(--wac-text-on-primary);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.wac-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.wac-header-title {
    font-size: calc(var(--wac-font-size) + 2px);
    font-weight: 600;
    line-height: 1.3;
}

.wac-header-subtitle {
    font-size: calc(var(--wac-font-size) - 2px);
    opacity: 0.85;
    line-height: 1.3;
    margin-top: 2px;
}

.wac-header-close {
    background: none;
    border: none;
    color: var(--wac-text-on-primary);
    cursor: pointer;
    opacity: 0.8;
    padding: 6px;
    border-radius: 8px;
    transition: opacity 0.2s, background 0.2s;
}

.wac-header-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
}

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

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

.wac-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

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

/* Message Bubbles */
.wac-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: wacFadeIn 0.3s ease;
}

@keyframes wacFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.wac-message-user {
    align-self: flex-end;
}

.wac-message-assistant {
    align-self: flex-start;
}

.wac-message-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: var(--wac-font-size);
    line-height: 1.55;
    word-wrap: break-word;
}

.wac-message-user .wac-message-bubble {
    background: var(--wac-primary);
    color: var(--wac-text-on-primary);
    border-bottom-right-radius: 4px;
}

.wac-message-assistant .wac-message-bubble {
    background: var(--wac-bg);
    color: var(--wac-text);
    border: 1px solid var(--wac-border);
    border-bottom-left-radius: 4px;
}

.wac-message-bubble p {
    margin: 0 0 8px 0;
}

.wac-message-bubble p:last-child {
    margin-bottom: 0;
}

.wac-message-bubble strong {
    font-weight: 600;
}

.wac-message-bubble ul,
.wac-message-bubble ol {
    margin: 6px 0;
    padding-left: 20px;
}

.wac-message-bubble li {
    margin: 3px 0;
}

.wac-message-bubble a {
    color: var(--wac-primary);
    text-decoration: underline;
}

.wac-message-user .wac-message-bubble a {
    color: var(--wac-text-on-primary);
}

.wac-message-time {
    font-size: 11px;
    color: var(--wac-text-secondary);
    margin-top: 4px;
    padding: 0 4px;
}

.wac-message-user .wac-message-time {
    text-align: right;
}

/* Product Cards */
.wac-product-cards {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 8px 4px 12px 4px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

.wac-product-cards::-webkit-scrollbar {
    height: 4px;
}

.wac-product-cards::-webkit-scrollbar-thumb {
    background: #D1D5DB;
    border-radius: 2px;
}

.wac-product-card {
    flex: 0 0 180px;
    scroll-snap-align: start;
    background: var(--wac-bg);
    border: 1px solid var(--wac-border);
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    color: var(--wac-text);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}

.wac-product-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.wac-product-card-image-wrap {
    position: relative;
    width: 100%;
    height: 140px;
    overflow: hidden;
    background: #F3F4F6;
}

.wac-product-card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.wac-product-card:hover .wac-product-card-image {
    transform: scale(1.05);
}

.wac-product-card-badges {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.wac-product-card-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    line-height: 1;
    width: fit-content;
}

.wac-badge-sale {
    background: #DC2626;
    color: #FFFFFF;
}

.wac-badge-outofstock {
    background: #6B7280;
    color: #FFFFFF;
}

.wac-product-card-info {
    padding: 12px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.wac-product-card-name {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--wac-text);
}

.wac-product-card-price {
    font-size: 15px;
    font-weight: 700;
    color: var(--wac-primary);
    margin-bottom: 6px;
}

/* Rating Stars */
.wac-product-rating {
    display: flex;
    align-items: center;
    gap: 1px;
    margin-bottom: 8px;
}

.wac-star {
    font-size: 12px;
    color: #FBBF24;
}

.wac-star-empty {
    color: #D1D5DB;
}

.wac-product-card-cta {
    display: block;
    width: 100%;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--wac-primary);
    background: none;
    border: none;
    padding: 8px 0 0;
    margin-top: auto;
    border-top: 1px solid var(--wac-border);
    text-decoration: none;
    letter-spacing: 0.2px;
}

/* Typing Indicator */
.wac-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--wac-bg);
    border: 1px solid var(--wac-border);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    max-width: 80px;
}

.wac-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9CA3AF;
    animation: wacBounce 1.4s infinite;
}

.wac-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.wac-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* Input Area */
.wac-chat-input-area {
    padding: 14px 16px;
    border-top: 1px solid var(--wac-border);
    background: var(--wac-bg);
    flex-shrink: 0;
}

.wac-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--wac-bg-secondary);
    border: 1px solid var(--wac-border);
    border-radius: 12px;
    padding: 8px 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.wac-input-wrapper:focus-within {
    border-color: var(--wac-primary);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

.wac-input {
    flex: 1;
    border: none;
    background: none;
    font-size: var(--wac-font-size);
    line-height: 1.5;
    resize: none;
    outline: none;
    color: var(--wac-text);
    max-height: 120px;
    font-family: var(--wac-font);
}

.wac-input::placeholder {
    color: #9CA3AF;
}

.wac-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: var(--wac-primary);
    color: var(--wac-text-on-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.2s;
}

.wac-send-btn:hover:not(:disabled) {
    background: var(--wac-primary-dark);
    transform: scale(1.05);
}

.wac-send-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.wac-powered-by {
    text-align: center;
    font-size: 11px;
    color: #9CA3AF;
    margin-top: 8px;
}

/* ─── Mobile Responsive ─────────────────────────────────── */

/*
 * Mobile strategy: FULLSCREEN chat on phones.
 * The chat window covers the entire viewport for maximum usability.
 * Toggle button shrinks. Safe-area insets for notched phones (iPhone X+).
 */

/* Phones: fullscreen chat */
@media (max-width: 480px) {
    #wac-chat-widget {
        bottom: 16px;
    }

    #wac-chat-widget.wac-position-bottom-right {
        right: 16px;
    }

    #wac-chat-widget.wac-position-bottom-left {
        left: 16px;
    }

    .wac-toggle-btn {
        width: min(var(--wac-btn-size), 54px);
        height: min(var(--wac-btn-size), 54px);
    }

    .wac-toggle-btn svg {
        width: 22px;
        height: 22px;
    }

    /* Fullscreen chat window on mobile */
    .wac-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        width: 100dvw;
        height: 100vh;
        height: 100dvh;
        max-width: 100vw;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: var(--wac-radius);
        border: none;
        animation: wacSlideUpMobile 0.25s ease;
    }

    @keyframes wacSlideUpMobile {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* Hide toggle button when chat is open */
    #wac-chat-widget.wac-chat-open .wac-toggle-btn {
        display: none;
    }

    /* Header: safe area for notched phones */
    .wac-chat-header {
        padding: 14px 16px;
        padding-top: max(14px, env(safe-area-inset-top, 14px));
    }

    .wac-header-title {
        font-size: 16px;
    }

    .wac-header-subtitle {
        font-size: 12px;
    }

    .wac-header-close {
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Messages area: more room on fullscreen */
    .wac-chat-messages {
        padding: 14px 12px;
        gap: 10px;
    }

    .wac-message {
        max-width: 88%;
    }

    .wac-message-bubble {
        font-size: 15px;
        padding: 10px 14px;
        line-height: 1.5;
    }

    .wac-message-time {
        font-size: 11px;
    }

    /* Product cards: wider on fullscreen */
    .wac-product-cards {
        gap: 10px;
        padding: 8px 4px 12px 4px;
    }

    .wac-product-card {
        flex: 0 0 165px;
    }

    .wac-product-card-image-wrap {
        height: 120px;
    }

    .wac-product-card-info {
        padding: 10px;
    }

    .wac-product-card-name {
        font-size: 13px;
    }

    .wac-product-card-price {
        font-size: 14px;
    }

    .wac-product-card-cta {
        font-size: 12px;
        padding: 8px 0 2px;
    }

    /* Input area: safe area for bottom bar (iPhone etc.) */
    .wac-chat-input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
    }

    .wac-input-wrapper {
        padding: 8px 12px;
    }

    .wac-input {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    .wac-send-btn {
        width: 40px;
        height: 40px;
        min-width: 44px;
        min-height: 44px;
    }

    .wac-powered-by {
        font-size: 10px;
        margin-top: 6px;
    }

    /* History panel on mobile */
    .wac-history-item {
        padding: 14px;
    }

    .wac-history-load-btn {
        padding: 8px 16px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    .wac-history-new-btn {
        padding: 14px;
        min-height: 44px;
    }
}

/* Very small phones (iPhone SE 320px, small Android) */
@media (max-width: 375px) {
    .wac-toggle-btn {
        width: 50px;
        height: 50px;
    }

    .wac-toggle-btn svg {
        width: 20px;
        height: 20px;
    }

    .wac-chat-header {
        padding: 12px 14px;
        padding-top: max(12px, env(safe-area-inset-top, 12px));
    }

    .wac-header-avatar {
        width: 34px;
        height: 34px;
    }

    .wac-header-avatar svg {
        width: 16px;
        height: 16px;
    }

    .wac-header-info {
        gap: 10px;
    }

    .wac-header-title {
        font-size: 15px;
    }

    .wac-header-subtitle {
        font-size: 11px;
    }

    .wac-chat-messages {
        padding: 10px;
        gap: 8px;
    }

    .wac-message {
        max-width: 92%;
    }

    .wac-message-bubble {
        font-size: 14px;
        padding: 9px 12px;
    }

    .wac-product-cards {
        gap: 8px;
        padding: 6px 2px 10px 2px;
    }

    .wac-product-card {
        flex: 0 0 150px;
    }

    .wac-product-card-image-wrap {
        height: 100px;
    }

    .wac-product-card-info {
        padding: 8px;
    }

    .wac-product-card-name {
        font-size: 12px;
        margin-bottom: 4px;
    }

    .wac-product-card-price {
        font-size: 13px;
        margin-bottom: 4px;
    }

    .wac-star {
        font-size: 10px;
    }

    .wac-product-card-cta {
        font-size: 11px;
        padding: 6px 0 2px;
    }

    .wac-chat-input-area {
        padding: 8px 10px;
        padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
    }

    .wac-input-wrapper {
        padding: 6px 10px;
        gap: 6px;
    }
}

/* Landscape mode on phones */
@media (max-height: 500px) and (max-width: 768px) {
    .wac-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-width: 100vw;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: var(--wac-radius);
        border: none;
    }

    #wac-chat-widget.wac-chat-open .wac-toggle-btn {
        display: none;
    }

    .wac-chat-header {
        padding: 8px 14px;
        padding-left: max(14px, env(safe-area-inset-left, 14px));
        padding-right: max(14px, env(safe-area-inset-right, 14px));
    }

    .wac-header-avatar {
        width: 28px;
        height: 28px;
    }

    .wac-header-avatar svg {
        width: 14px;
        height: 14px;
    }

    .wac-header-title {
        font-size: 14px;
    }

    .wac-header-subtitle {
        display: none;
    }

    .wac-chat-messages {
        padding: 8px 12px;
        padding-left: max(12px, env(safe-area-inset-left, 12px));
        padding-right: max(12px, env(safe-area-inset-right, 12px));
        gap: 6px;
    }

    .wac-message-bubble {
        padding: 7px 10px;
        font-size: 13px;
    }

    .wac-message-time {
        font-size: 10px;
        margin-top: 2px;
    }

    .wac-product-card {
        flex: 0 0 140px;
    }

    .wac-product-card-image-wrap {
        height: 80px;
    }

    .wac-product-card-info {
        padding: 6px 8px;
    }

    .wac-product-card-name {
        font-size: 11px;
    }

    .wac-product-card-price {
        font-size: 12px;
    }

    .wac-product-card-cta {
        font-size: 10px;
        padding: 4px 0 0;
    }

    .wac-chat-input-area {
        padding: 6px 12px;
        padding-left: max(12px, env(safe-area-inset-left, 12px));
        padding-right: max(12px, env(safe-area-inset-right, 12px));
    }

    .wac-input-wrapper {
        padding: 4px 8px;
    }

    .wac-input {
        max-height: 60px;
    }

    .wac-send-btn {
        width: 32px;
        height: 32px;
        min-width: 36px;
        min-height: 36px;
    }

    .wac-powered-by {
        display: none;
    }
}

/* Prevent body scroll when chat is open on mobile */
body.wac-body-no-scroll {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Chat History Panel */
.wac-history-panel {
    background: var(--wac-bg);
    border: 1px solid var(--wac-border);
    border-radius: 12px;
    overflow: hidden;
    animation: wacFadeIn 0.3s ease;
}

.wac-history-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: var(--wac-primary);
    color: var(--wac-text-on-primary);
    font-size: 13px;
    font-weight: 600;
}

.wac-history-icon {
    font-size: 16px;
}

.wac-history-item {
    padding: 12px 14px;
    border-bottom: 1px solid var(--wac-border);
    transition: background 0.15s;
}

.wac-history-item:last-of-type {
    border-bottom: none;
}

.wac-history-item:hover {
    background: var(--wac-bg-secondary);
}

.wac-history-item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.wac-history-date {
    font-size: 11px;
    font-weight: 600;
    color: var(--wac-text-secondary);
}

.wac-history-count {
    font-size: 11px;
    color: var(--wac-text-secondary);
    background: var(--wac-bg-secondary);
    padding: 2px 6px;
    border-radius: 10px;
    border: 1px solid var(--wac-border);
}

.wac-history-preview {
    font-size: 12px;
    color: var(--wac-text);
    margin-bottom: 8px;
    line-height: 1.4;
}

.wac-history-load-btn {
    font-size: 12px;
    font-weight: 600;
    color: var(--wac-primary);
    background: none;
    border: 1px solid var(--wac-primary);
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.wac-history-load-btn:hover {
    background: var(--wac-primary);
    color: var(--wac-text-on-primary);
}

.wac-history-new-btn {
    display: block;
    width: 100%;
    padding: 11px 14px;
    background: var(--wac-bg-secondary);
    border: none;
    border-top: 1px solid var(--wac-border);
    color: var(--wac-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: background 0.15s;
}

.wac-history-new-btn:hover {
    background: var(--wac-border);
}

.wac-history-separator {
    text-align: center;
    font-size: 11px;
    color: var(--wac-text-secondary);
    padding: 4px 12px;
    position: relative;
}

.wac-history-separator::before,
.wac-history-separator::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 25%;
    height: 1px;
    background: var(--wac-border);
}

.wac-history-separator::before { left: 0; }
.wac-history-separator::after { right: 0; }

.wac-history-loading {
    text-align: center;
    font-size: 13px;
    color: var(--wac-text-secondary);
    padding: 16px;
    animation: wacFadeIn 0.3s ease;
}
