:root {
  color: #17221e;
  background: #f2f6f4;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --green: #087c59;
  --green-bg: #e7f4ee;
  --yellow: #815b00;
  --yellow-bg: #fff4d8;
  --red: #a83232;
  --red-bg: #fdebea;
  --border: #dce6e1;
  --muted: #5a6b64;
}

* { box-sizing: border-box; }
body { margin: 0; }
button { font: inherit; }

.health-page { max-width: 1180px; margin: 0 auto; padding: 32px; }
.health-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.health-header h1 { margin: 4px 0 8px; font-size: clamp(30px, 4vw, 46px); }
.health-eyebrow { margin: 0; color: var(--green); font-weight: 800; }
.health-intro { max-width: 760px; margin: 0; color: var(--muted); font-size: 17px; line-height: 1.7; }
#refresh-health { border: 0; border-radius: 12px; padding: 12px 20px; background: var(--green); color: #fff; cursor: pointer; white-space: nowrap; }
#refresh-health:disabled { cursor: wait; opacity: .6; }

.health-card, .health-summary, .health-section { background: #fff; border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 10px 32px #173d2b0d; }
.health-loading, .health-error { display: flex; align-items: center; gap: 16px; padding: 24px; }
.health-loading p, .health-error p { margin: 6px 0 0; color: var(--muted); }
.health-error { display: block; border-color: #efb9b5; background: #fffafa; }
.health-error h2 { margin: 0; color: var(--red); }
.health-spinner { width: 30px; height: 30px; border: 4px solid #cfe2da; border-top-color: var(--green); border-radius: 50%; animation: health-spin .8s linear infinite; }
@keyframes health-spin { to { transform: rotate(360deg); } }

.health-summary { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 20px; padding: 24px; border-left: 8px solid var(--green); }
.health-summary.status-attention { border-left-color: #d39b18; }
.health-summary.status-error { border-left-color: var(--red); }
.health-summary-badge, .health-check-badge { display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; font-weight: 800; }
.health-summary-badge { min-width: 90px; min-height: 90px; padding: 15px; background: var(--green-bg); color: var(--green); font-size: 22px; }
.status-attention .health-summary-badge { background: var(--yellow-bg); color: var(--yellow); }
.status-error .health-summary-badge { background: var(--red-bg); color: var(--red); }
.health-summary h2 { margin: 0 0 8px; font-size: 26px; }
.health-summary p { margin: 4px 0; color: var(--muted); line-height: 1.6; }
.health-summary-counts { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.health-summary-counts span { padding: 6px 10px; border-radius: 999px; font-weight: 700; }
.count-healthy { background: var(--green-bg); color: var(--green); }
.count-attention { background: var(--yellow-bg); color: var(--yellow); }
.count-error { background: var(--red-bg); color: var(--red); }

.health-sections { display: grid; gap: 18px; margin-top: 20px; }
.health-section { padding: 22px; }
.health-section h2 { margin: 0 0 14px; font-size: 23px; }
.health-checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.health-check { min-width: 0; padding: 16px; border: 1px solid var(--border); border-radius: 14px; background: #fbfcfb; }
.health-check-wide { grid-column: 1 / -1; }
.health-check.status-attention { border-color: #efd28a; background: #fffdf7; }
.health-check.status-error { border-color: #efb9b5; background: #fffafa; }
.health-check-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.health-check-heading h3 { margin: 0; font-size: 18px; }
.health-check-badge { flex: 0 0 auto; padding: 5px 10px; background: var(--green-bg); color: var(--green); font-size: 13px; }
.status-attention .health-check-badge { background: var(--yellow-bg); color: var(--yellow); }
.status-error .health-check-badge { background: var(--red-bg); color: var(--red); }
.health-check-summary { margin: 12px 0 0; line-height: 1.65; overflow-wrap: anywhere; }
.health-check-action { margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--yellow-bg); color: #654700; line-height: 1.6; }
.status-error .health-check-action { background: var(--red-bg); color: #7d2020; }
.health-check-time { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.health-metrics { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.health-metric { min-width: 0; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.health-metric span { display: block; color: var(--muted); font-size: 12px; line-height: 1.35; }
.health-metric strong { display: block; margin-top: 4px; font-size: 21px; }
.health-metric.metric-healthy { border-color: #b9ddce; background: var(--green-bg); }
.health-metric.metric-attention { border-color: #efd28a; background: var(--yellow-bg); }
.health-metric.metric-error { border-color: #efb9b5; background: var(--red-bg); }
.device-monitor-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.device-monitor-row { min-width: 0; padding: 12px; border: 1px solid var(--border); border-radius: 11px; background: #fff; }
.device-monitor-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.device-monitor-heading strong { display: block; overflow-wrap: anywhere; }
.device-monitor-id { display: block; margin-top: 3px; color: var(--muted); font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.device-state { flex: 0 0 auto; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.device-state-healthy { background: var(--green-bg); color: var(--green); }
.device-state-attention { background: var(--yellow-bg); color: var(--yellow); }
.device-state-error { background: var(--red-bg); color: var(--red); }
.device-monitor-note, .device-monitor-error, .device-monitor-action, .device-monitor-empty { margin: 7px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.device-monitor-error { color: var(--red); font-weight: 700; }
.device-monitor-action { color: #654700; }
.scan-issue-groups { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.scan-issue-group { padding: 12px; border: 1px solid var(--border); border-radius: 11px; background: #fff; }
.scan-issue-group h4 { margin: 0 0 8px; }
.scan-issue-group p { margin: 5px 0; color: var(--muted); line-height: 1.5; overflow-wrap: anywhere; }
.health-details { margin-top: 10px; }
.health-details summary { width: max-content; max-width: 100%; color: var(--muted); cursor: pointer; }
.health-details pre { max-height: 260px; overflow: auto; margin: 8px 0 0; padding: 10px; border-radius: 9px; background: #f1f4f2; font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.health-footnote { margin: 20px 4px 0; color: var(--muted); line-height: 1.6; }

[hidden] { display: none !important; }

@media (max-width: 760px) {
  .health-page { padding: 16px; }
  .health-header { display: block; }
  #refresh-health { width: 100%; margin-top: 16px; }
  .health-summary { grid-template-columns: 1fr; }
  .health-summary-badge { min-width: 0; min-height: 0; width: max-content; font-size: 18px; }
  .health-checks { grid-template-columns: 1fr; }
  .health-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .device-monitor-list, .scan-issue-groups { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .health-spinner { animation: none; }
}
