/* MACH Design System (MDS) — components · v1.0 (2026-11-01)
 * Needs tokens.css. Every class starts with "mds-", so it lives next to Tailwind, Bootstrap or Bitrix UI without clashes.
 * Put class="mds" on the root element of the app (or of the embedded app's container) for the base styles.
 * Grammar: one depth strategy (hairline borders, shadow only for floating layers), 4px grid, control height 36px,
 * 14px body, semantic colours only, every interactive element has hover / active / focus-visible / disabled.
 */

/* ---------- base ---------- */
.mds, .mds *, .mds *::before, .mds *::after { box-sizing: border-box; }
.mds {
  font-family: var(--mds-font-sans); font-size: var(--mds-text-md); line-height: var(--mds-leading-normal);
  color: var(--mds-text); background: var(--mds-bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility;
}
.mds :where(h1, h2, h3, h4, p, ul, ol, figure) { margin: 0; }
.mds :where(h1, h2, h3) { font-weight: var(--mds-weight-semibold); line-height: var(--mds-leading-tight); text-wrap: balance; }
.mds :where(p) { text-wrap: pretty; max-width: var(--mds-measure); }
.mds :where(a) { color: var(--mds-link); text-decoration: none; }
.mds :where(a:hover) { text-decoration: underline; text-underline-offset: 2px; }
.mds :where(button, input, select, textarea) { font: inherit; color: inherit; }
.mds :where(:focus-visible) { outline: none; box-shadow: var(--mds-focus-ring); border-radius: var(--mds-radius-xs); }
.mds ::selection { background: var(--mds-accent-soft-2); }
.mds-h1 { font-size: var(--mds-text-2xl); letter-spacing: var(--mds-tracking-tight); font-weight: var(--mds-weight-semibold); }
.mds-h2 { font-size: var(--mds-text-xl); letter-spacing: var(--mds-tracking-tight); font-weight: var(--mds-weight-semibold); }
.mds-h3 { font-size: var(--mds-text-lg); font-weight: var(--mds-weight-semibold); }
.mds-muted { color: var(--mds-text-2); }
.mds-subtle { color: var(--mds-text-3); font-size: var(--mds-text-sm); }
.mds-num { font-variant-numeric: tabular-nums; }
.mds-mono { font-family: var(--mds-font-mono); font-size: 0.92em; }
.mds-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.mds-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- layout ---------- */
.mds-stack { display: flex; flex-direction: column; gap: var(--mds-gap, var(--mds-space-4)); }
.mds-row { display: flex; align-items: center; gap: var(--mds-gap, var(--mds-space-2)); min-width: 0; }
.mds-row--wrap { flex-wrap: wrap; }
.mds-row--between { justify-content: space-between; }
.mds-spacer { flex: 1; }
.mds-grid { display: grid; gap: var(--mds-gap, var(--mds-space-4)); grid-template-columns: repeat(var(--mds-cols, 12), minmax(0, 1fr)); }
.mds-grid--auto { grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--mds-min, 240px)), 1fr)); }
@media (max-width: 767px) { .mds-grid:not(.mds-grid--auto) { grid-template-columns: minmax(0, 1fr); } }

