/* SpareCompare design system (ADR-0016). Everything is prefixed sc-.
 * Sections: 1 fonts, 2 tokens, 3 base, 4 shell layout (top bar, sidebar), 5 components,
 * 6 more components (dialog and its wide variant, row menu, toast, sparkline, link, code, small and
 * danger button, small segmented control) and the in-row table helpers (.sc-actions, .sc-row-bad, a table inside an
 * expanded row or a dialog body), 7 master-detail components (split pane, list, thread,
 * search field, composer bar, neutral badge), 8 check (labelled checkbox).
 * Pages may hold layout only in their own <style>; no colours, fonts, radii or shadows there.
 */

/* ---------- 1. Fonts (self-hosted, OFL; see fonts/OFL.txt) ---------- */
@font-face {
  font-family: "Geist";
  src: url("../fonts/Geist-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("../fonts/GeistMono-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ---------- 2. Tokens ---------- */
/* Light is the default; js/theme-init.js sets <html data-theme="light|dark">. */
:root {
  --sc-bg: #F3F4F7;
  --sc-surface: #FFFFFF;
  --sc-surface-2: #F7F8FA;
  --sc-border: #E4E7EC;
  --sc-border-strong: #D0D5DD;
  /* The boundary of an interactive control (input, button, segmented control): >= 3:1 on
   * the page and on every surface (WCAG 1.4.11). --sc-border-strong is only a divider. */
  --sc-border-control: #7C8699;
  --sc-text: #0F172A;
  --sc-muted: #566074;

  --sc-accent: #2F4BF0;
  --sc-accent-ink: #FFFFFF;
  --sc-accent-text: #2F4BF0;
  --sc-accent-soft: color-mix(in srgb, var(--sc-accent) 9%, transparent);
  --sc-focus: var(--sc-accent);

  --sc-ok: #13795B;
  --sc-ok-soft: #E3F4EC;
  --sc-bad: #B42318;
  --sc-bad-soft: #FDECEA;
  --sc-warn-bg: #FFF6E0;
  --sc-warn-border: #F2D58F;
  --sc-warn-text: #5C4000;

  --sc-topbar-h: 60px;
  --sc-sidebar-w: 252px;

  --sc-shadow-pop: 0 8px 24px rgb(15 23 42 / 0.18);

  --sc-font: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --sc-font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Dark. Printing keeps the light tokens, so this block is skipped for print. */
@media not print {
  :root[data-theme="dark"] {
    --sc-bg: #0A0E16;
    --sc-surface: #111724;
    --sc-surface-2: #161D2C;
    --sc-border: #1F2838;
    --sc-border-strong: #2B364B;
    --sc-border-control: #667289;
    --sc-text: #E8EBF2;
    --sc-muted: #9BA6BA;

    /* --sc-accent (#2F4BF0) is only 2.89:1 on the dark surface; text, the focus
     * ring and chart fills use the lighter accent (>= 3:1, ADR-0016 Decision 11). */
    --sc-accent-text: #8D9CF7;
    --sc-accent-soft: color-mix(in srgb, var(--sc-accent) 22%, transparent);
    --sc-focus: var(--sc-accent-text);

    --sc-ok: #4FD1A1;
    --sc-ok-soft: #10302A;
    --sc-bad: #FF9288;
    --sc-bad-soft: #3A1512;
    --sc-warn-bg: #2A2208;
    --sc-warn-border: #5B4A12;
    --sc-warn-text: #F3DC9B;
  }
}

/* ---------- 3. Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--sc-bg);
  color: var(--sc-text);
  font-family: var(--sc-font);
  font-size: 14px;
  line-height: 1.45;
  font-feature-settings: "tnum" 1, "ss01" 1;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

code,
kbd,
samp,
pre {
  font-family: var(--sc-font-mono);
}

:focus-visible {
  outline: 2px solid var(--sc-focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  :root {
    color-scheme: light !important;
  }
}

/* ---------- 4. Shell layout (js/shell.js) ---------- */
/* The top bar and sidebar are fixed and their space is reserved on <body> here, so
 * nothing moves when shell.js draws them or when the ping answers. */
body[data-shell] {
  min-width: 1024px;
  padding-top: var(--sc-topbar-h);
  padding-left: var(--sc-sidebar-w);
}

.sc-skip {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 8px 14px;
  border: 1px solid var(--sc-border-strong);
  border-radius: 8px;
  background: var(--sc-surface);
  color: var(--sc-text);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-200%);
}
.sc-skip:focus {
  transform: none;
}

.sc-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 1024px;
  height: var(--sc-topbar-h);
  padding: 0 20px;
  background: var(--sc-surface);
  border-bottom: 1px solid var(--sc-border);
}
.sc-topbar-end {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.sc-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--sc-text);
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
}
.sc-brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--sc-accent);
  color: var(--sc-accent-ink);
  font-size: 15px;
}

/* Sidebar: .sc-side is the fixed frame (holds the collapse handle, the tooltip and the
 * group pop-over's anchor); .sc-sidebar inside it scrolls. body[data-sidebar] reserves
 * the width, so the page content moves with it. */
body[data-shell][data-sidebar="collapsed"] {
  --sc-sidebar-w: 56px;
}
body[data-shell].sc-anim {
  transition: padding-left 0.15s;
}
.sc-side {
  position: fixed;
  top: var(--sc-topbar-h);
  bottom: 0;
  left: 0;
  z-index: 20;
  width: var(--sc-sidebar-w);
}
.sc-anim .sc-side {
  transition: width 0.15s;
}
.sc-sidebar {
  display: flex;
  flex-direction: column;
  gap: 2px;
  height: 100%;
  padding: 12px;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--sc-surface);
  border-right: 1px solid var(--sc-border);
}
/* Room above the first icon for the collapse handle, which straddles the narrow strip. */
[data-sidebar="collapsed"] .sc-sidebar {
  padding: 48px 8px 12px;
}

