:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --line: #d8e2ef;
  --line-strong: #b7c8df;
  --text: #1f2937;
  --muted: #64748b;
  --blue: #2f80ed;
  --blue-soft: #eaf3ff;
  --green: #13966b;
  --green-soft: #eafaf3;
  --red: #df3d43;
  --red-soft: #fff0f1;
  --amber: #b7791f;
  --amber-soft: #fff8e8;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.07);
}

* { box-sizing: border-box; }

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

button,
select,
input {
  font: inherit;
}

button,
select {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: #334155;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 760;
}

button { cursor: pointer; }

code {
  padding: 1px 5px;
  border-radius: 5px;
  background: #eef3f9;
  color: #334155;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
}

.sidebar {
  background: #172033;
  color: #e8eef7;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #2f80ed;
  color: #fff;
  font-size: 20px;
  font-weight: 880;
}

.brand strong {
  display: block;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: #9fb0c7;
  font-size: 12px;
  font-weight: 700;
}

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

.nav button {
  width: 100%;
  min-height: 42px;
  border: 0;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  padding: 0 12px;
}

.nav button.active {
  background: #263752;
  color: #fff;
}

.sidebar-note {
  margin-top: auto;
  border: 1px solid rgba(203, 213, 225, 0.18);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 8px;
  color: #aebcd0;
  font-size: 13px;
  line-height: 1.55;
}

.sidebar-note strong {
  color: #fff;
  font-size: 14px;
}

.sidebar-note a {
  color: #94c5ff;
  text-decoration: none;
  font-weight: 780;
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 74px;
  padding: 15px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(12px);
}

.title-block h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.title-block p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

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

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

.check-pill {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  padding: 0 12px;
  color: #334155;
  font-size: 14px;
  font-weight: 760;
}

.check-pill input {
  width: 17px;
  height: 17px;
  accent-color: var(--blue);
}

.content {
  padding: 18px;
  display: grid;
  gap: 16px;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 16px;
}

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

.kpi-card,
.panel,
.app-card,
.resource-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.kpi-card {
  min-height: 112px;
  padding: 15px;
  box-shadow: var(--shadow);
}

.kpi-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.kpi-value {
  margin-top: 10px;
  font-size: 30px;
  line-height: 1.1;
  font-weight: 860;
  letter-spacing: 0;
}

.kpi-foot {
  margin-top: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(340px, 0.8fr);
  gap: 16px;
}

.panel {
  min-width: 0;
  box-shadow: var(--shadow);
}

.panel-head {
  min-height: 68px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
}

.panel-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

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

.app-card {
  min-height: 134px;
  padding: 14px;
  display: grid;
  gap: 10px;
}

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

.app-title strong {
  font-size: 16px;
}

.status-pill {
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 820;
}

.ok { color: var(--green); }
.warn { color: var(--amber); }
.bad { color: var(--red); }

.status-pill.ok { background: var(--green-soft); color: var(--green); }
.status-pill.warn { background: var(--amber-soft); color: var(--amber); }
.status-pill.bad { background: var(--red-soft); color: var(--red); }

.app-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  font-weight: 650;
}

.resource-list {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.resource-item {
  padding: 13px;
}

.resource-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #334155;
  font-size: 14px;
  font-weight: 800;
}

.bar {
  height: 9px;
  border-radius: 999px;
  overflow: hidden;
  background: #e8eef6;
  margin-top: 10px;
}

.bar span {
  display: block;
  height: 100%;
  width: var(--bar-value, 0%);
  border-radius: inherit;
  background: var(--blue);
}

.bar.warn span { background: #d9961d; }
.bar.bad span { background: var(--red); }

.link-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: 1px solid #9cc9ff;
  border-radius: 7px;
  background: var(--blue-soft);
  color: var(--blue);
  text-decoration: none;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 840px;
}

th,
td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: #f8fbff;
  font-size: 13px;
  font-weight: 840;
}

td {
  color: #263241;
  font-size: 14px;
  font-weight: 650;
}

.device-name {
  display: grid;
  gap: 3px;
}

.device-name strong {
  font-size: 15px;
}

.device-name span {
  color: var(--muted);
  font-size: 12px;
}

.metric-value {
  font-size: 19px;
  font-weight: 860;
  letter-spacing: 0;
}

.metric-unit {
  margin-left: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.history-head {
  align-items: flex-start;
}

.history-tools select {
  max-width: 210px;
}

.chart-summary {
  min-height: 42px;
  padding: 10px 16px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 720;
  border-bottom: 1px solid var(--line);
}

.chart-box {
  height: 430px;
  padding: 14px 16px 18px;
}

.chart-box canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.endpoint-list {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.endpoint-row {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  color: #334155;
  font-size: 14px;
  font-weight: 760;
}

.endpoint-row span:last-child {
  color: var(--muted);
  font-size: 13px;
}

.event-log {
  min-height: 340px;
  max-height: 520px;
  overflow: auto;
  margin: 0;
  padding: 14px 16px;
  color: #334155;
  font: 12px/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

.empty {
  padding: 24px 16px;
  color: var(--muted);
  font-weight: 700;
}

@media (max-width: 1180px) {
  .kpi-grid,
  .app-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .topbar,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions,
  .history-tools {
    width: 100%;
    justify-content: flex-start;
  }

  .top-actions select,
  .history-tools select,
  .history-tools button {
    flex: 1 1 160px;
  }

  .kpi-grid,
  .app-grid {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 12px;
  }

  .chart-box {
    height: 340px;
    padding: 10px;
  }
}
