/*
 * Stoei Core — controls: buttons, icon buttons, the light/dark switch, form
 * fields and the messages around them. Shared by websites and apps.
 *
 * Load after tokens.css and base.css, before web.css (websites) or stoei.css
 * (apps). One set of rules for both: the app look comes from settings in the
 * app's theme file (themes/app-starter.css sets the compact app sizes).
 *
 * Every look value comes from tokens.css; this file only reads settings.
 * Behaviour (live field checks, loading and "Saved" buttons, messages beside
 * buttons, the switch) is in js/stoei.js. Examples: test/index.html.
 * Check: php tools/check-css.php
 */

/* ---------- Buttons ----------
   <button class="st-btn st-btn--primary">Save</button>
   Kinds: --primary, --secondary, --ghost, --danger (outline), --danger-fill
   (solid, for the last step of a delete), --pill, --outline (no fill, takes
   the text colour of where it sits, like the light/dark switch: Log out in a
   dark top bar).
   Sizes: --sm, (normal), --lg. Shapes: --icon (a square for one sign such
   as an arrow; give it an aria-label), --block (full width).
   States: hover, keyboard focus (base.css ring), disabled, loading
   (aria-busy="true") and done (data-st-state="done"), set by stoei.js. */

.st-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--st-space-2);
  min-height: var(--st-button-height); padding: 0 var(--st-button-pad);
  border: var(--st-line-width) solid transparent; border-radius: var(--st-radius-control);
  font-family: inherit; font-size: var(--st-button-text); font-weight: var(--st-button-weight);
  line-height: var(--st-leading-tight); white-space: var(--st-button-wrap); text-align: center;
  text-decoration: none; cursor: pointer;
}
.st-btn:hover { text-decoration: none; }

.st-btn--sm { --st-button-height: var(--st-control-height-sm); --st-button-pad: var(--st-space-4); --st-button-text: var(--st-text-3); }
.st-btn--lg { --st-button-height: var(--st-control-height-lg); --st-button-pad: var(--st-space-7); --st-button-text: var(--st-text-7); }
.st-btn--icon { --st-button-pad: var(--st-space-3); --st-button-text: var(--st-text-5); min-inline-size: var(--st-button-height); }
.st-btn--block { width: 100%; }

/* Hover only changes a button that can be used. */
.st-btn--primary, .st-tone--accent { background: var(--st-color-accent-fill); color: var(--st-color-on-accent); } /* .st-tone--accent: a page section on the accent band */
.st-btn--primary:hover:not(:disabled, [aria-disabled="true"]) { background: var(--st-color-accent-fill-hover); color: var(--st-color-on-accent); }

.st-btn--secondary {
  background: var(--st-button-secondary-bg); color: var(--st-button-secondary-text);
  border-color: var(--st-button-secondary-line);
}
.st-btn--secondary:hover:not(:disabled, [aria-disabled="true"]) {
  background: var(--st-button-secondary-hover-bg); color: var(--st-button-secondary-text);
  border-color: var(--st-color-accent);
}

.st-btn--ghost { background: transparent; color: var(--st-color-text-soft); border-color: var(--st-color-line-strong); }
.st-btn--ghost:hover:not(:disabled, [aria-disabled="true"]), .st-jump a:hover { /* .st-jump: a Hero's jump list (web.css) */ background: var(--st-color-sunk); color: var(--st-color-text); }

.st-btn--outline { background: transparent; color: inherit; border-color: var(--st-color-icon-line); }
.st-btn--outline:hover:not(:disabled, [aria-disabled="true"]) { background: var(--st-color-icon-hover); color: inherit; }

.st-btn--danger { background: transparent; color: var(--st-color-bad); border-color: var(--st-color-bad); }
.st-btn--danger:hover:not(:disabled, [aria-disabled="true"]) { background: var(--st-color-bad-tint); color: var(--st-color-bad-hover); }
.st-btn--danger-fill { background: var(--st-color-bad); color: var(--st-color-on-bad); border-color: var(--st-color-bad); }
.st-btn--danger-fill:hover:not(:disabled, [aria-disabled="true"]) { background: var(--st-color-bad-hover); color: var(--st-color-on-bad); border-color: var(--st-color-bad-hover); }

