:root {
  --bg: #05080d;
  --panel: #0b121b;
  --panel-2: #101a26;
  --line: #1b2a3a;
  --text: #e6f1fb;
  --muted: #7d93a8;
  --accent: #38d6ff;
  --accent-2: #1aa6d6;
  --ok: #3ddc97;
  --warn: #ffb547;
  --bad: #ff5d6c;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button, select, input, textarea { font: inherit; color: inherit; }
button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px;
  cursor: pointer; transition: background .15s, border-color .15s, opacity .15s; }
button:hover { border-color: var(--accent-2); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: linear-gradient(180deg, #1fb8e8, #1488b4); border-color: transparent; color: #021018; font-weight: 600; }
button.ghost { background: transparent; }
button.small { padding: 6px 10px; font-size: 13px; }
button.toggle.on { background: rgba(56, 214, 255, .16); border-color: var(--accent); color: var(--accent); }
select, input:not([type=checkbox]):not([type=range]), textarea { background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; outline: none; width: 100%; }
select:focus, input:focus, textarea:focus { border-color: var(--accent-2); }
textarea { resize: vertical; }
h3 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); }
small { display: block; font-size: 12px; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; margin: 0; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; flex-wrap: wrap; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .04em; }
.brand .icon { width: 30px; height: 30px; filter: drop-shadow(0 0 6px rgba(56, 214, 255, .35)); }
.wordmark { width: min(220px, 70%); height: auto; justify-self: center; margin: 4px 0 2px; }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 30%, rgba(56, 214, 255, .10), transparent 60%); }
.login-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 28px 22px; display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card .brand { font-size: 22px; }
.login-card p { margin: 0; text-align: center; }

