/* BSS ChatPilot — storefront widget (light-DOM, scoped under .chatpilot, themed via CSS variables).
   Messenger-style: white chat area, avatars on received messages, grouped bubbles, primary sent bubbles.
   Avatars are pure CSS (data-URI SVG) — no DB / no network cost. */

.chatpilot {
    --cp-primary: #2563eb;
    --cp-header-bg: #2563eb;
    --cp-header-text: #ffffff;
    --cp-shopper: #2563eb;
    --cp-agent: #f0f0f0;
    --cp-launcher-icon: #ffffff;
    --cp-radius: 16px;
    --cp-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    position: fixed;
    bottom: var(--cp-offset-y, 22px);
    z-index: 2147483000;
    font-family: var(--cp-font);
    font-size: 14px;
    line-height: 1.4;
}

.chatpilot.chatpilot--right { right: var(--cp-offset-x, 22px); }
.chatpilot.chatpilot--left { left: var(--cp-offset-x, 22px); }

/* ---------- Launcher ---------- */
.chatpilot-launcher {
    position: relative; /* anchor for the unread notification badge */
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 0;
    cursor: pointer;
    height: 46px;
    padding: 0 16px 0 14px;
    border-radius: 23px;
    background: var(--cp-primary);
    color: var(--cp-launcher-icon);
    box-shadow: 0 8px 20px rgba(0,0,0,.18);
    transition: transform .15s ease, box-shadow .15s ease;
    text-decoration: none; /* also used as an <a> for the staff → console launcher */
}

