:root {
  --bg: #e8eef9;
  --bg-soft: #f6f8fe;
  --card: rgba(255, 255, 255, 0.9);
  --card-strong: #ffffff;
  --line: rgba(64, 76, 109, 0.09);
  --text: #233047;
  --muted: #76829a;
  --blue: #5e78ff;
  --cyan: #2fd5f4;
  --purple: #6e2edc;
  --pink: #ff5c8a;
  --yellow: #ffd35a;
  --orange: #ff9f80;
  --green: #13bf81;
  --red: #f14a67;
  --navy: #2e4058;
  --shadow: 0 14px 40px rgba(61, 88, 129, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(94, 120, 255, 0.18), transparent 24%),
    radial-gradient(circle at top right, rgba(47, 213, 244, 0.16), transparent 22%),
    linear-gradient(180deg, #f7fbff 0%, #e8eef9 100%);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 18px 120px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 4px 22px;
}

.topbar-tag {
  margin: 0 0 6px;
  color: var(--muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 700;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 52px);
}

.status-pill,
.badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
  font-size: 14px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.status-offline {
  background: #b9c2d6;
}

.status-simulated {
  background: var(--yellow);
}

.status-connected {
  background: var(--green);
}

.badge-outline {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.26);
  box-shadow: none;
}

.badge-safe {
  background: rgba(19, 191, 129, 0.12);
  color: #089764;
}

.badge-alert {
  background: rgba(241, 74, 103, 0.12);
  color: #d13957;
}

.page-body {
  display: grid;
}

.tab-panel {
  display: none;
  animation: fade-in 240ms ease;
}

.tab-panel.is-active {
  display: grid;
  gap: 18px;
}

.hero-card,
.section-card,
.gauge-card,
.monitor-card,
.fault-card {
  background: var(--card);
  border-radius: 30px;
  box-shadow: var(--shadow);
}

.hero-card {
  padding: 24px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 140px;
  min-height: 78px;
  border-radius: 24px;
  color: white;
  font-size: 30px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--blue) 0%, var(--purple) 100%);
}

.hero-card h2,
.fault-head h2,
.card-inline-head h2,
.gauge-head h2 {
  margin: 0 0 8px;
}

.hero-card p,
.hint-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.protocol-legend {
  margin-top: 10px !important;
  max-width: 56ch;
  color: #496372 !important;
}

