/* ============================================================
   LocalDesign Chat Widget
   ============================================================ */

#ld-chat-widget {
    --ld-chat-font: var(--ld-font-body, var(--ld-font, 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif));
    --ld-chat-font-base: 1rem;      /* 16px — readable on all client sites */
    --ld-chat-font-sm: 0.9375rem;   /* 15px — header name */
    --ld-chat-font-xs: 0.8125rem;   /* 13px — status, cart, products */
    --ld-chat-font-2xs: 0.75rem;    /* 12px — badges, small labels */

    position: fixed;
    z-index: 99999;
    font-family: var(--ld-chat-font);
    font-size: var(--ld-chat-font-base);
    line-height: 1.5;
    color: #111827;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Position + size handled by fab.css (--ld-fab-*) */

/* ── Bubble ──────────────────────────────────────────────── */
.ld-chat-bubble {
    border-radius: 50%;
    background: var(--ld-primary, #2563EB);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0,0,0,.20);
    transition: transform .2s, box-shadow .2s;
    position: relative;
    overflow: visible;
    color: #fff;
}

.ld-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0,0,0,.28);
}

.ld-chat-bubble:active { transform: scale(.96); }

.ld-chat-bubble-icon,
.ld-chat-bubble-close {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .2s, transform .2s;
}

.ld-chat-bubble-icon svg { width: 28px; height: 28px; }
.ld-chat-bubble-close svg { width: 24px; height: 24px; }

.ld-chat-bubble-close { opacity: 0; transform: rotate(-90deg); }

.ld-chat-open .ld-chat-bubble-icon { opacity: 0; transform: rotate(90deg); }
.ld-chat-open .ld-chat-bubble-close { opacity: 1; transform: rotate(0); }

.ld-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #EF4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    animation: ld-chat-pop .3s ease;
}

@keyframes ld-chat-pop {
    from { transform: scale(0); }
    to   { transform: scale(1); }
}

/* Pulse ring: fab.css (.ld-fab-pulse--chat) */

/* ── Panel ───────────────────────────────────────────────── */
.ld-chat-panel {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 380px;
    max-height: 560px;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 8px 40px rgba(0,0,0,.18);
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(.96);
    pointer-events: none;
    transition: opacity .22s ease, transform .22s ease;
}

.ld-chat-open .ld-chat-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Header ──────────────────────────────────────────────── */
.ld-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 16px 14px;
    background: var(--ld-primary, #2563EB);
    color: #fff;
    flex-shrink: 0;
}

.ld-chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: var(--ld-chat-font-sm);
    font-family: inherit;
    flex-shrink: 0;
}

.ld-chat-header-info { flex: 1; min-width: 0; }

.ld-chat-header-name {
    font-weight: 600;
    font-size: var(--ld-chat-font-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ld-chat-header-status {
    font-size: var(--ld-chat-font-xs);
    opacity: .9;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.ld-chat-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ADE80;
    display: inline-block;
}

.ld-chat-header-close {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
    opacity: .75;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .15s;
    flex-shrink: 0;
}
.ld-chat-header-close:hover { opacity: 1; }
.ld-chat-header-close svg { width: 20px; height: 20px; }

/* ── Cart banner ─────────────────────────────────────────── */
.ld-chat-cart-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: #F0FDF4;
    border-bottom: 1px solid #BBF7D0;
    font-size: var(--ld-chat-font-xs);
    font-weight: 500;
    color: #166534;
    flex-shrink: 0;
}

.ld-chat-cart-banner svg { width: 18px; height: 18px; flex-shrink: 0; }

#ld-chat-cart-label { flex: 1; }

#ld-chat-cart-wa {
    background: #22C55E;
    color: #fff;
    border: none;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
    white-space: nowrap;
}
#ld-chat-cart-wa:hover { background: #16A34A; }

/* ── Messages ────────────────────────────────────────────── */
.ld-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.ld-chat-messages::-webkit-scrollbar { width: 4px; }
.ld-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ld-chat-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

