/*! ui-kit v1.1.0 | MIT | https://gitlab.dimaga.tech/frontend/ui-kit */
/* Design tokens and components. No external fonts or CDNs: the files are
   served by the application itself (see README.md).
   Theme: light by default, dark via prefers-color-scheme or [data-theme="dark"];
   [data-theme="light"] forces light. tg.js (optional) maps Telegram Mini App
   colours onto the same tokens. */

/* ---------- tokens ---------- */
:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --fs-2xs: 11px;
  --fs-xs: 12px;
  --fs-sm: 13.5px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 21px;
  --fs-2xl: 26px;
  --lh: 1.5;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-full: 999px;

  --dur: .16s;
  --tap: 44px; /* minimum touch target */
  --tap-sm: 34px;
  --tap-lg: 52px;
  --sticky-top: 0px; /* height of a sticky app header above sticky table heads */
  --maxw: 640px;

  /* light */
  --bg: #f5f4fa;
  --surface: #ffffff;
  --surface-2: #f0eef8;
  --border: #e2dfee;
  --border-strong: #cfcae2;
  --text: #1a1730;
  --muted: #676382;
  --accent: #7446f2;
  --accent-hover: #6334e6;
  --accent-soft: rgba(116, 70, 242, .11);
  --on-accent: #ffffff;
  --link: #6334e6;
  --ok: #14743e;
  --ok-soft: rgba(24, 138, 74, .11);
  --warn: #935800;
  --warn-soft: rgba(214, 131, 0, .13);
  --err: #bd2f35;
  --err-soft: rgba(208, 52, 58, .1);
  --info: #2a63be;
  --info-soft: rgba(47, 111, 214, .1);
  --shadow-sm: 0 1px 2px rgba(26, 23, 48, .06);
  --shadow-md: 0 8px 28px rgba(26, 23, 48, .14);
  --overlay: rgba(18, 16, 32, .45);
  --on-err: #ffffff;
  --knob: #ffffff;
  --focus: var(--accent);
  color-scheme: light;
}

/* The two dark blocks must stay identical (checked by scripts/check.mjs). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0e17;
    --surface: #18162a;
    --surface-2: #211e36;
    --border: #2d2946;
    --border-strong: #3d3860;
    --text: #ebe8f7;
    --muted: #9d97ba;
    --accent: #8f66ff;
    --accent-hover: #a384ff;
    --accent-soft: rgba(143, 102, 255, .18);
    --on-accent: #ffffff;
    --link: #b39cff;
    --ok: #4cc47a;
    --ok-soft: rgba(76, 196, 122, .14);
    --warn: #f0a54a;
    --warn-soft: rgba(240, 165, 74, .15);
    --err: #f06a6a;
    --err-soft: rgba(240, 106, 106, .14);
    --info: #6ea2ff;
    --info-soft: rgba(110, 162, 255, .14);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow-md: 0 12px 36px rgba(0, 0, 0, .5);
    --overlay: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f0e17;
  --surface: #18162a;
  --surface-2: #211e36;
  --border: #2d2946;
  --border-strong: #3d3860;
  --text: #ebe8f7;
  --muted: #9d97ba;
  --accent: #8f66ff;
  --accent-hover: #a384ff;
  --accent-soft: rgba(143, 102, 255, .18);
  --on-accent: #ffffff;
  --link: #b39cff;
  --ok: #4cc47a;
  --ok-soft: rgba(76, 196, 122, .14);
  --warn: #f0a54a;
  --warn-soft: rgba(240, 165, 74, .15);
  --err: #f06a6a;
  --err-soft: rgba(240, 106, 106, .14);
  --info: #6ea2ff;
  --info-soft: rgba(110, 162, 255, .14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-md: 0 12px 36px rgba(0, 0, 0, .5);
  --overlay: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-md)/var(--lh) var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: var(--fs-2xl); font-weight: 700; }
h2 { font-size: var(--fs-xl); font-weight: 700; }
h3 { font-size: var(--fs-lg); font-weight: 650; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: .92em; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* visually hidden, still read by screen readers */
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.icon {
  width: 20px; height: 20px; flex-shrink: 0; display: inline-block; vertical-align: middle;
  stroke: currentColor; fill: none;
}
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 28px; height: 28px; }
.icon-xl { width: 44px; height: 44px; }

/* ---------- layout ---------- */
/* side and bottom safe areas: iPhone in landscape, Telegram Mini App */
.container { width: 100%; max-width: var(--maxw); margin: 0 auto;
  padding: var(--sp-4) max(var(--sp-4), env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(var(--sp-4), env(safe-area-inset-left)); }
.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.stack-lg { display: flex; flex-direction: column; gap: var(--sp-4); }
.row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.xsmall { font-size: var(--fs-xs); }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { height: 1px; background: var(--border); border: 0; margin: var(--sp-4) 0; }
.section-title {
  font-size: var(--fs-xs); font-weight: 650; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); margin: var(--sp-5) 0 var(--sp-2);
}
/* group title: a divider with a caption, <div class="group-title">Узлы <span class="sub">3 из 5</span></div> */
.group-title {
  display: flex; align-items: center; gap: var(--sp-2); margin: var(--sp-6) 0 var(--sp-3);
  font-size: var(--fs-xs); font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.group-title:first-child { margin-top: 0; }
.group-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.group-title .sub { text-transform: none; letter-spacing: 0; font-weight: 500; }
/* responsive grid: .grid-2/3/4 collapse to 2 columns below 960 px and to one below 640 px */
.grid { display: grid; gap: var(--sp-4); grid-template-columns: minmax(0, 1fr); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid > .span-all { grid-column: 1 / -1; }
/* the grid gap spaces its items: no sibling margins */
.grid > :is(.card, .field, .switch, .check) + :is(.card, .field, .switch, .check) { margin-top: 0; }
@media (max-width: 960px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); } }
/* spacing: top margins on the token scale */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--sp-1); }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); }
.mt-6 { margin-top: var(--sp-6); }

/* app header */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg); /* fallback without color-mix() */
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.app-header .inner {
  max-width: var(--maxw); margin: 0 auto; padding: 10px max(var(--sp-4), env(safe-area-inset-right)) 10px max(var(--sp-4), env(safe-area-inset-left));
  display: flex; align-items: center; gap: var(--sp-3); min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 750; font-size: var(--fs-lg); color: var(--text); }