.hero-actions,
.button-row,
.action-row,
.comm-hero {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.card-stack,
.settings-grid {
  display: grid;
  gap: 16px;
}

.section-card {
  overflow: hidden;
}

.section-card > .card-inline-head,
.section-card > .device-list,
.section-card > .log-view,
.section-card > .field-grid,
.section-card > .hint-text,
.section-card > .settings-list {
  padding-left: 22px;
  padding-right: 22px;
}

.section-card > .card-inline-head {
  padding-top: 22px;
}

.section-card > .device-list,
.section-card > .log-view,
.section-card > .field-grid,
.section-card > .hint-text,
.section-card > .settings-list {
  padding-bottom: 22px;
}

.section-head {
  width: 100%;
  border: 0;
  padding: 22px 28px;
  color: white;
  font-size: 22px;
  font-weight: 800;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, #5e78ff 0%, #7a4bd8 100%);
}

.section-head-peach {
  background: linear-gradient(135deg, #ffcd96 0%, #ffb9ab 100%);
}

.section-head-indigo {
  background: linear-gradient(135deg, #2fd5f4 0%, #4b1fa5 100%);
}

.section-head-yellow {
  background: linear-gradient(135deg, #ff7d99 0%, #ffd83a 100%);
}

.section-head-pink {
  background: linear-gradient(135deg, #ff8ea1 0%, #ffb7f4 100%);
}

.section-head-cyan {
  background: linear-gradient(135deg, #4aa2f0 0%, #35e4e0 100%);
}

.section-body {
  padding: 22px;
}

.section-body.is-collapsed {
  display: none;
}

.section-arrow {
  transition: transform 180ms ease;
}

.section-head.is-collapsed .section-arrow {
  transform: rotate(180deg);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.field-card {
  display: grid;
  gap: 10px;
  padding: 18px;
  border-radius: 24px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  border: 1px solid var(--line);
}

.field-card.is-protocol-field {
  border-color: rgba(16, 132, 95, 0.28);
  box-shadow: 0 10px 24px rgba(18, 140, 100, 0.08);
}

.field-label-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.protocol-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(19, 191, 129, 0.12);
  color: #0f7f58;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.protocol-note {
  display: block;
  margin-top: -2px;
  color: #4f6b7a;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}

.field-card label {
  font-size: 14px;
  font-weight: 700;
}

.field-card input,
.field-card select {
  width: 100%;
  border: 1px solid rgba(94, 120, 255, 0.08);
  border-radius: 18px;
  padding: 14px 16px;
  background: #fbfcff;
  box-shadow: inset 0 2px 10px rgba(152, 166, 199, 0.1);
}

.field-card small {
  color: var(--muted);
}

.quick-tuning-card {
  margin-bottom: 18px;
  padding: 20px;
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(94, 120, 255, 0.14) 0%, rgba(47, 213, 244, 0.14) 100%);
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 18px;
}

.quick-tuning-card h3,
.mini-card h3,
.monitor-card h3 {
  margin: 0 0 10px;
}

.quick-tuning-card p {
  margin: 0;
  line-height: 1.7;
  color: var(--muted);
}

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

.quick-metrics div,
.monitor-card,
.mini-card {
  padding: 16px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.8);
}

.quick-metrics span,
.monitor-card h3 {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.quick-metrics strong,
.monitor-card strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
}

.results-grid,
.monitor-grid,
.comm-grid {
  display: grid;
  gap: 16px;
}

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

.monitor-top {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.gauge-card {
  padding: 22px;
}

.gauge-head,
.card-inline-head,
.fault-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.card-inline-head {
  flex-wrap: wrap;
}

.card-inline-head h2,
.fault-head h2,
.gauge-head h2 {
  flex: 1 1 220px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.dial {
  --value: 0.2;
  --accent: #5e78ff;
  position: relative;
  width: min(100%, 330px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, white 0 48%, transparent 49%),
    conic-gradient(from 220deg, rgba(94, 120, 255, 0.12) 0deg, rgba(94, 120, 255, 0.12) 280deg, transparent 281deg 360deg);
}

.dial::before {
  content: "";
  position: absolute;
  inset: 18px;
  border-radius: 50%;
  border: 16px solid rgba(94, 120, 255, 0.12);
  border-top-color: var(--accent);
  border-right-color: var(--accent);
  transform: rotate(220deg);
}

.dial-needle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 38%;
  background: var(--accent);
  border-radius: 999px;
  transform-origin: bottom center;
  transform: translateX(-50%) translateY(-100%) rotate(calc(-130deg + (var(--value) * 260deg)));
  box-shadow: 0 0 12px rgba(94, 120, 255, 0.3);
}

.dial-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 6px;
}

.dial-center strong {
  font-size: 36px;
}

.dial-center span {
  color: var(--muted);
}

.monitor-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.monitor-card strong {
  font-size: 28px;
}

.gradient-btn,
.primary-btn,
.ghost-btn,
.nav-item,
.file-btn {
  border: 0;
  border-radius: 999px;
  padding: 14px 22px;
  cursor: pointer;
  transition: transform 160ms ease, opacity 160ms ease;
}

.gradient-btn:hover,
.primary-btn:hover,
.ghost-btn:hover,
.nav-item:hover,
.file-btn:hover {
  transform: translateY(-1px);
}

.primary-btn {
  color: white;
  background: linear-gradient(135deg, var(--blue) 0%, var(--purple) 100%);
}

.ghost-btn,
.file-btn {
  color: var(--text);
  background: rgba(94, 120, 255, 0.1);
}

.gradient-purple {
  color: white;
  background: linear-gradient(135deg, #55d6ef 0%, #4b1fa5 100%);
}

.gradient-cyan {
  color: white;
  background: linear-gradient(135deg, #44b8ff 0%, #2fd5f4 100%);
}

.gradient-red {
  color: white;
  background: linear-gradient(135deg, #ff7f87 0%, #f14a67 100%);
}

.gradient-white {
  color: var(--blue);
  background: linear-gradient(135deg, #ffffff 0%, #eff4ff 100%);
  border: 1px solid rgba(94, 120, 255, 0.1);
}

.value-list,
.check-list,
.recommendations,
.settings-list {
  margin: 0;
  padding: 0;
}

.value-list {
  display: grid;
  gap: 12px;
}

.value-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(35, 48, 71, 0.08);
}

.value-list dd {
  margin: 0;
  font-weight: 800;
}

.check-list {
  list-style: none;
  display: grid;
  gap: 10px;
}

.check-list li {
  padding: 10px 12px;
  border-radius: 16px;
  line-height: 1.55;
  background: rgba(238, 243, 255, 0.8);
}

.check-ok {
  border-left: 4px solid var(--green);
}

.check-warn {
  border-left: 4px solid var(--yellow);
}

.check-danger {
  border-left: 4px solid var(--red);
}

.fault-card {
  padding: 24px;
}

.fault-card p {
  margin: 14px 0 0;
  font-size: 18px;
  line-height: 1.7;
}

.device-list {
  display: grid;
  gap: 12px;
  min-height: 180px;
}

.device-item,
.log-item {
  padding: 16px;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffffff 0%, #f6f9ff 100%);
  border: 1px solid var(--line);
}

.device-item strong {
  display: block;
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}

.device-item p,
.log-item p {
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.log-view {
  display: grid;
  gap: 10px;
  max-height: 540px;
  overflow: auto;
}

.log-item time {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.settings-list {
  display: grid;
  gap: 14px;
}

.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.switch-row input {
  width: 22px;
  height: 22px;
}

.panel-dark {
  background: linear-gradient(180deg, #24344f 0%, #1f2b42 100%);
  color: white;
}

.panel-dark .recommendations {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.recommendation-card {
  padding: 18px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.08);
}

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

.recommendation-card p {
  margin: 0;
  color: rgba(255, 255, 255, 0.76);
  line-height: 1.7;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: min(100% - 24px, 760px);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
  box-shadow: 0 18px 45px rgba(56, 78, 116, 0.22);
}

.nav-item {
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  font-weight: 700;
}

.nav-item.is-active {
  color: white;
  background: linear-gradient(135deg, var(--blue) 0%, var(--purple) 100%);
}

.file-btn input {
  display: none;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 960px) {
  .hero-card,
  .quick-tuning-card,
  .monitor-top,
  .results-grid,
  .monitor-grid,
  .comm-grid,
  .panel-dark .recommendations,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .hero-card {
    grid-template-columns: 1fr;
  }

  .comm-hero {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding-inline: 12px;
  }

  .topbar {
    padding-bottom: 16px;
  }

  .section-head {
    padding-inline: 18px;
    font-size: 18px;
  }

  .section-body,
  .gauge-card,
  .fault-card,
  .hero-card {
    padding: 18px;
  }

  .dial-center strong {
    font-size: 28px;
  }

  .comm-hero,
  .action-row,
  .button-row,
  .hero-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .gradient-btn,
  .primary-btn,
  .ghost-btn,
  .file-btn {
    width: 100%;
    justify-content: center;
    text-align: center;
    padding: 13px 16px;
  }

  .status-pill,
  .badge-pill {
    max-width: 100%;
    white-space: normal;
    line-height: 1.4;
  }

  .card-inline-head,
  .fault-head,
  .gauge-head {
    align-items: flex-start;
  }

  .card-inline-head h2,
  .fault-head h2,
  .gauge-head h2 {
    flex-basis: 100%;
    font-size: 18px;
    line-height: 1.3;
  }

  .section-card > .card-inline-head,
  .section-card > .device-list,
  .section-card > .log-view,
  .section-card > .field-grid,
  .section-card > .hint-text,
  .section-card > .settings-list {
    padding-left: 16px;
    padding-right: 16px;
  }

  .section-card > .card-inline-head {
    padding-top: 16px;
  }

  .section-card > .device-list,
  .section-card > .log-view,
  .section-card > .field-grid,
  .section-card > .hint-text,
  .section-card > .settings-list {
    padding-bottom: 16px;
  }

  .device-item,
  .log-item,
  .field-card,
  .monitor-card,
  .mini-card {
    padding: 14px;
  }
}
