/* XControl cloud UI — admin + cabinet */
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --sidebar: #1a1d24;
  --sidebar-text: #c9cdd4;
  --sidebar-active: #ffffff;
  --accent: #00a870;
  --accent-dim: #e6f7f0;
  --text: #1f2329;
  --muted: #8f959e;
  --border: #e5e6eb;
  --danger: #e34d59;
  --warn: #ed7b2f;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --sidebar-w: 220px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--accent); text-decoration: none; }

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand .logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
}

.sidebar-brand .cabinet-type {
  font-size: 0.75rem;
  color: var(--sidebar-text);
  margin-top: 0.25rem;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
}

.nav-item {
  display: block;
  padding: 0.65rem 1rem;
  color: var(--sidebar-text);
  cursor: pointer;
  border-left: 3px solid transparent;
}

.nav-item:hover { background: rgba(255, 255, 255, 0.05); color: #fff; }

.nav-item.active {
  color: var(--sidebar-active);
  background: rgba(0, 168, 112, 0.15);
  border-left-color: var(--accent);
}

.sidebar-foot {
  padding: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.8rem;
}

.sidebar-foot .nav-item-foot {
  display: block;
  border: none;
  padding: 0.35rem 0;
  color: var(--sidebar-text);
}

.sidebar-foot .nav-item-foot:hover {
  color: #fff;
}

.sidebar-foot .sidebar-hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.sidebar-foot .sidebar-admin-pill {
  margin: 0.35rem 0;
}

.time-sync-banner {
  border-left: 3px solid var(--warn, #ed7b2f);
  background: rgba(237, 123, 47, 0.08);
}

.rule-time-blocked {
  opacity: 0.92;
}

.sidebar-foot .btn-logout {
  width: 100%;
  margin-top: 0.5rem;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.topbar h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.content {
  padding: 1.25rem;
  flex: 1;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
@media (max-width: 768px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; }
  .grid2 { grid-template-columns: 1fr; }
}

input, select, textarea, button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0.5rem 0.65rem;
}

textarea {
  width: 100%;
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  min-height: 280px;
  resize: vertical;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 500;
}

button:hover { filter: brightness(0.95); }
button.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--danger); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
.field { margin-bottom: 0.75rem; }
.field label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; }
.field input, .field select { width: 100%; }

