.keyvox-chat {
    --chat-navy: #1a1740;
    --chat-surface: #f7f7fb;
    --chat-card: #ffffff;
    --chat-blue: #4d6fe8;
    --chat-outgoing-gradient: linear-gradient(to bottom, #839cff 0%, var(--chat-blue) 100%);
    --chat-yellow: var(--keyvox-logo-ring);
    --chat-panel-yellow: var(--d4-yellow, #ffd500);
    --chat-text: #1f2030;
    --chat-muted: #6f7180;
    --chat-border: #e2e3eb;
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 1100;
    color: var(--chat-text);
    font-family: "Kanit", sans-serif;
}

.keyvox-chat .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.keyvox-chat__launcher {
    position: relative;
    display: grid;
    width: 58px;
    height: 58px;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: #000;
    box-shadow: 0 14px 36px rgba(8, 7, 30, 0.38);
    color: #fff;
    cursor: pointer;
    transition: transform 180ms ease, box-shadow 180ms ease;
}

.keyvox-chat__launcher::before {
    content: "";
    position: absolute;
    inset: 0;
    border: 2px solid var(--chat-yellow);
    border-radius: inherit;
    box-shadow: 0 0 4px var(--keyvox-logo-ring-glow);
    pointer-events: none;
}

.keyvox-chat__launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 17px 42px rgba(8, 7, 30, 0.46);
}

.keyvox-chat__launcher:focus-visible,
.keyvox-chat__header-close:focus-visible,
.keyvox-chat__suggestions button:focus-visible,
.keyvox-chat__composer button:focus-visible,
.keyvox-chat__result:focus-visible,
.keyvox-chat__download-cta:focus-visible,
.keyvox-chat__contact a:focus-visible,
.keyvox-chat__faq-links a:focus-visible {
    outline: 3px solid rgba(255, 213, 0, 0.78);
    outline-offset: 3px;
}

.keyvox-chat__question-mark {
    color: #5856D6;
    font-family: "Kanit", sans-serif;
    font-size: 2.13rem;
    font-weight: 600;
    line-height: 1;
    transition: opacity 160ms ease, transform 160ms ease;
}

.keyvox-chat__launcher-close {
    position: absolute;
    width: 19px;
    height: 19px;
    opacity: 0;
    transform: rotate(-45deg);
    transition: opacity 160ms ease, transform 160ms ease;
}

.keyvox-chat__launcher-close::before,
.keyvox-chat__launcher-close::after {
    content: "";
    position: absolute;
    top: 9px;
    left: 0;
    width: 19px;
    height: 2px;
    border-radius: 2px;
    background: #fff;
}

.keyvox-chat__launcher-close::after { transform: rotate(90deg); }
.keyvox-chat[data-state="open"] .keyvox-chat__launcher > .keyvox-chat__question-mark { opacity: 0; transform: scale(0.8); }
.keyvox-chat[data-state="open"] .keyvox-chat__launcher-close { opacity: 1; transform: rotate(45deg); }

.keyvox-chat__panel {
    position: absolute;
    bottom: 72px;
    left: 0;
    display: grid;
    width: min(390px, calc(100vw - 32px));
    height: min(610px, calc(100dvh - 116px));
    min-height: 430px;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    overflow: hidden;
    border: 1px solid var(--chat-panel-yellow);
    border-radius: 25px;
    background: var(--chat-surface);
    box-shadow: 0 28px 80px rgba(8, 7, 30, 0.34), 0 8px 24px rgba(8, 7, 30, 0.18);
    opacity: 0;
    transform: translateY(12px) scale(0.975);
    transform-origin: bottom left;
    pointer-events: none;
    transition: opacity 180ms ease, transform 180ms ease;
}

.keyvox-chat[data-state="open"] .keyvox-chat__panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.keyvox-chat__panel[hidden] { display: none; }

.keyvox-chat__header {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 72px;
    padding: 13px 14px 13px 16px;
    background: var(--chat-navy);
    color: #fff;
}

.keyvox-chat__identity {
    display: grid;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    place-items: center;
}

.keyvox-chat__identity .keyvox-logo__bar {
    height: 30%;
    animation: keyvox-chat-logo-wave 1.047s linear infinite;
}

.keyvox-chat__identity .keyvox-logo__bar:nth-child(2) { animation-delay: -0.133s; }
.keyvox-chat__identity .keyvox-logo__bar:nth-child(3) { animation-delay: -0.266s; }
.keyvox-chat__identity .keyvox-logo__bar:nth-child(4) { animation-delay: -0.399s; }
.keyvox-chat__identity .keyvox-logo__bar:nth-child(5) { animation-delay: -0.532s; }

@keyframes keyvox-chat-logo-wave {
    0%, 50%, 100% { height: 30%; }
    25% { height: 41%; }
    75% { height: 18%; }
}

.keyvox-chat__header h2 {
    margin: 0;
    color: #fff;
    font-size: 1.03rem;
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: 0;
}

.keyvox-chat__header p {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 3px 0 0;
    color: rgba(255, 255, 255, 0.68);
    font-size: 0.72rem;
    line-height: 1.2;
}

.keyvox-chat__header p span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #53d66f;
    box-shadow: 0 0 0 3px rgba(83, 214, 111, 0.14);
}