.sc-side-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sc-side-heading {
  margin: 0;
  padding: 14px 12px 4px;
  color: var(--sc-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.sc-side-section:first-child .sc-side-heading {
  padding-top: 4px;
}
[data-sidebar="collapsed"] .sc-side-section + .sc-side-section {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--sc-border);
}
/* Still read by assistive tech when the sidebar is narrow. */
[data-sidebar="collapsed"] .sc-side-heading,
[data-sidebar="collapsed"] .sc-side-label {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.sc-side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--sc-text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
[data-sidebar="collapsed"] .sc-side-link {
  justify-content: center;
  padding: 10px 0;
}
.sc-side-link:hover {
  background: var(--sc-surface-2);
}
.sc-side-link[aria-current="page"],
[data-sidebar="collapsed"] .sc-side-link.sc-has-current {
  background: var(--sc-accent-soft);
  color: var(--sc-accent-text);
  font-weight: 600;
}
.sc-side-icon {
  flex: none;
  width: 18px;
  height: 18px;
}
.sc-side-label {
  flex: 1;
  min-width: 0;
}

.sc-side-chevron {
  flex: none;
  width: 14px;
  height: 14px;
  transition: transform 0.15s;
}
.sc-side-group-btn[aria-expanded="true"] .sc-side-chevron {
  transform: rotate(90deg);
}
[data-sidebar="collapsed"] .sc-side-chevron {
  display: none;
}
.sc-side-children {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 2px 0 2px 18px;
  padding-left: 8px;
  border-left: 1px solid var(--sc-border);
}
.sc-side-children[hidden],
.sc-side-pop[hidden],
.sc-tip[hidden] {
  display: none;
}
/* Collapsed, a group's links live in its pop-over, never inline. */
[data-sidebar="collapsed"] .sc-side-children {
  display: none;
}

.sc-side-pop {
  position: fixed;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 200px;
  padding: 6px;
  border: 1px solid var(--sc-border-strong);
  border-radius: 10px;
  background: var(--sc-surface);
  box-shadow: var(--sc-shadow-pop);
}
.sc-side-pop .sc-side-link {
  justify-content: flex-start;
  padding: 8px 12px;
}
.sc-side-pop .sc-side-label {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
}

.sc-tip {
  position: fixed;
  z-index: 50;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--sc-text);
  color: var(--sc-surface);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  transform: translateY(-50%);
}

/* The collapse handle: a round button on the frame's right edge. It stays put because the
 * frame is fixed below the top bar; the arrow points the way the sidebar will move. */
.sc-side-handle {
  position: absolute;
  top: 14px;
  right: -14px;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--sc-border-strong);
  border-radius: 50%;
  background: var(--sc-surface);
  color: var(--sc-text);
  cursor: pointer;
}
.sc-side-handle:hover {
  background: var(--sc-surface-2);
}
.sc-side-handle-icon {
  width: 14px;
  height: 14px;
}
[data-sidebar="collapsed"] .sc-side-handle-icon {
  transform: rotate(180deg);
}

/* Theme switch: a button with role="switch"; on = dark. */
.sc-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--sc-text);
  cursor: pointer;
}
.sc-switch-track {
  position: relative;
  flex: none;
  width: 36px;
  height: 20px;
  border: 1px solid var(--sc-muted);
  border-radius: 999px;
  background: var(--sc-surface-2);
}
.sc-switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--sc-muted);
  transition: transform 0.15s;
}
.sc-switch[aria-checked="true"] .sc-switch-track {
  background: var(--sc-accent);
  border-color: var(--sc-accent-text);
}
.sc-switch[aria-checked="true"] .sc-switch-track::after {
  background: var(--sc-accent-ink);
  transform: translateX(16px);
}

/* User menu and organization switcher: a button opening a panel (shell.js Menu). */
.sc-menu {
  position: relative;
}
.sc-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 280px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  color: var(--sc-text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.sc-orgs .sc-menu-btn {
  max-width: 360px;
  border-color: var(--sc-border-strong);
  border-radius: 8px;
  padding: 6px 10px;
}
.sc-menu-btn:hover,
.sc-menu-btn[aria-expanded="true"] {
  background: var(--sc-surface-2);
}
.sc-menu-icon,
.sc-menu-chevron {
  flex: none;
  width: 16px;
  height: 16px;
}
.sc-menu-chevron {
  color: var(--sc-muted);
}
.sc-menu-name,
.sc-orgs-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sc-orgs-prefix {
  color: var(--sc-muted);
}
.sc-orgs-name {
  font-weight: 600;
}
.sc-avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--sc-accent-soft);
  color: var(--sc-accent-text);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}
.sc-tag {
  flex: none;
  padding: 1px 6px;
  border: 1px solid var(--sc-border-strong);
  border-radius: 999px;
  color: var(--sc-muted);
  font-size: 11px;
  font-weight: 600;
}
.sc-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 240px;
  max-width: 320px;
  padding: 6px;
  border: 1px solid var(--sc-border-strong);
  border-radius: 10px;
  background: var(--sc-surface);
  box-shadow: var(--sc-shadow-pop);
}
.sc-menu-panel[hidden] {
  display: none;
}
.sc-menu-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 2px;
}
.sc-menu-email {
  min-width: 0;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sc-menu-badge {
  flex: none;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--sc-accent-soft);
  color: var(--sc-accent-text);
  font-size: 11px;
  font-weight: 700;
}
.sc-menu-meta {
  padding: 2px 12px 6px;
  color: var(--sc-muted);
  font-size: 13px;
}
.sc-menu-meta:empty {
  display: none;
}
.sc-menu-sep {
  width: 100%;
  margin: 4px 0;
  border: 0;
  border-top: 1px solid var(--sc-border);
}
.sc-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--sc-text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.sc-menu-item:focus-visible {
  outline-offset: -2px;
}
.sc-menu-item:hover:not(:disabled) {
  background: var(--sc-surface-2);
}
.sc-menu-item:disabled {
  color: var(--sc-muted);
  cursor: default;
}
.sc-menu-item[aria-current="true"] {
  background: var(--sc-accent-soft);
  color: var(--sc-accent-text);
  font-weight: 600;
}
.sc-orgs-panel {
  min-width: 280px;
}
.sc-orgs-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: min(60vh, 360px);
  overflow-y: auto;
}
.sc-orgs-list .sc-orgs-name {
  flex: 1;
}

[data-shell] main:focus {
  outline: none;
}
[data-shell] main {
  scroll-margin-top: var(--sc-topbar-h);
}

@media print {
  body[data-shell] {
    min-width: 0;
    padding: 0;
  }
  .sc-skip,
  .sc-topbar,
  .sc-side {
    display: none;
  }
}

/* ---------- 5. Components ---------- */
/* Pages use these as they are; a page's own <style> holds that page's layout only. */

/* Button: .sc-btn, plus .sc-btn-primary or .sc-btn-ghost. Works on <button> and <a>.
 * A disabled <button> uses :disabled; a link uses aria-disabled="true". */
