:root {
  --bg: #f2f2f7;
  --surface: rgba(255, 255, 255, 0.76);
  --surface-solid: #ffffff;
  --line: rgba(0, 0, 0, 0.06);
  --line-strong: rgba(0, 0, 0, 0.1);
  --ink: #0a0a0a;
  --ink-soft: #3c3c43;
  --muted: #8e8e93;
  --accent: #0a84ff;
  --green: #34c759;
  --orange: #ff9f0a;
  --red: #ff453a;
  --radius: 26px;
  --shadow: 0 14px 36px rgba(20, 30, 60, 0.09);
  --shadow-soft: 0 8px 24px rgba(20, 30, 60, 0.06);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  padding: 30px 36px 110px;
  font-family: -apple-system, "SF Pro Display", "Segoe UI", Inter, system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 520px at 10% -12%, #dbe7ff 0%, transparent 62%),
    radial-gradient(760px 420px at 108% 2%, #ffe4ef 0%, transparent 58%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 24px; font-weight: 650; }
h3 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); margin: 22px 0 10px; }
p { margin: 0; }

/* ---------- шапка ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 4px 18px;
  margin-bottom: 8px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { font-size: 34px; font-weight: 650; }
.brand .muted { font-size: 14px; margin-top: 4px; }

.actions { display: flex; gap: 8px; }

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(18px);
  color: var(--ink-soft);
  font-size: 17px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.icon-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-soft); }

/* ---------- карточки-показатели ---------- */

.cards {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 18px;
  margin-bottom: 18px;
}

.card {
  background: var(--surface);
  backdrop-filter: blur(26px);
  -webkit-backdrop-filter: blur(26px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
}

.card-label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}

.card-sub { margin-top: 8px; font-size: 13.5px; color: var(--muted); }

.climate-temp {
  font-size: 56px;
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1;
  margin: 10px 0 6px;
}

.climate-unit { font-size: 24px; color: var(--muted); font-weight: 500; margin-left: 4px; }

.energy-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 10px;
  font-size: 14px;
  color: var(--muted);
}

.energy-row b { color: var(--ink); font-size: 17px; font-weight: 600; }

.kpi-big { font-size: 44px; font-weight: 600; letter-spacing: -0.03em; line-height: 1; margin-top: 12px; }
.kpi-big span { font-size: 20px; color: var(--muted); font-weight: 500; margin-left: 6px; }
.kpi-split { display: flex; gap: 20px; margin-top: 14px; }
.kpi-split div { flex: 1; }
.kpi-split .k { font-size: 12px; color: var(--muted); }
.kpi-split .v { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; }

/* ---------- плитки ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  gap: 4px;
  padding: 20px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(26px);
  box-shadow: var(--shadow-soft);
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.tile-ico {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 20px;
  background: linear-gradient(140deg, #e9f1ff, #fbfdff);
  margin-bottom: 12px;
}

.tile-title { font-size: 16.5px; font-weight: 600; letter-spacing: -0.01em; }
.tile-sub { font-size: 13.5px; color: var(--muted); }
.tile-status { font-size: 12.5px; color: var(--accent); min-height: 16px; margin-top: 2px; }
.tile-status.ok { color: var(--green); }
.tile-status.err { color: var(--red); }

/* ---------- разделы ---------- */

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); gap: 16px; }

.cam-tile {
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.cam-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #0b0f14;
  display: grid;
  place-items: center;
}

.cam-frame img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.2s; }
.cam-frame img.visible { opacity: 1; }
.cam-fallback { position: absolute; color: #8b97ab; font-size: 13px; }

.cam-foot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  font-size: 13.5px;
  color: var(--ink-soft);
}

.cam-foot span:last-child { color: var(--muted); }

.kv { display: block; }
.kv > div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv > div:last-child { border-bottom: none; }
.kv .k { color: var(--muted); }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.pill {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--ink-soft);
  background: rgba(120, 120, 128, 0.12);
}

