/* ============================================================================
   Website assistant widget, shared by ai.vodoro.de and vodoro.de
   (templates/partials/assistant.html, assistant.js).

   Colours come only from --vd-assist-* variables, which each site maps onto
   its own palette: vodoro.css (dark, blue/green) and website.css (light,
   green). Add a new colour here as a variable and define it in both, never as
   a site token, or the widget breaks on the other site. --vd-assist-z is
   per site too: the two use different z-index scales. The radii and
   --ease-out are shared foundation tokens that both stylesheets define.

   Form fields are styled here rather than inherited: the two sites' global
   input styles differ, and the widget must look the same on both.
   ========================================================================== */

/* Scoped to the panel, not :root -- these are this component's dimensions,
   not site tokens. */
.vd-assist-panel {
    --vd-assist-w: 380px;
    --vd-assist-h: min(560px, 70vh);
}

.vd-assist-panel input,
.vd-assist-panel textarea,
.vd-assist-panel select {
    box-sizing: border-box;
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--vd-assist-line-strong);
    border-radius: var(--radius-sm);
    background: var(--vd-assist-field);
    color: var(--vd-assist-text-strong);
    font: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.vd-assist-panel input::placeholder,
.vd-assist-panel textarea::placeholder {
    color: var(--vd-assist-faint);
}

.vd-assist-panel input:focus,
.vd-assist-panel textarea:focus,
.vd-assist-panel select:focus {
    border-color: var(--vd-assist-focus);
    box-shadow: 0 0 0 3px var(--vd-assist-focus-ring);
    outline: none;
}

/* Honeypot in the callback form: off-screen, not display:none, so naive bots
   still fill it. */
.vd-assist-panel .vd-hp {
    position: absolute !important;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Page scroll lock while the full-screen panel is open on a phone (set by
   assistant.js). */
html.vd-assist-open,
html.vd-assist-open body {
    overflow: hidden;
}

.vd-assist-launcher {
    position: fixed;
    right: 2.25rem;
    bottom: 1.5rem;
    z-index: var(--vd-assist-z);
    width: 56px;
    height: 56px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-pill);
    background: var(--vd-assist-accent);
    color: var(--vd-assist-on-accent);
    cursor: pointer;
    box-shadow: var(--vd-assist-shadow);
    transition: transform 0.25s var(--ease-out), box-shadow 0.25s var(--ease-out);
}

.vd-assist-launcher:hover {
    transform: translateY(-2px);
    box-shadow: var(--vd-assist-shadow-lg);
}

.vd-assist-launcher:focus-visible {
    outline: 2px solid var(--vd-assist-link);
    outline-offset: 3px;
}

.vd-assist-launcher__icon {
    width: 24px;
    height: 24px;
}

.vd-assist-launcher__icon--close { display: none; }
.vd-assist-launcher.is-open .vd-assist-launcher__icon--chat { display: none; }
.vd-assist-launcher.is-open .vd-assist-launcher__icon--close { display: block; }

/* The back-to-top button lives in the same corner. Lift it above the
   launcher whenever the assistant is on the page, or the two overlap. */
.vd-assist-launcher ~ .back-to-top,
body:has(.vd-assist-launcher) .back-to-top {
    bottom: calc(1.5rem + 56px + 0.75rem);
}

.vd-assist-panel {
    position: fixed;
    right: 2.25rem;
    bottom: calc(1.5rem + 56px + 0.75rem);
    z-index: calc(var(--vd-assist-z) + 1);
    width: var(--vd-assist-w);
    max-width: calc(100vw - 3rem);
    height: var(--vd-assist-h);
    display: flex;
    flex-direction: column;
    background: var(--vd-assist-surface);
    border: 1px solid var(--vd-assist-line-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--vd-assist-shadow-lg);
    overflow: hidden;
}

/* Focused by script on phones (tabindex=-1) so the keyboard stays closed;
   that is not a keyboard focus to highlight. */
.vd-assist-panel:focus {
    outline: none;
}

/* The JS toggles the hidden attribute on the panel and on its body/forms
   (chat vs. callback form). Those elements set display: flex above, which
   beats the browser's [hidden] { display: none }, so restate it here or the
   panel can never be closed. */
.vd-assist-panel[hidden],
.vd-assist-panel [hidden] {
    display: none;
}

.vd-assist-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--vd-assist-line);
    background: var(--vd-assist-surface-2);
}

.vd-assist-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 650;
    color: var(--vd-assist-text-strong);
}

.vd-assist-header__actions {
    display: flex;
    gap: 0.25rem;
}

.vd-assist-iconbtn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--vd-assist-muted);
    cursor: pointer;
}

.vd-assist-iconbtn:hover {
    background: var(--vd-assist-surface-3);
    color: var(--vd-assist-text);
}

.vd-assist-iconbtn:focus-visible {
    outline: 2px solid var(--vd-assist-link);
    outline-offset: 1px;
}

.vd-assist-iconbtn svg {
    width: 16px;
    height: 16px;
}

.vd-assist-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.vd-assist-log {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    /* Scrolling past the end of the chat must not scroll the page behind it. */
    overscroll-behavior: contain;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.vd-assist-bubble {
    max-width: 85%;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius);
    font-size: 0.88rem;
    line-height: 1.55;
}

.vd-assist-bubble p {
    margin: 0 0 0.6rem;
}

.vd-assist-bubble p:last-child {
    margin-bottom: 0;
}

.vd-assist-bubble a {
    color: var(--vd-assist-link);
}