.st-btn--pill {
  --st-button-height: var(--st-touch); --st-button-pad: var(--st-space-5);
  border-radius: var(--st-radius-pill); background: var(--st-color-surface); color: var(--st-color-text);
}

/* Buttons and fields that can't be used. */
.st-btn:disabled, .st-btn[aria-disabled="true"],
:is(.st-input, .st-select, .st-textarea, .st-field :where(input, select, textarea)):disabled,
.st-field-wrap:has(> input:disabled) { opacity: var(--st-opacity-disabled); cursor: not-allowed; }

/* Loading: a turning ring before the words; the button can't be pressed twice.
   Stays at full strength (it is busy, not unavailable). */
.st-btn[aria-busy="true"] { opacity: 1; cursor: progress; }
.st-btn[aria-busy="true"]::before {
  content: ""; inline-size: 1em; block-size: 1em; flex: none;
  border: var(--st-icon-stroke) solid currentColor; border-inline-end-color: transparent;
  border-radius: var(--st-radius-pill);
}
@media (prefers-reduced-motion: no-preference) {
  .st-btn[aria-busy="true"]::before { animation: st-spin var(--st-motion-spin) linear infinite; }
}
@keyframes st-spin { to { transform: rotate(1turn); } }

/* Done: a tick and a short word ("Saved") for a moment, then back to normal. */
.st-btn[data-st-state="done"]::before {
  content: ""; inline-size: 1em; block-size: 1em; flex: none;
  background: currentColor; mask: var(--st-icon-check) center / contain no-repeat;
}

/* ---------- Round icon buttons and the light/dark switch ----------
   Take the text color of where they sit (page, header band, top bar).
   <button type="button" class="st-theme-switch" data-stoei-theme-toggle></button>
   stoei.js adds the moon and sun icons and the spoken label. */

.st-icon-btn, .st-theme-switch {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  inline-size: var(--st-touch); block-size: var(--st-touch); padding: 0;
  border: var(--st-line-width) solid var(--st-color-icon-line); border-radius: var(--st-radius-pill);
  background: transparent; color: inherit; cursor: pointer;
}
.st-icon-btn:hover, .st-theme-switch:hover { background: var(--st-color-icon-hover); text-decoration: none; }
/* On: a button that shows a choice is on (aria-pressed="true") or has its options open
   (aria-expanded="true"). Real attributes, so a screen reader says it too. After :hover, so on stays on. */
.st-icon-btn:is([aria-pressed="true"], [aria-expanded="true"]) { background: var(--st-icon-btn-on-bg); }

/* Moon in light mode (press for dark), sun in dark mode. Decided by CSS, so the
   right icon shows before any script runs. */
.st-theme-switch__sun { display: none; }
:root[data-theme="dark"] .st-theme-switch__sun { display: block; }
:root[data-theme="dark"] .st-theme-switch__moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .st-theme-switch__sun { display: block; }
  :root:not([data-theme="light"]) .st-theme-switch__moon { display: none; }
}

/* ---------- Link buttons ----------
   A button that looks like a link, for a small step inside text or a table
   row: Undo, Restore, Remove, Sign out. --danger for a step that removes.
   <button type="submit" class="st-link-btn">Undo</button>
   Takes the size of the text around it; --st-link-btn-height gives a row a
   taller tap area. */