.ld-chat-msg { display: flex; flex-direction: column; animation: ld-chat-fadein .2s ease; }
@keyframes ld-chat-fadein { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:none; } }

.ld-chat-msg-bot { align-items: flex-start; }
.ld-chat-msg-user { align-items: flex-end; }

.ld-chat-bubble-bot {
    background: #F3F4F6;
    color: #111827;
    padding: 12px 16px;
    border-radius: 4px 16px 16px 16px;
    max-width: 82%;
    word-break: break-word;
    font-family: inherit;
    font-size: var(--ld-chat-font-base);
    line-height: 1.55;
}

.ld-chat-bubble-user {
    background: var(--ld-primary, #2563EB);
    color: #fff;
    padding: 12px 16px;
    border-radius: 16px 4px 16px 16px;
    max-width: 82%;
    word-break: break-word;
    font-family: inherit;
    font-size: var(--ld-chat-font-base);
    line-height: 1.55;
}

.ld-chat-bubble-error {
    background: #FEF2F2;
    color: #DC2626;
    border: 1px solid #FECACA;
}

/* ── Typing indicator ────────────────────────────────────── */
.ld-chat-typing {
    padding: 4px 14px 0;
    flex-shrink: 0;
}

.ld-typing-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    padding: 10px 14px;
    background: #F3F4F6;
    border-radius: 4px 16px 16px 16px;
}

.ld-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9CA3AF;
    animation: ld-typing-bounce .9s infinite;
    display: inline-block;
}
.ld-typing-dots span:nth-child(2) { animation-delay: .15s; }
.ld-typing-dots span:nth-child(3) { animation-delay: .30s; }

@keyframes ld-typing-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40%           { transform: translateY(-6px); }
}

/* ── Product cards ───────────────────────────────────────── */
.ld-chat-products {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 320px;
}

