:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #0f766e;
  --accent-weak: #e6f4f2;
  --blue: #1d4ed8;
  --green: #16a34a;
  --orange: #ea580c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--accent); }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  letter-spacing: .01em;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, #0f766e, #115e59 55%, #1e3a8a);
  display: inline-block;
}

.tabs { display: flex; gap: 4px; }

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
}

.tab:hover { background: #f1f5f9; color: var(--text); }
.tab.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }

.topbar .spacer { flex: 1; }

/* ---------- layout ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 56px; }

.tool-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
  gap: 18px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}

.card h2 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-head h2 { margin: 0; }

.filter-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.filter-toggle input { margin: 0; accent-color: var(--accent); }

.filter-info { margin-top: 10px; }
.filter-info:empty { display: none; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.row:last-child { margin-bottom: 0; }

label { color: var(--muted); min-width: 64px; }

select {
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

button {
  font: inherit;
  padding: 8px 16px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

button:hover:not(:disabled) { background: #f8fafc; border-color: #cbd5e1; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: #115e59; }
button.danger { background: #b91c1c; border-color: #b91c1c; color: #fff; }
button.danger:hover:not(:disabled) { background: #991b1b; }

.hint { color: var(--muted); font-size: 13px; }

.note {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  color: #92400e;
  font-size: 13px;
  line-height: 1.5;
}

.tip { color: var(--muted); font-size: 13.5px; white-space: pre-line; margin: 0; }

/* ---------- metrics ---------- */
.metric {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
}

.metric:last-of-type { border-bottom: 0; }
.m-name { width: 150px; color: var(--muted); }
.m-value { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; min-width: 84px; }
.m-value.spo2 { color: var(--blue); }
.m-value.hr { color: var(--green); }
.m-value.temp { color: var(--orange); }
.m-unit { color: var(--muted); }

.status-line {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; }
.status-dot.connected { background: var(--blue); }
.status-dot.collecting { background: var(--green); }
.status-dot.stopped { background: var(--orange); }
.status-dot.error { background: #b91c1c; }

/* ---------- docs ---------- */
.docs-grid {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.sidebar { position: sticky; top: 76px; }

.sidebar .card { padding: 16px; }

.sidebar label { display: block; margin-bottom: 6px; }

.sidebar select { width: 100%; margin-bottom: 16px; }

.doc-nav { display: flex; flex-direction: column; gap: 2px; }

.doc-nav button {
  text-align: left;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}

.doc-nav button:hover { background: #f1f5f9; }
.doc-nav button.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }

.doc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 34px;
  min-height: 400px;
  overflow-wrap: break-word;
}

.doc h1, .doc h2, .doc h3, .doc h4, .doc h5 { line-height: 1.3; margin: 1.5em 0 .6em; scroll-margin-top: 70px; }
.doc h1 { font-size: 26px; margin-top: .2em; }
.doc h2 { font-size: 21px; padding-bottom: .3em; border-bottom: 1px solid var(--border); }
.doc h3 { font-size: 17px; }
.doc h4, .doc h5 { font-size: 15px; }
.doc p { margin: .8em 0; }
.doc img { max-width: 100%; border-radius: 8px; border: 1px solid var(--border); margin: 8px 0; }
.doc ul, .doc ol { padding-left: 1.6em; }
.doc li { margin: .3em 0; }
.doc hr { border: 0; border-top: 1px solid var(--border); margin: 1.6em 0; }
.doc blockquote {
  margin: 1em 0;
  padding: 2px 16px;
  border-left: 3px solid #cbd5e1;
  color: var(--muted);
}
.doc blockquote p { margin: .5em 0; }
.doc code {
  background: #f1f5f9;
  border-radius: 5px;
  padding: .15em .4em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .9em;
}
.doc pre {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 1em 0;
}
.doc pre code { background: transparent; color: inherit; padding: 0; font-size: 13px; line-height: 1.6; }

.table-wrap { overflow-x: auto; margin: 1em 0; }
.doc table { border-collapse: collapse; width: 100%; font-size: 14px; }
.doc th, .doc td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.doc th { background: #f8fafc; font-weight: 600; }

.doc-error { color: #b91c1c; }

/* ---------- footer ---------- */
footer { text-align: center; color: var(--muted); font-size: 12.5px; padding: 24px 16px 40px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .tool-grid, .docs-grid { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .doc { padding: 20px; }
  .topbar { padding: 10px 14px; gap: 12px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #16213a;
    --border: #24304a;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --accent: #2dd4bf;
    --accent-weak: rgba(45, 212, 191, .12);
  }
  .tab:hover, .doc-nav button:hover { background: #1e293b; }
  button:hover:not(:disabled) { background: #1e293b; border-color: #334155; }
  .doc code { background: #1e293b; }
  .doc th { background: #1e293b; }
  .doc pre { background: #0b1220; }
  .note { background: #2a2312; border-color: #6b4f12; color: #fcd34d; }
}
