/* ==========================================================================
   Release tracker (.rt-*) — the Finalize Sprint live tracker.

   A FEATURE stylesheet, not an append to the 4394-line styles.css, following
   the css/manifest.css precedent (index.html loads both). Every value is a
   token declared in styles.css, so both themes work with no overrides here:
   the `--status-*` triples flip at :root[data-theme="dark"] and the accent
   family derives from --accent / --secondary / --ring.

   Ported from the approved mockup (frontend/mockups/release-tracker.html),
   minus its .mk-* scenario-switcher chrome. Three motion values differ from
   the mockup and each is deliberate — see the comments at .rt-phase__fill,
   .rt-swap and .rt-feed li.is-new.
   ========================================================================== */

.rt {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
}
.rt__body { display: flex; flex-direction: column; gap: 20px; }

/* --- Now: the one thing to read first. Tone carries state; glyph + words are
   always present, so the colour is never the only signal. */
.rt-now {
    --tone: var(--accent-text);
    --tone-bg: hsl(var(--status-info-bg));
    --tone-border: hsl(var(--status-info-border));
    border: 1px solid var(--tone-border);
    background: var(--tone-bg);
    border-radius: var(--radius);
    padding: 16px 18px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
        "glyph head    actions"
        "glyph detail  actions"
        "glyph facts   actions"
        "glyph list    list";
    gap: 4px 14px;
    align-items: start;
    transition: background-color 200ms var(--ease-out), border-color 200ms var(--ease-out);
}
.rt-now[data-tone="warn"] {
    --tone: hsl(var(--status-warning-text));
    --tone-bg: hsl(var(--status-warning-bg));
    --tone-border: hsl(var(--status-warning-border));
}
.rt-now[data-tone="danger"] {
    --tone: hsl(var(--status-error-text));
    --tone-bg: hsl(var(--status-error-bg));
    --tone-border: hsl(var(--status-error-border));
}
.rt-now[data-tone="ready"] {
    --tone: var(--accent-text);
    --tone-bg: var(--accent-tint);
    --tone-border: transparent;
}

.rt-now__glyph {
    grid-area: glyph;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: var(--tone);
    font-size: 0.95rem;
    font-weight: 700;
    position: relative;
    margin-top: 1px;
}
.rt-now__glyph::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid currentColor;
    opacity: 0.3;
}
/* Waiting: an arc runs round the ring. Constant motion, so linear; slow enough
   to read as "working", not "loading". It is the SECOND signal, never the only
   one — the countdown below says the same thing in words. */
.rt-now[data-live="true"] .rt-now__glyph::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top-color: currentColor;
    animation: spin 1.4s linear infinite;
}
/* Stale: we do not know the current state, so nothing may look alive. */
.rt-now[data-stale="true"] { opacity: 0.72; }
.rt-now[data-stale="true"] .rt-now__glyph::after { display: none; }

.rt-now__headline {
    grid-area: head;
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.4;
    text-wrap: balance;
}
.rt-now__detail {
    grid-area: detail;
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.55;
    max-width: 68ch;
}
.rt-now__facts {
    grid-area: facts;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    margin-top: 6px;
    font-size: 0.82rem;
    color: var(--text-secondary);
}
.rt-now__facts b {
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}
.rt-now__facts .is-over { color: var(--tone); }
.rt-now__actions {
    grid-area: actions;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-end;
}
/* Several problems at once: one row each, with its own way out. */
.rt-now__list {
    grid-area: list;
    list-style: none;
    margin: 10px 0 0;
    padding: 0;
    display: grid;
    border-top: 1px solid var(--tone-border);
}
.rt-now__item {
    display: grid;
    grid-template-columns: minmax(130px, 180px) minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 10px 0;
}
.rt-now__item + .rt-now__item { border-top: 1px solid var(--tone-border); }
.rt-now__item-name { font-weight: 600; color: var(--text-primary); font-size: 0.9rem; }
.rt-now__item-text { font-size: 0.88rem; color: var(--text-secondary); min-width: 0; }
.rt-now__item-text .rt-mark { display: inline-grid; vertical-align: -3px; margin-right: 6px; }
.rt-now__item-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    align-items: center;
    justify-content: flex-end;
}

.rt-link {
    color: var(--accent-text);
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    border-radius: 4px;
}
.rt-link::after { content: " \2197"; font-weight: 400; }
.rt-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.rt-link:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.rt-nowrap { white-space: nowrap; }

/* State change: one authored moment. Content settles in from 4px with a 2px
   blur so the old and new sentences never read as two overlapping objects.
   The blur is a DECLARED deviation from the transform/opacity-only motion
   floor — a recorded user decision, kept because the swap replaces a whole
   sentence rather than moving an object. */
