/* The floating assistant (Components/Layout/AssistantHost.razor): the logo's eclipse, slowly alive, carrying a conversation
   from page to page. The eclipse markup and colours are the page loader's (app.css "page loading"); only its pace and the
   states are set here. Below Bootstrap's modals (1050) so a dialog still covers it, above the pet (pet.css) and tool runs. */

.rl-assist {
    --assist-size: 56px;
    --assist-glow: rgba(168, 85, 247, 0.55);
    --assist-ink: #ede9fe;
    position: fixed;
    z-index: 1040;
    width: var(--assist-size);
    height: var(--assist-size);
    transition: left .35s var(--rl-ease, ease), top .35s var(--rl-ease, ease), opacity .3s ease;
    touch-action: none;
}
.rl-assist.is-dragging { transition: none; }

/* ── the eclipse ───────────────────────────────────────────────────────────────────────────────────────────────── */
.rl-assist__orb {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    cursor: grab;
    animation: rl-assist-float 7s ease-in-out infinite;
    -webkit-tap-highlight-color: transparent;
}
.rl-assist.is-dragging .rl-assist__orb { cursor: grabbing; animation: none; transform: scale(1.08); }
.rl-assist__orb:focus-visible { outline: 2px solid var(--rl-accent); outline-offset: 6px; }

.rl-assist__eclipse { --eclipse-size: 100%; width: 100%; height: 100%; pointer-events: none; }
/* Slower than the page loader's: this one lives on the screen, and something always spinning fast is a distraction. */
.rl-assist__eclipse .eclipse__sun { animation-duration: 14s; }
.rl-assist__eclipse .eclipse__corona { inset: -75%; animation-duration: 5.5s; }
.rl-assist__orb:hover .rl-assist__eclipse .eclipse__corona { animation-duration: 2.6s; }

/* A ring that only shows in a state: listening ripples it outward, asking makes it amber. */
.rl-assist__ring {
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid transparent;
    pointer-events: none;
    opacity: 0;
}

