:root {
  --bg-main: radial-gradient(circle at top left, #f6fff8 0%, #eefaf9 30%, #edf4ff 68%, #f7f0ff 100%);
  --panel-bg: rgba(255, 255, 255, 0.72);
  --text-main: #16313d;
  --text-soft: #64808b;
  --text-muted: #88a1aa;
  --shadow-soft: 0 22px 50px rgba(58, 114, 139, 0.14);
  --shadow-card: 0 16px 32px rgba(87, 118, 137, 0.12);
  --primary: #3cbfb5;
  --primary-dark: #1f8e88;
  --accent-blue: #4f8cff;
  --accent-yellow: #f4b942;
  --accent-green: #67c587;
  --danger: #ff7a7a;
  --success: #39bf7b;
  --radius-xl: 34px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --dashboard-base-width: 1600px;
  --dashboard-base-height: 900px;
  --dashboard-scale: 1;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
}

body { overflow: auto; }
body.dashboard-page { overflow: hidden; }
button { font: inherit; border: 0; cursor: pointer; }
h1, h2, h3, p { margin: 0; }

.app-body { width: 100vw; min-height: 100vh; }
.orientation-shell { width: 100vw; min-height: 100vh; padding: 0.9rem; }

.force-landscape .orientation-shell {
  position: fixed;
  top: 100%;
  left: 0;
  width: 100vh;
  height: 100vw;
  transform: rotate(-90deg);
  transform-origin: top left;
  padding: 0.6rem;
}

.scene-page {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: var(--radius-xl);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.42), rgba(255,255,255,0.2)),
    radial-gradient(circle at 50% 22%, rgba(255, 244, 184, 0.28), transparent 24%),
    linear-gradient(180deg, rgba(255,255,255,0.38), rgba(241, 248, 250, 0.66));
  box-shadow: var(--shadow-soft);
}

.scene-page::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(124, 164, 168, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124, 164, 168, 0.08) 1px, transparent 1px);
  background-size: 30px 30px;
  pointer-events: none;
}

.connection-page .scene-page,
.dashboard-page .scene-page,
.single-page-app .scene-page { padding: 1.1rem; }

.single-page-shell {
  display: grid;
  min-height: calc(100vh - 1.8rem);
}

.connect-split-scene,
.dashboard-workbench {
  display: grid;
  gap: 1rem;
}

.connect-split-scene {
  grid-template-columns: minmax(24rem, 0.92fr) minmax(0, 1.08fr);
  min-height: calc(100vh - 4rem);
  align-items: center;
}

.dashboard-stage-view {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: calc(100vh - 4rem);
  padding: 0.35rem;
  overflow: hidden;
}

.dashboard-stage-view[hidden],
.dashboard-workbench[hidden],
.connect-split-scene[hidden] {
  display: none;
}

.dashboard-stage-frame {
  width: min(calc((100vh - 5.4rem) * 16 / 9), calc(100vw - 3rem));
  aspect-ratio: 16 / 9;
  max-width: 100%;
  max-height: calc(100vh - 5.4rem);
  border-radius: 30px;
  padding: 0.85rem;
  background: linear-gradient(180deg, rgba(255,255,255,0.46), rgba(255,255,255,0.2));
  border: 1px solid rgba(255,255,255,0.68);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.dashboard-stage-canvas {
  width: 100%;
  height: 100%;
  padding: 0;
  border-radius: 26px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255,255,255,0.34), rgba(241,248,250,0.3));
}

.dashboard-stage-canvas .dashboard-workbench {
  width: var(--dashboard-base-width);
  height: var(--dashboard-base-height);
  transform: scale(var(--dashboard-scale));
  transform-origin: top left;
}

.dashboard-stage-canvas .dashboard-workbench,
.dashboard-stage-canvas .left-monitor-column,
.dashboard-stage-canvas .right-pot-column,
.dashboard-stage-canvas .quad-chart-grid,
.dashboard-stage-canvas .log-band,
.dashboard-stage-canvas .mini-chart-card,
.dashboard-stage-canvas .record-card,
.dashboard-stage-canvas .mini-chart-wrap,
.dashboard-stage-canvas .schematic-board,
.dashboard-stage-canvas .pot-illustration,
.dashboard-stage-canvas .table-wrap,
.dashboard-stage-canvas .command-card ul {
  min-height: 0;
}

.dashboard-workbench {
  grid-template-columns: minmax(0, 0.94fr) minmax(0, 1.06fr);
  min-height: 100%;
  height: 100%;
  align-items: stretch;
}

.left-monitor-column,
.right-pot-column,
.floating-terminal,
.pot-stage,
.schematic-board,
.record-card,
.scene-toolbar,
.chart-toolbar-bar,
.mini-chart-card,
.log-band {
  position: relative;
  z-index: 1;
}

.floating-terminal,
.pot-stage,
.schematic-board,
.record-card,
.scene-toolbar,
.chart-toolbar-bar,
.mini-chart-card,
.log-band {
  background: var(--panel-bg);
  border: 1px solid rgba(255,255,255,0.68);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-card);
}

