/* Scout AI Chatbot Widget v1.3.62-20260526 — WordPress Plugin */
/* C-05: --drc-zindex is host-overridable. Default 2147483000 (max int 32 − 647)
   so the widget sits above virtually every host site stacking context but still
   leaves a small headroom for a host's own emergency-modal layer. A host that
   wants the widget BEHIND its own overlay can set #drc-chatbot-root{z-index:N}
   inline or override --drc-zindex globally. */
:root { --drc-color: #155dfc; --drc-radius: 18px; --drc-zindex: 2147483000; }

#drc-chatbot-root {
    position: fixed; z-index: var(--drc-zindex, 2147483000);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
#drc-chatbot-root.bottom-right { bottom: 20px; right: 20px; }
#drc-chatbot-root.bottom-left  { bottom: 20px; left: 20px; }

/* ── Launcher bubble (AI Studio design — Session 30) ──────── */
#drc-bubble {
    width: 60px; height: 60px; border-radius: 50%;
    background: var(--drc-color); color: #fff;
    border: none; cursor: pointer;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18), 0 0 0 0 rgba(21,93,252,0.4);
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.25s cubic-bezier(.4,0,.2,1), box-shadow 0.25s cubic-bezier(.4,0,.2,1);
    position: relative;
}
#drc-bubble:hover { transform: scale(1.05); box-shadow: 0 12px 32px rgba(0,0,0,0.22), 0 0 0 6px rgba(21,93,252,0.13); }
#drc-bubble:active { transform: scale(0.95); }

#drc-bubble-icon {
    position: relative; width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.25s;
}
#drc-bubble-icon .ic {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.3s cubic-bezier(.4,0,.2,1), opacity 0.25s;
}
#drc-bubble-icon .ic-chat  { transform: rotate(0deg) scale(1); opacity: 1; }
#drc-bubble-icon .ic-close { transform: rotate(-90deg) scale(0.6); opacity: 0; }
#drc-bubble.is-open #drc-bubble-icon .ic-chat  { transform: rotate(90deg) scale(0.6); opacity: 0; }
#drc-bubble.is-open #drc-bubble-icon .ic-close { transform: rotate(0deg) scale(1); opacity: 1; }

#drc-bubble-dot {
    position: absolute; top: 2px; right: 2px;
    width: 12px; height: 12px;
    background: #10b981; border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: opacity 0.2s, transform 0.2s;
}
#drc-bubble.is-open #drc-bubble-dot { opacity: 0; transform: scale(0.5); }

#drc-bubble-loader {
    position: absolute; inset: 0;
    display: none; align-items: center; justify-content: center; gap: 5px;
}
#drc-bubble.is-loading #drc-bubble-loader { display: flex; }
#drc-bubble.is-loading #drc-bubble-icon,
#drc-bubble.is-loading #drc-bubble-dot { opacity: 0; }
#drc-bubble-loader span {
    width: 6px; height: 6px;
    background: #fff; border-radius: 50%;
    animation: drc-bubble-bounce 0.6s infinite ease-in-out;
}
#drc-bubble-loader span:nth-child(2) { animation-delay: 0.15s; }
#drc-bubble-loader span:nth-child(3) { animation-delay: 0.30s; }
@keyframes drc-bubble-bounce {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}

#drc-badge {
    position: absolute; top: -2px; right: -2px;
    background: #e53e3e; color: #fff; border-radius: 50%;
    width: 18px; height: 18px; font-size: 11px; font-weight: 700;
    display: none; align-items: center; justify-content: center;
    border: 2px solid #fff;
    z-index: 2;
}

