/* SKM · ТРМ1033 — оформление приложения. Только токены из tokens.css (копия skm-tokens.css студии v17). */

/* ---------- База ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--backdrop-mesh);
  background-attachment: fixed;
  color: var(--label);
  font: var(--text-subhead)/var(--leading-normal) var(--font-sans);
  overflow-x: hidden;
}
h1, h2, h3 { font-family: var(--font-display); letter-spacing: var(--tracking-display); line-height: var(--leading-tight); }
h1 { font-size: var(--text-title2); font-weight: var(--weight-semibold); margin: 0; }
h2 { font-size: var(--text-title3); font-weight: var(--weight-semibold); margin: 0 0 var(--space-3); }
h3 { font-size: var(--text-headline); font-weight: var(--weight-semibold); margin: 0; }
p { margin: 0 0 var(--space-2); }
a { color: var(--brand-text); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: var(--focus-width) solid var(--focus-ring); outline-offset: var(--focus-offset); }
img { max-width: 100%; }
[hidden] { display: none !important; }
.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; }
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 100; background: var(--bg-elevated); padding: var(--space-2) var(--space-3); border-radius: var(--r-xs); }
.skip-link:focus { left: 8px; }
.muted { color: var(--label-3); }
.small { font-size: var(--text-caption); }
.ico { flex: none; vertical-align: -0.2em; }
.spacer { flex: 1 1 auto; }

/* Чёрные иконки дизайна в тёмной теме — инвертируем (логотип — растровый, не трогаем) */
:root[data-theme="dark"] img[src$="exit.svg"],
:root[data-theme="dark"] img[src$="user.svg"],
:root[data-theme="dark"] img[src$="settings.svg"],
:root[data-theme="dark"] img[src$="grid-large.svg"],
:root[data-theme="dark"] img[src$="grid-compact.svg"],
:root[data-theme="dark"] img[src$="eye-hidden.svg"] { filter: invert(1); }

/* ---------- Кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--size-target); padding: 0 var(--space-4);
  border: 1px solid var(--separator); border-radius: var(--r-capsule);
  background: var(--bg-elevated); color: var(--label);
  font-weight: var(--weight-medium); text-decoration: none; cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard), transform var(--dur-fast) var(--ease-standard);
  touch-action: manipulation;
}
.btn:hover:not(:disabled) { background: var(--bg-sunken); }
.btn:active:not(:disabled) { transform: scale(var(--press-scale)); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--label-on-brand); }
.btn-primary:hover:not(:disabled) { background: var(--brand-strong); }
.btn-danger { background: var(--status-alarm); border-color: var(--status-alarm); color: #fff; }
:root[data-theme="dark"] .btn-danger { color: #1a0002; }
.btn-danger-text { color: var(--status-alarm); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--fill-3); }
.btn-sm { min-height: 36px; padding: 0 var(--space-3); font-size: var(--text-footnote); }
@media (pointer: coarse) { .btn-sm { min-height: var(--size-target); } }
.btn-wide { width: 100%; }
.icon-btn {
  display: inline-grid; place-content: center; width: var(--size-target); height: var(--size-target);
  padding: 0; border: 1px solid var(--separator); border-radius: 50%;
  background: var(--bg-elevated); color: var(--label); cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--bg-sunken); }
.icon-btn img { width: 26px; height: 26px; }
.input, .select {
  min-height: var(--size-target); padding: 0 var(--space-3);
  border: 1px solid var(--separator); border-radius: var(--r-field);
  background: var(--bg-elevated); color: var(--label); max-width: 100%;
}
textarea.input { padding: var(--space-2) var(--space-3); width: 100%; resize: vertical; }
.input-short { width: 120px; }
.input:disabled, .select:disabled { opacity: .55; }
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; accent-color: var(--brand); flex: none; }
.field { margin: 0 0 var(--space-4); border: 0; padding: 0; min-width: 0; }
.field > label, .field > legend, .ctl-block > label, .ctl-block > legend { display: block; font-weight: var(--weight-semibold); margin-bottom: var(--space-1); font-size: var(--text-footnote); color: var(--label-2); padding: 0; }
.field .input, .field .select { width: 100%; }
.field .input-short { width: 120px; }
.check { display: flex; align-items: center; gap: var(--space-2); min-height: var(--size-target); cursor: pointer; }
.checks { display: grid; gap: 0; max-height: 260px; overflow: auto; border: 1px solid var(--separator); border-radius: var(--r-field); padding: var(--space-1) var(--space-3); }
.radios { display: grid; }
.hint { color: var(--label-3); font-size: var(--text-footnote); margin: var(--space-1) 0 var(--space-2); }
.hint-flash { color: var(--status-warning); font-weight: var(--weight-semibold); }
.field-err { color: var(--danger); font-size: var(--text-footnote); margin: var(--space-1) 0 0; min-height: 0; }
.field-err:empty { display: none; }
.field-errs { color: var(--danger); margin: var(--space-2) 0; padding-left: var(--space-5); }
.field-errs:empty { display: none; }
.link { font-size: var(--text-footnote); display: inline-flex; align-items: center; min-height: var(--size-target); }
.plain { margin: 0 0 var(--space-3); padding-left: var(--space-5); }

/* Переключатель */
.switch { display: flex; align-items: center; gap: var(--space-3); min-height: var(--size-target); cursor: pointer; font-weight: var(--weight-medium); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; flex: none; width: 52px; height: 32px; border-radius: 16px; background: var(--gray-300); transition: background var(--dur-base) var(--ease-standard); }
:root[data-theme="dark"] .switch-track { background: var(--gray-700); }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-1); transition: transform var(--dur-base) var(--ease-spring); }
.switch input:checked + .switch-track { background: var(--status-ok); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: var(--focus-width) solid var(--focus-ring); outline-offset: 2px; }