.brand:hover { text-decoration: none; }
.brand svg { width: 28px; height: 28px; }
.brand .dot { color: var(--accent); }

/* page head (title + back) */
.page-head { display: flex; align-items: center; gap: var(--sp-2); margin: var(--sp-2) 0 var(--sp-4); min-height: 40px; }
.page-head h1 { font-size: var(--fs-xl); }

/* ---------- card ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--sp-4); box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--sp-3); }
.card.compact { padding: var(--sp-3); border-radius: var(--r-md); }
/* flush: no padding, for a table or a list edge to edge; .card-head keeps its inset */
.card.flush { padding: 0; overflow: clip; }
.card.flush > .card-head { padding: var(--sp-4) var(--sp-4) 0; }
.card-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.card-head h3 { flex: 1; min-width: 0; }
.card-head .icon-tile { flex: none; }
.card-foot { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-4); }
.icon-tile {
  width: 40px; height: 40px; border-radius: var(--r-md); display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
/* Icons and their tiles never shrink: next to long text in a flex row they
   would be squashed. Add new icon-like classes here. */
.icon, .icon-tile, .avatar, .dot, .brand svg, .qr { flex-shrink: 0; }
.icon-tile.ok { background: var(--ok-soft); color: var(--ok); }
.icon-tile.warn { background: var(--warn-soft); color: var(--warn); }
.icon-tile.err { background: var(--err-soft); color: var(--err); }
.icon-tile.muted { background: var(--surface-2); color: var(--muted); }
.icon-tile.info { background: var(--info-soft); color: var(--info); }
.icon-tile.sm { width: 34px; height: 34px; border-radius: 10px; }
.icon-tile.sm .icon { width: 18px; height: 18px; }
.icon-tile.lg { width: 48px; height: 48px; border-radius: var(--r-lg); }
.icon-tile.lg .icon { width: 24px; height: 24px; }

/* list rows (tappable) */
.list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; }
.list-item {
  display: flex; align-items: center; gap: var(--sp-3); padding: 12px var(--sp-3); min-height: 56px;
  background: var(--surface); color: var(--text); border: 0; width: 100%; text-align: left;
  font: inherit; cursor: pointer; transition: background var(--dur);
}
.list-item + .list-item { border-top: 1px solid var(--border); }
.list-item:hover { background: var(--surface-2); text-decoration: none; }
.list-item:focus-visible { outline-offset: -2px; } /* .list clips outside outlines */
.list-item .title { font-weight: 600; }
.list-item .sub { color: var(--muted); font-size: var(--fs-sm); }
.list-item .chev { color: var(--muted); margin-left: auto; }

/* key/value lines */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px var(--sp-4); font-size: var(--fs-sm); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; min-width: 0; overflow-wrap: anywhere; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 var(--sp-4); border-radius: var(--r-md);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: 600 var(--fs-sm)/1 var(--font); cursor: pointer; white-space: nowrap; position: relative;
  transition: background var(--dur), border-color var(--dur), color var(--dur), opacity var(--dur);
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: default; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-ghost.plain { color: var(--muted); }
.btn-ghost.plain:hover { color: var(--text); background: var(--surface-2); }
.btn-danger { color: var(--err); border-color: var(--border-strong); border-color: color-mix(in srgb, var(--err) 35%, var(--border)); }
.btn-danger:hover { background: var(--err-soft); }
.btn-danger-ghost { color: var(--err); }
.btn-danger-ghost:hover { background: var(--err-soft); color: var(--err); }
.btn-sm { min-height: var(--tap-sm); padding: 0 var(--sp-3); border-radius: var(--r-sm); font-size: var(--fs-xs); }
.btn-lg { min-height: var(--tap-lg); padding: 0 var(--sp-6); border-radius: var(--r-lg); font-size: var(--fs-md); }
.btn-block { width: 100%; }
.btn-icon { width: var(--tap); padding: 0; }
.btn-icon.btn-sm { width: var(--tap-sm); }
.btn-icon.btn-lg { width: var(--tap-lg); }
.btn .icon { width: 18px; height: 18px; }
.btn-lg .icon { width: 20px; height: 20px; }
/* stacked: icon over a short label, for app-like button grids */
.btn-stack { flex-direction: column; gap: var(--sp-1); min-height: 64px; padding: var(--sp-2) var(--sp-3); white-space: normal; text-align: center; font-size: var(--fs-xs); line-height: 1.2; }
.btn-stack .icon { width: 22px; height: 22px; }
.spin { animation: ui-spin 1s linear infinite; }
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* ---------- form fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: var(--sp-4); }
.field > label, .label { font-size: var(--fs-sm); font-weight: 600; }
.field > label .muted, .label .muted { font-weight: 500; }
.hint { color: var(--muted); font-size: var(--fs-xs); line-height: 1.45; }
.input, .select, .textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border-radius: var(--r-md);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: var(--fs-md) var(--font); outline: none;
  transition: border-color var(--dur), box-shadow var(--dur);
}
.textarea { min-height: 84px; resize: vertical; font: var(--fs-sm)/1.5 var(--mono); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--err); }
.input:disabled, .select:disabled, .textarea:disabled { opacity: .6; cursor: default; background-color: var(--surface-2); }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 40px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
/* compact inputs for dense layouts (tables, toolbars) */
.input-sm, .select-sm { min-height: var(--tap-sm); padding-top: 6px; padding-bottom: 6px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.select.select-sm { padding-right: 36px; }
.input-lg, .select-lg { min-height: var(--tap-lg); padding-top: 12px; padding-bottom: 12px; font-size: var(--fs-lg); border-radius: var(--r-lg); }
.textarea-lg { min-height: 160px; }
/* auto: as wide as the content, not the whole row */
.input.auto, .select.auto { width: auto; max-width: 100%; }
/* error text under a field: <span class="hint err" id="…">; the field gets aria-invalid and aria-describedby */
.hint.err { color: var(--err); }
/* field with an icon: <div class="input-icon"><svg class="icon">…</svg><input class="input"></div>;
   .end — the icon or a small button at the right edge; .sm — around an .input-sm */
.input-icon { position: relative; display: block; min-width: 0; }
.input-icon > .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.input-icon > .input { padding-left: 40px; }
.input-icon.end > .icon { left: auto; right: 12px; }
.input-icon.end > .input { padding-left: 12px; padding-right: 40px; }
.input-icon > .btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); min-height: 32px; width: 32px; padding: 0; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); }
.input-icon > .btn:hover { background: var(--surface-2); color: var(--text); }
.input-icon.sm > .icon { left: 10px; width: 16px; height: 16px; }
.input-icon.sm > .input { padding-left: 34px; }
.input-icon.sm.end > .icon { left: auto; right: 10px; }
.input-icon.sm.end > .input { padding-left: 10px; padding-right: 34px; }

