/*
 * console.css: the fosEventBus System Console's own parts (spec/SYSTEM-CONSOLE.md), on the May look.
 * Linked after tokens.css, shell.css and control-page.css. It declares no colour, size or font of its own: every value is a token.
 * It sets only .bus-* classes, never a .cp- class, so the block stays the block. Design: ui/console/DESIGN.md.
 */

/* ---- The test-data mark (BUS-13): on the whole page while the double is plugged in ---------------------------------------- */
.bus-testmark {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3);
  padding: var(--sp-2) var(--page-inset);
  background: color-mix(in srgb, var(--warn) 14%, var(--bg));
  border-bottom: 2px dashed var(--warn);
  color: var(--text); font-size: var(--fs-md);
}
.bus-testmark-label {
  font-family: var(--mono); font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.08em;
  color: var(--bg); background: var(--warn); padding: 1px var(--sp-2); border-radius: var(--r-sm);
}
[data-theme='light'] .bus-testmark-label { color: var(--bg-2); background: var(--chip-warn-text); }
/* The frame carries the mark too, so a screenshot of any one part still shows it. */
body[data-on-double='true'] .bus-part { border-top: 2px dashed color-mix(in srgb, var(--warn) 60%, transparent); }

/* ---- The bus not reachable: one line at the top, a retry, old data marked ------------------------------------------------ */
.bus-unreachable {
  display: none; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3);
  padding: var(--sp-2) var(--sp-3); margin: var(--sp-3) 0 0;
  border: 1px solid var(--danger); border-radius: var(--r-md);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--text); font-size: var(--fs-md);
}
body[data-bus='unreachable'] .bus-unreachable { display: flex; }
.bus-stale { display: none; font-size: var(--fs-xs); color: var(--text-2); font-style: italic; }
body[data-bus='unreachable'] .bus-stale { display: inline; }
body[data-bus='unreachable'] .bus-part-body { opacity: 0.72; }
body[data-bus='unreachable'] .bus-send .btn-primary { background: var(--bg-3); color: var(--text-3); border-color: var(--line-2); cursor: not-allowed; }

/* ---- The page grid: the block's 1:2, with the bus's parts in its places ----------------------------------------------------
   DOM order is the phone order (spec Rules): status, send + who got it, stream, more. On a desk the send column is the chat third. */
.bus-grid { display: grid; gap: var(--cp-gap, 1rem); align-items: start; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  /* The send column is taller than the three parts beside it: its spare height goes to a fourth, empty row, so the gaps between the parts stay the gap. */
  grid-template-rows: auto auto auto 1fr; }
.bus-status { grid-column: 2; grid-row: 1; }
.bus-left   { grid-column: 1; grid-row: 1 / span 4; position: sticky; top: calc(var(--sp-5) + 40px); display: flex; flex-direction: column; gap: var(--cp-gap, 1rem); min-width: 0; }
.bus-stream { grid-column: 2; grid-row: 2; }
.bus-more   { grid-column: 2; grid-row: 3; }
@media (max-width: 720px) {
  .bus-grid { display: flex; flex-direction: column; align-items: stretch; }
  .bus-left { position: static; }
}

/* ---- A part: the block's panel, with a head that names it and says when it was read --------------------------------------- */
.bus-part { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; min-width: 0; overflow-wrap: anywhere; }
.bus-part-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-1) var(--sp-3); margin-bottom: var(--sp-3); }
.bus-part-head h2 { margin: 0; font-size: var(--fs-sm); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); }
.bus-part-head .bus-read-at { margin-left: auto; font-size: var(--fs-xs); color: var(--text-3); font-family: var(--mono); }

/* Loading: the part's frame with a quiet mark. Other parts stay usable. */
.bus-loading { display: none; align-items: center; gap: var(--sp-2); min-height: var(--tap-min); font-size: var(--fs-md); color: var(--text-3); }
.bus-loading::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); animation: bus-breathe 1.6s ease-in-out infinite; }
@keyframes bus-breathe { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .bus-loading::before { animation: none; opacity: 0.6; } }
.bus-part[aria-busy='true'] .bus-loading { display: flex; }
.bus-part[aria-busy='true'] .bus-part-body { display: none; }

/* Empty: words, never a blank area. */
.bus-empty { margin: 0; padding: var(--sp-3) 0; font-size: var(--fs-md); color: var(--text-2); }
.bus-empty-hint { display: block; font-size: var(--fs-sm); color: var(--text-3); margin-top: var(--sp-1); }

