/**
 * WeblabsUI – Chatbot widget (frontend).
 *
 * Runs next to a theme we do not control, so every rule is scoped under
 * .wui-chat, every property is set explicitly, and the widget sits on its
 * own layer above the page — the same discipline feedback.css follows,
 * and for the same reason.
 */

.wui-chat {
    --chat-bg: #ffffff;
    --chat-fg: #1d2327;
    --chat-muted: #6b7280;
    --chat-line: #e5e7eb;
    --chat-accent: #b45309;
    --chat-accent-fg: #ffffff;
    --chat-bubble-user: #012f2c;
    --chat-bubble-user-fg: #ffffff;
    --chat-bubble-bot: #f3f4f6;
    --chat-bubble-bot-fg: #1d2327;
    --chat-radius: 14px;
    --chat-shadow: 0 10px 40px rgba(0, 0, 0, .16);

    position: static;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    letter-spacing: normal;
    text-transform: none;
    color: var(--chat-fg);
}

.wui-chat :where(p, span, strong, label, button, textarea, input, select, code) {
    font-family: inherit;
    letter-spacing: normal;
    text-transform: none;
}

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

/* ── Launcher ────────────────────────────────────────────── */

.wui-chat__launcher {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 2147483000;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 50%;
    background: var(--chat-accent);
    color: var(--chat-accent-fg);
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
    transition: transform .15s ease, box-shadow .15s ease;
}

.wui-chat__launcher:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 10px 26px rgba(0, 0, 0, .3);
}

.wui-chat__launcher:focus-visible {
    outline: 3px solid rgba(180, 83, 9, .35);
    outline-offset: 2px;
}

/* ── Window ──────────────────────────────────────────────── */

.wui-chat__window {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 2147483100;
    display: flex;
    flex-direction: column;
    width: min(380px, calc(100vw - 44px));
    height: min(600px, calc(100vh - 60px));
    border: 1px solid var(--chat-line);
    border-radius: var(--chat-radius);
    background: var(--chat-bg);
    box-shadow: var(--chat-shadow);
    overflow: hidden;
}

.wui-chat__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--chat-line);
    font-size: 14px;
    flex: 0 0 auto;
}

.wui-chat__head-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.wui-chat__model {
    padding: 4px 6px;
    border: 1px solid var(--chat-line);
    border-radius: 6px;
    background: #fff;
    color: var(--chat-fg);
    font: inherit;
    font-size: 11px;
    max-width: 140px;
}

.wui-chat__x {
    border: 0;
    background: none;
    padding: 0 4px;
    font-size: 22px;
    line-height: 1;
    color: var(--chat-muted);
    cursor: pointer;
}

.wui-chat__x:hover { color: var(--chat-fg); }

/* ── Messages ────────────────────────────────────────────── */

.wui-chat__body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.wui-chat__row {
    display: flex;
}

.wui-chat__row--user {
    justify-content: flex-end;
}

.wui-chat__row--assistant {
    justify-content: flex-start;
}

.wui-chat__bubble {
    max-width: 84%;
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-line;
    word-break: break-word;
}

.wui-chat__row--user .wui-chat__bubble {
    background: var(--chat-bubble-user);
    color: var(--chat-bubble-user-fg);
    border-bottom-right-radius: 4px;
}

.wui-chat__row--assistant .wui-chat__bubble {
    background: var(--chat-bubble-bot);
    color: var(--chat-bubble-bot-fg);
    border-bottom-left-radius: 4px;
}

/* Typing indicator: three dots, staggered pulse. */
.wui-chat__typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 14px;
}

.wui-chat__typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chat-muted);
    animation: wui-chat-bounce 1.2s infinite ease-in-out;
}

.wui-chat__typing span:nth-child(2) { animation-delay: .15s; }
.wui-chat__typing span:nth-child(3) { animation-delay: .3s; }

@keyframes wui-chat-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* ── Footer / input ──────────────────────────────────────── */

.wui-chat__footer {
    flex: 0 0 auto;
    border-top: 1px solid var(--chat-line);
    padding: 10px 12px;
}

.wui-chat__image-preview {
    position: relative;
    display: inline-block;
    margin-bottom: 8px;
}

.wui-chat__image-preview img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--chat-line);
    display: block;
}