/* checkbox and radio: <label class="check"><input type="checkbox"><span>Текст</span></label> */
.check { display: flex; align-items: flex-start; gap: var(--sp-2); cursor: pointer; font-size: var(--fs-md); min-height: 24px; }
.check input {
  appearance: none; -webkit-appearance: none; flex: none; width: 20px; height: 20px; margin: 1px 0 0;
  border: 2px solid var(--border-strong); border-radius: var(--r-xs); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; transition: background var(--dur), border-color var(--dur);
}
.check input[type="radio"] { border-radius: 50%; }
.check input::after { content: ""; width: 10px; height: 6px; border: solid var(--on-accent); border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); opacity: 0; }
.check input[type="radio"]::after { width: 8px; height: 8px; border: 0; border-radius: 50%; background: var(--on-accent); transform: none; }
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { opacity: 1; }
.check input:indeterminate { background: var(--accent); border-color: var(--accent); }
.check input:indeterminate::after { opacity: 1; width: 10px; height: 0; border-width: 0 0 2px; transform: none; }
.check input[aria-invalid="true"] { border-color: var(--err); }
.check:not([aria-busy="true"]):has(input:disabled) { cursor: default; opacity: .55; }
.check input:disabled { cursor: default; }
.check .hint { display: block; margin-top: 2px; }
.check + .check { margin-top: var(--sp-3); }

/* switch: <label class="switch"><input type="checkbox"><span class="track"></span><span>Text</span></label> */
.switch { position: relative; display: flex; align-items: flex-start; gap: var(--sp-3); cursor: pointer; min-height: 32px; }
.switch input { position: absolute; top: 0; left: 0; opacity: 0; width: 1px; height: 1px; margin: 0; }
.switch .track {
  flex: none; position: relative; width: 44px; height: 26px; border-radius: var(--r-full);
  background: var(--border-strong); transition: background var(--dur); margin-top: 1px;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--knob); box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform var(--dur);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch input:disabled + .track { opacity: .5; }
.switch:has(input:disabled) { cursor: default; }
.switch .text { display: flex; flex-direction: column; gap: 2px; font-size: var(--fs-md); }
.switch + .switch, .switch + .field, .field + .switch { margin-top: var(--sp-4); }
.switch.sm { min-height: 22px; gap: var(--sp-2); }
.switch.sm .track { width: 34px; height: 20px; margin-top: 0; }
.switch.sm .track::after { top: 2px; left: 2px; width: 16px; height: 16px; }
.switch.sm input:checked + .track::after { transform: translateX(14px); }
.switch.sm .text { font-size: var(--fs-sm); }

/* option cards (radio): <label class="option"><input type="radio" name=..><span class="option-body">..</span></label> */
.options { display: flex; flex-direction: column; gap: var(--sp-2); }
.option { position: relative; display: block; cursor: pointer; }
.option input { position: absolute; top: 0; left: 0; opacity: 0; margin: 0; }
.option-body {
  display: flex; gap: var(--sp-3); align-items: flex-start; padding: 14px; border-radius: var(--r-md);
  border: 1.5px solid var(--border); background: var(--surface); transition: border-color var(--dur), background var(--dur);
}
.option-body::before {
  content: ""; flex: none; width: 20px; height: 20px; border-radius: 50%; margin-top: 1px;
  border: 2px solid var(--border-strong); background: var(--surface); transition: all var(--dur);
}
.option input:checked + .option-body { border-color: var(--accent); background: var(--accent-soft); }
.option input:checked + .option-body::before { border-color: var(--accent); background: radial-gradient(circle, var(--accent) 0 5px, transparent 6px); }
.option input:focus-visible + .option-body { outline: 2px solid var(--focus); outline-offset: 2px; }
.option input:disabled + .option-body { opacity: .55; cursor: default; }
.option-title { font-weight: 650; display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.option-desc { color: var(--muted); font-size: var(--fs-sm); margin-top: 2px; }

/* segmented control / tabs: <div class="segmented" role="tablist"><button aria-selected="true"> */
.segmented {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--border);
}
.segmented button {
  min-height: 36px; padding: 0 14px; border: 0; border-radius: calc(var(--r-md) - 3px); background: transparent;
  color: var(--muted); font: 600 var(--fs-sm) var(--font); cursor: pointer; transition: all var(--dur);
}
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented button:disabled, .tabs button:disabled { opacity: .5; cursor: default; }
.segmented.block { display: flex; }
.segmented.block button { flex: 1; }
.segmented.sm { padding: 2px; border-radius: var(--r-sm); }
.segmented.sm button { min-height: 28px; padding: 0 10px; font-size: var(--fs-xs); border-radius: calc(var(--r-sm) - 2px); }
.segmented.lg button { min-height: var(--tap); padding: 0 var(--sp-5); font-size: var(--fs-md); }
.tabs { display: flex; gap: var(--sp-4); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button {
  padding: 10px 2px; border: 0; background: none; color: var(--muted); font: 600 var(--fs-sm) var(--font);
  border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tabs button:hover { color: var(--text); }
.tabs button:focus-visible { outline-offset: -2px; } /* .tabs scrolls and clips outside outlines */

/* ---------- status ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 650; white-space: nowrap; line-height: 1.5;
  background: var(--surface-2); color: var(--muted);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.no-dot::before { display: none; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.err { background: var(--err-soft); color: var(--err); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.lg { font-size: var(--fs-sm); padding: 4px 12px; }
.pill.sm { font-size: var(--fs-2xs); padding: 1px 7px; gap: 4px; }
.pill.sm::before { width: 6px; height: 6px; }
.badge {
  display: inline-flex; align-items: center; padding: 1px 8px; border-radius: var(--r-full);
  font-size: var(--fs-2xs); font-weight: 700; letter-spacing: .02em; background: var(--accent); color: var(--on-accent);
}
.badge.soft { background: var(--accent-soft); color: var(--accent); }
.badge.lg { font-size: var(--fs-xs); padding: 2px 10px; }
/* tag: a small neutral label, <span class="tag">beta</span>; tones .ok .warn .err .info .accent */
.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: var(--r-full);
  font-size: var(--fs-2xs); font-weight: 650; line-height: 1.6; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.tag.mono { font-family: var(--mono); font-weight: 500; }
.tag.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.err { background: var(--err-soft); color: var(--err); border-color: transparent; }
.tag.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.tag.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
/* chip: a removable token, <span class="chip"><span>example.com</span><button aria-label="Убрать">×icon</button></span> */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 2px; max-width: 100%; min-height: 28px; padding: 2px 3px 2px 10px;
  border-radius: var(--r-full); background: var(--surface-2); border: 1px solid var(--border);
  font-size: var(--fs-xs); font-weight: 600; color: var(--text);
}
.chip:not(:has(> button)) { padding-right: 10px; }
.chip > a, .chip > span { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.chip.mono > a, .chip.mono > span { font-family: var(--mono); font-weight: 500; }
.chip > button {
  width: 22px; height: 22px; border: 0; border-radius: 50%; background: none; color: var(--muted);
  display: grid; place-items: center; cursor: pointer; flex: none; padding: 0;
}
.chip > button:hover { background: var(--err-soft); color: var(--err); }
.chip > button .icon { width: 14px; height: 14px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.err { background: var(--err); }
.dot.warn { background: var(--warn); }
.dot.info { background: var(--info); }
.dot.lg { width: 10px; height: 10px; }
/* chart legend: <div class="legend"><span><i class="dot ok"></i>Работает</span>…</div> */
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-4); font-size: var(--fs-xs); color: var(--muted); }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }

/* banner / alert */
.banner {
  display: flex; gap: var(--sp-3); align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md);
  background: var(--info-soft); color: var(--text); font-size: var(--fs-sm);
}
.banner .icon { color: var(--info); margin-top: 1px; }
.banner.ok { background: var(--ok-soft); } .banner.ok .icon { color: var(--ok); }
.banner.warn { background: var(--warn-soft); } .banner.warn .icon { color: var(--warn); }
.banner.err { background: var(--err-soft); } .banner.err .icon { color: var(--err); }
/* lg: a status callout with a title and actions,
   <div class="banner lg warn"><svg class="icon">…</svg><div class="grow"><b class="title">…</b><p>…</p></div><div class="actions">…</div></div> */
.banner.lg { padding: var(--sp-4); gap: var(--sp-3); font-size: var(--fs-md); border-radius: var(--r-lg); align-items: center; flex-wrap: wrap; }
.banner.lg > .icon { width: 28px; height: 28px; margin-top: 0; }
.banner .title { display: block; font-weight: 700; }
.banner .actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-left: auto; }
.banner.lg p { font-size: var(--fs-sm); color: var(--muted); margin-top: 2px; }

/* progress */
.progress { height: 8px; border-radius: var(--r-full); background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width .4s; }
.progress.ok > i { background: var(--ok); }
.progress.warn > i { background: var(--warn); }
.progress.err > i { background: var(--err); }
.progress.sm { height: 4px; }
.progress.lg { height: 12px; }
/* meter: a bar with its value, <div class="meter"><div class="progress"><i style="width:40%"></i></div><span>4 из 10</span></div> */
.meter { display: flex; align-items: center; gap: var(--sp-2); min-width: 150px; }
.meter .progress { flex: 1; height: 6px; min-width: 60px; }
.meter > span { font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; }

/* history strip: <span class="hist"><i class="ok"></i><i class="err"></i><i></i></span> */
.hist { display: inline-flex; gap: 2px; align-items: center; vertical-align: middle; }
.hist i { display: block; width: 4px; height: 14px; border-radius: 2px; background: var(--border); }
.hist i.ok { background: var(--ok); }
.hist i.err { background: var(--err); }

/* spinner */
.spinner {
  width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent); animation: ui-spin .8s linear infinite; display: inline-block;
}
.loading-screen { display: grid; place-items: center; min-height: 50vh; }
.spinner.sm { width: 16px; height: 16px; border-width: 2px; }
.spinner.lg { width: 36px; height: 36px; border-width: 3px; }
.loading-screen.sm { min-height: 120px; }
/* skeleton: placeholders while loading, <span class="skeleton" style="width:60%"></span>; .text .title .block .circle */
.skeleton {
  display: block; height: 1em; border-radius: var(--r-xs);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%) 0 0 / 200% 100%;
  animation: ui-shimmer 1.4s ease-in-out infinite;
}
.skeleton.text { height: .9em; margin: .3em 0; }
.skeleton.title { height: 1.4em; width: 50%; }
.skeleton.block { height: 96px; border-radius: var(--r-md); }
.skeleton.circle { width: 36px; height: 36px; border-radius: 50%; flex: none; }
@keyframes ui-shimmer { to { background-position: -200% 0; } }

/* ---------- code / copy box ---------- */
.copybox {
  display: flex; align-items: stretch; border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface-2); overflow: hidden;
}
.copybox code {
  flex: 1; min-width: 0; padding: 10px 12px; font: var(--fs-sm)/1.5 var(--mono); color: var(--text);
  overflow-wrap: anywhere; white-space: pre-wrap; user-select: all;
}
.copybox .btn { border: 0; border-left: 1px solid var(--border-strong); border-radius: 0; background: var(--surface); min-height: auto; }
.copybox .btn:hover { background: var(--accent-soft); color: var(--accent); }
.copybox .btn:focus-visible { outline-offset: -2px; } /* .copybox clips outside outlines */
/* code or log box: <pre class="codeblock">; .log is quieter and wraps lines */
.codeblock {
  margin: 0; font: var(--fs-xs)/1.6 var(--mono); color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-md); padding: 12px 14px;
  max-height: 60vh; overflow: auto; white-space: pre; tab-size: 2;
}
.codeblock.log { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); max-height: 320px; line-height: 1.7; }
.codeblock:focus-visible { outline-offset: -2px; }

