/* Presents stored screener JSON as an inspectable, editable definition document. */
.definition-document {
  max-height: 40rem;
  padding: var(--space-7);
  overflow: auto;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  margin: 0;
  background: var(--color-surface-muted);
  color: var(--color-heading);
  font-size: var(--font-size-md);
  line-height: 1.6;
  white-space: pre-wrap;
}

.workflow-steps {
  display: grid;
  gap: var(--space-5);
  max-width: var(--copy-width);
  padding-left: var(--space-9);
  margin: var(--space-8) 0 0;
}

.screener-resources {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: var(--space-6);
  padding-block: var(--space-6);
  color: var(--color-text-muted);
}

.screener-save-form {
  display: flex;
  align-items: end;
  gap: var(--space-4);
}

@scope (.screener-save-form) {
  .field {
    min-width: min(22rem, 45vw);
  }
}

.screener-index-actions {
  display: flex;
  justify-content: flex-end;
  padding-block: var(--space-6);
}

/* Keeps cohort scope compact so the report begins near the top of the viewport. */
.performance-filters {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-5) var(--space-7);
  padding: var(--space-6);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-6);
  background: var(--color-surface);
  box-shadow: var(--shadow-panel);
}

@scope (.performance-filters) {
  > header {
    display: flex;
    grid-column: 1 / -1;
    align-items: end;
    justify-content: space-between;
    gap: var(--space-7);
    padding-bottom: var(--space-5);
    border-bottom: var(--border-width) solid var(--color-border);
  }

  h2,
  p {
    margin: 0;
  }

  header p {
    margin-top: var(--space-1);
    color: var(--color-text-faint);
    font-size: var(--font-size-sm);
  }

  header p strong {
    color: var(--color-heading);
  }

  header nav {
    display: flex;
    max-width: 100%;
    gap: var(--space-2);
    overflow-x: auto;
  }

  header nav a {
    display: grid;
    flex: 0 0 auto;
    gap: var(--space-1);
    padding: var(--space-3) var(--space-4);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-heading);
    text-decoration: none;
  }

  header nav a[aria-current="page"] {
    border-color: var(--color-accent-strong);
    background: var(--color-surface-strong);
  }

  header nav span {
    color: var(--color-text-faint);
    font-size: var(--font-size-xs);
  }

  fieldset {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-4);
    min-width: 0;
    padding: 0;
    border: 0;
    margin: 0;
  }

  legend {
    grid-column: 1 / -1;
    margin-bottom: var(--space-1);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    font-weight: 750;
  }

  :is(fieldset, details > div) label {
    display: grid;
    gap: var(--space-1);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    font-weight: 750;
  }

  label small {
    color: var(--color-text-faint);
    font-weight: 500;
  }

  :is(input[type="date"], input[type="number"]) {
    width: 100%;
    min-width: 0;
    min-height: var(--control-height);
    padding: var(--space-3) var(--space-4);
    border: var(--border-width) solid var(--color-border-strong);
    border-radius: var(--radius-md);
    background: var(--color-surface-strong);
    color: var(--color-heading);
  }

  footer {
    display: flex;
    align-items: end;
  }

  details {
    grid-column: 1 / -1;
    padding-top: var(--space-4);
    border-top: var(--border-width) solid var(--color-border);
  }

  summary {
    color: var(--color-heading);
    font-size: var(--font-size-md);
    font-weight: 750;
    cursor: pointer;
  }

  details > div {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-4);
    padding-top: var(--space-4);
  }
}

/* Prioritizes one compact result table and one inspectable discovery table. */
.screener-performance {
  display: grid;
  gap: var(--space-6);
}