/* App shell: sidebar + topbar + content. Embedded Bitrix24 apps use .mds-page alone (the portal has its own chrome). */
.mds-app { display: grid; grid-template-columns: var(--mds-sidebar-w) minmax(0, 1fr); grid-template-rows: var(--mds-topbar-h) minmax(0, 1fr); min-height: 100dvh; }
.mds-app--collapsed { grid-template-columns: var(--mds-sidebar-w-collapsed) minmax(0, 1fr); }
.mds-sidebar { grid-row: 1 / -1; background: var(--mds-surface); border-right: 1px solid var(--mds-border); display: flex; flex-direction: column; padding: var(--mds-space-3); gap: var(--mds-space-1); overflow-y: auto; }
.mds-sidebar__brand { height: calc(var(--mds-topbar-h) - var(--mds-space-3)); display: flex; align-items: center; gap: var(--mds-space-2); padding: 0 var(--mds-space-2); font-weight: var(--mds-weight-semibold); }
.mds-sidebar__section { margin-top: var(--mds-space-4); padding: 0 var(--mds-space-2) var(--mds-space-1); font-size: var(--mds-text-xs); color: var(--mds-text-3); font-weight: var(--mds-weight-medium); }
.mds-nav-item { display: flex; align-items: center; gap: var(--mds-space-3); height: var(--mds-control-md); padding: 0 var(--mds-space-2); border-radius: var(--mds-radius-sm); color: var(--mds-text-2); font-weight: var(--mds-weight-medium); text-decoration: none !important; transition: background var(--mds-duration-fast) var(--mds-ease-out), color var(--mds-duration-fast) var(--mds-ease-out); }
.mds-nav-item:hover { background: var(--mds-surface-hover); color: var(--mds-text); }
.mds-nav-item[aria-current="page"] { background: var(--mds-accent-soft); color: var(--mds-accent-text); }
.mds-nav-item__count { margin-left: auto; font-size: var(--mds-text-xs); color: var(--mds-text-3); font-variant-numeric: tabular-nums; }
.mds-topbar { display: flex; align-items: center; gap: var(--mds-space-3); padding: 0 var(--mds-space-6); background: var(--mds-surface); border-bottom: 1px solid var(--mds-border); position: sticky; top: 0; z-index: var(--mds-z-sticky); }
.mds-main { overflow: auto; }
.mds-page { width: 100%; max-width: var(--mds-content-max); margin: 0 auto; padding: var(--mds-space-6); display: flex; flex-direction: column; gap: var(--mds-space-6); }
.mds-page--narrow { max-width: calc(var(--mds-form-max) + 2 * var(--mds-space-6)); }
.mds-page-header { display: flex; align-items: flex-start; gap: var(--mds-space-4); flex-wrap: wrap; }
/* Titles keep at least 280px: on a phone the actions wrap below the title instead of squeezing it. */
.mds-page-header__titles { display: flex; flex-direction: column; gap: var(--mds-space-1); min-width: 0; flex: 1 1 280px; }
.mds-page-header__actions { display: flex; gap: var(--mds-space-2); align-items: center; flex-wrap: wrap; }
.mds-breadcrumb { display: flex; gap: var(--mds-space-1); align-items: center; font-size: var(--mds-text-sm); color: var(--mds-text-3); flex-wrap: wrap; }
.mds-breadcrumb a { color: var(--mds-text-2); }
.mds-breadcrumb__sep { color: var(--mds-text-disabled); }
@media (max-width: 1023px) {
  .mds-app { grid-template-columns: minmax(0, 1fr); }
  .mds-sidebar { display: none; }
  .mds-sidebar[data-open="true"] { display: flex; position: fixed; inset: 0 auto 0 0; width: min(86vw, var(--mds-sidebar-w)); z-index: var(--mds-z-drawer); box-shadow: var(--mds-shadow-3); }
  .mds-page { padding: var(--mds-space-4); gap: var(--mds-space-4); }
  .mds-topbar { padding: 0 var(--mds-space-4); }
}

