/* ═══════════════════════════════════════════════════════════════════
   Jewellery Chatbot Widget — Luxury Gold & Adaptive Theme
   Built better than kshomestore chatbot.
   Supports: light mode, dark mode, auto-detect, live theme switching.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Design Tokens (Default: Luxury Dark Gold) ─────────────────────────── */
:root {
    --jw-primary: #c9a84c;
    /* Signature gold */
    --jw-primary-dk: #9a7330;
    /* Darker gold */
    --jw-primary-lt: #e8c96a;
    /* Light gold */
    --jw-dark: #1a1008;
    /* Deep dark background */
    --jw-bg: #0d0a04;
    /* Chat window bg */
    --jw-surface: #1e1507;
    /* Message surface */
    --jw-surface2: #2a1e09;
    /* Elevated surface */
    --jw-cream: #fdf6e8;
    /* Light cream for AI bubble */
    --jw-border: rgba(201, 168, 76, 0.25);
    --jw-text: #f5edd8;
    /* Main text */
    --jw-text-muted: rgba(245, 237, 216, 0.55);
    --jw-shadow: 0 24px 64px rgba(0, 0, 0, 0.6), 0 4px 16px rgba(201, 168, 76, 0.15);
    --jw-font: 'Playfair Display', 'Inter', 'Segoe UI', system-ui, serif;
    --jw-font-body: 'Lato', 'Inter', 'Segoe UI', system-ui, sans-serif;
    --jw-radius: 18px;
    --jw-btn-size: 62px;
}

/* ── Light mode overrides ─────────────────────────────────────────────── */
.jw-theme-light,
[data-jw-theme="light"] {
    --jw-bg: #fffdf5;
    --jw-surface: #fff;
    --jw-surface2: #fdf3d4;
    --jw-dark: #1a1008;
    --jw-text: #2c1a06;
    --jw-text-muted: #8c714a;
    --jw-border: rgba(201, 168, 76, 0.3);
    --jw-shadow: 0 24px 64px rgba(44, 26, 6, 0.18);
}

/* ── System dark-mode detection ───────────────────────────────────────── */
@media (prefers-color-scheme: light) {
    #jw-chat:not([data-override-theme]) {
        --jw-bg: #fffdf5;
        --jw-surface: #fff;
        --jw-surface2: #fdf3d4;
        --jw-text: #2c1a06;
        --jw-text-muted: #8c714a;
        --jw-border: rgba(201, 168, 76, 0.3);
        --jw-shadow: 0 24px 64px rgba(44, 26, 6, 0.18);
    }
}

/* ── Container ──────────────────────────────────────────────────────────── */
#jw-chat {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 999999;
    font-family: var(--jw-font-body);
    font-size: 14px;
    line-height: 1.55;
}

/* ── Chat Window ────────────────────────────────────────────────────────── */
#jw-window {
    position: absolute;
    bottom: 78px;
    right: 0;
    width: 385px;
    height: 600px;
    background: var(--jw-bg);
    border-radius: 22px;
    box-shadow: var(--jw-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--jw-border);
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.28s cubic-bezier(.4, 0, .2, 1), transform 0.28s cubic-bezier(.4, 0, .2, 1);
}

#jw-window.jw-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
#jw-header {
    background: linear-gradient(135deg, #1f1304 0%, #0d0a04 50%, #1a0f03 100%);
    border-bottom: 1px solid var(--jw-border);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

#jw-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(201, 168, 76, 0.06), transparent);
    animation: jw-shimmer 3s infinite;
}

@keyframes jw-shimmer {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(100%);
    }
}

#jw-header-left {
    display: flex;
    align-items: center;
    gap: 13px;
    position: relative;
    z-index: 1;
}

#jw-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--jw-primary), var(--jw-primary-dk));
    border: 2px solid rgba(201, 168, 76, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    box-shadow: 0 0 16px rgba(201, 168, 76, 0.3);
    animation: jw-glow-pulse 3s infinite;
}

