.pk-chat {
    --pk-accent: #991b1b;
    --pk-accent-strong: #7f1d1d;
    --pk-bg: #ffffff;
    --pk-surface: #f8fafc;
    --pk-border: #e5e7eb;
    --pk-text: #111827;
    --pk-muted: #6b7280;
    --pk-shadow: 0 22px 60px rgba(15, 23, 42, .18), 0 6px 18px rgba(15, 23, 42, .08);
    position: fixed;
    z-index: 2147483000;
    right: 22px;
    bottom: 22px;
    color: var(--pk-text);
    font: 13px/1.5 inherit;
    text-align: start;
}

[dir="rtl"] .pk-chat {
    right: auto;
    left: 22px;
}

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

.pk-chat svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.pk-chat__launcher {
    display: grid;
    width: 50px;
    height: 50px;
    margin-inline-start: auto;
    padding: 0;
    place-items: center;
    color: #fff;
    background: linear-gradient(145deg, #b91c1c, var(--pk-accent-strong));
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 16px;
    box-shadow: 0 12px 30px rgba(127, 29, 29, .28);
    cursor: pointer;
    transition: transform .18s ease, box-shadow .18s ease;
}

.pk-chat__launcher:hover { transform: translateY(-2px); box-shadow: 0 16px 34px rgba(127, 29, 29, .34); }
.pk-chat__launcher:focus-visible, .pk-chat button:focus-visible, .pk-chat textarea:focus-visible { outline: 3px solid rgba(185, 28, 28, .22); outline-offset: 2px; }

.pk-chat__panel {
    position: absolute;
    right: 0;
    bottom: 62px;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    width: min(370px, calc(100vw - 32px));
    height: min(560px, calc(100vh - 112px));
    overflow: hidden;
    color: var(--pk-text);
    background: var(--pk-bg);
    border: 1px solid var(--pk-border);
    border-radius: 20px;
    box-shadow: var(--pk-shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px) scale(.98);
    transform-origin: bottom right;
    transition: opacity .18s ease, transform .18s ease, visibility .18s;
}

[dir="rtl"] .pk-chat__panel { right: auto; left: 0; transform-origin: bottom left; }
.pk-chat.is-open .pk-chat__panel { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }

.pk-chat__header {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) 34px 34px;
    gap: 6px;
    align-items: center;
    min-height: 66px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--pk-border);
}

.pk-chat__brand {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    color: #fff;
    background: var(--pk-accent);
    border-radius: 11px;
}

.pk-chat__brand svg { width: 17px; height: 17px; }
.pk-chat__heading { display: grid; min-width: 0; }
.pk-chat__heading strong { overflow: hidden; font-size: 13px; font-weight: 700; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.pk-chat__heading small { overflow: hidden; color: var(--pk-muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }

.pk-chat__icon-button {
    display: grid;
    width: 32px;
    height: 32px;
    padding: 0;
    place-items: center;
    color: var(--pk-muted);
    background: transparent;
    border: 0;
    border-radius: 9px;
    cursor: pointer;
}

.pk-chat__icon-button:hover { color: var(--pk-text); background: var(--pk-surface); }
.pk-chat__icon-button svg { width: 17px; height: 17px; }

.pk-chat__messages {
    overflow-x: hidden;
    overflow-y: auto;
    padding: 16px 14px 8px;
    background: linear-gradient(180deg, var(--pk-bg), var(--pk-surface));
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.pk-chat__message { display: flex; margin: 0 0 10px; }
.pk-chat__message--user { justify-content: flex-end; }
.pk-chat__message--assistant { justify-content: flex-start; }

.pk-chat__bubble {
    max-width: 86%;
    padding: 9px 11px;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    background: var(--pk-bg);
    border: 1px solid var(--pk-border);
    border-radius: 14px 14px 14px 5px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .04);
}

[dir="rtl"] .pk-chat__message--assistant .pk-chat__bubble { border-radius: 14px 14px 5px 14px; }
.pk-chat__message--user .pk-chat__bubble { color: #fff; background: var(--pk-accent); border-color: var(--pk-accent); border-radius: 14px 14px 5px 14px; }
[dir="rtl"] .pk-chat__message--user .pk-chat__bubble { border-radius: 14px 14px 14px 5px; }
.pk-chat__bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

.pk-chat__status {
    min-height: 0;
    padding: 0 15px;
    color: var(--pk-muted);
    background: var(--pk-surface);
    font-size: 11px;
    opacity: 0;
}

.pk-chat__status.is-visible { min-height: 26px; padding-top: 4px; opacity: 1; }

.pk-chat__composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 38px;
    gap: 8px;
    align-items: end;
    padding: 10px;
    background: var(--pk-bg);
    border-top: 1px solid var(--pk-border);
}

.pk-chat__composer textarea {
    width: 100%;
    min-height: 38px;
    max-height: 112px;
    margin: 0;
    padding: 9px 11px;
    resize: none;
    color: var(--pk-text);
    font: inherit;
    line-height: 1.4;
    background: var(--pk-surface);
    border: 1px solid var(--pk-border);
    border-radius: 12px;
}

.pk-chat__composer textarea::placeholder { color: #9ca3af; }
.pk-chat__composer button {
    display: grid;
    width: 38px;
    height: 38px;
    padding: 0;
    place-items: center;
    color: #fff;
    background: var(--pk-accent);
    border: 0;
    border-radius: 12px;
    cursor: pointer;
}

.pk-chat__composer button:hover { background: var(--pk-accent-strong); }
.pk-chat__composer button:disabled, .pk-chat__composer textarea:disabled { cursor: not-allowed; opacity: .55; }
.pk-chat__composer button svg { width: 17px; height: 17px; }
[dir="rtl"] .pk-chat__composer button svg { transform: scaleX(-1); }

@media (max-width: 520px) {
    .pk-chat, [dir="rtl"] .pk-chat { right: 14px; bottom: 14px; left: auto; }
    .pk-chat__panel, [dir="rtl"] .pk-chat__panel {
        position: fixed;
        right: 10px;
        bottom: 76px;
        left: 10px;
        width: auto;
        height: min(620px, calc(100dvh - 94px));
        transform-origin: bottom center;
    }
}

@media (prefers-reduced-motion: reduce) {
    .pk-chat__launcher, .pk-chat__panel { transition: none; }
}

@media (prefers-color-scheme: dark) {
    .pk-chat {
        --pk-bg: #111827;
        --pk-surface: #18212f;
        --pk-border: #2c3747;
        --pk-text: #f8fafc;
        --pk-muted: #a9b4c4;
        --pk-shadow: 0 24px 70px rgba(0, 0, 0, .45);
    }
}