/* ---------- buttons ---------- */
.mds-btn {
  --_bg: var(--mds-surface); --_fg: var(--mds-text); --_bd: var(--mds-border-strong); --_bg-h: var(--mds-surface-2); --_bg-a: var(--mds-surface-sunken);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--mds-space-2);
  height: var(--mds-control-md); padding: 0 var(--mds-space-4); border-radius: var(--mds-radius-md);
  border: 1px solid var(--_bd); background: var(--_bg); color: var(--_fg);
  font-size: var(--mds-text-md); font-weight: var(--mds-weight-medium); line-height: 1; white-space: nowrap; cursor: pointer; user-select: none;
  transition: background-color var(--mds-duration-fast) var(--mds-ease-out), border-color var(--mds-duration-fast) var(--mds-ease-out), transform var(--mds-duration-instant) var(--mds-ease-out);
}
.mds-btn:hover { background: var(--_bg-h); }
.mds-btn:active { background: var(--_bg-a); transform: scale(0.97); }
.mds-btn:focus-visible { outline: none; box-shadow: var(--mds-focus-ring); }
.mds-btn:disabled, .mds-btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; transform: none; }
.mds-btn svg { width: var(--mds-icon-sm); height: var(--mds-icon-sm); flex: none; }
.mds-btn--primary { --_bg: var(--mds-accent); --_fg: var(--mds-on-accent); --_bd: transparent; --_bg-h: var(--mds-accent-hover); --_bg-a: var(--mds-accent-press); }
.mds-btn--ghost { --_bg: transparent; --_bd: transparent; --_fg: var(--mds-text-2); --_bg-h: var(--mds-surface-hover); --_bg-a: var(--mds-surface-sunken); }
.mds-btn--danger { --_bg: var(--mds-danger-solid); --_fg: #fff; --_bd: transparent; --_bg-h: var(--mds-danger); --_bg-a: var(--mds-danger); }
.mds-btn--danger-quiet { --_fg: var(--mds-danger); }
.mds-btn--sm { height: var(--mds-control-sm); padding: 0 var(--mds-space-3); font-size: var(--mds-text-sm); border-radius: var(--mds-radius-sm); }
.mds-btn--lg { height: var(--mds-control-lg); padding: 0 var(--mds-space-5); font-size: var(--mds-text-lg); }
.mds-btn--icon { width: var(--mds-control-md); padding: 0; }
.mds-btn--icon.mds-btn--sm { width: var(--mds-control-sm); }
.mds-btn--block { width: 100%; }
.mds-btn[aria-busy="true"] { color: transparent; position: relative; pointer-events: none; }
.mds-btn[aria-busy="true"]::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--_fg); border-right-color: transparent; animation: mds-spin 0.7s linear infinite; }
@media (pointer: coarse) { .mds-btn { min-height: var(--mds-control-lg); } }

/* ---------- form fields ---------- */
.mds-field { display: flex; flex-direction: column; gap: var(--mds-space-1); min-width: 0; }
.mds-label { font-size: var(--mds-text-sm); font-weight: var(--mds-weight-medium); color: var(--mds-text); }
.mds-label__req { color: var(--mds-danger); margin-left: 2px; }
.mds-label__opt { color: var(--mds-text-3); font-weight: var(--mds-weight-regular); margin-left: var(--mds-space-1); }
.mds-hint { font-size: var(--mds-text-xs); color: var(--mds-text-3); }
.mds-error { font-size: var(--mds-text-xs); color: var(--mds-danger); display: flex; gap: var(--mds-space-1); align-items: flex-start; }
.mds-input, .mds-select, .mds-textarea {
  width: 100%; height: var(--mds-control-md); padding: 0 var(--mds-space-3);
  background: var(--mds-input-bg); color: var(--mds-text); border: 1px solid var(--mds-border-input); border-radius: var(--mds-radius-md);
  font-size: var(--mds-text-md); transition: border-color var(--mds-duration-fast) var(--mds-ease-out), box-shadow var(--mds-duration-fast) var(--mds-ease-out);
}
.mds-textarea { height: auto; min-height: 88px; padding: var(--mds-space-2) var(--mds-space-3); line-height: var(--mds-leading-normal); resize: vertical; }
.mds-select { appearance: none; padding-right: var(--mds-space-8); background-image: linear-gradient(45deg, transparent 50%, var(--mds-text-3) 50%), linear-gradient(135deg, var(--mds-text-3) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.mds-input::placeholder, .mds-textarea::placeholder { color: var(--mds-text-3); }
.mds-input:hover, .mds-select:hover, .mds-textarea:hover { border-color: var(--mds-text-3); }
.mds-input:focus, .mds-select:focus, .mds-textarea:focus { outline: none; border-color: var(--mds-accent); box-shadow: 0 0 0 3px var(--mds-accent-soft-2); }
.mds-input[aria-invalid="true"], .mds-select[aria-invalid="true"], .mds-textarea[aria-invalid="true"] { border-color: var(--mds-danger); }
.mds-input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--mds-danger-soft); }
.mds-input:disabled, .mds-select:disabled, .mds-textarea:disabled { background: var(--mds-surface-sunken); color: var(--mds-text-disabled); cursor: not-allowed; }
.mds-input[readonly] { background: var(--mds-surface-2); }
.mds-input--sm { height: var(--mds-control-sm); font-size: var(--mds-text-sm); }
.mds-input-group { position: relative; display: flex; align-items: center; }
.mds-input-group > svg { position: absolute; left: var(--mds-space-3); width: var(--mds-icon-sm); height: var(--mds-icon-sm); color: var(--mds-text-3); pointer-events: none; }
.mds-input-group > .mds-input { padding-left: calc(var(--mds-space-3) + var(--mds-icon-sm) + var(--mds-space-2)); }
.mds-check { display: inline-flex; align-items: center; gap: var(--mds-space-2); cursor: pointer; min-height: 24px; }
.mds-check input:not(.mds-switch) { width: 16px; height: 16px; margin: 0; accent-color: var(--mds-accent); cursor: pointer; }
.mds-switch { appearance: none; width: 32px; height: 18px; border-radius: var(--mds-radius-full); background: var(--mds-border-strong); position: relative; cursor: pointer; transition: background var(--mds-duration-fast) var(--mds-ease-out); flex: none; }
.mds-switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: var(--mds-shadow-1); transition: transform var(--mds-duration-fast) var(--mds-ease-out); }
.mds-switch:checked { background: var(--mds-accent); }
.mds-switch:checked::after { transform: translateX(14px); }
.mds-form { display: flex; flex-direction: column; gap: var(--mds-space-5); max-width: var(--mds-form-max); }
.mds-form-section { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: var(--mds-space-6); padding: var(--mds-space-6) 0; border-top: 1px solid var(--mds-divider); }
.mds-form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--mds-space-4); }
.mds-form-actions { display: flex; gap: var(--mds-space-2); justify-content: flex-end; padding-top: var(--mds-space-4); border-top: 1px solid var(--mds-divider); }
@media (max-width: 767px) { .mds-form-section { grid-template-columns: 1fr; gap: var(--mds-space-3); } .mds-input, .mds-select { height: var(--mds-control-lg); font-size: var(--mds-text-lg); } }