/* Сегменты */
.seg { display: inline-flex; padding: 3px; gap: 3px; border-radius: var(--r-capsule); background: var(--fill-2); max-width: 100%; }
.seg button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 var(--space-4); border: 0; border-radius: var(--r-capsule); background: transparent; color: var(--label); cursor: pointer; font-weight: var(--weight-medium); white-space: nowrap; }
.seg button img { width: 18px; height: 18px; }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--label-on-brand); }
.seg button[aria-pressed="true"] img { filter: invert(1); }
:root[data-theme="dark"] .seg button[aria-pressed="true"] img { filter: invert(1); }
.seg button:disabled { opacity: .5; cursor: not-allowed; }
.seg-wide { display: flex; width: 100%; }
.seg-wide button { flex: 1 1 0; padding: 0 var(--space-2); min-height: var(--size-target); }

/* Плашки */
.pill, .status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 12px; border-radius: var(--r-capsule); font-size: var(--text-footnote); font-weight: var(--weight-semibold); white-space: nowrap; }
.pill-ok { background: var(--status-ok-bg); color: var(--status-ok); }
.pill-warn { background: var(--status-warning-bg); color: var(--status-warning); }
.pill-err { background: var(--status-alarm-bg); color: var(--status-alarm); }
.pill-info { background: var(--fill-2); color: var(--label-2); }
.st-running { background: var(--status-ok-bg); color: var(--status-ok); }
.st-starting { background: var(--status-ack-bg); color: var(--status-ack); }
.st-stopped { background: var(--fill-2); color: var(--label); }
.st-alarm { background: var(--status-alarm-bg); color: var(--status-alarm); }
.st-keyoff { background: var(--fill-1); color: var(--label); border: 1px solid var(--separator-strong); }
.st-nolink { background: var(--status-offline-bg); color: var(--status-offline); border: 1px dashed var(--status-offline); }
.st-unknown { background: var(--fill-2); color: var(--label-3); }
.count-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--r-capsule); background: var(--status-alarm); color: #fff; font-size: var(--text-caption); font-weight: var(--weight-bold); }
:root[data-theme="dark"] .count-badge { color: #1a0002; }
.age { display: inline-flex; align-items: center; gap: 4px; color: var(--status-warning); font-size: var(--text-footnote); font-weight: var(--weight-medium); }
.card-err { color: var(--label-3); font-size: var(--text-footnote); margin: var(--space-1) 0 0; }
.card-busy, .busy { display: inline-flex; align-items: center; gap: 6px; color: var(--status-ack); font-size: var(--text-footnote); margin: 0; }
.meas { font-variant-numeric: tabular-nums; font-weight: var(--weight-semibold); }
.meas-bad { color: var(--label-3); font-style: italic; font-weight: var(--weight-regular); }

/* Сообщения */
.msg { padding: var(--space-3) var(--space-4); border-radius: var(--r-field); border: 1px solid var(--separator); background: var(--bg-elevated); margin: 0 0 var(--space-3); }
.msg-err { background: var(--status-alarm-bg); border-color: var(--status-alarm); color: var(--status-alarm); }
.msg-warn { background: var(--status-warning-bg); border-color: var(--status-warning); color: var(--status-warning); }
.msg-ok { background: var(--status-ok-bg); border-color: var(--status-ok); color: var(--status-ok); }

/* Уведомления */
.toasts { position: fixed; z-index: 200; left: 50%; bottom: var(--space-4); transform: translateX(-50%); display: grid; gap: var(--space-2); width: min(480px, calc(100vw - 32px)); pointer-events: none; }
.toast { padding: var(--space-3) var(--space-4); border-radius: var(--r-field); background: var(--bg-elevated); color: var(--label); border: 1px solid var(--separator); box-shadow: var(--shadow-3); font-weight: var(--weight-medium); }
.toast-ok { border-left: 6px solid var(--status-ok); }
.toast-warn { border-left: 6px solid var(--status-warning); }
.toast-err { border-left: 6px solid var(--status-alarm); }

/* ---------- Шапка ---------- */
.apphead {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 72px; padding: var(--space-2) var(--space-5);
  background: var(--glass-thick-fill); -webkit-backdrop-filter: var(--glass-thick-blur); backdrop-filter: var(--glass-thick-blur);
  border-bottom: 1px solid var(--separator);
}
.brand { display: inline-flex; align-items: center; gap: var(--space-2); text-decoration: none; flex: none; }
.brand img { width: 52px; height: 52px; border-radius: 50%; }
.brand-text { font: 400 var(--text-title1)/1 var(--font-display); color: var(--brand-text); }
.nav { display: flex; align-items: center; gap: 4px; padding: 4px; border-radius: var(--r-capsule); background: var(--fill-2); flex-wrap: wrap; min-width: 0; }
.nav a { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 var(--space-4); border-radius: var(--r-capsule); color: var(--label); text-decoration: none; font-weight: var(--weight-medium); white-space: nowrap; }
.nav a:hover { background: var(--bg-sunken); }
.nav a[aria-current="page"] { background: var(--brand); color: var(--label-on-brand); }
.badge { display: inline-grid; place-content: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--status-alarm); color: #fff; font-size: var(--text-caption); font-weight: var(--weight-bold); }
.head-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); flex: none; }
.user-badge { display: inline-flex; align-items: center; gap: var(--space-2); height: 48px; padding: 0 var(--space-4) 0 6px; border-radius: var(--r-capsule); background: var(--brand-soft); max-width: 260px; }
.user-badge img { width: 34px; height: 34px; flex: none; }
.user-text { display: grid; line-height: 1.15; min-width: 0; }
.user-text b, .user-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-text small { color: var(--label-2); }
.nav-toggle { display: none; }

