:root {
  color-scheme: dark;
  --bg: #17181b;
  --bg-elev: #1d1e22;
  --panel: #222327;
  --panel2: #2a2b30;
  --panel3: #333439;
  --surface-hover: rgba(255, 255, 255, .06);
  --border: #38393e;
  --border-soft: #2c2d31;
  --border-strong: #48494e;
  --text: #f5f5f7;
  --muted: #98989d;
  --muted-2: #6e6e73;
  --tab-active-text: #f5f5f7;
  --accent: #0a84ff;
  --accent-2: #409cff;
  --accent-hover: #2492ff;
  --accent-dim: rgba(10, 132, 255, 0.16);
  --green: #30d158;
  --red: #ff453a;
  --amber: #ffd60a;
  --amber-text: #ffd60a;
  --radius: 12px;
  --radius-sm: 7px;
  --radius-lg: 18px;
  --sidebar-w: 312px;
  --shadow-1: 0 1px 1px rgba(0, 0, 0, .18), 0 2px 8px rgba(0, 0, 0, .14);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, .2), 0 12px 32px rgba(0, 0, 0, .28);
  --shadow-3: 0 4px 10px rgba(0, 0, 0, .22), 0 24px 70px rgba(0, 0, 0, .45);
  --shadow-glow: 0 0 0 3px rgba(10, 132, 255, .3);
  --ring: 0 0 0 3px rgba(10, 132, 255, .32);
  --selection-bg: rgba(10, 132, 255, .4);
  --term-bg: #1b1c1f;
  --term-fg-soft: #d6d6da;
  --desktop-bg: #101113;
  --toolbar-bg: rgba(255, 255, 255, .028);
  --footer-bg: rgba(255, 255, 255, .03);
  --kbd-bg: rgba(255, 255, 255, .07);
  --kbd-border: rgba(255, 255, 255, .16);
  --dot-off: #5a5b60;
  --inset-highlight: rgba(255, 255, 255, .04);
  --toast-bg: rgba(40, 41, 46, .78);
  --overlay-bg: rgba(0, 0, 0, .42);
  --login-card-bg: rgba(34, 35, 39, .8);
  --card-border-soft: rgba(255, 255, 255, .1);
  --scrollbar-thumb: #4a4b50;
  --scrollbar-thumb-hover: #5c5d62;
  --seg-track: rgba(118, 118, 128, .24);
  --seg-thumb: #636368;
  --icon-dim: rgba(255, 255, 255, .55);
}

/* ---------- Светлая тема ---------- */

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f5f7;
  --bg-elev: #ffffff;
  --panel: #ffffff;
  --panel2: #f2f2f5;
  --panel3: #e8e8ec;
  --surface-hover: rgba(0, 0, 0, .05);
  --border: #d9d9de;
  --border-soft: #e3e3e8;
  --border-strong: #c2c2c8;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --muted-2: #98989d;
  --tab-active-text: #1d1d1f;
  --accent: #0071e3;
  --accent-2: #2e8bff;
  --accent-hover: #0077ed;
  --accent-dim: rgba(0, 113, 227, 0.1);
  --green: #34c759;
  --red: #ff3b30;
  --amber: #ff9500;
  --amber-text: #b25000;
  --shadow-1: 0 1px 1px rgba(0, 0, 0, .04), 0 2px 10px rgba(0, 0, 0, .06);
  --shadow-2: 0 2px 8px rgba(0, 0, 0, .06), 0 14px 36px rgba(0, 0, 0, .12);
  --shadow-3: 0 4px 12px rgba(0, 0, 0, .08), 0 28px 70px rgba(0, 0, 0, .2);
  --shadow-glow: 0 0 0 3px rgba(0, 113, 227, .25);
  --ring: 0 0 0 3px rgba(0, 113, 227, .25);
  --selection-bg: rgba(0, 113, 227, .25);
  --term-bg: #ffffff;
  --term-fg-soft: #3a3a3e;
  --desktop-bg: #e8e8ed;
  --toolbar-bg: rgba(0, 0, 0, .025);
  --footer-bg: rgba(0, 0, 0, .03);
  --kbd-bg: rgba(0, 0, 0, .05);
  --kbd-border: rgba(0, 0, 0, .14);
  --dot-off: #c7c7cc;
  --inset-highlight: rgba(255, 255, 255, .7);
  --toast-bg: rgba(255, 255, 255, .88);
  --overlay-bg: rgba(0, 0, 0, .3);
  --login-card-bg: rgba(255, 255, 255, .85);
  --card-border-soft: rgba(0, 0, 0, .07);
  --scrollbar-thumb: #c6c6cb;
  --scrollbar-thumb-hover: #aeaeB4;
  --seg-track: rgba(120, 120, 128, .16);
  --seg-thumb: #ffffff;
  --icon-dim: rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Segoe UI Variable", "Segoe UI", system-ui, Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--selection-bg); }

