/*
 * Version 3 -- System Health workspace.
 *
 * Continues the shell token system and the anatomy every other V3 panel uses:
 * a status line, an error region, an empty state, and a content region of
 * headed sections.
 *
 * ---------------------------------------------------------------------------
 * No traffic lights
 * ---------------------------------------------------------------------------
 *
 * The Version 2 System Health module coloured every row green, yellow, or red
 * through `status-dot-*` classes. Nothing of that model survives here. This
 * page has no severity, no grade, and no health score to colour by, so there
 * is no palette for one.
 *
 * The only two tinted things on the page are tied to *stored* facts, never to
 * a judgement this page formed, and both carry the same fact in words beside
 * them so a reader who sees no colour loses nothing:
 *
 *   .v3-sh-outcome--failure   an import whose recorded outcome was "failure",
 *                             which also reads "Failure"
 *   .v3-sh-fact--absent       storage that is not reachable, which also reads
 *                             "Not reachable"
 *
 * Both are drawn as a left border plus muted surface -- no filled colour block,
 * no dot, nothing that could be mistaken for a rating.
 *
 * Every table scrolls inside its own wrapper, so the page body never scrolls
 * sideways however wide a source filename or record key turns out to be.
 */

.v3-panel--system-health {
  max-width: 1240px;
}

/* ---- status, empty, error ----------------------------------------------- */

.v3-sh-status {
  margin: 0 0 var(--v3-space-4);
  font-size: 0.85rem;
  color: var(--v3-text-muted);
}

.v3-sh-empty {
  margin: 0 0 var(--v3-space-4);
  padding: var(--v3-space-4);
  max-width: 76ch;
  border-radius: var(--v3-radius-md);
  border: 1px dashed var(--v3-border-strong);
  background: var(--v3-surface-muted);
  color: var(--v3-text-muted);
}

.v3-sh-error {
  margin: 0 0 var(--v3-space-4);
  padding: var(--v3-space-4);
  border-radius: var(--v3-radius-md);
  border: 1px solid var(--v3-border-strong);
  background: var(--v3-surface);
}

.v3-sh-error-title {
  margin: 0 0 var(--v3-space-1);
  font-weight: 700;
}

.v3-sh-error-detail {
  margin: 0;
  font-size: 0.82rem;
  color: var(--v3-text-muted);
  overflow-wrap: anywhere;
}

/* ---- explicit recovery control (P17C3B) -----------------------------------
 * The one data-changing action this page offers. Set apart from the
 * informational cards by an outline and a heading, not by colour: nothing
 * about it is an alarm, and it uses the shell's neutral tokens only.
 */

.v3-sh-recovery {
  margin: 0 0 var(--v3-space-4);
}

.v3-sh-action {
  max-width: 76ch;
  padding: var(--v3-space-4);
  border-radius: var(--v3-radius-md);
  border: 2px solid var(--v3-border-strong);
  background: var(--v3-surface);
}

.v3-sh-action-heading {
  margin-top: 0;
}

.v3-sh-action-text {
  margin: 0 0 var(--v3-space-3);
  line-height: 1.5;
}

.v3-sh-action-list {
  margin: 0 0 var(--v3-space-3);
}

.v3-sh-action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--v3-space-2);
}

.v3-sh-action .v3-button:focus-visible {
  outline: 2px solid var(--v3-focus-ring);
  outline-offset: 2px;
}

.v3-sh-action .v3-button[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ---- sections ----------------------------------------------------------- */

.v3-panel--system-health section {
  margin-bottom: var(--v3-space-6);
}

.v3-sh-heading {
  margin: 0 0 var(--v3-space-3);
  padding-bottom: var(--v3-space-2);
  border-bottom: 1px solid var(--v3-border);
  font-size: 1rem;
  font-weight: 700;
  color: var(--v3-text);
}

.v3-sh-subheading {
  margin: var(--v3-space-5) 0 var(--v3-space-2);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--v3-text);
}

.v3-sh-note {
  margin: 0 0 var(--v3-space-3);
  max-width: 82ch;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--v3-text-muted);
}

/* A limitation is set apart by a rule, not by a colour that implies alarm. */
.v3-sh-note--limitation {
  padding: var(--v3-space-2) var(--v3-space-3);
  border-left: 3px solid var(--v3-border-strong);
  background: var(--v3-surface-muted);
  border-radius: 0 var(--v3-radius-sm) var(--v3-radius-sm) 0;
}

