

.chat {
    --ink: #f6f1e8;
    --ink-dim: rgba(246, 241, 232, 0.62);
    --glass: rgba(22, 18, 16, 0.72);
    --glass-edge: rgba(255, 255, 255, 0.14);
    --sand: #d8a355;
    --bubble-bot: rgba(255, 255, 255, 0.10);
    --bubble-me: rgba(216, 163, 85, 0.92);
    --radius: 18px;

    
    --launcher: 84px;    
    --panel-w: 430px;    
    --panel-h: 640px;
    --gutter: 20px;      
    --msg-font: 14.5px;
    --pad: 16px;

    font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.chat__beacon {
    position: fixed;
    
    right: max(var(--gutter), env(safe-area-inset-right));
    bottom: max(var(--gutter), env(safe-area-inset-bottom));
    z-index: 40;

    width: var(--launcher);
    height: var(--launcher);
    display: grid;
    place-items: center;
}

.chat__beacon[hidden] {
    display: none;
}

@keyframes chatTrace {
    to { transform: rotate(360deg); }
}

@keyframes chatTraceBack {
    to { transform: rotate(-360deg); }
}

.chat__launcher {
    position: relative;
    z-index: 1;

    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    padding: 0;

    color: var(--ink);
    font: inherit;

    background: var(--glass);
    backdrop-filter: blur(16px) saturate(1.3);
    -webkit-backdrop-filter: blur(16px) saturate(1.3);
    border: 1px solid var(--glass-edge);
    border-radius: 50%;
    overflow: hidden;              
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
    cursor: pointer;

    transition: transform .35s cubic-bezier(.25, 1, .5, 1), box-shadow .3s ease, opacity .25s ease;
}

.chat__launcher:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
}

.chat__launcher:focus-visible {
    outline: 2px solid var(--sand);
    outline-offset: 3px;
}

.chat__launcher img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat__launcher svg {
    width: 30px;
    height: 30px;
    stroke: var(--sand);
}

.chat__launcher[hidden] {
    display: none;
}

.chat__scrim[aria-hidden="true"] {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.chat__panel {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 41;

    display: flex;
    flex-direction: column;
    width: min(var(--panel-w), calc(100vw - var(--gutter) * 2));
    
    height: min(var(--panel-h), calc(100vh - var(--gutter) * 2));
    height: min(var(--panel-h), calc(100dvh - var(--gutter) * 2));

    transform: translate(-50%, -50%);

    color: var(--ink);
    background: var(--glass);
    backdrop-filter: blur(26px) saturate(1.4);
    -webkit-backdrop-filter: blur(26px) saturate(1.4);
    border: 1px solid var(--glass-edge);
    border-radius: var(--radius);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
    overflow: hidden;

    transform-origin: center;
    transition: opacity .28s ease, transform .32s cubic-bezier(.25, 1, .5, 1), visibility .32s;
}

.chat__panel[aria-hidden="true"] {
    opacity: 0;
    visibility: hidden;
    transform: translate(-50%, -46%) scale(.96);
    pointer-events: none;
}

.chat__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 14px 14px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.09);
    flex: none;
}

.chat__title {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
    letter-spacing: .01em;
}

.chat__status {
    display: block;
    font-size: 12px;
    font-weight: 400;
    color: var(--ink-dim);
    margin-top: 2px;
}

.chat__dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #6ddc8b;
    margin-right: 6px;
    vertical-align: 1px;
}

.chat__spacer { flex: 1; }

.chat__close {
    flex: none;
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    color: var(--ink-dim);
    background: transparent;
    border: 0;
    border-radius: 8px;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: background .2s ease, color .2s ease;
}

.chat__close:hover { background: rgba(255, 255, 255, .09); color: var(--ink); }
.chat__close:focus-visible { outline: 2px solid var(--sand); outline-offset: 2px; }

.chat__log {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: calc(var(--pad) + 2px) var(--pad) 6px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .2) transparent;
}

.chat__log::-webkit-scrollbar { width: 8px; }
.chat__log::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .18);
    border-radius: 4px;
}

.chat__msg {
    max-width: 84%;
    padding: 11px 14px;
    border-radius: 16px;
    font-size: var(--msg-font);
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    animation: chatIn .3s cubic-bezier(.25, 1, .5, 1) both;
}

@keyframes chatIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

.chat__msg--bot {
    align-self: flex-start;
    background: var(--bubble-bot);
    border: 1px solid rgba(255, 255, 255, .07);
    border-bottom-left-radius: 5px;
}

.chat__msg--me {
    align-self: flex-end;
    background: var(--bubble-me);
    color: #241a0d;
    font-weight: 500;
    border-bottom-right-radius: 5px;
}

.chat__msg p { margin: 0; }
.chat__msg p + p { margin-top: 9px; }

.chat__typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 14px;
    background: var(--bubble-bot);
    border-radius: 16px;
    border-bottom-left-radius: 5px;
}

.chat__typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ink-dim);
    animation: chatBounce 1.2s infinite ease-in-out;
}

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

@keyframes chatBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .45; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.chat__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 10px var(--pad) 4px;
    flex: none;
}

.chat__chips:empty { display: none; }

.chat__chip {
    padding: 7px 13px;
    font: inherit;
    font-size: 12.5px;
    color: var(--ink);
    background: rgba(255, 255, 255, .07);
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 999px;
    cursor: pointer;
    transition: background .2s ease, border-color .2s ease, transform .2s ease;
}

.chat__chip:hover {
    background: rgba(216, 163, 85, .22);
    border-color: var(--sand);
    transform: translateY(-1px);
}

.chat__chip:focus-visible { outline: 2px solid var(--sand); outline-offset: 2px; }

