/*
    Smart Signals navigator (Components/Shared/SmartSignals/SmartSignalNavigator.razor + js/smart-signal-navigator.js):
    the track under every Smart Signals rail, the web twin of the mobile SmartSignalNavigatorView. Global so it can read
    the tokens of the rail it sits in by inheritance: the Dashboard rails' --ss-* (HomeSmartSignals.razor.css) and the
    Recurring rail's --rc-* (recurring-area.css). Each marker carries its card's own color as --sn-ink, so the dot is the
    color the card reads as. Light and dark; reduced motion keeps it still.
*/
.sn {
    --sn-line: #E4E9F1;
    --sn-core: #FFFFFF;
    --sn-badge-bg: rgba(58, 66, 86, .9);
    --sn-badge-text: #F8FAFC;
    --sn-tip-bg: rgba(15, 23, 42, .94);
    --sn-tip-text: #F8FAFC;
    --sn-new: var(--ss-primary, var(--tx-primary, #5A45E6));
    --sn-card: var(--ss-card-spend, #EF4444);
    --sn-investment: var(--ss-investment, #16A34A);
    --sn-budget: var(--ss-budget, #C026D3);
    --sn-muted: var(--ss-muted, var(--rc-muted, #64748B));
    --sn-text: var(--ss-text, var(--rc-text, #0F172A));
    --sn-live: var(--ss-live, #0284C7);
    --sn-critical: var(--ss-critical, var(--rc-sig-critical-ink, #FF392B));
    --sn-caution: var(--ss-caution, var(--rc-sig-warning-ink, #B45309));
    --sn-positive: var(--ss-positive, var(--rc-sig-positive-ink, #16A34A));
    --sn-head: var(--sn-new);
    --sn-run: var(--sn-muted);
    position: relative;
    margin-top: .35rem;
    user-select: none;
    -webkit-user-select: none;
}

[data-bs-theme="dark"] .sn {
    --sn-line: rgba(255, 255, 255, .08);
    --sn-core: #F1F5F9;
    --sn-badge-bg: rgba(42, 48, 71, .95);
    --sn-badge-text: #E8EAF2;
    --sn-tip-bg: rgba(20, 24, 38, .96);
    --sn-tip-text: #E8EAF2;
    --sn-live: var(--ss-live, #38BDF8);
    --sn-text: var(--ss-text, var(--rc-text, #E6E9EF));
}

/* ---- The track: one slot per card; the marker sits at its slot's center. The markers sit 3px below the track's
   center so the count badges above them have room (the mobile fix for the clipped badge). Kept short and quiet, like
   mobile: a hairline with small dots, so the cards above stay the focus. */
.sn-track {
    position: relative;
    height: 20px;
    margin: 0 4px;
    touch-action: pan-y;
    cursor: pointer;
    --sn-y: calc(50% + 2px);
}

.sn[data-scrubbing="true"] .sn-track { cursor: grabbing; }

.sn-line {
    position: absolute;
    left: 6px;
    right: 6px;
    top: var(--sn-y);
    height: 1px;
    margin-top: -.5px;
    border-radius: 1px;
    background: var(--sn-line);
}

.sn-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* A run: a soft band under its markers in the run's hue (the rest quieter). */
.sn-band {
    position: absolute;
    top: var(--sn-y);
    left: calc(var(--s) / var(--sn-n) * 100% + 3px);
    width: max(8px, calc(var(--c) / var(--sn-n) * 100% - 6px));
    height: 3px;
    margin-top: -1.5px;
    border-radius: 2px;
    background: color-mix(in srgb, var(--sn-band) 14%, transparent);
    animation: sn-band-in .5s cubic-bezier(.22, 1, .36, 1) backwards;
}

.sn-band-quiet {
    background: color-mix(in srgb, var(--sn-band) 7%, transparent);
}

/* Where the rail draws a divider: a short rule, in the live hue with a dot on top around the live alerts. */
.sn-rule {
    position: absolute;
    top: var(--sn-y);
    left: calc(var(--at) / var(--sn-n) * 100%);
    width: 1px;
    height: 8px;
    margin: -4px 0 0 -.5px;
    border-radius: 2px;
    background: var(--sn-line);
}

.sn-rule-live {
    width: 1px;
    margin-left: -.5px;
    background: color-mix(in srgb, var(--sn-live) 55%, transparent);
}

.sn-rule-live::before {
    content: "";
    position: absolute;
    left: 50%;
    top: -3px;
    width: 3px;
    height: 3px;
    margin-left: -1.5px;
    border-radius: 50%;
    background: var(--sn-live);
}

/* A run's count on a small pill at its first marker's upper right (the Bills runway's badge), outlined in the run's hue. */
.sn-count {
    position: absolute;
    top: calc(var(--sn-y) - 13px);
    left: calc((var(--s) + .5) / var(--sn-n) * 100% + 3px);
    min-width: 12px;
    height: 10px;
    padding: 0 3px;
    border-radius: 5px;
    background: color-mix(in srgb, var(--sn-band) 12%, transparent);
    color: var(--sn-band);
    font-size: 7px;
    font-weight: 700;
    line-height: 10px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    animation: sn-pop .42s cubic-bezier(.34, 1.56, .64, 1) .2s backwards;
}

/* ---- The markers: a button per slot (the whole slot is the hit area); a small solid dot drawn by ::before in the card's ink
   (no ring, like mobile). Dashboard-rail cards lift their accent toward white in dark (--ss-ink). */
.sn-dots {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: repeat(var(--sn-n), minmax(0, 1fr));
}

.sn-dot {
    --sn-dot: var(--sn-ink);
    --sn-r: 4px;
    position: relative;
    display: block;
    min-width: 0;
    height: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--sn-dot);
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

[data-bs-theme="dark"] .sn-dot[data-lift] {
    --sn-dot: color-mix(in srgb, var(--sn-ink) 74%, #FFFFFF);
}

.sn-dot::before {
    content: "";
    position: absolute;
    left: 50%;
    top: var(--sn-y);
    width: var(--sn-r);
    height: var(--sn-r);
    margin: calc(var(--sn-r) / -2) 0 0 calc(var(--sn-r) / -2);
    border-radius: 50%;
    background: var(--sn-dot);
    transition: transform .22s cubic-bezier(.34, 1.56, .64, 1), box-shadow .2s ease;
    animation: sn-pop .46s cubic-bezier(.34, 1.56, .64, 1) backwards;
    animation-delay: calc(min(var(--i), 18) * 26ms);
}

.sn-dot-critical { --sn-r: 5px; }

.sn-dot-critical::before {
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--sn-dot) 16%, transparent);
}

/* Under the pointer the marker swells and its neighbours lean in (a dock). */
@media (hover: hover) {
    .sn-dot:hover::before { transform: scale(1.5); }
    .sn-dot:hover + .sn-dot::before,
    .sn-dot:has(+ .sn-dot:hover)::before { transform: scale(1.2); }
}

.sn-dot:focus-visible::before {
    box-shadow: 0 0 0 2.5px color-mix(in srgb, var(--sn-dot) 40%, transparent);
}

/* The hover preview: the card's title in a small tip above its marker, with the card's color as a swatch. */
.sn-dot::after {
    content: attr(data-tip);
    position: absolute;
    left: 50%;
    bottom: calc(100% - 2px);
    max-width: 220px;
    padding: 5px 9px 5px 20px;
    border-radius: 8px;
    background:
        radial-gradient(circle at 10px 50%, var(--sn-dot) 0 3.5px, transparent 4px),
        var(--sn-tip-bg);
    color: var(--sn-tip-text);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .22);
    opacity: 0;
    transform: translate(-50%, 4px) scale(.96);
    transform-origin: 50% 100%;
    transition: opacity .14s ease, transform .18s cubic-bezier(.22, 1, .36, 1);
    pointer-events: none;
    z-index: 5;
}

.sn-dot[data-edge="start"]::after { left: 0; transform: translate(0, 4px) scale(.96); transform-origin: 0 100%; }
.sn-dot[data-edge="end"]::after { left: auto; right: 0; transform: translate(0, 4px) scale(.96); transform-origin: 100% 100%; }

@media (hover: hover) {
    .sn-dot:hover::after,
    .sn-dot:focus-visible::after {
        opacity: 1;
        transform: translate(-50%, 0) scale(1);
        transition-delay: .12s;
    }

    .sn-dot[data-edge="start"]:hover::after,
    .sn-dot[data-edge="start"]:focus-visible::after,
    .sn-dot[data-edge="end"]:hover::after,
    .sn-dot[data-edge="end"]:focus-visible::after { transform: translate(0, 0) scale(1); }
}

.sn[data-scrubbing="true"] .sn-dot::after { opacity: 0; }

/* ---- The playhead: a glow, a ring in the current card's color and a light core, gliding on the script's spring and
   stretching with its speed. Hidden until the script has placed it. */
.sn-head {
    --sn-stretch: 1;
    position: absolute;
    top: var(--sn-y);
    left: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 1.5px solid var(--sn-head);
    background: radial-gradient(circle, var(--sn-head) 0 1.2px, var(--sn-core) 1.6px);
    box-shadow: 0 0 0 2.5px color-mix(in srgb, var(--sn-head) 14%, transparent);
    transform: translate(-50%, -50%) scaleX(var(--sn-stretch));
    pointer-events: none;
    opacity: 0;
    transition: opacity .25s ease, border-color .25s ease, box-shadow .25s ease, background .25s ease;
    z-index: 2;
}

.sn[data-nav-ready] .sn-head { opacity: 1; }

.sn[data-scrubbing="true"] .sn-head {
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--sn-head) 16%, transparent);
}

/* ---- The caption: the run (glyph, label in its hue, "2 of 3") at the left, the feed's headline at the right. */
.sn-caption {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    min-height: 16px;
    margin: 0 10px;
    font-size: .6875rem;
    line-height: 1.2;
}

.sn-cap-run {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    min-width: 0;
    color: var(--sn-muted);
    opacity: 0;
    transition: opacity .2s ease;
}

.sn[data-nav-ready] .sn-cap-run { opacity: 1; }

.sn-caption[data-swap="true"] .sn-cap-run { animation: sn-swap .26s ease; }

.sn-cap-glyph {
    color: var(--sn-run);
    font-size: .5625rem;
}

.sn-cap-label {
    color: var(--sn-run);
    font-weight: 700;
    letter-spacing: .08em;
    font-size: .625rem;
    white-space: nowrap;
}

.sn-cap-detail {
    color: var(--sn-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.sn-headline {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    flex-shrink: 0;
    margin-left: auto;
    font-size: .75rem;
    font-weight: 600;
    color: var(--sn-muted);
    white-space: nowrap;
}

.sn-headline-glyph { font-size: .625rem; }

.sn-urgency-critical { color: var(--sn-critical); }
.sn-urgency-caution { color: var(--sn-caution); }
.sn-urgency-positive .sn-headline-glyph { color: var(--sn-positive); }

.sn-headline-text { display: inline-flex; }

.sn-ch { display: inline-block; }

/* The attention wave (the mobile SmartSignalsHeadlineView, toned down): the glyph pulses, then each letter swells to
   1.16x and back in turn, then it rests; about every 6s while an attention line is shown. */
.sn-urgency-critical .sn-ch,
.sn-urgency-caution .sn-ch {
    animation: sn-wave 6s ease-in-out infinite;
    animation-delay: calc(.35s + var(--c) * 38ms);
}

.sn-urgency-critical .sn-headline-glyph,
.sn-urgency-caution .sn-headline-glyph {
    animation: sn-glyph 6s ease-in-out infinite;
}

/* ---- Keyframes */
@keyframes sn-pop {
    from { transform: scale(0); opacity: 0; }
}

@keyframes sn-band-in {
    from { transform: scaleX(0); transform-origin: 0 50%; opacity: 0; }
}

@keyframes sn-swap {
    0% { opacity: 1; transform: none; }
    35% { opacity: 0; transform: translateY(2px); }
    36% { opacity: 0; transform: translateY(-2px); }
    100% { opacity: 1; transform: none; }
}

@keyframes sn-wave {
    0%, 4.5%, 100% { transform: none; }
    1.8% { transform: scale(1.16) translateY(-.5px); }
}

@keyframes sn-glyph {
    0%, 5%, 100% { transform: none; }
    2.2% { transform: scale(1.2); }
}

@media (prefers-reduced-motion: reduce) {
    .sn-dot::before,
    .sn-band,
    .sn-count,
    .sn-ch,
    .sn-headline-glyph,
    .sn-caption[data-swap="true"] .sn-cap-run { animation: none !important; }

    .sn-dot::before,
    .sn-dot::after,
    .sn-head { transition: none; }
}

/* ---- The loading navigator under a skeleton rail: a track line and the headline's place, shimmering with the cards
   (the bones' shimmer comes from .dsh-bone). */
.sn-bones {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: .6rem 10px .1rem;
}

.sn-bone-track { flex: 1 1 auto; height: 3px; border-radius: 2px; }
.sn-bone-headline { flex: 0 0 auto; width: min(150px, 34vw); height: 10px; border-radius: 5px; }

/* Narrow screens: a little less air around the caption. */
@media (max-width: 575.98px) {
    .sn-caption { margin: 0 6px; }
    .sn-headline { font-size: .6875rem; }
}