.st-link-btn {
  min-block-size: var(--st-link-btn-height); padding: 0; border: 0; background: none;
  font: inherit; color: var(--st-color-accent-text); text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.st-link-btn:hover { color: var(--st-color-accent-hover); }
.st-link-btn--danger { color: var(--st-color-bad); }
.st-link-btn--danger:hover { color: var(--st-color-bad-hover); }

/* ---------- Form fields ----------
   <div class="st-field">
     <label for="email">Email</label>
     <input id="email" type="email" required aria-describedby="email-hint email-msg">
     <p class="st-field__hint" id="email-hint">For receipts only.</p>
     <p class="st-field__msg" id="email-msg"></p>
   </div>
   Fields work inside .st-field, or on their own with .st-input, .st-select
   or .st-textarea. A wrong field gets aria-invalid="true"; a right one, when
   it has something to say, gets .is-valid on its .st-field (stoei.js). */

.st-field { display: flex; flex-direction: column; gap: var(--st-space-2); min-width: 0; }
.st-field :where(label), .st-field__label { font-weight: var(--st-weight-strong); font-size: var(--st-text-small); }
.st-field__optional, .st-hours th small { font-weight: 400; color: var(--st-color-text-muted); }
.st-field-row { display: flex; flex-wrap: wrap; gap: var(--st-space-5); }
.st-field-row > .st-field { flex: 1 1 220px; }

.st-input, .st-select, .st-textarea,
.st-field :where(input:not([type="checkbox"], [type="radio"], [type="file"]), select, textarea) {
  inline-size: 100%; min-height: var(--st-field-height); padding: 0 var(--st-field-pad);
  font-family: inherit; font-size: var(--st-text-body); color: var(--st-color-text);
  background: var(--st-color-raised); border: var(--st-line-width) solid var(--st-color-line-strong);
  border-radius: var(--st-radius-control);
}
.st-textarea, .st-field :where(textarea) { padding-block: var(--st-space-3); resize: vertical; min-height: var(--st-textarea-height); }
:is(.st-input, .st-textarea, .st-field :where(input, textarea))::placeholder { color: var(--st-color-text-faint); }

.st-input:hover, .st-select:hover, .st-textarea:hover,
.st-field :where(input, select, textarea):hover { border-color: var(--st-color-line-hover); }
.st-input:focus, .st-select:focus, .st-textarea:focus,
.st-field :where(input, select, textarea):focus { border-color: var(--st-color-accent); }
/* Wrong and right win over hover and focus. */
:is(.st-input, .st-select, .st-textarea, .st-field :where(input, select, textarea))[aria-invalid="true"] { border-color: var(--st-color-bad); }
.st-field.is-valid :where(input, select, textarea) { border-color: var(--st-color-ok); }

/* A field with something inside it: a search icon, a clear button. The box is the field
   (same border, corner, height and side space as .st-input); the input inside has none.
   <div class="st-field-wrap"><svg aria-hidden="true">...</svg><input type="search" aria-label="Search"></div>
   The whole box shows hover, focus (accent line and the focus ring, in base.css) and a wrong
   input (aria-invalid) like a plain field. */
.st-field-wrap {
  display: flex; align-items: center; gap: var(--st-space-2); min-inline-size: 0;
  min-block-size: var(--st-field-height); padding-inline: var(--st-field-pad);
  font-size: var(--st-text-body); color: var(--st-color-text-muted);
  background: var(--st-color-raised); border: var(--st-line-width) solid var(--st-color-line-strong);
  border-radius: var(--st-radius-control);
}
.st-field-wrap > svg { flex: none; inline-size: var(--st-space-5); block-size: var(--st-space-5); }
.st-field-wrap > input {
  flex: 1; min-inline-size: 0; inline-size: auto; min-block-size: 0; align-self: stretch; padding: 0;
  font: inherit; color: var(--st-color-text); background: transparent; border: 0; border-radius: 0; outline: 0;
}
.st-field-wrap > input::placeholder { color: var(--st-color-text-faint); }
.st-field-wrap:hover { border-color: var(--st-color-line-hover); }
.st-field-wrap:focus-within { border-color: var(--st-color-accent); }
.st-field-wrap:has(> input[aria-invalid="true"]) { border-color: var(--st-color-bad); }

/* Text under a field: a hint, then what is wrong (or right). */
.st-field__hint, .st-card__date, .st-form-msg { font-size: var(--st-text-caption); color: var(--st-color-text-muted); }
/* A web address or email in a hint or message breaks at the box's edge instead of widening the form (0.73.4). */
.st-field__hint, .st-field__msg, .st-form-msg { overflow-wrap: anywhere; }
.st-field__msg { font-size: var(--st-text-caption); font-weight: var(--st-weight-strong); color: var(--st-color-bad); }
.st-field__ok, .st-field.is-valid .st-field__msg { font-size: var(--st-text-caption); color: var(--st-color-ok); }
.st-field__msg:empty { display: none; }

.st-choice { display: flex; align-items: center; gap: var(--st-space-3); min-height: var(--st-control-height-sm); }
.st-choice input { inline-size: 20px; block-size: 20px; accent-color: var(--st-color-accent); }

/* ---------- Buttons with a message beside them ----------
   <div class="st-actions">
     <button class="st-btn st-btn--primary">Save</button>
     <p class="st-form-msg" role="status"></p>
   </div>
   The message sits where the eye already is, instead of a pop-up. */

.st-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--st-space-3); }
/* .st-form-msg shares its text style with .st-field__hint (above).
   Only beside buttons does the message share a row and need a width to wrap at.
   Under a field (a column) a flex size would become its height (0.5.0 bug). */