.pill.ok { background: rgba(52, 199, 89, 0.14); color: #1c8a3c; }
.pill.err { background: rgba(255, 69, 58, 0.12); color: #b3261e; }

.hint { margin-top: 14px; font-size: 13px; color: var(--muted); line-height: 1.5; }

code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: rgba(120, 120, 128, 0.12); padding: 2px 6px; border-radius: 6px; }

/* ---------- кнопки и поля ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface-solid);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 14px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; box-shadow: none; }

.gate-button {
  width: 100%;
  padding: 34px;
  border-radius: 26px;
  border: 1px solid var(--line);
  background: var(--surface);
  font: inherit;
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
}

.json {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(120, 120, 128, 0.08);
  color: var(--ink-soft);
  font-size: 12.5px;
  overflow: auto;
  max-height: 220px;
}

input, select {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: #fff;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
}

input:focus, select:focus { outline: 2px solid rgba(10, 132, 255, 0.35); outline-offset: 1px; }

/* ---------- сцены и лампы ---------- */

.scene-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }

.scene-btn {
  background: rgba(10, 132, 255, 0.1);
  border-color: rgba(10, 132, 255, 0.25);
  color: #0a63c9;
}

.light-body { display: flex; flex-direction: column; gap: 12px; padding: 0 14px 16px; }

.light-slider { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.light-slider b { color: var(--ink); font-weight: 600; }
.light-slider input[type="range"] { width: 100%; accent-color: var(--accent); }

.light-slider input[type="color"] {
  width: 100%;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: transparent;
}

/* ---------- таб-бар ---------- */

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(26px);
  -webkit-backdrop-filter: blur(26px);
  border: 1px solid var(--line);
  box-shadow: 0 18px 44px rgba(20, 30, 60, 0.16);
  z-index: 40;
}

.tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
  border: none;
  background: transparent;
  font-family: inherit;
  white-space: nowrap;
}