.v3-sh-note-inline {
  display: inline-block;
  margin-left: var(--v3-space-1);
  font-size: 0.72rem;
  color: var(--v3-text-muted);
}

.v3-sh-list {
  margin: 0 0 var(--v3-space-3);
  padding-left: var(--v3-space-5);
  font-size: 0.82rem;
  color: var(--v3-text-muted);
}

.v3-sh-list li {
  margin-bottom: var(--v3-space-1);
}

/* ---- overview tiles ----------------------------------------------------- */

.v3-sh-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--v3-space-3);
}

.v3-sh-tile {
  display: flex;
  flex-direction: column;
  gap: var(--v3-space-1);
  padding: var(--v3-space-4);
  border-radius: var(--v3-radius-md);
  border: 1px solid var(--v3-border);
  background: var(--v3-surface);
  min-width: 0;
}

.v3-sh-tile-label {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--v3-text-muted);
}

.v3-sh-tile-value {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--v3-maroon);
  overflow-wrap: anywhere;
}

.v3-sh-tile-detail {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--v3-text-muted);
}

/* ---- roster reconciliation ---------------------------------------------- */

/* Shown only when the roster kept fewer records than it was handed. Set apart
   by a rule and a muted surface, exactly as a limitation note is -- it states
   an accounting fact, not a severity. */
.v3-sh-reconciliation {
  margin-top: var(--v3-space-3);
  padding: var(--v3-space-3) var(--v3-space-4);
  border-left: 3px solid var(--v3-border-strong);
  border-radius: 0 var(--v3-radius-sm) var(--v3-radius-sm) 0;
  background: var(--v3-surface-muted);
}

.v3-sh-reconciliation-headline {
  margin: 0 0 var(--v3-space-2);
  max-width: 82ch;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--v3-text);
}

.v3-sh-reconciliation .v3-sh-list {
  margin-bottom: var(--v3-space-2);
}

.v3-sh-reconciliation .v3-sh-note {
  margin-bottom: 0;
}

/* ---- persistence facts -------------------------------------------------- */

.v3-sh-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--v3-space-3);
  margin-bottom: var(--v3-space-4);
}

.v3-sh-fact {
  display: flex;
  flex-direction: column;
  gap: var(--v3-space-1);
  padding: var(--v3-space-4);
  border-radius: var(--v3-radius-md);
  border: 1px solid var(--v3-border);
  background: var(--v3-surface);
  min-width: 0;
}

/* Storage that cannot be reached. The card also reads "Not reachable". */
.v3-sh-fact--absent {
  border-left: 3px solid var(--v3-border-strong);
  background: var(--v3-surface-muted);
}

.v3-sh-fact-label {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--v3-text-muted);
}

.v3-sh-fact-value {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--v3-text);
  overflow-wrap: anywhere;
}

.v3-sh-fact-detail {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--v3-text-muted);
}

/* ---- tables ------------------------------------------------------------- */

.v3-sh-table-wrap {
  overflow-x: auto;
  max-width: 100%;
  margin-bottom: var(--v3-space-4);
}

.v3-sh-table-wrap:focus-visible {
  outline: 2px solid var(--v3-focus-ring);
  outline-offset: 2px;
}

.v3-sh-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.v3-sh-table caption {
  margin-bottom: var(--v3-space-2);
  max-width: 82ch;
  text-align: left;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--v3-text-muted);
}

.v3-sh-table th,
.v3-sh-table td {
  padding: var(--v3-space-2);
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--v3-border);
}

