/* ═══════════════════════════════════════════════════════════════════════════
   NEGATRON — база: сброс, типографика, формы, кнопки, иконки, модалки,
   статусы, утилиты, движение. Значения — только из tokens.css.
   Экранные стили — в styles.css.
   ═══════════════════════════════════════════════════════════════════════════ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-md) / var(--lh-body) var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Плавная смена темы: без скачка яркости (apple-design §14). */
  transition: background-color var(--dur-slow) var(--ease-in-out), color var(--dur-slow) var(--ease-in-out);
}

/* ── Типографика ─────────────────────────────────────────────────────────── */
h1, h2, h3, h4, p {
  margin: 0;
}

h1 {
  font-size: var(--fs-xl);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: var(--track-tight);
}

h2 {
  font-size: var(--fs-lg);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: var(--track-tight);
}

h3 {
  font-size: var(--fs-lg);
  font-weight: 700;
  line-height: var(--lh-tight);
}

h4 {
  font-size: var(--fs-md);
  font-weight: 700;
  line-height: var(--lh-tight);
}

small {
  font-size: var(--fs-sm);
}

a {
  color: var(--accent-strong);
}

code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: var(--r-sm);
}

pre {
  margin: 0;
  overflow: auto;
  padding: var(--s-3);
  background: var(--code-bg);
  color: var(--code-fg);
  font: var(--fs-sm) / 1.5 var(--font-mono);
  white-space: pre-wrap;
  word-break: break-word;
}

.muted {
  color: var(--muted);
}

.mono {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
}

.ok-text { color: var(--accent-strong); }
.bad-text { color: var(--danger); }

.caps {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Иконки (монохромный SVG-спрайт, см. #icon-sprite в index.html) ──────── */
.ic {
  width: 1.15em;
  height: 1.15em;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.2em;
  pointer-events: none;
}
.ic.ok { color: var(--accent-strong); }
.ic.warn { color: var(--warn); }
.ic.bad { color: var(--danger); }
.ic.info { color: var(--info); }
.ic.muted { color: var(--muted); }
.ic.spin { animation: icSpin 0.9s linear infinite; }

@keyframes icSpin {
  to { transform: rotate(360deg); }
}

/* ── Формы ───────────────────────────────────────────────────────────────── */
label {
  display: grid;
  gap: var(--s-1);
  min-width: 0;
  align-content: start;
}

label > span {
  color: var(--muted);
  font-size: var(--fs-sm);
}

label > span small {
  font-size: var(--fs-xs);
}

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

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--input-bg);
  color: var(--text);
  padding: 7px 10px;
  line-height: 1.4;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast), background var(--dur-fast);
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="checkbox"],
input[type="radio"] {
  width: 15px;
  height: 15px;
  padding: 0;
  margin: 0;
  accent-color: var(--accent);
  border-radius: 3px;
  flex: none;
}

input[type="range"] {
  padding: 0;
  border: none;
  background: transparent;
  accent-color: var(--accent-strong);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

select {
  padding-right: 28px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--muted);
  cursor: pointer;
}

.checkbox input {
  width: auto;
}

/* Чекбокс/радио в строку с подписью и подсказкой */
.inline-check,
.choice-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  justify-content: flex-start;
  gap: var(--s-2);
  font-size: var(--fs-md);
  color: var(--text);
  cursor: pointer;
}
.inline-check { color: var(--muted); margin-top: calc(-1 * var(--s-1)); }
.inline-check input,
.choice-row input { width: auto; margin: 0; flex: none; }
.inline-check span { color: var(--muted); }
.choice-row .hint { color: var(--muted); font-size: var(--fs-sm); }
.choice-row select { width: auto; }
.choice-row + .choice-row { margin-top: var(--s-1); }

.field-status {
  margin: var(--s-1) 0 0;
  color: var(--muted);
  font-size: var(--fs-sm);
}
.field-status:empty { display: none; }
.field-status.bad { color: var(--danger); }

