.kle-chat {
    --chat-purple: var(--purple, #5d1f82);
    --chat-dark: var(--purple-dark, #441463);
    --chat-ink: #21192b;
    --chat-muted: #61596b;
    --chat-border: #e8e0ec;
    position: fixed;
    inset-inline-end: max(26px, env(safe-area-inset-right, 0px));
    inset-block-end: max(22px, env(safe-area-inset-bottom, 0px));
    z-index: 54;
    display: grid;
    justify-items: end;
    gap: 11px;
    color: var(--chat-ink);
    font: 14px/1.45 Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
}

.kle-chat[hidden], .kle-chat [hidden] { display: none !important; }
.kle-chat *, .kle-chat *::before, .kle-chat *::after { box-sizing: border-box; }
.kle-chat button, .kle-chat input, .kle-chat textarea { font: inherit; }
.kle-chat button { cursor: pointer; }
.kle-chat button:disabled { cursor: wait; opacity: .58; }
.kle-chat button:focus-visible, .kle-chat a:focus-visible, .kle-chat summary:focus-visible { outline: 2px solid #ba87e0; outline-offset: 3px; }

.kle-chat-launch {
    position: relative;
    isolation: isolate;
    display: grid;
    place-items: center;
    width: 62px;
    height: 62px;
    margin-bottom: 23px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .4);
    border-radius: 50%;
    background: var(--chat-purple);
    box-shadow: 0 7px 19px rgba(55, 20, 75, .26);
    color: #fff;
    font-weight: 750 !important;
}
.kle-chat-launch::before {
    content: '';
    position: absolute;
    inset: -2px;
    z-index: -1;
    border: 2px solid var(--chat-purple);
    border-radius: inherit;
    opacity: 0;
    pointer-events: none;
    animation: kle-chat-pulse 2.4s ease-out 2;
}
@keyframes kle-chat-pulse {
    0% { transform: scale(1); opacity: .55; }
    65%, 100% { transform: scale(1.32); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
    .kle-chat-launch::before { animation: none; }
}
.kle-chat-launch:hover, .kle-chat-send:hover, .kle-chat-contact-submit:hover { background: var(--chat-dark); }
.kle-chat-launch[aria-expanded='true'] { display: none; }
.kle-chat-symbol { display: block; width: 32px; height: 32px; }
.kle-chat-launch-label {
    position: absolute;
    inset-block-start: calc(100% + 4px);
    inset-inline-end: 50%;
    transform: translateX(50%);
    padding: 2px 7px;
    border: 1px solid var(--chat-border);
    border-radius: 7px;
    background: #fff;
    color: var(--chat-purple);
    font-size: 12px;
    line-height: 1.25;
    white-space: nowrap;
}
.kle-chat-unread { position: absolute; inset: -2px -4px auto auto; min-width: 20px; padding: 0 4px; border: 1px solid #fff; border-radius: 10px; background: #a2234b; color: #fff; font-size: 12px; text-align: center; }

.kle-chat-panel {
    width: min(440px, calc(100vw - 52px));
    height: min(610px, calc(100vh - 44px));
    height: min(610px, calc(100dvh - 44px));
    display: grid;
    grid-template-rows: auto minmax(80px, 1fr) auto;
    overflow: hidden;
    border: 1px solid var(--chat-border);
    border-radius: 19px;
    background: #fff;
    box-shadow: 0 14px 48px rgba(45, 20, 59, .22), 0 3px 12px rgba(45, 20, 59, .10);
}
.kle-chat-header { display: flex; align-items: center; gap: 11px; min-width: 0; min-height: 68px; padding: 11px 12px 11px 15px; border-bottom: 1px solid var(--chat-border); }
.kle-chat-heading { flex: 1; min-width: 0; }
.kle-chat-heading h2 { display: flex; align-items: flex-end; gap: 4px; margin: 0; color: var(--chat-purple); font-size: 13px; line-height: 1.2; letter-spacing: -.02em; }
.kle-chat-heading h2 img { width: 112px; height: auto; }
.kle-chat-heading h2 span { padding-bottom: 4px; }
.kle-chat-heading p { margin: 4px 0 0; color: var(--chat-muted); font-size: 12px; }
.kle-chat-close { width: 44px; height: 44px; flex: 0 0 44px; border: 0; border-radius: 10px; background: transparent; color: var(--chat-muted); font-size: 27px !important; line-height: 1 !important; }
.kle-chat-close:hover { background: #f5f0f7; color: var(--chat-purple); }

.kle-chat-thread { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 17px 16px; background: #f8f5fa; scrollbar-width: thin; }
.kle-chat-thread:focus-visible { outline: 2px solid #ba87e0; outline-offset: -2px; }
.kle-chat-intro { max-width: min(90%, 310px); margin: 0; padding: 11px 13px; border: 1px solid var(--chat-border); border-radius: 16px 16px 16px 5px; background: #fff; }
.kle-chat-messages { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: start; gap: 10px; margin: 0; padding: 0; list-style: none; }
.kle-chat-message { min-width: min(142px, 100%); max-width: 89%; padding: 9px 13px 7px; border: 1px solid var(--chat-border); border-radius: 16px 16px 16px 5px; background: #fff; box-shadow: 0 1px 2px rgba(45, 20, 59, .06); overflow-wrap: anywhere; }
.kle-chat-message.is-visitor { justify-self: end; border-color: #e8d9f0; border-radius: 16px 16px 5px 16px; background: #f0e5f6; }
.kle-chat-message.is-unread { border-color: #c69de0; }
.kle-chat-message strong { display: block; margin-bottom: 2px; color: var(--chat-purple); font-size: 12px; font-weight: 700; }
.kle-chat-message p { margin: 0; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.kle-chat-message time { display: block; margin: 3px 0 0; color: var(--chat-muted); font-size: 11px; text-align: end; }
.kle-chat-attachments { display: grid; gap: 4px; margin-top: 5px; }
.kle-chat-attachment { display: block; padding: 6px 8px; border: 1px solid #d8c4e4; border-radius: 8px; background: #fff; color: var(--chat-purple); text-decoration: underline; text-underline-offset: 2px; }
.kle-chat-attachment:hover { background: #f8f0fb; }
.kle-chat-attachment-note { color: var(--chat-muted); font-size: 12px; }

.kle-chat-controls { min-height: 0; max-height: 310px; overflow: auto; overscroll-behavior: contain; padding: 9px 12px 10px; border-top: 1px solid var(--chat-border); background: #fff; }
.kle-chat-wait { margin: 0 0 6px; padding: 6px 8px; border-radius: 7px; background: #f6effa; color: #553a66; font-size: 12px; }
.kle-chat-contact { margin: 0 0 8px; border: 1px solid var(--chat-border); border-radius: 8px; background: #faf7fb; }
.kle-chat-contact summary { display: flex; justify-content: space-between; gap: 8px; align-items: center; min-height: 37px; padding: 6px 10px; border-radius: 8px; color: var(--chat-purple); font-size: 12px; font-weight: 700; cursor: pointer; list-style: none; }
.kle-chat-contact summary::-webkit-details-marker { display: none; }
.kle-chat-contact summary::after { content: ''; width: 6px; height: 6px; margin-left: 1px; border: solid currentColor; border-width: 0 1px 1px 0; transform: rotate(45deg); }
.kle-chat-contact[open] summary::after { transform: rotate(225deg); }
.kle-chat-contact summary span:first-child { flex: 1; }
.kle-chat-contact summary span:nth-child(2) { color: #366d50; }
.kle-chat-contact form { display: grid; gap: 7px; padding: 0 10px 8px; }
.kle-chat-contact form p { margin: 0; color: var(--chat-muted); font-size: 12px; }
.kle-chat-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.kle-chat-fields label { display: grid; gap: 2px; color: var(--chat-ink); font-size: 12px; }
.kle-chat-fields input, .kle-chat-composer textarea { width: 100%; min-width: 0; min-height: 39px; padding: 6px 8px; border: 1px solid #ddcfe4; border-radius: 8px; background: #fff; color: var(--chat-ink); }
.kle-chat-fields input:focus, .kle-chat-composer textarea:focus { outline: 2px solid #c290dd; outline-offset: 0; }
.kle-chat-consent { display: flex; align-items: flex-start; gap: 7px; color: var(--chat-muted); font-size: 11px; }
.kle-chat-consent input { flex: 0 0 auto; width: 16px; height: 16px; margin: 0; accent-color: var(--chat-purple); }
.kle-chat-consent a, .kle-chat-policy { color: var(--chat-purple); text-decoration: underline; text-underline-offset: 2px; }
.kle-chat-contact-actions { display: flex; gap: 7px; }
.kle-chat-contact-submit, .kle-chat-send { min-height: 40px; padding: 6px 10px; border: 0; border-radius: 8px; background: var(--chat-purple); color: #fff; font-size: 13px !important; font-weight: 750 !important; }
.kle-chat-skip { min-height: 40px; padding: 4px 8px; border: 0; border-radius: 8px; background: transparent; color: var(--chat-purple); font-size: 12px !important; }
.kle-chat-skip:hover { background: #f2e8f7; }
.kle-chat-composer { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 7px; align-items: end; }
.kle-chat-composer textarea { min-height: 46px; max-height: 95px; line-height: 1.3; resize: vertical; }
.kle-chat-send { min-height: 46px; }
.kle-chat-attach label { display: grid; place-items: center; width: 44px; height: 46px; border: 1px solid #ddcfe4; border-radius: 8px; background: #fff; color: var(--chat-purple); cursor: pointer; }
.kle-chat-attach label:hover { background: #f5edf8; }
.kle-chat-attach input:focus-visible + label { outline: 2px solid #ba87e0; outline-offset: 2px; }
.kle-chat-selected-file { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; padding: 2px 5px 2px 10px; border: 1px solid var(--chat-border); border-radius: 8px; background: #faf7fb; color: var(--chat-purple); }
.kle-chat-file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kle-chat-clear-file { flex: 0 0 40px; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 7px; background: transparent; color: var(--chat-purple); font-size: 22px !important; }
.kle-chat-clear-file:hover { background: #f2e8f7; }
.kle-chat-error, .kle-chat-contact form .kle-chat-error { margin: 5px 0 0; color: #982438; font-size: 12px; }
.kle-chat-policy { display: inline-block; margin-top: 6px; font-size: 11px; }
.kle-chat-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

body:has(.cookie-notice:not([hidden])) .kle-chat-launch { visibility: hidden; }

@media (max-width: 680px) {
    .kle-chat { inset-inline: max(10px, env(safe-area-inset-left, 0px)) max(10px, env(safe-area-inset-right, 0px)); inset-block-end: calc(69px + env(safe-area-inset-bottom, 0px)); pointer-events: none; }
    .kle-chat-panel, .kle-chat-launch { pointer-events: auto; }
    .kle-chat-launch { width: 54px; height: 54px; margin-inline-end: 9px; }
    .kle-chat-symbol { width: 29px; height: 29px; }
    .kle-chat-panel { width: min(440px, 100%); height: min(560px, calc(100vh - 85px - env(safe-area-inset-bottom, 0px))); height: min(560px, calc(100dvh - 85px - env(safe-area-inset-bottom, 0px))); }
    .kle-chat-fields input, .kle-chat-composer textarea { font-size: 16px; }
    .kle-chat.is-keyboard { inset-block-end: calc(5px + var(--chat-keyboard-offset)); }
    .kle-chat.is-keyboard .kle-chat-panel { height: min(560px, calc(var(--chat-viewport-height) - 11px)); grid-template-rows: auto minmax(30px, 1fr) auto; }
    .kle-chat.is-keyboard .kle-chat-controls { max-height: min(310px, calc(var(--chat-viewport-height) - 111px)); }
}