.sc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--sc-border-control);
  border-radius: 8px;
  background: var(--sc-surface);
  color: var(--sc-text);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s;
}
.sc-btn:not(:disabled, [aria-disabled="true"]):hover {
  background: var(--sc-surface-2);
}
.sc-btn:not(:disabled, [aria-disabled="true"]):active {
  background: var(--sc-border);
}
.sc-btn-primary {
  border-color: var(--sc-accent);
  background: var(--sc-accent);
  color: var(--sc-accent-ink);
}
.sc-btn-primary:not(:disabled, [aria-disabled="true"]):hover {
  background: color-mix(in srgb, var(--sc-accent) 88%, #000);
}
.sc-btn-primary:not(:disabled, [aria-disabled="true"]):active {
  background: color-mix(in srgb, var(--sc-accent) 76%, #000);
}
.sc-btn-ghost {
  border-color: transparent;
  background: none;
}
.sc-btn:disabled,
.sc-btn[aria-disabled="true"] {
  border-color: var(--sc-border);
  background: var(--sc-surface-2);
  color: var(--sc-muted);
  cursor: not-allowed;
}
.sc-btn-ghost:disabled,
.sc-btn-ghost[aria-disabled="true"] {
  border-color: transparent;
  background: none;
}

/* Field: a label, a control and optional hint / error text, stacked.
 *   <div class="sc-field"><label class="sc-label" for="x">Name</label><input class="sc-input" id="x">
 *   <p class="sc-hint">...</p></div>
 * Mark a bad control with aria-invalid="true" and put the reason in .sc-field-error. */
.sc-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.sc-label {
  font-size: 13px;
  font-weight: 600;
}
.sc-hint,
.sc-field-error {
  margin: 0;
  font-size: 13px;
}
.sc-hint {
  color: var(--sc-muted);
}
.sc-field-error {
  color: var(--sc-bad);
  font-weight: 600;
}
.sc-input,
.sc-select {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--sc-border-control);
  border-radius: 8px;
  background: var(--sc-surface);
  color: var(--sc-text);
}
textarea.sc-input {
  min-height: 72px;
  resize: vertical;
}
.sc-input::placeholder {
  color: var(--sc-muted);
  opacity: 1;
}
.sc-input:not(:disabled, [aria-invalid="true"]):hover,
.sc-select:not(:disabled, [aria-invalid="true"]):hover {
  border-color: var(--sc-text);
}
.sc-input:focus,
.sc-select:focus {
  border-color: var(--sc-focus);
}
.sc-input[aria-invalid="true"],
.sc-select[aria-invalid="true"] {
  border-color: var(--sc-bad);
}
.sc-input:disabled,
.sc-select:disabled {
  border-color: var(--sc-border);
  background: var(--sc-surface-2);
  color: var(--sc-muted);
  cursor: not-allowed;
}

/* Segmented control: one choice out of a few, as real controls. Either buttons with
 * aria-pressed="true" on the chosen one, or a visually hidden radio before each label:
 *   <div class="sc-seg" role="group" aria-label="Period"><button class="sc-seg-btn" aria-pressed="true">7d</button>...
 *   <div class="sc-seg" role="radiogroup" aria-label="Bucket"><input type="radio" id="a" name="b"><label class="sc-seg-btn" for="a">Day</label>... */
.sc-seg {
  position: relative;
  display: inline-flex;
  border: 1px solid var(--sc-border-control);
  border-radius: 8px;
  background: var(--sc-surface);
}
.sc-seg > input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  opacity: 0;
}
.sc-seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-left: 1px solid var(--sc-border-control);
  background: none;
  color: var(--sc-text);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.sc-seg > :first-child,
.sc-seg > input:first-child + .sc-seg-btn {
  border-left: 0;
}
.sc-seg > .sc-seg-btn:first-child,
.sc-seg > input:first-child + .sc-seg-btn {
  border-radius: 7px 0 0 7px;
}
.sc-seg > .sc-seg-btn:last-child {
  border-radius: 0 7px 7px 0;
}
.sc-seg-btn:focus-visible,
.sc-seg > input:focus-visible + .sc-seg-btn {
  outline: 2px solid var(--sc-focus);
  outline-offset: -2px;
}
.sc-seg-btn:not(:disabled, [aria-pressed="true"]):hover,
.sc-seg > input:not(:disabled, :checked):hover + .sc-seg-btn {
  background: var(--sc-surface-2);
}
.sc-seg-btn[aria-pressed="true"],
.sc-seg > input:checked + .sc-seg-btn {
  background: var(--sc-accent);
  color: var(--sc-accent-ink);
  font-weight: 700;
}
.sc-seg-btn:not(:disabled, [aria-pressed="true"]):active,
.sc-seg > input:not(:disabled, :checked):active + .sc-seg-btn {
  background: var(--sc-border);
}
/* On the accent fill the ring would be accent on accent; draw it in the ink colour instead. */
.sc-seg-btn[aria-pressed="true"]:focus-visible,
.sc-seg > input:checked:focus-visible + .sc-seg-btn {
  outline-color: var(--sc-accent-ink);
  outline-offset: -4px;
}
.sc-seg-btn:disabled,
.sc-seg > input:disabled + .sc-seg-btn {
  background: var(--sc-surface-2);
  color: var(--sc-muted);
  cursor: not-allowed;
}

/* Toggle chip: a button that switches one value on or off, with a count of what it would
 * show. Several can be on at once; put them in a .sc-chips row, which wraps. Selected is
 * aria-pressed="true" and looks different in more than colour: a check mark and a heavier
 * border besides the soft fill. Chips carry no tone of their own (a badge in the data does).
 *   <div class="sc-chips" role="group" aria-label="Status">
 *   <button type="button" class="sc-chip" aria-pressed="false">Open <span class="sc-chip-count">12</span></button></div> */