.mono { font-family: "SF Mono", ui-monospace, "Cascadia Code", "Consolas", monospace; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

#app { display: flex; height: 100vh; position: relative; z-index: 1; }

/* SVG-иконки (SF Symbols-подобные) */
.icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  vertical-align: -2px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon.solid { fill: currentColor; stroke: none; }
.icon.lg { width: 18px; height: 18px; }

/* ---------- Sidebar ---------- */

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 14px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  color: #fff;
}

.brand-title { font-size: 15.5px; font-weight: 650; letter-spacing: .1px; }
.brand-sub { font-size: 12px; color: var(--muted); }

.filters { padding: 4px 12px 12px; display: flex; flex-direction: column; gap: 8px; }

/* Теги-фильтры групп (мультивыбор, как метки) */
.group-chips { display: flex; flex-wrap: wrap; gap: 5px; max-height: 92px; overflow-y: auto; }
.group-chips:empty { display: none; }
.gchip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px;
  border-radius: 980px;
  border: none;
  background: var(--seg-track);
  color: var(--text);
  font-size: 11.5px; line-height: 1.4;
  font-weight: 590;
  cursor: pointer;
  user-select: none;
  transition: background .15s ease, color .15s ease, transform .1s ease;
}
.gchip:hover { background: var(--surface-hover); }
.gchip:active { transform: scale(.96); }
.gchip.active { background: var(--c, var(--accent)); color: #fff; }
.gchip.active .gchip-dot { background: #fff !important; }
.gchip-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

input[type="search"], input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input[type="search"]:focus, input[type="text"]:focus, input[type="password"]:focus,
select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--ring);
}
input[type="search"] { border-radius: 980px; padding-left: 14px; }
select { cursor: pointer; }

.device-list { flex: 1; overflow-y: auto; padding: 2px 10px 10px; }

.device-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: none;
  user-select: none;
  transition: background .12s ease;
}
.device-row:hover { background: var(--surface-hover); }
.device-row:focus-visible { outline: none; box-shadow: var(--ring); }
.device-row.selected { background: var(--accent); }
.device-row.selected .dev-item-name,
.device-row.selected .dev-item-sub { color: #fff; }
.device-row.selected .dot { box-shadow: 0 0 0 2px rgba(255, 255, 255, .5); }
.device-row.offline { opacity: .5; }
.device-row.offline:hover { opacity: .85; }

.dev-item-text { flex: 1; min-width: 0; }
.dev-item-name { font-size: 12.5px; font-weight: 510; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dev-item-sub { font-size: 10.5px; line-height: 1.3; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); display: inline-block; flex-shrink: 0; }
.dot.on { background: var(--green); }
.dot.off { background: var(--dot-off); }

.sidebar-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-soft);
  font-size: 12px;
  background: var(--footer-bg);
}

.list-empty { text-align: center; color: var(--muted); padding: 34px 10px; font-size: 13px; }

.group-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 10px 4px;
  font-size: 11px;
  font-weight: 590;
  color: var(--muted);
  user-select: none;
}
.group-head .cnt { margin-left: auto; font-weight: 400; color: var(--muted-2); }

/* ---------- Main ---------- */

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; z-index: 1; }

.empty {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px;
  color: var(--muted);
}
.empty-icon { color: var(--muted-2); }
.empty-title { font-size: 21px; font-weight: 650; color: var(--text); letter-spacing: .2px; }
.empty-sub { font-size: 13px; max-width: 340px; text-align: center; }