/* ---- 1. Status strip: the block's KPI tiles. The level is said in words as well as by the edge ------------------------------ */
.bus-status .cp-kpi-strip { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); }
@media (max-width: 720px) {
  /* The block's phone strip: two to a row; health, the one that matters first, takes the whole row. */
  .bus-status .cp-kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bus-status .cp-kpi:first-child { grid-column: 1 / -1; }
}
.bus-status .cp-kpi-value { font-size: var(--fs-md); }
.bus-level-word { font-family: var(--sans); }
.bus-kpi-figure-small { font-size: var(--fs-md); font-weight: 500; font-family: var(--sans); color: var(--text); }

/* ---- 2. Send an event: a form in the chat third --------------------------------------------------------------------------- */
.bus-form { display: flex; flex-direction: column; gap: var(--sp-3); }
.bus-field { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; }
.bus-field label { font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); }
.bus-field .bus-help { font-size: var(--fs-xs); color: var(--text-3); }
.bus-input, .bus-select {
  min-height: var(--tap-min); width: 100%; padding: var(--sp-2) var(--sp-3);
  background: var(--bg-3); color: var(--text); border: 1px solid var(--line-2); border-radius: 7px;
  font-family: var(--sans); font-size: var(--fs-md);
}
.bus-input.bus-mono, .bus-select.bus-mono { font-family: var(--mono); font-size: var(--fs-sm); }
.bus-input:focus-visible, .bus-select:focus-visible, .btn:focus-visible, .bus-row:focus-visible, .bus-link:focus-visible, .bus-tab:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.bus-field[data-invalid='true'] .bus-input, .bus-field[data-invalid='true'] .bus-select { border-color: var(--danger); }
.bus-field-error { display: none; font-size: var(--fs-sm); color: var(--danger); }
.bus-field[data-invalid='true'] .bus-field-error { display: block; }
.bus-fieldset { border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-3); margin: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.bus-fieldset legend { padding: 0 var(--sp-1); font-size: var(--fs-sm); color: var(--text-2); }
.bus-sendas { font-size: var(--fs-sm); color: var(--text-3); }
.bus-sendas code { font-family: var(--mono); color: var(--text-2); }
.bus-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.bus-actions .btn-primary { flex: 1 1 auto; justify-content: center; }

/* The answer to a send: the stored event, or the refusal in plain words. */
.bus-result { border-radius: var(--r-md); padding: var(--sp-3); font-size: var(--fs-md); }
.bus-result-ok { border: 1px solid color-mix(in srgb, var(--ok) 50%, transparent); background: color-mix(in srgb, var(--ok) 8%, transparent); }
.bus-result-refused { border: 1px solid var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); }
.bus-result-title { font-weight: 600; margin: 0 0 var(--sp-1); color: var(--text); }
.bus-result p { margin: 0; color: var(--text-2); }
.bus-result ul { margin: var(--sp-1) 0 0; padding-left: var(--sp-4); color: var(--text-2); }
/* A read the bus refused (CON-29): said plainly where the part's data would be. Calmer than a refused send: nothing the reader typed failed. */
.bus-refused { border-radius: var(--r-md); padding: var(--sp-3); font-size: var(--fs-md); border: 1px solid var(--warn); background: color-mix(in srgb, var(--warn) 8%, transparent); }
.bus-refused-title { font-weight: 600; margin: 0 0 var(--sp-1); color: var(--text); }
.bus-refused p { margin: 0; color: var(--text-2); }
.bus-result code, .bus-id { font-family: var(--mono); font-size: var(--fs-sm); color: var(--text-2); }

/* ---- 3. Who got it: one row per delivery ---------------------------------------------------------------------------------- */
.bus-about { margin: 0 0 var(--sp-3); font-size: var(--fs-md); color: var(--text-2); }
.bus-about strong { color: var(--text); font-weight: 600; }
.bus-deliveries { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.bus-delivery {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-1) var(--sp-3); align-items: center;
  padding: var(--sp-2) var(--sp-3); min-height: var(--tap-min);
  background: var(--bg-3); border: 1px solid var(--line); border-left: 3px solid var(--unknown); border-radius: var(--r-md);
}
.bus-delivery[data-ended='done'], .bus-delivery[data-ended='handled-in-code'] { border-left-color: var(--ok); }
.bus-delivery[data-ended='dead-letter'] { border-left-color: var(--danger); }
.bus-delivery[data-ended='held-budget'], .bus-delivery[data-ended='pending'] { border-left-color: var(--warn); }
.bus-delivery[data-ended='skipped-duplicate'] { border-left-color: var(--text-3); }
.bus-target { display: flex; flex-direction: column; min-width: 0; }
.bus-link { color: var(--accent); text-decoration: none; font-weight: 500; font-size: var(--fs-md); display: inline-flex; align-items: center; min-height: var(--tap-min); }
.bus-link:hover { text-decoration: underline; }
.bus-ended { font-size: var(--fs-sm); font-weight: 500; color: var(--text); white-space: nowrap; }
.bus-meta { grid-column: 1 / -1; font-size: var(--fs-xs); color: var(--text-3); font-family: var(--mono); }