.sc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.sc-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--sc-border-control);
  border-radius: 999px;
  background: var(--sc-surface);
  color: var(--sc-text);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s;
}
.sc-chip-count {
  color: var(--sc-muted);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.sc-chip:not(:disabled, [aria-pressed="true"]):hover {
  background: var(--sc-surface-2);
}
.sc-chip:focus-visible {
  outline: 2px solid var(--sc-focus);
  outline-offset: 2px;
}
.sc-chip[aria-pressed="true"] {
  border-color: var(--sc-accent-text);
  /* The second pixel of the heavier border; an inset shadow so the border adds no size.
   * The check mark below does add its width, so a row of chips may rewrap on a toggle. */
  box-shadow: inset 0 0 0 1px var(--sc-accent-text);
  background: var(--sc-accent-soft);
}
.sc-chip[aria-pressed="true"] .sc-chip-count {
  color: var(--sc-text);
}
/* The check mark, drawn with borders so it needs no font glyph. */
.sc-chip[aria-pressed="true"]::before {
  content: "";
  flex: none;
  width: 5px;
  height: 9px;
  margin: -2px 2px 0 0;
  border: solid var(--sc-accent-text);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.sc-chip:disabled {
  border-color: var(--sc-border);
  background: var(--sc-surface-2);
  color: var(--sc-muted);
  cursor: not-allowed;
}

/* Badge / status chip: always carries text. Variants: sc-badge-ok, -bad, -warn, -accent, and
 * -neutral (section 7) for a value that carries no judgement. */
.sc-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border: 1px solid var(--sc-border);
  border-radius: 999px;
  background: var(--sc-surface-2);
  color: var(--sc-text);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}
.sc-badge::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.sc-badge-ok {
  border-color: transparent;
  background: var(--sc-ok-soft);
  color: var(--sc-ok);
}
.sc-badge-bad {
  border-color: transparent;
  background: var(--sc-bad-soft);
  color: var(--sc-bad);
}
.sc-badge-warn {
  border-color: var(--sc-warn-border);
  background: var(--sc-warn-bg);
  color: var(--sc-warn-text);
}
.sc-badge-accent {
  border-color: transparent;
  background: var(--sc-accent-soft);
  color: var(--sc-accent-text);
}

/* Card: .sc-card with optional .sc-card-head (.sc-card-title and actions side by side). */
.sc-card {
  padding: 16px;
  border: 1px solid var(--sc-border);
  border-radius: 12px;
  background: var(--sc-surface);
}
.sc-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.sc-card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

/* KPI card: a figure to read first. .sc-kpis lays several out in a row. */
.sc-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.sc-kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  border: 1px solid var(--sc-border);
  border-radius: 12px;
  background: var(--sc-surface);
}
.sc-kpi-label {
  color: var(--sc-muted);
  font-size: 13px;
  font-weight: 600;
}
.sc-kpi-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.15;
}
.sc-kpi-note {
  color: var(--sc-muted);
  font-size: 13px;
}
/* Interactive tile: the same card as a <button type="button" class="sc-kpi sc-kpi-btn"> with
 * the same label, value and note inside (spans only). aria-pressed="true" marks the active
 * tile with a heavier border and a check mark besides the soft fill. */
.sc-kpi-btn {
  position: relative;
  width: 100%;
  font: inherit;
  text-align: left;
  color: inherit;
  /* A control's boundary must reach 3:1 (Decision 11); the plain card's divider need not. */
  border-color: var(--sc-border-control);
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s;
}
/* Room for the check mark, so a long label never runs under it. */
.sc-kpi-btn .sc-kpi-label {
  padding-right: 22px;
}
.sc-kpi-btn:hover {
  background: var(--sc-surface-2);
}
.sc-kpi-btn:focus-visible {
  outline: 2px solid var(--sc-focus);
  outline-offset: 2px;
}
.sc-kpi-btn[aria-pressed="true"] {
  border-color: var(--sc-accent-text);
  box-shadow: inset 0 0 0 1px var(--sc-accent-text);
  background: var(--sc-accent-soft);
}
.sc-kpi-btn[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  top: 14px;
  right: 16px;
  width: 6px;
  height: 11px;
  border: solid var(--sc-accent-text);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Simple bars: a ranked list, each row a label, a bar and its value (the value is text,
 * so the bar is never the only carrier). Set each bar's length with style="--sc-bar-pct: 80%".
 *   <ul class="sc-bars"><li class="sc-bar"><span class="sc-bar-label">A</span>
 *   <span class="sc-bar-track"><span class="sc-bar-fill" style="--sc-bar-pct: 80%"></span></span>
 *   <span class="sc-bar-value">120</span></li></ul> */
.sc-bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.sc-bar {
  display: grid;
  grid-template-columns: minmax(80px, 30%) 1fr auto;
  align-items: center;
  gap: 12px;
}
.sc-bar-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sc-bar-track {
  height: 8px;
  border-radius: 999px;
  background: var(--sc-border);
}
.sc-bar-fill {
  display: block;
  width: var(--sc-bar-pct, 0%);
  height: 100%;
  border-radius: 999px;
  background: var(--sc-accent-text);
}
.sc-bar-value {
  min-width: 3ch;
  font-weight: 600;
  text-align: right;
}

/* Notice: an inline message. Default is informational; sc-notice-ok, -warn, -bad for others.
 * Give it role="status" or role="alert" in the markup; the text says what it is. */
.sc-notice {
  padding: 10px 14px;
  border: 1px solid var(--sc-border-strong);
  border-left: 4px solid var(--sc-accent-text);
  border-radius: 8px;
  background: var(--sc-accent-soft);
  color: var(--sc-text);
}
.sc-notice-title {
  margin: 0 0 2px;
  font-weight: 700;
}
.sc-notice-ok {
  border-color: var(--sc-border-strong);
  border-left-color: var(--sc-ok);
  background: var(--sc-ok-soft);
}
.sc-notice-bad {
  border-color: var(--sc-border-strong);
  border-left-color: var(--sc-bad);
  background: var(--sc-bad-soft);
}
.sc-notice-warn {
  border-color: var(--sc-warn-border);
  border-left-color: var(--sc-warn-text);
  background: var(--sc-warn-bg);
  color: var(--sc-warn-text);
}

/* Empty state: for a card, a chart or a table cell with nothing to show. */
.sc-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 32px 16px;
  color: var(--sc-muted);
  text-align: center;
}
.sc-empty-title {
  margin: 0;
  color: var(--sc-text);
  font-size: 15px;
  font-weight: 650;
}
.sc-empty-body {
  margin: 0;
  max-width: 48ch;
}

/* Page frame: the content column of every migrated page, inside <main class="sc-page">.
 * A head row holds the title (and a hint under it) on the left and the page's actions on
 * the right; the cards and states follow, stacked with an even gap.
 *   <main class="sc-page"><div class="sc-page-head"><div><h1 class="sc-page-title">Title</h1>
 *   <p class="sc-hint">...</p></div><div>actions</div></div> ... </main> */
.sc-page {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}
.sc-page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 16px;
}
.sc-page-title {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.25;
}

/* Table: wrap it in .sc-table-wrap. The header sticks just under the top bar while the page
 * scrolls, so no ancestor between the table and the page may set overflow (that would make
 * it the scroll container and the header would stop sticking).
 * A row that is a state is <tr class="sc-table-state"><td colspan="N">: empty has just that
 * class; loading adds sc-table-loading (spinner, with the text "Loading…" beside it) and the
 * table gets aria-busy="true" while it loads; an error adds class sc-table-error on the td
 * (bad colour, with a retry button inside). js/sc-table.js writes all three. */