@media (max-width: 1100px) {
  .apphead { flex-wrap: wrap; padding: var(--space-2) var(--space-3); }
  .brand-text { display: none; }
  .user-text { display: none; }
  .user-badge { padding: 0 6px; }
}
@media (max-width: 860px) {
  .nav-toggle { display: inline-grid; }
  .brand img { width: 44px; height: 44px; }
  .nav { display: none; order: 10; flex: 1 1 100%; flex-direction: column; align-items: stretch; border-radius: var(--r-field); background: var(--bg-elevated); border: 1px solid var(--separator); }
  .nav a { min-height: var(--size-target); }
  body.nav-open .nav { display: flex; }
}

/* ---------- Страница ---------- */
.view { outline: none; }
.page { padding: var(--space-5); max-width: 1500px; margin: 0 auto; min-width: 0; }
.page.narrow { max-width: 760px; }
.page-head { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; justify-content: space-between; margin-bottom: var(--space-4); }
.panel { background: var(--bg-elevated); border: 1px solid var(--separator); border-radius: var(--r-panel); padding: var(--space-5); box-shadow: var(--shadow-1); margin-bottom: var(--space-4); min-width: 0; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; }
.toolbar { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-3); }
.toolbar > label:not(.sr-only) { font-weight: var(--weight-semibold); }
.search { flex: 1 1 240px; min-width: 0; }
.search input { width: 100%; min-height: var(--size-target); padding: 0 var(--space-4); border: 1px solid var(--separator); border-radius: var(--r-capsule); background: var(--bg-elevated); }
.summary { color: var(--label-2); font-size: var(--text-footnote); }
@media (max-width: 600px) {
  .page { padding: var(--space-3); }
  .panel { padding: var(--space-4); border-radius: 24px; }
  .toolbar .select { flex: 1 1 100%; }
  .toolbar .seg { flex: 1 1 100%; }
  .toolbar .seg button { flex: 1 1 0; }
}

