/* Пульт PISKA и mini: тёмная приборная панель (макет A из Nano Banana).
   Один акцент - сигнальный зелёный для «включено» и главных действий, янтарь - предупреждения,
   красный - только необратимое. Глубина - тонкие линии, без теней. */

:root {
  --bg: #111316;
  --panel: #181b1f;
  --raised: #1f2328;
  --press: #262b31;
  --line: #2a2f36;
  --text: #e8ebee;
  --muted: #9aa2ab;
  --faint: #6d757e;
  --on: #45d483;
  --on-ink: #0d2618;
  --on-soft: rgba(69, 212, 131, 0.13);
  --warn: #f4b13e;
  --warn-soft: rgba(244, 177, 62, 0.12);
  --danger: #ff6a5c;
  --danger-soft: rgba(255, 106, 92, 0.12);
  --off: #5b636c;
  --radius: 14px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--font);
  font-feature-settings: "tnum" 1;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
::selection { background: var(--on-soft); color: var(--text); }
:focus-visible { outline: 2px solid var(--on); outline-offset: 2px; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h2, h3, p { margin: 0; }

.sprite { display: none; }
.ico {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.ico.big { width: 36px; height: 36px; color: var(--muted); }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding:
    calc(12px + var(--tg-content-safe-area-inset-top, 0px))
    calc(12px + var(--tg-safe-area-inset-right, 0px))
    calc(24px + var(--tg-safe-area-inset-bottom, 0px))
    calc(12px + var(--tg-safe-area-inset-left, 0px));
}
.view { display: grid; gap: 10px; animation: enter 220ms var(--ease); }
.view[hidden] { display: none; }
/* Только сдвиг, без прозрачности: если анимация встанет на паузу, экран всё равно виден. */
@keyframes enter { from { transform: translateY(8px); } }

/* карточки машин и панели */
.machine, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 12px;
}
.machine { gap: 14px; }
.machine-head {
  all: unset;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "name chev" "status chev";
  row-gap: 3px;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.machine-head:focus-visible { outline: 2px solid var(--on); outline-offset: 4px; }
.machine-name { grid-area: name; font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
.machine-role { font-size: 13px; font-weight: 500; color: var(--faint); margin-left: 6px; letter-spacing: 0; }
.machine-status { grid-area: status; display: inline-flex; align-items: center; gap: 7px; font-size: 14px; color: var(--muted); }
.machine-head .chev { grid-area: chev; align-self: center; color: var(--faint); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); flex: none; }
.on .dot, .dot.on { background: var(--on); box-shadow: 0 0 0 3px var(--on-soft); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.status-on { color: var(--on); }
.status-warn { color: var(--warn); }

.machine-body { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center; }
.metrics { display: grid; gap: 8px; }
.metric { display: grid; grid-template-columns: 92px 1fr; align-items: baseline; gap: 8px; }
.metric dt { color: var(--muted); font-size: 13px; }
.metric dd { margin: 0; font-weight: 550; }
.metric .hot { color: var(--warn); }
.metric .sub { color: var(--muted); font-weight: 400; }

.meter { height: 4px; border-radius: 2px; background: var(--raised); overflow: hidden; margin-top: 6px; }
.meter i { display: block; height: 100%; width: var(--v, 0%); background: var(--on); border-radius: inherit; transition: width 400ms var(--ease); }
.meter.warn i { background: var(--warn); }
.meter.danger i { background: var(--danger); }

/* кнопка питания */
.power {
  width: 76px; height: 76px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--raised);
  border: 1px solid var(--line);
  color: var(--muted);
  transition: transform 160ms var(--ease), background 160ms, color 160ms, border-color 160ms;
}
.power .ico { width: 30px; height: 30px; stroke-width: 2; }
.power:active { transform: scale(0.95); }
.power.is-on { color: var(--on); border-color: rgba(69, 212, 131, 0.55); background: radial-gradient(circle at 50% 40%, rgba(69, 212, 131, 0.16), var(--raised) 70%); }
.power.is-off { color: var(--text); }
.power[aria-busy="true"] { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { border-color: var(--on); } }

/* плитки и кнопки */
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile, .btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 12px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 550;
  transition: background 140ms, transform 140ms var(--ease), opacity 140ms;
}
.tile { flex-direction: column; gap: 5px; min-height: 64px; font-size: 13px; color: var(--muted); }
.tile .ico { color: var(--text); }
.tile:active, .btn:active, .row.link:active { background: var(--press); transform: scale(0.98); }
.btn.primary { background: var(--on); border-color: var(--on); color: var(--on-ink); }
.btn.wide { width: 100%; min-height: 50px; font-size: 15px; }
.btn.danger, .tile.danger, .tile.danger .ico { color: var(--danger); }
.btn:disabled, .tile:disabled, .row.link:disabled { opacity: 0.45; pointer-events: none; }
[aria-busy="true"] { position: relative; pointer-events: none; }
.btn[aria-busy="true"]::after, .tile[aria-busy="true"]::after, .row[aria-busy="true"]::after, .icon-btn[aria-busy="true"]::after {
  content: ""; position: absolute; right: 10px; top: calc(50% - 7px);
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--faint); border-top-color: var(--on);
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm); color: var(--muted);
}
.icon-btn:active { background: var(--press); }
.icon-btn.accent { color: var(--on); }
.icon-btn .ico { width: 18px; height: 18px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions > .btn { flex: 1 1 0; }
.actions > .quick { flex: 1 1 100%; }
.actions.grid2 { display: grid; grid-template-columns: 1fr 1fr; }

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel h2 { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
.panel h3 { font-size: 13px; font-weight: 600; color: var(--muted); }
.with-ico { display: inline-flex; align-items: center; gap: 7px; }
.with-ico .ico { width: 16px; height: 16px; }
.hint { font-size: 13px; color: var(--faint); }
.muted { color: var(--muted); }

/* списки */
.rows { list-style: none; margin: 0; padding: 0; display: grid; }
.rows > li + li { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: 10px;
  min-height: 46px; padding: 8px 2px;
  width: 100%; background: none; border: 0; text-align: left;
}
.rows.compact .row { min-height: 34px; padding: 5px 0; font-size: 14px; }
.row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .val { color: var(--muted); font-size: 13px; white-space: nowrap; }
.row.link { border-radius: 8px; }
.row.link .chev { margin-left: auto; color: var(--faint); width: 18px; height: 18px; }
.row.link > .ico:first-child { color: var(--muted); }
.row.link.danger, .row.link.danger > .ico:first-child { color: var(--danger); }
.row-actions { display: flex; gap: 2px; margin-left: auto; }
.kill { font-size: 13px; font-weight: 550; color: var(--danger); background: var(--danger-soft); border: 0; border-radius: 8px; padding: 6px 10px; }

.out:empty { display: none; }
.out { padding: 4px 2px 12px; font-size: 14px; color: var(--muted); display: grid; gap: 6px; }
.out strong { color: var(--text); font-weight: 550; }
.out .ok { color: var(--on); }
.out .bad { color: var(--danger); }
.out .btn { justify-self: start; margin-top: 4px; }

/* датчики */
.sensors { display: grid; gap: 12px; }
.sensor { display: grid; gap: 2px; }
.sensor-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.sensor-top span:first-child { color: var(--muted); font-size: 14px; }
.sensor-top b { font-weight: 600; }
.sensor-top b small { color: var(--muted); font-weight: 400; font-size: 13px; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 3px; }
.segmented button { min-height: 38px; border: 0; border-radius: 8px; background: transparent; font-size: 14px; font-weight: 550; color: var(--muted); }
.segmented button.active { background: var(--press); color: var(--text); }
.segmented button:active { background: var(--press); }

.pill { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--raised); color: var(--muted); }
.pill.on { background: var(--on-soft); color: var(--on); }
.mc-players { font-size: 15px; }
.mc-players .muted { font-size: 13px; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; font-size: 14px; }
.switch-row .muted { font-size: 13px; }
input[role="switch"] {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 44px; height: 26px; border-radius: 13px; margin: 0;
  background: var(--press); border: 1px solid var(--line); position: relative; cursor: pointer;
  transition: background 160ms;
}
input[role="switch"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--muted); transition: transform 180ms var(--ease), background 160ms;
}
input[role="switch"]:checked { background: var(--on); border-color: var(--on); }
input[role="switch"]:checked::after { transform: translateX(18px); background: var(--on-ink); }