.sc-table-wrap {
  border: 1px solid var(--sc-border);
  border-radius: 12px;
  background: var(--sc-surface);
}
.sc-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}
.sc-table thead th {
  position: sticky;
  top: var(--sc-topbar-h);
  z-index: 2;
  padding: 10px 12px;
  border-bottom: 1px solid var(--sc-border);
  background: var(--sc-surface-2);
  color: var(--sc-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.sc-table tbody th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--sc-border);
  font-weight: 600;
  text-align: left;
  vertical-align: top;
}
.sc-table thead th:first-child {
  border-top-left-radius: 11px;
}
.sc-table thead th:last-child {
  border-top-right-radius: 11px;
}
.sc-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--sc-border);
  vertical-align: top;
}
.sc-table tbody tr:last-child :is(td, th) {
  border-bottom: 0;
}
.sc-table tbody tr:last-child td:first-child {
  border-bottom-left-radius: 11px;
}
.sc-table tbody tr:last-child td:last-child {
  border-bottom-right-radius: 11px;
}
.sc-table tbody tr:hover :is(td, th) {
  background: var(--sc-surface-2);
}
/* A row that is set apart (for example a blocked one): quieter text. The information must
 * also be in the row's own words; this only helps the eye. Links and badges keep their colour. */
.sc-table tbody tr.sc-row-muted :is(td, th) {
  color: var(--sc-muted);
}
.sc-table .sc-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.sc-table .sc-table-state td,
.sc-table .sc-table-state:hover td {
  padding: 32px 16px;
  background: none;
  color: var(--sc-muted);
  text-align: center;
}
.sc-table-loading td::before,
.sc-table-detail-loading::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 10px;
  border: 2px solid var(--sc-border-strong);
  border-top-color: var(--sc-accent-text);
  border-radius: 50%;
  vertical-align: -2px;
  animation: sc-spin 0.8s linear infinite;
}
@keyframes sc-spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .sc-table-loading td::before,
  .sc-table-detail-loading::before {
    animation: none;
  }
}

/* Table helper (js/sc-table.js). Text for screen readers only. */
.sc-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Sort button inside a header cell; the arrow follows the cell's aria-sort, so the sorted
 * column is told by shape, not colour. Each arrow is declared twice on purpose: the second
 * form gives the glyph an empty text alternative where supported (aria-sort already says it),
 * the first is the fallback. */
.sc-th-sort {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: -4px -6px;
  padding: 4px 6px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}
.sc-th-sort:hover {
  color: var(--sc-text);
}
.sc-th-sort::after {
  content: "↕";
  content: "↕" / "";
  opacity: 0.55;
}
.sc-table th[aria-sort="ascending"] .sc-th-sort,
.sc-table th[aria-sort="descending"] .sc-th-sort {
  color: var(--sc-text);
}
.sc-table th[aria-sort="ascending"] .sc-th-sort::after {
  content: "▲";
  content: "▲" / "";
  opacity: 1;
}
.sc-table th[aria-sort="descending"] .sc-th-sort::after {
  content: "▼";
  content: "▼" / "";
  opacity: 1;
}
/* The second selector outranks the state row's muted text colour. */
.sc-table .sc-table-error,
.sc-table .sc-table-state td.sc-table-error {
  color: var(--sc-bad);
}
.sc-table-error .sc-btn {
  margin-top: 10px;
}

/* Row expansion: a narrow first column holds the toggle; the detail row sits right under its
 * row and inherits no hover colour. */
.sc-table-toggle-cell {
  width: 1%;
  padding-right: 0;
}
.sc-table-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--sc-border-control);
  border-radius: 6px;
  background: var(--sc-surface);
  color: var(--sc-text);
  cursor: pointer;
}
.sc-table-toggle:hover {
  background: var(--sc-surface-2);
}
.sc-table-chevron {
  width: 7px;
  height: 7px;
  margin-right: 2px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.12s;
}
.sc-table-toggle[aria-expanded="true"] .sc-table-chevron {
  margin: -3px 0 0;
  transform: rotate(45deg);
}
.sc-table .sc-table-open :is(td, th) {
  border-bottom-color: transparent;
}
.sc-table .sc-table-detail > td,
.sc-table .sc-table-detail:hover > td {
  padding: 4px 16px 16px 52px;
  background: var(--sc-surface-2);
}
.sc-table-detail-state {
  padding: 12px 0;
  color: var(--sc-muted);
}

/* Pager under a table: range text on the left, numbered pages on the right. */
.sc-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 2px;
}
.sc-pager[hidden] {
  display: none;
}
.sc-pager-range {
  margin: 0;
  color: var(--sc-muted);
  font-variant-numeric: tabular-nums;
}
.sc-pager-pages {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.sc-pager-btn {
  min-width: 36px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: var(--sc-text);
  font: inherit;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.sc-pager-btn:not([aria-disabled="true"], [aria-current="page"]):hover {
  background: var(--sc-surface-2);
  border-color: var(--sc-border);
}
.sc-pager-btn[aria-current="page"] {
  border-color: var(--sc-accent);
  background: var(--sc-accent);
  color: var(--sc-accent-ink);
  cursor: default;
}
.sc-pager-btn[aria-disabled="true"] {
  color: var(--sc-muted);
  cursor: not-allowed;
}
.sc-pager-gap {
  display: inline-block;
  min-width: 24px;
  color: var(--sc-muted);
  text-align: center;
}

@media print {
  .sc-table thead th {
    position: static;
  }
  .sc-pager {
    display: none;
  }
}

/* Supplier map (js/sc-map.js). The dots are img/world-dots.svg used as a mask, so their
 * colour is a token and follows the theme; bubbles are SVG circles styled here. The stage keeps
 * the picture's proportions (1000 x 394.44, as in js/sc-map.js) at any width. Dots and bubble outlines are
 * non-text graphics: --sc-border-control and --sc-accent-text are both >= 3:1 on the surface. */
.sc-map-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1000 / 394.44;
}
.sc-map-dots {
  position: absolute;
  inset: 0;
  background: var(--sc-border-control);
  -webkit-mask: url("../img/world-dots.svg") center / 100% 100% no-repeat;
  mask: url("../img/world-dots.svg") center / 100% 100% no-repeat;
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}
.sc-map-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.sc-map-bubble {
  fill: color-mix(in srgb, var(--sc-accent-text) 30%, transparent);
  stroke: var(--sc-accent-text);
  stroke-width: 2;
  cursor: default;
}
.sc-map-bubble:hover,
.sc-map-bubble:focus {
  fill: color-mix(in srgb, var(--sc-accent-text) 55%, transparent);
  stroke-width: 3;
}
.sc-map-bubble:focus-visible {
  outline: 2px solid var(--sc-focus);
  outline-offset: 3px;
}
.sc-map-tip {
  --sc-map-gap: 12px;
  position: absolute;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--sc-text);
  color: var(--sc-surface);
  box-shadow: var(--sc-shadow-pop);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - var(--sc-map-gap)));
}
.sc-map-tip[hidden] {
  display: none;
}
.sc-map-tip-below {
  transform: translate(-50%, var(--sc-map-gap));
}
.sc-map-tip-left {
  transform: translate(-12%, calc(-100% - var(--sc-map-gap)));
}
.sc-map-tip-right {
  transform: translate(-88%, calc(-100% - var(--sc-map-gap)));
}
.sc-map-tip-below.sc-map-tip-left {
  transform: translate(-12%, var(--sc-map-gap));
}
.sc-map-tip-below.sc-map-tip-right {
  transform: translate(-88%, var(--sc-map-gap));
}