/* ---------- Таблицы ---------- */
.table-wrap { background: var(--bg-elevated); border: 1px solid var(--separator); border-radius: 24px; overflow: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: var(--text-subhead); }
.tbl th { text-align: left; padding: 12px 16px; font-size: var(--text-footnote); font-weight: var(--weight-semibold); color: var(--label-3); border-bottom: 1px solid var(--separator); white-space: nowrap; }
.tbl td { padding: 10px 16px; border-bottom: 1px solid var(--separator); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl a { font-weight: var(--weight-semibold); }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .btn + .btn { margin-left: 4px; }
.tbl tr.row-active td:first-child { box-shadow: inset 4px 0 0 var(--status-alarm); }
.tbl-devices tr.row-alarm td:first-child { box-shadow: inset 4px 0 0 var(--status-alarm); }
.tbl-devices tr.row-warning td:first-child { box-shadow: inset 4px 0 0 var(--status-warning); }
.tbl-devices tr.row-unknown td { background: repeating-linear-gradient(45deg, transparent 0 8px, var(--fill-3) 8px 16px); }
/* Узкий экран: строки таблицы становятся карточками, без горизонтальной прокрутки */
@media (max-width: 760px) {
  .table-wrap { background: transparent; border: 0; overflow: visible; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .tbl tr { background: var(--bg-elevated); border: 1px solid var(--separator); border-radius: 20px; padding: var(--space-2) var(--space-3); margin-bottom: var(--space-3); }
  .tbl td { border: 0; padding: 6px 0; display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: var(--space-2); overflow-wrap: anywhere; }
  .tbl td::before { content: attr(data-label); color: var(--label-3); font-size: var(--text-footnote); font-weight: var(--weight-semibold); }
  .tbl td:not([data-label]) { display: block; }
  .tbl td:not([data-label])::before { content: none; }
  .row-actions { text-align: left; white-space: normal; display: flex !important; flex-wrap: wrap; gap: var(--space-2); }
  .row-actions .btn + .btn { margin-left: 0; }
  .tbl tr.row-active, .tbl-devices tr.row-alarm { border-left: 6px solid var(--status-alarm); }
  .tbl-devices tr.row-warning { border-left: 6px solid var(--status-warning); }
  .tbl tr.row-active td:first-child, .tbl-devices tr td:first-child { box-shadow: none; }
}

/* ---------- Главная ---------- */
.home { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: calc(100vh - 72px); }
.groups-pane { border-right: 1px solid var(--separator); background: var(--glass-regular-fill); -webkit-backdrop-filter: var(--glass-regular-blur); backdrop-filter: var(--glass-regular-blur); padding: var(--space-4); position: sticky; top: 72px; height: calc(100vh - 72px); overflow: auto; }
.groups-pane-head { display: flex; align-items: center; justify-content: space-between; }
.groups-pane-head h2 { margin: 0; }
.drawer-close, .drawer-open, .drawer-scrim { display: none; }
.home-main { max-width: none; margin: 0; }
.group-tree ul { list-style: none; margin: 0; padding: 0; }
.gnode { display: flex; align-items: center; gap: var(--space-2); width: 100%; min-height: var(--size-target); padding: 0 var(--space-3) 0 calc(var(--space-3) + var(--depth, 0) * 18px); margin: 2px 0; border: 0; border-radius: var(--r-capsule); background: transparent; color: var(--label); cursor: pointer; text-align: left; }
.gnode:hover { background: var(--fill-3); }
.gnode[aria-current="true"] { background: var(--brand); color: var(--label-on-brand); }
.gname { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gcount { flex: none; font-size: var(--text-caption); font-weight: var(--weight-semibold); opacity: .8; }
@media (max-width: 1024px) {
  .home { display: block; }
  .drawer-open { display: inline-flex; }
  .drawer-close { display: inline-grid; }
  .groups-pane { position: fixed; z-index: 120; top: 0; left: 0; bottom: 0; height: auto; width: min(320px, 86vw); transform: translateX(-105%); transition: transform var(--dur-slow) var(--ease-standard); background: var(--bg-elevated); box-shadow: var(--shadow-3); }
  .groups-pane.open { transform: none; }
  .drawer-scrim { display: block; position: fixed; inset: 0; z-index: 110; background: var(--scrim); }
  .drawer-scrim[hidden] { display: none; }
}

/* Карточки приборов */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--space-4); }
@media (max-width: 400px) { .cards { grid-template-columns: minmax(0, 1fr); } }
.dcard {
  position: relative; display: flex; flex-direction: column; gap: var(--space-2);
  padding: var(--space-4) var(--space-5); min-width: 0;
  background: var(--bg-elevated); color: var(--label); text-decoration: none;
  border: 2px solid var(--separator); border-left-width: 8px; border-radius: 28px; box-shadow: var(--shadow-1);
  transition: transform var(--dur-fast) var(--ease-standard), box-shadow var(--dur-fast) var(--ease-standard);
}
.dcard:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.dcard-head { display: flex; align-items: flex-start; gap: var(--space-2); }
.dcard-name { flex: 1 1 auto; overflow-wrap: anywhere; font-size: var(--text-headline); }
.card-lock { flex: none; color: var(--label); }
.dcard-group { color: var(--label-3); font-size: var(--text-footnote); margin: -4px 0 0; overflow-wrap: anywhere; }
.dcard-status { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.dcard-vals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); margin: var(--space-1) 0 0; }
.dcard-vals div { min-width: 0; }
.dcard-vals dt { color: var(--label-3); font-size: var(--text-caption); }
.dcard-vals dd { margin: 0; font-size: var(--text-footnote); overflow-wrap: anywhere; }
.sev-normal { border-color: var(--status-ok); }
.sev-warning { border-color: var(--status-warning); }
.sev-alarm { border-color: var(--status-alarm); box-shadow: 0 0 0 2px var(--status-alarm-bg), var(--shadow-1); }
.sev-neutral { border-color: var(--gray-500); }
.sev-unknown { border-color: var(--status-offline); border-style: dashed; }
/* «Нет связи» — серо и со штриховкой, явно не норма */
.dcard.card-noLink {
  background: repeating-linear-gradient(135deg, var(--bg-elevated) 0 10px, var(--status-offline-bg) 10px 20px);
  color: var(--label-2);
}
.dcard.card-noLink .meas { color: var(--label-3); }
.dcard.card-keyOff { background: linear-gradient(var(--fill-3), var(--fill-3)), var(--bg-elevated); }
.dcard.card-alarm .dcard-name { color: var(--status-alarm); }

