/* ControlDesk — компоненты и раскладка. Только токены из tokens.css, никаких «случайных» значений. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs-m)/var(--lh-body) var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3, .head { font-family: var(--font-head); line-height: var(--lh-tight); letter-spacing: -0.01em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-2); }
.mono { font-family: var(--font-mono); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-s); }

/* ---------- иконки ---------- */
.ico { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.ico-s { width: 20px; height: 20px; }
.ico-l { width: 32px; height: 32px; }

/* ---------- раскладка приложения ---------- */
#app {
  position: fixed; inset: 0;
  height: var(--app-h);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "main" "tabs";
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  background: var(--bg);
}

#topbar {
  grid-area: top;
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  min-height: 52px;
  padding: calc(var(--safe-top) + var(--sp-2)) var(--sp-4) var(--sp-2);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.pc { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; min-height: var(--touch); }
.pc-name { font-family: var(--font-head); font-weight: 700; font-size: var(--fs-l); min-width: 0; background: none; border: 0; padding: 0; text-align: left; }

.chip {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  min-height: 32px; padding: 0 var(--sp-3);
  border-radius: var(--r-pill);
  font-size: var(--fs-s); font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2);
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
#app[data-conn="ready"] .chip { background: var(--accent-soft); color: var(--accent); }
#app[data-conn="connecting"] .chip, #app[data-conn="checking"] .chip, #app[data-conn="reconnecting"] .chip { background: var(--warn-soft); color: var(--warn); }
#app[data-conn="connecting"] .chip::before, #app[data-conn="checking"] .chip::before, #app[data-conn="reconnecting"] .chip::before { animation: pulse 1.1s ease-in-out infinite; }
#app[data-conn="offline"] .chip, #app[data-conn="denied"] .chip { background: var(--danger-soft); color: var(--danger); }
#app[data-conn="expired"] .chip { background: var(--warn-soft); color: var(--warn); }

#views { grid-area: main; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding: var(--sp-4); padding-bottom: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-4); }
#view-screen { padding: 0; gap: 0; overflow: hidden; }

/* нижние разделы */
#tabbar {
  grid-area: tabs;
  display: grid; grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding-bottom: var(--safe-bottom);
}
.tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 56px; padding: var(--sp-2) var(--sp-1);
  background: none; border: 0; color: var(--text-2);
  font-size: var(--fs-xs); font-weight: 600;
  transition: color var(--dur-1) var(--ease);
}
.tab[aria-selected="true"] { color: var(--accent); }
.tab[aria-selected="true"]::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
.tab:active { background: var(--surface-2); }

/* альбомная ориентация: разделы уходят в левую рейку, экран получает максимум места */
@media (orientation: landscape) and (max-height: 520px) {
  #app { grid-template-columns: 84px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "tabs top" "tabs main"; }
  #tabbar { grid-template-columns: 1fr; grid-template-rows: repeat(4, 1fr); border-top: 0; border-right: 1px solid var(--line); padding-bottom: 0; padding-top: var(--safe-top); }
  #topbar { min-height: 44px; padding-top: var(--sp-1); padding-bottom: var(--sp-1); }
  .tab[aria-selected="true"]::before { top: 30%; bottom: 30%; left: 0; right: auto; width: 3px; height: auto; border-radius: 0 3px 3px 0; }
}

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--touch); min-width: var(--touch); padding: 0 var(--sp-4);
  border-radius: var(--r-m); border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: var(--fs-s); line-height: 1.1;
  transition: transform var(--dur-1) var(--ease), background var(--dur-1) var(--ease), opacity var(--dur-1);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger-solid { background: var(--danger); color: var(--danger-ink); border-color: transparent; }
.btn-quiet { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-block { display: flex; width: 100%; }
.btn-icon { padding: 0; width: var(--touch); }
.btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.btn[aria-busy="true"] { pointer-events: none; color: transparent; position: relative; }
.btn[aria-busy="true"]::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--text-2); border-top-color: var(--accent); animation: spin 0.7s linear infinite; }
.btn-primary[aria-busy="true"]::after { border-color: color-mix(in srgb, var(--accent-ink) 40%, transparent); border-top-color: var(--accent-ink); }
@media (hover: hover) { .btn:hover { background: color-mix(in srgb, var(--surface-2) 80%, var(--text)); } .btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, white); } }