/* Country list: the map's text alternative. Collapsed by default; scrolls inside itself, so
 * its header sticks to the list, not to the top bar. */
.sc-map-list {
  margin-top: 12px;
}
.sc-map-list > summary {
  width: fit-content;
  color: var(--sc-accent-text);
  font-weight: 600;
  cursor: pointer;
}
.sc-map-list .sc-table-wrap {
  max-height: 280px;
  margin-top: 8px;
  overflow: auto;
}
.sc-map-list .sc-table thead th {
  top: 0;
}
.sc-map-unplaced {
  color: var(--sc-muted);
  font-weight: 400;
}

@media print {
  .sc-map-tip {
    display: none;
  }
}

/* ---------- 6. More components: dialog, toast, link, code, small button, sparkline, in-row table helpers ---------- */

/* Link in running text and tables. */
.sc-link {
  color: var(--sc-accent-text);
  text-decoration: none;
}
.sc-link:hover {
  text-decoration: underline;
}

/* A value shown verbatim (a URL, an id) in its own block. */
.sc-code {
  display: block;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--sc-surface-2);
  color: var(--sc-text);
  font-family: var(--sc-font-mono);
  font-size: 12px;
  overflow-wrap: anywhere;
}

/* Small segmented control, for a choice inside a table row: <div class="sc-seg sc-seg-sm">. */
.sc-seg-sm .sc-seg-btn {
  min-height: 26px;
  padding: 0 8px;
  font-size: 13px;
}

/* Small and destructive variants of .sc-btn, for in-row actions and confirmations. */
.sc-btn-sm {
  min-height: 28px;
  padding: 0 8px;
  font-size: 13px;
}
.sc-btn-danger {
  border-color: var(--sc-bad);
  background: var(--sc-bad);
  color: var(--sc-surface);
}
.sc-btn-danger:not(:disabled, [aria-disabled="true"]):hover {
  background: color-mix(in srgb, var(--sc-bad) 88%, #000);
}
.sc-btn-danger:not(:disabled, [aria-disabled="true"]):active {
  background: color-mix(in srgb, var(--sc-bad) 76%, #000);
}
.sc-btn-ghost.sc-btn-danger {
  background: none;
  color: var(--sc-bad);
}
.sc-btn-ghost.sc-btn-danger:not(:disabled, [aria-disabled="true"]):hover {
  background: var(--sc-bad-soft);
}

/* Dialog: a native <dialog class="sc-dialog"> opened with showModal() (focus is trapped and
 * Escape closes it). Children: .sc-dialog-title, .sc-dialog-body, .sc-dialog-actions; for a
 * long body see .sc-dialog-wide below. */
.sc-dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 20px 24px;
  border: 1px solid var(--sc-border-strong);
  border-radius: 12px;
  background: var(--sc-surface);
  color: var(--sc-text);
  box-shadow: var(--sc-shadow-pop);
}
.sc-dialog::backdrop {
  background: rgb(15 23 42 / 0.5);
}
.sc-dialog-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 700;
}
.sc-dialog-body {
  margin: 0 0 16px;
  color: var(--sc-muted);
}
.sc-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
/* The page behind a modal dialog does not scroll. */
:root:has(.sc-dialog[open]) {
  overflow: hidden;
}
/* Wide variant for a dialog with a long body: .sc-dialog-wide adds a head row
 * (.sc-dialog-head: the .sc-dialog-title and a close button) and the body scrolls inside the
 * dialog. Padding sits on the children, so a click on the dialog's own box is a click outside. */
.sc-dialog-wide[open] {
  display: flex;
  flex-direction: column;
  width: min(960px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  padding: 0;
}
.sc-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--sc-border);
}
.sc-dialog-head .sc-dialog-title {
  margin: 0;
}
.sc-dialog-wide .sc-dialog-body {
  min-height: 0;
  margin: 0;
  padding: 16px 24px 24px;
  overflow-y: auto;
  color: var(--sc-text);
}

/* Row menu (js/sc-rowmenu.js): a pop-over list of actions opened from a button. The script
 * appends the panel to <body> and sets top and left; it is fixed to the window so a scrolling
 * table wrapper cannot clip it. Items reuse .sc-menu-item and .sc-menu-sep from the top bar
 * menus. A destructive item is bold (the separator above it is added by the script), so it
 * differs without colour. */
.sc-rowmenu {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 55;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 160px;
  max-width: min(280px, calc(100vw - 16px));
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--sc-border-strong);
  border-radius: 10px;
  background: var(--sc-surface);
  box-shadow: var(--sc-shadow-pop);
}
.sc-rowmenu:focus {
  outline: none;
}
.sc-rowmenu .sc-menu-item {
  white-space: nowrap;
}
.sc-rowmenu .sc-rowmenu-danger {
  color: var(--sc-bad);
  font-weight: 700;
}
.sc-rowmenu .sc-rowmenu-danger:hover:not(:disabled) {
  background: var(--sc-bad-soft);
}
.sc-rowmenu .sc-rowmenu-danger:disabled {
  color: var(--sc-muted);
}
.sc-rowmenu-btn[aria-expanded="true"] {
  background: var(--sc-surface-2);
}

/* Toast: a .sc-notice with a tone class inside one .sc-toasts container. Put the container
 * (role="status") in the page's markup, not in a script at the moment of the first toast, or
 * screen readers may not announce it. Confirmations go away by themselves; a failure stays
 * until it is dismissed. */