.tab.active { background: var(--accent); color: #fff; }

/* ---------- вход ---------- */

.login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(700px 400px at 20% 0%, #dbe7ff 0%, transparent 60%),
    radial-gradient(600px 360px at 90% 10%, #ffe4ef 0%, transparent 55%),
    var(--bg);
}

.login-box {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 30px;
  border-radius: 28px;
  background: var(--surface);
  backdrop-filter: blur(26px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.login-box h1 { font-size: 26px; }
.login-box label { display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--muted); }

.error { color: var(--red); font-size: 13px; min-height: 18px; }

/* ---------- поток ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 60;
  padding: 24px;
}

.overlay-bar { display: flex; align-items: center; gap: 16px; color: #fff; font-size: 16px; }
.overlay img { max-width: 100%; max-height: 78vh; border-radius: 18px; background: #000; }
.overlay-note { color: #c7d2e4; font-size: 13px; }

/* ---------- диалоги ---------- */

.dialog {
  border: none;
  border-radius: 26px;
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  background: var(--surface-solid);
  box-shadow: 0 30px 80px rgba(10, 20, 40, 0.28);
}

.dialog::backdrop { background: rgba(10, 12, 16, 0.35); backdrop-filter: blur(4px); }

.dialog form { padding: 26px 26px 20px; display: flex; flex-direction: column; gap: 14px; }
.dialog h2 { font-size: 22px; }

.dialog fieldset {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog legend { padding: 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.dialog label { display: flex; flex-direction: column; gap: 7px; font-size: 13px; color: var(--muted); }

.dialog-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.dialog-actions .error { margin-right: auto; }

/* ---------- адаптив ---------- */

@media (max-width: 980px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  body {
    padding: 18px 16px calc(150px + env(safe-area-inset-bottom));
    scroll-padding-bottom: calc(150px + env(safe-area-inset-bottom));
  }
  .brand h1 { font-size: 28px; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .climate-temp { font-size: 46px; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 12px; }
  .tile { padding: 16px; border-radius: 20px; }
  .tabbar {
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    transform: none;
    justify-content: space-between;
  }
  .tab { padding: 9px 12px; font-size: 13px; }
}

.kpi-big b { font-weight: 600; font-size: 44px; letter-spacing: -0.03em; }

/* ---------- тёмная тема ---------- */

html[data-theme="dark"] {
  --bg: #0a0c10;
  --surface: rgba(255, 255, 255, 0.055);
  --surface-solid: #12161d;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --ink: #eef2f8;
  --ink-soft: #c3ccda;
  --muted: #8b97ab;
  --accent: #4c9aff;
  --green: #3ddc84;
  --red: #ff6b60;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.45);
  --shadow-soft: 0 12px 30px rgba(0, 0, 0, 0.35);
}

html[data-theme="dark"] body {
  background:
    radial-gradient(900px 500px at 8% -10%, rgba(76, 154, 255, 0.20) 0%, transparent 60%),
    radial-gradient(700px 420px at 100% 0%, rgba(124, 92, 255, 0.16) 0%, transparent 55%),
    var(--bg);
}

html[data-theme="dark"] .topbar { background: rgba(10, 12, 16, 0.55); }
html[data-theme="dark"] .icon-btn { background: rgba(255, 255, 255, 0.06); color: var(--ink-soft); }
html[data-theme="dark"] .tile-ico { background: linear-gradient(140deg, rgba(76, 154, 255, 0.18), rgba(255, 255, 255, 0.04)); }
html[data-theme="dark"] .tabbar { background: rgba(20, 24, 32, 0.78); }
html[data-theme="dark"] .tab { color: var(--ink-soft); }
html[data-theme="dark"] .tab.active { background: var(--accent); color: #06121f; }
html[data-theme="dark"] input,
html[data-theme="dark"] select { background: #0f131a; color: var(--ink); }
html[data-theme="dark"] .btn { background: rgba(255, 255, 255, 0.06); color: var(--ink); }
html[data-theme="dark"] .btn.primary { background: var(--accent); color: #06121f; }
html[data-theme="dark"] .scene-btn { background: rgba(76, 154, 255, 0.14); color: #9cc4ff; }
html[data-theme="dark"] .pill { background: rgba(255, 255, 255, 0.08); color: var(--ink-soft); }
html[data-theme="dark"] .pill.ok { background: rgba(61, 220, 132, 0.16); color: #7ee2a8; }
html[data-theme="dark"] .pill.err { background: rgba(255, 107, 96, 0.16); color: #ff9d95; }
html[data-theme="dark"] .login { background: radial-gradient(700px 400px at 20% 0%, #12203a 0%, transparent 60%), var(--bg); }
html[data-theme="dark"] .json { background: rgba(255, 255, 255, 0.05); color: var(--ink-soft); }
html[data-theme="dark"] .cam-foot { color: var(--ink-soft); }
html[data-theme="dark"] .gate-button { background: rgba(255, 255, 255, 0.06); color: var(--ink); }

/* сетка полей в диалоге настроек */
.dialog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog-grid label { font-size: 12px; }
@media (max-width: 640px) { .dialog-grid { grid-template-columns: 1fr; } }

/* строка «запомнить на этом устройстве» */
.checkbox-row { flex-direction: row !important; align-items: center; gap: 9px; color: var(--ink-soft); font-size: 13.5px; }
.checkbox-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }

/* защита от горизонтального переполнения на узких экранах */
.tile, .card, .cam-tile, .tiles, .cards, .grid, .energy-row, .kpi-split { min-width: 0; }
.tile-title { overflow-wrap: anywhere; }
.energy-row b, .kpi-big b { white-space: nowrap; }
html, body { max-width: 100%; overflow-x: hidden; }

@media (max-width: 640px) {
  .tile-title { font-size: 15px; }
  .tile-sub { font-size: 12.5px; }
  .tab { padding: 9px 8px; font-size: 12.5px; }
  .energy-row { font-size: 13px; }
  .energy-row b { font-size: 15px; }
}

/* ---- главная: выключатель и ворота ---- */

.home-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.home-actions .gate-button { height: 100%; }

.tabbar { overflow-x: auto; scrollbar-width: none; }
.tabbar::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; }

@media (max-width: 720px) {
  .home-actions { grid-template-columns: minmax(0, 1fr); }
}

/* ---- двухклавишный выключатель как физический ---- */

.switch-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  padding: 22px;
  place-items: center;
}

.paddle {
  position: relative;
  width: min(100%, 138px);
  aspect-ratio: 4 / 5;
  border-radius: 15px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: linear-gradient(168deg, #3c3c41 0%, #232327 46%, #0e0e10 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.13),
    inset 0 -4px 10px rgba(0, 0, 0, 0.75),
    0 10px 22px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s ease;
}

.paddle:active { transform: scale(0.985); }
.paddle:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.paddle:disabled { opacity: 0.7; cursor: default; }

.paddle .led {
  position: absolute;
  left: 50%;
  bottom: 13%;
  width: 6px;
  height: 14px;
  border-radius: 3px;
  transform: translateX(-50%);
  background: #f4f6fa;
  box-shadow: 0 0 7px rgba(255, 255, 255, 0.55);
  transition: background 0.18s ease, box-shadow 0.18s ease;
}

.paddle.on .led {
  background: #3f8cff;
  box-shadow: 0 0 10px rgba(63, 140, 255, 0.95), 0 0 24px rgba(63, 140, 255, 0.55);
}

.switch-card .card-sub { grid-column: 1 / -1; margin: 0; }

/* название раздела уже показано в шапке — не дублируем */
.section-head h2 { display: none; }
.section-head > :not(h2) { margin-left: auto; }

/* показания энергии в настройках */
.energy-base { display: flex; flex-direction: column; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.energy-base:last-child { border-bottom: none; }
.energy-base-name { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.energy-base-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 640px) { .energy-base-fields { grid-template-columns: 1fr; } }

/* ---- вкладка «Голос» ---- */

.voice-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 26px 16px;
}

.voice-mic {
  position: relative;
  width: 148px;
  height: 148px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: radial-gradient(circle at 35% 30%, #3a6bff 0%, #1d3bb8 55%, #101a4d 100%);
  box-shadow: 0 18px 40px rgba(35, 80, 220, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.28);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.voice-mic:active { transform: scale(0.97); }
.voice-mic:disabled { opacity: 0.6; cursor: default; }
.voice-mic-icon { font-size: 54px; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35)); }
.voice-mic.recording { background: radial-gradient(circle at 35% 30%, #ff5f6d 0%, #c9203a 55%, #5c0c1c 100%); box-shadow: 0 18px 40px rgba(220, 40, 70, 0.45); }
.voice-mic.recording .voice-mic-ring {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid rgba(255, 90, 110, 0.6);
  animation: voice-pulse 1.4s ease-out infinite;
}

@keyframes voice-pulse {
  0% { transform: scale(0.92); opacity: 0.9; }
  100% { transform: scale(1.18); opacity: 0; }
}

.voice-status { font-size: 14px; color: var(--muted); text-align: center; min-height: 20px; }

.voice-card { width: min(560px, 100%); }
.voice-line { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.voice-line:last-child { border-bottom: none; }
.voice-line .k { color: var(--muted); min-width: 64px; }

/* ---- вкладка «Харнесс» ---- */

.harness-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.harness-feed {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 320px;
  max-height: calc(100vh - 320px);
  overflow-y: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  backdrop-filter: blur(22px);
}

.harness-msg {
  max-width: min(680px, 90%);
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.harness-msg.user {
  align-self: flex-end;
  background: linear-gradient(160deg, #3a6bff, #2350c8);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.harness-msg.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

/* ---- Харнесс: голосовой ассистент ---- */

.hn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: calc(100vh - 210px);
  padding: 18px 18px 24px;
  border-radius: 28px;
  overflow: hidden;
  background:
    radial-gradient(120% 62% at 50% 108%, rgba(255, 60, 140, 0.55) 0%, rgba(120, 30, 180, 0.35) 38%, transparent 72%),
    radial-gradient(90% 50% at 50% 100%, rgba(255, 120, 60, 0.35) 0%, transparent 65%),
    linear-gradient(180deg, #05060a 0%, #0a0713 42%, #1a0a26 72%, #2a0b2f 100%);
}

.hn.live { box-shadow: inset 0 0 120px rgba(255, 60, 160, 0.18); }

.hn-wave { width: 100%; height: 150px; display: block; }

.hn-timer {
  margin-top: 10px;
  font-size: 30px;
  font-weight: 300;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.92);
}

.hn-status {
  margin-top: 6px;
  font-size: 12.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
}

.hn-status.ok { color: #7ef0b0; }
.hn-status.err { color: #ff8b8b; }

.hn-feed {
  flex: 1;
  width: 100%;
  max-height: 34vh;
  margin: 14px 0 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 4px;
  mask-image: linear-gradient(180deg, transparent 0%, #000 12%, #000 88%, transparent 100%);
}

.hn-feed .hint { color: rgba(255, 255, 255, 0.45); text-align: center; margin: 24px auto; max-width: 280px; }

.harness-msg {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
}

.harness-msg.user {
  align-self: flex-end;
  background: rgba(120, 90, 255, 0.35);
  border: 1px solid rgba(160, 130, 255, 0.35);
  color: #fff;
}

.harness-msg.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #eef2f8;
}

.hn-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 26px;
  margin-top: 10px;
}

.hn-round {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.85);
  font-size: 17px;
  cursor: pointer;
  backdrop-filter: blur(10px);
}

.hn-round.active { background: rgba(255, 90, 140, 0.35); border-color: rgba(255, 120, 170, 0.6); }

.hn-mic {
  position: relative;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 28%, #ff9ad5 0%, #b163ff 42%, #6a3bff 72%, #3a1f9e 100%);
  box-shadow:
    0 0 26px rgba(200, 90, 255, 0.55),
    0 0 60px rgba(255, 90, 190, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.hn-mic-icon { font-size: 34px; filter: drop-shadow(0 2px 6px rgba(40, 0, 60, 0.5)); }

.hn-ring {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 140, 210, 0.5);
  opacity: 0;
}

.hn.live .hn-ring { animation: hn-pulse 2.4s ease-out infinite; }
.hn.live .hn-ring-2 { animation-delay: 1.2s; }

@keyframes hn-pulse {
  0% { transform: scale(0.92); opacity: 0.75; }
  100% { transform: scale(1.45); opacity: 0; }
}

.hn.live .hn-mic { box-shadow: 0 0 34px rgba(255, 90, 190, 0.75), 0 0 90px rgba(255, 60, 160, 0.45); }


.hn-log { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; }

.hn-log-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.7);
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.hn-chevron { transition: transform 0.18s ease; }
.hn-feed.collapsed { display: none; }
.hn-log.collapsed .hn-chevron { transform: rotate(-90deg); }

/* Лента не должна уходить под панель кнопок: только верхнее затухание. */
.hn-feed {
  mask-image: linear-gradient(180deg, transparent 0%, #000 10%);
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 10%);
  padding: 0 4px 16px;
  scroll-padding-bottom: 16px;
}

.hn-controls {
  position: relative;
  z-index: 2;
  margin-top: 16px;
  padding-top: 6px;
}

/* ---------- Чат: зеркало рабочей сессии ---------- */
.chat {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: calc(100vh - 220px);
  min-height: 380px;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
}

.chat-head-text { display: flex; flex-direction: column; gap: 2px; }
.chat-head-text strong { font-size: 15px; font-weight: 650; }
.chat-sub { font-size: 12px; color: var(--muted); }

.chat-feed {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 6px 4px 10px;
  scroll-behavior: smooth;
}

.chat-msg {
  max-width: min(720px, 88%);
  padding: 10px 14px;
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 8px;
}

.chat-msg.bot {
  align-self: flex-start;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-bottom-left-radius: 8px;
}

.chat-who {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.62;
  margin-bottom: 4px;
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.chat-form textarea {
  flex: 1;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
  max-height: 160px;
  padding: 8px 10px;
}

.chat-send { width: 42px; height: 42px; border-radius: 50%; font-size: 18px; line-height: 1; }
body.chat-busy .chat-head { border-color: var(--accent); }
.chat-head-actions { display: flex; align-items: center; gap: 8px; }
.chat-select {
  max-width: 230px;
  padding: 7px 10px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface-solid);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
}
/* ---------- Учётные записи ---------- */
.accounts-list { display: flex; flex-direction: column; gap: 8px; max-height: 240px; overflow-y: auto; margin: 10px 0 4px; }
.account-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-solid); }
.account-info { flex: 1; font-size: 13px; }
.account-tabs { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0; }
.account-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.account-form label { display: block; margin: 6px 0; }
/* Диалог учётных записей: заголовок не должен обрезаться на низком экране */
#accounts {
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px 26px 10px;
}
#accounts h2 { margin: 0 0 6px; }
#accounts > p { margin: 0 0 12px; }
#accounts > h3 { margin: 18px 0 8px; }
#accounts .account-form { padding: 0; gap: 10px; }
#accounts .account-form label { color: var(--muted); }
#accounts .checkbox-row { display: flex; flex-direction: row; align-items: center; gap: 9px; }
#accounts .checkbox-row input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
#accounts input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  display: inline-grid;
  place-content: center;
  cursor: pointer;
}
#accounts input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
#accounts input[type="checkbox"]:checked::after { content: "✓"; color: #fff; font-size: 12px; line-height: 1; }
/* ---- Вкладка «Картинки» ---- */
.studio-attach {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 0 0 8px;
  width: fit-content;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.studio-attach img {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 10px;
}

.studio-pic { max-width: min(520px, 92%); }
.studio-pic img {
  display: block;
  max-width: min(460px, 100%);
  border-radius: 12px;
  margin-bottom: 8px;
}

.studio-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.studio-mini {
  display: block;
  width: 120px;
  border-radius: 10px;
  margin-top: 8px;
}
.studio-note {
  font-size: 12px;
  color: var(--muted);
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0 4px;
  max-width: min(520px, 92%);
}
/* ---- Маска для правки фото ---- */
.studio-attach { flex-direction: column; align-items: stretch; gap: 8px; max-width: min(400px, 84vw); }

.studio-canvas-wrap { position: relative; display: inline-block; line-height: 0; }

.studio-canvas-wrap #studio-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
}

.studio-canvas-wrap #studio-mask {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  cursor: crosshair;
  touch-action: none;
  opacity: 0.9;
}

.studio-mask-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.studio-hint { font-size: 12px; color: var(--muted); }
.studio-balance {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* ---- Правка layout вкладки «Картинки»: превью не должно выдавливать поле ввода ---- */
.chat { overflow: hidden; }

.chat-feed { min-height: 0; overscroll-behavior: contain; }

.studio-attach {
  flex: 0 0 auto;
  max-width: min(100%, 420px);
  max-height: 40vh;
  overflow: auto;
}

.studio-canvas-wrap { width: fit-content; max-width: 100%; }

.studio-canvas-wrap #studio-canvas {
  width: auto;
  max-width: 100%;
  max-height: 30vh;
  height: auto;
}

.studio-mask-bar { flex-wrap: wrap; }