/* steps */
.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: var(--sp-3); }
.steps li { counter-increment: step; display: flex; gap: var(--sp-3); font-size: var(--fs-sm); }
.steps li::before {
  content: counter(step); flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: var(--fs-xs);
}
.steps li > div { flex: 1; min-width: 0; }
.steps li > div > div, .steps li > div > .copybox { margin-top: 8px; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 calc(-1 * var(--sp-4)); padding: 0 var(--sp-4); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: var(--fs-xs);
  padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table .group td { color: var(--muted); font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; padding-top: 14px; }
.table.compact th { padding: 4px 6px; }
.table.compact td { padding: 5px 6px; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.actions .row { justify-content: flex-end; flex-wrap: nowrap; gap: 4px; }
.table .title { font-weight: 650; }
.table a.title { color: var(--text); }
.table a.title:hover { color: var(--accent); text-decoration: none; }
.table .sub { color: var(--muted); font-size: var(--fs-xs); margin-top: 1px; }
.table .cell-main { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
/* rows that open details: tr.clickable (+ .open), the details row tr.expand right after it */
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover > td, .table tr.open > td { background: var(--surface-2); }
.table tr.expand > td { padding: 0; background: var(--surface-2); }
.table .chev { color: var(--muted); transition: transform var(--dur); display: inline-flex; }
.table tr.open .chev { transform: rotate(90deg); }
/* edge to edge inside .card.flush: the outer cells keep the card's inset */
.card.flush > .table th:first-child, .card.flush > .table td:first-child,
.card.flush > .table-wrap > .table th:first-child, .card.flush > .table-wrap > .table td:first-child { padding-left: var(--sp-4); }
.card.flush > .table th:last-child, .card.flush > .table td:last-child,
.card.flush > .table-wrap > .table th:last-child, .card.flush > .table-wrap > .table td:last-child { padding-right: var(--sp-4); }
.card.flush > .table-wrap { margin: 0; padding: 0; }
/* sticky head: stays under a sticky app header of height --sticky-top */
.table.sticky { border-collapse: separate; border-spacing: 0; }
.table.sticky th { position: sticky; top: var(--sticky-top); z-index: 2; background: var(--surface); }
.table-wrap .table.sticky th { position: static; } /* inside an overflow wrapper sticky has nothing to stick to */
/* stackable: below 720 px every row becomes a card of label: value lines, labels from td[data-label] */
@media (max-width: 720px) {
  .table.stackable thead { display: none; }
  .table.stackable, .table.stackable tbody, .table.stackable tr { display: block; width: 100%; }
  .table.stackable tr { padding: 10px var(--sp-4); border-bottom: 1px solid var(--border); }
  .table.stackable tbody tr:last-child { border-bottom: 0; }
  .table.stackable td { display: flow-root; width: 100%; border: 0; padding: 3px 0; text-align: right; min-height: 26px; }
  .table.stackable td[data-label]::before {
    content: attr(data-label); float: left; margin-right: var(--sp-3); color: var(--muted);
    font-size: var(--fs-xs); font-weight: 600; text-align: left; line-height: 22px;
  }
  .table.stackable td .switch, .table.stackable td .meter { display: inline-flex; }
  .table.stackable td .meter { min-width: 0; width: 60%; }
  .table.stackable td.primary { text-align: left; padding-bottom: 6px; }
  .table.stackable td.actions { text-align: left; padding-top: 8px; }
  .table.stackable td.actions .row { justify-content: flex-start; flex-wrap: wrap; }
  .table.stackable td.hide-m, .table.stackable td:empty { display: none; }
  .table.stackable tr.group { padding-top: 14px; padding-bottom: 4px; }
  .table.stackable tr.group > td { text-align: left; padding: 0; }
  .table.stackable tr.open, .table.stackable tr.clickable:hover { background: var(--surface-2); }
  .table.stackable tr.open > td, .table.stackable tr.clickable:hover > td { background: none; }
  .table.stackable tr.expand { padding: 0; }
  .table.stackable tr.expand > td { padding: 0; text-align: left; }
  .card.flush > .table.stackable td, .card.flush > .table-wrap > .table.stackable td { padding-left: 0; padding-right: 0; }
}

/* ---------- stats ---------- */
/* <div class="stats"><div class="stat ok"><div class="k">Онлайн</div><div class="v">12<span class="u">из 14</span></div><div class="s">за час</div></div></div>
   button.stat[aria-pressed] filters the list below */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--sp-3); }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
  padding: 14px 16px; min-width: 0;
}
button.stat { display: block; font: inherit; color: inherit; text-align: left; cursor: pointer; width: 100%; }
button.stat:hover { border-color: var(--border-strong); }
button.stat[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.stat .k { font-size: var(--fs-xs); font-weight: 650; color: var(--muted); letter-spacing: .03em; }
.stat .v { font-size: var(--fs-2xl); font-weight: 750; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.25; }
.stat .v.mono { font-size: var(--fs-md); font-family: var(--mono); padding: 5px 0 2px; }
.stat .v .u { font-size: var(--fs-md); font-weight: 600; color: var(--muted); margin-left: 4px; }
.stat .s { font-size: var(--fs-xs); color: var(--muted); margin-top: 2px; }
.stat.ok .v { color: var(--ok); }
.stat.warn .v { color: var(--warn); }
.stat.err .v { color: var(--err); }
.stat.info .v { color: var(--info); }
.stats.sm .stat { padding: 10px 12px; }
.stats.sm .stat .v:not(.mono) { font-size: var(--fs-xl); }
@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); }
  .stat { padding: 10px 12px; }
  .stat .v:not(.mono) { font-size: var(--fs-xl); }
}

/* ---------- timeline: time · dot · text ---------- */
/* <ol class="timeline"><li><time>12:40</time><i class="dot ok"></i><div>Текст <span class="sub">детали</span></div></li></ol> */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline > li {
  display: grid; grid-template-columns: 88px 10px minmax(0, 1fr); gap: var(--sp-2); align-items: baseline;
  padding: 6px 0; border-top: 1px solid var(--border); font-size: var(--fs-sm);
}
.timeline > li:first-child { border-top: 0; }
.timeline time { font: var(--fs-xs) var(--mono); color: var(--muted); white-space: nowrap; }
.timeline .dot { align-self: center; }
.timeline .sub { display: block; color: var(--muted); font-size: var(--fs-xs); }
@media (max-width: 480px) { .timeline > li { grid-template-columns: 64px 10px minmax(0, 1fr); } }

