/*
 * Version 3 -- Reports workspace, on screen and on paper.
 *
 * Two presentations of one document. The screen rules build a configuration
 * form beside a live preview; the `@media print` block at the end strips the
 * application away and lets the same markup flow onto pages. No second
 * renderer, no canvas, no image -- what prints is the semantic HTML the
 * preview shows, which is the only way the two can be guaranteed to agree.
 *
 * Nothing here is coloured by outcome. A report has no governed status to
 * express, and `MISSION_CONTROL_SPEC.md` §7 forbids an unexplained colour
 * anywhere in this application.
 */

/* ---- panel width --------------------------------------------------------- */

/*
 * The shell caps a panel at 760px, which suits a form and a short prose page.
 * A report is a document with a wide table -- a hundred athletes across five
 * systems -- and at 760px it rendered into a narrow column with two thirds of a
 * desktop viewport left empty. Widened here rather than in the shell, so no
 * other page's layout changes.
 */
.v3-panel--reports {
  max-width: 1240px;
}

/* ---- status and error --------------------------------------------------- */

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

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

.v3-rpt-error p {
  margin: 0 0 var(--v3-space-1);
}

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

/* ---- configuration form ------------------------------------------------- */

.v3-rpt-configuration {
  padding: var(--v3-space-4);
  margin-bottom: var(--v3-space-5);
  border-radius: var(--v3-radius-md);
  border: 1px solid var(--v3-border);
  background: var(--v3-surface-muted);
}

.v3-rpt-config-heading,
.v3-rpt-preview-heading {
  margin: 0 0 var(--v3-space-3);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--v3-text);
}

.v3-rpt-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--v3-space-3);
  margin-bottom: var(--v3-space-3);
}

.v3-rpt-field {
  display: flex;
  flex-direction: column;
  gap: var(--v3-space-1);
  min-width: 0;
  flex: 1 1 12rem;
}

.v3-rpt-field label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--v3-text-muted);
}

.v3-rpt-field select,
.v3-rpt-field input {
  min-width: 0;
  width: 100%;
}

.v3-rpt-field select:focus-visible,
.v3-rpt-field input:focus-visible,
.v3-rpt-check input:focus-visible {
  outline: 2px solid var(--v3-focus-ring);
  outline-offset: 2px;
}

.v3-rpt-sections {
  display: flex;
  flex-wrap: wrap;
  gap: var(--v3-space-3);
  margin: 0 0 var(--v3-space-3);
  padding: var(--v3-space-3);
  border-radius: var(--v3-radius-sm);
  border: 1px solid var(--v3-border);
  background: var(--v3-surface);
}

.v3-rpt-sections legend {
  padding: 0 var(--v3-space-1);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--v3-text-muted);
}

.v3-rpt-check {
  display: flex;
  align-items: center;
  gap: var(--v3-space-1);
  font-size: 0.82rem;
  color: var(--v3-text);
  cursor: pointer;
}

.v3-rpt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--v3-space-2);
}

/* ---- the report document ------------------------------------------------ */

.v3-rpt-document {
  display: block;
  padding: var(--v3-space-5);
  border-radius: var(--v3-radius-md);
  border: 1px solid var(--v3-border);
  background: var(--v3-surface);
}

.v3-rpt-empty {
  padding: var(--v3-space-4);
  border-radius: var(--v3-radius-md);
  border: 1px dashed var(--v3-border-strong);
  background: var(--v3-surface-muted);
  color: var(--v3-text-muted);
}

.v3-rpt-empty p {
  margin: 0;
  max-width: 64ch;
}

/* ---- report header ------------------------------------------------------ */

.v3-rpt-header {
  padding-bottom: var(--v3-space-3);
  margin-bottom: var(--v3-space-4);
  border-bottom: 2px solid var(--v3-maroon);
}

.v3-rpt-eyebrow {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--v3-text-muted);
}

.v3-rpt-title {
  margin: var(--v3-space-1) 0 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--v3-maroon);
}

.v3-rpt-subject {
  margin: 2px 0 var(--v3-space-3);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--v3-text);
  overflow-wrap: anywhere;
}

