:root {
  --bg: #0b1220;
  --bg-soft: #111c30;
  --panel: rgba(20, 32, 54, 0.82);
  --panel-border: rgba(148, 163, 184, 0.16);
  --text: #e8eef9;
  --muted: #93a4bd;
  --green: #34d399;
  --blue: #60a5fa;
  --orange: #fb923c;
  --red: #f87171;
  --amber: #fbbf24;
  --radius: 18px;
  --shadow: 0 18px 45px rgba(2, 6, 23, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(circle at 12% 0%, rgba(52, 211, 153, 0.13), transparent 38%),
    radial-gradient(circle at 88% 8%, rgba(96, 165, 250, 0.16), transparent 42%),
    linear-gradient(180deg, var(--bg), var(--bg-soft));
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  width: min(100%, 540px);
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.sub {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.4px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  padding: 7px 11px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.62);
  color: var(--muted);
  font-size: 12px;
}

.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.12);
}

.status.connected .dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.14);
}

.status.connected { color: #bbf7d0; }

.status.error .dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.14);
}

.status.error { color: #fecaca; }

.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.card {
  position: relative;
  overflow: hidden;
  min-height: 124px;
  padding: 15px 16px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  transition: border-color 0.25s, transform 0.25s;
}

.card::after {
  content: "";
  position: absolute;
  inset: auto -30% -65% auto;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.08);
}

.card.accent-green::after { background: rgba(52, 211, 153, 0.12); }
.card.accent-blue::after { background: rgba(96, 165, 250, 0.12); }
.card.accent-orange::after { background: rgba(251, 146, 60, 0.12); }

.card[data-level="warning"] {
  border-color: rgba(251, 191, 36, 0.55);
}

.card[data-level="alarm"] {
  border-color: rgba(248, 113, 113, 0.7);
  background: linear-gradient(145deg, rgba(69, 26, 35, 0.92), rgba(20, 32, 54, 0.88));
}

.card-label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.3px;
}

.card-value {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-top: 10px;
  font-size: 30px;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.card-value small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.card-value.text-value {
  font-size: 24px;
}

.accent-green .card-value { color: var(--green); }
.accent-blue .card-value { color: var(--blue); }
.accent-orange .card-value { color: var(--orange); }
.card[data-level="warning"] .card-value { color: var(--amber); }
.card[data-level="alarm"] .card-value { color: var(--red); }

.card-foot {
  margin-top: 9px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.panel {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.hint {
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
}

.row:first-of-type { border-top: none; }

.row-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.row-info strong {
  font-size: 14px;
  font-weight: 600;
}

.row-info small {
  color: var(--muted);
  font-size: 11px;
}

.stepper {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.4);
  overflow: hidden;
}

.stepper button {
  width: 38px;
  height: 38px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.18s;
}

.stepper button:hover { background: rgba(148, 163, 184, 0.12); }
.stepper button:active { background: rgba(148, 163, 184, 0.22); }

.stepper input {
  width: 68px;
  height: 38px;
  border: none;
  border-left: 1px solid var(--panel-border);
  border-right: 1px solid var(--panel-border);
  background: transparent;
  color: var(--text);
  text-align: center;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  outline: none;
  -moz-appearance: textfield;
}

.stepper input::-webkit-inner-spin-button,
.stepper input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.slider-row span {
  min-width: 52px;
  color: var(--orange);
  font-size: 17px;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--orange) var(--fill, 0%), rgba(148, 163, 184, 0.24) var(--fill, 0%));
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  width: 22px;
  height: 22px;
  border: 3px solid #fff7ed;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 3px 10px rgba(251, 146, 60, 0.45);
  cursor: pointer;
  -webkit-appearance: none;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 3px solid #fff7ed;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 3px 10px rgba(251, 146, 60, 0.45);
  cursor: pointer;
}

input[type="range"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.quick {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 15px;
}

.quick button {
  min-height: 40px;
  padding: 8px 4px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s, transform 0.18s;
}

.quick button:hover { border-color: rgba(251, 146, 60, 0.5); }
.quick button:active { transform: translateY(1px); }
.quick button:disabled { opacity: 0.45; cursor: not-allowed; }

.foot {
  padding: 6px 2px 0;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom));
  z-index: 10;
  max-width: min(86vw, 360px);
  padding: 11px 16px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.96);
  color: var(--text);
  font-size: 13px;
  text-align: center;
  box-shadow: 0 12px 32px rgba(2, 6, 23, 0.55);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.22s, transform 0.22s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error { border-color: rgba(248, 113, 113, 0.6); color: #fecaca; }
.toast.ok { border-color: rgba(52, 211, 153, 0.5); color: #bbf7d0; }

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

@media (max-width: 360px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .card { padding: 13px; min-height: 116px; }
  .card-value { font-size: 26px; }
  .stepper button { width: 34px; }
  .stepper input { width: 60px; }
}