/* ── Кнопки ──────────────────────────────────────────────────────────────── */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 7px 12px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
  transition:
    background var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

button:where(:hover:not(:disabled)) {
  background: var(--accent-strong);
}

/* Реакция на нажатие — мгновенно, на pointer-down (apple-design §1). */
button:where(:active:not(:disabled)) {
  transform: scale(0.97);
}

button:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button.primary {
  background: var(--accent);
  color: var(--on-accent);
}
button.primary:where(:hover:not(:disabled)) { background: var(--accent-strong); }

button.ghost,
button.secondary {
  color: var(--text);
  background: var(--panel);
  border-color: var(--line);
}
button.ghost:where(:hover:not(:disabled)),
button.secondary:where(:hover:not(:disabled)) {
  background: var(--surface-3);
  border-color: var(--line-strong);
}

button.warn {
  background: var(--warn);
  color: #fff;
}
button.warn:where(:hover:not(:disabled)) {
  background: color-mix(in srgb, var(--warn), #000 18%);
}

button.danger {
  background: var(--danger);
  color: #fff;
}
button.danger:where(:hover:not(:disabled)) {
  background: color-mix(in srgb, var(--danger), #000 16%);
}

/* Мягкие (тонированные) кнопки */
.btn-soft-green,
.btn-soft-yellow,
.btn-soft-red,
.btn-soft-blue {
  border: 1px solid transparent;
  font-weight: 600;
}
.btn-soft-green { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-border); }
.btn-soft-green:hover:not(:disabled) { background: var(--ok-border); }
.btn-soft-yellow { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-border); }
.btn-soft-yellow:hover:not(:disabled) { background: var(--warn-border); }
.btn-soft-red { background: var(--danger-bg); color: var(--danger-fg); border-color: var(--danger-border); }
.btn-soft-red:hover:not(:disabled) { background: var(--danger-border); }
.btn-soft-blue { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-border); }
.btn-soft-blue:hover:not(:disabled) { background: color-mix(in srgb, var(--info-bg), #000 8%); }

/* Ссылка, оформленная как кнопка */
a.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
  transition: background var(--dur-fast);
}
a.primary:hover { background: var(--accent-strong); }
a.primary.disabled { opacity: 0.5; pointer-events: none; }

/* Размеры */
button.sm,
.btn-sm {
  padding: 4px 9px;
  font-size: var(--fs-sm);
}

/* Квадратная кнопка-иконка */
.icon-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: var(--fs-md);
  line-height: 1;
}
.icon-btn .ic { width: 16px; height: 16px; }

/* Бейдж стоимости API на кнопках */
.api-cost-badge {
  display: inline-block;
  margin-left: 2px;
  padding: 1px 6px;
  font-size: var(--fs-xs);
  font-weight: 600;
  border-radius: var(--r-pill);
  background: rgba(0, 0, 0, 0.12);
  color: inherit;
  white-space: nowrap;
  vertical-align: middle;
  opacity: 0.9;
}
button.danger .api-cost-badge,
button.warn .api-cost-badge {
  background: rgba(255, 255, 255, 0.25);
}
button.ghost .api-cost-badge {
  background: var(--surface-3);
  color: var(--muted);
}
button.primary .api-cost-badge { background: rgba(255, 255, 255, 0.22); color: inherit; }
.su-grid td button .api-cost-badge { color: inherit; }   /* иначе «td small» красит бейдж в серый */
button:disabled .api-cost-badge { opacity: 0.6; }

/* Группа действий */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}
.actions.stack {
  flex-direction: column;
  align-items: stretch;
}

