:root {
  --bg: #eef2f7;
  --surface: #fff;
  --text: #1d2129;
  --muted: #86909c;
  --primary: #409eff;
  --primary-hover: #337ecc;
  --danger: #d93026;
  --ok: #1a9f4b;
  --border: #e5eaf0;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(20, 40, 80, 0.08);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(ellipse at 10% 0%, rgba(64,158,255,0.12), transparent 45%),
    radial-gradient(ellipse at 90% 10%, rgba(26,111,212,0.08), transparent 40%),
    var(--bg);
}
#app { min-height: 100vh; }
.shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.brand h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0.02em;
}
.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-danger { background: #ffece8; color: var(--danger); }
.stats {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  min-width: 120px;
  box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 20px; }
.stat span { color: var(--muted); font-size: 12px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
}
.card:hover {
  transform: translateY(-2px);
  border-color: rgba(64,158,255,0.45);
  box-shadow: 0 12px 32px rgba(20,40,80,0.12);
}
.card.is-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(64,158,255,0.18);
}
.card-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.pill {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}
.pill-ok { background: #e8f8ee; color: var(--ok); }
.pill-bad { background: #ffece8; color: var(--danger); }
.card-id {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
  word-break: break-all;
  color: #337ecc;
}
.card-meta {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
}
.empty, .error {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
}
.layout-split {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 960px) {
  .layout-split { grid-template-columns: 1fr; }
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 520px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}
.panel-head h2 {
  margin: 0;
  font-size: 16px;
}
.panel-body {
  flex: 1;
  position: relative;
  min-height: 480px;
  background: #fff;
}
.chat-mount {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.chat-mount > * {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
}
.chat-mount.is-hidden {
  visibility: hidden;
  pointer-events: none;
}
.chat-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.96);
  padding: 24px;
  text-align: center;
}
.mic-banner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.45;
  color: #9a3412;
  background: #fff7ed;
  border-bottom: 1px solid #fed7aa;
}
.mqtt-box {
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  max-height: 160px;
  overflow: auto;
  background: #f7fafc;
  font-size: 12px;
  font-family: ui-monospace, Consolas, monospace;
}
.mqtt-line { margin: 0 0 6px; color: #4e5969; white-space: pre-wrap; word-break: break-all; }
.mqtt-line .t { color: var(--muted); margin-right: 6px; }

.btn-xs { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.mqtt-panel {
  border-top: 1px solid var(--border);
  background:
    linear-gradient(180deg, #f4f8fc 0%, #eef3f9 100%);
  max-height: min(52vh, 520px);
  overflow: auto;
  padding: 12px 14px 14px;
}
.mqtt-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.mqtt-panel-head strong { font-size: 14px; }
.mqtt-empty {
  padding: 18px 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.mqtt-raw {
  margin: 0;
  padding: 12px;
  border-radius: 12px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 11px;
  line-height: 1.5;
  overflow: auto;
  max-height: 240px;
  white-space: pre-wrap;
  word-break: break-all;
}
.tele-plant {
  position: relative;
  border-radius: 16px;
  padding: 14px;
  overflow: hidden;
  color: #e8f1f8;
  background:
    radial-gradient(ellipse at 0% 0%, rgba(56, 189, 248, 0.22), transparent 50%),
    radial-gradient(ellipse at 100% 0%, rgba(34, 197, 94, 0.16), transparent 45%),
    linear-gradient(145deg, #0b1726 0%, #123048 48%, #0d2136 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 12px 28px rgba(8, 24, 48, 0.18);
  animation: tele-in .35s ease;
}
.tele-plant.tone-warn {
  background:
    radial-gradient(ellipse at 0% 0%, rgba(251, 191, 36, 0.2), transparent 50%),
    linear-gradient(145deg, #1a1408 0%, #3a2a0c 50%, #1a1408 100%);
}
.tele-plant.tone-bad {
  background:
    radial-gradient(ellipse at 0% 0%, rgba(248, 113, 113, 0.22), transparent 50%),
    linear-gradient(145deg, #1a0b0b 0%, #3a1212 50%, #1a0b0b 100%);
}
@keyframes tele-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.tele-hero {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.tele-kicker {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(226, 241, 248, 0.55);
  margin-bottom: 4px;
}
.tele-status {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.25;
}
.tele-mode {
  margin: 6px 0 0;
  font-size: 13px;
  color: rgba(226, 241, 248, 0.72);
}
.tele-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-content: flex-start;
  justify-content: flex-start;
  max-width: none;
}
.tele-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  white-space: nowrap;
}
.dyn-block-head {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}
.dyn-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.dyn-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
.dyn-chip {
  font-size: 11px;
  font-weight: 650;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(125, 211, 252, 0.22);
  color: #bae6fd;
}
.dyn-chip[data-k="version"] {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.1);
  color: rgba(226,241,248,0.7);
  font-weight: 500;
}
.dyn-ids {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 12px;
  color: rgba(226,241,248,0.55);
  font-variant-numeric: tabular-nums;
}
.dyn-id-item em {
  font-style: normal;
  margin-right: 4px;
  color: rgba(226,241,248,0.38);
}
.dyn-title-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px 18px;
  align-items: start;
}
@media (max-width: 720px) {
  .dyn-title-row { grid-template-columns: 1fr; }
  .dyn-badge-rail { justify-content: flex-start; }
}
.dyn-title-main { min-width: 0; }
.dyn-badge-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  max-width: 280px;
}
.dyn-block-head.is-nested .dyn-title-row {
  grid-template-columns: minmax(0, 1fr) auto;
}
.dyn-block-head.is-nested .dyn-badge-rail {
  max-width: 220px;
}
.tb-ok { background: rgba(34,197,94,0.18); color: #86efac; border-color: rgba(34,197,94,0.28); }
.tb-warn { background: rgba(251,191,36,0.18); color: #fde68a; border-color: rgba(251,191,36,0.28); }
.tb-bad { background: rgba(248,113,113,0.2); color: #fecaca; border-color: rgba(248,113,113,0.3); }
.tb-mute { color: rgba(226,241,248,0.7); }
.tb-stage { background: rgba(56,189,248,0.16); color: #7dd3fc; }
.tb-water { background: rgba(125,211,252,0.14); color: #bae6fd; }
.tele-metrics {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 14px;
  align-items: center;
  margin-bottom: 12px;
}
@media (max-width: 640px) {
  .tele-metrics { grid-template-columns: 1fr; justify-items: center; }
}
.tele-gauge {
  position: relative;
  width: 112px;
  height: 112px;
}
.gauge-svg {
  width: 112px;
  height: 112px;
  transform: rotate(-90deg);
}
.gauge-track {
  fill: none;
  stroke: rgba(255,255,255,0.1);
  stroke-width: 10;
}
.gauge-value {
  fill: none;
  stroke: #38bdf8;
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dasharray .6s ease;
  filter: drop-shadow(0 0 6px rgba(56,189,248,0.45));
}
.tone-warn .gauge-value { stroke: #fbbf24; filter: drop-shadow(0 0 6px rgba(251,191,36,0.4)); }
.tone-bad .gauge-value { stroke: #f87171; filter: drop-shadow(0 0 6px rgba(248,113,113,0.4)); }
.gauge-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.gauge-label b { font-size: 22px; line-height: 1; }
.gauge-label span { font-size: 11px; color: rgba(226,241,248,0.6); margin-top: 2px; }
.tele-metric-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}
.tele-metric {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 10px 12px;
}
.tele-metric span {
  display: block;
  font-size: 11px;
  color: rgba(226,241,248,0.55);
  margin-bottom: 4px;
}
.tele-metric strong {
  font-size: 13px;
  font-weight: 650;
  word-break: break-word;
}
.tele-chems {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.tele-chems-title {
  font-size: 11px;
  color: rgba(226,241,248,0.55);
  margin-bottom: 8px;
  letter-spacing: 0.06em;
}
.chem-row {
  display: grid;
  grid-template-columns: 72px 1fr 36px;
  gap: 8px;
  align-items: center;
  margin-bottom: 7px;
  font-size: 12px;
}
.chem-name { color: rgba(226,241,248,0.75); }
.chem-bar {
  height: 7px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
.chem-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #38bdf8, #22d3ee);
  transition: width .5s ease;
}
.chem-val { text-align: right; font-variant-numeric: tabular-nums; color: #bae6fd; }
.tele-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 12px;
  font-size: 11px;
  color: rgba(226,241,248,0.45);
}
.tele-generic {
  border-radius: 14px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--border);
}
.tele-generic .tele-kicker { color: var(--muted); margin-bottom: 10px; }
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.field-chip {
  background: #f5f8fb;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}
.field-chip span {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
}
.field-chip strong {
  font-size: 13px;
  word-break: break-word;
}
.mqtt-feed {
  margin-top: 12px;
  border-top: 1px dashed rgba(20,40,80,0.12);
  padding-top: 8px;
}
.mqtt-feed-item {
  display: grid;
  grid-template-columns: 64px 58px 1fr;
  gap: 8px;
  align-items: baseline;
  padding: 6px 4px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}
.mqtt-feed-item:hover { background: rgba(255,255,255,0.65); }
.mqtt-feed-item .t { color: var(--muted); font-variant-numeric: tabular-nums; }
.mqtt-feed-item .kind {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #337ecc;
}
.mqtt-feed-item .kind[data-k="plant"] { color: #0f766e; }
.mqtt-feed-item .kind[data-k="dynamic"] { color: #0f766e; }
.mqtt-feed-item .kind[data-k="text"] { color: var(--muted); }
.mqtt-feed-item .sum {
  color: #334155;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.panel-body { min-height: 360px; }

.dyn-board .tele-metrics.only-metrics {
  grid-template-columns: 1fr;
}
.dyn-gauges {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
  justify-content: flex-start;
}
.dyn-gauges.compact .tele-gauge.sm {
  width: 88px;
  height: auto;
}
.dyn-gauges.compact .gauge-svg {
  width: 88px;
  height: 88px;
}
.tele-gauge {
  position: relative;
  width: 112px;
  height: auto;
  text-align: center;
}
.gauge-caption {
  margin-top: 2px;
  font-size: 11px;
  color: rgba(226,241,248,0.55);
}
.dyn-section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.dyn-section .sec-badges {
  justify-content: flex-start;
  max-width: none;
  margin-bottom: 8px;
}
.tele-chems.nested { margin-top: 8px; padding-top: 0; border-top: 0; }
.dyn-hint {
  margin-left: auto;
  opacity: 0.7;
}
.dyn-panel-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #e8f1f8;
}
.tele-status.is-sub { font-size: 17px; }
.nested-panel {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 12px;
  margin-top: 10px;
}
.eq-wall { margin-top: 10px; }
.eq-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.eq-card {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 10px 12px;
  animation: tele-in .35s ease;
}
.eq-card.eq-ok { box-shadow: inset 0 0 0 1px rgba(34,197,94,0.18); }
.eq-card.eq-warn { box-shadow: inset 0 0 0 1px rgba(251,191,36,0.22); }
.eq-card.eq-bad { box-shadow: inset 0 0 0 1px rgba(248,113,113,0.22); }
.eq-card-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
  margin-bottom: 8px;
}
.eq-card-head strong { font-size: 13px; }
.eq-sub {
  margin-top: 2px;
  font-size: 11px;
  color: rgba(226,241,248,0.5);
}
.eq-metrics {
  display: grid;
  gap: 4px;
  margin-top: 6px;
}
.eq-metrics > div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: rgba(226,241,248,0.7);
}
.eq-extras {
  display: grid;
  gap: 4px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed rgba(255,255,255,0.1);
}
.eq-extras > div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: rgba(226,241,248,0.55);
}
.eq-extras b {
  color: rgba(226,241,248,0.85);
  font-weight: 600;
  text-align: right;
  word-break: break-all;
}
.dyn-table-wrap { margin-top: 10px; }
.dyn-table-scroll { overflow: auto; max-height: 220px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.08); }
.dyn-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.dyn-table th, .dyn-table td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dyn-table th { color: rgba(226,241,248,0.5); font-weight: 650; background: rgba(0,0,0,0.15); }
.dyn-table td { color: rgba(226,241,248,0.88); }
.dyn-timeline { margin-top: 10px; }
.tl-item {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 8px;
  margin-bottom: 8px;
}
.tl-dot {
  width: 8px; height: 8px; border-radius: 50%;
  margin-top: 6px;
  background: #38bdf8;
}
.tl-warn .tl-dot { background: #fbbf24; }
.tl-bad .tl-dot, .tl-item.tl-bad .tl-dot { background: #f87171; }
.tl-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}
.tl-top span { color: rgba(226,241,248,0.45); font-size: 11px; }
.tl-detail { font-size: 11px; color: rgba(226,241,248,0.55); margin-top: 2px; }
.dyn-matrix { margin-top: 10px; }
.mx-grid { display: grid; gap: 4px; }
.mx-row { display: flex; flex-wrap: wrap; gap: 4px; }
.mx-cell {
  min-width: 42px;
  padding: 4px 6px;
  text-align: center;
  font-size: 11px;
  border-radius: 6px;
  background: rgba(56,189,248,0.12);
  color: #e0f2fe;
  font-variant-numeric: tabular-nums;
}
.dyn-chips { margin-top: 10px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.dyn-chip.soft {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.1);
  color: rgba(226,241,248,0.8);
  font-weight: 500;
}
.dyn-preview {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0,0,0,0.25);
}
.dyn-preview pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 11px;
  color: rgba(226,241,248,0.7);
  max-height: 120px;
  overflow: auto;
}
.tele-foot.soft { opacity: 0.75; margin-top: 8px; }
.mqtt-panel { max-height: min(68vh, 720px); }
.dyn-gauges.compact .tele-gauge.sm .gauge-svg { width: 72px; height: 72px; }
.dyn-gauges.compact .tele-gauge.sm { width: 76px; }

.tele-metrics {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: start;
  margin-bottom: 12px;
}
@media (max-width: 640px) {
  .tele-metrics { grid-template-columns: 1fr; justify-items: stretch; }
  .dyn-gauges { justify-content: center; }
}
.hint {
  padding: 24px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}
.field-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.field-row input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 180px;
}