.chat { display: flex; gap: 6px; }
.chat input {
  flex: 1; min-width: 0; min-height: 42px; padding: 0 12px;
  background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius-sm); caret-color: var(--on);
}
.chat input::placeholder { color: var(--faint); }
.chat input:focus { outline: none; border-color: var(--on); }
.chat .icon-btn { width: 42px; height: 42px; border-color: var(--line); background: var(--raised); }

.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--warn-soft); color: var(--warn); font-size: 14px;
}
.alert p { color: var(--text); }
.alert .muted { color: #c9b089; }

.shot { margin: 0; display: grid; gap: 8px; }
.shot img { width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--line); display: block; }
.shot figcaption { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--muted); }

.crumbs { font-size: 14px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px; }
.crumbs b { color: var(--text); font-weight: 550; }
.log {
  margin: 0; max-height: 70vh; overflow: auto; padding: 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  font: 12px/1.45 var(--mono); color: #c7cdd3; white-space: pre-wrap; word-break: break-word;
}
.empty { justify-items: center; text-align: center; padding: 32px 20px; gap: 10px; }

/* скелет загрузки */
.sk { display: block; border-radius: 6px; background: linear-gradient(90deg, var(--raised), var(--press), var(--raised)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.sk-line { width: 140px; height: 14px; }
.sk-block { width: 100%; height: 62px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.toast {
  position: fixed; left: 50%; bottom: calc(18px + var(--tg-safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  max-width: min(92vw, 480px); padding: 11px 16px; border-radius: 12px;
  background: #2b3036; color: var(--text); font-size: 14px; border: 1px solid #353b42;
  animation: toast 200ms var(--ease);
}
.toast.err { color: #ffd1cc; border-color: rgba(255, 106, 92, 0.45); }
@keyframes toast { from { opacity: 0; transform: translate(-50%, 8px); } }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

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