/* ---------- Страница прибора ---------- */
.device-page { max-width: 1500px; }
.dev-top { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-2); }
.dev-title { flex: 1 1 260px; min-width: 0; }
.dev-title h1 { overflow-wrap: anywhere; }
.dev-title p { margin: 2px 0 0; }
.dev-nav { display: flex; gap: var(--space-1); }
.dev-status { display: flex; align-items: center; gap: var(--space-2) var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-4); }
.dev-status .status-pill { font-size: var(--text-subhead); padding: 6px 16px; }
.kv .k { color: var(--label-3); font-size: var(--text-footnote); margin-right: 4px; }
.dev-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 400px); gap: var(--space-4); align-items: start; }
.col-main, .col-side { min-width: 0; }
@media (max-width: 1000px) {
  .dev-grid { grid-template-columns: minmax(0, 1fr); }
  .col-side { order: -1; }
}
@media (max-width: 600px) {
  .dev-nav span { display: none; }
}

/* Мнемосхема: экран всегда тёмный, как пульт оператора (цвета внутри SVG — из logic/scheme.js) */
.scheme-box { width: 100%; overflow: hidden; border-radius: 20px; background: #0d0f12; border: 1px solid #1c2127; padding: 8px 6px 4px; }
.scheme-svg { display: block; width: 100%; height: auto; }
.scheme-svg text { font-family: var(--font-sans); }
@keyframes sv-spin { to { transform: rotate(360deg); } }
@keyframes hmi-flow { to { stroke-dashoffset: -48; } }
@keyframes hmi-glow { 0%, 100% { opacity: .04; } 50% { opacity: .12; } }
.hmi-flow, .hmi-flow > * { animation: hmi-flow 1.6s linear infinite; }
.hmi-water { animation: hmi-flow 2.2s linear infinite; }
.hmi-spin { animation: sv-spin 1.1s linear infinite; transform-box: fill-box; transform-origin: center; }
.hmi-spin-fast { animation: sv-spin .7s linear infinite; transform-box: fill-box; transform-origin: center; }
.hmi-glow { animation: hmi-glow 2.6s ease-in-out infinite; }
.hmi-spin-slow { animation: sv-spin 6s linear infinite; transform-box: fill-box; transform-origin: center; }
/* Лопатки заслонки поворачиваются за время хода привода (~6 с), а не прыгают. */
.hmi-blade { transition: transform 6s ease-in-out; transform-box: fill-box; transform-origin: center; }
@media (prefers-reduced-motion: reduce) {
  .hmi-flow, .hmi-flow > *, .hmi-water, .hmi-spin, .hmi-spin-fast, .hmi-spin-slow, .hmi-glow { animation: none; }
  .hmi-blade { transition: none; }
}
:root[data-motion="reduce"] :is(.hmi-flow, .hmi-flow > *, .hmi-water, .hmi-spin, .hmi-spin-fast, .hmi-spin-slow, .hmi-glow) { animation: none; }
/* Текстовый список под схемой нужен только на узком экране, где подписи схемы мелкие. */
@media (min-width: 761px) { .hmi-facts { display: none; } }

.indicators { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-1) var(--space-4); }
.indicators li { display: flex; align-items: center; gap: var(--space-2); min-height: 32px; min-width: 0; }
.ind-name { color: var(--label-3); }
.ind-val { font-weight: var(--weight-semibold); }
.ind-dot { flex: none; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--status-offline); background: transparent; }
.ind-dot.el-on, .ind-dot.el-ok { background: var(--status-ok); border-color: var(--status-ok); }
.ind-dot.el-off { background: var(--gray-400); border-color: var(--gray-500); }
.ind-dot.el-starting { background: var(--status-ack); border-color: var(--status-ack); }
.ind-dot.el-fault { background: var(--status-alarm); border-color: var(--status-alarm); border-radius: 2px; }
.ind-dot.el-warn { background: var(--status-warning); border-color: var(--status-warning); border-radius: 2px; }
.ind-dot.el-unknown { border-style: dashed; }
.ind-lock { grid-column: 1 / -1; padding: var(--space-2) var(--space-3); border-radius: var(--r-field); background: var(--fill-2); border: 2px solid var(--separator-strong); }