.keyvox-chat__header-close {
    display: grid;
    width: 36px;
    height: 36px;
    margin-left: auto;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.78);
    cursor: pointer;
}

.keyvox-chat__header-close i {
    font-size: 1.1em;
    font-weight: 900;
    -webkit-text-stroke: 0.35px currentColor;
}

.keyvox-chat__messages {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 18px 14px 12px;
    scrollbar-width: thin;
    scrollbar-color: #c6c8d3 transparent;
}

.keyvox-chat__messages > :first-child {
    margin-top: auto;
}

.keyvox-chat__message {
    display: flex;
    margin-bottom: 11px;
}

.keyvox-chat__message--user { justify-content: flex-end; }

.keyvox-chat__message--download {
    flex-direction: column;
    align-items: flex-start;
}

.keyvox-chat__bubble {
    position: relative;
    max-width: 88%;
    padding: 10px 13px;
    border: 1px solid transparent;
    border-radius: 17px 17px 17px 5px;
    background: #e9e9eb;
    box-shadow: none;
    color: #000;
}

.keyvox-chat__message--assistant .keyvox-chat__bubble::before,
.keyvox-chat__message--user .keyvox-chat__bubble::before,
.keyvox-chat__message--assistant .keyvox-chat__bubble::after,
.keyvox-chat__message--user .keyvox-chat__bubble::after {
    content: "";
    position: absolute;
    bottom: -1px;
    height: 15px;
}

.keyvox-chat__message--assistant .keyvox-chat__bubble::before {
    left: -7px;
    width: 14px;
    border-bottom-right-radius: 13px 11px;
    background: #e9e9eb;
}

.keyvox-chat__message--assistant .keyvox-chat__bubble::after {
    left: -11px;
    width: 10px;
    border-bottom-right-radius: 10px;
    background: var(--chat-surface);
}

.keyvox-chat__message--user .keyvox-chat__bubble {
    border-color: transparent;
    border-radius: 17px 17px 5px 17px;
    background-color: var(--chat-blue);
    background-image: var(--chat-outgoing-gradient);
    background-position: center var(--chat-gradient-position, 0);
    background-repeat: no-repeat;
    background-size: 100% var(--chat-gradient-height, 100%);
    box-shadow: none;
    color: #fff;
}

.keyvox-chat__message--user .keyvox-chat__bubble::before {
    right: -7px;
    width: 14px;
    border-bottom-left-radius: 13px 11px;
    background-color: var(--chat-blue);
    background-image: var(--chat-outgoing-gradient);
    background-position: center var(--chat-tail-gradient-position, 0);
    background-repeat: no-repeat;
    background-size: 100% var(--chat-gradient-height, 100%);
}

.keyvox-chat__message--user .keyvox-chat__bubble::after {
    right: -11px;
    width: 10px;
    border-bottom-left-radius: 10px;
    background: var(--chat-surface);
}

.keyvox-chat__bubble p {
    margin: 0;
    color: inherit;
    font-family: "Kanit Light", "Kanit", sans-serif;
    font-size: 0.91rem;
    font-weight: 300;
    line-height: 1.46;
}

.keyvox-chat__bubble .keyvox-chat__bridge {
    margin-top: 9px;
    color: var(--chat-muted);
    font-size: 0.82rem;
}

.keyvox-chat__bubble .keyvox-chat__contact {
    margin-top: 10px;
}

.keyvox-chat__contact a {
    font: inherit;
    color: #405fcf;
    text-underline-offset: 2px;
}

.keyvox-chat__contact a:hover {
    color: #304aa9;
}

.keyvox-chat__faq-links {
    display: grid;
    gap: 7px;
    margin-top: 10px;
}

.keyvox-chat__faq-links a {
    color: #405fcf;
    font: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.keyvox-chat__faq-links a:hover {
    color: #304aa9;
}

.keyvox-chat__typing {
    display: flex;
    width: 54px;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.keyvox-chat__typing i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #a2a4b1;
    animation: keyvox-chat-typing 1.05s ease-in-out infinite;
}

.keyvox-chat__typing i:nth-child(2) { animation-delay: 120ms; }
.keyvox-chat__typing i:nth-child(3) { animation-delay: 240ms; }

@keyframes keyvox-chat-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.55; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.keyvox-chat__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 1px 0 8px;
}

.keyvox-chat__suggestions[hidden] { display: none; }

