/*
 * "Ask your AI" (Brand Bible 1.3 §7.10).
 * A quiet 48 px graphite tile with a spark in the page's service accent: it reads as
 * AI help, not as a filled contact button. Its label slides out on hover or keyboard
 * focus, and once per page at a natural reading pause. The chooser is a popover
 * on wide screens and a bottom sheet on phones. Motion uses transform and opacity
 * only and is removed for reduced-motion users.
 */

.ask-ai {
    --ask-accent: var(--amtecco-mark);
    --ask-surface: var(--amtecco-graphite);
    --ask-line: var(--amtecco-line-strong);
    position: fixed;
    /* Above the fixed navigation, below Bootstrap modals (1050). */
    z-index: 1045;
    right: max(1rem, env(safe-area-inset-right, 0px));
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    color: var(--amtecco-paper);
    font-family: var(--amtecco-sans);
    opacity: 0;
    transform: translate3d(0, 8px, 0);
    transition: opacity var(--amtecco-motion-reveal) var(--amtecco-ease-out), transform var(--amtecco-motion-reveal) var(--amtecco-ease-out);
}

.ask-ai[data-accent="srt"] { --ask-accent: var(--amtecco-srt); }
.ask-ai[data-accent="cdn"] { --ask-accent: var(--amtecco-cdn); }
.ask-ai[data-accent="ai"] { --ask-accent: var(--amtecco-ai, #e3a857); }
.ask-ai[data-accent="fast"] { --ask-accent: var(--amtecco-fast, #7ccb8d); }
.ask-ai[data-accent="tspulse"] { --ask-accent: var(--amtecco-tspulse, #ec2d27); }

.ask-ai.is-visible {
    opacity: 1;
    transform: none;
}

.ask-ai button,
.ask-ai a {
    font: inherit;
    color: inherit;
}

/* ---------- The tile and its sliding label ---------- */

.ask-ai__trigger {
    position: relative;
    display: block;
    padding: 0;
    border: 0;
    background: transparent;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.ask-ai__mark {
    display: grid;
    width: 3rem;
    height: 3rem;
    place-items: center;
    border: 1px solid color-mix(in srgb, var(--ask-accent) 55%, transparent);
    border-radius: var(--amtecco-radius);
    background: var(--ask-surface);
    box-shadow: 0 0.75rem 1.75rem rgba(0, 0, 0, 0.38);
    color: var(--ask-accent);
    transition: box-shadow var(--amtecco-motion-ui) var(--amtecco-ease-standard), border-color var(--amtecco-motion-ui) var(--amtecco-ease-standard);
}

.ask-ai__label {
    position: absolute;
    top: 0;
    right: calc(100% + 0.5rem);
    display: flex;
    height: 3rem;
    align-items: center;
    padding: 0 1rem;
    border: 1px solid var(--ask-line);
    border-radius: var(--amtecco-radius);
    background: var(--ask-surface);
    box-shadow: 0 0.75rem 1.75rem rgba(0, 0, 0, 0.38);
    color: var(--amtecco-paper);
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transform: translate3d(0.5rem, 0, 0);
    transition: opacity var(--amtecco-motion-ui) var(--amtecco-ease-standard), transform var(--amtecco-motion-ui) var(--amtecco-ease-out);
}

.ask-ai__trigger:hover .ask-ai__label,
.ask-ai__trigger:focus-visible .ask-ai__label,
.ask-ai.is-hint .ask-ai__label {
    opacity: 1;
    pointer-events: auto;
    transform: none;
}

/* The chooser already names the subject; the label steps aside while it is open. */
.ask-ai.is-open .ask-ai__label {
    opacity: 0;
    pointer-events: none;
}

.ask-ai__trigger:hover .ask-ai__mark,
.ask-ai__trigger:focus-visible .ask-ai__mark,
.ask-ai.is-hint .ask-ai__mark,
.ask-ai.is-open .ask-ai__mark {
    border-color: var(--ask-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ask-accent) 28%, transparent), 0 0.75rem 1.75rem rgba(0, 0, 0, 0.38);
}

.ask-ai__trigger:focus-visible {
    outline: none;
}

.ask-ai__trigger:focus-visible .ask-ai__mark {
    outline: 2px solid var(--amtecco-paper);
    outline-offset: 3px;
}

.ask-ai__trigger:active .ask-ai__mark {
    transform: translateY(1px);
}

/* ---------- Confirmation toast ---------- */

.ask-ai__toast {
    position: absolute;
    right: 0;
    bottom: calc(100% + 0.75rem);
    display: grid;
    width: min(21rem, calc(100vw - 2rem));
    gap: 0.25rem;
    padding: 0.875rem 1rem;
    border: 1px solid var(--ask-line);
    border-left: 3px solid var(--ask-accent);
    border-radius: var(--amtecco-radius);
    background: var(--ask-surface);
    box-shadow: 0 1rem 2.5rem rgba(0, 0, 0, 0.45);
    color: var(--amtecco-paper);
    font-size: 0.9375rem;
    line-height: 1.45;
}

.ask-ai__toast-action {
    display: inline-flex;
    justify-self: start;
    min-height: 2.75rem;
    align-items: center;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--amtecco-paper) !important;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 0.2em;
    cursor: pointer;
}

.ask-ai__backdrop {
    position: fixed;
    inset: 0;
    z-index: -1;
    background: rgba(9, 11, 13, 0.62);
}

/* ---------- Phones: tile stays small; the chooser becomes a bottom sheet ---------- */

@media (min-width: 768px) {
    .ask-ai {
        right: max(1.5rem, env(safe-area-inset-right, 0px));
        bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 767.98px) {
    .ask-ai__panel {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        max-height: var(--ask-panel-max, calc(100dvh - 6rem));
        padding: 1.25rem 1rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
        border-width: 1px 0 0;
        border-radius: var(--amtecco-radius) var(--amtecco-radius) 0 0;
    }

    .ask-ai__label {
        max-width: calc(100vw - 6rem);
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ask-ai,
    .ask-ai__label,
    .ask-ai__mark,
    .ask-ai__option {
        transition: none;
    }
}

/* Very short screens (phones in landscape): pinning the header and actions would leave
   almost no room, so the whole chooser becomes the one scroll area instead. */
@media (max-height: 30rem) {
    .ask-ai__panel {
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .ask-ai__body {
        flex: none;
        min-height: auto;
        overflow: visible;
    }
}

/* ---------- Opening and closing ----------
 * Transform and opacity only. Entering decelerates and takes a little longer;
 * leaving accelerates and is quicker, so the page is handed back promptly.
 * The script adds .is-shown after unhiding and hides again after the exit. */

.ask-ai {
    --ask-enter: 280ms;
    --ask-exit: 180ms;
    --ask-ease-exit: cubic-bezier(0.4, 0, 1, 1);
}

.ask-ai__panel,
.ask-ai__toast,
.ask-ai__backdrop {
    opacity: 0;
    transition: opacity var(--ask-exit) var(--ask-ease-exit), transform var(--ask-exit) var(--ask-ease-exit);
}

.ask-ai__panel {
    transform: translate3d(0, 0.5rem, 0) scale(0.97);
    transform-origin: bottom right;
}

.ask-ai__toast {
    transform: translate3d(0, 0.375rem, 0);
    transform-origin: bottom right;
}

.ask-ai__panel.is-shown,
.ask-ai__toast.is-shown,
.ask-ai__backdrop.is-shown {
    opacity: 1;
    transform: none;
    transition-duration: var(--ask-enter);
    transition-timing-function: var(--amtecco-ease-out);
}

/* Phones: the sheet slides up from the edge as one solid surface while the page dims. */
@media (max-width: 767.98px) {
    .ask-ai {
        --ask-enter: 340ms;
        --ask-exit: 220ms;
    }

    .ask-ai__panel {
        opacity: 1;
        transform: translate3d(0, 100%, 0);
    }

    .ask-ai__panel.is-shown {
        transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .ask-ai {
        --ask-enter: 120ms;
        --ask-exit: 120ms;
    }

    .ask-ai__panel,
    .ask-ai__toast {
        opacity: 0;
        transform: none;
    }
}

@media print {
    .ask-ai {
        display: none !important;
    }
}
