/* DW.Chat widget — fully self-contained and namespaced (dwc-chat__*) so it never collides with,
   or depends on, host-site CSS. Accent colour is driven by the --dwc-accent custom property. */

.dwc-chat,
.dwc-chat *,
.dwc-chat *::before,
.dwc-chat *::after { box-sizing: border-box; }

.dwc-chat {
    --dwc-accent: #1f6feb;
    --dwc-accent-contrast: #ffffff;
    --dwc-bg: #ffffff;
    --dwc-fg: #1b1f24;
    --dwc-muted: #6b7280;
    --dwc-border: #e6e8eb;
    --dwc-assistant-bg: #f4f5f7;
    --dwc-radius: 16px;
    --dwc-shadow: 0 12px 40px rgba(15, 23, 42, .18);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    color: var(--dwc-fg);
}

/* ---------- Launcher ---------- */
.dwc-chat__launcher {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 2147483000;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    border-radius: 999px;
    padding: 12px 20px;
    background: var(--dwc-accent);
    color: var(--dwc-accent-contrast);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .22);
    transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}

.dwc-chat__launcher::before {
    content: "";
    width: 18px;
    height: 18px;
    background: currentColor;
    -webkit-mask: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3C6.5 3 2 6.6 2 11c0 2.2 1.1 4.2 3 5.6V21l3.6-2a11 11 0 0 0 3.4.5c5.5 0 10-3.6 10-8S17.5 3 12 3Z'/%3E%3C/svg%3E");
    mask: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3C6.5 3 2 6.6 2 11c0 2.2 1.1 4.2 3 5.6V21l3.6-2a11 11 0 0 0 3.4.5c5.5 0 10-3.6 10-8S17.5 3 12 3Z'/%3E%3C/svg%3E");
}

.dwc-chat__launcher:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(15, 23, 42, .28); }

/* Position variants */
.dwc-chat--widget[data-position="bottom-left"] .dwc-chat__launcher,
.dwc-chat--widget[data-position="bottom-left"] .dwc-chat__panel { right: auto; left: 20px; }

/* Hide launcher until initialised (avoids a flash) and while the panel is open */
.dwc-chat--widget:not([data-chat-ready="true"]) .dwc-chat__launcher { visibility: hidden; }
.dwc-chat--widget.dwc-chat--open .dwc-chat__launcher { display: none; }

/* ---------- Panel ---------- */
.dwc-chat__panel {
    display: flex;
    flex-direction: column;
    background: var(--dwc-bg);
    border: 1px solid var(--dwc-border);
    border-radius: var(--dwc-radius);
    overflow: hidden;
}

/* THE critical rule: a hidden panel must not render, or it overlays and blocks the launcher. */
.dwc-chat__panel[hidden] { display: none; }
.dwc-chat--closing .dwc-chat__panel { pointer-events: none; }

.dwc-chat--widget .dwc-chat__panel {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 2147483001;
    width: 370px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 40px);
    box-shadow: var(--dwc-shadow);
    transform: translateY(10px) scale(.98);
    opacity: 0;
    transform-origin: bottom right;
    transition: opacity .18s ease, transform .18s ease;
}

.dwc-chat--widget[data-position="bottom-left"] .dwc-chat__panel { transform-origin: bottom left; }
.dwc-chat--widget.dwc-chat--open .dwc-chat__panel { transform: translateY(0) scale(1); opacity: 1; }
.dwc-chat--widget.dwc-chat--closing .dwc-chat__panel { transform: translateY(10px) scale(.98); opacity: 0; }

.dwc-chat--page .dwc-chat__panel {
    width: 100%;
    max-width: 760px;
    height: min(72vh, 640px);
    margin: 0 auto;
    box-shadow: 0 2px 14px rgba(15, 23, 42, .08);
}

/* ---------- Header ---------- */
.dwc-chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 14px 16px;
    background: var(--dwc-accent);
    color: var(--dwc-accent-contrast);
    flex: 0 0 auto;
}

/* Set the colour explicitly (not just inherited from .dwc-chat__header): an inherited colour loses
   to ANY host rule that targets the element directly — e.g. a storefront's `h2 { color: … }` /
   `p { color: … }` — regardless of specificity, which left the heading stuck on the host's dark colour. */
.dwc-chat__title { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.2; color: var(--dwc-accent-contrast); }
.dwc-chat__subtitle { margin: 3px 0 0; font-size: 12px; opacity: .85; line-height: 1.2; color: var(--dwc-accent-contrast); }

.dwc-chat__close {
    border: none;
    background: rgba(255, 255, 255, .18);
    color: var(--dwc-accent-contrast); /* explicit, not inherited — a host `button { color }` rule would win otherwise */
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    flex: 0 0 auto;
    transition: background .15s ease;
}
.dwc-chat__close:hover { background: rgba(255, 255, 255, .3); }

/* ---------- Messages ---------- */
.dwc-chat__messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #fbfbfc;
}

.dwc-chat__message { max-width: 82%; display: flex; flex-direction: column; }
.dwc-chat__message--user { align-self: flex-end; align-items: flex-end; }
.dwc-chat__message--assistant,
.dwc-chat__message--error { align-self: flex-start; align-items: flex-start; }