/* ---- 4. The stream: events newest first ------------------------------------------------------------------------------------ */
.bus-filters { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.bus-filters .bus-field { flex: 1 1 180px; }
.bus-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.bus-row {
  display: grid; grid-template-columns: 88px minmax(0, 1.1fr) minmax(0, 1.4fr) minmax(0, 1fr); gap: var(--sp-3); align-items: center;
  width: 100%; min-height: var(--tap-min); padding: var(--sp-2) var(--sp-3);
  background: transparent; border: 0; border-bottom: 1px solid var(--line); border-left: 3px solid transparent;
  color: var(--text); font: inherit; font-size: var(--fs-md); text-align: left; cursor: pointer;
}
.bus-row:hover { background: var(--bg-3); }
.bus-row[aria-current='true'] { background: var(--bg-3); border-left-color: var(--accent); }
.bus-row-new { animation: bus-new var(--dur-mark) ease-out 1; }
@keyframes bus-new { from { background: color-mix(in srgb, var(--accent) 16%, transparent); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .bus-row-new { animation: none; } }
.bus-time { font-family: var(--mono); font-size: var(--fs-xs); color: var(--text-3); }
.bus-kind { justify-self: start; font-family: var(--mono); font-size: var(--fs-xs); color: var(--text-2); background: var(--bg); border: 1px solid var(--line-2); padding: 1px var(--sp-2); border-radius: var(--r-sm); }
.bus-object { display: flex; flex-direction: column; min-width: 0; }
.bus-object-name { font-weight: 500; color: var(--text); }
.bus-by { font-size: var(--fs-sm); color: var(--text-2); }
.bus-rows-head { display: grid; grid-template-columns: 88px minmax(0, 1.1fr) minmax(0, 1.4fr) minmax(0, 1fr); gap: var(--sp-3); padding: 0 var(--sp-3) var(--sp-1); font-size: var(--fs-xs); color: var(--text-3); border-bottom: 1px solid var(--line-2); }
.bus-older { margin-top: var(--sp-3); }
@media (max-width: 720px) {
  .bus-rows-head { display: none; }
  .bus-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: 'object time' 'kind by'; gap: var(--sp-1) var(--sp-2); padding: var(--sp-2); }
  .bus-row .bus-object { grid-area: object; }
  .bus-row .bus-time { grid-area: time; justify-self: end; }
  .bus-row .bus-kind { grid-area: kind; }
  .bus-row .bus-by { grid-area: by; justify-self: end; text-align: right; }
}

/* ---- 5 to 9: one tap away, a row of tabs ------------------------------------------------------------------------------------ */
.bus-tabs { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.bus-tab { min-height: var(--tap-min); }
.bus-tab[aria-selected='true'] { background: var(--bg-3); border-color: var(--accent); color: var(--text); }
.bus-more-open { display: none; width: 100%; justify-content: center; }
@media (max-width: 720px) {
  .bus-more-open { display: inline-flex; }
  .bus-more[data-open='false'] .bus-tabs, .bus-more[data-open='false'] .bus-more-body { display: none; }
}

/* ---- The header line: the type chip and the test-data chip beside the title ---------------------------------------------- */
.bus-chip-test { order: 2; font-family: var(--mono); font-size: var(--fs-xs); color: var(--warn); border: 1px dashed var(--warn); padding: 0 var(--sp-2); border-radius: var(--r-sm); }
[data-theme='light'] .bus-chip-test { color: var(--chip-warn-text); border-color: var(--chip-warn-text); }
.bus-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---- 5 to 9: the shared pieces of the panels behind the tabs ---------------------------------------------------------------- */
.bus-more-body { margin-top: var(--sp-4); }
.bus-more-body[hidden] { display: none !important; }
.bus-more[aria-busy='true'] .bus-more-body:not([hidden]) .bus-loading { display: flex; }
.bus-lede { margin: 0 0 var(--sp-3); font-size: var(--fs-md); color: var(--text-2); }
.bus-quiet { color: var(--text-3); }
.bus-more-rows { font-size: var(--fs-sm); margin: var(--sp-3) 0 0; }
.bus-count { font-family: var(--mono); font-size: var(--fs-xs); color: var(--on-accent); background: var(--danger); border-radius: 999px; padding: 0 6px; margin-left: var(--sp-1); }
.bus-h3 { margin: 0; font-size: var(--fs-md); font-weight: 600; color: var(--text); }
.bus-table { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.bus-card { background: var(--bg-3); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-2) var(--sp-3); min-width: 0; }
.bus-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-2); min-height: 32px; font-size: var(--fs-md); color: var(--text); }
.bus-card-note { margin: var(--sp-1) 0 0; font-size: var(--fs-sm); color: var(--text-2); }
.bus-card-note code { font-family: var(--mono); }
.bus-row-action { margin-left: auto; }
.bus-dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px var(--sp-3); margin: var(--sp-2) 0 0; font-size: var(--fs-sm); }
.bus-dl dt { color: var(--text-3); }
.bus-dl dd { margin: 0; color: var(--text); display: flex; flex-wrap: wrap; gap: var(--sp-1); align-items: baseline; }
/* A line with no label of its own (a dismissed letter's who and when, CON-14c) spans both columns; in the first it would widen the labels and squeeze every value. */
.bus-dl > dd.bus-dismissed-by { grid-column: 1 / -1; }
.bus-tag { font-family: var(--mono); font-size: var(--fs-xs); color: var(--text-2); background: var(--bg-2); border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 0 6px; }
.bus-source { font-size: var(--fs-xs); color: var(--text-3); border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 0 6px; }
.bus-source-added { color: var(--accent); border-color: var(--accent); }