/* Пульт */
.control { position: relative; }
.ctl-reason { display: flex; align-items: flex-start; gap: var(--space-2); padding: var(--space-3); border-radius: var(--r-field); background: var(--status-offline-bg); color: var(--label); font-weight: var(--weight-medium); margin-bottom: var(--space-3); }
.ctl-reason-key { background: var(--fill-1); border: 2px solid var(--separator-strong); font-weight: var(--weight-semibold); }
/* Переключатели пульта: нажатая половина показывает состояние прибора, а не последнее нажатие. */
.control {
  --p-bg: var(--fill-2); --p-line: var(--separator); --p-text: var(--label-2);
  --p-ok-bg: #d8f5f0; --p-ok-line: #2bb3a3; --p-ok-text: #0b5d54;
  --p-win-bg: #dcebff; --p-win-line: #3b82d6; --p-win-text: #12457f;
  --p-sum-bg: #fdefd2; --p-sum-line: #d9921a; --p-sum-text: #7a4a07;
  --p-stop-bg: #eceef1; --p-stop-line: #8a94a3; --p-stop-text: #3a414b;
}
:root[data-theme="dark"] .control {
  --p-bg: #13171c; --p-line: #232930; --p-text: #8a94a3;
  --p-ok-bg: #0d2926; --p-ok-line: #1b5952; --p-ok-text: #5ee3d2;
  --p-win-bg: #0e2137; --p-win-line: #234d85; --p-win-text: #8cc0ff;
  --p-sum-bg: #2a1d08; --p-sum-line: #6b4a12; --p-sum-text: #f5b547;
  --p-stop-bg: #1d232b; --p-stop-line: #3a434e; --p-stop-text: #c3cbd5;
}
.pseg { display: flex; gap: 4px; padding: 4px; border-radius: 16px; background: var(--p-bg); border: 1px solid var(--p-line); }
.pseg button { position: relative; overflow: hidden; flex: 1 1 0; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 0 var(--space-2); border: 0; border-radius: 12px; background: transparent; color: var(--p-text); font: inherit; font-weight: var(--weight-medium); cursor: pointer; white-space: nowrap; }
.pseg button:hover:not(:disabled) { background: color-mix(in srgb, var(--p-text) 10%, transparent); }
.pseg button:focus-visible { outline: 2px solid var(--p-win-line); outline-offset: 1px; }
.pseg button:disabled { opacity: .45; cursor: not-allowed; }
.pseg button img { width: 16px; height: 16px; }
.pseg button[aria-pressed="true"] { box-shadow: inset 0 0 0 1px var(--p-line); }
.pseg-run[aria-pressed="true"], .pseg-auto[aria-pressed="true"] { background: var(--p-ok-bg); color: var(--p-ok-text); box-shadow: inset 0 0 0 1px var(--p-ok-line); }
.pseg-winter[aria-pressed="true"] { background: var(--p-win-bg); color: var(--p-win-text); box-shadow: inset 0 0 0 1px var(--p-win-line); }
.pseg-summer[aria-pressed="true"] { background: var(--p-sum-bg); color: var(--p-sum-text); box-shadow: inset 0 0 0 1px var(--p-sum-line); }
.pseg-stop[aria-pressed="true"] { background: var(--p-stop-bg); color: var(--p-stop-text); box-shadow: inset 0 0 0 1px var(--p-stop-line); }
.pseg button[aria-pressed="true"] { cursor: default; }
.pseg-stop { user-select: none; -webkit-user-select: none; touch-action: none; -webkit-touch-callout: none; }
.hold-fill { position: absolute; inset: 0; background: var(--status-alarm); opacity: .3; transform: scaleX(0); transform-origin: left center; pointer-events: none; border-radius: inherit; }
.hold-label { position: relative; display: inline-flex; align-items: center; gap: 6px; }
.ctl-block { border: 0; padding: 0; margin: var(--space-4) 0 0; min-width: 0; }
.ctl-first { margin-top: 0; }
.stepper-row { display: flex; gap: var(--space-2); align-items: stretch; flex-wrap: wrap; }
.stepper { flex: 1 1 200px; display: flex; align-items: center; min-width: 0; border-radius: 14px; background: var(--p-bg); border: 1px solid var(--p-line); }
.stepper-btn { flex: none; width: 52px; min-height: 52px; border: 0; background: transparent; color: var(--p-text); font-size: 22px; line-height: 1; cursor: pointer; border-radius: 14px; }
.stepper-btn:hover:not(:disabled) { color: var(--label); background: color-mix(in srgb, var(--p-text) 10%, transparent); }
.stepper-btn:disabled { opacity: .45; cursor: not-allowed; }
.stepper-input { flex: 1 1 auto; min-width: 0; width: 100%; border: 0; background: transparent; color: var(--label); text-align: right; font: inherit; font-size: var(--text-title3, 20px); font-weight: var(--weight-semibold); padding: 0 2px; }
.stepper-input:focus { outline: none; }
.stepper:focus-within { box-shadow: 0 0 0 2px var(--p-win-line); }
.stepper-input.stepper-changed { color: var(--status-warning); }
.stepper-unit { flex: none; color: var(--p-text); padding: 0 6px 0 4px; font-weight: var(--weight-medium); }
.stepper-row .btn-primary { min-height: 52px; }
.btn-quiet { background: transparent; border: 1px solid var(--p-line); color: var(--label-2); }
#btn-reset { margin-top: var(--space-4); }
.cmd-note { display: flex; align-items: flex-start; gap: var(--space-2); margin-top: var(--space-3); padding: var(--space-3); border-radius: var(--r-field); border: 1px solid var(--separator); font-weight: var(--weight-medium); }
.note-ok { background: var(--status-ok-bg); color: var(--status-ok); border-color: var(--status-ok); }
.note-warn { background: var(--status-warning-bg); color: var(--status-warning); border-color: var(--status-warning); }
.note-err { background: var(--status-alarm-bg); color: var(--status-alarm); border-color: var(--status-alarm); }
.note-busy { background: var(--status-ack-bg); color: var(--status-ack); border-color: var(--status-ack); }
.note-busy .ico, .busy .ico, .card-busy .ico, .test-result .ico:first-child { animation: sv-spin 1s linear infinite; }

