/*
 * AI assistant launcher — see partials/ai-launcher.blade.php (ledger TRI-104).
 *
 * Mirrors the Molin widget's own launcher (measured 2026-10-08: bubble 64px at right 20 / bottom 24,
 * bar 252x50 centred at bottom 24 from 768px up, ring accent #45ba01) so the hand-over to the real
 * widget does not jump. Stays below the cookie pop-up (z-index 99999) so consent is never covered,
 * and steps out of the way of the mobile menu and of modals.
 */

@property --ai-launcher-angle {
    syntax: "<angle>";
    initial-value: 0deg;
    inherits: false;
}

.ai-launcher {
    --ai-launcher-accent: #45ba01; /* the widget's ring colour — decorative only */
    --ai-launcher-action: #368c00; /* the same green, dark enough for a white icon (4.3:1) */
    --ai-launcher-ink: #444141;
    --ai-launcher-line: #d1d5db;
    --ai-launcher-focus: #1f2937;
    --ai-launcher-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
        0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --ai-launcher-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI",
        Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
        "Segoe UI Emoji";
    --ai-launcher-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    /* No transform here, ever: a transformed ancestor becomes the containing block of the fixed
       children and they would leave the viewport corners. The entrance moves them via `translate`. */
    position: relative;
    z-index: 1050;
    opacity: 0;
    transition: opacity 0.4s ease;
    font-family: var(--ai-launcher-font);
}

.ai-launcher[hidden] {
    display: none;
}

.ai-launcher.is-visible {
    opacity: 1;
}

.ai-launcher.is-leaving {
    opacity: 0;
    pointer-events: none;
}

/* Out of the way while the mobile menu or a dialog is open: those sit inside lower stacking
   contexts (the header is z-index 30) and the launcher would paint over them. */
.modal-open .ai-launcher,
body:has(.rd-navbar-nav-wrap.active) .ai-launcher,
body:has(.rd-navbar-collapse.active) .ai-launcher {
    visibility: hidden;
}

.ai-launcher *,
.ai-launcher *::before,
.ai-launcher *::after {
    box-sizing: border-box;
}

.ai-launcher__bar,
.ai-launcher__bubble {
    translate: 0 12px;
    transition: translate 0.4s cubic-bezier(0.2, 0.8, 0.2, 1),
        transform 0.3s ease;
}

.ai-launcher.is-visible .ai-launcher__bar,
.ai-launcher.is-visible .ai-launcher__bubble {
    translate: none;
}

/* The theme sets `button:focus, a:focus { outline: none !important }` — so this needs it too. */
.ai-launcher__send:focus-visible,
.ai-launcher__bubble:focus-visible,
.ai-launcher__close:focus-visible,
.ai-launcher a:focus-visible {
    outline: 2px solid var(--ai-launcher-focus) !important;
    outline-offset: 3px;
}

/* The thin animated ring the widget draws around both controls. */
.ai-launcher__frame {
    --ai-launcher-angle: 0deg; /* without @property support the ring would blink, not spin */
    display: block;
    padding: 1px;
    border-radius: 18px;
    background: conic-gradient(
        from var(--ai-launcher-angle),
        var(--ai-launcher-line) 0deg 230deg,
        var(--ai-launcher-accent) 300deg,
        var(--ai-launcher-line) 360deg
    );
    box-shadow: var(--ai-launcher-shadow);
    animation: ai-launcher-spin 4s linear infinite;
}

@keyframes ai-launcher-spin {
    to {
        --ai-launcher-angle: 360deg;
    }
}

/* ---- Bar (desktop) ---------------------------------------------------------------------- */

.ai-launcher__bar {
    position: fixed;
    left: 50%;
    bottom: var(--ai-launcher-bottom);
    margin: 0;
    transform: translateX(-50%);
}

.ai-launcher__bar .ai-launcher__frame {
    transition: transform 0.5s ease, box-shadow 0.2s ease;
}

.ai-launcher__bar:focus-within .ai-launcher__frame {
    box-shadow: 0 0 0 2px var(--ai-launcher-action), var(--ai-launcher-shadow);
}

.ai-launcher__field {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 250px;
    padding: 8px 8px 8px 12px;
    border-radius: 17px;
    background: #fff;
    cursor: text;
    transition: width 0.5s ease;
}

.ai-launcher__bar:focus-within .ai-launcher__field {
    width: 380px;
}

.ai-launcher__input {
    flex: 1 1 auto;
    min-width: 0;
    height: 20px;
    margin: 0;
    padding: 0 4px 0 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: #1f2937;
    font: 400 14px/20px var(--ai-launcher-font);
    -webkit-appearance: none;
    appearance: none;
}

.ai-launcher__input:focus {
    outline: none;
}

.ai-launcher__input::placeholder {
    color: #6b7280;
    font-weight: 300;
    opacity: 1;
}

.ai-launcher__send {
    position: relative;
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--ai-launcher-action);
    color: #fff;
    cursor: pointer;
    transition: filter 0.2s ease;
}

/* What starts, and where to read about it — shown the moment the visitor reaches for the bar. */
.ai-launcher__note {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 10px);
    width: max-content;
    max-width: 340px;
    margin: 0;
    padding: 7px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--ai-launcher-shadow);
    color: #374151;
    font: 400 12px/1.45 var(--ai-launcher-font);
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transform: translate(-50%, 6px);
    transition: opacity 0.25s ease, transform 0.25s ease,
        visibility 0s linear 0.25s;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