.sc-toasts {
  position: fixed;
  top: calc(var(--sc-topbar-h) + 12px);
  right: 16px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 32px));
}
.sc-toasts > .sc-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--sc-shadow-pop);
  background-color: var(--sc-surface);
}

/* Toasts that must not cover a pane's header action (a button at the top right of a detail
 * pane): start them below the header's first line. Add next to .sc-toasts. */
.sc-toasts-below-head {
  top: calc(var(--sc-topbar-h) + 104px);
}

/* Sparkline: a small inline SVG line of points. */
.sc-spark {
  display: block;
  width: 100%;
  height: 84px;
}
.sc-spark-axis {
  stroke: var(--sc-border-strong);
  stroke-width: 1;
}
.sc-spark-line {
  fill: none;
  stroke: var(--sc-accent-text);
  stroke-width: 2;
}
.sc-spark-point {
  fill: var(--sc-accent-text);
  stroke: var(--sc-surface);
  stroke-width: 1;
}

/* A table inside an expanded row or a dialog body: a plain framed table that does not stick,
 * and cells that line up by the same classes as the outer one. .sc-actions right-aligns a
 * column of in-row buttons; .sc-row-bad marks a row in the bad tone (colour plus a badge or
 * text, never alone). */
:is(.sc-table-detail-body, .sc-dialog-body) .sc-table {
  border: 1px solid var(--sc-border);
  border-radius: 10px;
  background: var(--sc-surface);
}
:is(.sc-table-detail-body, .sc-dialog-body) .sc-table thead th {
  position: static;
  letter-spacing: normal;
  text-transform: none;
}
.sc-table thead th.sc-actions,
.sc-table td.sc-actions {
  text-align: right;
  white-space: nowrap;
}
.sc-table tbody tr.sc-row-bad :is(td, th),
.sc-table tbody tr.sc-row-bad:hover :is(td, th) {
  background: var(--sc-bad-soft);
  color: var(--sc-bad);
}

@media print {
  .sc-toasts,
  .sc-rowmenu,
  .sc-dialog {
    display: none;
  }
}

/* ---------- 7. Master-detail components: split pane, list, thread, search, composer, neutral badge ---------- */
/* For a page that shows a list of things on the left and the selected one on the right. No
 * script is needed for the look; the page's script fills the markup and sets the states.
 *
 * Split pane: put .sc-split straight inside <body data-shell> (as the page's <main>), not
 * inside .sc-page. It fills the height under the top bar; the two panes never make the page
 * scroll, each scrolls inside itself. Width of the list pane: 420px; to change it set
 * --sc-split-list-w on the .sc-split element, e.g. style="--sc-split-list-w: 360px".
 *   <main class="sc-split">
 *     <section class="sc-pane sc-pane-list" aria-label="List">
 *       <div class="sc-pane-head">search, filter</div>
 *       <div class="sc-pane-body"><ul class="sc-list">...</ul></div>
 *     </section>
 *     <section class="sc-pane sc-pane-detail" aria-labelledby="detailTitle">
 *       <div class="sc-pane-head"><h2 class="sc-pane-title" id="detailTitle">Title</h2>
 *         <div class="sc-pane-meta">...</div></div>
 *       <div class="sc-pane-body">thread, or an .sc-empty / .sc-notice state</div>
 *       <div class="sc-composer">...</div>   (a fixed bottom bar; optional)
 *     </section>
 *   </main>
 * .sc-pane-head and .sc-pane-foot / .sc-composer stay put; only .sc-pane-body scrolls.
 *
 * List: a <ul class="sc-list"> of <li><button type="button" class="sc-list-item">. The chosen
 * row has aria-current="true" (set it from script, remove it from the others); the look follows
 * that attribute: a soft background, a bar on the left edge and a bolder title, so it is not told
 * by colour alone. A row holds up to three lines:
 *   <span class="sc-list-top"><span class="sc-list-title">Title</span><span class="sc-list-time">Today</span></span>
 *   <span class="sc-list-preview">Two lines of text at most.</span>
 *   <span class="sc-list-meta"><span class="sc-badge ...">Open</span> ... <span class="sc-list-note">Data</span></span>
 * Only phrasing content goes inside the button (use <span>, never <div> or <p>).
 *
 * Thread: <ol class="sc-thread"> of messages, oldest first.
 *   <li class="sc-msg"> (add sc-msg-accent for the other side of the conversation)
 *     <span class="sc-msg-avatar" aria-hidden="true">A</span>
 *     <div class="sc-msg-main">
 *       <div class="sc-msg-head"><span class="sc-msg-author">Author</span>
 *         <span class="sc-msg-email">a@b.c</span><time class="sc-msg-time" datetime="...">Oct 28, 2026, 9:42 AM</time></div>
 *       <div class="sc-msg-bubble">The text; line breaks are kept. Write it as text, not HTML.</div>
 *       <p class="sc-msg-files">file.png, https://...</p>   (optional; a paperclip is drawn in front)
 *     </div></li>
 *
 * Search field: .sc-search around a type="search" .sc-input with a magnifier in front. Keep a
 * <label class="sc-sr-only" for="..."> so the field is named for screen readers.
 *   <div class="sc-search"><label class="sc-sr-only" for="q">Search</label><input class="sc-input" id="q" type="search"></div>
 *
 * Composer: the bottom bar of a pane. A text area on top, a row of actions under it
 * (.sc-composer-actions: a message on the left, buttons on the right). Other parts may sit
 * between them (an .sc-field with a second input, an .sc-notice that replaces the text area);
 * switch them on and off with the hidden attribute, the .sc-composer, .sc-field, .sc-notice and
 * .sc-btn rules below honour it.
 *   <div class="sc-composer"><label class="sc-sr-only" for="r">Reply</label><textarea class="sc-input" id="r"></textarea>
 *     <div class="sc-composer-actions"><p class="sc-composer-msg" role="alert"></p><button class="sc-btn sc-btn-primary">Send</button></div></div>
 *
 * Neutral badge: .sc-badge-neutral next to .sc-badge-ok, -bad, -warn and -accent, for a value
 * that carries no judgement (Closed, Low, Medium). It still carries text.
 */
.sc-split {
  display: grid;
  grid-template-columns: var(--sc-split-list-w, 420px) minmax(0, 1fr);
  height: calc(100vh - var(--sc-topbar-h));
  min-height: 360px;
  overflow: hidden;
}
.sc-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--sc-surface);
}
.sc-pane-list {
  border-right: 1px solid var(--sc-border);
}
.sc-pane-head,
.sc-pane-foot {
  flex: none;
  padding: 12px 16px;
}
.sc-pane-head {
  border-bottom: 1px solid var(--sc-border);
}
.sc-pane-foot {
  border-top: 1px solid var(--sc-border);
}
.sc-pane-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
.sc-pane-title {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.sc-pane-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  color: var(--sc-muted);
  font-size: 13px;
}