/* ── Тумблер (switch) ────────────────────────────────────────────────────── */
.switch {
  position: relative;
  flex-shrink: 0;
  width: 36px;
  height: 20px;
}
.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.switch__slider {
  position: absolute;
  inset: 0;
  border-radius: var(--r-pill);
  background: var(--line-strong);
  transition: background var(--dur-fast) var(--ease-out);
}
.switch__slider::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform var(--dur) var(--ease-out);
}
.switch input:checked + .switch__slider { background: var(--accent); }
.switch input:checked + .switch__slider::before { transform: translateX(16px); }
.switch input:focus-visible + .switch__slider {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Тумблер-карточка */
.toggle-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-3);
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.toggle-card:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.toggle-card__text { display: grid; gap: 2px; min-width: 0; }
.toggle-card__title { font-size: var(--fs-md); color: var(--text); }
.toggle-card__hint { font-size: var(--fs-sm); color: var(--muted); line-height: 1.35; }

/* ── Статусы, пилюли, плашки ─────────────────────────────────────────────── */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 4px 10px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: var(--fs-sm);
  font-weight: 500;
}
.status-pill.ok { color: var(--accent-strong); border-color: var(--ok-border); background: var(--ok-bg); }
.status-pill.error { color: var(--danger); border-color: var(--danger-border); background: var(--danger-bg); }

.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  background: var(--surface-3);
  color: var(--text);
  margin-right: 6px;
}
.pill.ok { background: var(--ok-bg); color: var(--ok-fg); border: 1px solid var(--ok-border); }
.pill.bad { background: var(--danger-bg); color: var(--danger-fg); border: 1px solid var(--danger-border); }
.pill.warn { background: var(--warn-bg); color: var(--warn-fg); border: 1px solid var(--warn-border); }
.pill.info { background: var(--info-bg); color: var(--info-fg); border: 1px solid var(--info-border); }
.pill.muted { background: var(--bg-3); color: var(--c-muted); border: 1px solid var(--line); }

.alert-danger,
.alert-info,
.alert-warn {
  margin: var(--s-2) 0 var(--s-3);
  border: 1px solid;
  border-radius: var(--r-sm);
  padding: var(--s-2) var(--s-3);
  font-size: var(--fs-md);
}
.alert-danger { border-color: var(--danger-border); background: var(--danger-bg); color: var(--danger); }
.alert-info { border-color: var(--info-border); background: var(--info-bg); color: var(--info-fg); }
.alert-warn { border-color: var(--warn-border); background: var(--warn-bg); color: var(--warn-fg); }
.alert-danger ul { margin: var(--s-1) 0 0; padding-left: 18px; }

/* Точка статуса */
.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  vertical-align: middle;
}
.status-dot.ok { background: var(--accent-strong); }
.status-dot.error { background: var(--danger); }

/* ── Карточки ────────────────────────────────────────────────────────────── */
.meta-card {
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
}
.meta-card.wide { width: 100%; }
.meta-card h3,
.meta-card h4 { margin: 0; color: var(--text); }
.meta-card h3 { font-size: var(--fs-md); font-weight: 700; }
.meta-card h4 { margin-top: var(--s-3); font-size: var(--fs-sm); font-weight: 700; }
.meta-card p { margin-top: var(--s-2); }
.meta-card.mb { margin-bottom: var(--s-3); }

/* Строки «ключ — значение» */
.kv {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: var(--s-2);
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-sm);
}
.kv span { color: var(--muted); }
.kv strong { min-width: 0; color: var(--text); font-weight: 600; overflow-wrap: anywhere; }

.info-list { margin-top: var(--s-2); color: var(--muted); font-size: var(--fs-sm); }
.info-list strong { color: var(--text); }
.info-list ul { margin: var(--s-2) 0 0; padding-left: 18px; }
.info-list li { margin: 3px 0; overflow-wrap: anywhere; }

.clean-list { list-style: none; margin: var(--s-2) 0 0; padding: 0; }
.info-list .clean-list { padding: 0; }
.list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s-2);
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.list-row > span:first-child { min-width: 0; overflow-wrap: anywhere; }

