:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #d9e1ea;
  --green: #0b9f6a;
  --green-soft: #e8f7f0;
  --red: #c83a3a;
  --red-soft: #fdecec;
  --amber: #b7791f;
  --amber-soft: #fff7e6;
  --blue: #2368b8;
  --blue-soft: #eaf2ff;
  --radius: 8px;
  --shadow: 0 12px 28px rgba(18, 31, 53, .08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #eef4f3 0%, var(--bg) 38%, #f8fafc 100%);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  background: rgba(255, 255, 255, .86);
  border: 1px solid rgba(217, 225, 234, .92);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}

h1 {
  margin: 4px 0 0;
  font-size: 26px;
  line-height: 1.2;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn,
.mini {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius);
  min-height: 38px;
  padding: 0 14px;
  font-weight: 700;
  transition: .16s ease;
}

.btn.primary {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

.btn.ghost:hover,
.mini:hover {
  border-color: var(--green);
  color: var(--green);
}

.btn:disabled,
.mini:disabled,
.control:disabled {
  cursor: wait;
  opacity: .72;
}

.state-dot {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 11px;
  color: var(--muted);
  background: #eef2f6;
  font-size: 13px;
  font-weight: 700;
}

.state-dot.ok {
  color: var(--green);
  background: var(--green-soft);
}

.state-dot.bad {
  color: var(--red);
  background: #fdecec;
}

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

.side {
  position: sticky;
  top: 16px;
  height: fit-content;
  display: grid;
  gap: 8px;
}

.nav-item {
  height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  text-align: left;
  padding: 0 14px;
  font-weight: 800;
}

.nav-item.active {
  background: var(--panel);
  border-color: var(--line);
  color: var(--green);
  box-shadow: var(--shadow);
}

.content {
  min-width: 0;
}

.panel {
  display: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel.active {
  display: block;
  animation: panelIn .16s ease;
}

@keyframes panelIn {
  from {
    opacity: .55;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 92px;
  background: linear-gradient(180deg, #fff 0%, #fbfcfd 100%);
  position: relative;
  overflow: hidden;
}

.metric:before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: #c7d2de;
}

.metric span,
.device-row span,
.field span,
.endpoint-box span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 12px;
  font-size: 24px;
  line-height: 1.1;
}

.metric strong[data-mode="good"] {
  color: var(--green);
}

.metric strong[data-mode="warn"] {
  color: var(--amber);
}

.metric strong[data-mode="bad"] {
  color: var(--red);
}

.metric:has(strong[data-mode="good"]):before {
  background: var(--green);
}

.metric[data-mode="good"]:before {
  background: var(--green);
}

.metric:has(strong[data-mode="warn"]):before {
  background: var(--amber);
}

.metric[data-mode="warn"]:before {
  background: var(--amber);
}

.metric:has(strong[data-mode="bad"]):before {
  background: var(--red);
}

.metric[data-mode="bad"]:before {
  background: var(--red);
}

.section-title {
  margin: 22px 0 12px;
  font-weight: 900;
  font-size: 16px;
}

.section-title.with-action {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.control {
  border: 1px solid var(--line);
  background: #fbfcfd;
  border-radius: var(--radius);
  min-height: 76px;
  padding: 12px;
  text-align: left;
  position: relative;
  transition: .16s ease;
}

.control:hover {
  border-color: var(--green);
  background: #fff;
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(18, 31, 53, .07);
}

.control span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.control b {
  display: block;
  margin-top: 8px;
  color: var(--green);
  font-size: 20px;
}

.control.danger b {
  color: var(--red);
}

.control.is-running:after {
  content: "执行中";
  position: absolute;
  right: 10px;
  top: 10px;
  color: var(--blue);
  background: var(--blue-soft);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
}

.device-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.device-row div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfcfd;
}

.device-row b {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  font-size: 18px;
  min-width: 54px;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 12px;
  background: #eef2f6;
  color: var(--muted);
}

.device-row div[data-state="on"] {
  border-color: rgba(11, 159, 106, .26);
  background: var(--green-soft);
}

.device-row b[data-state="on"] {
  background: #fff;
  color: var(--green);
}

.device-row div[data-state="off"] {
  border-color: rgba(183, 121, 31, .28);
  background: var(--amber-soft);
}

.device-row b[data-state="off"] {
  background: #fff;
  color: var(--amber);
}

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

.field {
  display: grid;
  gap: 7px;
}

.field.wide {
  grid-column: 1 / -1;
}

.field input,
.field select,
.field textarea,
.test-line input,
.test-line select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
  color: var(--text);
  min-height: 40px;
  padding: 9px 10px;
  outline: none;
}

.field textarea {
  resize: vertical;
  line-height: 1.55;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.test-line input:focus,
.test-line select:focus {
  border-color: var(--green);
  background: #fff;
}

.switch-row {
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
}

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

.endpoint-box {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.endpoint-box div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  overflow: hidden;
}

code {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  color: var(--blue);
  font-size: 13px;
}

.command-list {
  display: grid;
  gap: 10px;
}

.command-row {
  display: grid;
  grid-template-columns: 42px 160px minmax(180px, 1fr) minmax(160px, .7fr);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

.command-row input[type="text"] {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
}

.command-name {
  font-weight: 800;
}

.test-line {
  display: grid;
  grid-template-columns: 220px minmax(160px, 1fr) auto;
  gap: 10px;
  margin-top: 16px;
}

.hint-card {
  min-height: 40px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
  color: var(--muted);
  padding: 9px 10px;
  font-weight: 700;
}

.rule-master {
  margin-bottom: 12px;
}

.rule-list {
  display: grid;
  gap: 10px;
}

.rule-row {
  display: grid;
  grid-template-columns: 42px 1fr 120px 120px 120px 160px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fbfcfd;
}

.rule-row strong {
  display: block;
  font-size: 14px;
}

.rule-row span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.rule-row input,
.rule-row select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 9px;
  width: 100%;
}

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

.list {
  display: grid;
  gap: 8px;
  max-height: 560px;
  overflow: auto;
}

.item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fbfcfd;
  border-left-width: 4px;
}

.item strong {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin-bottom: 4px;
}

.item em {
  min-width: 54px;
  border-radius: 999px;
  padding: 2px 7px;
  background: #eef2f6;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  text-align: center;
  text-transform: uppercase;
}

.item .item-title {
  color: var(--text);
}

.item small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.item.info,
.item.audit,
.item.callback,
.item.done {
  border-left-color: var(--green);
}

.item.warning strong {
  color: var(--amber);
}

.item.error strong,
.item.failed strong {
  color: var(--red);
}

.item.warning {
  border-left-color: var(--amber);
}

.item.error,
.item.failed {
  border-left-color: var(--red);
}

.auth-mask {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(14, 23, 38, .45);
}

.auth-mask.hidden {
  display: none;
}

.auth-box {
  width: min(360px, 100%);
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 18px;
  box-shadow: 0 22px 50px rgba(14, 23, 38, .22);
}

.auth-box h2 {
  margin: 0 0 14px;
}

.auth-box p {
  margin: -6px 0 14px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 13px;
}

.auth-box input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 10px;
  margin-bottom: 12px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  background: #172033;
  color: #fff;
  border-radius: var(--radius);
  padding: 11px 14px;
  box-shadow: 0 18px 36px rgba(14, 23, 38, .22);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: .18s ease;
  overflow-wrap: anywhere;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .side {
    position: static;
    display: flex;
    overflow: auto;
    padding-bottom: 2px;
  }

  .nav-item {
    min-width: 96px;
    text-align: center;
  }

  .metric-grid,
  .control-grid,
  .form-grid,
  .split {
    grid-template-columns: 1fr 1fr;
  }

  .command-row {
    grid-template-columns: 42px 1fr;
  }

  .command-row input[type="text"] {
    grid-column: 1 / -1;
  }

  .rule-row {
    grid-template-columns: 42px 1fr;
  }

  .rule-row input,
  .rule-row select {
    grid-column: 1 / -1;
  }
}

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

  .topbar,
  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .metric-grid,
  .control-grid,
  .form-grid,
  .device-row,
  .split,
  .test-line {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 14px;
  }
}