@scope (.screener-performance) {
  .data-table[data-kind="performance-summary"] {
    min-width: 0;
    table-layout: fixed;
  }

  .data-table[data-kind="performance-summary"] :is(th, td) {
    padding-block: var(--space-5);
  }

  .data-table[data-kind="performance-summary"] :is(th, td):first-child {
    width: 60%;
  }

  .data-table[data-kind="performance-summary"] tr[data-emphasis="primary"] td:first-child,
  .data-table[data-kind="performance-summary"] tr[data-emphasis="primary"] td[data-numeric]:first-of-type {
    color: var(--color-heading);
    font-weight: 800;
  }

  .data-table[data-kind="performance-summary"] td[data-direction="1"] {
    color: var(--color-accent-strong);
    font-weight: 850;
  }

  .data-table[data-kind="performance-summary"] td[data-direction="-1"] {
    color: var(--color-danger);
    font-weight: 850;
  }

  .data-table[data-kind="performance-summary"] td[data-direction="0"] {
    color: var(--color-text-muted);
    font-weight: 750;
  }

  article > footer details {
    width: 100%;
  }

  article > footer summary {
    color: var(--color-text-muted);
    font-weight: 750;
    cursor: pointer;
  }

  article > footer details p {
    max-width: var(--copy-width);
    margin: var(--space-4) 0 0;
  }

  .performance-details > header p:last-child {
    margin-bottom: 0;
    color: var(--color-text-muted);
  }

  .performance-details > header p strong {
    color: var(--color-heading);
  }

  .performance-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-5);
    padding: var(--space-6) var(--space-fluid-card) 0;
    border-top: var(--border-width) solid var(--color-border);
    color: var(--color-text-muted);
  }

  .performance-pagination a {
    font-weight: 750;
    text-decoration: none;
  }
}

/* Preserves funnel direction while selecting the stage represented by the table. */
.performance-pipeline {
  width: 100%;
  padding: 0 var(--space-fluid-card) var(--space-5);
  border-bottom: var(--border-width) solid var(--color-border);
}

@scope (.performance-pipeline) {
  ol {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: var(--space-7);
    padding: 0;
    margin: 0;
    list-style: none;
  }

  li {
    position: relative;
    min-width: 0;
  }

  li:not(:last-child)::after {
    position: absolute;
    z-index: 1;
    top: 50%;
    right: calc(-1 * var(--space-6));
    color: var(--color-border-strong);
    content: "→";
    font-size: var(--font-size-lg);
    font-weight: 800;
    line-height: 1;
    transform: translate(50%, -50%);
  }

  a {
    display: grid;
    height: 100%;
    min-height: var(--control-height);
    align-content: center;
    gap: var(--space-1);
    padding: var(--space-4) var(--space-5);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface-muted);
    color: var(--color-text-muted);
    text-decoration: none;
  }

  a:hover,
  a:focus-visible {
    border-color: var(--color-accent-strong);
    background: var(--color-surface-strong);
    color: var(--color-heading);
  }

  a[aria-current="step"] {
    border-color: var(--color-accent-strong);
    background: var(--color-surface-strong);
    box-shadow: inset 0 calc(-1 * var(--space-1)) 0 var(--color-accent-strong);
    color: var(--color-heading);
  }

  strong {
    color: var(--color-heading);
    font-size: var(--font-size-h2);
    font-variant-numeric: tabular-nums;
    line-height: 1;
  }

  a[aria-current="step"] strong {
    color: var(--color-accent-strong);
  }

  span {
    font-size: var(--font-size-sm);
    line-height: 1.25;
  }
}

@media (max-width: 640px) {
  .screener-resources,
  .screener-save-form {
    align-items: stretch;
    flex-direction: column;
  }

  @scope (.screener-save-form) {
    .field {
      min-width: 0;
    }
  }

  .performance-filters {
    grid-template-columns: 1fr;
  }

  @scope (.performance-filters) {
    > header {
      align-items: stretch;
      flex-direction: column;
    }

    header nav {
      padding-bottom: var(--space-1);
    }

    footer,
    details {
      grid-column: 1;
    }

    footer input {
      width: 100%;
    }

    details > div {
      grid-template-columns: 1fr;
    }
  }

  @scope (.performance-pipeline) {
    ol {
      gap: var(--space-2);
    }

    li:not(:last-child)::after {
      right: calc(-1 * var(--space-1));
      font-size: var(--font-size-sm);
    }

    a {
      padding: var(--space-3) var(--space-1);
      text-align: center;
    }

    strong {
      font-size: var(--font-size-lg);
    }

    span {
      font-size: var(--font-size-xs);
      white-space: nowrap;
    }
  }
}