/* ---------- surfaces ---------- */
.mds-card { background: var(--mds-surface); border: 1px solid var(--mds-border); border-radius: var(--mds-radius-lg); min-width: 0; }
.mds-card__header { display: flex; align-items: center; gap: var(--mds-space-3); padding: var(--mds-space-4) var(--mds-space-5); border-bottom: 1px solid var(--mds-divider); min-height: 56px; }
.mds-card__title { font-size: var(--mds-text-lg); font-weight: var(--mds-weight-semibold); }
.mds-card__body { padding: var(--mds-space-5); }
.mds-card__footer { padding: var(--mds-space-3) var(--mds-space-5); border-top: 1px solid var(--mds-divider); display: flex; gap: var(--mds-space-2); justify-content: flex-end; }
.mds-card--flush .mds-card__body { padding: 0; }
.mds-card--interactive { cursor: pointer; transition: border-color var(--mds-duration-fast) var(--mds-ease-out); }
.mds-card--interactive:hover { border-color: var(--mds-border-strong); }
.mds-divider { border: 0; border-top: 1px solid var(--mds-divider); margin: 0; }
.mds-dl { display: grid; grid-template-columns: minmax(120px, max-content) minmax(0, 1fr); gap: var(--mds-space-2) var(--mds-space-6); font-size: var(--mds-text-md); }
.mds-dl dt { color: var(--mds-text-2); }
.mds-dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* KPI tile: a number that answers a question. Delta colour = good/bad, not up/down. */
.mds-kpis { display: grid; gap: var(--mds-space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
@media (max-width: 767px) { .mds-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--mds-space-3); } .mds-kpi__value { font-size: var(--mds-text-xl); white-space: nowrap; } .mds-kpi { padding: var(--mds-space-3) var(--mds-space-4); } }
.mds-kpi { background: var(--mds-surface); border: 1px solid var(--mds-border); border-radius: var(--mds-radius-lg); padding: var(--mds-space-4) var(--mds-space-5); display: flex; flex-direction: column; gap: var(--mds-space-1); min-width: 0; }
.mds-kpi__label { font-size: var(--mds-text-sm); color: var(--mds-text-2); }
.mds-kpi__value { font-size: var(--mds-text-3xl); font-weight: var(--mds-weight-semibold); letter-spacing: var(--mds-tracking-tight); font-variant-numeric: tabular-nums; line-height: var(--mds-leading-tight); }
.mds-kpi__meta { font-size: var(--mds-text-xs); color: var(--mds-text-3); display: flex; gap: var(--mds-space-2); align-items: center; }
.mds-delta { font-weight: var(--mds-weight-medium); font-variant-numeric: tabular-nums; }
.mds-delta--good { color: var(--mds-success); }
.mds-delta--bad { color: var(--mds-danger); }