/* Аварии прибора */
.alarm-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.alarm-item { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; padding: var(--space-2) var(--space-3); border-radius: var(--r-field); background: var(--bg-grouped); }
.ok-line { display: flex; align-items: center; gap: var(--space-2); color: var(--status-ok); font-weight: var(--weight-medium); }
.warn-line { display: flex; align-items: center; gap: var(--space-2); color: var(--status-warning); font-weight: var(--weight-medium); }

/* График */
.sched-status { padding: var(--space-3) var(--space-4); border-radius: var(--r-field); background: var(--bg-grouped); margin-bottom: var(--space-3); }
.sched-status p:last-child { margin-bottom: 0; }
.rules { display: grid; gap: var(--space-3); margin-top: var(--space-3); }
.rule { border: 1px solid var(--separator); border-radius: 20px; padding: var(--space-3) var(--space-4); margin: 0; min-width: 0; }
.rule legend { font-weight: var(--weight-semibold); padding: 0 var(--space-1); }
.days { display: flex; flex-wrap: wrap; gap: 6px; }
.day { min-width: var(--size-target); min-height: var(--size-target); padding: 0 6px; border: 1px solid var(--separator); border-radius: 12px; background: var(--bg-elevated); color: var(--label-2); cursor: pointer; font-weight: var(--weight-semibold); }
.day[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--label-on-brand); }
.times { display: flex; gap: var(--space-3); flex-wrap: wrap; margin-top: var(--space-3); }
.times label { display: grid; gap: 2px; font-size: var(--text-footnote); color: var(--label-2); font-weight: var(--weight-semibold); }
.times .input { font-size: var(--text-headline); }
.rule-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-2); }
.form-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-3); }

/* Журнал прибора */
.jlist { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); max-height: 520px; overflow: auto; }
.jitem { padding: var(--space-2) var(--space-3); border-radius: var(--r-field); background: var(--bg-grouped); font-size: var(--text-footnote); }
.jline { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.jtime { color: var(--label-3); font-variant-numeric: tabular-nums; }
.jnote { color: var(--label-2); margin-top: 2px; overflow-wrap: anywhere; }

/* Имитация */
.sim summary { cursor: pointer; min-height: var(--size-target); display: flex; align-items: center; font-weight: var(--weight-semibold); }
.sim[open] summary { margin-bottom: var(--space-2); }
.sim-row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-2); }
.sim-k { min-width: 80px; font-weight: var(--weight-semibold); font-size: var(--text-footnote); color: var(--label-2); }
.sim-cause .select { flex: 1 1 100%; }