/* Unread notification badge — a red pill at the launcher's top-right corner (WhatsApp/Messenger style). */
.chatpilot-launcher-badge {
    position: absolute;
    top: -5px;
    inset-inline-end: -4px; /* logical → sits correctly in both LTR and RTL */
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: #e0245e;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 0 0 2px #fff;
    pointer-events: none;
    animation: chatpilot-badge-pop .18s ease;
}
.chatpilot-launcher-badge[hidden] { display: none; }
@keyframes chatpilot-badge-pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.chatpilot-launcher:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(0,0,0,.24); text-decoration: none; }
.chatpilot-launcher:hover .chatpilot-launcher-text { color: var(--cp-launcher-icon); }
.chatpilot-launcher:focus-visible { outline: 3px solid rgba(0,0,0,.35); outline-offset: 2px; }
.chatpilot-launcher-text { font-weight: 600; font-size: 14px; }
.chatpilot-ico { width: 20px; height: 20px; fill: none; stroke: var(--cp-launcher-icon); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chatpilot-ico-close { display: none; }

/* When the panel is open, hide the launcher entirely — the panel header already has a close button,
   so the bottom button would just be a redundant X (Messenger hides it too). */
.chatpilot.is-open .chatpilot-launcher { display: none; }

/* ---------- RTL ---------- */
/* dir="rtl" on the root already mirrors every flex row (message sides, header, composer). These fix the
   few physical-margin / corner details. The launcher/panel corner stays where the position SETTING says
   (it uses physical right/left, not logical), so RTL doesn't move it. */
.chatpilot--rtl .chatpilot-name { margin: 0 12px 2px 0; }
.chatpilot--rtl .chatpilot-status-dot { right: auto; left: -1px; }
.chatpilot--rtl .chatpilot-meta { text-align: left; }
.chatpilot--rtl .chatpilot-row.is-shopper .chatpilot-meta { text-align: right; }

/* ---------- Panel ---------- */
/* Anchored to the bottom (the launcher is hidden while open, so no gap is reserved for it).
   Height adapts to the viewport so it always fits, down to small/short screens. */
.chatpilot-panel {
    position: absolute;
    bottom: 0;
    width: 360px;
    max-width: calc(100vw - 28px);
    height: min(560px, calc(100vh - 40px));
    height: min(560px, calc(100dvh - 40px)); /* dvh accounts for mobile browser chrome; vh above is the fallback */
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: var(--cp-radius);
    box-shadow: 0 24px 60px rgba(0,0,0,.28);
    overflow: hidden;
    opacity: 0;
    transform: translateY(12px) scale(.98);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
}
.chatpilot--right .chatpilot-panel { right: 0; }
.chatpilot--left .chatpilot-panel { left: 0; transform-origin: bottom left; }
.chatpilot.is-open .chatpilot-panel { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

/* ---------- Draggable launcher ("chat head") ---------- */
/* touch-action:none lets a finger drag the pill instead of scrolling the page (only when enabled). */
.chatpilot--draggable .chatpilot-launcher { touch-action: none; cursor: grab; }
.chatpilot.is-dragging .chatpilot-launcher { cursor: grabbing; transition: none; }

/* Once moved, the root is positioned by inline left/top from JS — drop the corner offsets so they don't fight it. */
.chatpilot--free { bottom: auto; right: auto; }

/* When the launcher has been moved, anchor the panel so it grows toward screen centre from the pill.
   These carry higher specificity than the .chatpilot--right/left panel rules above, so they win.
   Only edges + transform-origin are set here (never `transform`) to keep the open/close animation intact.
   Scoped to ≥481px so the mobile full-screen panel (inset:0 below) is never affected. */
@media (min-width: 481px) {
    .chatpilot--free.chatpilot--open-up .chatpilot-panel { top: auto; bottom: 0; }
    .chatpilot--free.chatpilot--open-down .chatpilot-panel { bottom: auto; top: 0; }
    .chatpilot--free.chatpilot--open-left .chatpilot-panel { left: auto; right: 0; }
    .chatpilot--free.chatpilot--open-right .chatpilot-panel { right: auto; left: 0; }
    .chatpilot--free.chatpilot--open-up.chatpilot--open-left .chatpilot-panel { transform-origin: bottom right; }
    .chatpilot--free.chatpilot--open-up.chatpilot--open-right .chatpilot-panel { transform-origin: bottom left; }
    .chatpilot--free.chatpilot--open-down.chatpilot--open-left .chatpilot-panel { transform-origin: top right; }
    .chatpilot--free.chatpilot--open-down.chatpilot--open-right .chatpilot-panel { transform-origin: top left; }
}

/* ---------- Header (Messenger: avatar + name + status) ---------- */
.chatpilot-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px 10px 14px;
    background: var(--cp-header-bg);
    color: var(--cp-header-text);
}
.chatpilot-headavatar {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    flex: 0 0 auto;
    background: rgba(255,255,255,.22) center/22px no-repeat;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ffffff'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 20c0-4 4-6 8-6s8 2 8 6z'/%3E%3C/svg%3E");
}
.chatpilot-headinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; line-height: 1.2; }
.chatpilot-header-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* presence: a small green dot that softly glows ONLY while an agent is online; fully hidden when away */
.chatpilot-status-dot { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border-radius: 50%; background: #31a24c; border: 2px solid var(--cp-header-bg); animation: chatpilot-presence-pulse 2s ease-out infinite; }
.chatpilot-status-dot.is-away { display: none; }
@keyframes chatpilot-presence-pulse { 0% { box-shadow: 0 0 0 0 rgba(49,162,76,.55); } 70% { box-shadow: 0 0 0 6px rgba(49,162,76,0); } 100% { box-shadow: 0 0 0 0 rgba(49,162,76,0); } }
.chatpilot-close { background: transparent; border: 0; cursor: pointer; color: inherit; opacity: .85; padding: 4px; border-radius: 8px; }
.chatpilot-close:hover { opacity: 1; background: rgba(255,255,255,.15); }
.chatpilot-close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.chatpilot-icon-btn { background: transparent; border: 0; cursor: pointer; color: inherit; opacity: .85; padding: 4px; border-radius: 8px; }
.chatpilot-icon-btn:hover { opacity: 1; background: rgba(255,255,255,.15); }
.chatpilot-icon-btn:disabled { opacity: .4; cursor: default; background: transparent; }
.chatpilot-theme-btn svg { width: 18px; height: 18px; fill: currentColor; }
.chatpilot-clear-btn svg { width: 18px; height: 18px; fill: currentColor; }
.chatpilot-human-btn svg { width: 19px; height: 19px; fill: currentColor; }
.chatpilot-mute-btn svg { width: 19px; height: 19px; fill: currentColor; }
.chatpilot-mute-btn .chatpilot-ico-muted { display: none; }
.chatpilot-mute-btn.is-muted .chatpilot-ico-sound { display: none; }
.chatpilot-mute-btn.is-muted .chatpilot-ico-muted { display: inline; }

/* ---------- Popovers (theme / emoji) ---------- */
/* Hidden by default; the flex/grid layout is applied ONLY when the JS clears [hidden] (otherwise an
   unconditional display:flex/grid would override the [hidden] attribute and the picker would show). */
.chatpilot-pop { position: absolute; bottom: 66px; left: 10px; right: 10px; background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; box-shadow: 0 12px 30px rgba(0,0,0,.18); padding: 10px; z-index: 5; max-height: 230px; overflow-y: auto; display: none; }
.chatpilot-themepicker:not([hidden]) { display: flex; flex-wrap: wrap; gap: 8px; }
.chatpilot-swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #cbd5e1; cursor: pointer; transition: transform .12s ease; }
.chatpilot-swatch:hover { transform: scale(1.08); }
.chatpilot-emojipicker:not([hidden]) { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.chatpilot-emoji { background: transparent; border: 0; cursor: pointer; font-size: 20px; line-height: 1; padding: 5px; border-radius: 8px; }
.chatpilot-emoji:hover { background: #f1f5f9; }

/* ---------- Messages ---------- */
.chatpilot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px 6px;
    background: var(--cp-msg-bg, #ffffff);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* a row = avatar (received only) + a vertical stack (name? + bubble + meta) */
.chatpilot-row { display: flex; align-items: flex-end; gap: 7px; margin-top: 10px; max-width: 100%; }
.chatpilot-row.is-grouped { margin-top: 2px; }
.chatpilot-row.is-shopper { flex-direction: row-reverse; }
.chatpilot-row.is-agent { justify-content: flex-start; }

.chatpilot-avatar {
    width: 28px; height: 28px; border-radius: 50%; flex: 0 0 auto; align-self: flex-end;
    background: #e4e6eb center/18px no-repeat;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23667781'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 20c0-4 4-6 8-6s8 2 8 6z'/%3E%3C/svg%3E");
}
.chatpilot-avatar.is-ai {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23667781'%3E%3Crect x='5' y='9' width='14' height='9' rx='3'/%3E%3Ccircle cx='9.5' cy='13.5' r='1.3' fill='%23fff'/%3E%3Ccircle cx='14.5' cy='13.5' r='1.3' fill='%23fff'/%3E%3Crect x='11' y='4' width='2' height='3'/%3E%3C/svg%3E");
}
.chatpilot-avatar.is-hidden { visibility: hidden; }

.chatpilot-stack { display: flex; flex-direction: column; min-width: 0; max-width: calc(100% - 44px); }
.chatpilot-row.is-shopper .chatpilot-stack { align-items: flex-end; max-width: 80%; }
.chatpilot-name { font-size: 11px; color: #65676b; margin: 0 0 2px 12px; }

.chatpilot-msg { width: fit-content; max-width: 100%; padding: 8px 12px; border-radius: 18px; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; font-size: 14px; }
.chatpilot-row.is-shopper .chatpilot-msg { background: var(--cp-shopper); color: #fff; border-bottom-right-radius: 5px; }
.chatpilot-row.is-agent .chatpilot-msg { background: var(--cp-agent); color: #050505; border-bottom-left-radius: 5px; }
/* mid-group: soften the joined corners so a run reads as one block */
.chatpilot-row.is-grouped.is-shopper .chatpilot-msg { border-top-right-radius: 5px; }
.chatpilot-row.is-grouped.is-agent .chatpilot-msg { border-top-left-radius: 5px; }

.chatpilot-msg.is-system { align-self: center; }
.chatpilot-row.is-system { justify-content: center; }
.chatpilot-sys { align-self: center; max-width: 90%; margin: 10px auto 2px; color: #8a8d91; font-size: 12px; text-align: center; }

/* lazy history: top-of-thread loading spinner shown while an older page is fetched */
.chatpilot-history-loading { align-self: center; padding: 8px 0 4px; }
.chatpilot-history-spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid #d1d5db; border-top-color: var(--chatpilot-primary, #2563eb); border-radius: 50%; animation: chatpilot-spin .7s linear infinite; }
@keyframes chatpilot-spin { to { transform: rotate(360deg); } }

.chatpilot-meta { font-size: 10px; color: #8a8d91; margin: 2px 6px 0; }
.chatpilot-tick { font-size: 11px; color: #8a8d91; }
.chatpilot-tick.is-read { color: var(--cp-primary); }
.chatpilot-seen { font-size: 10px; color: var(--cp-primary); text-align: right; margin: 2px 6px 0; align-self: flex-end; }
.chatpilot-edited { font-size: 10px; color: #8a8d91; margin: 1px 6px 0; }

.chatpilot-msg.is-deleted { font-style: italic; opacity: .8; background: #e9e9eb !important; color: #65676b !important; }

.chatpilot-msg.is-attachment { padding: 3px; }
.chatpilot-att-img { max-width: 210px; max-height: 220px; border-radius: 14px; cursor: pointer; display: block; }
.chatpilot-att-file { color: inherit; text-decoration: underline; word-break: break-all; }

/* inline links inside message text — inherit the bubble's colour so they stay readable on both sides */
.chatpilot-msg .chatpilot-link, .chatpilot-sys .chatpilot-link { color: inherit; text-decoration: underline; word-break: break-all; }
.chatpilot-row.is-shopper .chatpilot-msg .chatpilot-link { color: #fff; }

/* image preview modal (lightbox) */
.chatpilot-lightbox { position: fixed; inset: 0; z-index: 2147483000; display: none; align-items: center; justify-content: center; padding: 24px; background: rgba(0,0,0,.8); }
.chatpilot-lightbox.is-open { display: flex; }
.chatpilot-lightbox-body { display: flex; flex-direction: column; gap: 10px; max-width: 92vw; max-height: 92vh; }
.chatpilot-lightbox-bar { display: flex; align-items: center; gap: 10px; color: #fff; }
.chatpilot-lightbox-name { flex: 1; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chatpilot-lightbox-btn { width: 36px; height: 36px; flex: 0 0 auto; border-radius: 50%; border: 0; background: rgba(255,255,255,.16); color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; font-size: 15px; }
.chatpilot-lightbox-btn:hover { background: rgba(255,255,255,.32); }
.chatpilot-lightbox-btn svg { width: 18px; height: 18px; }
.chatpilot-lightbox-img { max-width: 92vw; max-height: calc(92vh - 50px); object-fit: contain; border-radius: 8px; background: #fff; }

.chatpilot-msg.is-cards { background: transparent !important; padding: 0; max-width: 100%; width: 100%; }
.chatpilot-row.is-agent .chatpilot-stack:has(.is-cards) { max-width: calc(100% - 44px); }
/* A card bubble is full-width, so the hover "react" action would sit beside a 100%-wide bubble and spill
   past the panel edge (then get clipped by overflow-x:hidden). Make the row full-width and let the cards
   bubble flex/shrink so the action button stays beside it, inside the panel. */
.chatpilot-bubblerow:has(.is-cards) { width: 100%; }
.chatpilot-bubblerow:has(.is-cards) .chatpilot-msg.is-cards { width: auto; flex: 1 1 auto; min-width: 0; }
.chatpilot-card { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; padding: 8px; margin-bottom: 6px; }
.chatpilot-card-thumb { flex: 0 0 auto; display: block; }
.chatpilot-card-thumb img { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; display: block; }
.chatpilot-card-info { flex: 1; min-width: 0; }
.chatpilot-card-name { font-weight: 600; color: #0f172a; text-decoration: none; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chatpilot-card-price { color: var(--cp-primary); font-size: 13px; }
.chatpilot-card-actions { flex: 0 0 auto; display: flex; flex-direction: column; gap: 4px; }
.chatpilot-card-add { border: 0; background: var(--cp-primary); color: #fff; border-radius: 8px; padding: 7px 11px; font-size: 12px; cursor: pointer; text-align: center; text-decoration: none; display: block; }
.chatpilot-card-add:disabled { opacity: .7; cursor: default; }
.chatpilot-card-add.is-unavailable { background: #e5e7eb; color: #9ca3af; cursor: not-allowed; opacity: 1; }
.chatpilot-card-view { border: 1px solid var(--cp-primary); background: #fff; color: var(--cp-primary); border-radius: 8px; padding: 6px 11px; font-size: 12px; cursor: pointer; text-align: center; text-decoration: none; display: block; }
.chatpilot-card-view:hover { background: rgba(37,99,235,.08); }

/* ---------- Message actions (edit / delete on the sender's own messages, on hover) ---------- */
/* bubble + actions wrapper; actions are absolutely placed to the left of the bubble so they stay
   centered on the bubble and never push it / take layout space. */
.chatpilot-bubblerow { position: relative; display: flex; align-items: center; gap: 4px; width: fit-content; max-width: 100%; }
.chatpilot-bubblerow.is-shopper { flex-direction: row-reverse; } /* own message → actions to the LEFT of the bubble */
.chatpilot-actions { display: flex; gap: 2px; flex: 0 0 auto; opacity: 0; transition: opacity .12s ease; }
.chatpilot-row:hover .chatpilot-actions { opacity: 1; }
.chatpilot-action { width: 28px; height: 28px; border: 0; border-radius: 50%; cursor: pointer; background-color: transparent; background-repeat: no-repeat; background-position: center; background-size: 15px; transition: background-color .12s ease; }
.chatpilot-action[hidden] { display: none; }
.chatpilot-action--edit { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%232563eb'%3E%3Cpath d='M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a1 1 0 0 0 0-1.41l-2.34-2.34a1 1 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z'/%3E%3C/svg%3E"); }
.chatpilot-action--edit:hover { background-color: #dbeafe; }
.chatpilot-action--delete { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23dc2626'%3E%3Cpath d='M6 19a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z'/%3E%3C/svg%3E"); }
.chatpilot-action--delete:hover { background-color: #fee2e2; }
.chatpilot-action--react { display: inline-flex; align-items: center; justify-content: center; }
.chatpilot-action--react::before { content: "🙂"; font-size: 15px; }
.chatpilot-action--react:hover { background-color: #f1f5f9; }
.chatpilot-action--more { display: inline-flex; align-items: center; justify-content: center; }
.chatpilot-action--more::before { content: "⋯"; font-size: 20px; font-weight: 700; color: #4b5563; line-height: 1; }
.chatpilot-action--more:hover { background-color: #f1f5f9; }
/* the "⋮" message menu (Edit / Unsend / Delete for me) */
.chatpilot-msgmenu { position: absolute; z-index: 45; min-width: 150px; background: #fff; border: 1px solid #e5e7eb; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.16); padding: 5px; }
.chatpilot-msgmenu-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 12px; border-radius: 6px; font-size: 13px; cursor: pointer; color: #111827; }
.chatpilot-msgmenu-item:hover:not(:disabled) { background: #f1f5f9; }
.chatpilot-msgmenu-item.is-danger { color: #dc2626; }
.chatpilot-msgmenu-item:disabled { color: #b0b3b8; cursor: default; }
/* actions are inline flex items right beside the bubble (see .chatpilot-bubblerow) — no gap, no overflow. */
.chatpilot-messages { overflow-x: hidden; }

/* reactions: floating picker bar + chips under the bubble */
.chatpilot-reactbar { position: absolute; z-index: 40; display: flex; gap: 4px; background: #fff; border: 1px solid #e5e7eb; border-radius: 24px; padding: 5px 9px; box-shadow: 0 6px 22px rgba(0,0,0,.18); }
.chatpilot-reactbar button { border: 0; background: transparent; font-size: 24px; line-height: 1; cursor: pointer; padding: 2px; border-radius: 50%; transition: transform .12s ease; }
.chatpilot-reactbar button:hover { transform: scale(1.35) translateY(-2px); }
.chatpilot-reactions { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; }
.chatpilot-reactions:empty { display: none; }
.chatpilot-reaction { border: 1px solid #e5e7eb; background: #fff; border-radius: 12px; padding: 0 7px; font-size: 12px; line-height: 19px; cursor: pointer; }
.chatpilot-reaction.is-mine { border-color: var(--chatpilot-primary, #2563eb); background: #eff6ff; }

/* inline editor — mirrors the composer input: a compact rounded field that grows a little, never a giant box.
   While editing, the bubble goes neutral + tight so the white field and Save/Cancel read cleanly. */
.chatpilot-msg:has(.chatpilot-edit) { padding: 5px !important; background: #eef1f5 !important; }
.chatpilot-edit { display: flex; flex-direction: column; gap: 6px; width: 210px; max-width: 100%; }
.chatpilot-edit-text { resize: none; border: 0; border-radius: 16px; padding: 9px 13px; font: inherit; font-size: 14px; line-height: 1.4; min-height: 36px; max-height: 96px; overflow-y: auto; box-sizing: border-box; outline: none; color: #050505; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.08); }
.chatpilot-edit-text:focus { box-shadow: 0 0 0 2px var(--cp-primary); }
.chatpilot-edit-actions { display: flex; gap: 6px; justify-content: flex-end; }
.chatpilot-edit-save, .chatpilot-edit-cancel { border: 0; border-radius: 999px; padding: 5px 14px; font-size: 12px; font-weight: 600; cursor: pointer; }
.chatpilot-edit-save { background: var(--cp-primary); color: #fff; }
.chatpilot-edit-cancel { background: #e4e6eb; color: #050505; }
.chatpilot-edited { font-size: 10px; color: #8a8d91; margin-left: 4px; }

/* ---------- Typing (left bubble, Messenger-style; hidden unless the other side is typing) ---------- */
.chatpilot-typing { gap: 4px; align-items: center; margin: 4px 0 4px 47px; padding: 9px 13px; background: var(--cp-agent); border-radius: 18px; width: fit-content; display: none; }
.chatpilot-typing:not([hidden]) { display: flex; }
.chatpilot-typing span { width: 7px; height: 7px; border-radius: 50%; background: #b0b3b8; animation: cp-bounce 1.2s infinite ease-in-out; }
.chatpilot-typing span:nth-child(2) { animation-delay: .15s; }
.chatpilot-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes cp-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ---------- Input (Messenger pill; shares the shopper-chosen theme background) ---------- */
.chatpilot-input { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; border-top: 1px solid rgba(0,0,0,.06); background: var(--cp-msg-bg, #fff); }
.chatpilot-inputbar { display: flex; align-items: flex-end; gap: 4px; }

/* attachment preview shown before the file is actually sent */
.chatpilot-preview { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 2px 0; }
.chatpilot-preview[hidden] { display: none; }
.chatpilot-preview-item { position: relative; }
.chatpilot-preview-img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; display: block; border: 1px solid #e2e8f0; }
.chatpilot-preview-file { display: flex; align-items: center; gap: 6px; background: #f0f2f5; border-radius: 10px; padding: 8px 10px; max-width: 200px; }
.chatpilot-preview-file span { font-size: 12px; color: #050505; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chatpilot-preview-remove { position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: 50%; border: 2px solid #fff; background: #4b5563; color: #fff; font-size: 12px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.chatpilot-text {
    flex: 1; resize: none; border: 0; border-radius: 20px;
    padding: 11px 15px; font: inherit; font-size: 15px; line-height: 1.45;
    min-height: 44px; max-height: 140px; overflow-y: auto; outline: none;
    box-sizing: border-box; background: #f0f2f5; color: #050505;
}
.chatpilot-text::placeholder { color: #8a8d91; }
/* character counter — only shown as the shopper nears the max-length cap */
.chatpilot-charcount { align-self: flex-end; font-size: 11px; color: #8a8d91; padding: 0 8px; }
.chatpilot-charcount.is-max { color: #e01e5a; font-weight: 600; }
.chatpilot-attach, .chatpilot-emoji-btn, .chatpilot-send {
    flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; background: transparent;
}
.chatpilot-attach:hover, .chatpilot-emoji-btn:hover { background: #f0f2f5; }
.chatpilot-attach svg { width: 22px; height: 22px; fill: none; stroke: var(--cp-primary); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chatpilot-emoji-btn { font-size: 20px; line-height: 1; }
.chatpilot-send svg { width: 22px; height: 22px; fill: var(--cp-primary); }
.chatpilot-send:hover { background: #f0f2f5; }
.chatpilot-send:disabled { opacity: .45; cursor: default; }

/* ---------- Voice notes ---------- */
.chatpilot-mic-btn {
    flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; background: transparent;
}
.chatpilot-mic-btn:hover { background: #f0f2f5; }
.chatpilot-mic-btn svg { width: 22px; height: 22px; fill: var(--cp-primary); }
.chatpilot-mic-btn.is-recording { background: #fee2e2; }
.chatpilot-mic-btn.is-recording svg { fill: #ef4444; }

/* compact player used in both the message bubble and the send-preview */
.chatpilot-voice { display: flex; align-items: center; gap: 8px; min-width: 168px; }
.chatpilot-voice-play {
    flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%; border: 0; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--cp-primary); color: #fff; font-size: 13px; line-height: 1;
}
.chatpilot-voice-track { flex: 1; height: 5px; border-radius: 3px; background: rgba(0,0,0,.14); cursor: pointer; overflow: hidden; }
.chatpilot-voice-fill { height: 100%; width: 0; background: var(--cp-primary); border-radius: 3px; }
.chatpilot-voice-time { flex: 0 0 auto; font-size: 11px; color: #6b7280; font-variant-numeric: tabular-nums; }
/* shopper bubble is on the primary colour → invert the player to stay readable */
.chatpilot-row.is-shopper .chatpilot-voice-play { background: #fff; color: var(--cp-primary); }
.chatpilot-row.is-shopper .chatpilot-voice-track { background: rgba(255,255,255,.35); }
.chatpilot-row.is-shopper .chatpilot-voice-fill { background: #fff; }
.chatpilot-row.is-shopper .chatpilot-voice-time { color: rgba(255,255,255,.9); }

/* recording-in-progress bar (shown in the preview slot) */
.chatpilot-rec { display: flex; align-items: center; gap: 8px; background: #f0f2f5; border-radius: 12px; padding: 8px 12px; }
.chatpilot-rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #ef4444; animation: chatpilot-recpulse 1s ease-in-out infinite; }
.chatpilot-rec-time { font-size: 13px; color: #050505; font-variant-numeric: tabular-nums; }
.chatpilot-rec-label { flex: 1; font-size: 12px; color: #6b7280; }
.chatpilot-rec-cancel { width: 24px; height: 24px; border-radius: 50%; border: 0; background: #4b5563; color: #fff; font-size: 14px; line-height: 1; cursor: pointer; }
.chatpilot-preview-voice { background: #f0f2f5; border-radius: 12px; padding: 8px 10px; }
@keyframes chatpilot-recpulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ---------- Composer hardening ----------
   The widget is light-DOM, so page/theme CSS (e.g. nopCommerce's cart page) can leak in and collapse the
   textarea → the placeholder wraps and a scrollbar (▲▼) appears. Pin the composer sizing at #chatpilot-root
   specificity so no page rule can override it, and keep the icon buttons compact so the textarea has room. */
#chatpilot-root .chatpilot-inputbar { flex-wrap: nowrap; min-width: 0; gap: 3px; }
#chatpilot-root .chatpilot-text {
    flex: 1 1 auto; min-width: 0; width: auto; margin: 0;
    box-sizing: border-box; -webkit-appearance: none; appearance: none;
    font-family: inherit; font-size: 15px; line-height: 1.4;
    min-height: 42px; height: 42px; max-height: 140px;
    padding: 10px 14px; border: 0; border-radius: 20px;
    resize: none; overflow-x: hidden; scrollbar-width: thin;
}
/* thin, arrow-less scrollbar (kills the chunky ▲▼ on Windows when the text is tall) */
#chatpilot-root .chatpilot-text::-webkit-scrollbar { width: 6px; }
#chatpilot-root .chatpilot-text::-webkit-scrollbar-thumb { background: rgba(0,0,0,.22); border-radius: 3px; }
#chatpilot-root .chatpilot-text::-webkit-scrollbar-button { display: none; height: 0; }
#chatpilot-root .chatpilot-attach,
#chatpilot-root .chatpilot-emoji-btn,
#chatpilot-root .chatpilot-mic-btn,
#chatpilot-root .chatpilot-send {
    flex: 0 0 auto; width: 36px; height: 36px; min-width: 36px; margin: 0; padding: 0;
}

.chatpilot-foot { text-align: center; font-size: 10px; color: #b0b3b8; padding: 4px 6px 7px; background: var(--cp-msg-bg, #fff); }

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
    .chatpilot { bottom: 14px; }
    .chatpilot.chatpilot--right { right: 14px; }
    .chatpilot.chatpilot--left { left: 14px; }
    .chatpilot-panel {
        position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh;
        max-width: 100vw; max-height: 100dvh; border-radius: 0;
    }
}
