/*
 * Assistant plugin: the chat button, greeting bubble and chat panel in the
 * bottom-right corner. Uses the theme's design tokens.
 */

.as-root {
    --as-button: 60px;
    --as-gap: var(--space-md);
    position: fixed;
    right: var(--as-gap);
    bottom: var(--as-gap);
    z-index: calc(var(--overlay-z-index) - 2);   /* under the header, menus and cookie banner */
    font-family: inherit;
    color: var(--text-main);
}

/* Hidden while the main or language menu is open */
body.menu-open .as-root,
body.lang-open .as-root {
    visibility: hidden;
}

.as-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Round button with the smiling face */
.as-launcher {
    display: block;
    width: var(--as-button);
    height: var(--as-button);
    padding: 5px;           /* white margin around the ring */
    border: 0;
    border-radius: var(--border-radius-full);
    background: var(--bg-main);
    box-shadow: var(--box-shadow-md);
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

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

.as-launcher:focus-visible,
.as-teaser button:focus-visible,
.as-chip:focus-visible,
.as-close:focus-visible,
.as-send:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 3px;
}

.as-icon {
    display: block;
    width: 100%;
    height: 100%;
    shape-rendering: geometricPrecision;  /* smooth ring edges at every size */
}

/* On hover the ring turns one segment and the smile widens a little */
.as-ring,
.as-smile {
    transition: transform var(--transition-normal);
    transform-origin: 50% 50%;
}

.as-launcher:hover .as-ring {
    transform: rotate(120deg);
}

.as-launcher:hover .as-smile {
    transform: scaleX(1.1);
    transform-origin: 50% 60%;
}

/* Greeting bubble next to the button */
.as-teaser {
    position: absolute;
    right: calc(var(--as-button) + var(--space-sm));
    bottom: calc((var(--as-button) - 2.75rem) / 2);
    display: flex;
    align-items: center;
    max-width: calc(100vw - var(--as-button) - var(--as-gap) * 2 - var(--space-sm));
    height: 2.75rem;
    padding-left: var(--space-md);
    border-radius: var(--border-radius-full);
    background: var(--bg-main);
    box-shadow: var(--box-shadow-md);
    white-space: nowrap;
    animation: as-teaser-in var(--transition-slow) both;
}

.as-teaser[hidden] {
    display: none;
}

.as-teaser.is-leaving {
    animation: as-teaser-out var(--transition-fast) both;
}

.as-teaser-text {
    padding: 0;
    border: 0;
    background: none;
    color: var(--text-main);
    font: inherit;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.as-teaser-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 2.25rem;
    height: 2.25rem;
    margin: 0 var(--space-xs);
    padding: 0;
    border: 0;
    border-radius: var(--border-radius-full);
    background: none;
    color: var(--text-muted);
    cursor: pointer;
}

.as-teaser-close:hover {
    color: var(--color-primary);
}

@keyframes as-teaser-in {
    from { opacity: 0; transform: translateX(var(--space-sm)); }
    to   { opacity: 1; transform: none; }
}

@keyframes as-teaser-out {
    to { opacity: 0; transform: translateX(var(--space-sm)); }
}

/* Chat panel */
.as-panel {
    margin: 0;
    padding: 0;             /* the theme pads every <section> */
    position: absolute;
    right: 0;
    bottom: calc(var(--as-button) + var(--space-sm));
    display: flex;
    flex-direction: column;
    width: min(23.75rem, calc(100vw - var(--as-gap) * 2));
    height: min(35rem, calc(100dvh - var(--as-button) - var(--as-gap) * 3));
    border-radius: var(--border-radius-lg);
    background: var(--bg-main);
    box-shadow: var(--box-shadow-lg);
    overflow: hidden;
    transform-origin: 100% 100%;
    animation: as-panel-in var(--transition-fast) both;
}

.as-panel[hidden] {
    display: none;
}

@keyframes as-panel-in {
    from { opacity: 0; transform: translateY(var(--space-sm)) scale(0.98); }
    to   { opacity: 1; transform: none; }
}

.as-head {
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    background: var(--bg-main);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-sm) var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-color);
}

.as-head-icon {
    width: 2rem;
    height: 2rem;
    flex-shrink: 0;
}

.as-head h2 {
    flex: 1;
    margin: 0;
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-tight);
}

.as-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--icon-size);
    height: var(--icon-size);
    padding: 0;
    border: 0;
    border-radius: var(--border-radius-full);
    background: none;
    color: var(--color-primary);
    cursor: pointer;
}

.as-close:hover {
    background: var(--primary-a08);
}

