/* MwSwitchGroup — single-select segmented button group in the edge-glow theme language.
   Prefix: mw-sg-*
   Requires: MudBlazor CSS variables for theme-aware colors.

   Recipe & invariants: docs/plans/mitware-theme/edge-glow-and-tail-corner.md
   Design iteration:    docs/mockups/edge-glow-switch.html (★ Finale Richtung)
   Production ancestor: mw-chat.css (.mw-chat-msg-bubble, 4-layer background)

   Structure (rendered by MwSwitchGroup.razor):
     .mw-sg                 container — island strip, tail corner top-left (14px : 4px)
       .mw-sg-thumb         glow carrier — geometry + rail color set inline by mw-switch-group.ts
       .mw-sg-btn           one per option; .mw-sg-btn--on = selected, .mw-sg-btn--railed = has own rail

   Modifiers: .mw-sg--h / .mw-sg--v (orientation) · .mw-sg--handoff (crossfade animation,
   thumb hidden) · .mw-sg--embedded (inside an MwInputComposer strip). */

/* NOTE: Registered so the thumb's rail can color-morph mid-flight (Glide + per-option rails). */
@property --mw-sg-rail {
    syntax: '<color>';
    inherits: true;
    initial-value: transparent;
}

/* NOTE: Container — island strip. The tail corner (4px against 14px) points at the group's
   origin top-left; with --mw-sg-rail unset everything degrades to plain hairlines. */
.mw-sg {
    --mw-sg-rail: transparent;
    --mw-sg-hairline: color-mix(in srgb, var(--mud-palette-lines-default) 55%, transparent);
    --mw-sg-hairline-strong: var(--mud-palette-lines-default);
    position: relative;
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    background: var(--mud-palette-surface);
    border: 1px solid var(--mw-sg-hairline);
    border-radius: 14px;
    border-top-left-radius: 4px;
}

.mw-sg--v {
    flex-direction: column;
    min-width: 156px;
}

/* NOTE: Option buttons — flat chips above the thumb (z-index 1 vs 0). */
.mw-sg-btn {
    position: relative;
    z-index: 1;
    appearance: none;
    border: 0;
    background: transparent;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.45;
    color: var(--mud-palette-text-secondary);
    padding: 6px 15px;
    border-radius: 12px;
    border-top-left-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.28s ease;
}

.mw-sg--v .mw-sg-btn {
    text-align: left;
    padding: 8px 15px;
}

.mw-sg-btn:hover { color: var(--mud-palette-text-primary); }

.mw-sg-btn:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--mw-sg-btn-rail, var(--mw-sg-rail)) 60%, var(--mw-sg-hairline-strong));
    outline-offset: -2px;
}

.mw-sg-btn--on { color: var(--mud-palette-text-primary); }

/* Options carrying their own rail tint their active label toward the category color. */
.mw-sg-btn--railed.mw-sg-btn--on {
    color: color-mix(in srgb, var(--mw-sg-btn-rail) 55%, var(--mud-palette-text-primary));
}

/* NOTE: The thumb — the glow carrier, 4-layer recipe from mw-chat.css:
   ① fill with the ≤7% category wash (padding-box),
   ② corner-anchored radial glow, anchored bottom-left = diagonal to the tail corner (border-box),
   ③ hairline base wherever the glow has faded (border-box),
   ④ bloom as a whisper off the glowing corner (offset toward it, never upward).
   The top edge never glows. Geometry (left/top/width/height) and a per-option --mw-sg-rail are
   set inline by mw-switch-group.ts — no rules here may set those. */
.mw-sg-thumb {
    position: absolute;
    z-index: 0;
    pointer-events: none;
    border-radius: 12px;
    border-top-left-radius: 4px;
    border: 1.5px solid transparent;
    background:
        linear-gradient(
            color-mix(in srgb, var(--mw-sg-rail) 7%, var(--mud-palette-surface)),
            color-mix(in srgb, var(--mw-sg-rail) 7%, var(--mud-palette-surface))) padding-box,
        radial-gradient(135% 125% at 0% 100%,
            color-mix(in srgb, var(--mw-sg-rail) 80%, transparent) 0%,
            color-mix(in srgb, var(--mw-sg-rail) 45%, transparent) 40%,
            transparent 72%) border-box,
        linear-gradient(var(--mw-sg-hairline-strong), var(--mw-sg-hairline-strong)) border-box;
    box-shadow: -3px 2px 9px -8px color-mix(in srgb, var(--mw-sg-rail) 65%, transparent);
}

/* Transitions arm only after the JS module committed the first layout (double rAF),
   so the thumb never flies in from (0,0) on mount. */
.mw-sg-thumb--ready {
    transition:
        left 0.34s cubic-bezier(0.3, 0.7, 0.2, 1.02),
        top 0.34s cubic-bezier(0.3, 0.7, 0.2, 1.02),
        width 0.34s cubic-bezier(0.3, 0.7, 0.2, 1.02),
        height 0.34s cubic-bezier(0.3, 0.7, 0.2, 1.02),
        --mw-sg-rail 0.34s ease;
}

/* NOTE: Handoff animation — no moving part. The thumb is hidden; each option renders its own
   indicator (masked 1.5px glow ring + wash) that crossfades via opacity. */
.mw-sg--handoff .mw-sg-thumb { display: none; }

.mw-sg--handoff .mw-sg-btn {
    transition: color 0.3s ease, background-color 0.38s ease, box-shadow 0.38s ease;
}

.mw-sg--handoff .mw-sg-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1.5px;
    background:
        radial-gradient(135% 125% at 0% 100%,
            color-mix(in srgb, var(--mw-sg-btn-rail, var(--mw-sg-rail)) 80%, transparent) 0%,
            color-mix(in srgb, var(--mw-sg-btn-rail, var(--mw-sg-rail)) 45%, transparent) 40%,
            transparent 72%),
        linear-gradient(var(--mw-sg-hairline-strong), var(--mw-sg-hairline-strong));
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask-composite: exclude;
    opacity: 0;
    transition: opacity 0.38s ease;
    pointer-events: none;
}

.mw-sg--handoff .mw-sg-btn--on {
    background-color: color-mix(in srgb, var(--mw-sg-btn-rail, var(--mw-sg-rail)) 7%, transparent);
    box-shadow: -3px 2px 9px -8px color-mix(in srgb, var(--mw-sg-btn-rail, var(--mw-sg-rail)) 65%, transparent);
}

.mw-sg--handoff .mw-sg-btn--on::before { opacity: 1; }

/* NOTE: Embedded in an MwInputComposer strip — the component flattens ITSELF (the composer stays
   ignorant of it): tail corners dropped (a tail corner inside a merged strip would violate the
   one-tail-corner read), stretches to the strip height, hairline matches the inputs' border. */
.mw-sg--embedded {
    height: 100%;
    align-items: stretch;
    padding: 3px;
    background: transparent;
    border-color: var(--mud-palette-lines-inputs);
    border-radius: var(--mud-default-borderradius);
}

.mw-sg--embedded .mw-sg-btn,
.mw-sg--embedded .mw-sg-thumb {
    border-radius: calc(var(--mud-default-borderradius) - 2px);
}

@media (prefers-reduced-motion: reduce) {
    .mw-sg-thumb--ready,
    .mw-sg--handoff .mw-sg-btn,
    .mw-sg--handoff .mw-sg-btn::before { transition-duration: 0.01ms !important; }
}