/* Pre-open tooltip — auto-shows once 1.5s after load, dismissed on first click */
#drc-tooltip {
    position: absolute; bottom: 74px;
    background: #fff; color: #0f172a;
    font-size: 12.5px; font-weight: 600;
    padding: 10px 14px; border-radius: 14px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.16), 0 1px 3px rgba(0,0,0,0.06);
    white-space: nowrap;
    opacity: 0; visibility: hidden;
    transform: translateY(8px) scale(0.95);
    transition: opacity 0.3s, transform 0.3s, visibility 0.3s;
    pointer-events: none;
}
#drc-chatbot-root.bottom-right #drc-tooltip { right: 0; }
#drc-chatbot-root.bottom-left  #drc-tooltip { left: 0; }
#drc-tooltip.show {
    opacity: 1; visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
#drc-tooltip::after {
    content: ""; position: absolute; bottom: -4px;
    width: 10px; height: 10px;
    background: #fff; transform: rotate(45deg);
}
#drc-chatbot-root.bottom-right #drc-tooltip::after { right: 22px; }
#drc-chatbot-root.bottom-left  #drc-tooltip::after { left: 22px; }

/* ── Chat window ──────────────────────────────────────────── */
#drc-window {
    position: absolute; bottom: 74px;
    width: 360px;
    background: #fff;
    border-radius: var(--drc-radius);
    box-shadow: 0 8px 40px rgba(0,0,0,0.16), 0 1px 3px rgba(0,0,0,0.08);
    display: flex; flex-direction: column;
    overflow: hidden;
    max-height: 540px;
    opacity: 0; visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s cubic-bezier(.4,0,.2,1), transform 0.3s cubic-bezier(.4,0,.2,1), visibility 0.3s;
    pointer-events: none;
}
#drc-chatbot-root.bottom-right #drc-window { right: 0; transform-origin: bottom right; }
#drc-chatbot-root.bottom-left  #drc-window { left: 0;  transform-origin: bottom left; }
#drc-window.open {
    opacity: 1; visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Header — white, clean ────────────────────────────────── */
#drc-header {
    background: #fff;
    padding: 14px 16px;
    display: flex; align-items: center; gap: 11px;
    border-bottom: 1px solid #f0f0f0;
    flex-shrink: 0;
}
#drc-header-avatar {
    width: 40px; height: 40px; border-radius: 11px;
    overflow: hidden; flex-shrink: 0; position: relative;
}
#drc-avatar-dot {
    position: absolute; bottom: -2px; right: -2px;
    width: 11px; height: 11px;
    background: #22c55e; border-radius: 50%;
    border: 2px solid #fff;
}