/* ---------- карточки и списки ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); }
.card-title { display: flex; align-items: center; gap: var(--sp-2); font-family: var(--font-head); font-weight: 700; font-size: var(--fs-m); }
.card-title .ico { color: var(--accent); }
.card-title .grow { flex: 1; min-width: 0; }
.card-danger { border-color: color-mix(in srgb, var(--danger) 38%, var(--line)); background: color-mix(in srgb, var(--danger) 5%, var(--surface)); }
.card-danger .card-title .ico { color: var(--danger); }
.card-note { font-size: var(--fs-s); color: var(--text-2); }

.list { display: flex; flex-direction: column; }
.item {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--sp-3);
  min-height: 56px; padding: var(--sp-2) var(--sp-1);
  background: none; border: 0; border-top: 1px solid var(--line); text-align: left; width: 100%;
  touch-action: manipulation;
}
.list > .item:first-child { border-top: 0; }
.item:active { background: var(--surface-2); }
.item .ico { color: var(--text-2); }
.item-main { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.item-title { font-size: var(--fs-m); font-weight: 500; }
.item-sub { font-size: var(--fs-s); color: var(--text-2); }
.item-trail { display: flex; align-items: center; gap: var(--sp-1); color: var(--text-2); }
.item[data-kind="dir"] .ico:first-child { color: var(--accent); }

/* строка со своей основной областью нажатия и вложенными кнопками (окна) */
.item-win { grid-template-columns: auto minmax(0, 1fr) auto; padding: 0 var(--sp-1); }
.item-win:active { background: none; }
.item-btn { display: flex; align-items: center; width: 100%; min-width: 0; min-height: var(--touch); padding: var(--sp-2) 0; background: none; border: 0; text-align: left; touch-action: manipulation; }
.item-btn:active { opacity: 0.7; }

.grid-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: var(--sp-2); }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 88px; padding: var(--sp-3) var(--sp-2);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-m);
  font-size: var(--fs-s); font-weight: 600; text-align: center; touch-action: manipulation;
}
.tile .ico { color: var(--accent); width: 28px; height: 28px; }
.tile:active { transform: scale(0.97); }
.tile[aria-busy="true"] { opacity: 0.6; pointer-events: none; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-1) var(--sp-4); font-size: var(--fs-s); }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; text-align: right; min-width: 0; overflow-wrap: anywhere; }

.row { display: flex; align-items: center; gap: var(--sp-2); }
.row-wrap { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.grow { flex: 1 1 0; min-width: 0; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-2); }

.badge { display: inline-flex; align-items: center; min-height: 20px; padding: 0 var(--sp-2); border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-2); padding: var(--sp-6) var(--sp-4); color: var(--text-2); }
.empty .ico { width: 36px; height: 36px; opacity: 0.7; }

/* ---------- поля ---------- */
.field {
  width: 100%; min-height: var(--touch); padding: 0 var(--sp-3);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-m);
  font-size: var(--fs-m); outline: none;
}
textarea.field { padding: var(--sp-3); min-height: 84px; resize: none; line-height: var(--lh-body); }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field::placeholder { color: var(--text-2); opacity: 0.8; }
select.field { appearance: none; -webkit-appearance: none; padding-right: var(--sp-5); background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }
.search { position: relative; }
.search .ico { position: absolute; left: var(--sp-3); top: 50%; translate: 0 -50%; color: var(--text-2); pointer-events: none; }
.search .field { padding-left: 44px; }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: var(--touch); background: transparent; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--line); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--line); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -11px; border-radius: 50%; background: var(--accent); border: 3px solid var(--bg); box-shadow: 0 0 0 1px var(--accent); }
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); border: 3px solid var(--bg); }

/* переключатель режимов */
.seg { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 2px; border-radius: var(--r-m); background: var(--surface-2); border: 1px solid var(--line); }
.seg button { min-height: var(--touch); min-width: var(--touch); padding: 0 var(--sp-2); border: 0; border-radius: calc(var(--r-m) - 3px); background: none; color: var(--text-2); font-size: var(--fs-s); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); touch-action: manipulation; }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25); }
.seg button[aria-checked="true"] .ico { color: var(--accent); }

