/*
 * Stoei Core — code box: a command, cron line, file path, key or snippet
 * in a box with a Copy button at the top right. Shared by websites, the
 * Stoei CMS admin and apps. Load after tokens.css and base.css.
 *
 *   PHP:  echo stoei_code_box($text, ['label' => 'Copy command']);
 *         (php/stoei-code-box.php writes the markup below)
 *   <div class="st-code" data-st-code>
 *     <pre class="st-code__text" tabindex="0"><code>…</code></pre>
 *     <button type="button" class="st-code__copy" aria-label="Copy command" hidden>…icons…
 *       <span class="st-code__done" aria-hidden="true">Copied</span></button>
 *     <span class="st-code__say visually-hidden" role="status"></span>
 *   </div>
 *
 * js/code-box.js shows the button (it stays hidden without the script; the
 * text can always be selected by hand), copies the exact text and shows
 * "Copied" for 2 seconds (data-st-copied on the box), also said aloud.
 * Long lines scroll sideways inside the box, never the page: a command must
 * stay one line, and a wrapped line looks like two (--st-code-wrap: pre-wrap
 * wraps them instead). .st-code--tall caps the
 * height (exports); taller text scrolls inside.
 *
 * Every look value is a --st-code-* setting in tokens.css.
 * Check: php tools/check-css.php
 */

.st-code {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start;
  min-width: 0; max-width: 100%; margin-block: var(--st-code-space);
  color: var(--st-code-color); background: var(--st-code-bg);
  border: var(--st-line-width) solid var(--st-code-line); border-radius: var(--st-code-radius);
}
.st-code__text {
  margin: 0; padding: var(--st-code-pad-y) var(--st-code-pad-x);
  overflow-x: auto; white-space: var(--st-code-wrap); overflow-wrap: anywhere; tab-size: 4;
  font-family: var(--st-code-font); font-size: var(--st-code-text); line-height: var(--st-code-leading);
  color: inherit; background: none; border-radius: var(--st-code-radius);
}
.st-code__text code { font: inherit; color: inherit; background: none; padding: 0; border-radius: 0; }
.st-code--tall .st-code__text { max-height: var(--st-code-max-height); overflow-y: auto; }

.st-code__copy:not([hidden]) {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--st-code-gap);
  min-width: var(--st-code-button-size); min-height: var(--st-code-button-size);
  margin: var(--st-code-gap); padding: 0 var(--st-code-gap);
  color: var(--st-code-button-color); background: none; border: 0; border-radius: var(--st-code-radius);
  font: inherit; font-size: var(--st-text-caption); font-weight: var(--st-weight-strong); cursor: pointer;
}
.st-code__copy:hover { color: var(--st-code-color); background: var(--st-color-icon-hover); }
.st-code__copy svg { width: 18px; height: 18px; flex: none; }
.st-code__tick, .st-code__done { display: none; }
.st-code[data-st-copied] .st-code__copy { color: var(--st-code-done-color); }
.st-code[data-st-copied] .st-code__icon { display: none; }
.st-code[data-st-copied] .st-code__tick { display: block; }
.st-code[data-st-copied] .st-code__done { display: inline; }
.st-code[data-st-copied="selected"] .st-code__copy { color: var(--st-code-color); }
.st-code[data-st-copied="selected"] .st-code__icon { display: block; }
.st-code[data-st-copied="selected"] .st-code__tick { display: none; }

/* <code> inside a sentence: the same family of colors, no button. */
:where(code:not(.st-code code)) {
  font-family: var(--st-code-font); font-size: var(--st-text-code);
  background: var(--st-code-inline-bg); padding: var(--st-code-inline-pad); border-radius: var(--st-code-inline-radius);
  overflow-wrap: anywhere;
}