/* ---------- Группы ---------- */
.gtree, .gtree ul { list-style: none; margin: 0; padding: 0; }
.gtree { background: var(--bg-elevated); border: 1px solid var(--separator); border-radius: 24px; padding: var(--space-2); }
.gt-row { display: flex; align-items: center; gap: var(--space-2) var(--space-3); flex-wrap: wrap; padding: var(--space-2) var(--space-3) var(--space-2) calc(var(--space-3) + var(--depth, 0) * 24px); border-bottom: 1px solid var(--separator); }
.gtree > li:last-child > .gt-row:last-child { border-bottom: 0; }
.gt-name { display: inline-flex; align-items: center; gap: var(--space-2); min-width: 0; overflow-wrap: anywhere; }
.gt-count { font-size: var(--text-footnote); }
.gt-actions { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
@media (max-width: 600px) { .gt-row { padding-left: calc(var(--space-2) + var(--depth, 0) * 12px); } .gt-actions { margin-left: 0; } }

/* ---------- Диалоги ---------- */
.dlg { width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; border: 1px solid var(--separator); border-radius: 28px; background: var(--bg-elevated); color: var(--label); box-shadow: var(--shadow-3); }
.dlg-wide { width: min(720px, calc(100vw - 24px)); }
.dlg::backdrop { background: var(--scrim); }
.dlg-form { display: flex; flex-direction: column; max-height: calc(100vh - 26px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-4) var(--space-5) var(--space-2); }
.dlg-head h2 { margin: 0; overflow-wrap: anywhere; }
.dlg-body { padding: var(--space-2) var(--space-5); overflow: auto; }
.dlg-error { margin: 0 var(--space-5) var(--space-2); padding: var(--space-3); border-radius: var(--r-field); background: var(--status-alarm-bg); color: var(--status-alarm); font-weight: var(--weight-medium); }
.dlg-foot { display: flex; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap; padding: var(--space-3) var(--space-5) var(--space-4); border-top: 1px solid var(--separator); }
.dlg-text { font-size: var(--text-body); }
.step { border: 1px solid var(--separator); border-radius: 20px; padding: var(--space-3) var(--space-4); margin: 0 0 var(--space-3); min-width: 0; }
.step legend { display: flex; align-items: center; gap: var(--space-2); font-weight: var(--weight-semibold); padding: 0 var(--space-1); }
.step-n { display: inline-grid; place-content: center; width: 26px; height: 26px; border-radius: 50%; background: var(--brand); color: var(--label-on-brand); font-size: var(--text-footnote); }
.test-result { display: flex; align-items: flex-start; gap: var(--space-2); margin-top: var(--space-3); }
.test-result:empty { display: none; }
.test-result.note-ok, .test-result.note-err { padding: var(--space-3); border-radius: var(--r-field); border: 1px solid; }
@media (max-width: 600px) {
  .dlg { border-radius: 20px; }
  .dlg-head, .dlg-body, .dlg-foot { padding-left: var(--space-4); padding-right: var(--space-4); }
  .dlg-foot .btn { flex: 1 1 auto; }
}

/* ---------- Вход ---------- */
.login-page { background: radial-gradient(ellipse at 85% 0%, var(--brand-wash) 0, transparent 55%), var(--bg-grouped); }
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-4); padding: var(--space-6) var(--space-4); }
.login-logo { width: 96px; height: 96px; border-radius: 50%; box-shadow: var(--shadow-1); }
.login-title { color: var(--brand-text); font: 400 var(--text-title1)/1.2 var(--font-display); text-align: center; }
.login-card { width: min(440px, 100%); padding: var(--space-5); background: var(--brand-strong); border-radius: var(--r-panel); box-shadow: var(--shadow-2); display: grid; gap: var(--space-2); color: var(--label-on-brand); }
.login-card h2 { text-align: center; color: var(--label-on-brand); margin: 0 0 var(--space-2); }
.login-label { font-size: var(--text-footnote); font-weight: var(--weight-semibold); color: var(--label-on-brand-2); }
.login-card input { width: 100%; height: 56px; padding: 0 var(--space-4); border: 1px solid var(--label-on-brand-2); border-radius: var(--r-capsule); background: rgba(255, 255, 255, 0.14); color: var(--label-on-brand); font-size: var(--text-body); }
.login-card :focus-visible { outline-color: #fff; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 60px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: var(--size-target); height: var(--size-target); border: 0; border-radius: 50%; background: transparent; cursor: pointer; display: grid; place-content: center; }
.pw-toggle img { filter: brightness(0) invert(1); }
.pw-toggle[aria-pressed="true"] { background: rgba(255, 255, 255, 0.2); }
.login-submit { height: 56px; margin-top: var(--space-2); border: 0; border-radius: var(--r-capsule); background: var(--bg-elevated); color: var(--brand-text); font-weight: var(--weight-semibold); font-size: var(--text-headline); cursor: pointer; }
.login-submit:hover:not(:disabled) { background: var(--bg-sunken); }
.login-submit:disabled { opacity: .7; }
.login-error { margin: var(--space-2) 0 0; padding: var(--space-3); border-radius: var(--r-field); background: var(--bg-elevated); color: var(--status-alarm); font-weight: var(--weight-semibold); }
.login-foot { color: var(--label-3); font-size: var(--text-footnote); text-align: center; }
@media (max-width: 480px) {
  .login-title { font-size: var(--text-title2); }
  .login-card { padding: var(--space-4); }
}
