/*
 * .seq-console — the log viewer (docs/design-system/component-inventory.md, "Console").
 *
 * A fixed-height mono block at --text-fine on --console-surface in --console-ink, with a
 * line-number gutter, a persistent header carrying the job_log artifact link and a copyable
 * line range, and an --excerpt variant trimmed to the log excerpt with a control that opens
 * the whole console. The real app pages or virtualises .seq-console__lines; the markup is one
 * .seq-console__line per rendered line with the absolute line number on data-line, so a page
 * that starts at line 41 000 numbers itself correctly without CSS counters.
 *
 * Markup:
 *   <div class="seq-console">
 *     <div class="seq-console__header">
 *       <a class="seq-console__artifact-link" href="...">job_log · artifacts #91</a>
 *       <span class="seq-console__count">41 208 lines · showing 1–40</span>
 *       <span class="seq-console__range">lines <code>1–40</code> <button class="seq-copy ...">copy</button></span>
 *     </div>
 *     <div class="seq-console__lines" tabindex="0">
 *       <div class="seq-console__line" data-line="1">...</div>
 *       <div class="seq-console__line seq-console__line--exit" data-line="40">exit status 1</div>
 *     </div>
 *     <div class="seq-console__footer">...open the whole console...</div>   (--excerpt only)
 *   </div>
 */

.seq-console {
  --console-lines-height: var(--console-height);
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: var(--stroke-weight-1) solid var(--border-default);
  border-radius: var(--corner-radius-xs);
  background: var(--console-surface);
  color: var(--console-ink);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-12);
  font-weight: var(--font-weight-400);
  font-variant-numeric: var(--numerals);
  line-height: 1.5;
}

/* ---------- Persistent header: artifact link left, copyable range right ---------- */
.seq-console__header,
.seq-console__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--spacing-8) var(--spacing-16);
  padding: var(--spacing-8) var(--spacing-12);
  background: var(--background-surface-1);
}
.seq-console__header {
  border-block-end: var(--stroke-weight-1) solid var(--border-subtle);
}
.seq-console__footer {
  border-block-start: var(--stroke-weight-1) solid var(--border-subtle);
}

.seq-console__artifact-link {
  color: var(--text-primary);
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: var(--underline-offset);
}
.seq-console__artifact-link:hover {
  text-decoration-color: currentColor;
}

/* Touch: the artifact link in the header and footer is one line of fine data, about 18px; on
   a coarse pointer a transparent ::before makes it at least 44 by 44 without moving it. */
@media (pointer: coarse) {
  .seq-console__artifact-link {
    position: relative;
  }
  .seq-console__artifact-link::before {
    content: "";
    position: absolute;
    inset: min(0px, calc((100% - 44px) / 2));
  }
}

/* The line count and the window shown, between the link and the range. */
.seq-console__count {
  color: var(--text-secondary);
}

.seq-console__range {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-8);
  margin-inline-start: auto;
  color: var(--text-secondary);
}
.seq-console__range code {
  color: var(--text-primary);
}

/* ---------- The lines: fixed height, scrollable, keyboard focusable ---------- */
.seq-console__lines {
  height: var(--console-lines-height);
  overflow: auto;
  margin: 0;
  padding-block: var(--spacing-8);
  overscroll-behavior: contain;
}

/* One line: gutter with the absolute line number, then the text preserved verbatim. */
.seq-console__line {
  display: grid;
  grid-template-columns: 6ch minmax(0, 1fr);
  column-gap: var(--spacing-12);
  padding-inline-end: var(--spacing-12);
  white-space: pre;
}
.seq-console__line::before {
  content: attr(data-line) / "";            /* alternative text empty: the gutter number is not read aloud */
  text-align: end;
  padding-inline: var(--spacing-8);
  color: var(--text-secondary);             /* the number is content the range readout depends on: 6.39:1 */
  border-inline-end: var(--stroke-weight-1) solid var(--border-subtle);
  user-select: none;
}
.seq-console__line:hover {
  background: var(--background-hover);
}

/* A line inside the selected (copyable) range: the changed-wash tint plus a solid gutter rule. */
.seq-console__line.is-selected {
  background: var(--wash-changed);
}
.seq-console__line.is-selected::before {
  color: var(--text-primary);
  border-inline-end-color: var(--border-strong);
}

/* The final "exit status N" line of a failed attempt: the failed state's colour, and the text itself names
   the code so the state survives without color. */
.seq-console__line--exit {
  color: var(--state-failed);
}

/* Lines written to stderr carry a "!" after the line number as well as secondary ink. */

/* ---------- --excerpt: trimmed to the log excerpt, with a control to open the whole console ---------- */
.seq-console--excerpt {
  --console-lines-height: auto;
}
.seq-console--excerpt .seq-console__lines {
  max-height: var(--console-excerpt-height);
}
.seq-console__open {
  margin-inline-start: auto;
}

/* ---------- On paper: the first 200 lines, unscrolled, and a sentence saying so ----------
   The fixed height is on .seq-console__lines, so that is what opens up. */
@media print {
  .seq-console__lines {
    height: auto;
    max-height: none;
    overflow: visible;
  }
  .seq-console__line:nth-of-type(n + 201) {
    display: none;
  }
  .seq-console__line:nth-of-type(200)::after {
    content: " — lines beyond 200 are not printed; the full job_log artifact is linked above.";
    color: var(--text-secondary);
  }
}