/* ── Подсказки ───────────────────────────────────────────────────────────── */
.info-tooltip {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--panel);
  color: var(--accent-strong);
  font-size: var(--fs-xs);
  font-weight: 800;
  cursor: help;
}
.tooltip-box {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 5;
  display: none;
  min-width: 180px;
  max-width: min(320px, 70vw);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--code-bg);
  color: #fff;
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: 1.4;
  box-shadow: var(--elev-2);
}
.info-tooltip:hover .tooltip-box,
.info-tooltip:focus .tooltip-box { display: block; }

.has-tip { position: relative; }
.has-tip::after {
  content: attr(data-tip);
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 60;
  width: max-content;
  max-width: 360px;
  white-space: pre-line;
  text-align: left;
  background: var(--code-bg);
  color: #fff;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  font-weight: 400;
  line-height: 1.45;
  box-shadow: var(--elev-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease-out);
}
.has-tip:hover::after,
.has-tip:focus-visible::after { opacity: 1; }

/* ── Модалки ─────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--s-6);
  animation: modalFade var(--dur) var(--ease-out);
}
.modal[hidden] { display: none; }
.modal-dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  box-shadow: var(--elev-3);
  animation: modalPop var(--dur) var(--ease-out);
}
.modal-dialog.modal-wide { max-width: 1100px; }
.modal-dialog.modal-medium { max-width: 640px; }
.modal-header h2 { margin: 0; font-size: var(--fs-lg); font-weight: 700; }
.modal-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-2) var(--s-3);
}
.modal-form .span-2 { grid-column: span 2; }
.modal-actions {
  display: flex;
  gap: var(--s-2);
  justify-content: flex-end;
  /* Липкий футер: кнопки видны даже в длинной модалке. */
  position: sticky;
  bottom: calc(-1 * var(--s-5));
  margin: 0 calc(-1 * var(--s-5)) calc(-1 * var(--s-5));
  padding: var(--s-3) var(--s-5);
  background: var(--panel);
  border-top: 1px solid var(--line);
}

@keyframes modalFade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modalPop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* ── Утилиты (замена инлайн-стилей) ──────────────────────────────────────── */
.mt-2 { margin-top: var(--s-2) !important; }
.mt-3 { margin-top: var(--s-3) !important; }
.mt-4 { margin-top: var(--s-4) !important; }
.mb-2 { margin-bottom: var(--s-2) !important; }
.mb-3 { margin-bottom: var(--s-3) !important; }
.m-0 { margin: 0 !important; }
.w-full { width: 100%; }
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.pointer { cursor: pointer; }
.row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
}
.hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: var(--s-2) 0;
}
.indent-list {
  margin: var(--s-2) 0 0 18px;
  padding: 0;
}
.sub-note { margin: var(--s-1) 0 0 var(--s-4); color: var(--muted); }
.callout-danger {
  border-left: 3px solid var(--danger);
  padding: var(--s-2) var(--s-3);
  margin-bottom: var(--s-2);
}
.callout-danger.slim { padding: 0 0 0 var(--s-2); margin: 0; }
.pad-3 { padding: var(--s-3); }

/* ── Меньше движения ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Волна 1: подсказка «?» у заголовка экрана ───────────────────────────── */
.title-row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
}
.help {
  position: relative;
  display: inline-block;
  flex: none;
}
.help > summary {
  list-style: none;
  cursor: pointer;
  width: 22px;
  height: 22px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--fs-sm);
  line-height: 1;
  transition: color var(--dur-fast), border-color var(--dur-fast), background var(--dur-fast);
}
.help > summary::-webkit-details-marker { display: none; }
.help > summary:hover { color: var(--text); background: var(--surface-3); }
.help[open] > summary { color: var(--accent-strong); border-color: var(--accent); }
.help-box {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 70;
  width: min(480px, 80vw);
  padding: var(--s-3) var(--s-4);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--elev-3);
  font-size: var(--fs-md);
  font-weight: 400;
  color: var(--text);
  line-height: 1.5;
  animation: popIn var(--dur) var(--ease-out);
  transform-origin: top left;
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.96) translateY(-4px); }
  to { opacity: 1; transform: none; }
}

