/*
 * Storefront sales chatbot (N15).
 *
 * Every selector is anchored on #enp-sc: one id beats the shop theme's
 * class-based button/typography rules (Woodmart loads after us), so the widget
 * looks the same on any theme without a wall of !important.
 *
 * Physical left/right are used on purpose: the panel is dir="rtl", and logical
 * inset-inline-* flips there (that bug already cost us once on the panel bot).
 */

#enp-sc {
    --enp-sc-c: #2563eb;
    --enp-sc-t: #fff;
    --enp-sc-r: 18px;
    --enp-sc-w: 380px;
    --enp-sc-h: 540px;
    --enp-sc-x: 20px;
    --enp-sc-y: 20px;
    --enp-sc-bg: #fff;
    --enp-sc-fg: #1f2430;
    --enp-sc-mute: #6b7280;
    --enp-sc-line: #e5e7eb;
    --enp-sc-in: #f3f4f6;
    position: fixed;
    z-index: 99990;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.7;
    direction: rtl;
}

#enp-sc.enp-sc-dark {
    --enp-sc-bg: #14181f;
    --enp-sc-fg: #e8eaf0;
    --enp-sc-mute: #9aa3b2;
    --enp-sc-line: #2a3140;
    --enp-sc-in: #1d232e;
}

#enp-sc.enp-sc-br { right: var(--enp-sc-x); bottom: var(--enp-sc-y); }
#enp-sc.enp-sc-bl { left: var(--enp-sc-x);  bottom: var(--enp-sc-y); }
#enp-sc.enp-sc-tr { right: var(--enp-sc-x); top: var(--enp-sc-y); }
#enp-sc.enp-sc-tl { left: var(--enp-sc-x);  top: var(--enp-sc-y); }

/* ---------------------------------------------------------- launcher */

#enp-sc .enp-sc-launcher {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 0 18px;
    height: 56px;
    min-width: 56px;
    border: 0;
    border-radius: 999px;
    background: var(--enp-sc-c);
    color: var(--enp-sc-t);
    box-shadow: 0 10px 25px rgba(0, 0, 0, .18);
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease;
}
#enp-sc .enp-sc-launcher:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(0, 0, 0, .22); }
#enp-sc .enp-sc-launcher svg { width: 24px; height: 24px; fill: currentColor; flex: 0 0 auto; }
#enp-sc .enp-sc-launcher-text { font-size: 14px; font-weight: 600; white-space: nowrap; }
#enp-sc.is-open .enp-sc-launcher { display: none; }

/* ------------------------------------------------------------- panel */

#enp-sc .enp-sc-panel {
    display: flex;
    flex-direction: column;
    width: min(var(--enp-sc-w), calc(100vw - 24px));
    height: min(var(--enp-sc-h), calc(100vh - 40px));
    background: var(--enp-sc-bg);
    color: var(--enp-sc-fg);
    border: 1px solid var(--enp-sc-line);
    border-radius: var(--enp-sc-r);
    box-shadow: 0 24px 60px rgba(0, 0, 0, .22);
    overflow: hidden;
}
#enp-sc .enp-sc-panel[hidden] { display: none; }

#enp-sc .enp-sc-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    background: var(--enp-sc-c);
    color: var(--enp-sc-t);
}
#enp-sc .enp-sc-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
#enp-sc .enp-sc-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    object-fit: cover; background: rgba(255, 255, 255, .2); flex: 0 0 auto;
}
#enp-sc .enp-sc-avatar-ph { display: flex; align-items: center; justify-content: center; }
#enp-sc .enp-sc-avatar-ph svg { width: 20px; height: 20px; fill: currentColor; }
#enp-sc .enp-sc-names { display: flex; flex-direction: column; min-width: 0; }
#enp-sc .enp-sc-names strong { font-size: 14px; font-weight: 700; color: inherit; }
#enp-sc .enp-sc-names small { font-size: 11.5px; opacity: .85; }
#enp-sc .enp-sc-actions { display: flex; gap: 2px; flex: 0 0 auto; }
#enp-sc .enp-sc-ico {
    display: flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; padding: 0;
    border: 0; border-radius: 8px; background: transparent;
    color: var(--enp-sc-t); cursor: pointer; opacity: .85;
}
#enp-sc .enp-sc-ico:hover { background: rgba(255, 255, 255, .18); opacity: 1; }
#enp-sc .enp-sc-ico svg { width: 16px; height: 16px; fill: currentColor; }

/* -------------------------------------------------------------- body */

#enp-sc .enp-sc-body { flex: 1 1 auto; overflow-y: auto; padding: 14px; }
#enp-sc .enp-sc-body[hidden] { display: none; }
#enp-sc .enp-sc-msgs { display: flex; flex-direction: column; gap: 10px; }

#enp-sc .enp-sc-msg { display: flex; flex-direction: column; max-width: 88%; }
/* RTL: the visitor's own message hugs the left, the bot answers from the right. */
#enp-sc .enp-sc-me { align-self: flex-end; }
#enp-sc .enp-sc-bot { align-self: flex-start; }

#enp-sc .enp-sc-bubble {
    padding: 9px 12px;
    border-radius: 14px;
    background: var(--enp-sc-in);
    color: var(--enp-sc-fg);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
#enp-sc .enp-sc-me .enp-sc-bubble { background: var(--enp-sc-c); color: var(--enp-sc-t); }
#enp-sc .enp-sc-tag { margin-top: 3px; font-size: 11px; color: var(--enp-sc-mute); }
#enp-sc .enp-sc-bubble a { color: var(--enp-sc-c); text-decoration: underline; }
#enp-sc .enp-sc-me .enp-sc-bubble a { color: var(--enp-sc-t); }