/* Messages */
.as-log {
    flex: 1;
    min-height: 0;          /* scroll inside the panel instead of growing past it */
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-md);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.as-msg {
    max-width: 88%;
    padding: var(--space-sm) 0.875rem;
    border-radius: var(--border-radius-md);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-snug);
    overflow-wrap: anywhere;
    white-space: pre-line;
}

.as-msg--bot {
    align-self: flex-start;
    border-bottom-left-radius: var(--border-radius-sm);
    background: var(--bg-light);
}

.as-msg--user {
    align-self: flex-end;
    border-bottom-right-radius: var(--border-radius-sm);
    background: var(--color-primary);
    color: var(--text-light);
}

.as-msg--error {
    background: var(--primary-a08);
    color: var(--color-primary-dark);
}

.as-msg a {
    color: var(--color-primary);
    text-decoration: underline;
}

/* Ready questions */
.as-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-top: var(--space-xs);
}

.as-chip {
    padding: 0.4rem 0.875rem;
    border: 1px solid var(--color-primary);
    border-radius: var(--border-radius-full);
    background: var(--bg-main);
    color: var(--color-primary);
    font: inherit;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    line-height: var(--line-height-snug);
    text-align: left;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.as-chip:hover {
    background: var(--primary-a08);
}

/* "Thinking" dots */
.as-typing {
    display: inline-flex;
    gap: 4px;
    padding: 0.25rem 0;
}

.as-typing span {
    width: 6px;
    height: 6px;
    border-radius: var(--border-radius-full);
    background: var(--text-muted);
    animation: as-dot 1s infinite ease-in-out;
}

.as-typing span:nth-child(2) { animation-delay: 0.15s; }
.as-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes as-dot {
    0%, 60%, 100% { opacity: 0.3; transform: none; }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* Log in to ask own questions (in place of the question field) */
.as-login {
    flex-shrink: 0;
    padding: var(--space-sm) var(--space-sm) 0;
    border-top: 1px solid var(--border-color);
}

.as-login[hidden] {
    display: none;
}

.as-login p {
    margin: 0 0 var(--space-xs);
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-snug);
}

.as-login-links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs) var(--space-md);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
}

.as-login-links a {
    color: var(--color-primary);
}

.as-login-links .as-login-primary {
    text-decoration: none;
}

.as-form[hidden] {
    display: none;
}

/* Question field */
.as-form {
    flex-shrink: 0;
    display: flex;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-sm) 0;
    border-top: 1px solid var(--border-color);
}

.as-form input {
    flex: 1;
    min-width: 0;
    padding: var(--space-sm) 0;
    border: 0;
    border-bottom: 1px solid var(--border-color);
    border-radius: 0;
    background: transparent;
    color: var(--text-main);
    font: inherit;
    font-size: var(--font-size-base);   /* 16px: no zoom on phones */
    transition: border-color var(--transition-fast);
}

.as-form input:hover {
    border-color: var(--border-color-hover);
}

.as-form input:focus {
    outline: 0;
    border-color: var(--color-primary);
}

.as-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 2.875rem;
    height: 2.875rem;
    padding: 0;
    border: 0;
    border-radius: var(--border-radius-full);
    background: var(--color-primary);
    color: var(--text-light);
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.as-send:hover {
    background: var(--color-primary-dark);
}

.as-send:disabled {
    opacity: 0.5;
    cursor: default;
}

.as-note {
    flex-shrink: 0;
    margin: 0;
    padding: var(--space-xs) var(--space-md) var(--space-sm);
    color: var(--text-muted);
    font-size: var(--font-size-2xs);
    line-height: var(--line-height-snug);
    text-align: center;
}

/* Phones: the panel takes most of the screen, the button hides behind it */
@media (max-width: 520px) {
    .as-root {
        --as-button: 56px;
        --as-gap: var(--space-sm);
    }

    .as-root[data-state="open"] .as-launcher {
        visibility: hidden;
    }

    .as-panel {
        position: fixed;
        left: var(--as-gap);
        right: var(--as-gap);
        bottom: var(--as-gap);
        width: auto;
        height: min(36rem, calc(100dvh - var(--as-gap) * 2 - 4rem));
    }
}

@media (prefers-reduced-motion: reduce) {
    .as-teaser,
    .as-panel,
    .as-typing span {
        animation: none;
    }

    .as-ring,
    .as-smile {
        transition: none;
    }
}

/* Where the round button would cover the last footer links (narrower screens
   with the links on the right), the links stop before it; no extra space under the footer */
@media (min-width: 577px) and (max-width: 1320px) {
    body:has(.as-root) .footer-bottom-inner {
        padding-right: calc(60px + 1.5rem);
    }
}