.rt-swap { animation: rt-swap-in 220ms var(--ease-out); }
@keyframes rt-swap-in {
    from { opacity: 0; transform: translateY(4px); filter: blur(2px); }
}
/* A press on the blocked Announce points at the panel that says what is left. */
.rt-flash { animation: rt-flash 700ms var(--ease-out); }
@keyframes rt-flash {
    0%, 40% { box-shadow: 0 0 0 3px var(--accent-ring); }
    100%    { box-shadow: 0 0 0 0 transparent; }
}

/* --- Countdown to the next check. */
.rt-pulse {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: -8px;
    min-height: 26px;
}
.rt-pulse__text { font-variant-numeric: tabular-nums; }
.rt-pulse__text strong { font-weight: 500; color: var(--text-secondary); }
.rt-pulse .btn { padding: 4px 10px; font-size: 0.8rem; }
.rt-checking { display: inline-flex; align-items: center; gap: 6px; }

.rt-alert {
    flex-basis: 100%;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    border: 1px solid hsl(var(--status-error-border));
    background: hsl(var(--status-error-bg));
    color: hsl(var(--status-error-text));
}
.rt-alert[data-tone="info"] {
    border-color: var(--border-color);
    background: var(--surface-sunken);
    color: var(--text-secondary);
}
.rt-alert__icon { grid-row: span 3; font-weight: 700; }
.rt-alert__title { font-weight: 600; color: var(--text-primary); }
.rt-alert__text { color: var(--text-secondary); line-height: 1.5; }
.rt-alert__row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin-top: 6px;
}
.rt-alert code { font-family: var(--font-mono); font-size: 0.78rem; }

/* --- Phases: the release-wide stepper. */
.rt-phases {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
}
.rt-phase { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.rt-phase__bar {
    height: 4px;
    border-radius: 999px;
    background: var(--surface-sunken);
    overflow: hidden;
}
/* 240ms, not the mockup's 300ms: the motion floor is UNDER 300ms, and 300 is
   not under 300. */
.rt-phase__fill {
    display: block;
    height: 100%;
    transform-origin: left;
    transform: scaleX(0);
    background: var(--accent-primary);
    transition: transform 240ms var(--ease-in-out), background-color 200ms var(--ease-out);
}
.rt-phase[data-state="done"]    .rt-phase__fill { transform: scaleX(1); background: var(--success); }
.rt-phase[data-state="current"] .rt-phase__fill { transform: scaleX(1); }
.rt-phase[data-state="warn"]    .rt-phase__fill { transform: scaleX(1); background: var(--warning); }
.rt-phase[data-state="danger"]  .rt-phase__fill { transform: scaleX(1); background: var(--danger); }
.rt-phase__label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.rt-phase__sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    min-height: 1.1em;
}
.rt-phase[data-state="done"]    .rt-phase__label { color: var(--text-secondary); }
.rt-phase[data-state="current"] .rt-phase__label { color: var(--accent-text); }
.rt-phase[data-state="warn"]    .rt-phase__label { color: hsl(var(--status-warning-text)); }
.rt-phase[data-state="danger"]  .rt-phase__label { color: hsl(var(--status-error-text)); }

/* --- Section heads. */
.rt-sec { display: flex; flex-direction: column; gap: 8px; }
.rt-sec__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.rt-sec__title { margin: 0; font-size: 0.875rem; font-weight: 600; color: var(--text-primary); }
.rt-sec__aside { font-size: 0.8rem; color: var(--text-muted); }

/* --- Projects: one row each, problems first, the finished ones folded away. */
.rt-projects { border: 1px solid var(--border-color); border-radius: var(--radius); }
.rt-proj + .rt-proj, .rt-fold { border-top: 1px solid var(--border-color); }
.rt-proj__row {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
    padding: 12px 14px;
}
.rt-proj__id { min-width: 0; display: flex; align-items: baseline; gap: 6px; }
.rt-proj__name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.92rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rt-proj__ver {
    flex: none;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-muted);
}
.rt-proj__status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    color: var(--text-secondary);
    min-width: 0;
}
.rt-proj__status b { font-weight: 600; flex: none; }
.rt-proj__status .rt-time {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rt-mark {
    flex: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 0.7rem;
    font-weight: 700;
}
.rt-mark--done   { background: hsl(var(--status-success-bg)); color: hsl(var(--status-success-text)); }
.rt-mark--wait   { background: hsl(var(--status-info-bg));    color: var(--accent-text); }
.rt-mark--wait::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.rt-mark--warn   { background: hsl(var(--status-warning-bg)); color: hsl(var(--status-warning-text)); }
.rt-mark--danger { background: hsl(var(--status-error-bg));   color: hsl(var(--status-error-text)); }
.rt-proj__links { display: flex; gap: 16px; justify-content: flex-end; align-items: center; }

.rt-toggle {
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    background: none;
    border: 0;
    padding: 4px 6px;
    margin: -4px -6px;
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: color var(--transition);
}
.rt-toggle::after {
    content: "";
    width: 6px;
    height: 6px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
    transition: transform 160ms var(--ease-out);
}
.rt-toggle[aria-expanded="true"]::after { transform: translateY(1px) rotate(225deg); }
.rt-toggle:hover { color: var(--text-primary); }
.rt-toggle:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }

.rt-steps {
    list-style: none;
    margin: 0;
    padding: 0 14px 12px 14px;
    display: grid;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    animation: rt-fade 160ms var(--ease-out);
}
.rt-steps[hidden] { display: none; }
.rt-steps li { display: grid; grid-template-columns: 52px 18px 1fr; gap: 8px; align-items: baseline; }
.rt-steps time { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); }
.rt-steps .is-fail { color: hsl(var(--status-error-text)); }

.rt-fold {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    background: var(--surface-sunken);
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-radius: 0 0 var(--radius) var(--radius);
}
.rt-fold .rt-mark { display: inline-grid; vertical-align: -4px; margin-right: 8px; }
@keyframes rt-fade { from { opacity: 0; } }

/* --- Activity: what moved under the hood, newest first. */
.rt-feed { list-style: none; margin: 0; padding: 0; display: grid; }
.rt-feed li {
    display: grid;
    grid-template-columns: 52px 1fr auto;
    gap: 12px;
    align-items: baseline;
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.rt-feed time {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.rt-feed .rt-feed__who { color: var(--text-primary); font-weight: 500; }
/* 220ms entry, then a 1.6s background DECAY that marks which row is new. The
   decay is declared rather than clipped to 300ms: it is the mark fading out,
   not the element arriving. */
.rt-feed li.is-new { animation: rt-feed-in 220ms var(--ease-out), rt-feed-mark 1.6s ease 220ms; }
@keyframes rt-feed-in { from { opacity: 0; transform: translateY(-4px); } }
@keyframes rt-feed-mark { from { background: var(--accent-tint); } to { background: transparent; } }
.rt-feed__more { justify-self: start; margin-top: 4px; }

/* --- Finish: the same drawn check as QA Build and Release New Build. */
.rt-finish { padding: 12px 0 4px; }
.rt-finish .qa-success__msg { max-width: 54ch; }
.rt-finish .qa-success__title {
    margin: 0 0 6px;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
}
.rt-finish .qa-success__steps { max-width: 560px; margin-left: auto; margin-right: auto; }
.rt-finish .qa-success__step { animation: rt-feed-in 220ms var(--ease-out) both; }
.rt-finish code { font-family: var(--font-mono); font-size: 0.82rem; }

/* --- Footer: lives inside the shared modal footer, so only the note and the
   blocked-button treatment are ours. */
.rt__note {
    margin: 0;
    font-size: 0.82rem;
    color: var(--text-muted);
    flex: 1 1 280px;
    max-width: 62ch;
    text-align: left;
}
.btn.is-blocked { opacity: 0.55; }

@media (max-width: 768px) {
    .rt-now {
        grid-template-columns: auto 1fr;
        grid-template-areas:
            "glyph head"
            ".     detail"
            ".     facts"
            ".     actions"
            "list  list";
    }
    .rt-now__actions { align-items: flex-start; flex-direction: row; flex-wrap: wrap; margin-top: 8px; }
    .rt-now__item { grid-template-columns: minmax(0, 1fr); gap: 4px; }
    .rt-now__item-actions { justify-content: flex-start; margin-top: 4px; }
    .rt-phase__label { font-size: 0.72rem; white-space: normal; line-height: 1.25; }
    .rt-proj__row { grid-template-columns: minmax(0, 1fr) auto; }
    .rt-proj__status { grid-column: 1 / -1; grid-row: 2; }
    .rt-proj__name { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
    .rt-now { transition: none; }
    .rt-now[data-live="true"] .rt-now__glyph::after { animation: none; }
    .rt-swap, .rt-feed li.is-new, .rt-finish .qa-success__step { animation: rt-fade 160ms ease; }
    .rt-flash { animation: none; outline: 3px solid var(--accent-ring); }
    .rt-phase__fill { transition: none; }
    .rt-steps { animation: none; }
    .rt-toggle, .rt-toggle::after { transition: none; }
}