@keyframes jw-glow-pulse {

    0%,
    100% {
        box-shadow: 0 0 10px rgba(201, 168, 76, 0.25);
    }

    50% {
        box-shadow: 0 0 22px rgba(201, 168, 76, 0.5);
    }
}

#jw-title {
    color: var(--jw-primary-lt);
    font-family: var(--jw-font);
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.1px;
}

#jw-status {
    color: rgba(245, 237, 216, 0.6);
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.jw-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #86efac;
    display: inline-block;
    animation: jw-pulse 2s infinite;
}

@keyframes jw-pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.35;
    }
}

#jw-close {
    background: rgba(201, 168, 76, 0.12);
    border: 1px solid rgba(201, 168, 76, 0.2);
    color: var(--jw-primary-lt);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    position: relative;
    z-index: 1;
}

#jw-close:hover {
    background: rgba(201, 168, 76, 0.25);
}

/* ── Messages Area ──────────────────────────────────────────────────────── */
#jw-messages {
    flex: 1;
    padding: 16px 14px 8px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--jw-bg);
    scroll-behavior: smooth;
}

#jw-messages::-webkit-scrollbar {
    width: 3px;
}

#jw-messages::-webkit-scrollbar-thumb {
    background: var(--jw-primary-dk);
    border-radius: 3px;
}

/* ── Message Wrappers ───────────────────────────────────────────────────── */
.jw-msg-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 100%;
    animation: jw-fadein 0.22s ease;
}

@keyframes jw-fadein {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

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

.jw-ai,
.jw-admin {
    flex-direction: row;
}

.jw-user {
    flex-direction: row-reverse;
}

.jw-error {
    flex-direction: row;
}

/* ── Avatars ─────────────────────────────────────────────────────────────── */
.jw-av-sm {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--jw-primary), var(--jw-primary-dk));
    color: #000;
    font-size: 13px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-bottom: 4px;
}

.jw-admin .jw-av-sm {
    background: linear-gradient(135deg, #4ade80, #16a34a);
}

/* ── Bubbles ─────────────────────────────────────────────────────────────── */
.jw-bubble {
    max-width: 80%;
    padding: 11px 15px;
    border-radius: var(--jw-radius);
    word-break: break-word;
    font-size: 13.5px;
    line-height: 1.58;
}

.jw-ai .jw-bubble {
    background: var(--jw-surface);
    color: var(--jw-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--jw-border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.jw-user .jw-bubble {
    background: linear-gradient(135deg, var(--jw-primary), var(--jw-primary-dk));
    color: #1a0d00;
    border-bottom-right-radius: 4px;
    box-shadow: 0 3px 12px rgba(201, 168, 76, 0.4);
    font-weight: 500;
}

.jw-admin .jw-bubble {
    background: rgba(74, 222, 128, 0.12);
    color: #86efac;
    border: 1px solid rgba(74, 222, 128, 0.2);
    border-bottom-left-radius: 4px;
}

.jw-error .jw-bubble {
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-bottom-left-radius: 4px;
    font-size: 12.5px;
}

/* Bubble content typography */
.jw-bubble strong {
    font-weight: 700;
}

.jw-bubble em {
    font-style: italic;
}

.jw-bubble p {
    margin: 0 0 6px 0;
}

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

/* Timestamps */
.jw-ts {
    font-size: 10px;
    color: var(--jw-text-muted);
    align-self: flex-end;
    margin-bottom: 4px;
    white-space: nowrap;
}

.jw-user .jw-ts {
    order: -1;
}

/* ── Product Cards in Chat ──────────────────────────────────────────────── */
.jw-products-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    max-width: 320px;
    margin-top: 10px;
    animation: jw-fadein 0.3s ease;
}

.jw-product-card {
    background: var(--jw-surface2);
    border: 1px solid var(--jw-border);
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    transition: transform 0.15s, box-shadow 0.15s;
    display: block;
}

.jw-product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(201, 168, 76, 0.25);
    border-color: var(--jw-primary);
}

.jw-product-img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: var(--jw-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: var(--jw-primary);
}

.jw-product-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.jw-product-info {
    padding: 8px 10px;
}

.jw-product-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--jw-text);
    line-height: 1.4;
    margin-bottom: 3px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.jw-product-meta {
    font-size: 10px;
    color: var(--jw-text-muted);
    margin-bottom: 2px;
}