/* ── Волна 1: тосты (статус / завершение / предупреждение / ошибка) ─────── */
.toasts {
  position: fixed;
  right: var(--s-4);
  bottom: var(--s-4);
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: var(--s-2);
  align-items: start;
  padding: var(--s-2) var(--s-3);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  box-shadow: var(--elev-3);
  font-size: var(--fs-md);
  animation: toastIn var(--dur-slow) var(--ease-out);
}
.toast .ic { width: 18px; height: 18px; margin-top: 1px; }
.toast.ok { border-left-color: var(--accent); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast.info { border-left-color: var(--info); }
.toast strong { display: block; font-weight: 600; }
.toast p { margin: 2px 0 0; color: var(--muted); white-space: pre-line; overflow-wrap: anywhere; }
.toast .toast-close {
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.toast .toast-close:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.toast.leaving { animation: toastOut var(--dur) var(--ease-out) forwards; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateY(6px); }
}

/* ── Волна 1: скелетон загрузки и пустое состояние ──────────────────────── */
.skeleton {
  display: grid;
  gap: var(--s-2);
  padding: var(--s-3);
}
.skeleton i {
  display: block;
  height: 12px;
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--line) 50%, var(--surface-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
.skeleton i:nth-child(2n) { width: 72%; }
.skeleton i:nth-child(3n) { width: 86%; }
@keyframes shimmer {
  to { background-position: -200% 0; }
}
.empty-state {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: var(--s-6) var(--s-4);
  text-align: center;
  color: var(--muted);
}
.empty-state .ic { width: 22px; height: 22px; margin-bottom: var(--s-1); }
.empty-state p { margin: 0; color: var(--text); font-weight: 500; }
.empty-state small { color: var(--muted); }
.empty-state .actions { margin-top: var(--s-2); justify-content: center; }

/* ═══════════════════════════════════════════════════════════════════════════
   Волна 2 — таблицы и реестры (2026-09-15).
   Единый стиль таблицы, статус-бейдж с текстом, один чип на сущность,
   панель фильтров «поиск + только активные», свёрнутые детали в ячейке.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Таблица данных ──────────────────────────────────────────────────────── */
.su-table {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: clip;              /* не scroll-контейнер → thead липнет к окну */
}
.su-grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.su-grid th,
.su-grid td {
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
}
.su-grid th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
  box-shadow: inset 0 -1px 0 var(--line);
}
.su-grid tbody tr:last-child td { border-bottom: none; }
.su-grid td small { color: var(--muted); }
.su-grid th.num,
.su-grid td.num { text-align: right; white-space: nowrap; }
.su-grid td.nowrap { white-space: nowrap; }
.su-grid td.shrink-cell { width: 32%; max-width: 0; }   /* ужимается под ширину, содержимое режется с «…» */
.su-grid tbody tr:not(.bm-header):hover td { background: var(--hover); }
/* Зебра по группам БМ: каждая вторая группа — на втором фоне */
.su-grid tbody tr.g-alt td { background: var(--surface-2); }
.su-grid tbody tr.g-alt:not(.bm-header):hover td { background: var(--hover); }
.su-grid tr.bm-header td {
  background: var(--surface-3);
  color: var(--text);
  font-weight: 700;
  padding: var(--s-1) var(--s-3);
  border-top: 1px solid var(--line);
}
.su-grid tr.bm-header td small { color: var(--muted); font-weight: 500; }
.su-grid tbody tr.bm-header:first-child td { border-top: none; }
.su-actions { white-space: nowrap; }
.su-actions button { margin: 0 4px 0 0; }
.su-actions div { margin-top: 4px; }
.su-actions .row { display: flex; gap: var(--s-1); align-items: center; flex-wrap: wrap; }
@media (max-width: 980px) {
  .su-table { overflow: hidden; overflow-x: auto; }
  .su-grid th { position: static; }
}

/* ── Статус-бейдж: цвет + текст, цвет не единственный носитель смысла ────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px 2px 6px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--surface-3);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  vertical-align: middle;
}
.status-badge::before {
  content: "";
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dot-muted);
}
.status-badge.ok   { color: var(--ok-fg);     border-color: var(--ok-border);     background: var(--ok-bg); }
.status-badge.ok::before   { background: var(--accent-strong); }
.status-badge.bad  { color: var(--danger-fg); border-color: var(--danger-border); background: var(--danger-bg); }
.status-badge.bad::before  { background: var(--danger); }
.status-badge.warn { color: var(--warn-fg);   border-color: var(--warn-border);   background: var(--warn-bg); }
.status-badge.warn::before { background: var(--warn); }
.status-badge.info { color: var(--info-fg);   border-color: var(--info-border);   background: var(--info-bg); }
.status-badge.info::before { background: var(--info); }
.status-badge.no-dot::before { display: none; }

/* ── Чипы: одна сущность — один вид ──────────────────────────────────────
   .acc-id   — ID (аккаунт, пиксель, фанка): моно, нейтральный, копируется.
   .app-badge — номер FB-профиля («XER 46»): акцентный бейдж.
   БМ и имена — обычный текст. */
.acc-id {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  margin-top: 2px;
  padding: 1px 6px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: 600 var(--fs-sm) / 1.5 var(--font-mono);
  letter-spacing: 0;
  cursor: pointer;
  user-select: all;
  transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
}
.acc-id::after {
  content: "⧉";
  font-size: var(--fs-xs);
  font-family: var(--font-ui);
  color: var(--muted);
  opacity: 0.7;
}
.acc-id:hover { background: var(--surface-3); border-color: var(--line-strong); }
.acc-id.copied { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok-fg); }
.acc-id.copied::after { content: "✓"; color: var(--ok-fg); opacity: 1; }
.acc-id:active { transform: scale(0.98); }