#devicePanel { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ---------- Buttons ---------- */
/* Стиль macOS: обычный регистр, вес 590, капсулы/скругления, hover — лёгкое
   затемнение, нажатие — лёгкое сжатие (scale), без uppercase и сдвигов */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--panel3);
  color: var(--text);
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 15px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 510;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease, transform .08s ease, box-shadow .15s ease;
}
.btn:hover { background: color-mix(in srgb, var(--panel3), #000 14%); }
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 590;
  border-radius: 980px;
  padding: 8px 17px;
}
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-hover); }
.btn.danger:hover { color: var(--red); background: var(--surface-hover); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:disabled:active { transform: none; }

/* Шпаргалки быстрых клавиш на кнопках — key-cap */
.btn kbd {
  font-family: "SF Mono", ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 10px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 5px;
  background: var(--kbd-bg);
  box-shadow: 0 1px 0 var(--kbd-border);
  color: inherit;
  opacity: .8;
  margin-left: 4px;
  vertical-align: 1px;
  white-space: nowrap;
}
.btn.primary kbd { color: rgba(255, 255, 255, .92); background: rgba(255, 255, 255, .18); box-shadow: 0 1px 0 rgba(0, 0, 0, .18); }
.btn.ghost kbd { color: var(--muted); }
.btn.ghost:hover kbd { color: var(--text); }
.pane-head .btn kbd { font-size: 9px; padding: 2px 5px; margin-left: 3px; }

/* ---------- Tabs (сегмент-контрол macOS) ---------- */

.tabs {
  display: flex;
  gap: 2px;
  background: var(--seg-track);
  border-radius: 980px;
  padding: 3px;
  margin: 10px 14px 6px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent;
  border: none;
  color: var(--text);
  padding: 7px 16px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 510;
  cursor: pointer;
  border-radius: 980px;
  flex-shrink: 0;
  white-space: nowrap;
  transition: background .15s ease, box-shadow .15s ease, color .15s ease;
}
.tab:hover { background: var(--surface-hover); }
.tab.active {
  background: var(--seg-thumb);
  color: var(--tab-active-text);
  font-weight: 590;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18), 0 2px 7px rgba(0, 0, 0, .1);
}

.tabpane { flex: 1; display: none; flex-direction: column; min-height: 0; }
.tabpane.active { display: flex; }

/* ---------- Terminal ---------- */

#tab-terminal { padding: 8px 12px 12px; }

.term-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 10px;
  flex-wrap: wrap;
}
.term-toolbar .btn { padding: 5px 11px; font-size: 12.5px; }
.term-status { font-size: 12px; margin-left: auto; white-space: nowrap; }
.term-toolbar #btnTermReconnect { margin-left: 0; }

#termWrap {
  flex: 1;
  border: none;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--term-bg);
  box-shadow: var(--shadow-1);
}
#termWrap .xterm { height: 100%; padding: 8px; }
/* В стоковом xterm.css вьюпорт всегда чёрный — в светлой теме это даёт чёрную рамку */
#termWrap .xterm .xterm-viewport { background-color: transparent; }
.term-msg {
  display: flex; align-items: center; justify-content: center;
  height: 100%;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- Files ---------- */

.file-list { flex: 1; overflow-y: auto; padding: 8px 14px; }

.file-row {
  display: flex; align-items: center; gap: 12px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s ease;
}
.file-row:hover { background: var(--surface-hover); }
.file-row.selected { background: var(--accent-dim); }
.file-icon { width: 20px; text-align: center; flex-shrink: 0; color: var(--accent); }
.file-icon .icon { stroke-width: 1.5; }
.file-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { color: var(--muted); font-size: 12px; width: 90px; text-align: right; flex-shrink: 0; }
.file-date { color: var(--muted); font-size: 12px; width: 150px; text-align: right; flex-shrink: 0; }
.files-note { color: var(--muted); text-align: center; padding: 44px; font-size: 13px; }

/* ---------- Files: панель ---------- */

.files-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--toolbar-bg);
  flex-wrap: wrap;
}
.files-toolbar .btn { padding: 6px 12px; font-size: 12.5px; }
.tb-sep { width: 1px; height: 22px; background: var(--border); margin: 0 2px; }
.fs-status { margin-left: auto; font-size: 12px; white-space: nowrap; }