/* ---------- badges & tags ---------- */
.mds-badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 var(--mds-space-2); border-radius: var(--mds-radius-full); font-size: var(--mds-text-xs); font-weight: var(--mds-weight-medium); white-space: nowrap; background: var(--mds-neutral-soft); color: var(--mds-neutral); }
.mds-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.mds-badge--plain::before { display: none; }
.mds-badge--success { background: var(--mds-success-soft); color: var(--mds-success); }
.mds-badge--warning { background: var(--mds-warning-soft); color: var(--mds-warning); }
.mds-badge--danger { background: var(--mds-danger-soft); color: var(--mds-danger); }
.mds-badge--info { background: var(--mds-info-soft); color: var(--mds-info); }
.mds-badge--accent { background: var(--mds-accent-soft); color: var(--mds-accent-text); }
.mds-tag { display: inline-flex; align-items: center; gap: var(--mds-space-1); height: 24px; padding: 0 var(--mds-space-2); border: 1px solid var(--mds-border); border-radius: var(--mds-radius-sm); font-size: var(--mds-text-xs); color: var(--mds-text-2); background: var(--mds-surface); }
.mds-count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--mds-radius-full); background: var(--mds-accent); color: var(--mds-on-accent); font-size: 11px; font-weight: var(--mds-weight-semibold); display: inline-grid; place-items: center; font-variant-numeric: tabular-nums; }

/* ---------- data table ---------- */
.mds-table-wrap { overflow: auto; border: 1px solid var(--mds-border); border-radius: var(--mds-radius-lg); background: var(--mds-surface); max-width: 100%; }
/* A narrow screen scrolls the table sideways instead of crushing its columns (or use a card list, see README). */
.mds-table { width: 100%; min-width: 720px; border-collapse: separate; border-spacing: 0; font-size: var(--mds-text-md); }
.mds-table th { position: sticky; top: 0; z-index: 1; background: var(--mds-surface-2); text-align: left; font-weight: var(--mds-weight-medium); font-size: var(--mds-text-sm); color: var(--mds-text-2); height: 40px; padding: 0 var(--mds-space-4); border-bottom: 1px solid var(--mds-border); white-space: nowrap; }
.mds-table td { height: var(--mds-row-default); padding: 0 var(--mds-space-4); border-bottom: 1px solid var(--mds-divider); vertical-align: middle; }
.mds-table tbody tr:last-child td { border-bottom: 0; }
.mds-table tbody tr { transition: background var(--mds-duration-instant) linear; }
.mds-table tbody tr:hover { background: var(--mds-surface-hover); }
.mds-table tbody tr[aria-selected="true"] { background: var(--mds-surface-selected); }
.mds-table .is-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mds-table .is-actions { width: 1%; white-space: nowrap; text-align: right; }
.mds-table .is-check { width: 44px; padding-right: 0; }
.mds-table .is-primary { font-weight: var(--mds-weight-medium); color: var(--mds-text); }
.mds-table th[aria-sort] { cursor: pointer; user-select: none; }
.mds-table th[aria-sort="ascending"]::after { content: " ↑"; color: var(--mds-text-3); }
.mds-table th[aria-sort="descending"]::after { content: " ↓"; color: var(--mds-text-3); }
.mds-table--compact td { height: var(--mds-row-compact); }
.mds-table--compact th { height: 34px; }
.mds-table-footer { display: flex; align-items: center; gap: var(--mds-space-3); padding: var(--mds-space-3) var(--mds-space-4); border-top: 1px solid var(--mds-border); font-size: var(--mds-text-sm); color: var(--mds-text-2); }
.mds-bulkbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--mds-space-3); padding: var(--mds-space-2) var(--mds-space-4); background: var(--mds-accent-soft); color: var(--mds-accent-text); border-bottom: 1px solid var(--mds-border); font-weight: var(--mds-weight-medium); }

