/* Scroll reveal (js/ui/motion.js): rows dissolve at a scroller's edges. Mirrored in
   browser-extension/src/lib/animations/ and desktop/src/support/motion/scrollReveal.hpp. */
@property --dissolve { syntax: "<number>"; inherits: false; initial-value: 0; }

.reveal-item {
    /* 0 = assembled, 1 = dissolved; registered so it can be TRANSITIONED. */
    --dissolve: 1;
    /* The feather motion.js revealFeather zeroes on the end the scroller is NOT clipping. */
    --fade-in: 10%;
    --fade-out: 10%;
    transform: none;
    /* Short while scrolling, so the dissolve tracks the scrollbar; a first ramp (.reveal-entering) is long. */
    transition: --dissolve 0.14s linear, transform 0.14s linear;
}
.reveal-item.reveal-in { --dissolve: 0; transform: none; }
/* Mounted only on a row straddling an edge: four gradient layers on every row made a transcript stutter. */
.reveal-item.reveal-masked {
    /* Union of three coprime dot grains (4/7/11px, dying at 80/95/110 so they thin in sequence, not a
       lattice) and a bottom→top wipe; intersect would punch holes in a settled row. */
    -webkit-mask-image:
        radial-gradient(circle at 50% 50%, #000 max(0%, calc(78% - var(--dissolve) * 78%)),
                        transparent max(0%, calc(84% - var(--dissolve) * 78%))),
        radial-gradient(circle at 50% 50%, #000 max(0%, calc(74% - var(--dissolve) * 95%)),
                        transparent max(0%, calc(80% - var(--dissolve) * 95%))),
        radial-gradient(circle at 50% 50%, #000 max(0%, calc(70% - var(--dissolve) * 110%)),
                        transparent max(0%, calc(76% - var(--dissolve) * 110%))),
        linear-gradient(to bottom, transparent 0, transparent var(--vis-start, 0%),
                        #000 calc(var(--vis-start, 0%) + var(--fade-in, 10%)),
                        #000 calc(var(--vis-end, 100%) - var(--fade-out, 10%)),
                        transparent var(--vis-end, 100%), transparent 100%);
    mask-image:
        radial-gradient(circle at 50% 50%, #000 max(0%, calc(78% - var(--dissolve) * 78%)),
                        transparent max(0%, calc(84% - var(--dissolve) * 78%))),
        radial-gradient(circle at 50% 50%, #000 max(0%, calc(74% - var(--dissolve) * 95%)),
                        transparent max(0%, calc(80% - var(--dissolve) * 95%))),
        radial-gradient(circle at 50% 50%, #000 max(0%, calc(70% - var(--dissolve) * 110%)),
                        transparent max(0%, calc(76% - var(--dissolve) * 110%))),
        linear-gradient(to bottom, transparent 0, transparent var(--vis-start, 0%),
                        #000 calc(var(--vis-start, 0%) + var(--fade-in, 10%)),
                        #000 calc(var(--vis-end, 100%) - var(--fade-out, 10%)),
                        transparent var(--vis-end, 100%), transparent 100%);
    /* 3× the width, centred: the "…" trigger beside the bubble must not be masked away (and its hit-testing). */
    -webkit-mask-size: 4px 4px, 7px 7px, 11px 11px, 300% 100%;
    mask-size: 4px 4px, 7px 7px, 11px 11px, 300% 100%;
    -webkit-mask-position: 0 0, 2px 3px, 5px 1px, center top;
    mask-position: 0 0, 2px 3px, 5px 1px, center top;
    -webkit-mask-repeat: repeat, repeat, repeat, no-repeat;
    mask-repeat: repeat, repeat, repeat, no-repeat;
    -webkit-mask-composite: source-over;   /* legacy spelling of "union" */
    mask-composite: add;
    /* No mask clip to the box, or the "…" beside the bubble is cut away, un-clickable. */
    -webkit-mask-clip: no-clip;
    mask-clip: no-clip;
}
/* Text rows (motion.js `smooth`) take the wipe alone: the grain ate letters (user report). The band is
   fixed (motion.js REVEAL_SMOOTH_FEATHER). */
.reveal-item.reveal-smooth { --fade-in: 12px; --fade-out: 12px; }
.reveal-item.reveal-smooth.reveal-masked {
    -webkit-mask-image:
        linear-gradient(to bottom, transparent 0, transparent var(--vis-start, 0%),
                        #000 calc(var(--vis-start, 0%) + var(--fade-in, 12px)),
                        #000 calc(var(--vis-end, 100%) - var(--fade-out, 12px)),
                        transparent var(--vis-end, 100%), transparent 100%);
    mask-image:
        linear-gradient(to bottom, transparent 0, transparent var(--vis-start, 0%),
                        #000 calc(var(--vis-start, 0%) + var(--fade-in, 12px)),
                        #000 calc(var(--vis-end, 100%) - var(--fade-out, 12px)),
                        transparent var(--vis-end, 100%), transparent 100%);
    -webkit-mask-size: 300% 100%;
    mask-size: 300% 100%;
    -webkit-mask-position: center top;
    mask-position: center top;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-clip: no-clip;
    mask-clip: no-clip;
}
.reveal-item.reveal-entering {
    transition: --dissolve 0.7s ease, transform 0.55s cubic-bezier(0.16, 1, 0.3, 1);
}
@media (prefers-reduced-motion: reduce) {
    /* A half-dissolved row is a surprise, not motion. */
    .reveal-item { --dissolve: 0 !important; transform: none !important;
                   -webkit-mask-image: none !important; mask-image: none !important; }
}