/* Индикатор передачи (скачивание/загрузка) */
.fs-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px 0;
}
.fs-progress-bar {
  flex: 1;
  height: 6px;
  border-radius: 980px;
  background: var(--seg-track);
  overflow: hidden;
}
.fs-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 980px;
  background: var(--accent);
  transition: width .18s ease, background .2s ease;
}
.fs-progress-text { font-size: 12px; white-space: nowrap; }
.fs-progress.done .fs-progress-fill { background: var(--green); }
.fs-progress.indeterminate .fs-progress-fill {
  width: 32% !important;
  animation: fs-indeterminate 1.1s ease-in-out infinite;
}
@keyframes fs-indeterminate {
  0% { margin-left: -32%; }
  100% { margin-left: 100%; }
}

.files-panes {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  padding: 10px 14px 14px;
  min-height: 0;
}

.file-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--bg-elev);
  border: none;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-1);
  transition: box-shadow .15s ease;
}
.file-pane.dragover {
  box-shadow: var(--shadow-glow), var(--shadow-1);
}

.pane-head {
  display: flex; align-items: center; gap: 6px;
  padding: 9px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--toolbar-bg);
}
.pane-head .btn { padding: 6px 10px; }
.pane-path { flex: 1; font-size: 12px; padding: 7px 10px; min-width: 0; }

.pane-cols {
  display: flex; align-items: center; gap: 12px;
  padding: 7px 12px;
  font-size: 11px;
  font-weight: 590;
  border-bottom: 1px solid var(--border-soft);
  user-select: none;
}
.pane-cols [data-sort] { cursor: pointer; white-space: nowrap; }
.pane-cols [data-sort]:hover { color: var(--text); }

.pane-list { flex: 1; overflow-y: auto; padding: 6px 8px; }
.pane-list .file-row { padding: 6px 10px; }

.pane-foot {
  padding: 7px 12px;
  font-size: 11.5px;
  border-top: 1px solid var(--border-soft);
  background: var(--footer-bg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- Commands ---------- */

#tab-cmd { padding: 14px 20px; gap: 10px; }
#cmdInput { min-height: 90px; resize: vertical; font-family: "SF Mono", ui-monospace, "Cascadia Code", "Consolas", monospace; }
.row { display: flex; gap: 8px; }
.cmd-out {
  flex: 1;
  background: var(--term-bg);
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--term-fg-soft);
  box-shadow: var(--shadow-1);
}

/* ---------- Power ---------- */

#tab-power { padding: 18px 20px; gap: 16px; overflow-y: auto; }

.power-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.power-btn {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: var(--bg-elev);
  border: none;
  border-radius: var(--radius);
  color: var(--text);
  padding: 22px 10px;
  font-size: 13px;
  font-weight: 510;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: background .15s ease, transform .08s ease, box-shadow .15s ease;
}
.power-btn .icon { width: 24px; height: 24px; stroke-width: 1.5; margin-bottom: 2px; }
.power-btn:hover { background: var(--surface-hover); box-shadow: var(--shadow-2); }
.power-btn:active { transform: scale(.97); }
.power-btn.red .icon { color: var(--red); }
.power-btn.amber .icon { color: var(--amber); }
.power-btn.green .icon { color: var(--green); }

.panel-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.panel {
  background: var(--bg-elev);
  border: none;
  border-radius: var(--radius);
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: var(--shadow-1);
}
.panel h3 { font-size: 13.5px; font-weight: 590; letter-spacing: .1px; }

/* ---------- Info (детали устройства) ---------- */

#tab-info { padding: 14px 18px; overflow-y: auto; }
.info-head {
  display: flex;
  justify-content: flex-end;
  max-width: 900px;
  padding-bottom: 10px;
}
#infoPane { max-width: 900px; }

.info-card {
  background: var(--bg-elev);
  border: none;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-1);
}
.info-card-title {
  font-size: 13px;
  font-weight: 590;
  letter-spacing: .1px;
  color: var(--text);
  margin-bottom: 10px;
}
.info-block {
  background: var(--panel2);
  border-radius: 10px;
  padding: 11px 13px;
  margin-bottom: 8px;
}
.info-block:last-child { margin-bottom: 0; }
.info-block-title { font-weight: 590; margin-bottom: 7px; font-size: 13px; }

.kv-row {
  display: flex; gap: 12px;
  padding: 3.5px 0;
  font-size: 13px;
}
.kv-key { width: 190px; color: var(--muted); flex-shrink: 0; }
.kv-val { word-break: break-all; }

/* ---------- Desktop ---------- */

#tab-desktop { padding: 0; }