.st-actions > .st-form-msg { flex: 1 1 200px; }
.st-form-msg--bad { color: var(--st-color-bad); }
.st-form-msg--ok { color: var(--st-color-ok); }

/* The list at the top of a form after a send was turned down: what to fix, each a link to its field. */
.st-errors { border: 2px solid var(--st-color-bad); border-radius: var(--st-radius-card); background: var(--st-color-surface); padding: var(--st-space-4) var(--st-space-6); display: flex; flex-direction: column; gap: var(--st-space-2); }
.st-errors:focus { outline: none; }
.st-errors:focus-visible { outline: var(--st-focus-width) solid var(--st-color-bad); outline-offset: var(--st-focus-offset); }
.st-errors__title { font-weight: 700; color: var(--st-color-bad); margin: 0; }
.st-errors ul { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: var(--st-space-1); }
.st-errors a { color: var(--st-color-bad); font-weight: 500; }

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: no-preference) {
  .st-btn, .st-icon-btn, .st-theme-switch, .st-input, .st-select, .st-textarea,
  .st-field :where(input, select, textarea) {
    transition: color var(--st-motion), background-color var(--st-motion), border-color var(--st-motion);
  }
}

/* ---------- Tags ----------
   A small label beside a title or in a table cell: a status, a type, a
   count. One part for websites, apps and the admin, so a fix here fixes
   every screen. Never restyle or re-space a tag in a view.
     Title <span class="st-tag">Page</span>
     <span class="st-tags"><span class="st-tag st-tag--ok">Paid</span></span>
   In a line of text, always write one space before a tag (screen readers
   and copied text need it); the tag adds --st-tag-before to it. Tags that
   start a box (alone in a table cell, on a card, at the start of a line)
   go in .st-tags: --st-tag-gap between them and none at the start.
   Colours: (none) quiet, --ok, --warn, --bad, --info, --accent (new or made
   here), --when (accent, dashed: scheduled or only under a condition). */
.st-tag {
  display: inline-flex; align-items: center; gap: var(--st-space-1); align-self: flex-start;
  max-width: 100%; margin: 0 0 0 var(--st-tag-before); padding: var(--st-tag-pad-y) var(--st-tag-pad-x);
  border: var(--st-line-width) solid var(--st-color-line); border-radius: var(--st-tag-radius);
  background: var(--st-color-sunk); color: var(--st-color-text-muted);
  font-size: var(--st-tag-text); font-weight: var(--st-tag-weight); line-height: var(--st-tag-leading);
  text-transform: var(--st-tag-case); letter-spacing: var(--st-tag-tracking); text-decoration: none; vertical-align: middle;
}
.st-tag > svg { flex: none; }
a.st-tag:hover { border-color: currentColor; }
.st-tags { display: flex; flex-wrap: wrap; align-items: center; gap: var(--st-space-1) var(--st-tag-gap); margin: 0; }
.st-tags > .st-tag { margin: 0; align-self: center; }
.st-tag--ok, .st-tag--warn, .st-tag--bad, .st-tag--info, .st-tag--accent, .st-tag--when { border-color: currentColor; background: transparent; }
.st-tag--ok { color: var(--st-color-ok); }
.st-tag--warn { color: var(--st-color-warn); }
.st-tag--bad { color: var(--st-color-bad); }
.st-tag--info { color: var(--st-color-info); }
.st-tag--accent, .st-tag--when { color: var(--st-color-accent-text); }
.st-tag--when { border-style: dashed; }