.chat__form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px var(--pad) max(14px, env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255, 255, 255, .09);
    flex: none;
}

.chat__input {
    flex: 1;
    resize: none;
    max-height: 110px;
    padding: 11px 14px;
    font: inherit;
    
    font-size: max(16px, var(--msg-font));
    line-height: 1.45;
    color: var(--ink);
    background: rgba(255, 255, 255, .07);
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 14px;
    transition: border-color .2s ease, background .2s ease;
}

.chat__input::placeholder { color: rgba(246, 241, 232, .42); }

.chat__input:focus {
    outline: none;
    border-color: var(--sand);
    background: rgba(255, 255, 255, .1);
}

.chat__send {
    flex: none;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    color: #241a0d;
    background: var(--sand);
    border: 0;
    border-radius: 12px;
    cursor: pointer;
    transition: transform .2s ease, opacity .2s ease;
}

.chat__send:hover { transform: scale(1.06); }
.chat__send:disabled { opacity: .35; cursor: default; transform: none; }
.chat__send:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.chat__send svg { width: 18px; height: 18px; }

@media (max-width: 389px) {
    .chat {
        --launcher: 62px;
        --gutter: 12px;
        --panel-w: 100vw;
        --panel-h: 100vh;
        --msg-font: 14px;
        --pad: 12px;
    }
    .chat__msg { max-width: 92%; }
    .chat__title { font-size: 14px; }
    .chat__status { font-size: 11px; }
}

@media (min-width: 390px) and (max-width: 600px) {
    .chat {
        --launcher: 70px;
        --gutter: 14px;
        --panel-w: 100vw;
        --panel-h: 100vh;
        --msg-font: 15px;
    }
    .chat__msg { max-width: 90%; }
}

@media (min-width: 601px) and (max-width: 900px) {
    .chat {
        --launcher: 82px;
        --gutter: 22px;
        --panel-w: 460px;
        --panel-h: 660px;
        --msg-font: 15.5px;
    }
}

@media (min-width: 901px) and (max-width: 1439px) {
    .chat {
        --launcher: 84px;
        --panel-w: 440px;
        --panel-h: 660px;
    }
}

@media (min-width: 1440px) {
    .chat {
        --launcher: 92px;
        --gutter: 28px;
        --panel-w: 480px;
        --panel-h: 720px;
        --msg-font: 15.5px;
        --pad: 18px;
    }
}

@media (min-width: 2200px) {
    .chat {
        --launcher: 112px;
        --gutter: 40px;
        --panel-w: 560px;
        --panel-h: 820px;
        --msg-font: 17px;
        --pad: 22px;
        --radius: 22px;
    }
    .chat__title { font-size: 17px; }
    .chat__status { font-size: 13.5px; }
    .chat__chip { font-size: 14px; }
}

@media (max-height: 460px) and (orientation: landscape) {
    .chat {
        --launcher: 54px;
        --gutter: 10px;
        --panel-w: 420px;
        --panel-h: 100vh;
        --pad: 10px;
    }
    .chat__header { padding: 9px 10px 8px 14px; }
    .chat__status { display: none; }   
    .chat__msg { max-width: 88%; }
}

@media (pointer: coarse) {
    .chat__close { width: 44px; height: 44px; }
    .chat__send { width: 46px; height: 46px; }
    .chat__chip { padding: 10px 15px; }
}

@media (prefers-reduced-motion: reduce) {
    .chat__launcher,
    .chat__scrim,
    .chat__panel,
    .chat__msg,
    .chat__chip,
    .chat__send {
        transition: none;
        animation: none;
    }
    .chat__typing span { animation-duration: 0.01ms; }

    
    .chat__nudge {
        transition: none;
    }
}

.chat__nudge {
    position: absolute;
    right: 0;
    bottom: calc(100% + 14px);
    transform: translateY(8px);

    display: flex;
    align-items: flex-start;
    gap: 6px;

    
    width: max-content;
    max-width: min(26rem, calc(100vw - var(--gutter, 24px) - 2rem));
    padding: 0.85em 0.6em 0.85em 1.15em;
    
    border-radius: 18px 18px 4px 18px;

    background: #fff;
    box-shadow: 0 6px 24px rgba(20, 17, 14, 0.22);

    opacity: 0;
    pointer-events: none;
    transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat__nudge.is-in {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.chat__nudge-ask {
    flex: 1;
    padding: 0;
    border: none;
    background: none;
    color: #2e2a24;
    font-family: inherit;
    
    font-size: 0.94rem;
    line-height: 1.5;
    text-align: left;
    cursor: pointer;
}

.chat__nudge-ask:hover {
    color: #8c6a45;
}

.chat__nudge-close {
    flex: none;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 999px;
    background: none;
    color: #2e2a24;
    font-family: inherit;
    font-size: 1.05rem;
    line-height: 1;
    opacity: 0.34;
    cursor: pointer;
    transition: opacity 0.25s ease, background-color 0.25s ease;
}

.chat__nudge-close:hover {
    opacity: 1;
    background: rgba(46, 42, 36, 0.09);
}

.chat__nudge-ask:focus-visible,
.chat__nudge-close:focus-visible {
    outline: 2px solid #8c6a45;
    outline-offset: 2px;
    border-radius: 4px;
}

.chat__nudge::after {
    content: "";
    position: absolute;
    right: 24px;
    bottom: -5px;
    width: 12px;
    height: 12px;
    background: #fff;
    transform: rotate(45deg);
    border-radius: 2px;
}

@media (max-width: 560px) {
    .chat__nudge {
        max-width: calc(100vw - var(--gutter, 24px) - 1.5rem);
        padding: 0.8em 0.5em 0.8em 1em;
    }
}