.desktop-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--border-soft);
}
.desktop-toolbar select { width: auto; padding: 7px 10px; }
.desktop-toolbar .btn { padding: 7px 12px; }
#dtInfo { margin-left: auto; font-size: 12px; }

.desktop-scroll {
  flex: 1;
  overflow: auto;
  background: var(--desktop-bg);
  display: flex;
}

.desktop-stage {
  margin: auto;
  padding: 10px;
}

#dtCanvas {
  display: block;
  background: var(--term-bg);
  border: none;
  border-radius: 8px;
  outline: none;
  width: auto;
  height: auto;
  box-shadow: var(--shadow-2);
}
#dtCanvas:focus { box-shadow: var(--shadow-glow), var(--shadow-2); }

/* «По ширине»: размер канваса считает applyDesktopScale() по фактическому
   контейнеру (CSS-вариант с 100vh-130px терял 130px в полном экране) */
#dtCanvas.scale-one { width: auto; height: auto; }

/* Полный экран: без рамок — канвас вплотную к краям дисплея */
#dtScroll:fullscreen #dtStage { padding: 0; }
#dtScroll:fullscreen #dtCanvas { border-radius: 0; }

.desktop-msg {
  position: absolute;
  left: 0; right: 0; top: 0;
  padding: 14px;
  text-align: center;
  font-size: 13px;
  pointer-events: none;
}
.desktop-stage { position: relative; }
.desktop-msg.hidden-msg { display: none; }

/* Статус поверх изображения рабочего стола: белый текст с тёмной обводкой —
   читается на любом фоне (обои, светлые и тёмные окна). Обводка красится
   позади заливки (paint-order), иначе толстый stroke съедает букву. */
.desktop-msg, .grp-msg {
  color: #fff;
  font-weight: 590;
  paint-order: stroke fill;
  -webkit-text-stroke: 2px rgba(10, 12, 16, .85);
  text-shadow: 0 1px 4px rgba(0, 0, 0, .45);
}
/* Без paint-order обводка шла бы поверх заливки — заменяем её контуром из теней */
@supports not (paint-order: stroke fill) {
  .desktop-msg, .grp-msg {
    -webkit-text-stroke: 0;
    text-shadow:
      -1px -1px 0 rgba(10, 12, 16, .85), 1px -1px 0 rgba(10, 12, 16, .85),
      -1px 1px 0 rgba(10, 12, 16, .85), 1px 1px 0 rgba(10, 12, 16, .85),
      0 0 8px rgba(0, 0, 0, .6);
  }
}

/* Индикатор скорости обновления экрана */
.dt-fps {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 980px;
  background: var(--seg-track);
  color: var(--muted);
  white-space: nowrap;
}
.dt-fps.live { color: var(--green); }

/* Режим «только просмотр» на кнопке — янтарный */
.btn.view-on {
  background: var(--amber);
  color: #1d1d1f;
}
.btn.view-on:hover { background: color-mix(in srgb, var(--amber), #000 10%); }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
}
.modal-card {
  width: 390px;
  max-width: calc(100vw - 40px);
  background: var(--login-card-bg);
  backdrop-filter: blur(32px);
  -webkit-backdrop-filter: blur(32px);
  border: 1px solid var(--card-border-soft);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-3);
  animation: cardin .24s cubic-bezier(.21, 1.02, .73, 1);
}
.modal-title { font-size: 15px; font-weight: 590; }
.modal-text {
  font-size: 13px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}
.modal-text.hidden, #modalInput.hidden { display: none; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.btn.danger-solid {
  background: var(--red);
  border-color: transparent;
  color: #fff;
}
.btn.danger-solid:hover { background: color-mix(in srgb, var(--red), #000 12%); }

/* ---------- Connection banner ---------- */

.conn-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 90;
  padding: 7px 14px;
  text-align: center;
  font-size: 12.5px;
  font-weight: 510;
  background: rgba(255, 214, 10, .95);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: #1d1d1f;
  box-shadow: var(--shadow-1);
}
.conn-banner.hidden { display: none; }

/* ---------- Tabs help button ---------- */

.tab-help { margin-left: auto; padding: 5px 12px; font-size: 13px; align-self: center; }

/* ---------- Desktop view-only badge ---------- */

.dt-viewbadge {
  position: absolute;
  top: 8px; left: 8px;
  padding: 4px 11px;
  border-radius: 980px;
  font-size: 11.5px;
  font-weight: 510;
  background: rgba(255, 214, 10, .16);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--amber-text);
  pointer-events: none;
  z-index: 5;
}
.dt-viewbadge.hidden { display: none; }

