/* ============================================================================
   Multi-Arch Release — Tree-View Sidebar
   ============================================================================
   Slide-in panel from the right covering ~46% of viewport width (min 540px,
   max 760px). Pipeline tree shows Stage → Phase → Component → individual
   jobs, each level a collapsible row. Failure branches default-expanded so
   the user lands on the things that need attention.
   ========================================================================= */
.mar-tree-sidebar {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    justify-content: flex-end;
}
.mar-tree-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    animation: mar-tree-fade-in 0.18s ease;
}
.mar-tree-panel {
    position: relative;
    width: 46vw;
    min-width: 540px;
    max-width: 760px;
    height: 100vh;
    background: var(--card-bg);
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    animation: mar-tree-slide-in 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes mar-tree-slide-in {
    from { transform: translateX(100%); }
    to   { transform: translateX(0); }
}
@keyframes mar-tree-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.mar-tree-header {
    flex: 0 0 auto;
    padding: 14px 18px 10px 18px;
    border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    /* SOLID background — `--bg-elevated` is only ~2% white in dark theme,
       so the scrolling body content was bleeding through the header.
       Layer a solid card-bg underneath a faint white tint for the
       "elevated" feel without losing opacity. */
    background-color: var(--card-bg);
    background-image: linear-gradient(rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.04));
    /* Defense-in-depth positioning. The flex layout already pins the
       header at the top of the panel (header has flex:0, body has flex:1
       + overflow:auto), but `position:sticky; top:0` adds a second line
       of defense: even if some upstream change inadvertently lets the
       panel itself become the scroll container (instead of just
       .mar-tree-body), the header stays glued to the top of the visible
       area instead of scrolling away and reappearing mid-content.
       z-index:5 protects against any descendant accidentally creating a
       higher stacking context. */
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 5;
    /* Subtle drop-shadow under the header so users see the visual
       separation between the (sticky) header and scrolling content. */
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: flex-start;
    gap: 12px;
}
.mar-tree-titles { flex: 1 1 auto; min-width: 0; }
.mar-tree-titles h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mar-tree-titles h3 #mar-tree-version {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    color: var(--primary-light, #818cf8);
}
.mar-tree-meta {
    margin-top: 4px;
    font-size: 0.74rem;
    color: var(--text-muted, #888);
    line-height: 1.4;
}
.mar-tree-meta a {
    color: var(--primary-light, #818cf8);
    text-decoration: none;
}
.mar-tree-meta a:hover { text-decoration: underline; }
.mar-tree-toolbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.mar-tree-toolbtn {
    background: transparent;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    color: var(--text-secondary, #aaa);
    padding: 4px 9px;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.mar-tree-toolbtn:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.4);
    color: var(--primary-light, #818cf8);
}
.mar-tree-toolbtn.is-active {
    background: rgba(99, 102, 241, 0.18);
    border-color: rgba(99, 102, 241, 0.6);
    color: #fff;
}
.mar-tree-toolbtn-icon { margin-right: 4px; }
.mar-tree-close {
    background: transparent;
    border: none;
    color: var(--text-muted, #888);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 2px 8px;
    transition: color 0.12s;
}
.mar-tree-close:hover { color: var(--status-fail, #ef4444); }

.mar-tree-body {
    flex: 1 1 auto;
    /* CRITICAL: without min-height:0, a flex item's default min-height:auto
       prevents shrinking below its content size — so overflow:auto never
       kicks in and the body GROWS to fit content, pushing the header
       offscreen visually (or letting body content render OVER the header
       in some browsers). Setting min-height:0 lets the body shrink to its
       allotted flex space and triggers proper internal scrolling. */
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
    font-size: 0.8rem;
    line-height: 1.4;
    /* Independent stacking context below the header (which is z-index:2).
       Defends against any descendant accidentally elevating above the
       header through a transform/will-change/etc. side effect. */
    position: relative;
    z-index: 1;
}
.mar-tree-panel {
    /* Defense in depth — even if the body's overflow somehow misbehaves,
       the panel itself clips its children at its 100vh box. */
    overflow: hidden;
}
.mar-tree-loading,
.mar-tree-empty,
.mar-tree-error {
    padding: 32px 18px;
    text-align: center;
    color: var(--text-muted, #888);
}
.mar-tree-error { color: var(--status-fail, #ef4444); }

/* Tree rows. Each level is indented +16px from parent. The row contains:
   chevron (▸/▾, hidden for leaves) + status icon + label + secondary text. */
.mar-tree-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 14px 4px 6px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background 0.1s ease;
    user-select: none;
}
.mar-tree-row:hover {
    background: rgba(99, 102, 241, 0.07);
    border-left-color: rgba(99, 102, 241, 0.5);
}
.mar-tree-row.is-leaf { cursor: default; }
.mar-tree-row.is-leaf:hover { background: transparent; }
.mar-tree-row.is-leaf a:hover ~ * { /* placeholder for future selectors */ }

/* A FAILED leaf is a "failure button" — clicking it opens the AI
   investigation modal (same as CI Nightly's FAIL badges). Restore the
   pointer cursor + give a red-tinted hover so the affordance reads as
   clickable, distinct from the inert green/skipped leaves. */
.mar-tree-row.is-leaf.mar-tree-leaf-fail-click { cursor: pointer; }
.mar-tree-row.is-leaf.mar-tree-leaf-fail-click:hover {
    background: rgba(239, 68, 68, 0.10);
    border-left-color: rgba(239, 68, 68, 0.6);
}
[data-theme="light"] .mar-tree-row.is-leaf.mar-tree-leaf-fail-click:hover {
    background: rgba(239, 68, 68, 0.10);
}

/* Tree expand chevron — small pill, same visual vocabulary as the
   matrix column-expander `.col-expand-pill`. 16x16 (vs 22x22 in the
   matrix) because tree rows are denser. Lucide chevron icon inside.
   pointer-events:none so the parent .mar-tree-row absorbs the click
   as one big target. Indentation per level is set inline via
   padding-left on the row. */
.mar-tree-chevron {
    flex: 0 0 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border: 1px solid rgba(99, 102, 241, 0.4);
    border-radius: 999px;
    background: rgba(99, 102, 241, 0.12);
    color: var(--accent-light, #818cf8);
    pointer-events: none;
    opacity: 0.7;
    transition:
        opacity var(--dur-fast) var(--ease-standard),
        background var(--dur-fast) var(--ease-standard),
        color var(--dur-fast) var(--ease-standard),
        box-shadow var(--dur-fast) var(--ease-standard);
}
.mar-tree-chevron i,
.mar-tree-chevron svg {
    width: 11px;
    height: 11px;
    stroke-width: 2.5;
    display: block;
}
[data-theme="light"] .mar-tree-chevron {
    border-color: rgba(99, 102, 241, 0.35);
    background: rgba(99, 102, 241, 0.08);
    color: var(--accent, #6366f1);
}
/* Leaf rows (no children to expand) — hide the pill entirely but
   keep the span for indentation alignment. */
.mar-tree-row.is-leaf .mar-tree-chevron {
    border-color: transparent !important;
    background: transparent !important;
    box-shadow: none !important;
}
.mar-tree-row.is-leaf .mar-tree-chevron i,
.mar-tree-row.is-leaf .mar-tree-chevron svg {
    display: none;
}
/* Hover on the row brightens the pill — same affordance as the
   matrix column-header pill. */
.mar-tree-row:not(.is-leaf):hover .mar-tree-chevron {
    opacity: 1;
    background: var(--accent, #6366f1);
    color: #fff;
    box-shadow: 0 1px 4px rgba(99, 102, 241, 0.35);
}
/* Expanded row keeps the pill locked bright. */
.mar-tree-row.is-expanded > .mar-tree-chevron {
    opacity: 1;
    background: var(--accent, #6366f1);
    color: #fff;
    box-shadow: 0 1px 4px rgba(99, 102, 241, 0.35);
}

.mar-tree-icon {
    flex: 0 0 18px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1;
}
.mar-tree-icon.s-pass    { color: var(--status-pass, #22c55e); }
.mar-tree-icon.s-fail    { color: var(--status-fail, #ef4444); }
.mar-tree-icon.s-running { color: var(--status-running, #f59e0b); }
.mar-tree-icon.s-na      { color: var(--text-muted, #888); }

.mar-tree-label {
    flex: 1 1 auto;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mar-tree-row.s-row-fail > .mar-tree-label {
    color: var(--status-fail, #ef4444);
}
/* Workflow-file sub-label — the underlying `.yml` (e.g. test_artifacts.yml)
   a node's jobs came from. Visually subordinate to the main label: small,
   dimmed, monospace, non-wrapping. Same muted vocabulary as the
   `(N dispatched runs)` note. */
.mar-tree-sublabel {
    margin-left: 8px;
    font-size: 0.62rem;
    font-weight: 500;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    color: var(--text-muted, #888);
    white-space: nowrap;
}
.mar-tree-summary {
    flex: 0 0 auto;
    font-size: 0.72rem;
    color: var(--text-muted, #888);
    font-variant-numeric: tabular-nums;
    margin-left: auto;
    padding-left: 8px;
}
.mar-tree-summary .pass-count { color: var(--status-pass, #22c55e); }
.mar-tree-summary .fail-count { color: var(--status-fail, #ef4444); font-weight: 700; }
.mar-tree-summary .run-count  { color: var(--status-running, #f59e0b); }

.mar-tree-children {
    /* No nested tree depth styling — each row sets its own padding-left
       inline so the indent is uniform per depth level. */
}

/* Leaf job rows — slightly different styling: monospace job-name suffix,
   right-aligned link arrow, smaller font. */
.mar-tree-row.is-leaf .mar-tree-label {
    font-weight: 500;
    font-size: 0.76rem;
    color: var(--text-secondary, #aaa);
}
.mar-tree-row.is-leaf .mar-tree-label code {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.72rem;
    background: transparent;
    padding: 0;
    color: inherit;
}
.mar-tree-leaf-link {
    flex: 0 0 auto;
    color: var(--primary-light, #818cf8);
    text-decoration: none;
    font-size: 0.72rem;
    margin-left: 8px;
    opacity: 0;
    transition: opacity 0.12s;
}
.mar-tree-row.is-leaf:hover .mar-tree-leaf-link { opacity: 1; }
.mar-tree-leaf-link:hover { text-decoration: underline; }

/* Per-stage tint on the top-level stage rows mirrors the matrix table's
   stage-pair tinting so users can mentally connect the two views. */
/* Per-LANE tint on top-level lane rows in the tree — mirrors the matrix
   table's lane tinting so users can mentally connect the matrix column to
   the tree branch. Stages within a lane don't get their own tint here —
   they inherit the lane row's color via the parent visual context. */
.mar-tree-row[data-mar-lane="setup"]          { background-color: rgba(148, 163, 184, 0.05); }
.mar-tree-row[data-mar-lane="linuxBuild"]     { background-color: rgba(56, 189, 248, 0.04); }
.mar-tree-row[data-mar-lane="linuxPkg"]       { background-color: rgba(34, 197, 94, 0.04); }
.mar-tree-row[data-mar-lane="linuxPublish"]   { background-color: rgba(20, 184, 166, 0.06); }
.mar-tree-row[data-mar-lane="linuxNativeTests"] { background-color: rgba(34, 211, 238, 0.05); }
.mar-tree-row[data-mar-lane="linuxTests"]     { background-color: rgba(132, 204, 22, 0.05); }
.mar-tree-row[data-mar-lane="linuxWheels"]    { background-color: rgba(168, 85, 247, 0.06); }
.mar-tree-row[data-mar-lane="linuxPytorchTests"]   { background-color: rgba(217, 70, 239, 0.06); }
.mar-tree-row[data-mar-lane="linuxJaxWheels"] { background-color: rgba(16, 185, 129, 0.07); }
.mar-tree-row[data-mar-lane="windowsBuild"]   { background-color: rgba(251, 146, 60, 0.04); }
.mar-tree-row[data-mar-lane="windowsPkg"]     { background-color: rgba(244, 114, 182, 0.04); }
.mar-tree-row[data-mar-lane="windowsPublish"] { background-color: rgba(251, 191, 36, 0.06); }
.mar-tree-row[data-mar-lane="windowsTests"]   { background-color: rgba(239, 68, 68, 0.04); }
.mar-tree-row[data-mar-lane="windowsPytorchTests"] { background-color: rgba(129, 140, 248, 0.06); }
.mar-tree-row[data-mar-lane="windowsWheels"]  { background-color: rgba(96, 165, 250, 0.06); }

/* "Failures only" filter — when active, hide tree-rows that don't have
   `data-has-failures="true"`. Container-wide attribute toggles visibility. */
.mar-tree-body[data-failures-only="true"] .mar-tree-row[data-has-failures="false"],
.mar-tree-body[data-failures-only="true"] .mar-tree-children[data-has-failures="false"] {
    display: none;
}

/* Light-theme adjustments */
[data-theme="light"] .mar-tree-panel {
    background: #fff;
    box-shadow: -6px 0 16px rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .mar-tree-row:hover { background: rgba(99, 102, 241, 0.07); }
[data-theme="light"] .mar-tree-header {
    /* Override both layers in light theme — solid pale-slate background,
       no white overlay (would wash it out). */
    background-color: #f8fafc;
    background-image: none;
    border-bottom-color: #e2e8f0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* Narrow-screen fallback — sidebar takes near-full width */
@media (max-width: 768px) {
    .mar-tree-panel { width: 92vw; min-width: 0; }
}

/* Re-run indicator: small spinning glyph next to a terminal status when a
 * higher run_attempt is currently running. Keeps the headline status
 * authoritative (the last completed attempt) while signaling that a
 * re-run is in flight. */
.rerun-inflight-badge {
    display: inline-block;
    margin-left: 4px;
    padding: 0 4px;
    font-size: 0.75em;
    line-height: 1.2;
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.4);
    border-radius: 8px;
    cursor: help;
    animation: rerun-spin 2.4s linear infinite;
    transform-origin: center;
    vertical-align: middle;
}
@keyframes rerun-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ----------------------------------------------------------------------------
   Internal KPI dashboard helpers — chip-bar filters, regression-alert banner,
   sparkline SVG. All scoped to the internal Build Metrics tab (see
   frontend/internal/index.html).
   ---------------------------------------------------------------------------- */

/* Chip-bar multi-select. Pattern: render every option as a pill;
   .bm-chip-active marks selected ones. JS toggles the class and calls
   the change handler on click. Much simpler than a real <select multiple>
   widget for short lists (~4-15 items). */
.bm-chips {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
    vertical-align: middle;
}
.bm-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 11px;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    background: var(--card-bg, rgba(255, 255, 255, 0.04));
    border: 1px solid var(--card-border, rgba(255, 255, 255, 0.12));
    color: var(--text-secondary, #94a3b8);
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.bm-chip:hover {
    background: var(--card-bg-hover, rgba(255, 255, 255, 0.08));
    color: var(--text-primary, #e5e7eb);
}
.bm-chip-active {
    background: var(--primary-light, #818cf8);
    border-color: var(--primary-light, #818cf8);
    color: #0f172a;
    font-weight: 600;
}

/* Control bars — group a filter/control next to the chart(s) it scopes.
   Used for the global Repository scope (top), the Trend controls (above
   the three trend charts), and the per-chart Component filter. */
.bm-control-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    padding: 8px 12px;
    border: 1px solid var(--card-border, rgba(255, 255, 255, 0.10));
    border-radius: 8px;
    background: var(--card-bg, rgba(255, 255, 255, 0.03));
}
/* Trend controls stay visible while scrolling the long chart column so
   the user can re-scope without scrolling back up. */
.bm-control-bar-sticky {
    position: sticky;
    top: 8px;
    z-index: 5;
    margin: 4px 0 14px 0;
    backdrop-filter: blur(6px);
}
.bm-control-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary, #e5e7eb);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.bm-control-group {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.bm-control-sublabel {
    font-size: 0.74rem;
    color: var(--text-muted, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.bm-control-hint {
    font-size: 0.74rem;
    color: var(--text-muted, #64748b);
    font-style: italic;
}

/* Regression alert banner at the top of the KPI dashboard. Single row
   summary (counts + worst delta) with click-to-jump-to-section links.
   Color toned by severity: red when any flagged, dim when none. */
.bm-alerts-banner {
    border-radius: 8px;
    padding: 12px 16px;
    margin: 0 0 14px 0;
    border: 1px solid;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 0.88rem;
}
.bm-alerts-banner-warn {
    background: rgba(239, 68, 68, 0.10);
    border-color: rgba(239, 68, 68, 0.45);
    color: var(--text-primary, #e5e7eb);
}
.bm-alerts-banner-good {
    background: rgba(34, 197, 94, 0.08);
    border-color: rgba(34, 197, 94, 0.30);
    color: var(--text-secondary, #94a3b8);
}
.bm-alerts-icon {
    display: inline-flex;
    width: 28px;
    height: 28px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 1.05rem;
}
.bm-alerts-banner-warn .bm-alerts-icon {
    background: rgba(239, 68, 68, 0.20);
    color: rgb(254, 202, 202);
}
.bm-alerts-banner-good .bm-alerts-icon {
    background: rgba(34, 197, 94, 0.20);
    color: rgb(187, 247, 208);
}
.bm-alerts-banner button.bm-alerts-jump {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: inherit;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.78rem;
    cursor: pointer;
}
.bm-alerts-banner button.bm-alerts-jump:hover {
    background: rgba(255, 255, 255, 0.12);
}
/* Per-regression chips inside the alerts banner — each links to the
   build/artifact behind the regression. */
.bm-alert-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 0.74rem;
    font-variant-numeric: tabular-nums;
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
}
a.bm-alert-chip:hover {
    background: rgba(255, 255, 255, 0.14);
    text-decoration: none;
}

/* Inline SVG sparkline used inside the Build extremes KPI cards (spec
   2.3 / 2.4 optional "Trend (sparkline) of that component's build time
   over the selected period"). The size is fixed at 120x28 to avoid
   layout shift when data loads. */
.bm-sparkline {
    display: inline-block;
    vertical-align: middle;
    margin-left: 8px;
}
.bm-sparkline path { fill: none; stroke-width: 1.4; }
.bm-sparkline circle { fill: currentColor; }