/* List */
.sc-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.sc-list > li {
  border-bottom: 1px solid var(--sc-border);
}
.sc-list-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  padding: 12px 16px 12px 19px;
  border: 0;
  background: transparent;
  color: var(--sc-text);
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s;
}
.sc-list-item:hover {
  background: var(--sc-surface-2);
}
.sc-list-item:focus-visible {
  outline-offset: -2px;
}
.sc-list-item[aria-current="true"],
.sc-list-item[aria-current="true"]:hover {
  background: var(--sc-accent-soft);
}
.sc-list-item[aria-current="true"]::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 4px;
  background: var(--sc-accent-text);
}
.sc-list-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.sc-list-title {
  min-width: 0;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sc-list-item[aria-current="true"] .sc-list-title {
  font-weight: 700;
}
.sc-list-time {
  flex: none;
  color: var(--sc-muted);
  font-size: 12px;
  white-space: nowrap;
}
.sc-list-preview {
  display: -webkit-box;
  overflow: hidden;
  color: var(--sc-muted);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow-wrap: anywhere;
}
.sc-list-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.sc-list-note {
  color: var(--sc-muted);
  font-size: 12px;
}

/* Thread */
.sc-thread {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 0;
  padding: 16px;
  list-style: none;
}
.sc-msg {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.sc-msg-avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--sc-border-strong);
  border-radius: 50%;
  background: var(--sc-surface-2);
  color: var(--sc-text);
  font-size: 13px;
  font-weight: 700;
}
.sc-msg-accent .sc-msg-avatar {
  border-color: transparent;
  background: var(--sc-accent);
  color: var(--sc-accent-ink);
}
.sc-msg-main {
  min-width: 0;
  max-width: 72ch;
}
.sc-msg-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
  margin-bottom: 4px;
  font-size: 12px;
}
.sc-msg-author {
  font-size: 13px;
  font-weight: 700;
}
.sc-msg-email,
.sc-msg-time {
  color: var(--sc-muted);
}
.sc-msg-bubble {
  padding: 10px 12px;
  border: 1px solid var(--sc-border);
  border-radius: 4px 12px 12px 12px;
  background: var(--sc-surface-2);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.sc-msg-accent .sc-msg-bubble {
  border-color: var(--sc-border-strong);
  background: var(--sc-accent-soft);
}
.sc-msg-files {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 6px 0 0;
  color: var(--sc-muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.sc-msg-files::before {
  content: "";
  flex: none;
  width: 14px;
  height: 14px;
  align-self: center;
  background: currentColor;
  -webkit-mask: url("../img/icon-paperclip.svg") center / contain no-repeat;
  mask: url("../img/icon-paperclip.svg") center / contain no-repeat;
}

/* Search field */
.sc-search {
  position: relative;
}
.sc-search::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 11px;
  z-index: 1;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  background: var(--sc-muted);
  pointer-events: none;
  -webkit-mask: url("../img/icon-search.svg") center / contain no-repeat;
  mask: url("../img/icon-search.svg") center / contain no-repeat;
}
.sc-search > .sc-input {
  padding-left: 34px;
}

/* Composer bar */
.sc-composer {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--sc-border);
  background: var(--sc-surface-2);
}
.sc-composer textarea.sc-input {
  min-height: 64px;
  max-height: 200px;
}
.sc-composer-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}
.sc-composer-msg {
  flex: 1 1 auto;
  margin: 0;
  color: var(--sc-bad);
  font-size: 13px;
  font-weight: 600;
}

/* A pane's controls are switched on and off from script with the hidden attribute; these
 * components set their own display, which would otherwise win over it. */
.sc-composer[hidden],
.sc-empty[hidden],
.sc-field[hidden],
.sc-notice[hidden],
.sc-btn[hidden] {
  display: none;
}

/* Neutral badge */
.sc-badge-neutral {
  border-color: var(--sc-border-strong);
  background: var(--sc-surface-2);
  color: var(--sc-muted);
}

@media print {
  .sc-split {
    display: block;
    height: auto;
    min-height: 0;
    overflow: visible;
  }
  .sc-pane-body {
    overflow: visible;
  }
  .sc-composer {
    display: none;
  }
}

/* ---------- 8. Check ---------- */
/* Check: a labelled checkbox. The whole label is the click target. Put the input first and the
 * text after it; the text is the accessible name, so a row of a table that repeats the same
 * words can add aria-label="Can manage members: <email>" to the input.
 *   <label class="sc-check"><input type="checkbox"> Can invite and manage members</label>
 * The box is drawn here (appearance: none): its boundary is --sc-border-control (3:1), the
 * checked state fills with --sc-accent (border --sc-accent-text, which keeps 3:1 in the dark theme
 * too) and draws the mark with borders, as .sc-chip does, so the state does not rest on colour alone. Disabled: add the disabled attribute to the input.
 * To hide one, use the hidden attribute on the label. */
.sc-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  color: var(--sc-text);
  cursor: pointer;
}
.sc-check > input {
  appearance: none;
  display: grid;
  flex: none;
  place-content: center;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 1px solid var(--sc-border-control);
  border-radius: 4px;
  background: var(--sc-surface);
  cursor: inherit;
}
.sc-check > input::after {
  content: "";
  width: 5px;
  height: 9px;
  margin-top: -2px;
  border: solid var(--sc-accent-ink);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  opacity: 0;
}
.sc-check > input:not(:disabled):hover {
  border-color: var(--sc-text);
}
.sc-check > input:checked {
  border-color: var(--sc-accent-text);
  background: var(--sc-accent);
}
.sc-check > input:checked::after {
  opacity: 1;
}
.sc-check > input:focus-visible {
  outline: 2px solid var(--sc-focus);
  outline-offset: 2px;
}
.sc-check > input:disabled {
  border-color: var(--sc-border);
  background: var(--sc-surface-2);
}
.sc-check > input:disabled:checked {
  border-color: var(--sc-muted);
  background: var(--sc-muted);
}
.sc-check:has(> input:disabled) {
  color: var(--sc-muted);
  cursor: not-allowed;
}
@media (forced-colors: active) {
  .sc-check > input:checked {
    border-color: Highlight;
    background: Highlight;
  }
  .sc-check > input::after {
    border-color: HighlightText;
  }
}
/* A component that sets its own display would otherwise win over [hidden]. */
.sc-check[hidden] {
  display: none;
}