/* ── Панель фильтров под шапкой: поиск + «Только активные» ───────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  margin: var(--s-3) 0;
}
.filter-bar__search {
  position: relative;
  flex: 1 1 260px;
  max-width: 420px;
}
.filter-bar__search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.filter-bar__search > .ic {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.filter-bar__search input {
  width: 100%;
  padding-left: 30px;
  padding-right: 28px;
}
.filter-bar__clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  padding: 3px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.filter-bar__clear .ic { position: static; transform: none; pointer-events: none; }
.filter-bar__clear:hover { background: var(--surface-3); color: var(--text); }
.filter-bar__search input:placeholder-shown ~ .filter-bar__clear { display: none; }
.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  margin: 0;
  padding: 0 var(--s-1);
  font-size: var(--fs-md);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.filter-bar__count {
  margin-left: auto;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ── Свёрнутые детали в ячейке («42 разрешения ▸», «1 ошибка ▸») ────────── */
.cell-details { display: inline-block; max-width: 100%; }
.cell-details > summary {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  cursor: pointer;
  color: var(--text);
  font-size: var(--fs-md);
  border-radius: var(--r-sm);
  padding: 1px 2px;
}
.cell-details > summary::-webkit-details-marker { display: none; }
.cell-details > summary::after {
  content: "";
  width: 0;
  height: 0;
  border: 4px solid transparent;
  border-left: 5px solid var(--muted);
  margin-left: 2px;
  transition: transform var(--dur-fast) var(--ease-out);
}
.cell-details[open] > summary::after { transform: rotate(90deg); }
.cell-details > summary:hover { background: var(--surface-3); }
.cell-details__body { margin-top: var(--s-2); }
.cell-details__body .su-scopes { max-width: 520px; }
.cell-details__body ul { margin: 0; padding-left: 18px; }
.cell-details__body li { margin: 2px 0; overflow-wrap: anywhere; }