.vd-assist-bubble--assistant {
    align-self: flex-start;
    background: var(--vd-assist-surface-3);
    border: 1px solid var(--vd-assist-line);
    color: var(--vd-assist-text);
    border-bottom-left-radius: var(--radius-sm);
}

.vd-assist-bubble--user {
    align-self: flex-end;
    background: var(--vd-assist-accent);
    color: var(--vd-assist-on-accent);
    border-bottom-right-radius: var(--radius-sm);
}

.vd-assist-status {
    margin: 0;
    padding: 0 1rem 0.5rem;
    font-size: 0.76rem;
    color: var(--vd-assist-muted);
    min-height: 1.1em;
}

/* Animated dots follow the status text only while a reply is in flight. */
.vd-assist-panel.is-busy .vd-assist-status::after {
    content: '';
    display: inline-block;
    width: 1.2em;
    text-align: left;
    animation: vd-assist-dots 1.2s steps(4, end) infinite;
}

@keyframes vd-assist-dots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
}

.vd-assist-notice {
    margin: 0;
    padding: 0.5rem 1rem;
    font-size: 0.72rem;
    line-height: 1.45;
    color: var(--vd-assist-muted);
    border-top: 1px solid var(--vd-assist-line);
}

.vd-assist-notice a {
    color: var(--vd-assist-link);
}

.vd-assist-form {
    display: flex;
    align-items: flex-end;
    gap: 0.4rem;
    padding: 0.7rem 0.8rem 0.8rem;
    border-top: 1px solid var(--vd-assist-line);
    background: var(--vd-assist-surface-2);
}

.vd-assist-form textarea {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    margin: 0;
    padding: 0.6rem 0.7rem;
    resize: none;
    font-size: 0.88rem;
    line-height: 1.4;
}

/* One line only: a placeholder that wraps in a one-row field is cut in half. */
.vd-assist-form textarea::placeholder {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vd-assist-send,
.vd-assist-callback {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.vd-assist-callback {
    background: transparent;
    border: 1px solid var(--vd-assist-line);
    color: var(--vd-assist-muted);
}

.vd-assist-callback:hover {
    color: var(--vd-assist-text);
    border-color: var(--vd-assist-line-strong);
}

.vd-assist-send {
    background: var(--vd-assist-accent);
    color: var(--vd-assist-on-accent);
}

.vd-assist-send svg,
.vd-assist-callback svg {
    width: 17px;
    height: 17px;
}

.vd-assist-form textarea:disabled {
    opacity: 0.6;
}

/* Callback form: replaces the log while open. */
.vd-assist-lead {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem;
}

.vd-assist-lead__title {
    margin: 0 0 0.8rem;
    font-size: 0.95rem;
    font-weight: 650;
    color: var(--vd-assist-text-strong);
}

.vd-assist-lead label {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--vd-assist-muted);
}

.vd-assist-lead input,
.vd-assist-lead textarea,
.vd-assist-lead select {
    width: 100%;
    margin-bottom: 0.8rem;
    padding: 0.55rem 0.7rem;
    font-size: 0.85rem;
}

.vd-assist-lead__error {
    margin: 0 0 0.7rem;
    font-size: 0.8rem;
    color: var(--vd-assist-error);
}

.vd-assist-lead__actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.vd-assist-lead__cancel {
    flex: 1;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--vd-assist-line);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--vd-assist-muted);
    font-size: 0.83rem;
    cursor: pointer;
}

.vd-assist-lead__cancel:hover {
    color: var(--vd-assist-text);
}

/* The callback form reuses the square send icon button for a text label. */
.vd-assist-lead__actions .vd-assist-send {
    width: auto;
    padding: 0 1.1rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.vd-assist-visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── 8c responsive: assistant on small screens ───────────────────────────── */
@media (max-width: 640px) {
    /* Full screen. --vd-assist-vv-* are set by assistant.js from
       window.visualViewport, so the panel shrinks above the on-screen keyboard
       instead of hiding the input behind it (100dvh ignores the keyboard on
       iOS). */
    .vd-assist-panel {
        right: 0;
        left: 0;
        top: var(--vd-assist-vv-top, 0);
        bottom: auto;
        width: 100%;
        max-width: none;
        height: var(--vd-assist-vv-h, 100dvh);
        border: none;
        border-radius: 0;
    }

    .vd-assist-launcher {
        right: 1rem;
        bottom: 1rem;
    }

    /* The panel covers it and has its own close button. */
    .vd-assist-launcher.is-open {
        display: none;
    }

    .vd-assist-header {
        padding: 0.5rem 0.5rem 0.5rem 1rem;
    }

    /* Thumb-sized touch targets. */
    .vd-assist-iconbtn {
        width: 44px;
        height: 44px;
    }

    .vd-assist-iconbtn svg {
        width: 20px;
        height: 20px;
    }

    .vd-assist-bubble {
        max-width: 90%;
        font-size: 0.95rem;
    }

    .vd-assist-notice {
        padding: 0.4rem 1rem;
        font-size: 0.68rem;
    }

    .vd-assist-form {
        padding-bottom: calc(0.8rem + env(safe-area-inset-bottom, 0px));
    }

    .vd-assist-send,
    .vd-assist-callback {
        width: 44px;
        height: 44px;
    }

    /* iOS Safari zooms the whole page into any field under 16px and does not
       zoom back out, which wrecks the full-screen layout. */
    .vd-assist-form textarea,
    .vd-assist-lead input,
    .vd-assist-lead textarea,
    .vd-assist-lead select {
        font-size: 16px;
    }

    .vd-assist-form textarea {
        min-height: 44px;
    }
}