/* :hover keeps it up while the pointer travels to the link — Safari does not focus a link on
   mousedown, so the input's blur would otherwise drop the note before the click lands. */
.ai-launcher__bar:focus-within .ai-launcher__note,
.ai-launcher__note:hover {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0);
    transition-delay: 0s;
}

.ai-launcher__note strong,
.ai-launcher__card strong {
    font-weight: 600;
}

.ai-launcher__note a,
.ai-launcher__card a {
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* ---- Bubble ------------------------------------------------------------------------------- */

.ai-launcher__bubble {
    position: fixed;
    right: 20px;
    bottom: var(--ai-launcher-bottom);
    display: block;
    width: 64px;
    height: 64px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 17px;
    background: transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.ai-launcher__bubble:active {
    transform: scale(0.97);
}

.ai-launcher__frame--bubble {
    width: 100%;
    height: 100%;
    border-radius: 17px;
}

.ai-launcher__face {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border-radius: 16px;
    background: #fff;
}

.ai-launcher__mark {
    display: block;
    fill: var(--ai-launcher-ink);
    transition: opacity 0.2s ease;
}

/* Pointer devices only: on touch a :hover sticks after the tap. */
@media (hover: hover) {
    .ai-launcher__bar:hover .ai-launcher__frame,
    .ai-launcher__bubble:hover {
        transform: scale(1.05);
    }

    .ai-launcher__bar:focus-within .ai-launcher__frame {
        transform: none;
    }

    .ai-launcher__send:hover {
        filter: brightness(1.1);
    }
}

/* ---- Busy / status / error ---------------------------------------------------------------- */

.ai-launcher__spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    opacity: 0;
    animation: ai-launcher-rotate 0.7s linear infinite;
}

.ai-launcher__face .ai-launcher__spinner {
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    color: var(--ai-launcher-action);
}

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

.ai-launcher.is-busy .ai-launcher__spinner {
    opacity: 1;
}

.ai-launcher.is-busy .ai-launcher__send-icon,
.ai-launcher.is-busy .ai-launcher__mark {
    opacity: 0;
}

.ai-launcher.is-busy .ai-launcher__send,
.ai-launcher.is-busy .ai-launcher__bubble {
    cursor: progress;
}

/* Status and error share one spot: above the to-top button, clear of the bar and its note. */
.ai-launcher__card {
    position: fixed;
    right: 20px;
    bottom: calc(172px + env(safe-area-inset-bottom, 0px));
    max-width: min(320px, calc(100vw - 40px));
    margin: 0;
    padding: 12px 14px;
    border-radius: 12px;
    background: #fff;
    box-shadow: var(--ai-launcher-shadow);
    color: #1f2937;
    font: 400 14px/1.45 var(--ai-launcher-font);
}

.ai-launcher__card[hidden] {
    display: none;
}

/* "Starting Molin" — the bubble path's counterpart of the bar's note, shown while it loads. */
.ai-launcher__status {
    display: none;
}

.ai-launcher.is-busy .ai-launcher__status {
    display: block;
}

.ai-launcher__bar:focus-within ~ .ai-launcher__status {
    display: none;
}

.ai-launcher__alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding-left: 17px;
    /* An inset stripe, not border-left: a border bends with the radius. */
    box-shadow: inset 3px 0 0 #d92d20, var(--ai-launcher-shadow);
}

.ai-launcher__close {
    flex: none;
    width: 24px;
    height: 24px;
    margin: -2px -4px 0 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #f3f4f6;
    color: #374151;
    font: 400 18px/24px var(--ai-launcher-font);
    cursor: pointer;
}

/* ---- Layout ------------------------------------------------------------------------------- */

/* Molin shows the bar from 768px only; phones get the bubble. */
@media (max-width: 767.98px) {
    .ai-launcher__bar {
        display: none;
    }
}

/* iOS zooms into any input under 16px on focus; touch screens get 16px. */
@media (hover: none) and (pointer: coarse) {
    .ai-launcher__input {
        font-size: 16px;
    }
}

/* The bar floats over the page bottom; give the footer room so its last links stay reachable. */
@media (min-width: 768px) {
    .has-ai-launcher .footer-modern::after {
        content: "";
        display: block;
        height: 74px;
    }
}

/* The theme's "to top" button sat exactly under the bubble — stack it above instead, centred on
   the same axis. Applies to the real widget's bubble too, which takes the same spot. */
.has-ai-launcher .ui-to-top {
    right: 22px;
    bottom: 100px;
    /* The theme parks it 100px below its spot; from 100px up that would leave it peeking in. */
    transform: translate3d(0, 200px, 0);
}

.has-ai-launcher .ui-to-top.active {
    transform: translate3d(0, 0, 0);
}

@media (prefers-reduced-motion: reduce) {
    .ai-launcher,
    .ai-launcher * {
        transition: none !important;
        animation: none !important;
    }

    /* Not motion: the delay that lets a click reach the note's link survives. */
    .ai-launcher .ai-launcher__note {
        transition: visibility 0s linear 0.25s !important;
    }

    .ai-launcher .ai-launcher__bar:focus-within .ai-launcher__note,
    .ai-launcher .ai-launcher__note:hover {
        transition-delay: 0s !important;
    }

    .ai-launcher__spinner {
        border-right-color: currentColor;
        border-style: dotted;
    }
}

@media (forced-colors: active) {
    .ai-launcher__field,
    .ai-launcher__face,
    .ai-launcher__note,
    .ai-launcher__card {
        border: 1px solid CanvasText;
    }

    .ai-launcher__mark {
        fill: CanvasText;
    }
}

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