#enp-sc .enp-sc-typing span {
    display: inline-block; width: 6px; height: 6px; margin: 0 1px;
    border-radius: 50%; background: var(--enp-sc-mute);
    animation: enp-sc-dot 1s infinite ease-in-out;
}
#enp-sc .enp-sc-typing span:nth-child(2) { animation-delay: .15s; }
#enp-sc .enp-sc-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes enp-sc-dot { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* ------------------------------------------------------ product cards */

#enp-sc .enp-sc-cards { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
#enp-sc .enp-sc-card {
    display: flex; align-items: center; gap: 10px;
    padding: 8px;
    border: 1px solid var(--enp-sc-line);
    border-radius: 12px;
    background: var(--enp-sc-bg);
    color: var(--enp-sc-fg);
    text-decoration: none;
}
#enp-sc .enp-sc-card:hover { border-color: var(--enp-sc-c); }
#enp-sc .enp-sc-card img { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; flex: 0 0 auto; }
#enp-sc .enp-sc-card-b { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
#enp-sc .enp-sc-card-n { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#enp-sc .enp-sc-card-p { font-size: 12.5px; color: var(--enp-sc-c); font-weight: 700; }
#enp-sc .enp-sc-card-o { font-size: 11.5px; color: var(--enp-sc-mute); font-weight: 400; }
#enp-sc .enp-sc-card-s { font-size: 11px; color: var(--enp-sc-mute); }

/* ------------------------------------------------------------- chips */

#enp-sc .enp-sc-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
#enp-sc .enp-sc-chip {
    padding: 6px 10px; font-size: 12.5px;
    border: 1px solid var(--enp-sc-line); border-radius: 999px;
    background: transparent; color: var(--enp-sc-fg); cursor: pointer;
}
#enp-sc .enp-sc-chip:hover { border-color: var(--enp-sc-c); color: var(--enp-sc-c); }

/* ----------------------------------------------------------- history */

#enp-sc .enp-sc-search { display: block; margin-bottom: 10px; }
#enp-sc .enp-sc-search input {
    width: 100%; padding: 9px 12px; font: inherit; font-size: 13px;
    border: 1px solid var(--enp-sc-line); border-radius: 10px;
    background: var(--enp-sc-in); color: var(--enp-sc-fg);
}
#enp-sc .enp-sc-threads { display: flex; flex-direction: column; gap: 6px; }
#enp-sc .enp-sc-thread {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 9px 10px; border: 1px solid var(--enp-sc-line); border-radius: 10px;
}
#enp-sc .enp-sc-thread button {
    padding: 0; border: 0; background: transparent; color: inherit;
    font: inherit; text-align: right; cursor: pointer; min-width: 0;
}
#enp-sc .enp-sc-thread-t { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#enp-sc .enp-sc-thread-d { display: block; font-size: 11px; color: var(--enp-sc-mute); }
#enp-sc .enp-sc-thread .enp-sc-del { color: var(--enp-sc-mute); flex: 0 0 auto; }
#enp-sc .enp-sc-thread .enp-sc-del:hover { color: #dc2626; }
#enp-sc .enp-sc-none { padding: 18px 0; text-align: center; font-size: 13px; color: var(--enp-sc-mute); }

/* -------------------------------------------------------------- foot */

#enp-sc .enp-sc-foot {
    display: flex; align-items: flex-end; gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--enp-sc-line);
    background: var(--enp-sc-bg);
}
#enp-sc .enp-sc-foot textarea {
    flex: 1 1 auto; min-height: 40px; max-height: 120px;
    padding: 9px 12px; font: inherit; font-size: 13.5px; line-height: 1.6;
    border: 1px solid var(--enp-sc-line); border-radius: 12px;
    background: var(--enp-sc-in); color: var(--enp-sc-fg);
    resize: none; overflow-y: auto;
}
#enp-sc .enp-sc-send {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; padding: 0; flex: 0 0 auto;
    border: 0; border-radius: 12px;
    background: var(--enp-sc-c); color: var(--enp-sc-t);
    cursor: pointer; text-decoration: none;
}
#enp-sc .enp-sc-send svg { width: 18px; height: 18px; fill: currentColor; transform: scaleX(-1); }
#enp-sc .enp-sc-send[disabled] { opacity: .5; cursor: default; }
#enp-sc .enp-sc-gate { flex-direction: column; align-items: stretch; gap: 10px; text-align: center; }
#enp-sc .enp-sc-gate p { margin: 0; font-size: 13px; color: var(--enp-sc-mute); }
#enp-sc .enp-sc-login { width: auto; height: auto; padding: 9px 14px; font-size: 13px; font-weight: 600; }
#enp-sc .enp-sc-handoff {
    margin: 0; padding: 7px 12px; font-size: 11.5px; text-align: center;
    color: var(--enp-sc-mute); background: var(--enp-sc-in);
}
#enp-sc .enp-sc-handoff a { color: var(--enp-sc-c); }
#enp-sc .enp-sc-err { margin-top: 8px; font-size: 12.5px; color: #dc2626; }

/* ------------------------------------------------------------ mobile */

@media (max-width: 520px) {
    #enp-sc.is-open { left: 0; right: 0; top: 0; bottom: 0; }
    /* Logged-in visitors (and the operator testing the shop) have the WordPress
       admin bar pinned above us at a higher z-index — start below it. */
    body.admin-bar #enp-sc.is-open { top: 46px; }
    #enp-sc.is-open .enp-sc-panel {
        width: 100vw; height: 100%; max-height: 100%;
        border: 0; border-radius: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    #enp-sc .enp-sc-launcher { transition: none; }
    #enp-sc .enp-sc-typing span { animation: none; }
}