.dwc-chat__message-text {
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 14px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.dwc-chat__message--user .dwc-chat__message-text {
    background: var(--dwc-accent);
    color: var(--dwc-accent-contrast);
    border-bottom-right-radius: 4px;
}
.dwc-chat__message--assistant .dwc-chat__message-text {
    background: var(--dwc-assistant-bg);
    color: var(--dwc-fg);
    border-bottom-left-radius: 4px;
}
.dwc-chat__message--error .dwc-chat__message-text { background: #fde8e8; color: #9b1c1c; }

.dwc-chat__timestamp { margin: 3px 4px 0; font-size: 10px; color: var(--dwc-muted); }

/* ---------- Typing ---------- */
.dwc-chat__typing { padding: 4px 16px 8px; font-size: 12px; color: var(--dwc-muted); font-style: italic; flex: 0 0 auto; }

/* ---------- Composer ---------- */
.dwc-chat__composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--dwc-border);
    background: var(--dwc-bg);
    flex: 0 0 auto;
}

.dwc-chat__input {
    flex: 1 1 auto;
    resize: none;
    border: 1px solid var(--dwc-border);
    border-radius: 12px;
    padding: 10px 12px;
    font: inherit;
    font-size: 14px;
    line-height: 1.4;
    height: 42px;
    min-height: 42px;
    max-height: 120px;
    overflow-y: hidden;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.dwc-chat__input:focus { border-color: var(--dwc-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--dwc-accent) 18%, transparent); }

.dwc-chat__send {
    border: none;
    border-radius: 12px;
    padding: 0 18px;
    height: 42px;
    background: var(--dwc-accent);
    color: var(--dwc-accent-contrast);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    flex: 0 0 auto;
    transition: filter .15s ease;
}
.dwc-chat__send:hover { filter: brightness(1.05); }
.dwc-chat__send:disabled { opacity: .55; cursor: default; }

/* ---------- Header controls (maximise + close) ---------- */
.dwc-chat__header-controls { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.dwc-chat__maximise {
    border: none;
    background: rgba(255, 255, 255, .18);
    color: var(--dwc-accent-contrast); /* explicit — beats host button colour rules, like the close button */
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    flex: 0 0 auto;
    transition: background .15s ease;
}
.dwc-chat__maximise:hover { background: rgba(255, 255, 255, .3); }
.dwc-chat__reset {
    border: none;
    background: rgba(255, 255, 255, .18);
    color: var(--dwc-accent-contrast);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    flex: 0 0 auto;
    transition: background .15s ease;
}
.dwc-chat__reset:hover { background: rgba(255, 255, 255, .3); }

/* ---------- Starter-prompt chips ---------- */
.dwc-chat__starters { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 2px 8px; }
.dwc-chat__starter {
    border: 1px solid var(--dwc-accent);
    background: transparent;
    color: var(--dwc-accent);
    font: inherit;
    font-size: 13px;
    padding: 7px 12px;
    border-radius: 999px;
    cursor: pointer;
    line-height: 1.2;
    transition: background .15s ease, color .15s ease;
}
.dwc-chat__starter:hover { background: var(--dwc-accent); color: var(--dwc-accent-contrast); }

/* Card "View product" cue */
.dwc-chat__card-cta { font-size: 12px; font-weight: 600; color: var(--dwc-accent); margin-top: 1px; }

/* Safe-Markdown formatting inside assistant replies */
.dwc-chat__message-text a { color: var(--dwc-accent); text-decoration: underline; }
.dwc-chat__message-text code { background: rgba(15, 23, 42, .07); padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.dwc-chat__message-text strong { font-weight: 700; }

/* ---------- 👍/👎 feedback ---------- */
.dwc-chat__feedback { display: flex; gap: 6px; margin-top: 6px; }
.dwc-chat__fb {
    border: 1px solid var(--dwc-border);
    background: var(--dwc-bg);
    border-radius: 999px;
    width: 30px;
    height: 26px;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    opacity: .65;
    transition: opacity .15s ease, border-color .15s ease, background .15s ease;
}
.dwc-chat__fb:hover { opacity: 1; }
.dwc-chat__fb.is-on { opacity: 1; border-color: var(--dwc-accent); background: color-mix(in srgb, var(--dwc-accent) 12%, transparent); }

/* ---------- Product / result cards ---------- */
.dwc-chat__cards { display: flex; flex-direction: column; gap: 8px; margin: 2px 0 8px; padding: 0 2px; }
.dwc-chat__card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border: 1px solid var(--dwc-border);
    border-radius: 12px;
    background: var(--dwc-bg);
    text-decoration: none;
    color: var(--dwc-fg);
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.dwc-chat__card:hover { border-color: var(--dwc-accent); box-shadow: 0 4px 14px rgba(15, 23, 42, .12); transform: translateY(-1px); }
.dwc-chat__card-img {
    width: 58px;
    height: 58px;
    object-fit: contain;
    border-radius: 8px;
    background: #fff;
    flex: 0 0 auto;
}
.dwc-chat__card-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.dwc-chat__card-title {
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--dwc-fg);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.dwc-chat__card-price { font-size: 13px; font-weight: 700; color: var(--dwc-accent); }

/* ---------- Maximised (near-full-screen) ---------- */
.dwc-chat--max .dwc-chat__panel { border-radius: 0; }
.dwc-chat--widget.dwc-chat--max .dwc-chat__panel,
.dwc-chat--widget.dwc-chat--max.dwc-chat--open .dwc-chat__panel,
.dwc-chat--page.dwc-chat--max .dwc-chat__panel {
    position: fixed;
    inset: 0;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    /* Size from the inset offsets (not 100vw, which includes the scrollbar and would clip the right edge). */
    width: auto;
    max-width: none;
    height: auto;
    max-height: none;
    margin: 0;
    transform: none;
    opacity: 1;
    z-index: 2147483001;
}