/* ---------- settings list: label and hint on the left, a control on the right ---------- */
/* <div class="settings"><div class="setting"><div class="grow"><div class="title">…</div><div class="hint">…</div></div><button class="btn btn-sm">…</button></div></div> */
.settings { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.setting { display: flex; align-items: center; gap: var(--sp-3); padding: 12px var(--sp-4); min-height: 56px; }
.setting + .setting { border-top: 1px solid var(--border); }
.setting .title { font-weight: 600; }
.setting .hint { margin-top: 2px; }
.setting > :last-child:not(.grow) { flex: none; }
.card.flush > .settings { border: 0; border-radius: 0; background: none; }
/* narrow screens: a wide control (a button) moves under the text, a switch stays on the right */
@media (max-width: 480px) { .setting { flex-wrap: wrap; } .setting > .grow { min-width: 60%; } }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: var(--sp-8) var(--sp-4); display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); }
.empty .icon-tile { width: 64px; height: 64px; border-radius: var(--r-xl); }
.empty .icon-tile .icon { width: 30px; height: 30px; }
.empty p { color: var(--muted); max-width: 360px; }

/* ---------- details (disclosure) ---------- */
details.disclosure { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
details.disclosure > summary {
  list-style: none; cursor: pointer; padding: 12px 14px; display: flex; align-items: center; gap: var(--sp-2);
  font-weight: 600; font-size: var(--fs-sm); min-height: var(--tap);
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary .chev { margin-left: auto; color: var(--muted); transition: transform var(--dur); }
details.disclosure[open] > summary .chev { transform: rotate(90deg); }
details.disclosure > .body { padding: 0 14px 14px; }

/* ---------- modal: <dialog class="modal"> ---------- */
/* Only the body scrolls. A modal <dialog> is scrollable itself (UA style), and
   focus() or scrollIntoView() inside would scroll it, sliding the content off
   the footer — hence overflow: clip on the dialog. */
dialog.modal {
  border: 0; padding: 0; border-radius: var(--r-lg); background: var(--surface); color: var(--text);
  width: min(440px, calc(100vw - 32px)); box-shadow: var(--shadow-md); overflow: clip;
}
dialog.modal::backdrop { background: var(--overlay); }
.modal-body { padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-3); }
dialog.modal .modal-body { max-height: calc(100vh - 170px); max-height: calc(100dvh - 170px); overflow: auto; overscroll-behavior: contain; }
@media (min-width: 481px) {
  dialog.modal.mid { width: min(620px, calc(100vw - 48px)); }
  dialog.modal.wide { width: min(980px, calc(100vw - 48px)); }
  dialog.modal.sm { width: min(360px, calc(100vw - 48px)); }
}
.modal-foot { display: flex; gap: var(--sp-2); justify-content: flex-end; padding: 0 var(--sp-5) var(--sp-5); flex-wrap: wrap; }
@media (max-width: 480px) {
  dialog.modal { margin: auto auto 0; width: 100vw; max-width: 100vw; border-radius: var(--r-lg) var(--r-lg) 0 0; }
  .modal-foot .btn { flex: 1; }
}

/* ---------- toast ---------- */
.toast-host {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; flex-direction: column; gap: var(--sp-2); z-index: 100; width: max-content; max-width: calc(100vw - 32px);
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--sp-2); padding: 11px 16px; border-radius: var(--r-md);
  background: var(--text); color: var(--bg); font-size: var(--fs-sm); font-weight: 550; box-shadow: var(--shadow-md);
  animation: ui-toast-in .2s ease;
}
.toast.err { background: var(--err); color: var(--on-err); }
.toast .icon { width: 18px; height: 18px; }
@keyframes ui-toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- sticky save bar ---------- */
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 12px var(--sp-4) calc(12px + env(safe-area-inset-bottom));
  background: var(--surface); /* fallback without color-mix() */
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border); box-shadow: var(--shadow-md);
}
.savebar .inner { max-width: var(--maxw); margin: 0 auto; display: flex; align-items: center; gap: var(--sp-2); }

/* ---------- menu (popover list) ---------- */
.menu { display: flex; flex-direction: column; }
.menu button, .menu a {
  display: flex; align-items: center; gap: var(--sp-3); min-height: 48px; padding: 0 var(--sp-2);
  background: none; border: 0; color: var(--text); font: 500 var(--fs-md) var(--font); cursor: pointer; text-align: left;
  border-radius: var(--r-sm);
}
.menu button:hover, .menu a:hover { background: var(--surface-2); text-decoration: none; }
.menu .danger { color: var(--err); }

/* avatar */
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; border: 0; cursor: pointer; font-size: var(--fs-sm);
  position: relative; overflow: hidden; padding: 0;
}
.avatar > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
span.avatar { cursor: default; }
.avatar.sm { width: 32px; height: 32px; font-size: var(--fs-xs); }
.avatar.md { width: 44px; height: 44px; font-size: var(--fs-md); }
.avatar.lg { width: 56px; height: 56px; font-size: var(--fs-lg); }
.avatar.xl { width: 80px; height: 80px; font-size: var(--fs-2xl); }

/* QR */
.qr { width: 180px; height: 180px; border-radius: var(--r-md); background: #fff; padding: 8px; display: block; }

/* ---------- file drop: UI.filedrop(el) ---------- */
/* <div class="filedrop"><input type="file" accept=".pem" multiple></div>; UI.filedrop builds the zone,
   the file list and the error line around the input */
.filedrop { display: flex; flex-direction: column; gap: var(--sp-2); }
.filedrop-zone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 132px; padding: var(--sp-5) var(--sp-4); text-align: center; cursor: pointer;
  border: 1.5px dashed var(--border-strong); border-radius: var(--r-lg); background: var(--surface);
  color: var(--muted); transition: border-color var(--dur), background var(--dur), color var(--dur);
}
.filedrop-zone .icon { color: var(--accent); }
.filedrop-zone .title { font-weight: 600; color: var(--text); font-size: var(--fs-sm); }
.filedrop:not(:has(input:disabled)) .filedrop-zone:hover { border-color: var(--accent); background: var(--accent-soft); }
.filedrop-zone:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.filedrop.over .filedrop-zone { border-color: var(--accent); border-style: solid; background: var(--accent-soft); color: var(--accent); }
.filedrop:not([aria-busy="true"]):has(input:disabled) .filedrop-zone { cursor: default; opacity: .55; }
.filedrop:has(input[aria-invalid="true"]) .filedrop-zone { border-color: var(--err); }
/* compact zone: .sm, and any zone once it has files */
.filedrop.sm .filedrop-zone, .filedrop.has-files:not(.over) .filedrop-zone {
  min-height: 72px; padding-block: var(--sp-3); flex-direction: row; flex-wrap: wrap; column-gap: var(--sp-2); row-gap: 2px;
}
.filedrop.sm .filedrop-zone .icon, .filedrop.has-files:not(.over) .filedrop-zone .icon { width: 22px; height: 22px; }
.filedrop.sm .filedrop-zone .hint { flex-basis: 100%; }
.filedrop.has-files:not(.over) .filedrop-zone .hint { display: none; }
.filedrop-files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.filedrop-files .file { display: flex; align-items: center; gap: var(--sp-2); padding: 6px 6px 6px var(--sp-3); min-height: 44px; flex-wrap: wrap; font-size: var(--fs-sm); }
.filedrop-files .file + .file { border-top: 1px solid var(--border); }
.filedrop-files .file > .icon { color: var(--muted); width: 18px; height: 18px; }
.filedrop-files .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.filedrop-files .size { color: var(--muted); font-size: var(--fs-xs); white-space: nowrap; font-variant-numeric: tabular-nums; }
.filedrop-files .progress { flex-basis: 100%; order: 5; margin: 0 6px 4px 26px; }