.keyvox-chat__suggestions button {
    padding: 7px 10px;
    border: 1px solid #d5d8ea;
    border-radius: 999px;
    background: #f1f2fb;
    color: #454b79;
    font: inherit;
    font-size: 0.74rem;
    cursor: pointer;
    transition: border-color 150ms ease, background 150ms ease;
}

.keyvox-chat__suggestions button:hover {
    border-color: #9ea9e8;
    background: #e9ebfb;
}

.keyvox-chat__results {
    display: grid;
    gap: 8px;
    margin-top: 11px;
}

.keyvox-chat__result {
    display: grid;
    gap: 4px;
    padding: 11px;
    border: 1px solid #dfe1eb;
    border-radius: 13px;
    background: #fafaff;
    color: var(--chat-text);
    text-decoration: none;
    transition: border-color 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

.keyvox-chat__result:hover {
    border-color: #aab3ec;
    box-shadow: 0 6px 18px rgba(77, 111, 232, 0.10);
    transform: translateY(-1px);
}

.keyvox-chat__result-label {
    color: #696c7c;
    font-size: 0.65rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.keyvox-chat__result strong {
    color: #24263a;
    font-size: 0.88rem;
    font-weight: 500;
    line-height: 1.25;
}

.keyvox-chat__result-description {
    display: -webkit-box;
    overflow: hidden;
    color: #727483;
    font-family: "Kanit Light", "Kanit", sans-serif;
    font-size: 0.75rem;
    line-height: 1.35;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.keyvox-chat__result-action {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
    color: #405fcf;
    font-size: 0.74rem;
    font-weight: 500;
}

.keyvox-chat__result-action i { font-size: 0.65rem; }

.keyvox-chat__download {
    width: min(280px, 88%);
    margin-top: 8px;
}

.keyvox-chat__download-cta {
    display: block;
    padding: 12px 18px;
    border: 1px solid var(--chat-panel-yellow);
    border-radius: 999px;
    background: var(--chat-panel-yellow);
    color: #000;
    font-size: 0.92rem;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    transition: transform 150ms ease, box-shadow 150ms ease;
}

.keyvox-chat__download-cta:hover {
    box-shadow: 0 7px 18px rgba(91, 76, 0, 0.16);
    transform: translateY(-1px);
}

.keyvox-chat__bubble .keyvox-chat__download-note {
    margin-top: 9px;
    color: var(--chat-muted);
    font-family: "Kanit Light", "Kanit", sans-serif;
    font-size: 0.78rem;
    line-height: 1.4;
}

.keyvox-chat__composer {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 12px;
    padding: 7px 7px 7px 13px;
    border: 1px solid #d8dae4;
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 2px 9px rgba(31, 32, 48, 0.06);
}

.keyvox-chat__composer:focus-within {
    border-color: #a8b2eb;
    box-shadow: 0 0 0 3px rgba(77, 111, 232, 0.09);
}

.keyvox-chat__composer textarea {
    flex: 1;
    min-width: 0;
    max-height: 96px;
    padding: 5px 0 4px;
    resize: none;
    overflow-y: auto;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--chat-text);
    font: inherit;
    font-size: 0.88rem;
    line-height: 1.35;
}

.keyvox-chat__composer textarea::placeholder { color: #9698a5; }

.keyvox-chat__composer button {
    display: grid;
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: var(--chat-blue);
    color: #fff;
    cursor: pointer;
    transition: opacity 150ms ease, transform 150ms ease;
}

.keyvox-chat__composer button:hover:not(:disabled) { transform: scale(1.04); }
.keyvox-chat__composer button:disabled { opacity: 0.32; cursor: default; }

.keyvox-chat__disclosure {
    margin: 7px 14px 10px;
    color: #90919d;
    font-size: 0.62rem;
    line-height: 1.2;
    text-align: center;
}

@media (max-width: 640px) {
    .keyvox-chat {
        bottom: max(14px, env(safe-area-inset-bottom));
        left: 14px;
    }

    .keyvox-chat__launcher {
        width: 54px;
        height: 54px;
    }

    .keyvox-chat__panel {
        position: fixed;
        inset: auto;
        top: var(--chat-mobile-top, 8px);
        left: var(--chat-mobile-left, 8px);
        width: var(--chat-mobile-width, calc(100vw - 16px));
        height: var(--chat-mobile-height, calc(100dvh - 16px));
        min-height: 0;
        max-height: none;
        border-radius: 23px;
        transform-origin: bottom left;
    }

    .keyvox-chat__header {
        min-height: 68px;
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .keyvox-chat__messages { padding: 16px 12px 10px; }
    .keyvox-chat__bubble { max-width: 91%; }
    .keyvox-chat__download { width: min(280px, 91%); }
    .keyvox-chat__composer { margin: 0 10px; }
    .keyvox-chat__composer textarea { font-size: 16px; }
    .keyvox-chat__disclosure { margin-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
    .keyvox-chat *,
    .keyvox-chat *::before,
    .keyvox-chat *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}