.app { min-height: 100%; display: flex; flex-direction: column; }
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top)); background: rgba(5, 8, 13, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.spacer { flex: 1; }
.link { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.control { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.control.mine { color: var(--ok); }

.layout { flex: 1; display: grid; grid-template-columns: 1fr; gap: 14px; padding: 14px 16px 24px; max-width: 1500px;
  width: 100%; margin: 0 auto; }
@media (min-width: 980px) { .layout { grid-template-columns: minmax(0, 1fr) 400px; align-items: start; }
  .side { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; } }

.stage { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3;
  border: 1px solid var(--line); }
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.overlays { position: absolute; pointer-events: none; }
.overlays > div { position: absolute; inset: 0; }
.overlays svg { width: 100%; height: 100%; display: block; overflow: visible; }
.stage-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.stage-info { position: absolute; left: 10px; bottom: 10px; font: 12px/1.3 ui-monospace, monospace; color: #cfe8ff;
  background: rgba(0, 0, 0, .55); padding: 4px 8px; border-radius: 8px; pointer-events: none; }
.stage-info:empty { display: none; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.toolbar-right { display: flex; gap: 8px; margin-left: auto; }
.toolbar-right select { width: auto; max-width: 240px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 6px 11px; border-radius: 999px; font-size: 13px; background: var(--panel); border: 1px solid var(--line);
  font-family: ui-monospace, monospace; }
.chip.on { border-color: var(--accent); color: var(--accent); background: rgba(56, 214, 255, .1); }
.overlay-chips { margin-top: 8px; }
.overlay-chips:empty { display: none; }
.overlay-chips::before { content: "Слои:"; color: var(--muted); font-size: 13px; align-self: center; margin-right: 4px; }

.tabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px;
  margin-bottom: 12px; overflow-x: auto; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px 10px; border-radius: 9px; white-space: nowrap; font-size: 14px; }
.tabs button.active { background: var(--panel-2); color: var(--accent); }
.tab { display: grid; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.badge { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.badge.live { color: var(--accent); border-color: var(--accent-2); }
.note { margin: 0; text-align: center; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.switch { appearance: none; width: 46px; height: 26px; border-radius: 999px; background: var(--line); position: relative;
  cursor: pointer; transition: background .2s; flex: none; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #cfe0ef; transition: transform .2s; }
.switch:checked { background: var(--accent-2); }
.switch:checked::after { transform: translateX(20px); background: #fff; }
.switch:disabled { opacity: .4; }
.say { display: grid; gap: 8px; }
.say-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.phrases { display: flex; flex-wrap: wrap; gap: 6px; }
.phrases button { font-size: 13px; padding: 6px 10px; border-radius: 999px; }
input[type=range] { width: 100%; accent-color: var(--accent); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; }
.kv > :nth-child(odd) { color: var(--muted); }
.list { display: grid; gap: 4px; font-size: 14px; }
.list .item { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.list .item:last-child { border-bottom: 0; }
.list .item .sub { margin-left: auto; color: var(--muted); font-size: 12px; }
.mono { font-family: ui-monospace, monospace; font-size: 13px; }

.stages { display: flex; flex-wrap: wrap; gap: 6px; }
.stage-chip { font-size: 12px; padding: 4px 8px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); }
.stage-chip.err { border-color: var(--bad); color: var(--bad); }
.chat { display: grid; gap: 8px; max-height: 50vh; overflow: auto; }
.msg { max-width: 88%; padding: 8px 11px; border-radius: 12px; font-size: 14px; }
.msg.user { justify-self: start; background: var(--panel-2); border: 1px solid var(--line); }
.msg.robot { justify-self: end; background: rgba(56, 214, 255, .12); border: 1px solid rgba(56, 214, 255, .35); }
.msg.robot.pending { opacity: .7; border-style: dashed; }
.msg.cut { text-decoration: line-through; opacity: .6; }
.msg .meta { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }

.owner { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.owner > summary { list-style: none; cursor: pointer; padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.owner > summary::-webkit-details-marker { display: none; }
.owner > summary .count { color: var(--muted); font-size: 12px; margin-left: auto; }
.owner-body { border-top: 1px solid var(--line); padding: 6px 14px 12px; display: grid; gap: 2px; }
.param { display: grid; grid-template-columns: 1fr minmax(120px, 44%); gap: 6px 10px; align-items: center; padding: 8px 0;
  border-bottom: 1px dashed var(--line); }
.param:last-of-type { border-bottom: 0; }
.param .name { font-family: ui-monospace, monospace; font-size: 13px; word-break: break-all; }
.param .desc { grid-column: 1 / -1; font-size: 12px; color: var(--muted); margin-top: -4px; }
.param .marks { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.mark { font-size: 11px; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.mark.changed { color: var(--warn); border-color: rgba(255, 181, 71, .5); }
.mark.saved { color: var(--ok); border-color: rgba(61, 220, 151, .5); }
.mark.restart { color: var(--accent); border-color: var(--accent-2); }
.param .marks button { margin-left: auto; }
.owner-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 8px; }
.svc { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; }
.svc > summary { cursor: pointer; padding: 10px 12px; list-style: none; display: grid; gap: 2px; }
.svc > summary::-webkit-details-marker { display: none; }
.svc-body { padding: 0 12px 12px; display: grid; gap: 8px; }
.svc pre { margin: 0; white-space: pre-wrap; word-break: break-all; font-size: 12px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px; max-height: 240px; overflow: auto; }

.toast { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; z-index: 50;
  max-width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(0, 0, 0, .5); }
.toast.bad { border-color: var(--bad); }
.icon-btn { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.btn-group { display: inline-flex; }
.btn-group > button:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }
.btn-group > button:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.btn-group > button.on, .btn-group > button:hover { position: relative; z-index: 1; }
#aec { padding: 9px 10px; font-size: 12px; font-weight: 600; letter-spacing: .06em; color: var(--muted); }
#aec.on { color: var(--accent); }
#gain { padding: 9px 10px; font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); min-width: 58px; }
#gain.on { color: var(--accent); }
.toolbar-right { position: relative; }
.gain-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; display: flex; align-items: center; gap: 10px;
  width: 280px; max-width: calc(100vw - 32px); padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); font-size: 13px; }
.gain-pop input { flex: 1; min-width: 0; }
.gain-value { min-width: 46px; text-align: right; font-variant-numeric: tabular-nums; color: var(--accent); }
@media (max-width: 520px) {
  .bar { gap: 8px 12px; }
  .toolbar-right { margin-left: 0; width: 100%; }
  .toolbar-right select { flex: 1; max-width: none; }
}

.layout > * { min-width: 0; }   /* колонки сжимаются по экрану, ряд вкладок прокручивается внутри себя */
.hint { margin: 0; font-size: 12px; }
.head-ctl { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.head-side { display: grid; gap: 12px; }
.joy { position: relative; width: 148px; height: 148px; border-radius: 50%; touch-action: none; cursor: grab;
  background: radial-gradient(circle, var(--panel-2) 0 55%, var(--bg) 56%); border: 1px solid var(--line); }
.joy::before, .joy::after { content: ""; position: absolute; background: var(--line); }
.joy::before { left: 50%; top: 12%; bottom: 12%; width: 1px; }
.joy::after { top: 50%; left: 12%; right: 12%; height: 1px; }
.joy.active { border-color: var(--accent); cursor: grabbing; }
.joy.disabled { opacity: .4; cursor: not-allowed; }
.joy-knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  background: linear-gradient(180deg, #1fb8e8, #1488b4); box-shadow: 0 0 12px rgba(56, 214, 255, .35); z-index: 1;
  pointer-events: none; }
.badge.bad { color: var(--bad); border-color: rgba(255, 93, 108, .5); }
.badge.warn { color: var(--warn); border-color: rgba(255, 181, 71, .5); }
.badge.ok { color: var(--ok); border-color: rgba(61, 220, 151, .5); }
.term { height: 52vh; overflow: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 12px; line-height: 1.45; white-space: pre-wrap; word-break: break-all; }
.term .ln { display: block; }
.term .t { color: var(--muted); margin-right: 8px; }
.term .tx { color: var(--accent); }
.term .ok { color: var(--ok); }
.term .err { color: var(--bad); }
.term .log { color: var(--muted); }
.term-form { display: flex; gap: 8px; }
.term-form button { flex: none; }
@media (max-width: 420px) { .head-ctl { grid-template-columns: 1fr; justify-items: center; } }

/* Режимы страницы и телеуправление */
.modes { display: flex; gap: 3px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.modes button, .seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-size: 14px; }
.modes button.active, .seg button.active { background: var(--panel-2); color: var(--accent); }
.seg { display: flex; gap: 2px; background: rgba(11, 18, 27, .75); border: 1px solid var(--line); border-radius: 10px; padding: 2px; }
.seg button { font-size: 13px; padding: 5px 10px; }
/* В режиме телеуправления страница ровно в экран: шапка сверху, видео занимает остаток. */
.app.tele { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
.teleop { flex: 1; display: flex; min-height: 0; }
.tele-stage { position: relative; flex: 1; background: #000; overflow: hidden; min-height: 240px;
  touch-action: none; user-select: none; -webkit-user-select: none; }
.tele-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.tele-top { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 8px; align-items: center;
  flex-wrap: wrap; z-index: 2; padding-top: env(safe-area-inset-top); }
.tele-top .badge { background: rgba(0, 0, 0, .6); }
.tele-top > button { background: rgba(11, 18, 27, .75); }
.tele-angles { font: 12px/1.3 ui-monospace, monospace; color: #cfe8ff; background: rgba(0, 0, 0, .55); padding: 4px 9px;
  border-radius: 999px; }
.tele-angles:empty { display: none; }
.tele-stick { position: absolute; bottom: max(18px, env(safe-area-inset-bottom)); display: grid; justify-items: center;
  gap: 6px; z-index: 2; }
.tele-stick.left { left: max(18px, env(safe-area-inset-left)); }
.tele-stick.right { right: max(18px, env(safe-area-inset-right)); }
.tele-stick .joy { width: min(36vmin, 200px); height: min(36vmin, 200px);
  background: radial-gradient(circle, rgba(16, 26, 38, .55) 0 55%, rgba(5, 8, 13, .35) 56%); backdrop-filter: blur(2px); }
.tele-stick .joy-knob { width: 34%; height: 34%; margin: -17% 0 0 -17%; }
.tele-label { font-size: 12px; color: var(--muted); background: rgba(0, 0, 0, .55); padding: 2px 9px; border-radius: 999px; }
.tele-keys { position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  font-size: 12px; color: var(--muted); background: rgba(0, 0, 0, .55); padding: 4px 10px; border-radius: 999px;
  white-space: nowrap; z-index: 2; }
@media (max-width: 640px) { .tele-keys { display: none; } }