/* Toolbar above a list: search, filters, view options, primary action on the right. */
.mds-toolbar { display: flex; align-items: center; gap: var(--mds-space-2); flex-wrap: wrap; }
.mds-toolbar .mds-input-group { width: min(320px, 100%); }
.mds-chip { display: inline-flex; align-items: center; gap: var(--mds-space-1); height: var(--mds-control-sm); padding: 0 var(--mds-space-3); border: 1px dashed var(--mds-border-strong); border-radius: var(--mds-radius-full); font-size: var(--mds-text-sm); color: var(--mds-text-2); background: transparent; cursor: pointer; }
.mds-chip[aria-pressed="true"] { border-style: solid; border-color: var(--mds-accent); background: var(--mds-accent-soft); color: var(--mds-accent-text); }

/* ---------- navigation inside a page ---------- */
.mds-tabs { display: flex; gap: var(--mds-space-1); border-bottom: 1px solid var(--mds-border); overflow-x: auto; scrollbar-width: none; }
.mds-tab { height: 40px; padding: 0 var(--mds-space-3); border: 0; background: none; color: var(--mds-text-2); font-weight: var(--mds-weight-medium); cursor: pointer; position: relative; white-space: nowrap; display: inline-flex; align-items: center; gap: var(--mds-space-2); }
.mds-tab:hover { color: var(--mds-text); }
.mds-tab[aria-selected="true"] { color: var(--mds-text); }
.mds-tab[aria-selected="true"]::after { content: ""; position: absolute; left: var(--mds-space-2); right: var(--mds-space-2); bottom: -1px; height: 2px; border-radius: 2px 2px 0 0; background: var(--mds-accent); }
.mds-segmented { display: inline-flex; padding: 2px; background: var(--mds-surface-sunken); border-radius: var(--mds-radius-md); gap: 2px; }
.mds-segmented button { height: calc(var(--mds-control-md) - 4px); padding: 0 var(--mds-space-3); border: 0; border-radius: var(--mds-radius-sm); background: transparent; color: var(--mds-text-2); font-weight: var(--mds-weight-medium); cursor: pointer; }
.mds-segmented button[aria-pressed="true"] { background: var(--mds-surface); color: var(--mds-text); box-shadow: var(--mds-shadow-1); }
.mds-pagination { display: flex; align-items: center; gap: var(--mds-space-1); }
.mds-pagination [aria-current="page"] { background: var(--mds-accent-soft); color: var(--mds-accent-text); border-color: transparent; }
.mds-steps { display: flex; gap: var(--mds-space-2); align-items: center; counter-reset: step; flex-wrap: wrap; }
.mds-step { display: flex; align-items: center; gap: var(--mds-space-2); color: var(--mds-text-3); font-weight: var(--mds-weight-medium); font-size: var(--mds-text-sm); }
.mds-step::before { counter-increment: step; content: counter(step); width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--mds-border-strong); font-size: var(--mds-text-xs); }
.mds-step[aria-current="step"] { color: var(--mds-text); }
.mds-step[aria-current="step"]::before { background: var(--mds-accent); color: var(--mds-on-accent); border-color: transparent; }
.mds-step[data-done="true"]::before { content: "✓"; background: var(--mds-accent-soft); color: var(--mds-accent-text); border-color: transparent; }
.mds-step + .mds-step::after { order: -1; content: ""; width: 24px; height: 1px; background: var(--mds-border-strong); }

