/*
 * Candidate reusable TUI component library.
 *
 * The live catalogue is the logical /dev/ route (hash route #/dev/).
 * Components here stay on the IBM EGA 8x14 cell grid and use only the site's
 * existing eight-colour palette. The catalogue deliberately exposes several
 * authentic text-mode families so one can later be promoted to the site-wide
 * canonical language without inventing feature-local styling.
 */

/* Dev-catalogue scaffolding. These selectors describe the laboratory page, not
 * public content semantics. */
.ui-component-catalog .ui-component {
  margin-bottom: calc(2 * var(--cell-h));
}

.ui-component-catalog .ui-component:last-child {
  margin-bottom: 0;
}

.ui-component-id {
  margin-bottom: 0 !important;
  color: var(--cyan);
}

.ui-component-use {
  color: var(--white);
}

.ui-component-example {
  margin-bottom: var(--cell-h);
}

.ui-component-compact {
  margin-bottom: 0 !important;
}

/* -------------------------------------------------------------------------
 * Heading families
 * ------------------------------------------------------------------------- */

.tui-title-bar,
.tui-title-frame,
.tui-section-bracket {
  margin: 0 0 var(--cell-h);
  font: inherit;
  font-weight: 400;
}

.document .tui-title-bar::before,
.document .tui-title-bar::after,
.document .tui-title-frame::before,
.document .tui-title-frame::after,
.document .tui-section-bracket::before,
.document .tui-section-bracket::after {
  font: inherit;
}

.tui-title-bar {
  display: block;
  overflow: hidden;
  padding: 0 1ch;
  background: var(--blue);
  color: var(--yellow);
  white-space: nowrap;
}

.document .tui-title-bar::before,
.document .tui-title-bar::after {
  content: none;
}

.tui-title-frame {
  color: var(--yellow);
}

.document .tui-title-frame::before {
  content: "\250c\2500 ";
  color: var(--green);
}

.document .tui-title-frame::after {
  content: " \2500\2510";
  color: var(--green);
}

.tui-section-bracket {
  color: var(--yellow);
}

.document .tui-section-bracket::before {
  content: "[ ";
  color: var(--cyan);
}

.document .tui-section-bracket::after {
  content: " ]";
  color: var(--cyan);
}

/* -------------------------------------------------------------------------
 * Rules and separators
 * ------------------------------------------------------------------------- */

.tui-rule,
.tui-rule-double {
  width: 100%;
  height: var(--cell-h);
  margin: 0 0 var(--cell-h);
  overflow: hidden;
  white-space: nowrap;
}

.tui-rule {
  color: var(--green);
}

.tui-rule-double {
  color: var(--cyan);
}

.tui-rule::before {
  content: "\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500\2500";
}

.tui-rule-double::before {
  content: "\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550\2550";
}

/* -------------------------------------------------------------------------
 * List families
 * ------------------------------------------------------------------------- */

.tui-list-bullet,
.tui-list-dash,
.tui-list-pointer,
.tui-list-index,
.tui-tree,
.tui-choice-list {
  padding-left: 0 !important;
  list-style: none;
}

.tui-list-bullet li,
.tui-list-dash li,
.tui-list-pointer li,
.tui-list-index li,
.tui-tree li {
  position: relative;
  padding-left: 3ch;
}

.tui-list-bullet li::before,
.tui-list-dash li::before,
.tui-list-pointer li::before,
.tui-list-index li::before,
.tui-tree li::before {
  position: absolute;
  left: 0;
  white-space: pre;
}

.tui-list-bullet li::before {
  content: "\2022 ";
  color: var(--white);
}

.tui-list-dash li::before {
  content: "- ";
  color: var(--magenta);
}

.tui-list-pointer li::before {
  content: "> ";
  color: var(--green);
}

.tui-list-index {
  counter-reset: tui-index;
}

.tui-list-index li {
  counter-increment: tui-index;
  padding-left: 5ch;
}

.tui-list-index li::before {
  content: "[" counter(tui-index, decimal-leading-zero) "] ";
  color: var(--cyan);
}

.tui-tree .tui-tree-branch::before {
  content: "\251c\2500 ";
  color: var(--green);
}

.tui-tree .tui-tree-last::before {
  content: "\2514\2500 ";
  color: var(--green);
}

.tui-choice-list li {
  display: grid;
  grid-template-columns: 2ch minmax(0, 1fr);
  min-height: var(--cell-h);
}

.tui-choice-list li::before {
  content: "  ";
  white-space: pre;
}

.tui-choice-list li[data-selected="true"] {
  background: var(--cyan);
  color: var(--black);
}