/* ---------- Групповые рабочие столы (мультидесктоп) ---------- */

#groupPanel { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.group-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--border-soft);
}
#grpStatus { margin-left: auto; font-size: 12px; }

.group-grid {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 12px;
  align-content: start;
}

.grp-tile {
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}

.grp-head {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--toolbar-bg);
}
.grp-name { font-size: 12.5px; font-weight: 590; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grp-btn { padding: 3px 9px; font-size: 11px; }
.grp-disc { margin-left: auto; }

.grp-body {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  height: 230px;
  background: var(--desktop-bg);
}
.grp-body canvas { max-width: 100%; max-height: 100%; background: var(--term-bg); outline: none; }
.grp-body canvas:focus { box-shadow: var(--ring); }
.grp-msg {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px;
  pointer-events: none;
}
.grp-msg.hidden { display: none; }

.group-dt-btn { width: 100%; }

/* ---------- Toasts ---------- */

#toasts {
  position: fixed;
  right: 18px; bottom: 18px;
  display: flex; flex-direction: column; gap: 9px;
  z-index: 100;
}
.toast {
  background: var(--toast-bg);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border: 1px solid var(--card-border-soft);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow-3);
  animation: slidein .24s cubic-bezier(.21, 1.02, .73, 1);
  max-width: 380px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}
.toast > span { flex: 1; word-break: break-word; }
.toast-x {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}
.toast-x:hover { color: var(--text); }
.toast.err { border-color: rgba(255, 69, 58, .5); }
.toast.ok { border-color: rgba(48, 209, 88, .5); }
@keyframes slidein { from { transform: translateX(30px) scale(.97); opacity: 0; } }

/* ---------- Login ---------- */

.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.login-card {
  width: 390px;
  max-width: calc(100vw - 40px);
  background: var(--login-card-bg);
  backdrop-filter: blur(32px);
  -webkit-backdrop-filter: blur(32px);
  border: 1px solid var(--card-border-soft);
  border-radius: var(--radius-lg);
  padding: 36px 30px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-3);
  animation: cardin .3s cubic-bezier(.21, 1.02, .73, 1);
}
@keyframes cardin { from { transform: translateY(12px); opacity: 0; } }

.login-logo {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 28px;
  color: #fff;
}

.login-title { font-size: 21px; font-weight: 700; margin-top: 10px; letter-spacing: .2px; }
.login-sub { font-size: 13px; color: var(--muted); margin: -6px 0 8px; }

.login-card input[type="text"], .login-card input[type="password"] {
  background: var(--panel2);
}

.login-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.login-check input { width: auto; accent-color: var(--accent); }

.btn.wide { width: 100%; padding: 12px; font-size: 14px; margin-top: 4px; }

.login-error {
  font-size: 12.5px;
  color: var(--red);
  min-height: 16px;
  white-space: pre-wrap;
  word-break: break-word;
}

.btn.theme-btn {
  margin-left: auto;
  padding: 4px 9px;
  font-size: 13px;
  line-height: 1;
}

/* Переключатель темы на странице входа (там сайдбар скрыт оверлеем) */
#btnThemeLogin {
  position: fixed;
  top: 16px;
  right: 16px;
  margin-left: 0;
}

/* Переключатель языка на странице входа — в стиле кнопки темы */
.lang-switch {
  position: fixed;
  top: 16px;
  right: 60px;
  display: flex;
  gap: 3px;
  z-index: 210;
}
.lang-btn {
  padding: 4px 9px;
  font-size: 13px;
  line-height: 1;
  color: var(--muted);
}
.lang-btn:hover { color: var(--text); }
.lang-btn.active { color: var(--text); background: var(--surface-hover); }

.btn.logout {
  margin-left: 0;
  padding: 4px 11px;
  font-size: 12px;
  color: var(--muted);
}
.btn.logout:hover { color: var(--red); }

/* ---------- Scrollbars ---------- */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border: 2px solid transparent;
  background-clip: padding-box;
  border-radius: 980px;
}
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent; }
/* ============================================================
   Мобильная ветка: список устройств на весь экран + полноэкранный
   рабочий стол в горизонтальной ориентации (двойной клик).
   Включается классом body.mobile-ui.
   ============================================================ */