/* 6. Routes */
.bus-arrow { color: var(--text-3); }
.bus-to { display: inline-flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-2); align-items: baseline; }
.bus-add { margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--line); }
.bus-row-fields { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); }
.bus-row-fields .bus-field { flex: 1 1 180px; }
.bus-when summary { cursor: pointer; min-height: var(--tap-min); display: flex; align-items: center; font-size: var(--fs-sm); color: var(--text-2); }
.bus-when summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 7. Dead letters: the state in words and by the edge; the row is never removed */
.bus-dead { border-left: 3px solid var(--danger); }
.bus-dead[data-state='retried'] { border-left-color: var(--ok); }
.bus-dead[data-state='dismissed'] { border-left-color: var(--text-3); }
.bus-dead[data-state='dismissed'] .bus-dl, .bus-dead[data-state='dismissed'] .bus-card-head { color: var(--text-2); }
.bus-state-word { font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-2); }
.bus-dead[data-state='open'] .bus-state-word { color: var(--danger); }
.bus-dead-actions { margin-top: var(--sp-2); }
.bus-dismiss { margin-top: var(--sp-2); padding: var(--sp-3); border: 1px dashed var(--line-2); border-radius: var(--r-md); display: flex; flex-direction: column; gap: var(--sp-2); }

/* 8. Tests: a row with no real test is never shown as passing */
.bus-tests-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-2); }
.bus-tests-head .btn { margin-left: auto; }
.bus-tally { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin: 0; }
.bus-row-id { font-family: var(--mono); font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.bus-result-chip { font-size: var(--fs-xs); font-weight: 600; border-radius: var(--r-sm); padding: 1px var(--sp-2); border: 1px solid; }
.bus-result-chip[data-result='passed'] { color: var(--ok-text); border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.bus-result-chip[data-result='failed'] { color: var(--danger); border-color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
[data-theme='light'] .bus-result-chip[data-result='failed'] { color: var(--chip-danger-text); }
.bus-result-chip[data-result='none'] { color: var(--text-2); border-style: dashed; border-color: var(--line-2); }
.bus-result-chip[data-result='running'] { color: var(--text-2); border-color: var(--accent); }
.bus-result-chip[data-result='zero'] { color: var(--text-2); border-color: var(--line-2); } /* a tally of 0 failed is calm, not red */
.bus-ran { font-size: var(--fs-xs); font-family: var(--mono); color: var(--text-3); }
.bus-gwt { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px var(--sp-3); margin: var(--sp-2) 0 0; font-size: var(--fs-sm); }
.bus-gwt dt { font-weight: 600; color: var(--text-3); }
.bus-gwt dd { margin: 0; color: var(--text); }

/* 9. Chain */
.bus-hash { font-size: var(--fs-lg); overflow-wrap: anywhere; }
@media (max-width: 720px) {
  .bus-chain-figures { grid-template-columns: minmax(0, 1fr); }
  .bus-row-action { margin-left: 0; }
  .bus-tests-head .btn { margin-left: 0; width: 100%; justify-content: center; }
}
/* The add-route form in part 6 (its own class, so it never matches the send form's selectors). */
.bus-route-form { display: flex; flex-direction: column; gap: var(--sp-3); }