.left-connect-panel {
  align-self: center;
  display: grid;
  align-content: center;
  gap: 1rem;
  min-height: min(34rem, 78vh);
  padding: 1.8rem;
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(255,255,255,0.92), rgba(245,250,251,0.78));
}

.eyebrow {
  display: inline-flex;
  width: fit-content;
  padding: 0.35rem 0.78rem;
  border-radius: 999px;
  background: rgba(60, 191, 181, 0.12);
  color: var(--primary-dark);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

h1 { font-size: clamp(1.65rem, 2.6vw, 2.5rem); line-height: 1.08; }
h2 { font-size: 1.08rem; }
h3 { font-size: 0.98rem; }

.hero-text,
.tip-text,
.status-label,
.chart-toolbar-bar p,
.node-title,
small,
.history-table,
.command-card li,
.latest-values span {
  color: var(--text-soft);
}

.hero-text,
.tip-text,
.chart-toolbar-bar p { line-height: 1.65; }

.terminal-actions { display: grid; gap: 0.7rem; }

.status-card,
.mini-status {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: fit-content;
  padding: 0.85rem 0.95rem;
  border-radius: 16px;
  background: rgba(250, 252, 252, 0.8);
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 6px rgba(255, 122, 122, 0.14);
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 0 6px rgba(57, 191, 123, 0.14);
}

.status-value { margin-top: 0.15rem; font-weight: 700; color: var(--text-main); }

.primary-btn,
.secondary-btn,
.chip-btn,
.node-action {
  border-radius: 999px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.primary-btn:hover,
.secondary-btn:hover,
.chip-btn:hover,
.node-action:hover { transform: translateY(-1px); }

.primary-btn {
  width: 100%;
  padding: 1rem 1.2rem;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #60d7d0);
  box-shadow: 0 14px 24px rgba(60, 191, 181, 0.22);
}

.secondary-btn {
  padding: 0.82rem 1.1rem;
  color: var(--text-main);
  background: rgba(230, 240, 245, 0.96);
}

.large-btn { font-size: 1rem; font-weight: 700; }

.pure-pot-stage,
.pot-board {
  border-radius: 30px;
  overflow: hidden;
  min-height: 0;
}

.stage-grid {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(100, 141, 146, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(100, 141, 146, 0.08) 1px, transparent 1px);
  background-size: 36px 36px;
}

.pot-illustration {
  position: relative;
  width: 100%;
  height: 100%;
}

.dashboard-illustration {
  min-height: 100%;
}

.draggable-board {
  isolation: isolate;
}

.floating-wire-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
  overflow: visible;
}

.floating-wire {
  stroke: rgba(62, 120, 124, 0.72);
  stroke-width: 3;
  stroke-linecap: round;
  filter: drop-shadow(0 0 8px rgba(60, 191, 181, 0.18));
}

.clean-pot-illustration { min-height: 100%; }

.plant-core {
  position: absolute;
  left: 50%;
  top: 56%;
  transform: translate(-50%, -50%);
  width: 24rem;
  height: 21rem;
}

.intro-pot-core { top: 55%; }
.tuned-pot-core { top: 47%; }

.pot-rim {
  position: absolute;
  left: 50%;
  bottom: 6.2rem;
  width: 12rem;
  height: 1.4rem;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #e8a77f, #cf8f63);
  border-radius: 24px;
}

.pot-body {
  position: absolute;
  left: 50%;
  bottom: 0.6rem;
  width: 10.2rem;
  height: 7rem;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #d89569, #ba774f);
  clip-path: polygon(10% 0, 90% 0, 78% 100%, 22% 100%);
  border-radius: 0 0 30px 30px;
  box-shadow: 0 20px 30px rgba(140, 94, 66, 0.18);
}

.soil {
  position: absolute;
  left: 50%;
  bottom: 6.4rem;
  width: 10.2rem;
  height: 2rem;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #745445, #53392e);
  clip-path: ellipse(48% 44% at 50% 50%);
}

.stem {
  position: absolute;
  left: 50%;
  bottom: 8rem;
  width: 0.55rem;
  height: 7rem;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #6fd39c, #2f9f72);
  border-radius: 999px;
}

.leaf {
  position: absolute;
  background: linear-gradient(135deg, #9cf0c0, #43b882 80%);
  border-radius: 100% 0 100% 0;
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.35);
}

.leaf-left { left: 6.9rem; bottom: 12rem; width: 4.2rem; height: 2.6rem; transform: rotate(-30deg); }
.leaf-right { right: 6.8rem; bottom: 12.8rem; width: 4.6rem; height: 2.8rem; transform: rotate(28deg) scaleX(-1); }
.leaf-center {
  position: absolute;
  left: 50%;
  bottom: 14.8rem;
  width: 3.4rem;
  height: 2.2rem;
  transform: translateX(-50%) rotate(-8deg);
  background: linear-gradient(135deg, #baf7cf, #57c58f 85%);
  border-radius: 100% 0 100% 0;
}

.light-beam {
  position: absolute;
  left: 50%;
  top: 0.8rem;
  width: 9rem;
  height: 11rem;
  transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(255, 234, 149, 0.36), rgba(255, 234, 149, 0));
  clip-path: polygon(35% 0, 65% 0, 100% 100%, 0 100%);
}

.left-monitor-column {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 0.8rem;
  min-height: 0;
}

.scene-toolbar,
.chart-toolbar-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 22px;
}