/* Continue-with-AI button — surfaces in queued state + on reload-into-paused (BUG-05) */
.drc-queue-action { align-self: center; margin: 4px 0; }
.drc-resume-ai-btn {
    background: none;
    border: 1.5px solid #6c757d;
    color: #6c757d;
    border-radius: 20px;
    padding: 5px 14px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.drc-resume-ai-btn:hover { background: #6c757d; color: #fff; }
#drc-header-info { flex: 1; min-width: 0; }
#drc-header-name {
    font-weight: 700; font-size: 14px; color: #111;
    line-height: 1.3; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
#drc-header-status {
    font-size: 10px; color: #888; margin-top: 2px;
    font-weight: 600; letter-spacing: .4px; text-transform: uppercase;
    /* C-02: prevent long status copy from pushing the header into a 2nd line
       on a narrow widget container (Replied a few minutes ago / overflow cases). */
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#drc-close-btn {
    background: none; border: none; color: #bbb; cursor: pointer;
    font-size: 20px; padding: 4px 6px; line-height: 1;
    border-radius: 6px; transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}
#drc-close-btn:hover { color: #555; background: #f5f5f5; }

/* ── Lead capture form ────────────────────────────────────── */
#drc-lead-form {
    display: flex; flex-direction: column; gap: 10px;
    padding: 20px 18px 16px; flex: 1;
    background: #fafafa;
}
.drc-lead-intro { text-align: center; margin-bottom: 4px; }
.drc-lead-icon { font-size: 32px; margin-bottom: 6px; }
.drc-lead-intro p { font-size: 13.5px; color: #555; line-height: 1.5; margin: 0; }
.drc-optional { color: #aaa; font-size: 12px; }

#drc-lead-form input {
    border: 1.5px solid #e8edf2; border-radius: 9px;
    padding: 9px 13px; font-size: 13.5px;
    outline: none; font-family: inherit;
    transition: border-color 0.2s; background: #fff;
    width: 100%; box-sizing: border-box;
}
#drc-lead-form input:focus { border-color: var(--drc-color); }

.drc-lead-buttons { display: flex; gap: 8px; margin-top: 4px; }
.drc-lead-btn-primary {
    flex: 1; background: var(--drc-color); color: #fff;
    border: none; border-radius: 9px; padding: 10px;
    font-size: 13.5px; font-weight: 600; cursor: pointer;
    font-family: inherit; transition: opacity 0.2s;
}
.drc-lead-btn-primary:hover { opacity: 0.88; }
.drc-lead-btn-skip {
    background: #f5f5f5; color: #666; border: none;
    border-radius: 9px; padding: 10px 14px;
    font-size: 13px; cursor: pointer; font-family: inherit;
    transition: background 0.2s;
}
.drc-lead-btn-skip:hover { background: #ebebeb; }

/* ── Chat area ────────────────────────────────────────────── */
#drc-chat-area { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ── Messages ─────────────────────────────────────────────── */
#drc-messages {
    flex: 1; overflow-y: auto; padding: 14px 14px 8px;
    display: flex; flex-direction: column; gap: 8px; min-height: 0;
}
.drc-msg {
    max-width: 82%; padding: 9px 13px;
    border-radius: 16px; font-size: 13.5px; line-height: 1.55; word-wrap: break-word;
}
.drc-msg.bot {
    background: #f1f3f5; color: #222;
    align-self: flex-start; border-bottom-left-radius: 4px;
}
.drc-msg.bot strong { font-weight: 700; }
.drc-msg.bot ul { margin: 4px 0 2px 0; padding-left: 18px; list-style: disc; }
.drc-msg.bot li { margin-bottom: 6px; }
.drc-msg.bot a { color: var(--drc-color); text-decoration: underline; word-break: break-all; }
.drc-msg.user {
    background: var(--drc-color); color: #fff;
    align-self: flex-end; border-bottom-right-radius: 4px;
}
.drc-msg.system {
    background: #fff8e1; color: #856404;
    align-self: center; font-size: 12px;
    border-radius: 10px; text-align: center;
    max-width: 92%; padding: 8px 12px;
}
.drc-msg.agent {
    background: #f0fdf4; color: #14532d;
    align-self: flex-start; border-bottom-left-radius: 4px;
    border-left: 3px solid #22c55e;
}
.drc-agent-label { font-size: 11px; color: #16a34a; font-weight: 700; margin-bottom: 4px; letter-spacing: 0.3px; }

/* ── Product cards ────────────────────────────────────────── */
.drc-cards { align-self: stretch; display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 8px; scrollbar-width: thin; flex-shrink: 0; }
.drc-card { flex: 0 0 150px; border: 1px solid #e6e8eb; border-radius: 12px; background: #fff; overflow: hidden; display: flex; flex-direction: column; }
.drc-card-imgwrap { display: block; width: 100%; height: 120px; background: #f6f7f8; flex-shrink: 0; }
.drc-card-imgwrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.drc-card-body { padding: 8px 9px 10px; display: flex; flex-direction: column; gap: 5px; }
.drc-card-name { font-size: 12.5px; font-weight: 600; color: #1a1a1a; text-decoration: none; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.drc-card-name:hover { color: var(--drc-color); }
.drc-card-meta { font-size: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.drc-card-price { font-weight: 700; color: #1a1a1a; }
.drc-card-sale { font-weight: 700; color: #1a8754; }
.drc-card-was { text-decoration: line-through; color: #9aa0a6; font-size: 11px; }
.drc-card-stock { font-size: 10.5px; }
.drc-card-stock.in { color: #1a8754; }
.drc-card-stock.out { color: #d63939; }
.drc-card-cart { margin-top: 2px; text-align: center; background: var(--drc-color); color: #fff; text-decoration: none; font-size: 12px; font-weight: 600; padding: 6px 8px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 30px; }
.drc-card-cart:hover { opacity: .9; }
.drc-card-cart.loading { opacity: .8; cursor: default; }
.drc-card-cart.added { background: #1a8754; cursor: default; }
.drc-cart-spin { width: 12px; height: 12px; border: 2px solid rgba(255,255,255,.5); border-top-color: #fff; border-radius: 50%; display: inline-block; animation: drc-cart-spin .6s linear infinite; }
@keyframes drc-cart-spin { to { transform: rotate(360deg); } }

/* ── Typing indicator ─────────────────────────────────────── */
#drc-typing {
    display: none; align-self: flex-start;
    padding: 10px 14px; background: #f1f3f5;
    border-radius: 16px; border-bottom-left-radius: 4px; gap: 4px;
}
#drc-typing span {
    display: inline-block; width: 6px; height: 6px;
    background: #bbb; border-radius: 50%;
    animation: drc-bounce 1.2s infinite;
}
#drc-typing span:nth-child(2) { animation-delay: 0.2s; }
#drc-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes drc-bounce {
    0%,80%,100% { transform: translateY(0); }
    40%          { transform: translateY(-5px); }
}

/* ── Input area — pill style ──────────────────────────────── */
#drc-input-area {
    padding: 10px 12px 12px;
    border-top: 1px solid #f0f0f0;
    display: flex; align-items: center; gap: 0;
    flex-shrink: 0; background: #fff;
}
#drc-input-pill {
    display: flex; align-items: center; gap: 6px;
    flex: 1; background: #f3f4f6;
    border-radius: 14px; padding: 6px 10px;
}
#drc-input {
    flex: 1; border: none !important; background: transparent !important;
    padding: 3px 4px !important; font-size: 13.5px !important;
    resize: none !important; outline: none !important;
    max-height: 72px !important; min-height: unset !important;
    height: auto !important; font-family: inherit !important;
    line-height: 1.5 !important; color: #222 !important;
    overflow-y: auto !important; box-sizing: border-box !important;
    box-shadow: none !important; margin: 0 !important;
}
#drc-input::placeholder { color: #aaa; }
#drc-img-btn {
    background: none; border: none; cursor: pointer; color: #aaa;
    padding: 3px 4px; border-radius: 6px;
    display: flex; align-items: center; flex-shrink: 0;
    transition: color 0.2s; line-height: 1;
}
#drc-img-btn:hover { color: var(--drc-color); }
#drc-emoji-btn {
    background: none; border: none; cursor: pointer; color: #aaa;
    padding: 3px 4px; flex-shrink: 0;
    font-size: 16px; line-height: 1; transition: color 0.2s;
}
#drc-emoji-btn:hover { color: #f59e0b; }

/* ── Send button ──────────────────────────────────────────── */
/* !important on sizing/spacing to defend against aggressive theme globals (WoodMart, Astra, etc.)
   that apply min-width/padding/width:auto to all <button> elements. Same pattern as #drc-input fix (session 18). */
#drc-send {
    width: 32px !important; height: 32px !important; min-width: 32px !important; max-width: 32px !important;
    min-height: 32px !important; max-height: 32px !important;
    border-radius: 50% !important;
    background: var(--drc-color); color: #fff;
    border: none !important; cursor: pointer;
    display: flex !important; align-items: center !important; justify-content: center !important;
    flex-shrink: 0; flex-grow: 0; flex-basis: 32px;
    margin-left: 6px !important; padding: 0 !important;
    box-sizing: border-box !important;
    box-shadow: none !important;
    transition: opacity 0.2s;
}
#drc-send:hover   { opacity: 0.85; }
#drc-send:active  { transform: scale(0.93); }
#drc-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
#drc-send svg { width: 14px; height: 14px; fill: #fff; display: block; }

/* ── Continue-on bar (cross-channel, Phase 1A) ──────────── */
#drc-continue-bar {
    display: none; align-items: center; justify-content: center;
    gap: 8px; padding: 7px 12px 9px;
    border-top: 1px solid #f0f0f0; background: #fafbfc;
}
#drc-continue-bar.open { display: flex; }
#drc-continue-label {
    font-size: 10px; color: #ccc; font-weight: 600;
    letter-spacing: .3px; text-transform: uppercase; margin-right: 4px;
}
.drc-cc-btn {
    width: 28px; height: 28px; border-radius: 50%; border: none;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0;
    transition: transform .15s, opacity .15s;
}
.drc-cc-btn:hover { transform: scale(1.12); }
.drc-cc-btn[disabled] { opacity: .5; cursor: wait; }
.drc-cc-btn[data-cc="whatsapp"]  { background: #25D366; }
.drc-cc-btn[data-cc="telegram"]  { background: #0088cc; }
.drc-cc-btn[data-cc="messenger"] { background: #0084ff; }

/* ── Footer ───────────────────────────────────────────────── */
#drc-footer {
    text-align: center; font-size: 10px; color: #ccc;
    padding: 5px 8px 7px; background: #fff;
    flex-shrink: 0; letter-spacing: .3px; font-weight: 600; text-transform: uppercase;
}

/* ── Mobile ───────────────────────────────────────────────── */
@media (max-width: 480px) {
    #drc-chatbot-root.bottom-right,
    #drc-chatbot-root.bottom-left { bottom: 0; right: 0; left: 0; width: 100%; }
    #drc-bubble { position: fixed; bottom: 16px; right: 16px; }
    #drc-window {
        position: fixed; bottom: 0; left: 0; right: 0;
        width: 100% !important; max-width: 100%;
        border-radius: 20px 20px 0 0; max-height: 85vh;
    }
    #drc-chatbot-root.bottom-right #drc-window,
    #drc-chatbot-root.bottom-left  #drc-window { right: 0; left: 0; }
    #drc-input { font-size: 16px; }
    .drc-msg { max-width: 88%; font-size: 14px; }
}

/* ── Image upload ─────────────────────────────────────────── */
#drc-img-preview { padding: 6px 12px 0; }
#drc-img-preview-inner { position: relative; display: inline-block; }
#drc-img-preview-thumb {
    max-width: 100px; max-height: 80px;
    border-radius: 8px; border: 2px solid var(--drc-color); display: block;
}
#drc-img-remove {
    position: absolute; top: -6px; right: -6px;
    width: 20px; height: 20px; border-radius: 50%;
    background: #e74c3c; color: #fff; border: none;
    cursor: pointer; font-size: 13px; line-height: 20px;
    text-align: center; padding: 0;
}
.drc-msg-image img { border-radius: 8px; }
.drc-msg-image span { display: block; margin-top: 4px; font-size: 13px; }

/* ── R-3: Tablet breakpoint (481–768px) ─────────────────────── */
@media (min-width: 481px) and (max-width: 768px) {
    #drc-window { width: 320px; height: 480px; }
    .drc-msg { font-size: 13.5px; }
}

/* ── R-4: iOS safe-area-inset-bottom ────────────────────────── */
@media (max-width: 480px) {
    #drc-window { padding-bottom: env(safe-area-inset-bottom, 0px); }
    #drc-input-row { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
}


/* ── R-6: Reduced motion ─────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    #drc-window, #drc-bubble, #drc-bubble-icon, #drc-bubble-icon .ic,
    #drc-bubble-loader span, #drc-bubble-dot, #drc-tooltip,
    #drc-close-btn, .drc-msg, .drc-star {
        transition: none !important;
        animation: none !important;
    }
}