.jw-product-price {
    font-size: 12px;
    font-weight: 700;
    color: var(--jw-primary-lt);
}

/* ── Typing Dots ─────────────────────────────────────────────────────────── */
#jw-typing {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 4px 14px 8px;
    background: var(--jw-bg);
}

#jw-typing-inner {
    display: flex;
    align-items: center;
    gap: 8px;
}

.jw-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--jw-surface);
    padding: 10px 14px;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--jw-border);
}

.jw-dots span {
    width: 7px;
    height: 7px;
    background: var(--jw-primary);
    border-radius: 50%;
    display: inline-block;
    animation: jw-bounce 1.3s infinite;
}

.jw-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

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

@keyframes jw-bounce {

    0%,
    80%,
    100% {
        transform: scale(0.7);
        opacity: 0.4;
    }

    40% {
        transform: scale(1.1);
        opacity: 1;
    }
}

/* ── Quick Replies ──────────────────────────────────────────────────────── */
#jw-quick {
    padding: 6px 14px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    background: var(--jw-bg);
    flex-shrink: 0;
    border-top: 1px solid var(--jw-border);
}

.jw-qr {
    background: var(--jw-surface);
    border: 1px solid var(--jw-border);
    color: var(--jw-primary-lt);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--jw-font-body);
    white-space: nowrap;
}

.jw-qr:hover {
    background: var(--jw-primary);
    border-color: var(--jw-primary);
    color: #1a0d00;
    box-shadow: 0 2px 10px rgba(201, 168, 76, 0.35);
    transform: translateY(-1px);
}

/* ── Input Footer ────────────────────────────────────────────────────────── */
#jw-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--jw-border);
    background: var(--jw-surface2);
    flex-shrink: 0;
}

#jw-input {
    flex: 1;
    padding: 10px 16px;
    border: 1.5px solid var(--jw-border);
    border-radius: 25px;
    outline: none;
    font-size: 13.5px;
    color: var(--jw-text);
    font-family: var(--jw-font-body);
    background: var(--jw-bg);
    transition: border-color 0.15s, box-shadow 0.15s;
}

#jw-input:focus {
    border-color: var(--jw-primary);
    box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.15);
}

#jw-input::placeholder {
    color: var(--jw-text-muted);
}

#jw-input:disabled {
    opacity: 0.5;
}

#jw-send {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--jw-primary), var(--jw-primary-dk));
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.12s, box-shadow 0.15s;
    box-shadow: 0 3px 12px rgba(201, 168, 76, 0.4);
}

#jw-send svg {
    width: 18px;
    height: 18px;
    fill: #1a0d00;
}

#jw-send:hover {
    transform: scale(1.1);
    box-shadow: 0 5px 18px rgba(201, 168, 76, 0.55);
}

#jw-send:disabled {
    background: #4a3d1a;
    box-shadow: none;
    transform: none;
    cursor: not-allowed;
}

/* ── WhatsApp Button ─────────────────────────────────────────────────────── */
#jw-whatsapp {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px 5px 10px;
    background: rgba(37, 211, 102, 0.12);
    border: 1px solid rgba(37, 211, 102, 0.25);
    color: #4ade80;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    flex-shrink: 0;
}

#jw-whatsapp:hover {
    background: rgba(37, 211, 102, 0.22);
}

/* ── Powered Bar ─────────────────────────────────────────────────────────── */
#jw-powered {
    text-align: center;
    padding: 5px 14px 7px;
    font-size: 10px;
    color: var(--jw-text-muted);
    background: var(--jw-surface2);
    border-top: 1px solid var(--jw-border);
    flex-shrink: 0;
}

#jw-powered a {
    color: var(--jw-primary);
    text-decoration: none;
    font-weight: 600;
}

#jw-powered a:hover {
    text-decoration: underline;
}