/* ── Кольцо лимита API + подпись значения ───────────────────────────────── */
.acc-gauge-wrap { display: inline-flex; align-items: center; gap: 6px; }
.acc-gauge-val { font-size: var(--fs-sm); font-variant-numeric: tabular-nums; color: var(--text); min-width: 3ch; }
.acc-gauge-empty { color: var(--muted); font-size: var(--fs-sm); cursor: help; }

/* Кнопка-иконка в строке (обновить аккаунт): подпись живёт в title */
.row-icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font-size: var(--fs-sm);
  cursor: pointer;
}
.row-icon-btn:hover:not(:disabled) { background: var(--surface-3); }
.row-icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.row-icon-btn .api-cost-badge { background: var(--surface-3); color: var(--muted); }
.su-scopes { display: flex; flex-wrap: wrap; gap: 4px; }
.su-scope {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--muted);
  font: 500 var(--fs-xs) / 1.6 var(--font-mono);
}
.su-scope-req { color: var(--ok-fg); border-color: var(--ok-border); background: var(--ok-bg); }

/* ═══ Волна 5 — справочники, подключения, модалки ════════════════════════ */
.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  flex-wrap: wrap;
  min-height: 30px;
}
.pane-head h3 { margin: 0; }
.pane-actions { display: flex; gap: var(--s-1); align-items: center; flex-wrap: wrap; }
.pane-actions button, .pane-actions a.primary { padding: 5px 10px; font-size: var(--fs-sm); }
.pane-actions .primary { padding: 7px 12px; font-size: var(--fs-md); }
.presets-pane .filter-bar__search { position: relative; flex: 0 0 auto; max-width: none; margin-bottom: var(--s-1); }
.presets-pane .filter-bar__search > .ic { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.presets-pane .filter-bar__search input { padding-left: 30px; }
.presets-pane .filter-bar__search input::-webkit-search-cancel-button { -webkit-appearance: none; }

/* Разрушающее действие: не заливка, а красный текст с иконкой */
.btn-danger-ghost {
  background: transparent;
  border: 1px solid transparent;
  color: var(--danger);
}
.btn-danger-ghost:where(:hover:not(:disabled)) { background: var(--danger-bg); border-color: var(--danger-border); }
.btn-danger-ghost:disabled { color: var(--muted); }

/* Меню «…» (details) */
.menu { position: relative; display: inline-block; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
}
.menu > summary.icon-btn:hover { background: var(--surface-3); }
.menu[open] > summary.icon-btn { background: var(--surface-3); border-color: var(--line-strong); }
.menu__list {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  min-width: 220px;
  padding: var(--s-1);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel);
  box-shadow: var(--elev-2);
  display: grid;
  gap: 2px;
  animation: menuIn var(--dur-fast) var(--ease-out);
  transform-origin: top right;
}
@keyframes menuIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
.menu__list button {
  justify-content: flex-start;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 7px 10px;
  border-radius: var(--r-sm);
  font-weight: 500;
}
.menu__list button:hover:not(:disabled) { background: var(--surface-3); }
.menu__list button.menu__danger { color: var(--danger); }
.menu__list button.menu__danger:hover:not(:disabled) { background: var(--danger-bg); }
.menu__list button:disabled { color: var(--muted); }
.conn-actions { margin-top: var(--s-2); }
.conn-card .status-badge { margin-left: auto; }
.conn-card .modal-form { display: grid; grid-template-columns: 1fr; gap: 4px; }

/* Сегментные вкладки */
.seg-tabs {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.seg-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 5px 12px;
  border-radius: var(--r-sm);
  font-weight: 600;
}
.seg-tab:hover:not(.active) { color: var(--text); background: var(--surface-3); }
.seg-tab.active { background: var(--panel); color: var(--text); box-shadow: var(--elev-1); }
.seg-tab__count {
  display: inline-block;
  min-width: 18px;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--muted);
  font-size: var(--fs-xs);
  text-align: center;
}
.seg-tab.active .seg-tab__count { background: var(--accent-soft); color: var(--accent-strong); }