/* ---------- Counts ----------
   The number beside a tab, a chip or a list title: "Trash (3)", "Eat 12".
   One part for websites, apps and the admin; never restyle it in a view.
     Trash <span class="st-count">(3)</span>
   Write one space before it (inside a flex tab or chip the gap does the
   spacing). On a filled current tab it takes the tab's own text colour. */
.st-count { color: var(--st-count-color); font-weight: var(--st-count-weight); }
.st-tab[aria-current="page"] .st-count { color: inherit; opacity: var(--st-count-on-fill); }

/* ---------- Tables ----------
   One table part for website text, apps and the admin (owner, 20 Nov 2026:
   one part per small element). Markup: <div class="st-table"><table>…</table></div>.
   The box scrolls sideways when the table is wider than the screen; give it
   role="region", tabindex="0" and an aria-label when it may scroll. The look
   is set with --st-table-* (tokens.css; the admin sets its own).
   Modifiers on the box:
     --plain   no box, for a table inside a card or panel
     --stack   phones: each row becomes a small block, every cell with its
               heading (data-label="…") in front
     --middle  cells centred top to bottom (rows with buttons or pictures)
   Cell classes: __check (a tick box column), __title (the main link of a row),
   __num (a number: right, no wrap), __center, __right, __nowrap,
   __inline (stacked: sits beside the cell before it), __block (stacked: the
   value starts on its own line under its heading), __hide-sm (hidden on
   phones). Row class: __sub (a row under the one before, indented). */
.st-table {
  position: relative; overflow-x: auto; max-width: var(--st-table-max, none);
  background: var(--st-table-bg); border: var(--st-line-width) solid var(--st-color-line); border-radius: var(--st-radius-card);
}
.st-table table { width: 100%; border-collapse: collapse; font-size: var(--st-table-text); line-height: 1.5; font-variant-numeric: var(--st-table-numbers); }
.st-table th, .st-table td { padding: var(--st-table-pad-y) var(--st-table-pad-x); text-align: left; vertical-align: top; }
.st-table td { min-width: var(--st-table-cell-min); }
.st-table thead th { font-size: var(--st-table-head-text); font-weight: var(--st-weight-strong); color: var(--st-table-head-color); background: var(--st-color-sunk); white-space: var(--st-table-head-wrap); }
.st-table :where(tr + tr, thead + tbody > tr:first-child) > * { border-top: var(--st-line-width) solid var(--st-color-line); }
.st-table tbody tr:hover { background: var(--st-table-hover); }
.st-table .st-table__check { width: 44px; }
.st-table__check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--st-color-accent); }
.st-table .st-table__title { font-weight: var(--st-weight-strong); min-width: 200px; }
.st-table__title > a { font-size: var(--st-text-4); text-decoration: none; }
.st-table__title > a:hover { text-decoration: underline; }
.st-table .st-table__num { text-align: right; white-space: nowrap; width: 1%; font-variant-numeric: tabular-nums; }
.st-table thead .st-table__num { white-space: normal; min-width: 64px; }
.st-table .st-table__center { text-align: center; }
.st-table .st-table__right { text-align: right; }
.st-table .st-table__nowrap { white-space: nowrap; }
.st-table .st-table__sub > th { padding-left: var(--st-space-7); font-weight: 400; }
.st-table--middle th, .st-table--middle td { vertical-align: middle; }
.st-table--plain { background: transparent; border: 0; border-radius: 0; }
.st-table--plain th, .st-table--plain td { padding-inline: var(--st-space-2); }
.st-table--plain thead th { background: transparent; }
.st-table--plain tbody th { font-weight: var(--st-weight-strong); }
@media (max-width: 720px) {
  .st-table .st-table__hide-sm { display: none; }
  .st-table .st-table__sub > th { padding-left: var(--st-space-6); }
  /* Stacked rows: the heading row stays for screen readers, hidden on screen. */
  .st-table--stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .st-table--stack table, .st-table--stack tbody, .st-table--stack tr { display: block; }
  .st-table--stack tr { padding: var(--st-space-4); }
  .st-table.st-table--stack tr > * { display: block; padding: 2px 0; border: 0; min-width: 0; width: auto; text-align: left; }
  .st-table--stack tr + tr { border-top: var(--st-line-width) solid var(--st-color-line); }
  /* inline-block: a struck-through value never strikes its heading */
  .st-table--stack td[data-label]::before { content: attr(data-label) ":\00a0"; display: inline-block; color: var(--st-color-text-muted); font-size: var(--st-text-2); }
  .st-table--stack td.st-table__block::before { display: block; }
  .st-table--stack td > div { display: inline; }
  .st-table--stack td .st-tags { display: inline-flex; vertical-align: middle; } /* a status tag sits on its label's line ("Status: Published") */
  .st-table.st-table--stack .st-table__inline { display: inline-block; margin-right: var(--st-space-4); }
  .st-table.st-table--stack .st-table__num, .st-table.st-table--stack .st-table__nowrap { white-space: normal; }
  .st-table--stack .st-table__num br { display: none; }
  .st-table--stack .st-table__num br + *::before { content: " · "; }
  /* A row with a tick box: the box on the left, the rest beside it. */
  .st-table--stack tr:has(> .st-table__check) { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 0 var(--st-space-2); }
  .st-table--stack tr:has(> .st-table__check) > :not(.st-table__check) { grid-column: 2; }
  .st-table--stack tr:has(> .st-table__check) > .st-table__check { grid-row: 1 / span 9; }
}