/* ---------- loading state: aria-busy="true" (UI.busy(el, fn) sets it) ---------- */
/* The spinning ring: a 2px border of currentColor with the right side open. Most components draw
   it as ::after; the switch, check, option, pill and icon tile turn a part of themselves into it. */
.btn[aria-busy="true"]::after, .input-icon[aria-busy="true"]::after, .list-item[aria-busy="true"]::after,
.setting[aria-busy="true"]::after, .menu [aria-busy="true"]::after, .segmented [aria-busy="true"]::after,
.tabs [aria-busy="true"]::after, .card[aria-busy="true"]::after, .chip[aria-busy="true"] > button::after,
.copybox[aria-busy="true"] .btn::after, .filedrop[aria-busy="true"] .filedrop-zone::after,
.icon-tile[aria-busy="true"]::after, .banner[aria-busy="true"]::after {
  content: ""; width: 16px; height: 16px; flex: none; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: ui-spin .7s linear infinite;
}
/* button: the label keeps the width under a centred ring */
.btn[aria-busy="true"] { color: transparent; pointer-events: none; }
.btn[aria-busy="true"]:disabled { opacity: 1; }
.btn[aria-busy="true"] > * { visibility: hidden; }
.btn[aria-busy="true"]::after { position: absolute; left: 50%; top: 50%; margin: -8px 0 0 -8px; color: var(--text); }
.btn-primary[aria-busy="true"]::after { color: var(--on-accent); }
.btn-ghost[aria-busy="true"]::after { color: var(--accent); }
.btn-ghost.plain[aria-busy="true"]::after { color: var(--muted); }
.btn-danger[aria-busy="true"]::after, .btn-danger-ghost[aria-busy="true"]::after { color: var(--err); }
.btn-sm[aria-busy="true"]::after { width: 14px; height: 14px; margin: -7px 0 0 -7px; }
/* field: wrap the input or the select in .input-icon, the ring sits at its right edge */
.input-icon[aria-busy="true"]::after { position: absolute; right: 12px; top: 50%; margin-top: -8px; color: var(--muted); }
.input-icon[aria-busy="true"] > .input, .input-icon[aria-busy="true"] > .select { padding-right: 40px; background-image: none; }
.input-icon[aria-busy="true"] > .btn { display: none; }
.input[aria-busy="true"], .select[aria-busy="true"], .textarea[aria-busy="true"] { cursor: progress; }
/* switch: the knob is the ring (rotate, so the knob's own transform stays) */
.switch[aria-busy="true"] { cursor: progress; }
.switch[aria-busy="true"] input:disabled + .track { opacity: 1; }
.switch[aria-busy="true"] .track::after {
  background: transparent; box-shadow: none; border: 2px solid var(--knob); border-right-color: transparent;
  animation: ui-rotate .7s linear infinite;
}
.switch[aria-busy="true"] input:not(:checked) + .track::after { border-color: var(--muted); border-right-color: transparent; }
/* the knob's offset moves to `translate`, which applies after `rotate`: the ring turns in place */
.switch[aria-busy="true"] input:checked + .track::after { transform: none; translate: 18px 0; }
.switch.sm[aria-busy="true"] input:checked + .track::after { translate: 14px 0; }
@keyframes ui-rotate { to { rotate: 360deg; } }
/* checkbox, radio: the box is the ring */
.check[aria-busy="true"] { cursor: progress; }
.check[aria-busy="true"] input {
  border-color: var(--accent); border-right-color: transparent; border-radius: 50%; background: transparent;
  animation: ui-spin .7s linear infinite;
}
.check[aria-busy="true"] input::after { opacity: 0; }
/* option card: the radio is the ring */
.option[aria-busy="true"] { cursor: progress; }
.option[aria-busy="true"] input:disabled + .option-body { opacity: 1; }
.option[aria-busy="true"] .option-body::before { border-color: var(--accent); border-right-color: transparent; background: none; animation: ui-spin .7s linear infinite; }
/* segmented, tabs: the button being switched to gets a ring after its label */
.segmented [aria-busy="true"], .tabs [aria-busy="true"] { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.segmented [aria-busy="true"]::after, .tabs [aria-busy="true"]::after { width: 12px; height: 12px; }
.segmented[aria-busy="true"], .tabs[aria-busy="true"] { cursor: progress; }
.segmented[aria-busy="true"] button, .tabs[aria-busy="true"] button { pointer-events: none; }
/* pill: the dot is the ring, a status being checked */
.pill[aria-busy="true"]::before { display: block; width: 9px; height: 9px; background: none; border: 1.5px solid currentColor; border-right-color: transparent; animation: ui-spin .7s linear infinite; }
.pill.sm[aria-busy="true"]::before { width: 7px; height: 7px; }
/* icon tile, banner: a ring in place of the icon */
.icon-tile[aria-busy="true"], .banner[aria-busy="true"] { position: relative; }
.icon-tile[aria-busy="true"] > .icon, .banner[aria-busy="true"] > .icon { visibility: hidden; }
.icon-tile[aria-busy="true"]::after { position: absolute; inset: 0; margin: auto; width: 45%; height: 45%; }
.banner[aria-busy="true"]::after { position: absolute; left: 14px; top: 13px; width: 18px; height: 18px; color: var(--info); }
.banner.lg[aria-busy="true"]::after { left: var(--sp-4); top: 50%; width: 28px; height: 28px; margin-top: -14px; }
.banner.ok[aria-busy="true"]::after { color: var(--ok); }
.banner.warn[aria-busy="true"]::after { color: var(--warn); }
.banner.err[aria-busy="true"]::after { color: var(--err); }
/* values that are not there yet shimmer: avatar, stat, kv, copybox */
.avatar[aria-busy="true"], :is(.stat, .stats)[aria-busy="true"] .v, .kv[aria-busy="true"] dd, .copybox[aria-busy="true"] code {
  color: transparent; background-image: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: ui-shimmer 1.4s ease-in-out infinite;
}
.avatar[aria-busy="true"] > img { display: none; }
:is(.stat, .stats)[aria-busy="true"] .v { width: 60%; border-radius: var(--r-xs); }
:is(.stat, .stats)[aria-busy="true"] .v * { visibility: hidden; }
.kv[aria-busy="true"] dd { justify-self: end; width: 40%; min-height: 1.2em; border-radius: var(--r-xs); }
.copybox[aria-busy="true"] code { user-select: none; }
.copybox[aria-busy="true"] .btn { color: transparent; pointer-events: none; }
.copybox[aria-busy="true"] .btn > * { visibility: hidden; }
.copybox[aria-busy="true"] .btn::after { position: absolute; color: var(--muted); }
button.stat[aria-busy="true"] { cursor: progress; }
/* list item, setting, menu entry: a ring at the right edge */
.list-item[aria-busy="true"], .setting[aria-busy="true"] { cursor: progress; }
.list-item[aria-busy="true"] .chev, .setting[aria-busy="true"] > :last-child:not(.grow) { display: none; }
.list-item[aria-busy="true"]::after, .setting[aria-busy="true"]::after, .menu [aria-busy="true"]::after { margin-left: auto; color: var(--muted); }
.menu [aria-busy="true"] { pointer-events: none; }
/* chip: the remove button is the ring */
.chip[aria-busy="true"] > button { pointer-events: none; }
.chip[aria-busy="true"] > button > * { display: none; }
.chip[aria-busy="true"] > button::after { width: 12px; height: 12px; color: var(--muted); }
/* card: the content dims under a centred ring */
.card[aria-busy="true"] { position: relative; }
.card[aria-busy="true"] > * { opacity: .45; pointer-events: none; transition: opacity var(--dur); }
.card[aria-busy="true"]::after { position: absolute; left: 50%; top: 50%; width: 24px; height: 24px; margin: -12px 0 0 -12px; color: var(--accent); }
/* table, list, settings, timeline: the content dims under a bar running along the top */
.table[aria-busy="true"] tbody, :is(.list, .settings, .timeline)[aria-busy="true"] > * { opacity: .45; pointer-events: none; transition: opacity var(--dur); }
:is(.list, .settings, .timeline)[aria-busy="true"], .table[aria-busy="true"] > tbody > tr:first-child {
  background: linear-gradient(90deg, transparent, var(--accent), transparent) no-repeat 0 0 / 40% 2px;
  animation: ui-indeterminate 1.1s ease-in-out infinite;
}
@keyframes ui-indeterminate { from { background-position-x: -60%; } to { background-position-x: 160%; } }
/* progress: the end is unknown */
.progress[aria-busy="true"] > i, .progress.indeterminate > i { width: 40% !important; animation: ui-progress 1.1s ease-in-out infinite; }
@keyframes ui-progress { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
/* file drop: a ring in the zone's corner, files can't be removed */
.filedrop[aria-busy="true"] .filedrop-zone { cursor: progress; pointer-events: none; padding-inline: 44px; }
.filedrop[aria-busy="true"] .filedrop-zone::after { position: absolute; right: 12px; top: 12px; color: var(--accent); }
.filedrop[aria-busy="true"] [data-remove] { visibility: hidden; }
/* dialog saving (UI.modal submit): the form is read-only */
dialog.modal[aria-busy="true"] .modal-body { pointer-events: none; }
dialog.modal[aria-busy="true"] .modal-body > :not(.modal-error) { opacity: .7; }
/* the whole page: <body aria-busy="true">, a bar at the top of the window */
body[aria-busy="true"]::before {
  content: ""; position: fixed; left: 0; right: 0; top: 0; height: 3px; z-index: 200;
  background: linear-gradient(90deg, transparent, var(--accent), transparent) no-repeat 0 0 / 40% 100%;
  animation: ui-indeterminate 1.1s ease-in-out infinite;
}

@media (min-width: 720px) {
  .container { padding-top: var(--sp-6); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  /* a still loader reads as a frozen page: loaders keep moving, slower */
  .spinner, .spin, .check[aria-busy="true"] input, .option[aria-busy="true"] .option-body::before, .pill[aria-busy="true"]::before,
  .btn[aria-busy="true"]::after, .input-icon[aria-busy="true"]::after, .list-item[aria-busy="true"]::after,
  .setting[aria-busy="true"]::after, .menu [aria-busy="true"]::after, .segmented [aria-busy="true"]::after,
  .tabs [aria-busy="true"]::after, .card[aria-busy="true"]::after, .chip[aria-busy="true"] > button::after,
  .copybox[aria-busy="true"] .btn::after, .filedrop[aria-busy="true"] .filedrop-zone::after,
  .icon-tile[aria-busy="true"]::after, .banner[aria-busy="true"]::after { animation: ui-spin 1.6s linear infinite !important; }
  .switch[aria-busy="true"] .track::after { animation: ui-rotate 1.6s linear infinite !important; }
  .progress[aria-busy="true"] > i, .progress.indeterminate > i { animation: ui-progress 2.2s ease-in-out infinite !important; }
  :is(.list, .settings, .timeline)[aria-busy="true"], .table[aria-busy="true"] > tbody > tr:first-child,
  body[aria-busy="true"]::before { animation: ui-indeterminate 2.2s ease-in-out infinite !important; }
}

/* toasts above the save bar while it is shown */
body:has(.savebar:not([hidden])) .toast-host { bottom: calc(84px + env(safe-area-inset-bottom)); }