.msg {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}
.msg.ok { background: var(--accent-dim); color: #067647; }
.msg.err { background: #fdecee; color: var(--danger); }
.msg.warn { background: #fff3e8; color: var(--warn); }

.pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
}
.pill.on { background: var(--accent-dim); color: #067647; }
.pill.off { background: #f2f3f5; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.55rem 0.4rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; }

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.device-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.device-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.device-card .name { font-weight: 600; margin-bottom: 0.35rem; }
.device-card .meta { font-size: 0.78rem; color: var(--muted); }
.device-card .metrics {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.75rem;
  font-size: 1.1rem;
  font-weight: 600;
}
.device-card .metrics span { font-size: 0.7rem; font-weight: 400; color: var(--muted); display: block; }

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-box {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.login-box h1 { margin: 0 0 0.25rem; font-size: 1.25rem; }
.login-box .sub { color: var(--muted); font-size: 0.85rem; margin-bottom: 1.25rem; }

.tabs { display: flex; gap: 0.25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.tab {
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.section-tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.75rem; }
.section-tab {
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  background: #f2f3f5;
  cursor: pointer;
}
.section-tab.active { background: var(--accent-dim); color: #067647; }

[hidden] { display: none !important; }

.pre-box {
  background: #f7f8fa;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.75rem;
  overflow: auto;
  max-height: 240px;
}

.detail-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.metric-tile {
  background: #f7f8fa;
  border-radius: 10px;
  padding: 0.85rem;
  text-align: center;
}
.metric-tile .val { font-size: 1.35rem; font-weight: 700; }
.metric-tile .lbl { font-size: 0.72rem; color: var(--muted); }

.control-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }

.device-tabs { margin-bottom: 1rem; }

.out-card { margin-bottom: 0.75rem; border-left: 4px solid var(--border); }
.out-card.state-on {
  border-left-color: var(--ok);
  background: linear-gradient(90deg, rgba(0, 168, 112, 0.08), var(--surface) 45%);
}
.out-card.state-off { border-left-color: #c9cdd4; }
.out-card.state-err {
  border-left-color: var(--warn);
  background: linear-gradient(90deg, rgba(237, 123, 47, 0.1), var(--surface) 45%);
}
.out-card.state-na { opacity: 0.72; border-left-color: #d0d3d9; }

.ch-accent-fan.out-card.state-on { border-left-color: #388bfd; }
.ch-accent-pump.out-card.state-on { border-left-color: #06b6d4; }
.ch-accent-mist.out-card.state-on { border-left-color: #a371f7; }
.ch-accent-light.out-card.state-on { border-left-color: #ed7b2f; }

.alarm-banner {
  background: rgba(227, 77, 89, 0.12);
  border: 1px solid rgba(227, 77, 89, 0.35);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  color: #b42318;
}
.offline-banner {
  background: #fff8e6;
  border: 1px solid #f5d08a;
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: #8a6116;
}
.dash-out-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.5rem;
}
.dash-out-tile {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  background: #f7f8fa;
  border-left-width: 4px;
}
.dash-out-name { font-weight: 600; font-size: 0.88rem; }
.dash-out-state { font-size: 0.72rem; color: var(--muted); margin-top: 0.15rem; }
.dash-out-tile.state-on { background: rgba(0, 168, 112, 0.06); }
.dash-out-tile.ch-accent-fan { border-left-color: #388bfd; }
.dash-out-tile.ch-accent-pump { border-left-color: #06b6d4; }
.dash-out-tile.ch-accent-mist { border-left-color: #a371f7; }
.dash-out-tile.ch-accent-light { border-left-color: #ed7b2f; }
.dash-out-tile.dash-ctrl-off {
  border-color: #dc2626;
  box-shadow: inset 0 0 0 1px rgba(220, 38, 38, 0.15);
}
.dash-out-tile.dash-ctrl-on {
  border-color: #16a34a;
  box-shadow: inset 0 0 0 1px rgba(22, 163, 74, 0.15);
}
.dash-out-tile.dash-ctrl-auto {
  border-color: #9333ea;
  box-shadow: inset 0 0 0 1px rgba(147, 51, 234, 0.12);
}
.device-sticker {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}
.sticker-yellow { background: #facc15; color: #1a1a1a; }
.sticker-green { background: #22c55e; color: #fff; }
.sticker-blue { background: #3b82f6; color: #fff; }
.sticker-cyan { background: #06b6d4; color: #fff; }
.sticker-black { background: #171717; color: #fff; }
.sticker-gray { background: #9ca3af; color: #fff; }
.sticker-red { background: #ef4444; color: #fff; }
.sticker-purple { background: #a855f7; color: #fff; }
.device-sticker-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.4rem;
  min-height: 1.4rem;
}
.device-sticker-row .device-sticker { flex: 0 1 auto; }
.sticker-edit-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
  padding: 0.1rem 0.25rem;
  border-radius: 4px;
  line-height: 1;
}
.sticker-edit-btn:hover { background: var(--bg); color: var(--text); }
.device-title-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  min-width: 0;
}
.device-title-row #deviceSelect { flex: 1; min-width: 8rem; }
.device-sticker-slot:empty { display: none; }
.sticker-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.sticker-modal {
  background: var(--surface);
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
  width: min(100%, 22rem);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}
.sticker-modal h3 { margin: 0 0 0.75rem; font-size: 1rem; }
.sticker-color-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.35rem;
}
.sticker-color-opt {
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.sticker-color-opt.selected { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface); }
.sticker-color-opt[data-color="yellow"] { background: #facc15; }
.sticker-color-opt[data-color="green"] { background: #22c55e; }
.sticker-color-opt[data-color="blue"] { background: #3b82f6; }
.sticker-color-opt[data-color="cyan"] { background: #06b6d4; }
.sticker-color-opt[data-color="black"] { background: #171717; }
.sticker-color-opt[data-color="gray"] { background: #9ca3af; }
.sticker-color-opt[data-color="red"] { background: #ef4444; }
.sticker-color-opt[data-color="purple"] { background: #a855f7; }
.sticker-modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.dash-rule-line {
  font-size: 0.85rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}
.dash-rule-line:last-child { border-bottom: none; }
.dash-link { text-decoration: none; }
.dash-link:hover { text-decoration: underline; }
.scenario-mode-row { margin-top: 0.65rem; align-items: center; }
.level-metrics { grid-template-columns: repeat(3, 1fr); }

.mqtt-terminal-wrap {
  max-height: 480px;
  overflow: auto;
  background: #0d1117;
  border-radius: 8px;
  padding: 0.5rem;
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
}
.term-line { margin-bottom: 0.65rem; padding-bottom: 0.5rem; border-bottom: 1px solid #21262d; }
.term-in { color: #79c0ff; }
.term-out { color: #7ee787; }
.term-log { color: #c9d1d9; }
.term-config { color: #ffa657; }
.term-warn { color: #d29922; }
.term-error { color: #f85149; }
.term-debug { color: #8b949e; }
.term-event { color: #a5d6ff; }
.term-hint { color: var(--muted); font-size: 0.72rem; margin: 0 0 0.5rem; }
.term-filter {
  font-size: 0.72rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--muted);
  user-select: none;
}
.term-filter.active {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(56, 139, 253, 0.12);
}
.term-time { color: #8b949e; }
.term-topic { color: #d2a8ff; display: block; margin: 0.2rem 0; word-break: break-all; }
.term-payload { margin: 0.25rem 0 0; white-space: pre-wrap; word-break: break-word; color: #e6edf3; background: transparent; }

.pwm-row-cloud {
  margin-top: 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.pwm-row-cloud input[type="range"] { width: 100%; max-width: 320px; }
.badge-pwm {
  display: inline-block;
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: rgba(56, 139, 253, 0.18);
  color: #58a6ff;
  vertical-align: middle;
}

.device-card .open-link {
  display: inline-block;
  margin-top: 0.65rem;
  font-size: 0.8rem;
  color: var(--accent);
}

.sensor-chip {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sensor-widget.stale {
  opacity: 0.72;
  border: 1px dashed var(--border);
}

.chart-block {
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.chart-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.spark {
  display: block;
  width: 100%;
  height: 72px;
}

.chart-full {
  width: 100%;
  margin-top: 0.25rem;
}

.chart-full .spark {
  width: 100%;
  height: 80px;
}

.btn-action {
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.btn-action:hover { filter: brightness(1.08); }

label.toggle.switch { margin: 0; }
.sensor-setup-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.sensor-desc {
  margin: 0.25rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}
.sensor-setup-card.sensor-on {
  border-color: rgba(63, 185, 80, 0.35);
  box-shadow: inset 3px 0 0 var(--ok);
}
.sensor-setup-card.sensor-off {
  opacity: 0.88;
  box-shadow: inset 3px 0 0 var(--border);
}
.section-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 1rem 0 0.5rem;
}
.settings-logic-card { margin-bottom: 0.75rem; }

label.toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}
label.toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
label.toggle .toggle-ui {
  width: 2.4rem;
  height: 1.35rem;
  background: #21262d;
  border: 1px solid var(--border);
  border-radius: 999px;
  position: relative;
  flex-shrink: 0;
}
label.toggle .toggle-ui::after {
  content: '';
  position: absolute;
  top: 0.12rem;
  left: 0.12rem;
  width: 1rem;
  height: 1rem;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.15s, background 0.15s;
}
label.toggle input:checked + .toggle-ui {
  background: rgba(63, 185, 80, 0.25);
  border-color: var(--ok);
}
label.toggle input:checked + .toggle-ui::after {
  transform: translateX(1rem);
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.logic-mode-auto { color: var(--ok); }
.logic-mode-manual { color: var(--warn); }
.logic-mode-off { color: var(--danger); }

.logic-mode-btn {
  font-weight: 600;
}
.logic-mode-btn.logic-mode-auto.active {
  border-color: var(--ok);
  background: rgba(63, 185, 80, 0.14);
  color: var(--ok);
}
.logic-mode-btn.logic-mode-manual.active {
  border-color: var(--warn);
  background: rgba(210, 153, 34, 0.14);
  color: var(--warn);
}
.logic-mode-btn.logic-mode-off.active {
  border-color: var(--danger);
  background: rgba(248, 81, 73, 0.12);
  color: var(--danger);
}

.alarm-dim { opacity: 0.55; }
.alarm-type-card { margin-bottom: 0.65rem; }
.alarm-channel-card { margin-bottom: 0.5rem; }
.alarm-spoiler { margin-top: 0.5rem; }
.scenario-edit-spoiler { margin-top: 0.5rem; }
.scenario-edit-form {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.5rem;
  max-width: 28rem;
}

.wifi-mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
  margin-top: 0.65rem;
}
.wifi-mode-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  padding: 0.65rem 0.75rem;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  color: var(--text);
}
.wifi-mode-btn strong { font-size: 0.88rem; }
.wifi-mode-hint { font-size: 0.68rem; color: var(--muted); line-height: 1.35; }
.wifi-mode-btn.active {
  border-color: var(--accent);
  background: rgba(56, 139, 253, 0.1);
}

.btn-factory {
  background: #da3633;
  color: #fff;
  border: 1px solid #b62324;
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
.btn-factory:hover { background: #b62324; }

.spectrum-gradient-wrap { width: 100%; margin-top: 0.5rem; }
.spectrum-gradient {
  display: block;
  width: 100%;
  height: 140px;
  border-radius: 8px;
  background: #0d1117;
}
.spec-axis-label {
  font-size: 9px;
  fill: #8b949e;
}

.alarm-config-block h2 { font-size: 0.95rem; margin: 0 0 0.65rem; }
.alarm-channel-grid { display: flex; flex-direction: column; gap: 0.35rem; }
.alarm-channel-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}
.alarm-channel-row:last-child { border-bottom: none; }
.alarm-ch-name { font-weight: 600; }

.notif-section { margin-bottom: 0.75rem; }
.notif-section-title {
  margin: 0 0 0.65rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.notif-active-banner { margin-bottom: 0.75rem; border-color: rgba(248, 81, 73, 0.45); }
.notif-item { padding: 0.55rem 0; border-bottom: 1px solid var(--border); }
.notif-item:last-child { border-bottom: none; }
.notif-past { opacity: 0.62; }
.notif-past .notif-text { color: var(--muted); }
.notif-live .notif-text { font-weight: 600; }
.notif-meta { font-size: 0.72rem; color: var(--muted); margin-bottom: 0.15rem; }
.notif-time { font-size: 0.72rem; color: var(--muted); margin-bottom: 0.15rem; }

.scenario-row.stale { opacity: 0.75; }
.scenario-toolbar { margin-bottom: 0.75rem; }
.scenario-head {
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.scenario-main { flex: 1; min-width: 0; }
.scenario-detail {
  margin: 0.35rem 0 0;
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.45;
}
.scenario-kind {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  background: rgba(56, 139, 253, 0.14);
  color: #58a6ff;
}
.scenario-toggle { flex-shrink: 0; }

.rule-step { margin-top: 0.65rem; }
.rule-step-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 0.35rem;
}
.rule-card { margin-bottom: 0.75rem; }
.rule-card.rule-disabled { opacity: 0.55; }
.rule-card.rule-broken { border-left: 3px solid var(--warn); }
.rule-preview {
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.65rem;
  background: rgba(88, 166, 255, 0.08);
  border: 1px solid rgba(88, 166, 255, 0.22);
  border-radius: 6px;
  font-size: 0.92rem;
  line-height: 1.45;
}
.rule-card-head { justify-content: space-between; margin-bottom: 0.35rem; }
.add-rule-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.add-rule-btns .add-btn { flex: 1; min-width: 120px; }
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.expr-tree { display: flex; flex-direction: column; gap: 0.5rem; }
.expr-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem;
  background: rgba(255, 255, 255, 0.02);
}
.expr-group-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.5rem; }
.expr-add-btns { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.35rem; }
.expr-leaf { position: relative; padding-right: 2rem; }
.expr-leaf .icon-btn { position: absolute; top: 0.25rem; right: 0; }
.cond-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
@media (min-width: 520px) {
  .cond-row { grid-template-columns: 1.2fr 0.8fr 0.8fr; }
}
.pwm-rule-block {
  margin: 0.5rem 0;
  padding: 0.55rem 0.65rem;
  border: 1px dashed rgba(88, 166, 255, 0.35);
  border-radius: 6px;
}
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  padding: 0.2rem 0.45rem;
  line-height: 1.2;
}
.icon-btn:hover { color: var(--text); border-color: var(--muted); }
.btn-danger-text { color: var(--danger); border-color: rgba(248, 81, 73, 0.35); }
.scenario-busy { opacity: 0.72; pointer-events: none; }
.cmd-hint { margin: 0.5rem 0 0; font-size: 0.78rem; }

.device-admin-card { margin-top: 0; }
.btn-danger { color: #f85149; border-color: rgba(248, 81, 73, 0.45); }
.btn-danger:hover { background: rgba(248, 81, 73, 0.12); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow: auto;
  padding: 1.25rem;
}
.modal h2 { margin: 0 0 1rem; font-size: 1.05rem; }
.constructor-section { margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.constructor-section:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.constructor-row { margin-top: 0.5rem; padding: 0.65rem 0.75rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
@media (max-width: 640px) { .grid3 { grid-template-columns: 1fr; } }

.topbar-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 1.25rem;
  flex-shrink: 0;
}
.topbar-back:hover { background: var(--bg); }

.small-muted { color: var(--muted); font-size: 0.78rem; margin: 0 0 0.75rem; }
.text-warn { color: var(--warn); }
.pill.warn { background: #fff3e8; color: var(--warn); }

.widget-head { justify-content: space-between; margin-bottom: 0.5rem; flex-wrap: wrap; gap: 0.35rem; }
.widget-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.75rem; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.78rem; }

.level-bar-wrap {
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.5rem;
}
.level-bar {
  height: 100%;
  background: linear-gradient(90deg, #6e9fff, #00a870);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.chart-interactive { position: relative; max-width: 100%; }
.chart-tooltip {
  position: absolute;
  z-index: 5;
  background: #1f2329;
  color: #fff;
  font-size: 0.72rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  pointer-events: none;
  white-space: nowrap;
}
.chart-hint { font-weight: normal; opacity: 0.75; }
.ts-toolbar {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.4rem;
  flex-wrap: wrap;
}
.ts-range-btn {
  font-size: 0.72rem;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.ts-range-btn.active {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(0, 168, 112, 0.12);
}
.ts-range-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.ts-chart-body { position: relative; cursor: crosshair; }
.ts-svg { display: block; width: 100%; height: auto; max-height: 96px; }
.ts-grid { stroke: rgba(255, 255, 255, 0.06); stroke-width: 1; }
.ts-area { fill-opacity: 0.1; }
.ts-tip .trend-up, .ts-tip strong.trend-up { color: #22c55e; }
.ts-tip .trend-down, .ts-tip strong.trend-down { color: #ef4444; }
.ts-tip-time { font-size: 0.75rem; opacity: 0.85; }

.spectrum-block { margin-top: 0.75rem; }
.spectrum-v {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 120px;
  padding: 0.25rem 0;
}
.spectrum-v-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  min-width: 0;
}
.spectrum-v-bar {
  width: 100%;
  max-width: 28px;
  border-radius: 4px 4px 2px 2px;
  transition: height 0.35s ease;
}
.spectrum-v-bar.spec-violet { background: #a371f7; }
.spectrum-v-bar.spec-indigo { background: #6e9fff; }
.spectrum-v-bar.spec-blue { background: #58a6ff; }
.spectrum-v-bar.spec-cyan { background: #39c5cf; }
.spectrum-v-bar.spec-green { background: #3fb950; }
.spectrum-v-bar.spec-yellow { background: #d29922; }
.spectrum-v-bar.spec-orange { background: #f0883e; }
.spectrum-v-bar.spec-red { background: #f85149; }
.spectrum-v-label { font-size: 0.58rem; color: var(--muted); margin-top: 0.2rem; }
.spectrum-empty { color: var(--muted); font-size: 0.85rem; padding: 1rem 0; }

.sensor-setup-card .field-label { display: block; margin-bottom: 0.5rem; font-size: 0.85rem; }
.sensor-setup-card select { width: 100%; margin-top: 0.25rem; }
.sensor-meta { font-size: 0.78rem; color: var(--muted); margin-top: 0.35rem; }
.row-btns { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.5rem; }

.notif-list { padding: 0; }
.notif-item { padding: 0.65rem 0; border-bottom: 1px solid var(--border); }
.notif-item:last-child { border-bottom: none; }
.notif-time { font-size: 0.72rem; color: var(--muted); }
.notif-text { font-size: 0.85rem; margin-top: 0.15rem; }
.notif-alarm .notif-text, .notif-warn .notif-text, .notif-error .notif-text { color: var(--warn); }

.lab-section { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 0.75rem; }
.lab-section-compact .lab-widget .widget-head { flex-wrap: wrap; gap: 0.35rem; }
.lab-section-compact .lab-widget .dash-link { margin-left: auto; font-size: 0.78rem; }
.lab-intro h2 { margin-top: 0; }
.lab-add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  align-items: center;
}
.lab-add-form input[type="number"],
.lab-add-form input[type="text"] {
  flex: 1 1 100px;
  min-width: 88px;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.lab-add-form .lab-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1 1 120px;
  min-width: 100px;
  font-size: 0.78rem;
  color: var(--muted);
}
.lab-add-form .lab-field input {
  width: 100%;
}
.lab-add-form .lab-field-note {
  flex: 2 1 160px;
}
.lab-latest-note { margin: 0.35rem 0 0.5rem; }
.lab-recent-wrap { margin-top: 0.65rem; }
.lab-recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.82rem;
}
.lab-recent-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}
.lab-recent-list li:last-child { border-bottom: none; }
.lab-recent-val { font-weight: 600; }
.lab-note { color: var(--muted); font-style: italic; }
.lab-del-btn {
  margin-left: auto;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0.25rem;
}
.lab-del-btn:hover { color: var(--warn); }
.lab-entry-card { margin-bottom: 0.75rem; }
.lab-widgets-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.flicker-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-top: 0.35rem;
}
.flicker-result {
  font-size: 0.85rem;
  color: var(--muted);
}
.flicker-result.flicker-warn { color: var(--warn); font-weight: 600; }
.flicker-result.flicker-ok { color: var(--accent); }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -0.25rem; }
.table-scroll table { min-width: 520px; }

@media (max-width: 768px) {
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; }
  .sidebar-nav { display: flex; flex: 1; padding: 0; overflow-x: auto; }
  .sidebar-nav .nav-item { white-space: nowrap; border-left: none; border-bottom: 3px solid transparent; }
  .sidebar-nav .nav-item.active { border-bottom-color: var(--accent); border-left: none; }
  .app-shell { flex-direction: column; }
  .content { padding: 0.75rem; }
  .device-tabs { overflow-x: auto; flex-wrap: nowrap; }
  .device-tabs .tab { white-space: nowrap; }
  .detail-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 0.5rem; }
  .metric-tile .val { font-size: 1.35rem; }
  .control-row { flex-wrap: wrap; }
  .control-row button { flex: 1 1 auto; min-width: 72px; }
  .grid2 { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .topbar { padding: 0.65rem 0.75rem; }
  #deviceSelect { font-size: 0.95rem; }
}