/* ---------- экран ПК и «рамка связи» ---------- */
.stage { flex: 1 1 0; min-height: 0; padding: var(--sp-2); display: flex; }
.link-frame {
  position: relative; flex: 1; min-width: 0; min-height: 0;
  border: 2px solid var(--frame, var(--link-idle));
  border-radius: 14px;
  background: var(--screen-bg);
  box-shadow: 0 0 0 1px transparent, 0 0 22px -8px var(--frame, transparent);
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
  overflow: hidden;
}
.link-frame[data-link="live"] { --frame: var(--link-live); }
.link-frame[data-link="wait"] { --frame: var(--link-wait); animation: frame-pulse 1.4s ease-in-out infinite; }
.link-frame[data-link="off"] { --frame: var(--link-off); }
.link-frame[data-link="idle"] { --frame: var(--link-idle); }
.screen-viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: crosshair; }
.screen-viewport img { position: absolute; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; user-select: none; -webkit-user-drag: none; will-change: transform; image-rendering: auto; }
.screen-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-3); padding: var(--sp-5); text-align: center; background: color-mix(in srgb, var(--screen-bg) 78%, transparent); color: #F3F6F4; }
.screen-overlay .muted { color: #9FB0B0; }
.screen-overlay .btn { min-width: 168px; }
.frame-badge { position: absolute; left: var(--sp-2); top: var(--sp-2); z-index: 2; display: flex; gap: var(--sp-1); pointer-events: none; }
.frame-badge .badge { background: rgba(5, 9, 11, 0.66); color: #F3F6F4; backdrop-filter: blur(6px); }
.tap-ripple { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; border: 2px solid var(--accent); pointer-events: none; animation: ripple 0.45s var(--ease) forwards; z-index: 3; }

.controls { display: flex; flex-direction: column; flex: none; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); padding: var(--sp-1) var(--sp-2); }   /* переносится: при 2+ мониторах «Старт» и настройки не уезжают за экран */

/* альбом: экран ПК занимает основную область, панели управления — колонкой справа */
@media (orientation: landscape) and (max-height: 520px) {
  #view-screen { flex-direction: row; }
  .controls { width: 216px; overflow-y: auto; padding: var(--sp-1) 0; scrollbar-width: none; }
  .controls .bar { flex-wrap: wrap; padding: var(--sp-1) var(--sp-2) var(--sp-1) 0; }
  .controls .bar .spacer { display: none; }
  .controls .bar-tools { grid-template-columns: repeat(2, 1fr); padding: var(--sp-1) var(--sp-2) var(--sp-1) 0; }
  .bar .btn:not(.btn-icon) { padding: 0 var(--sp-3); margin-left: auto; }   /* «Старт/Стоп» прижат вправо без отдельной распорки (она занимала отступ и провоцировала перенос) */
.monitor-pick { max-width: none; }
}
.bar-tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-1); padding: var(--sp-1) var(--sp-2) var(--sp-2); }
.tool { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px; padding: 4px 2px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); font-size: var(--fs-xs); font-weight: 600; color: var(--text); touch-action: manipulation; }
.tool .ico { color: var(--accent); }
.tool:active { transform: scale(0.97); }
.tool[aria-pressed="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.monitor-pick { width: auto; min-width: 96px; max-width: 34vw; }

/* полноэкранный (в т.ч. запасной, если API недоступен) */
#app.immersive { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr); grid-template-areas: "main"; padding: 0; }
#app.immersive #topbar, #app.immersive #tabbar, #app.immersive .controls { display: none; }
#app.immersive .stage { padding: 0; }
#app.immersive .link-frame { border-radius: 0; border-width: 2px; }
.immersive-tools { position: absolute; z-index: 5; top: calc(var(--safe-top) + var(--sp-2)); right: calc(var(--safe-right) + var(--sp-2)); display: none; gap: var(--sp-2); }
#app.immersive .immersive-tools { display: flex; }
.immersive-tools .btn { min-height: var(--touch); background: rgba(5, 9, 11, 0.7); color: #F3F6F4; border-color: rgba(243, 246, 244, 0.2); backdrop-filter: blur(6px); }

/* ---------- файлы ---------- */
.crumbs { display: flex; align-items: center; gap: var(--sp-1); overflow-x: auto; scrollbar-width: none; margin: 0 calc(var(--sp-4) * -1); padding: 0 var(--sp-4); flex: none; }
.crumbs::-webkit-scrollbar { display: none; }
.crumb { display: inline-flex; align-items: center; min-height: var(--touch); padding: 0 var(--sp-3); border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--line); font-size: var(--fs-s); font-weight: 600; white-space: nowrap; flex: none; }
.crumb[aria-current="page"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.crumb-sep { color: var(--text-2); flex: none; }
.files-card { padding: var(--sp-1) var(--sp-3); }

.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width var(--dur-2) linear; }
.progress[data-indeterminate] > i { width: 40%; animation: slide 1.1s ease-in-out infinite; }
.transfer { display: flex; flex-direction: column; gap: var(--sp-2); }
.transfer .row { align-items: flex-start; }

.inline-result { display: none; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-s); font-size: var(--fs-s); }
.inline-result[data-state] { display: flex; }
.inline-result[data-state="ok"] { background: var(--accent-soft); color: var(--accent); }
.inline-result[data-state="err"] { background: var(--danger-soft); color: var(--danger); }
.inline-result[data-state="busy"] { background: var(--surface-2); color: var(--text-2); }