/* Главный экран: сайдбар занимает всё пространство, панель вкладок скрыта */
body.mobile-ui #sidebar {
  width: 100%;
  min-width: 0;
  border-right: none;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
/* main не скрываем целиком — в нём живёт полноэкранный #mobileFs;
   прячем только его панели-дети */
body.mobile-ui #main > #emptyState,
body.mobile-ui #main > #devicePanel,
body.mobile-ui #main > #groupPanel,
body.mobile-ui .desktop-toolbar,
body.mobile-ui .tabs { display: none !important; }
body.mobile-ui .group-dt-btn { display: none !important; }
body.mobile-ui #deviceList { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* Крупные тапы по строкам устройств на сенсорном экране */
body.mobile-ui .device-row {
  padding: 14px 16px;
  margin: 0 8px;
  border-radius: var(--radius);
  min-height: 56px;
}
body.mobile-ui .device-row .dev-item-name { font-size: 16px; font-weight: 590; }
body.mobile-ui .device-row .dev-item-sub { font-size: 12.5px; }
body.mobile-ui .group-chips { max-height: none; padding-bottom: 2px; }
body.mobile-ui .gchip { padding: 7px 14px; font-size: 13px; }
body.mobile-ui #search {
  height: 42px;
  font-size: 16px; /* 16px+ — iOS не зумит поле при фокусе */
}
body.mobile-ui .sidebar-footer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }

/* ---------- Полноэкранный рабочий стол (mfs) ---------- */

.mobile-fs {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--desktop-bg);
  display: flex;
  flex-direction: column;
}
.mobile-fs.hidden { display: none !important; }

/* Компактный полупрозрачный тулбар поверх экрана */
.mfs-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 310;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: linear-gradient(rgba(0,0,0,.55), rgba(0,0,0,0));
  transition: opacity .25s ease;
  pointer-events: none;
}
.mfs-top > * { pointer-events: auto; }
.mfs-top.hidden-top { opacity: 0; pointer-events: none; }
.mfs-top.hidden-top > * { pointer-events: none; }
.mfs-name {
  font-size: 13px;
  font-weight: 590;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 26vw;
}
.mfs-top-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.mfs-btn {
  color: #fff;
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.14);
  min-width: 40px;
  min-height: 40px;
  padding: 6px 10px;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.mfs-btn[aria-pressed="true"] { background: var(--accent); border-color: transparent; color: #fff; }
.mfs-select {
  min-height: 40px;
  max-width: 118px;
  padding: 6px 8px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.35);
  color: #fff;
}
.mfs-select option { color: var(--text); background: var(--panel); }
.mfs-fps {
  font-size: 11px;
  color: rgba(255,255,255,.85);
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
  white-space: nowrap;
}

/* Экран: растягивается на весь фиксированный контейнер */
.mfs-scroll {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--desktop-bg);
}
.mfs-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}
.mfs-stage canvas {
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  outline: none;
}
/* в горизонтальной ориентации резерв под нижнюю панель спецклавиш */
@media (orientation: landscape) {
  body.mobile-ui .mfs-stage.has-kbdbar { padding-bottom: 46px; }
  body.mobile-ui .mfs-stage.has-kbdbar canvas {
    max-height: calc(100% - 46px);
  }
}

.mfs-kbdbar {
  position: absolute;
  left: 0; right: 0;
  bottom: 46px;
  z-index: 320;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border-soft);
}
.mfs-kbdbar input {
  flex: 1;
  height: 42px;
  font-size: 16px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
}

/* Панель спецклавиш снизу (только в горизонтальной ориентации) */
.mfs-toolbar {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  z-index: 315;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 8px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.55));
  pointer-events: none;
}
.mfs-toolbar > * { pointer-events: auto; }
@media (orientation: landscape) {
  .mfs-toolbar { display: flex; }
}

/* Двойной тап по строке устройства открывает mfs — hint-курсор не нужен,
   но выделяем активную строку ярче */
body.mobile-ui .device-row.selected {
  background: var(--accent-dim);
}

/* Уважение к reduced-motion в мобильной ветке */
@media (prefers-reduced-motion: reduce) {
  .mfs-top { transition: none; }
  body.mobile-ui .device-row,
  body.mobile-ui .gchip { transition: none; }
}