/* Поля гео-редактора: свёрнутые типы */
.geo-field { border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--panel); }
.geo-field > summary {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 6px 10px;
  list-style: none;
  cursor: pointer;
  font-size: var(--fs-sm);
  color: var(--muted);
  font-weight: 600;
}
.geo-field > summary::-webkit-details-marker { display: none; }
.geo-field > summary::before { content: ""; width: 0; height: 0; border: 4px solid transparent; border-left: 5px solid var(--muted); transition: transform var(--dur-fast); }
.geo-field[open] > summary::before { transform: rotate(90deg); }
.geo-field.has-value > summary { color: var(--text); }
.geo-field__count { margin-left: auto; font-weight: 500; color: var(--muted); }
.geo-field.has-value .geo-field__count { color: var(--accent-strong); }
.geo-field textarea { border: none; border-top: 1px solid var(--line); border-radius: 0 0 var(--r-sm) var(--r-sm); }

/* Модалка: появление из точки вызова */
.modal-dialog { transform-origin: var(--mox, 50%) var(--moy, 50%); }
@keyframes modalPop {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: none; }
}

.menu[hidden] { display: none !important; }

/* ── Подключения: карточки с иконкой, пояснением и бейджем ───────────────── */
#systemConnectionsScreen [hidden], #analyticsView [hidden], .app-rail [hidden] { display: none !important; }
.conn-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); margin-top: var(--s-3); }
.conn-card {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-4);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel);
  min-width: 0;
}
.conn-card--wide { grid-column: 1 / -1; }
.conn-card__head { display: flex; align-items: flex-start; gap: var(--s-3); }
.conn-card__icon {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  background: var(--surface-3);
  color: var(--accent-strong);
}
.conn-card__icon .ic { width: 18px; height: 18px; }
.conn-card__title { flex: 1; min-width: 0; }
.conn-card__title h3 { margin: 0; font-size: var(--fs-lg); }
.conn-card__title p { margin: 2px 0 0; color: var(--muted); font-size: var(--fs-sm); line-height: 1.4; }
.conn-card__head .status-badge { margin-left: auto; flex: none; margin-top: 4px; }
.conn-card__body { display: grid; gap: var(--s-2); }
.conn-line { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; min-width: 0; }
.conn-line > .acc-id { flex: 0 1 auto; min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }
.conn-card__actions a.ghost, .conn-card__actions a.primary {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  padding: 7px 12px; border-radius: var(--r-sm); font-weight: 600; line-height: 1.4;
}
.conn-card__actions a.ghost { border: 1px solid var(--line); background: transparent; color: var(--text); }
.conn-card__actions a.ghost:hover { background: var(--surface-3); }
.conn-card__actions a.primary { background: var(--accent); color: var(--on-accent); border: 1px solid transparent; }
.conn-card__actions a.primary:hover { background: var(--accent-strong); }
.conn-card__actions a.disabled { opacity: 0.5; pointer-events: none; }
.conn-label { flex: 0 0 64px; color: var(--muted); font-size: var(--fs-sm); }
.conn-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: var(--fs-sm); }
.conn-empty { margin: 0; color: var(--muted); }
.conn-form {
  display: grid;
  gap: var(--s-2);
  padding: var(--s-3);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.conn-form label { display: grid; gap: 4px; }
.conn-form label > span { font-size: var(--fs-sm); color: var(--muted); }
.conn-form small code { font-size: 0.95em; }
.conn-card__actions { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; margin-top: auto; }
.conn-card__actions--split { justify-content: space-between; }
.conn-sound { display: flex; align-items: center; gap: var(--s-2); }
.conn-card .alert-danger { margin: 0; }
@media (max-width: 900px) { .conn-grid { grid-template-columns: 1fr; } }

/* Смена раздела: экран появляется мягко, а не жёстким срезом (F-09). */
.workspace { animation: viewIn var(--dur) var(--ease-out); }
@keyframes viewIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