.rl-assist__badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
    border-radius: 7px;
    background: #a855f7;
    border: 2px solid var(--rl-bg);
    color: #fff;
    font: 700 10px/10px var(--rl-font);
    text-align: center;
    pointer-events: none;
    animation: rl-assist-pop .3s ease-out both;
}
.rl-assist__badge--ask { background: #f59e0b; min-width: 18px; height: 18px; border-radius: 9px; line-height: 14px; font-size: 11px; }

.rl-assist[data-state="thinking"] .eclipse__sun { animation-duration: 2.2s; }
.rl-assist[data-state="thinking"] .eclipse__corona { animation-duration: 1.8s; }

.rl-assist[data-state="speaking"] .eclipse__corona { animation: rl-assist-speak .9s ease-in-out infinite; }

.rl-assist[data-state="listening"] .rl-assist__ring {
    border-color: rgba(196, 181, 253, 0.85);
    animation: rl-assist-ripple 2s ease-out infinite;
}

.rl-assist[data-state="ask"] .rl-assist__ring {
    border-color: rgba(245, 158, 11, 0.9);
    animation: rl-assist-ripple 1.4s ease-out infinite;
}

@keyframes rl-assist-float { 0%, 100% { transform: translateY(0) rotate(0deg); } 50% { transform: translateY(-4px) rotate(-3deg); } }
@keyframes rl-assist-speak { 0%, 100% { opacity: .75; transform: scale(.96); } 50% { opacity: 1; transform: scale(1.12); } }
@keyframes rl-assist-ripple { 0% { opacity: .9; transform: scale(.9); } 100% { opacity: 0; transform: scale(1.45); } }
@keyframes rl-assist-pop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes rl-assist-in { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }

/* Put away: half of it peeks in from the screen's edge, dimmed, until it is clicked. */
.rl-assist--tucked { opacity: .72; }
.rl-assist--tucked:hover { opacity: 1; }
.rl-assist--tucked .rl-assist__orb { animation: none; }

/* ── the speech bubble beside it ─────────────────────────────────────────────────────────────────────────────── */
.rl-assist__bubble {
    position: absolute;
    bottom: calc(100% + 10px);
    width: max-content;
    max-width: min(18rem, calc(100vw - 2rem));
    padding: .5rem .75rem;
    border-radius: 14px;
    border: 1px solid var(--rl-border);
    background: color-mix(in srgb, var(--rl-surface) 94%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: var(--rl-shadow-md, 0 6px 24px rgba(0, 0, 0, .18));
    color: var(--rl-text);
    font-size: .86rem;
    line-height: 1.35;
    cursor: pointer;
    animation: rl-assist-in .25s var(--rl-ease, ease) both;
}
.rl-assist[data-side="left"] .rl-assist__bubble { right: 0; }
.rl-assist[data-side="right"] .rl-assist__bubble { left: 0; }
.rl-assist[data-vert="down"] .rl-assist__bubble { bottom: auto; top: calc(100% + 10px); }

/* ── the panel ─────────────────────────────────────────────────────────────────────────────────────────────── */
.rl-assist__panel {
    position: absolute;
    display: flex;
    flex-direction: column;
    width: min(23rem, calc(100vw - 1.5rem));
    height: min(32rem, calc(100vh - 6rem));
    border: 1px solid var(--rl-border);
    border-radius: 18px;
    background: color-mix(in srgb, var(--rl-surface) 96%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 18px 48px rgba(12, 6, 32, .28), 0 0 0 1px rgba(168, 85, 247, .12);
    color: var(--rl-text);
    overflow: hidden;
    animation: rl-assist-in .22s var(--rl-ease, ease) both;
    cursor: auto;
    touch-action: auto;
}
.rl-assist[data-side="left"] .rl-assist__panel { right: calc(100% + 12px); }
.rl-assist[data-side="right"] .rl-assist__panel { left: calc(100% + 12px); }
.rl-assist[data-vert="up"] .rl-assist__panel { bottom: 0; }
.rl-assist[data-vert="down"] .rl-assist__panel { top: 0; }

.rl-assist__head {
    display: flex;
    align-items: center;
    gap: .25rem;
    padding: .6rem .6rem .55rem .9rem;
    border-bottom: 1px solid var(--rl-border);
    background: linear-gradient(120deg, rgba(124, 58, 237, .14), transparent 70%);
}
.rl-assist__title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rl-assist__title strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: .95rem; }
.rl-assist__title small { color: var(--rl-text-muted); font-size: .75rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.rl-assist__icon {
    flex: none;
    display: inline-grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--rl-text-muted);
    cursor: pointer;
}
.rl-assist__icon svg { width: 1.05rem; height: 1.05rem; fill: none; stroke: currentColor; stroke-width: 1.6; }
.rl-assist__icon:hover { background: var(--rl-surface-sunken); color: var(--rl-text); }
.rl-assist__icon.is-on { background: rgba(168, 85, 247, .18); color: #a855f7; }
.rl-assist__icon.is-off { color: var(--rl-danger); }
.rl-assist__icon.is-off svg { opacity: .55; }

.rl-assist__log {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    padding: .8rem .8rem .4rem;
    overscroll-behavior: contain;
}
.rl-assist__hint { color: var(--rl-text-muted); font-size: .85rem; margin: auto 0; text-align: center; padding: 0 1rem; }

.rl-assist__msg {
    max-width: 88%;
    padding: .5rem .7rem;
    border-radius: 14px;
    font-size: .88rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
}
.rl-assist__msg--me { align-self: flex-end; background: var(--rl-bubble-user); color: var(--rl-bubble-user-text); white-space: pre-wrap; border-bottom-right-radius: 4px; }
.rl-assist__msg--it { align-self: flex-start; background: var(--rl-surface-raised); border: 1px solid var(--rl-border); border-bottom-left-radius: 4px; }
.rl-assist__msg--it > :first-child { margin-top: 0; }
.rl-assist__msg--it > :last-child { margin-bottom: 0; }
.rl-assist__msg--it p { margin: 0 0 .5em; }
.rl-assist__msg--it pre { font-size: .78rem; max-height: 12rem; overflow: auto; }
.rl-assist__msg--it img { max-width: 100%; border-radius: 8px; }
.rl-assist__msg--live { border-color: rgba(168, 85, 247, .35); }

.rl-assist__run { display: flex; align-items: center; gap: .45rem; font-size: .78rem; color: var(--rl-text-muted); padding-left: .2rem; }
.rl-assist__dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--rl-text-muted); flex: none; }
.rl-assist__run--running .rl-assist__dot { background: #a855f7; animation: rl-assist-speak 1s ease-in-out infinite; }
.rl-assist__run--awaitingapproval .rl-assist__dot { background: #f59e0b; }
.rl-assist__run--succeeded .rl-assist__dot { background: var(--rl-ok); }
.rl-assist__run--failed .rl-assist__dot, .rl-assist__run--denied .rl-assist__dot { background: var(--rl-danger); }

.rl-assist__typing { display: inline-flex; gap: 4px; padding: .2rem 0; }
.rl-assist__typing i { width: 6px; height: 6px; border-radius: 50%; background: #a855f7; animation: rl-assist-dots 1.2s ease-in-out infinite; }
.rl-assist__typing i:nth-child(2) { animation-delay: .15s; }
.rl-assist__typing i:nth-child(3) { animation-delay: .3s; }
@keyframes rl-assist-dots { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.rl-assist__ask {
    border: 1px solid rgba(245, 158, 11, .55);
    background: rgba(245, 158, 11, .08);
    border-radius: 12px;
    padding: .55rem .7rem;
    font-size: .85rem;
}
.rl-assist__ask p { margin: 0 0 .35rem; }
.rl-assist__ask details { font-size: .75rem; color: var(--rl-text-muted); margin-bottom: .45rem; }
.rl-assist__ask pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 8rem; overflow: auto; margin: .3rem 0 0; }
.rl-assist__askRow { display: flex; gap: .4rem; }

.rl-assist__note { margin: 0; font-size: .8rem; color: var(--rl-danger); }

.rl-assist__compose {
    display: flex;
    align-items: flex-end;
    gap: .35rem;
    padding: .55rem .6rem .6rem;
    border-top: 1px solid var(--rl-border);
}
.rl-assist__compose textarea {
    flex: 1;
    min-height: 2.25rem;
    max-height: 7rem;
    resize: none;
    padding: .45rem .6rem;
    border: 1px solid var(--rl-border);
    border-radius: 12px;
    background: var(--rl-surface);
    color: var(--rl-text);
    font: inherit;
    font-size: .88rem;
    field-sizing: content;
}
.rl-assist__compose textarea:focus { outline: none; border-color: #a855f7; box-shadow: 0 0 0 3px rgba(168, 85, 247, .18); }
.rl-assist__send {
    flex: none;
    height: 2.25rem;
    padding: 0 .85rem;
    border: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    color: #fff;
    font-weight: 600;
    font-size: .85rem;
    cursor: pointer;
}
.rl-assist__send--stop { background: var(--rl-surface-sunken); color: var(--rl-text); border: 1px solid var(--rl-border); }

/* ── the right-click menu (built by js/assistant.js on <body>) ──────────────────────────────────────────────────── */
.rl-assist-menu {
    position: fixed;
    z-index: 1060;
    min-width: 13rem;
    padding: .3rem;
    border: 1px solid var(--rl-border);
    border-radius: 12px;
    background: color-mix(in srgb, var(--rl-surface) 97%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 12px 36px rgba(12, 6, 32, .3);
    color: var(--rl-text);
    font-size: .86rem;
    animation: rl-assist-in .14s ease-out both;
}
.rl-assist-menu__item {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    padding: .38rem .6rem .38rem .35rem;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    text-align: left;
    cursor: pointer;
}
.rl-assist-menu__item:hover:not(:disabled), .rl-assist-menu__item:focus-visible { background: rgba(168, 85, 247, .14); outline: none; }
.rl-assist-menu__item:disabled { opacity: .45; cursor: default; }
.rl-assist-menu__item.is-danger { color: var(--rl-danger); }
.rl-assist-menu__item kbd { margin-left: auto; padding: 0 .3rem; font-size: .68rem; color: var(--rl-text-muted); background: transparent; border: 1px solid var(--rl-border); border-radius: 4px; }
.rl-assist-menu__tick { width: 1rem; text-align: center; color: #a855f7; font-weight: 700; }
.rl-assist-menu__sep { height: 1px; margin: .3rem .4rem; background: var(--rl-border); }

/* ── small screens: the panel takes the bottom of the screen ──────────────────────────────────────────────── */
@media (max-width: 560px) {
    .rl-assist__panel {
        position: fixed;
        left: .5rem !important;
        right: .5rem !important;
        top: auto !important;
        bottom: .5rem !important;
        width: auto;
        height: min(30rem, calc(100vh - 5rem));
    }
}

@media (prefers-reduced-motion: reduce) {
    .rl-assist, .rl-assist__orb { animation: none; transition: none; }
    .rl-assist__eclipse .eclipse__sun { animation-duration: 30s; }
    .rl-assist__eclipse .eclipse__corona, .rl-assist__ring, .rl-assist__typing i { animation: none; }
    .rl-assist[data-state="listening"] .rl-assist__ring, .rl-assist[data-state="ask"] .rl-assist__ring { opacity: 1; }
}

@media print { .rl-assist, .rl-assist-menu { display: none !important; } }