.v3-rpt-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--v3-space-4);
  margin: 0;
}

.v3-rpt-meta > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.v3-rpt-meta dt {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--v3-text-muted);
}

.v3-rpt-meta dd {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--v3-text);
}

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

.v3-rpt-section {
  margin-bottom: var(--v3-space-5);
}

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

.v3-rpt-note {
  margin: 0 0 var(--v3-space-2);
  max-width: 78ch;
  font-size: 0.8rem;
  color: var(--v3-text-muted);
}

/* ---- statistics --------------------------------------------------------- */

.v3-rpt-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--v3-space-3);
  margin: 0;
}

.v3-rpt-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--v3-space-3);
  border-radius: var(--v3-radius-sm);
  border: 1px solid var(--v3-border);
  background: var(--v3-surface-muted);
  min-width: 0;
}

.v3-rpt-stat dt {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--v3-text-muted);
}

.v3-rpt-stat dd {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--v3-maroon);
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.v3-rpt-stat-detail {
  margin: 0;
  font-size: 0.72rem;
  color: var(--v3-text-muted);
}

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

.v3-rpt-table-wrap {
  overflow-x: auto;
  max-width: 100%;
}

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

.v3-rpt-table caption {
  margin-bottom: var(--v3-space-2);
  text-align: left;
  font-size: 0.75rem;
  color: var(--v3-text-muted);
}

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

.v3-rpt-table thead th {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--v3-text-muted);
  border-bottom: 2px solid var(--v3-border-strong);
}

.v3-rpt-table tbody th {
  font-weight: 600;
  color: var(--v3-text);
  /*
   * `anywhere` was tried first and was wrong twice over: it broke names
   * mid-word ("Hargrov / e") and, because it also shrinks a column's
   * intrinsic width, it let the athlete column collapse to its narrowest
   * character. `break-word` breaks a word only when it cannot fit a line on
   * its own, which for an athlete name is effectively never.
   */
  overflow-wrap: break-word;
  min-width: 9rem;
}

.v3-rpt-table--athletes td,
.v3-rpt-table--athletes thead th {
  white-space: nowrap;
}

/* ---- findings ----------------------------------------------------------- */

.v3-rpt-group {
  margin-bottom: var(--v3-space-4);
}

.v3-rpt-group-heading {
  margin: 0 0 var(--v3-space-1);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--v3-text);
}

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

.v3-rpt-finding {
  display: flex;
  flex-direction: column;
  gap: var(--v3-space-1);
  padding: var(--v3-space-3);
  border-radius: var(--v3-radius-sm);
  border: 1px solid var(--v3-border);
  background: var(--v3-surface-muted);
  min-width: 0;
}

.v3-rpt-finding-system {
  margin: 0;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--v3-text-muted);
}

.v3-rpt-finding-title {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--v3-text);
  overflow-wrap: anywhere;
}

.v3-rpt-finding-outcome,
.v3-rpt-finding-value,
.v3-rpt-finding-reason,
.v3-rpt-finding-confidence {
  margin: 0;
  font-size: 0.78rem;
  color: var(--v3-text-muted);
}

.v3-rpt-finding-value strong {
  color: var(--v3-maroon);
}

.v3-rpt-basis > summary {
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--v3-maroon);
}

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

.v3-rpt-basis-list {
  display: grid;
  gap: 2px;
  margin: var(--v3-space-1) 0 0;
}

.v3-rpt-basis-list > div {
  display: flex;
  justify-content: space-between;
  gap: var(--v3-space-3);
  font-size: 0.75rem;
}

.v3-rpt-basis-list dt {
  margin: 0;
  color: var(--v3-text-muted);
}

.v3-rpt-basis-list dd {
  margin: 0;
  font-weight: 600;
  color: var(--v3-text);
  text-align: right;
  overflow-wrap: anywhere;
}

/* ---- limitations and routes --------------------------------------------- */

.v3-rpt-limitations {
  margin: 0;
  padding-left: var(--v3-space-4);
  max-width: 78ch;
}