/* ── Launcher Button ─────────────────────────────────────────────────────── */
#jw-btn {
    width: var(--jw-btn-size);
    height: var(--jw-btn-size);
    border-radius: 50%;
    background: linear-gradient(135deg, var(--jw-primary) 0%, var(--jw-primary-dk) 100%);
    box-shadow: 0 6px 24px rgba(201, 168, 76, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.22s cubic-bezier(.4, 0, .2, 1), box-shadow 0.22s;
    animation: jw-btn-appear 0.5s cubic-bezier(.4, 0, .2, 1);
}

@keyframes jw-btn-appear {
    from {
        opacity: 0;
        transform: scale(0.5);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

#jw-btn::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px solid rgba(201, 168, 76, 0.3);
    animation: jw-ring-pulse 3s infinite;
}

@keyframes jw-ring-pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 0.6;
    }

    50% {
        transform: scale(1.12);
        opacity: 0.1;
    }
}

#jw-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 10px 36px rgba(201, 168, 76, 0.65);
}

#jw-btn-icon {
    position: relative;
    width: 28px;
    height: 28px;
}

#jw-btn-icon svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 28px;
    height: 28px;
    fill: #1a0d00;
    transition: opacity 0.2s, transform 0.2s;
}

.jw-icon-chat {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.jw-icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.6);
}

#jw-btn.jw-open .jw-icon-chat {
    opacity: 0;
    transform: rotate(90deg) scale(0.6);
}

#jw-btn.jw-open .jw-icon-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Notification badge */
#jw-notif {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 20px;
    height: 20px;
    background: #ef4444;
    color: #fff;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid var(--jw-bg);
    animation: jw-pop 0.3s ease;
}

@keyframes jw-pop {
    from {
        transform: scale(0);
    }

    to {
        transform: scale(1);
    }
}

/* ── Disabled / Locked Screen ──────────────────────────────────────────── */
.jw-disabled-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 28px;
    text-align: center;
    gap: 14px;
}

.jw-disabled-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.12);
    border: 2px solid rgba(239, 68, 68, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
}

.jw-disabled-title {
    font-weight: 700;
    color: var(--jw-text);
    font-size: 1rem;
}

.jw-disabled-msg {
    font-size: 0.84rem;
    color: #fca5a5;
    line-height: 1.6;
    max-width: 270px;
}

/* ── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {

    /* ── Chat Window ── */
    #jw-window {
        width: calc(100vw - 20px);
        right: 0;
        bottom: 72px;
        border-radius: 16px;
        height: 68vh;
        max-height: 520px;
    }

    /* ── Launcher button: smaller ── */
    #jw-chat {
        right: 12px;
        bottom: 16px;
    }

    :root {
        --jw-btn-size: 46px;
        /* down from 62px on desktop */
    }

    #jw-btn-icon,
    #jw-btn-icon svg {
        width: 22px;
        height: 22px;
    }

    #jw-btn::before {
        inset: -2px;
    }

    /* ── Header: tighter ── */
    #jw-header {
        padding: 10px 14px;
    }

    #jw-avatar {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    #jw-title {
        font-size: 13px;
    }

    #jw-status {
        font-size: 10px;
    }

    #jw-close {
        width: 26px;
        height: 26px;
        font-size: 12px;
    }

    /* ── Messages ── */
    #jw-messages {
        padding: 12px 10px 6px;
        gap: 10px;
    }

    .jw-bubble {
        font-size: 12.5px;
        padding: 9px 12px;
    }

    /* ── Input footer ── */
    #jw-footer {
        padding: 9px 10px;
        gap: 6px;
    }

    #jw-input {
        padding: 8px 13px;
        font-size: 12.5px;
    }

    #jw-send {
        width: 36px;
        height: 36px;
    }

    #jw-send svg {
        width: 15px;
        height: 15px;
    }

    /* ── Quick replies ── */
    #jw-quick {
        padding: 5px 10px 6px;
        gap: 5px;
    }

    .jw-qr {
        font-size: 11px;
        padding: 4px 10px;
    }

    /* ── Products grid ── */
    .jw-products-grid {
        grid-template-columns: 1fr 1fr;
    }
}