:root {
  --bg: #07090f;
  --bg-2: #0d111a;
  --panel: rgba(14, 17, 26, 0.88);
  --panel-2: rgba(19, 23, 35, 0.96);
  --line: rgba(255, 255, 255, 0.10);
  --line-2: rgba(255, 255, 255, 0.16);
  --text: #eef2ff;
  --muted: #9ca3af;
  --accent: #fb7185;
  --accent-2: #38bdf8;
  --good: #34d399;
  --warn: #fbbf24;
  --danger: #fb7185;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --radius: 22px;
  --radius-sm: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(251, 113, 133, 0.10), transparent 35%),
    radial-gradient(circle at right center, rgba(56, 189, 248, 0.08), transparent 32%),
    linear-gradient(180deg, #05070d 0%, var(--bg) 100%);
}

a { color: inherit; }
button, input { font: inherit; }

.page-shell {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
  gap: 20px;
  align-items: stretch;
  margin-bottom: 22px;
}

.eyebrow, .panel-kicker {
  margin: 0 0 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: #fda4af;
}

h1 {
  margin: 0;
  font-size: clamp(2.2rem, 4vw, 4.2rem);
  line-height: 0.95;
}

.lede {
  max-width: 72ch;
  margin: 14px 0 0;
  color: #cbd5e1;
  font-size: 1.02rem;
  line-height: 1.65;
}

.mqtt-feed {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  padding-right: 4px;
}

.mqtt-feed .feed-row {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
}

.mqtt-feed .feed-topic {
  font-size: 0.78rem;
  color: #93c5fd;
  word-break: break-all;
}

.mqtt-feed .feed-payload {
  margin-top: 4px;
  font-size: 0.84rem;
  color: #e5e7eb;
}

.mqtt-feed .feed-meta {
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--muted);
}

.live-stream {
  scrollbar-color: rgba(248, 113, 113, 0.55) rgba(255, 255, 255, 0.05);
}

.pid-tuning-grid {
  margin-top: 12px;
}

.pid-tuning-grid label {
  display: grid;
  gap: 6px;
}

.pid-tuning-grid input {
  width: 100%;
}

.channel.pulse,
.channel.relay-pulse {
  animation: relayPulse 180ms ease-out;
}

@keyframes relayPulse {
  0% { transform: translateY(0); box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.0); }
  40% { transform: translateY(-1px); box-shadow: 0 0 0 6px rgba(251, 191, 36, 0.16); }
  100% { transform: translateY(0); box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.0); }
}

.hero-card,
.board-panel,
.details-panel,
.sensor-panel {
  background: linear-gradient(180deg, rgba(16, 20, 31, 0.90), rgba(9, 11, 17, 0.94));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.hero-card {
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.hero-stat {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 14px;
  background: rgba(255,255,255,0.02);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  color: var(--muted);
  font-size: 0.82rem;
}

.hero-stat strong {
  font-size: 2rem;
  line-height: 1;
}

.hero-stat span:last-child {
  color: #cbd5e1;
  font-size: 0.88rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, 0.8fr);
  gap: 20px;
  align-items: start;
}

.board-panel, .sensor-panel {
  padding: 18px;
}

.details-panel {
  padding: 18px;
  position: sticky;
  top: 18px;
}

.panel-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.panel-head.slim { align-items: center; }
.panel-head h2, .panel-head h3 { margin: 0; }
.panel-head h2 { font-size: 1.3rem; }

.legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  color: #d1d5db;
  font-size: 0.86rem;
}
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 10px;
}
.swatch {
  width: 12px; height: 12px; border-radius: 999px; display: inline-block;
}
.swatch.analog { background: var(--accent-2); }
.swatch.digital { background: var(--warn); }
.swatch.output { background: var(--good); }
.swatch.live { background: var(--accent); }

.banks-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.channel-bank {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 14px;
  background: rgba(255,255,255,0.02);
}

.bank-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.bank-title h3 {
  margin: 0;
  font-size: 1rem;
}

.bank-title span {
  color: var(--muted);
  font-size: 0.85rem;
}