.compact-toolbar { padding: 0.8rem 0.95rem; }
.toolbar-tools { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; justify-content: flex-end; }
.tool-btn { white-space: nowrap; }

.window-selector { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.chip-btn { padding: 0.54rem 0.88rem; background: rgba(233,241,246,0.98); color: var(--text-soft); }
.chip-btn.active { background: var(--text-main); color: #fff; }

.quad-chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 0.8rem;
  min-height: 0;
  align-content: stretch;
}

.mini-chart-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 0.78rem;
  border-radius: 24px;
  min-height: 0;
}

.mini-chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.mini-chart-head strong {
  font-size: 1.1rem;
  color: var(--text-main);
}

.mini-chart-wrap {
  min-height: 0;
  border-radius: 16px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255,255,255,0.76), rgba(241,247,250,0.95));
}

.mini-chart-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 180px;
}

.monitor-latest {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.latest-item {
  min-width: 7.5rem;
  padding: 0.66rem 0.82rem;
  border-radius: 14px;
  background: rgba(247, 251, 252, 0.96);
  border: 1px solid rgba(88, 130, 135, 0.1);
}

.latest-item strong { display: block; margin-top: 0.2rem; font-size: 1rem; }

.right-pot-column {
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(0, 0.5fr);
  gap: 0.8rem;
  min-height: 0;
}

.log-band {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: 0.8rem;
  padding: 0.75rem;
  border-radius: 24px;
  min-height: 0;
  overflow: hidden;
}

.record-card {
  padding: 0.8rem 0.9rem;
  border-radius: 20px;
  min-height: 0;
  overflow: hidden;
}

.command-card ul {
  margin: 0.65rem 0 0;
  padding-left: 1rem;
  height: 100%;
  min-height: 0;
  overflow: auto;
}

.command-card li {
  line-height: 1.5;
  word-break: break-all;
}

.compact-history-card,
.compact-log-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.table-wrap {
  min-height: 0;
  overflow: auto;
  border-radius: 16px;
  margin-top: 0.55rem;
  background: rgba(248, 251, 253, 0.9);
}

.compact-table-wrap { max-height: 100%; }

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.history-table th,
.history-table td {
  padding: 0.62rem 0.58rem;
  text-align: center;
  border-bottom: 1px solid rgba(214, 226, 235, 0.82);
}

.history-table thead th {
  position: sticky;
  top: 0;
  background: rgba(245, 250, 252, 0.98);
}

.empty-cell { color: var(--text-soft); }

.node { position: absolute; }

.floating-window {
  z-index: 4;
  cursor: grab;
  touch-action: none;
}

.floating-window.dragging {
  z-index: 5;
  cursor: grabbing;
}

.floating-window .node-shell {
  position: relative;
  min-width: 9rem;
  padding: 0.78rem 0.95rem;
  border-radius: 18px;
  background: rgba(255,255,255,0.96);
  border: 1px solid rgba(86, 130, 135, 0.22);
  box-shadow: 0 18px 30px rgba(84, 115, 132, 0.16);
}

.node-shell strong { display: block; margin-top: 0.22rem; font-size: 1.15rem; color: var(--text-main); }
.node-shell small { display: block; margin-top: 0.16rem; font-size: 0.78rem; color: var(--text-muted); }
.actionable-shell { min-width: 9.6rem; }
.node-action { margin-top: 0.55rem; padding: 0.56rem 0.86rem; color: #fff; background: linear-gradient(135deg, var(--text-main), #355b67); }

.draggable-node .node-shell {
  user-select: none;
}

.draggable-node .node-action {
  touch-action: manipulation;
}

.light-node { top: 1.4rem; left: 50%; transform: translateX(-50%); }
.air-temp-node { top: 5.2rem; left: 4.8%; }
.co2-node { top: 5.2rem; right: 4.8%; }
.fan-node { top: 15rem; left: 3.4%; }
.light-sensor-node { top: 14.6rem; right: 3.4%; }
.soil-node { bottom: 6.6rem; right: 10.5%; }
.pump-node { bottom: 5.8rem; left: 10.5%; }

@media (max-width: 1200px) {
  .connect-split-scene {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .left-connect-panel {
    min-height: auto;
  }
}

@media (max-width: 960px), (max-height: 760px) {
  .dashboard-stage-view {
    padding: 0.15rem;
  }

  .dashboard-stage-frame {
    width: min(calc((100vh - 2.2rem) * 16 / 9), calc(100vw - 0.4rem));
    max-height: calc(100vh - 2.2rem);
    padding: 0.35rem;
    border-radius: 20px;
  }

  .dashboard-stage-canvas {
    border-radius: 16px;
  }
}