/* ---------- feedback ---------- */
.mds-alert { display: flex; gap: var(--mds-space-3); padding: var(--mds-space-3) var(--mds-space-4); border-radius: var(--mds-radius-md); background: var(--mds-info-soft); color: var(--mds-text); border: 1px solid color-mix(in srgb, var(--mds-info) 22%, transparent); font-size: var(--mds-text-md); }
.mds-alert__title { font-weight: var(--mds-weight-semibold); }
.mds-alert > svg { flex: none; width: var(--mds-icon-md); height: var(--mds-icon-md); color: var(--mds-info); }
.mds-alert--success { background: var(--mds-success-soft); border-color: color-mix(in srgb, var(--mds-success) 22%, transparent); }
.mds-alert--success > svg { color: var(--mds-success); }
.mds-alert--warning { background: var(--mds-warning-soft); border-color: color-mix(in srgb, var(--mds-warning) 25%, transparent); }
.mds-alert--warning > svg { color: var(--mds-warning); }
.mds-alert--danger { background: var(--mds-danger-soft); border-color: color-mix(in srgb, var(--mds-danger) 22%, transparent); }
.mds-alert--danger > svg { color: var(--mds-danger); }
.mds-toast-region { position: fixed; right: var(--mds-space-6); bottom: var(--mds-space-6); z-index: var(--mds-z-toast); display: flex; flex-direction: column; gap: var(--mds-space-2); width: min(380px, calc(100vw - 2 * var(--mds-space-4))); }
.mds-toast { display: flex; gap: var(--mds-space-3); align-items: flex-start; padding: var(--mds-space-3) var(--mds-space-4); background: var(--mds-p-ink-900); color: var(--mds-p-ink-0); border-radius: var(--mds-radius-md); box-shadow: var(--mds-shadow-3); font-size: var(--mds-text-md); animation: mds-in var(--mds-duration-base) var(--mds-ease-out); }
.mds-toast a, .mds-toast button { color: var(--mds-p-teal-300); background: none; border: 0; font-weight: var(--mds-weight-semibold); cursor: pointer; padding: 0; }
:root[data-theme="dark"] .mds-toast { background: var(--mds-p-ink-0); color: var(--mds-p-ink-900); }
:root[data-theme="dark"] .mds-toast a, :root[data-theme="dark"] .mds-toast button { color: var(--mds-p-teal-800); }
.mds-progress { height: 6px; border-radius: var(--mds-radius-full); background: var(--mds-surface-sunken); overflow: hidden; }
.mds-progress > span { display: block; height: 100%; background: var(--mds-accent); border-radius: inherit; transition: width var(--mds-duration-slow) var(--mds-ease-out); }
.mds-spinner { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--mds-border-strong); border-top-color: var(--mds-accent); animation: mds-spin 0.7s linear infinite; }
.mds-skeleton { background: linear-gradient(90deg, var(--mds-surface-sunken) 0%, var(--mds-surface-2) 50%, var(--mds-surface-sunken) 100%); background-size: 200% 100%; animation: mds-shimmer 1.4s linear infinite; border-radius: var(--mds-radius-sm); min-height: 12px; }

/* Empty / error / no-permission state: what is here, why it is empty, ONE next action. */
.mds-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--mds-space-3); padding: var(--mds-space-12) var(--mds-space-6); color: var(--mds-text-2); }
.mds-empty__icon { width: 48px; height: 48px; border-radius: var(--mds-radius-lg); background: var(--mds-surface-sunken); color: var(--mds-text-3); display: grid; place-items: center; }
.mds-empty__icon svg { width: 24px; height: 24px; }
.mds-empty__title { font-size: var(--mds-text-lg); font-weight: var(--mds-weight-semibold); color: var(--mds-text); }
.mds-empty__text { max-width: 44ch; }