.ld-chat-product-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #F9FAFB;
    border: 1px solid #E5E7EB;
    border-radius: 12px;
    padding: 8px 10px;
    transition: border-color .15s;
}
.ld-chat-product-card:hover { border-color: var(--ld-primary, #2563EB); }

#ld-chat-widget .ld-chat-product-card img,
#ld-chat-widget .ld-chat-product-no-img {
    width: 56px;
    height: 56px;
    min-width: 56px;
    min-height: 56px;
    max-width: 56px;
    max-height: 56px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    display: block;
    background: #E5E7EB;
}

.ld-chat-product-info { flex: 1; min-width: 0; }

.ld-chat-product-name {
    font-weight: 600;
    font-size: var(--ld-chat-font-xs);
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ld-chat-product-price {
    color: var(--ld-primary, #2563EB);
    font-weight: 700;
    font-size: var(--ld-chat-font-xs);
    margin-top: 2px;
}

.ld-chat-add-btn {
    background: #F3F4F6;
    border: 1px solid #E5E7EB;
    color: #374151;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, color .15s, border-color .15s;
}
.ld-chat-add-btn:hover { background: var(--ld-primary, #2563EB); color: #fff; border-color: var(--ld-primary, #2563EB); }
.ld-chat-add-btn.ld-chat-added { background: #22C55E; color: #fff; border-color: #22C55E; }
.ld-chat-add-btn svg { width: 16px; height: 16px; }

/* ── Lead form ───────────────────────────────────────────── */
.ld-chat-lead-form { max-width: 320px; width: 100%; }
.ld-chat-lead-form-stale { opacity: .62; }
.ld-chat-lead-inputs { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

.ld-chat-lead-inputs input {
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: var(--ld-chat-font-base);
    outline: none;
    transition: border-color .15s;
    font-family: inherit;
    color: #111827;
    background: #fff;
}
.ld-chat-lead-inputs input:focus { border-color: var(--ld-primary, #2563EB); }
.ld-chat-lead-inputs input::placeholder { color: #9CA3AF; }

.ld-chat-lead-submit {
    background: var(--ld-primary, #2563EB);
    color: #fff;
    border: none;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: var(--ld-chat-font-base);
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s;
    font-family: inherit;
}
.ld-chat-lead-submit:hover { opacity: .88; }
.ld-chat-lead-submit:disabled { opacity: .55; cursor: default; }

/* ── WhatsApp CTA ────────────────────────────────────────── */
.ld-chat-wa-cta { display: flex; flex-direction: column; gap: 10px; max-width: 320px; }

.ld-chat-wa-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #22C55E;
    color: #fff;
    text-decoration: none;
    padding: 11px 18px;
    border-radius: 12px;
    font-weight: 600;
    font-size: var(--ld-chat-font-base);
    font-family: inherit;
    transition: background .15s;
}
.ld-chat-wa-btn:hover { background: #16A34A; color: #fff; }
.ld-chat-wa-btn svg { width: 20px; height: 20px; flex-shrink: 0; }

/* ── Input area ──────────────────────────────────────────── */
.ld-chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #F3F4F6;
    background: #fff;
    flex-shrink: 0;
}

.ld-chat-input {
    flex: 1;
    border: 1px solid #E5E7EB;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: var(--ld-chat-font-base);
    font-family: inherit;
    resize: none;
    outline: none;
    line-height: 1.5;
    min-height: 42px;
    max-height: 120px;
    overflow-y: auto;
    transition: border-color .15s;
    color: #111827;
    background: #F9FAFB;
}
.ld-chat-input:focus { border-color: var(--ld-primary, #2563EB); background: #fff; }
.ld-chat-input::placeholder { color: #9CA3AF; }

.ld-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--ld-primary, #2563EB);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity .15s, transform .1s;
}
.ld-chat-send:hover { opacity: .88; }
.ld-chat-send:active { transform: scale(.93); }
.ld-chat-send:disabled { opacity: .45; cursor: default; }
.ld-chat-send svg { width: 20px; height: 20px; }

/* ── Full layout (centered modal) ────────────────────────── */
#ld-chat-widget.ld-chat-layout-full.ld-chat-open {
    inset: 0;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

#ld-chat-widget.ld-chat-layout-full.ld-chat-open .ld-chat-backdrop {
    opacity: 1;
    pointer-events: auto;
}

#ld-chat-widget.ld-chat-layout-full.ld-chat-open .ld-chat-panel {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    pointer-events: auto;
}

#ld-chat-widget.ld-chat-layout-full.ld-chat-open .ld-chat-bubble {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

.ld-chat-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease;
    z-index: 0;
}

.ld-chat-layout-full .ld-chat-backdrop {
    display: block;
}

.ld-chat-layout-full.ld-chat-open .ld-chat-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    bottom: auto;
    right: auto;
    width: min(520px, calc(100vw - 32px));
    max-height: min(680px, calc(100vh - 48px));
    border-radius: 24px;
    z-index: 1;
    opacity: 0;
    transform: translate(-50%, -46%) scale(0.96);
    transition: opacity .22s ease, transform .22s ease;
}

.ld-chat-layout-full .ld-chat-products,
.ld-chat-layout-full .ld-chat-lead-form,
.ld-chat-layout-full .ld-chat-wa-cta {
    max-width: 100%;
}

/* ── Mobile: fullscreen panel ────────────────────────────── */
@media (max-width: 480px) {
    #ld-chat-widget { bottom: 16px; right: 16px; }

    .ld-chat-panel,
    .ld-chat-layout-full.ld-chat-open .ld-chat-panel {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: auto;
        width: 100%;
        max-height: 90dvh;
        border-radius: 20px 20px 0 0;
        transform: translateY(20px) scale(1);
    }

    .ld-chat-open .ld-chat-panel,
    .ld-chat-layout-full.ld-chat-open .ld-chat-panel {
        transform: translateY(0) scale(1);
    }

    #ld-chat-widget.ld-chat-layout-full.ld-chat-open {
        align-items: flex-end;
    }
}