.v3-rpt-limitations li {
  font-size: 0.8rem;
  color: var(--v3-text-muted);
  margin-bottom: var(--v3-space-1);
}

.v3-rpt-routes-wrap {
  margin-top: var(--v3-space-4);
}

.v3-rpt-routes {
  display: flex;
  flex-wrap: wrap;
  gap: var(--v3-space-2);
}

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

@media (max-width: 720px) {
  .v3-rpt-fields,
  .v3-rpt-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .v3-rpt-field {
    flex: 1 1 auto;
  }

  .v3-rpt-stats,
  .v3-rpt-findings {
    grid-template-columns: 1fr;
  }

  .v3-rpt-basis-list > div {
    flex-direction: column;
    gap: 2px;
  }

  .v3-rpt-basis-list dd {
    text-align: left;
  }
}

/* -------------------------------------------------------------------------
 * PRINT
 *
 * The application disappears and the report becomes the page. Paper size and
 * margins are left to the browser's own dialog rather than hard-coded, because
 * a coach printing on A4 and one printing on Letter both need this to work and
 * neither told us which they have.
 * ---------------------------------------------------------------------------
 */

@media print {
  /*
   * The shell is chrome. None of it belongs on paper.
   *
   * `.v3-header` is the application's own title bar and carries the Import
   * roster / Import data buttons -- printing those onto a coaching report was
   * caught by rendering the page, not by reading this file. `.v3-panel-intro`
   * is listed by its current name: it was `.v3-panel-status` until the intro
   * paragraph got a class of its own, and the stale selector silently stopped
   * matching, which is the same lesson twice.
   */
  .v3-sidebar,
  .v3-header,
  .v3-filter-bar,
  .v3-rpt-configuration,
  .v3-rpt-routes-wrap,
  .v3-rpt-status,
  .v3-panel--reports > .v3-panel-intro,
  .v3-rpt-preview-heading {
    display: none !important;
  }

  /* Every other panel is already `hidden`; this makes certain of it. */
  .v3-panel[hidden] {
    display: none !important;
  }

  .v3-shell,
  .v3-main,
  .v3-panel--reports {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }

  /* The panel's own <h2> would duplicate the report title. */
  .v3-panel--reports > h2 {
    display: none !important;
  }

  .v3-rpt-document {
    padding: 0 !important;
    border: 0 !important;
    background: #fff !important;
  }

  /* Ink economy, and legibility on paper. */
  .v3-rpt-stat,
  .v3-rpt-finding {
    background: #fff !important;
    border: 1px solid #999 !important;
  }

  .v3-rpt-title,
  .v3-rpt-stat dd,
  .v3-rpt-finding-value strong {
    color: #000 !important;
  }

  .v3-rpt-header {
    border-bottom: 2px solid #000 !important;
  }

  .v3-rpt-table thead th {
    border-bottom: 2px solid #000 !important;
  }

  /* A wide table must wrap onto paper rather than scroll off it. */
  .v3-rpt-table-wrap {
    overflow: visible !important;
    max-width: none !important;
  }

  .v3-rpt-table--athletes td,
  .v3-rpt-table--athletes thead th {
    white-space: normal !important;
  }

  /* A section should not be split across a page break if it can be helped,
     and a table's header should repeat when a long one has to be. */
  .v3-rpt-section {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .v3-rpt-header,
  .v3-rpt-stat,
  .v3-rpt-finding,
  .v3-rpt-table tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .v3-rpt-table thead {
    display: table-header-group;
  }

  /* A long athlete table is allowed to break -- forbidding it would push a
     hundred rows onto one impossible page. */
  .v3-rpt-section:has(.v3-rpt-table--athletes) {
    break-inside: auto;
    page-break-inside: auto;
  }

  .v3-rpt-section-heading {
    break-after: avoid;
    page-break-after: avoid;
  }

  /* The Data Basis disclosure is rendered open, but a browser honouring the
     attribute rather than the markup gets it forced open here too. */
  .v3-rpt-basis > summary {
    color: #000 !important;
  }

  details.v3-rpt-basis > * {
    display: revert !important;
  }
}