.wui-chat__image-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, .65);
    color: #fff;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
}

.wui-chat__form {
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.wui-chat__icon-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid var(--chat-line);
    border-radius: 8px;
    background: #fff;
    color: var(--chat-muted);
    cursor: pointer;
}

.wui-chat__icon-btn:hover {
    color: var(--chat-fg);
    border-color: var(--chat-accent);
}

.wui-chat__input {
    flex: 1 1 auto;
    min-height: 34px;
    max-height: 100px;
    padding: 8px 10px;
    border: 1px solid var(--chat-line);
    border-radius: 8px;
    background: #fff;
    color: var(--chat-fg);
    font: inherit;
    font-size: 13px;
    resize: none;
}

.wui-chat__input:focus {
    outline: none;
    border-color: var(--chat-accent);
    box-shadow: 0 0 0 3px rgba(180, 83, 9, .12);
}

.wui-chat__send {
    flex: 0 0 auto;
    padding: 8px 14px;
    border: 0;
    border-radius: 8px;
    background: var(--chat-accent);
    color: var(--chat-accent-fg);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.wui-chat__send:disabled { opacity: .6; cursor: default; }

.wui-chat__actions {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
}

.wui-chat__escalate,
.wui-chat__newchat {
    padding: 6px 10px;
    border: 1px solid var(--chat-line);
    border-radius: 7px;
    background: #fff;
    color: var(--chat-muted);
    font: inherit;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

.wui-chat__escalate:hover,
.wui-chat__newchat:hover {
    border-color: var(--chat-accent);
    color: var(--chat-accent);
}

/* ── Escalation panel ────────────────────────────────────── */

.wui-chat__escalate-panel {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    padding: 14px;
    background: var(--chat-bg);
}

.wui-chat__panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.wui-chat__panel-hint {
    margin: 0 0 14px;
    font-size: 12px;
    color: var(--chat-muted);
}

.wui-chat__field {
    display: block;
    margin-bottom: 12px;
}

.wui-chat__field-label {
    display: block;
    margin-bottom: 5px;
    font-size: 12px;
    font-weight: 600;
}

.wui-chat__field-input {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--chat-line);
    border-radius: 7px;
    background: #fff;
    color: var(--chat-fg);
    font: inherit;
    font-size: 13px;
}

.wui-chat__field-input:focus {
    outline: none;
    border-color: var(--chat-accent);
}

.wui-chat__message {
    min-height: 16px;
    margin: 0 0 8px;
    font-size: 12px;
    color: #b91c1c;
}

.wui-chat__cancel {
    padding: 8px 14px;
    border: 1px solid var(--chat-line);
    border-radius: 7px;
    background: #fff;
    color: var(--chat-muted);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

/* The panel sits over the window, its own actions row spans full width. */
.wui-chat__escalate-panel .wui-chat__actions {
    justify-content: flex-end;
    margin-top: auto;
}

/* ── Toast ───────────────────────────────────────────────── */

.wui-chat__toast {
    position: fixed;
    right: 22px;
    bottom: 84px;
    z-index: 2147483200;
    padding: 11px 16px;
    border-radius: 8px;
    background: #111827;
    color: #fff;
    font-size: 13px;
    box-shadow: var(--chat-shadow);
    transition: opacity .4s ease, transform .4s ease;
}

.wui-chat__toast.is-out {
    opacity: 0;
    transform: translateY(8px);
}

/* ── Dark mode ───────────────────────────────────────────
   Driven by WeblabsUI's own setting, never by prefers-color-scheme —
   see feedback.css for why that matters here. */

.wui-chat--dark {
    --chat-bg: #1e1e22;
    --chat-fg: #e5e7eb;
    --chat-muted: #9ca3af;
    --chat-line: #3f3f46;
    --chat-bubble-bot: #2b2b30;
    --chat-bubble-bot-fg: #e5e7eb;
}

.wui-chat--dark .wui-chat__model,
.wui-chat--dark .wui-chat__icon-btn,
.wui-chat--dark .wui-chat__input,
.wui-chat--dark .wui-chat__escalate,
.wui-chat--dark .wui-chat__newchat,
.wui-chat--dark .wui-chat__field-input,
.wui-chat--dark .wui-chat__cancel {
    background: #27272b;
    color: var(--chat-fg);
}