.tui-choice-list li[data-selected="true"]::before {
  content: "> ";
  color: var(--black);
}

/* -------------------------------------------------------------------------
 * Records, metadata and tabular text
 * ------------------------------------------------------------------------- */

.tui-kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0 2ch;
  padding: 0;
}

.tui-kv dt {
  color: var(--green);
  text-align: right;
}

.tui-kv dd {
  min-width: 0;
  margin: 0;
}

/*
 * Opt-in single-pair key/value treatment promoted from the /dev laboratory for
 * records whose labels and values share one green/black channel pair. The key
 * owns inverse video until either half of that row is highlighted; then inverse
 * video transfers to the actionable value while the key returns to normal video.
 */
.tui-kv--single-pair {
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0 1ch;
  color: var(--green);
}

.tui-kv--single-pair dt {
  align-self: start;
  height: var(--cell-h);
  padding: 0 1ch;
  background: var(--green);
  color: var(--black);
  text-align: left;
  white-space: nowrap;
}

.tui-kv--single-pair dt a {
  --pair-foreground: var(--black);
  --pair-background: var(--green);
  display: block;
  height: var(--cell-h);
  margin: 0 -1ch;
  padding: 0 1ch;
  background: transparent !important;
  color: inherit !important;
  text-decoration: none;
}

.tui-kv--single-pair dd {
  color: var(--green);
}

/*
 * The value hit-field reaches one cell back across the grid gap and adds one
 * cell after the visible value. Its text therefore stays in the same column,
 * while active inverse video covers "gap + value + trailing cell" as one field.
 */
.tui-kv--single-pair dd a {
  --pair-foreground: var(--green);
  --pair-background: var(--black);
  display: inline-block;
  margin-left: -1ch;
  padding: 0 1ch;
  background: var(--black) !important;
  color: var(--green) !important;
}

.tui-kv--single-pair dd a:hover,
.tui-kv--single-pair dd a:focus-visible {
  background: var(--green) !important;
  color: var(--black) !important;
}

.tui-kv--single-pair dt:has(a:hover) + dd a,
.tui-kv--single-pair dt:has(a:focus-visible) + dd a {
  background: var(--green) !important;
  color: var(--black) !important;
}

.tui-kv--single-pair dt:has(+ dd a:hover),
.tui-kv--single-pair dt:has(+ dd a:focus-visible) {
  background: var(--black) !important;
  color: var(--green) !important;
}

.tui-kv--single-pair dt:has(a:hover),
.tui-kv--single-pair dt:has(a:focus-visible) {
  background: var(--black) !important;
  color: var(--green) !important;
}

.terminal:has(.tui-kv--single-pair) {
  container-name: tui-kv-terminal;
  container-type: inline-size;
}

@container tui-kv-terminal (max-width: 383px) {
  .tui-kv--single-pair dt {
    grid-column: 1;
  }

  .tui-kv--single-pair dd {
    grid-column: 1 / -1;
  }

  .tui-kv--single-pair dd a {
    margin-left: 0;
    padding-left: 0;
  }
}

.tui-table {
  width: 100%;
  margin: 0 0 var(--cell-h);
  border-collapse: collapse;
  border-spacing: 0;
  font: inherit;
}

.tui-table th,
.tui-table td {
  padding: 0 2ch 0 0;
  text-align: left;
  vertical-align: top;
  font: inherit;
  font-weight: 400;
}

.tui-table th {
  background: var(--white);
  color: var(--black);
}

.tui-table tbody tr[data-selected="true"] {
  background: var(--cyan);
  color: var(--black);
}

/* -------------------------------------------------------------------------
 * Inline status, keys and messages
 * ------------------------------------------------------------------------- */

.tui-tag,
.tui-key {
  display: inline-block;
  padding: 0 1ch;
  font: inherit;
  font-weight: 400;
}

.tui-tag {
  background: var(--cyan);
  color: var(--black);
}

.tui-tag--warn {
  background: var(--yellow);
  color: var(--black);
}

.tui-tag--error {
  background: var(--red);
  color: var(--white);
}

.tui-key {
  background: var(--white);
  color: var(--black);
}

.tui-message {
  margin: 0 0 var(--cell-h);
  color: var(--white);
}

.tui-message::before {
  content: "[INFO] ";
  color: var(--cyan);
}

.tui-message--note::before {
  content: "[NOTE] ";
  color: var(--yellow);
}

.tui-message--warn::before {
  content: "[WARN] ";
  color: var(--yellow);
}

.tui-message--error::before {
  content: "[ERR ] ";
  color: var(--red);
}
