/*
 * Operations dashboard layer.
 *
 * This layer owns the state band, the pipeline strip, the figure grouping and the
 * review-backlog panels. Colour, typography, elevation and the table/chip vocabulary
 * continue to come from the central Xava design-system stylesheets, and every value
 * here resolves through --xava-ui-* tokens so the transition duration keeps honouring
 * prefers-reduced-motion.
 *
 * Xava renders in a single dark theme (App.razor hardcodes data-bs-theme="dark"), so
 * there is deliberately no light-mode branch.
 */

/* ---------------------------------------------------------------- state band */

/*
 * The band replaces a bare "Overall / Critical" tile. A level on its own told an
 * operator how bad things were but never which of the twelve conditions that can set
 * Critical had actually fired, so the first line here is always the condition.
 */
.xava-ops-band {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--xava-ui-space-4);
    padding: var(--xava-ui-space-4) var(--xava-ui-space-5);
    border: 1px solid var(--xava-ui-border);
    border-left: 3px solid var(--xava-ui-success);
    border-radius: var(--xava-ui-radius-md);
    background: var(--xava-ui-surface);
    box-shadow: var(--xava-ui-shadow-sm);
}

.xava-ops-band.is-warning {
    border-left-color: var(--xava-ui-warning);
}

.xava-ops-band.is-critical {
    border-left-color: var(--xava-ui-danger);
}

.xava-ops-band-state {
    font-size: 1.55rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -.01em;
}

.xava-ops-band-body {
    display: flex;
    flex: 1 1 24rem;
    flex-direction: column;
    gap: var(--xava-ui-space-1);
    min-width: 0;
}

/*
 * The cause is server-supplied text that can carry an unbroken token - a connection string
 * fragment out of a tenant database error, for instance. Without this it sets the flex item's
 * minimum content width and pushes the whole page sideways.
 */
.xava-ops-band-cause {
    margin: 0;
    font-size: .98rem;
    font-weight: 600;
    color: var(--xava-ui-text);
    overflow-wrap: anywhere;
}

.xava-ops-band-meta {
    margin: 0;
    font-size: .78rem;
    color: var(--xava-ui-muted);
}

.xava-ops-band-action {
    padding: var(--xava-ui-space-2) var(--xava-ui-space-4);
    border: 1px solid var(--xava-ui-border);
    border-radius: var(--xava-ui-radius-pill);
    background: var(--xava-ui-surface-raised);
    color: var(--xava-ui-text);
    font-size: .82rem;
    text-decoration: none;
    white-space: nowrap;
    transition: border-color var(--xava-ui-transition), background var(--xava-ui-transition);
}

.xava-ops-band-action:hover {
    border-color: var(--xava-ui-primary);
    color: var(--xava-ui-text);
}

/* The one new interactive control on the page; it takes the system focus ring like the rest. */
.xava-ops-band-action:focus-visible {
    outline: var(--xava-ui-focus-outline);
    outline-offset: var(--xava-ui-focus-outline-offset);
}

/* ------------------------------------------------------------ pipeline strip */

/*
 * Stages sit in source order and are read left to right, which is the order data
 * actually travels. The strip scrolls rather than wrapping: a wrapped pipeline reads
 * as two unrelated rows and loses the one thing the layout is carrying.
 */
.xava-ops-flow {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(11.5rem, 1fr);
    gap: var(--xava-ui-space-2);
    margin: 0;
    padding: 0 0 var(--xava-ui-space-2);
    list-style: none;
    overflow-x: auto;
}

.xava-ops-stage {
    display: flex;
    flex-direction: column;
    gap: var(--xava-ui-space-2);
    padding: var(--xava-ui-space-3) var(--xava-ui-space-4) var(--xava-ui-space-4);
    border: 1px solid var(--xava-ui-border);
    border-top: 2px solid var(--xava-ui-success);
    border-radius: var(--xava-ui-radius-md);
    background: var(--xava-ui-surface);
    min-width: 0;
}

.xava-ops-stage.is-warning {
    border-top-color: var(--xava-ui-warning);
}

.xava-ops-stage.is-critical {
    border-top-color: var(--xava-ui-danger);
}

.xava-ops-stage.is-stopped {
    border-top-color: var(--xava-ui-muted);
}

/*
 * A parked stage is tinted as well as edged. It is the one stage no worker drains, so
 * it should not read as just another queue that happens to be deep today.
 */
.xava-ops-stage.is-parked {
    background: color-mix(in srgb, var(--xava-ui-warning) 8%, var(--xava-ui-surface));
}

/* The arrow lives on the separator between stages, never after the last one. */
.xava-ops-stage + .xava-ops-stage {
    position: relative;
}

.xava-ops-stage + .xava-ops-stage::before {
    content: "";
    position: absolute;
    top: 50%;
    left: calc(var(--xava-ui-space-2) * -1);
    width: var(--xava-ui-space-2);
    height: 1px;
    background: var(--xava-ui-border-strong);
}

.xava-ops-stage-name {
    font-size: .84rem;
    font-weight: 650;
    color: var(--xava-ui-text);
}

/*
 * Wraps rather than overflowing. A six-figure backlog beside an uppercase unit label exceeds
 * the strip's minimum column width, and as a nowrap flex row it escaped the card and was
 * painted over by the next one.
 */