/* Leaving (motion.js leaveThenRemove): --leave-h is the measured height; `height: auto` cannot animate. */
.leaving {
    pointer-events: none;
    overflow: hidden;
    animation: rowLeave 0.22s cubic-bezier(0.4, 0, 1, 1) both;
}
@keyframes rowLeave {
    from { opacity: 1; transform: none; max-height: var(--leave-h, 200px); }
    60%  { opacity: 0; transform: translateX(-14px) scale(0.97); max-height: var(--leave-h, 200px); }
    to   { opacity: 0; transform: translateX(-14px) scale(0.97);
           max-height: 0; margin-top: 0; margin-bottom: 0; padding-top: 0; padding-bottom: 0; border-width: 0; }
}
/* Sliding and Transition (enterLeave.js MODE_ROW_MS): the row slides out its side or shrinks away, then
   its space closes. :where() keeps the list rule's weight, so a chat entry, chip or table row keeps its own. */
:where(:root[data-motion="slide"]) .leaving { animation: rowSlideLeave 0.34s cubic-bezier(0.55, 0, 0.75, 0.4) both; }
:where(:root[data-motion="transition"]) .leaving { animation: rowShrinkLeave 0.34s cubic-bezier(0.4, 0, 0.6, 1) both; }
/* …or, held (enterLeave.js LEAVE_HOLD_CLASS), the slot stays for the row that takes it over: every mode's
   own exit without the collapse. */
.leaving.leave-hold { animation-name: rowLeaveHold; }
@keyframes rowLeaveHold {
    from { opacity: 1; transform: none; }
    60%  { opacity: 0; transform: translateX(-14px) scale(0.97); }
    to   { opacity: 0; transform: translateX(-14px) scale(0.97); }
}
:where(:root[data-motion="slide"]) .leaving.leave-hold { animation-name: rowSlideAway; }
:where(:root[data-motion="transition"]) .leaving.leave-hold { animation-name: rowShrinkAway; }
@keyframes rowSlideAway { from { transform: none; } 70% { opacity: 1; } to { opacity: 0; transform: translateX(-104%); } }
@keyframes rowShrinkAway { from { opacity: 1; transform: none; } to { opacity: 0; transform: scale(0.78); } }
@keyframes rowSlideLeave {
    from { transform: none; max-height: var(--leave-h, 200px); }
    55%  { opacity: 1; transform: translateX(-104%); max-height: var(--leave-h, 200px); }
    to   { opacity: 0; transform: translateX(-104%);
           max-height: 0; margin-top: 0; margin-bottom: 0; padding-top: 0; padding-bottom: 0; border-width: 0; }
}
@keyframes rowShrinkLeave {
    from { opacity: 1; transform: none; max-height: var(--leave-h, 200px); }
    55%  { opacity: 0; transform: scale(0.78); max-height: var(--leave-h, 200px); }
    to   { opacity: 0; transform: scale(0.78);
           max-height: 0; margin-top: 0; margin-bottom: 0; padding-top: 0; padding-bottom: 0; border-width: 0; }
}
/* A flex column's gap fights a height collapse and a <tr> ignores max-height: those dissolve in place. */
.chat-transcript > .leaving, .chat-results.leaving,
.coordinates-table tbody tr.leaving {
    animation: cardLeave 0.22s ease both;
}
@keyframes cardLeave {
    from { opacity: 1; transform: none; }
    to   { opacity: 0; transform: translateY(-6px) scale(0.97); }
}
/* A chat entry melts (motion.js CHAT_LEAVE_MS): opacity + transform only — a blur beside the particles jank. */
.chat-transcript > .leaving, .ctx-assist-transcript > .leaving,
.chat-results.leaving, .chat-attached.leaving {
    animation: chatCardLeave 0.26s cubic-bezier(0.33, 0, 0.2, 1) both;
    will-change: opacity, transform;
}
@keyframes chatCardLeave {
    from { opacity: 1; transform: none; }
    to   { opacity: 0; transform: translateY(-8px) scale(0.95); }
}
/* …and arrives backwards (motion.js chatIn): a VEIL keeps its height but never shows it ahead of its own
   dust. !important so the row and reveal rules cannot out-rank it. */
.chat-transcript > .chat-entering, .ctx-assist-transcript > .chat-entering,
.chat-results.chat-entering, .chat-attached.chat-entering {
    opacity: 0 !important;
    /* The dust is a photograph of where the entry is: nothing moves under it. */
    animation: none !important;
    transition: none !important;
    pointer-events: none;
}
/* A chip also collapses its width (--leave-w); the negative margin swallows the gap it owned. */
.chat-attach-chip.leaving {
    animation: chipLeave 0.42s cubic-bezier(0.33, 0, 0.2, 1) both;
    will-change: opacity, transform;
}
@keyframes chipLeave {
    from { opacity: 1; transform: none; max-width: var(--leave-w, 240px); }
    30%  { opacity: 0; transform: translateY(-8px) scale(0.95); }
    38%  { opacity: 0; transform: translateY(-8px) scale(0.95); max-width: var(--leave-w, 240px); }
    to   { opacity: 0; transform: translateY(-8px) scale(0.95); max-width: 0;
           padding-left: 0; padding-right: 0; border-left-width: 0; border-right-width: 0;
           margin-right: calc(0px - var(--chip-gap, 6px)); }
}