/* ---------- шторки, тосты ---------- */
#sheet-root { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.scrim { position: absolute; inset: 0; background: var(--scrim); pointer-events: auto; animation: fade var(--dur-2) var(--ease); }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; pointer-events: auto;
  display: flex; flex-direction: column; gap: var(--sp-3);
  max-height: calc(var(--app-h) - var(--safe-top) - var(--sp-5));
  padding: var(--sp-2) var(--sp-4) calc(var(--sp-4) + var(--safe-bottom));
  padding-left: calc(var(--sp-4) + var(--safe-left)); padding-right: calc(var(--sp-4) + var(--safe-right));
  background: var(--surface); border-top: 1px solid var(--line-strong);
  border-radius: var(--r-l) var(--r-l) 0 0; box-shadow: var(--shadow);
  animation: rise var(--dur-2) var(--ease);
}
.sheet-grabber { width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); align-self: center; flex: none; }
.sheet-head { display: flex; align-items: center; gap: var(--sp-3); flex: none; }
.sheet-head h2 { font-size: var(--fs-l); flex: 1; min-width: 0; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.sheet-danger { border-top: 2px solid var(--danger); }
.sheet-dock { box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.3); }
.sheet-dock.no-scrim { pointer-events: auto; }
.confirm-icon { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--danger-soft); color: var(--danger); align-self: flex-start; }

#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--safe-bottom) + 76px); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); pointer-events: none; padding: 0 var(--sp-4); }
.toast { max-width: 100%; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-m); background: var(--surface-2); border: 1px solid var(--line-strong); box-shadow: var(--shadow); font-size: var(--fs-s); animation: rise var(--dur-2) var(--ease); }
.toast[data-kind="err"] { border-color: color-mix(in srgb, var(--danger) 50%, transparent); color: var(--text); }
.toast[data-kind="ok"] { border-color: color-mix(in srgb, var(--accent) 50%, transparent); }

/* клавиатура поверх экрана: низкая панель, клавиши — две строки с горизонтальной прокруткой */
.sheet-dock { gap: var(--sp-2); padding-top: var(--sp-1); }
.sheet-dock .sheet-grabber { display: none; }
.sheet-dock textarea.field { min-height: 64px; }
.kb-row { display: flex; gap: var(--sp-2); overflow-x: auto; scrollbar-width: none; margin: 0 calc(var(--sp-4) * -1); padding: 2px var(--sp-4); scroll-snap-type: x proximity; flex: none; }
.kb-row::-webkit-scrollbar { display: none; }
.kb-row .key { flex: none; min-width: 56px; scroll-snap-align: start; }
.key { min-height: var(--touch); padding: 0 var(--sp-3); border-radius: var(--r-m); background: var(--surface-2); border: 1px solid var(--line); font-weight: 600; font-size: var(--fs-s); touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.key:active { background: var(--accent-soft); }
.key[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* ---------- экраны состояний ---------- */
.state {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-4);
  padding: calc(var(--safe-top) + var(--sp-5)) var(--sp-5) calc(var(--safe-bottom) + var(--sp-5));
  text-align: center; background: var(--bg);
}
.state-icon { width: 84px; height: 84px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--surface); border: 2px solid var(--line-strong); color: var(--text-2); }
.state-icon .ico { width: 38px; height: 38px; }
.state[data-tone="wait"] .state-icon { border-color: var(--link-wait); color: var(--link-wait); }
.state[data-tone="off"] .state-icon { border-color: var(--link-off); color: var(--link-off); }
.state[data-tone="ok"] .state-icon { border-color: var(--link-live); color: var(--link-live); }
.state h1 { font-size: var(--fs-xl); }
.state p { max-width: 34ch; color: var(--text-2); font-size: var(--fs-m); }
.state .btn { min-width: 220px; }
.state-note { font-size: var(--fs-s); color: var(--text-2); }
.reconnect { position: absolute; left: var(--sp-3); right: var(--sp-3); top: var(--sp-3); z-index: 4; display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-m); background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 55%, transparent); font-size: var(--fs-s); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- диагностика ---------- */
.diag-log { font-family: var(--font-mono); font-size: var(--fs-xs); line-height: 1.5; color: var(--text-2); background: var(--surface-2); border-radius: var(--r-m); padding: var(--sp-3); max-height: 34vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- состояния/анимации ---------- */
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line-strong); border-top-color: var(--accent); animation: spin 0.8s linear infinite; flex: none; }
.spinner-s { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.35; } }
@keyframes frame-pulse { 50% { box-shadow: 0 0 0 1px transparent, 0 0 22px -4px var(--frame); } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
@keyframes ripple { from { transform: scale(0.4); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* узкие телефоны */
@media (max-width: 360px) {
  .view { padding: var(--sp-3); }
  .tool { font-size: 11px; }
  .tab { font-size: 11px; }   /* четыре раздела: «Приложения» должно помещаться в четверть ширины */
  .grid-tiles { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
}