.v3-sh-table thead th {
  background: var(--v3-surface);
  color: var(--v3-text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Row headers wrap on word boundaries and keep an intrinsic width, so a long
   athlete name neither breaks mid-word nor collapses its column. */
.v3-sh-table tbody th {
  font-weight: 600;
  color: var(--v3-text);
  overflow-wrap: break-word;
  min-width: 9rem;
}

.v3-sh-table tbody td {
  color: var(--v3-text);
}

.v3-sh-table--compact th,
.v3-sh-table--compact td {
  padding: var(--v3-space-1) var(--v3-space-2);
}

.v3-sh-numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* A filename comes from an imported file and can be arbitrarily long. */
.v3-sh-filename,
.v3-sh-key,
.v3-sh-record-key {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  overflow-wrap: anywhere;
}

.v3-sh-record-key {
  margin: 0;
  color: var(--v3-text-muted);
}

.v3-sh-stamp {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.v3-sh-stamp--unreadable {
  white-space: normal;
  overflow-wrap: anywhere;
}

/* A system with no records at all. The cell also reads "No canonical records". */
.v3-sh-row--no-records {
  background: var(--v3-surface-muted);
}

.v3-sh-outcome {
  display: inline-block;
  white-space: nowrap;
}

/* A stored outcome of "failure". The cell also reads "Failure". */
.v3-sh-outcome--failure {
  padding: 0 var(--v3-space-1);
  border-left: 3px solid var(--v3-border-strong);
  background: var(--v3-surface-muted);
}

/* ---- links -------------------------------------------------------------- */

.v3-sh-link {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--v3-maroon);
  text-align: left;
  text-decoration: underline;
  cursor: pointer;
  overflow-wrap: break-word;
}

.v3-sh-link:hover {
  color: var(--v3-maroon-dark);
}

.v3-sh-link:focus-visible {
  outline: 2px solid var(--v3-focus-ring);
  outline-offset: 2px;
}

/* ---- disclosures -------------------------------------------------------- */

.v3-sh-details {
  font-size: 0.78rem;
}

.v3-sh-details > summary {
  cursor: pointer;
  color: var(--v3-maroon);
}

.v3-sh-details > summary:focus-visible {
  outline: 2px solid var(--v3-focus-ring);
  outline-offset: 2px;
}

.v3-sh-details[open] > summary {
  margin-bottom: var(--v3-space-2);
}

.v3-sh-source-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--v3-space-2);
  margin: 0;
  padding: var(--v3-space-3);
  border-radius: var(--v3-radius-sm);
  background: var(--v3-surface-muted);
}

.v3-sh-source-row > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.v3-sh-source-row dt {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--v3-text-muted);
}

.v3-sh-source-row dd {
  margin: 0;
  font-size: 0.78rem;
  color: var(--v3-text);
  overflow-wrap: anywhere;
}

.v3-sh-candidates {
  margin: 0;
  padding-left: var(--v3-space-5);
}

.v3-sh-candidates li {
  margin-bottom: var(--v3-space-1);
}

.v3-sh-candidate-name {
  font-weight: 600;
  overflow-wrap: break-word;
}

.v3-sh-candidate-meta {
  margin-left: var(--v3-space-2);
  color: var(--v3-text-muted);
}

.v3-sh-warnings {
  margin: 0;
  padding-left: var(--v3-space-5);
  color: var(--v3-text-muted);
}

.v3-sh-reason,
.v3-sh-error-detail {
  margin: 0;
  max-width: 82ch;
  line-height: 1.5;
  color: var(--v3-text-muted);
  overflow-wrap: anywhere;
}

/* ---- review sections ---------------------------------------------------- */

.v3-sh-review-system {
  margin-bottom: var(--v3-space-5);
  padding: var(--v3-space-4);
  border-radius: var(--v3-radius-md);
  border: 1px solid var(--v3-border);
  background: var(--v3-surface);
  min-width: 0;
}

.v3-sh-review-system .v3-sh-subheading {
  margin-top: 0;
}

/* ---- governance --------------------------------------------------------- */

.v3-sh-gov-label {
  display: block;
  font-weight: 700;
}

.v3-sh-gov-description {
  display: block;
  margin-top: 2px;
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.45;
  color: var(--v3-text-muted);
}

/* Unresolved configuration is set apart the same way a limitation is: a rule
   and a muted surface. It reads "Not resolved for production" either way. */
.v3-sh-gov--unresolved {
  background: var(--v3-surface-muted);
}

/* ---- limitations -------------------------------------------------------- */

.v3-sh-limitations {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--v3-space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.v3-sh-limitations li {
  display: flex;
  flex-direction: column;
  gap: var(--v3-space-1);
  padding: var(--v3-space-4);
  border-radius: var(--v3-radius-md);
  border: 1px solid var(--v3-border);
  background: var(--v3-surface);
  min-width: 0;
}

.v3-sh-limitation-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--v3-text);
}

.v3-sh-limitation-detail {
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--v3-text-muted);
}

/* ---- responsive --------------------------------------------------------- */

@media (max-width: 720px) {
  .v3-sh-tiles,
  .v3-sh-facts,
  .v3-sh-limitations {
    grid-template-columns: 1fr;
  }

  .v3-sh-source-row {
    grid-template-columns: 1fr;
  }

  .v3-sh-review-system {
    padding: var(--v3-space-3);
  }
}