/* ---------- overlays ---------- */
.mds-overlay { position: fixed; inset: 0; background: var(--mds-overlay); z-index: var(--mds-z-modal); display: grid; place-items: center; padding: var(--mds-space-4); animation: mds-fade var(--mds-duration-base) var(--mds-ease-out); }
.mds-modal { width: min(560px, 100%); max-height: calc(100dvh - 2 * var(--mds-space-8)); display: flex; flex-direction: column; background: var(--mds-surface); border-radius: var(--mds-radius-xl); box-shadow: var(--mds-shadow-3); animation: mds-pop var(--mds-duration-base) var(--mds-ease-out); }
.mds-modal--lg { width: min(880px, 100%); }
.mds-modal__header { padding: var(--mds-space-5) var(--mds-space-6) var(--mds-space-3); display: flex; gap: var(--mds-space-3); align-items: flex-start; }
.mds-modal__title { font-size: var(--mds-text-xl); font-weight: var(--mds-weight-semibold); flex: 1; }
.mds-modal__body { padding: 0 var(--mds-space-6) var(--mds-space-5); overflow: auto; }
.mds-modal__footer { padding: var(--mds-space-4) var(--mds-space-6); border-top: 1px solid var(--mds-divider); display: flex; gap: var(--mds-space-2); justify-content: flex-end; }
.mds-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--mds-surface); box-shadow: var(--mds-shadow-3); z-index: var(--mds-z-drawer); display: flex; flex-direction: column; animation: mds-slide var(--mds-duration-slow) var(--mds-ease-out); }
.mds-drawer__header { padding: var(--mds-space-4) var(--mds-space-5); border-bottom: 1px solid var(--mds-divider); display: flex; align-items: center; gap: var(--mds-space-3); min-height: var(--mds-topbar-h); }
.mds-drawer__body { padding: var(--mds-space-5); overflow: auto; flex: 1; }
.mds-drawer__footer { padding: var(--mds-space-3) var(--mds-space-5); border-top: 1px solid var(--mds-divider); display: flex; gap: var(--mds-space-2); justify-content: flex-end; }
.mds-menu { min-width: 200px; padding: var(--mds-space-1); background: var(--mds-surface); border-radius: var(--mds-radius-md); box-shadow: var(--mds-shadow-2); z-index: var(--mds-z-dropdown); animation: mds-pop var(--mds-duration-fast) var(--mds-ease-out); transform-origin: var(--mds-origin, top left); }
.mds-menu__item { display: flex; align-items: center; gap: var(--mds-space-2); width: 100%; height: 32px; padding: 0 var(--mds-space-2); border: 0; border-radius: var(--mds-radius-sm); background: none; color: var(--mds-text); font-size: var(--mds-text-md); text-align: left; cursor: pointer; }
.mds-menu__item:hover, .mds-menu__item:focus-visible { background: var(--mds-surface-hover); box-shadow: none; }
.mds-menu__item--danger { color: var(--mds-danger); }
.mds-menu__sep { height: 1px; background: var(--mds-divider); margin: var(--mds-space-1) 0; }
.mds-tooltip { padding: var(--mds-space-1) var(--mds-space-2); background: var(--mds-p-ink-900); color: var(--mds-p-ink-0); border-radius: var(--mds-radius-sm); font-size: var(--mds-text-xs); z-index: var(--mds-z-tooltip); max-width: 280px; }

/* ---------- people & misc ---------- */
.mds-avatar { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--mds-accent-soft-2); color: var(--mds-accent-text); font-size: var(--mds-text-xs); font-weight: var(--mds-weight-semibold); flex: none; overflow: hidden; }
.mds-avatar img { width: 100%; height: 100%; object-fit: cover; }
.mds-avatar--lg { width: 40px; height: 40px; font-size: var(--mds-text-md); }
.mds-kbd { font-family: var(--mds-font-mono); font-size: 11px; padding: 1px 5px; border: 1px solid var(--mds-border-strong); border-bottom-width: 2px; border-radius: var(--mds-radius-xs); color: var(--mds-text-2); background: var(--mds-surface); }
.mds-timeline { display: flex; flex-direction: column; }
.mds-timeline__item { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: var(--mds-space-3); padding-bottom: var(--mds-space-4); position: relative; }
.mds-timeline__item::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--mds-border-strong); margin: 6px auto 0; }
.mds-timeline__item::after { content: ""; position: absolute; left: 9.5px; top: 18px; bottom: 0; width: 1px; background: var(--mds-divider); }
.mds-timeline__item:last-child::after { display: none; }

/* ---------- motion ---------- */
@keyframes mds-spin { to { transform: rotate(360deg); } }
@keyframes mds-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes mds-fade { from { opacity: 0; } }
@keyframes mds-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes mds-pop { from { opacity: 0; transform: scale(0.96); } }
@keyframes mds-slide { from { transform: translateX(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .mds *, .mds *::before, .mds *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