/* ---------- Letter ----------
   A written report or email shown in the weekly emails' look: a white card
   on a warm band (dark versions of both), 16px text, 560px wide. Used for
   Stoei Reports' weekly report; any app can show a letter with it.
     <div class="st-letter"><div class="st-letter__card">
       <p class="st-letter__head">Site · 9 to 15 November</p>
       <p class="st-letter__subject">Subject line</p>
       <p>…</p> <h3>Section</h3> <ul><li>…</li></ul>
       <p class="st-letter__foot">Small print</p>
     </div></div>
   While text is still being written, end it with
   <span class="st-letter__caret" aria-hidden="true"></span>. */
.st-letter { background: var(--st-letter-band); padding: var(--st-letter-band-pad) var(--st-space-3); border-radius: var(--st-radius-card); }
.st-letter__card { max-width: var(--st-letter-width); margin: 0 auto; background: var(--st-letter-card); color: var(--st-letter-ink); padding: var(--st-letter-pad); border-radius: var(--st-letter-radius); font-size: var(--st-letter-text); line-height: var(--st-letter-leading); overflow-wrap: anywhere; }
.st-letter__card > * { margin: 0 0 var(--st-letter-gap); }
.st-letter__card > :last-child { margin-bottom: 0; }
.st-letter__card ul { padding-left: var(--st-space-5); }
.st-letter__card li + li { margin-top: var(--st-space-2); }
.st-letter__card h3 { font-size: var(--st-letter-text); font-weight: var(--st-weight-strong); margin-top: var(--st-space-5); margin-bottom: var(--st-space-2); }
.st-letter__head, .st-letter__foot { font-size: var(--st-text-2); color: var(--st-letter-muted); }
.st-letter__subject { font-size: var(--st-letter-subject); font-weight: var(--st-weight-strong); line-height: var(--st-leading-tight); }
.st-letter__caret { display: inline-block; width: 0.5em; height: 1.1em; background: var(--st-letter-ink); vertical-align: text-bottom; }
@media (prefers-reduced-motion: no-preference) {
  .st-letter__caret { animation: st-letter-blink 1s steps(2) infinite; }
}
@keyframes st-letter-blink { 50% { opacity: 0; } }
@media (max-width: 480px) {
  .st-letter { padding: var(--st-space-3) 0; }
  .st-letter__card { padding: var(--st-space-4); }
}
@media print {
  .st-letter { background: none; padding: 0; }
  .st-letter__card { max-width: none; padding: 0; color: CanvasText; background: none; }
}