.channel-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.channel-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.channel {
  text-align: left;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 18px;
  padding: 14px;
  background: rgba(8, 10, 16, 0.98);
  color: var(--text);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
  min-height: 118px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.channel:hover,
.channel:focus-visible,
.sensor-card:hover,
.sensor-card:focus-visible,
.mqtt-actions button:hover,
.mqtt-actions button:focus-visible {
  transform: translateY(-2px);
  outline: none;
  border-color: rgba(255,255,255,0.28);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.channel.selected {
  border-color: rgba(251, 113, 133, 0.8);
  box-shadow: 0 0 0 1px rgba(251, 113, 133, 0.26), 0 16px 36px rgba(251, 113, 133, 0.14);
}

.channel.live {
  border-color: rgba(52, 211, 153, 0.65);
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.18);
}

.channel.alert {
  border-color: rgba(245, 158, 11, 0.72);
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.16);
}

.channel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.channel-id {
  font-size: 1.2rem;
  font-weight: 700;
}

.badge {
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge.analog { background: rgba(56, 189, 248, 0.12); color: #bae6fd; }
.badge.digital { background: rgba(251, 191, 36, 0.12); color: #fef08a; }
.badge.output { background: rgba(52, 211, 153, 0.12); color: #bbf7d0; }

.channel-name {
  font-size: 0.9rem;
  color: #dbe4f0;
  line-height: 1.35;
}

.channel-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.76rem;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.03);
  color: #cbd5e1;
}

.status-pill {
  border-radius: 999px;
  padding: 9px 12px;
  font-size: 0.8rem;
  border: 1px solid rgba(255,255,255,0.12);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #fde68a;
  background: rgba(245, 158, 11, 0.09);
}
.status-pill.analog { color: #bae6fd; background: rgba(56, 189, 248, 0.10); }
.status-pill.digital { color: #fde68a; background: rgba(245, 158, 11, 0.10); }
.status-pill.output { color: #bbf7d0; background: rgba(52, 211, 153, 0.10); }
.status-pill.live { color: #86efac; background: rgba(52, 211, 153, 0.10); }
.status-pill.offline { color: #fca5a5; background: rgba(251, 113, 133, 0.10); }

.detail-card, .mqtt-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  background: rgba(255,255,255,0.03);
  margin-bottom: 14px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.detail-row:last-of-type { border-bottom: 0; }
.detail-row span { color: var(--muted); }
.detail-row strong { text-align: right; }
.detail-copy, .mqtt-card p, .compat-card p, .wiring-card p { color: #d8deea; line-height: 1.6; }

.mqtt-card h3 {
  margin: 0 0 10px;
}

.mqtt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0;
}

.mqtt-grid label,
.slider-wrap,
.toggle-row {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: #dbe4f0;
  font-size: 0.86rem;
}

.mqtt-grid input,
.override-panel input[type="text"],
.slider-wrap input,
input[type="text"] {
  width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(8, 10, 16, 0.98);
  color: var(--text);
  padding: 11px 12px;
}

.mqtt-status-row {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 10px;
  align-items: center;
  margin: 12px 0 14px;
}

.mini-readout {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mini-readout span { color: var(--muted); font-size: 0.78rem; }
.mini-readout strong { font-size: 1.05rem; }

.slider-wrap {
  margin: 10px 0 12px;
}
.slider-wrap input[type="range"] {
  padding: 0;
}
.slider-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #cbd5e1;
}

.mqtt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.mqtt-actions button {
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(251, 113, 133, 0.14);
  color: #ffe4e6;
  padding: 10px 12px;
  border-radius: 14px;
  cursor: pointer;
}

.mqtt-actions button.ghost { background: rgba(255,255,255,0.04); color: #e5e7eb; }

.toggle-row {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  margin: 4px 0 10px;
}
.toggle-row input { width: 18px; height: 18px; }

.mqtt-note, .helper-text {
  color: var(--muted);
  margin: 0;
}

.graph-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255,255,255,0.03);
  padding: 16px;
  margin-bottom: 14px;
}

.graph-card h3 {
  margin: 4px 0 12px;
  font-size: 1.05rem;
}

.graph-wrap {
  position: relative;
  min-height: 180px;
}

.graph-wrap svg {
  display: block;
  width: 100%;
  height: auto;
}

.graph-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
  padding: 20px;
}

.overlay-panel {
  margin: 20px 0;
  padding: 18px;
  background: linear-gradient(180deg, rgba(16, 20, 31, 0.90), rgba(9, 11, 17, 0.94));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.overlay-stage {
  position: relative;
  margin-top: 10px;
  border-radius: 24px;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  background: radial-gradient(circle at top, rgba(255,255,255,0.10), transparent 38%), #111827;
  border: 1px solid rgba(255,255,255,0.10);
}

.overlay-stage img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #fff;
}

.overlay-layer {
  display: none;
}

.overlay-callout {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  max-width: min(220px, 34%);
  padding: 5px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(7, 9, 15, 0.78);
  backdrop-filter: blur(8px);
  color: #f8fafc;
  box-shadow: 0 10px 24px rgba(0,0,0,0.32);
  transform: translate(-50%, -50%);
}

.overlay-callout::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #fb7185;
  box-shadow: 0 0 0 4px rgba(251, 113, 133, 0.12);
  flex: 0 0 auto;
}

.overlay-callout strong {
  font-size: 0.72rem;
  line-height: 1;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.overlay-callout span {
  display: none;
}

.overlay-chip {
  display: none;
}

.overlay-callout.active {
  border-color: rgba(56, 189, 248, 0.85);
  background: rgba(14, 22, 32, 0.88);
}

.overlay-callout.selected-sensor {
  border-color: rgba(251, 113, 133, 0.8);
  background: rgba(32, 12, 18, 0.78);
}

.sensor-panel { margin-top: 20px; }

.sensor-detail-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255,255,255,0.03);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.sensor-detail-card h3 {
  margin: 4px 0 0;
  font-size: 1.15rem;
}

.sensor-detail-card p {
  margin: 10px 0 0;
  color: #d7deea;
  line-height: 1.55;
}

.detail-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.tag-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.sensor-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.sensor-card {
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 18px;
  padding: 14px;
  background: rgba(8, 10, 16, 0.96);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
  min-height: 170px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sensor-card.selected {
  border-color: rgba(251, 113, 133, 0.8);
  box-shadow: 0 0 0 1px rgba(251, 113, 133, 0.26), 0 16px 36px rgba(251, 113, 133, 0.14);
}
.sensor-card h3 { margin: 0; font-size: 1.02rem; }
.sensor-card p { margin: 0; color: #d7deea; line-height: 1.55; }
.sensor-card .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.chip {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.chip.analog { background: rgba(56, 189, 248, 0.14); color: #bae6fd; }
.chip.digital { background: rgba(251, 191, 36, 0.14); color: #fef08a; }
.chip.output { background: rgba(52, 211, 153, 0.14); color: #bbf7d0; }
.chip.live { background: rgba(251, 113, 133, 0.14); color: #fecdd3; }
.chip.note { background: rgba(255,255,255,0.06); color: #e5e7eb; }
.chip.override { background: rgba(168, 85, 247, 0.14); color: #ddd6fe; }
.badge.analog-output { background: rgba(52, 211, 153, 0.18); color: #bbf7d0; }

.footer-note {
  margin-top: 18px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  color: #cbd5e1;
  font-size: 0.9rem;
  padding: 0 4px;
}
.footer-note code {
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  padding: 2px 8px;
}

@media (max-width: 1180px) {
  .hero, .layout { grid-template-columns: 1fr; }
  .details-panel { position: static; }
  .sensor-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .channel-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .page-shell { width: min(100% - 18px, 100%); padding-top: 12px; }
  .hero-card { grid-template-columns: 1fr; }
  .channel-grid, .sensor-grid, .mqtt-grid, .mqtt-status-row { grid-template-columns: 1fr; }
  .legend { gap: 8px; }
  .footer-note { flex-direction: column; }
}