.xava-ops-stage-value {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 var(--xava-ui-space-2);
    min-width: 0;
}

.xava-ops-stage-value strong {
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.xava-ops-stage-unit {
    font-size: .68rem;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--xava-ui-muted);
}

.xava-ops-stage-rates {
    display: flex;
    flex-direction: column;
    gap: var(--xava-ui-space-1);
    margin: 0;
    padding-top: var(--xava-ui-space-2);
    border-top: 1px solid var(--xava-ui-border);
}

.xava-ops-stage-rates > div {
    display: flex;
    justify-content: space-between;
    gap: var(--xava-ui-space-3);
    font-size: .76rem;
}

.xava-ops-stage-rates dt {
    color: var(--xava-ui-muted);
    font-weight: 400;
}

.xava-ops-stage-rates dd {
    margin: 0;
    color: var(--xava-ui-text);
    font-variant-numeric: tabular-nums;
}

.xava-ops-stage-state {
    align-self: flex-start;
    padding: .18rem .55rem;
    border: 1px solid currentColor;
    border-radius: var(--xava-ui-radius-pill);
    font-size: .64rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--xava-ui-muted);
}

.xava-ops-stage.is-healthy .xava-ops-stage-state {
    color: var(--xava-ui-success);
}

.xava-ops-stage.is-warning .xava-ops-stage-state,
.xava-ops-stage.is-parked .xava-ops-stage-state {
    color: var(--xava-ui-warning);
}

.xava-ops-stage.is-critical .xava-ops-stage-state {
    color: var(--xava-ui-danger);
}

/* --------------------------------------------------------------- figure groups */

.xava-ops-group {
    display: grid;
    gap: var(--xava-ui-space-2);
}

.xava-ops-group-label {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--xava-ui-space-3);
    margin: 0;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--xava-ui-muted);
}

.xava-ops-group-label span {
    font-size: .76rem;
    font-weight: 400;
    letter-spacing: normal;
    text-transform: none;
}

/*
 * Scoped through .xava-metric on purpose. The note is a <span> inside a tile, and app.css
 * carries a `.xava-metric span` rule that sets colour and font-size; at 0-1-1 that rule
 * outranks a bare `.xava-ops-metric-note` class no matter which stylesheet loads last, so
 * the note would silently render at the label's size.
 */
.xava-metric .xava-ops-metric-note {
    display: block;
    margin-top: .3rem;
    font-size: .72rem;
    color: var(--xava-ui-muted);
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------- review backlog */

.xava-ops-review {
    display: grid;
    gap: var(--xava-ui-space-3);
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
}

.xava-ops-panel {
    display: flex;
    flex-direction: column;
    gap: var(--xava-ui-space-3);
    padding: var(--xava-ui-space-4);
    border: 1px solid var(--xava-ui-border);
    border-radius: var(--xava-ui-radius-md);
    background: var(--xava-ui-surface);
    min-width: 0;
}

.xava-ops-panel-title {
    margin: 0;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--xava-ui-muted);
}

.xava-ops-bars {
    display: flex;
    flex-direction: column;
    gap: var(--xava-ui-space-3);
    margin: 0;
}

.xava-ops-bar {
    display: flex;
    flex-direction: column;
    gap: .3rem;
}

.xava-ops-bar dt {
    font-size: .82rem;
    font-weight: 400;
    color: var(--xava-ui-text);
}

/*
 * The track lives inside the <dd> so the <dl> stays conforming - a bare <span> beside dt/dd
 * is not permitted. Visual order is track then figure; DOM order is the reverse so a screen
 * reader reads the label and its value without the decorative track between them.
 */
.xava-ops-bar dd {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--xava-ui-space-3);
    margin: 0;
    font-size: .82rem;
    color: var(--xava-ui-muted);
    font-variant-numeric: tabular-nums;
}

.xava-ops-bar-value {
    grid-column: 2;
    text-align: right;
}

.xava-ops-bar-track {
    grid-column: 1;
    height: 5px;
    border-radius: var(--xava-ui-radius-pill);
    background: var(--xava-ui-surface-raised);
    overflow: hidden;
}

.xava-ops-bar-fill {
    display: block;
    height: 100%;
    border-radius: var(--xava-ui-radius-pill);
    background: color-mix(in srgb, var(--xava-ui-warning) 60%, transparent);
}

.xava-ops-facts {
    display: flex;
    flex-direction: column;
    gap: var(--xava-ui-space-2);
    margin: 0;
}

.xava-ops-facts > div {
    display: flex;
    justify-content: space-between;
    gap: var(--xava-ui-space-3);
    font-size: .86rem;
}

.xava-ops-facts dt {
    color: var(--xava-ui-muted);
    font-weight: 400;
}

.xava-ops-facts dd {
    margin: 0;
    font-variant-numeric: tabular-nums;
}

.xava-ops-note {
    margin: 0;
    font-size: .78rem;
    line-height: 1.5;
    color: var(--xava-ui-muted);
    max-width: 68ch;
}

@media (max-width: 640px) {
    .xava-ops-band-state {
        font-size: 1.3rem;
    }

    .xava-ops-flow {
        grid-auto-columns: minmax(10.5rem, 1fr);
    }
}
