:root {
  color-scheme: light;
  font-family: "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  color: #203443;
  background: #eef4f5;
  --ink: #203443;
  --muted: #526879;
  --line: #d9e6e9;
  --accent: #096459;
  --panel: #ffffff;
  --heart: #9c3954;
  --breath: #157580;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; white-space: nowrap; }
button:disabled { opacity: .55; cursor: wait; }
:focus-visible { outline: 3px solid #2ca899; outline-offset: 3px; }
[hidden] { display: none !important; }

h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.65rem, 3vw, 2.2rem); line-height: 1.2; letter-spacing: -.035em; }
h2 { font-size: 1.23rem; line-height: 1.35; margin-bottom: 1rem; }
h3 { font-size: 1rem; line-height: 1.4; margin: 1rem 0 .5rem; }
p { line-height: 1.55; }
.subtle, footer { color: var(--muted); }
.form-error { color: #8b2c45; }

.layout {
  display: grid;
  min-height: 100dvh;
  grid-template-columns: 236px minmax(0, 1fr);
}
.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  align-self: start;
  gap: 2.35rem;
  height: 100dvh;
  padding: 26px 20px;
  border-right: 1px solid var(--line);
  background: #f8fbfb;
}
.wordmark {
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 1.05rem;
  font-weight: 750;
  letter-spacing: -.03em;
  color: #174640;
}
.wordmark-icon {
  flex-shrink: 0;
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 11px;
  background: #096459;
  color: white;
  font-size: 1.02rem;
}
nav { display: grid; gap: 5px; }
nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 46px;
  padding: 11px 12px;
  border-radius: 9px;
  white-space: nowrap;
  font-weight: 540;
  color: #476075;
}
nav a:hover { background: #eef5f4; }
nav a[aria-current] { color: #07594f; background: #dcefeb; font-weight: 720; }
.nav-marker { width: 7px; height: 7px; border-radius: 50%; border: 1px solid #78909f; }
nav a[aria-current] .nav-marker { background: var(--accent); border-color: transparent; }
.account { margin-top: auto; display: grid; gap: 9px; color: var(--muted); overflow-wrap: anywhere; }

.workspace { width: 100%; max-width: 1320px; padding: 32px clamp(16px, 4vw, 56px); }
.page-header { display: flex; align-items: end; justify-content: space-between; flex-wrap: wrap; gap: 16px; margin: 6px 0 24px; }
.device-picker { display: flex; align-items: center; gap: 8px; max-width: 100%; }
.device-picker label { color: var(--muted); font-size: .88rem; }
.device-picker select { width: min(340px, 42vw); min-width: 0; }

.panel {
  padding: clamp(17px, 2.4vw, 26px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  margin: 0 0 16px;
  min-width: 0;
}
.empty { text-align: center; padding-block: 40px; }
.empty-state { color: var(--muted); padding: 18px; border-radius: 10px; background: #f3f8f9; line-height: 1.55; }
.inline { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.notice { padding: 12px 16px; border-radius: 9px; margin: 0 0 16px; border: 1px solid var(--line); }
.panel > button { margin-top: 15px; }
.copy-area { width: 100%; min-height: 120px; margin-bottom: 12px; padding: 12px; font: inherit; border: 1px solid var(--line); border-radius: 8px; }
.pill { padding: 5px 10px; border-radius: 999px; font-size: .86rem; line-height: 1.35; font-weight: 650; display: inline-block; }
.green { color: #085a4a; background: #e0f2e9; }
.amber { color: #724717; background: #fff2de; }
.blue { color: #235778; background: #e9f2fb; }
.neutral { color: #445c6d; background: #edf3f5; }
.live-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 20px 25px;
  color: #e3f5ef;
  background: #174a46;
  border-radius: 14px;
  margin-bottom: 16px;
}
.live-banner strong { font-size: 1.15rem; color: white; }
.live-banner p { margin-top: 4px; }
.live-banner .subtle { color: #c6e1da; font-size: .9rem; }

.metrics, .stats { display: grid; gap: 15px; grid-template-columns: repeat(2,minmax(0,1fr)); }
.metrics { margin-bottom: 16px; }
.metric, .stat-card { border: 1px solid var(--line); border-radius: 13px; padding: clamp(16px,2.4vw,26px); }
.metric.heart, .stat-card.heart { background: #fff8fa; color: var(--heart); }
.metric.breath, .stat-card.breath { background: #f1fafb; color: var(--breath); }
.metric-label, .metric-value { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.metric-label { font-size: 1.02rem; font-weight: 700; align-items: center; }
.metric-marker { width: 9px; height: 9px; background: currentColor; border-radius: 50%; }
.metric-value { color: var(--ink); margin: 8px 0 4px; }
.metric-value strong { font-size: clamp(2.7rem, 6vw, 4.3rem); font-weight: 680; line-height: 1; font-variant-numeric: tabular-nums; }
.metric-value span, .metric p { font-size: .9rem; color: var(--muted); }
.stat-card h3 { margin-top: 0; }
.facts { display: grid; grid-template-columns: repeat(auto-fit,minmax(142px,1fr)); margin: 0; gap: 18px; }
.stat-card .facts { grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px; }
dt { font-size: .86rem; color: var(--muted); margin: 0 0 5px; }
dd { color: var(--ink); font-weight: 650; margin: 0; line-height: 1.4; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

.filters-form, .inline-form, .settings-form {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 13px;
}
.settings-form { display: grid; grid-template-columns: repeat(auto-fit,minmax(168px,1fr)); }
.settings-form button { justify-self: start; }
.panel > .inline-form, .family-form { margin-top: 18px; }
.field, .stack label { display: grid; gap: 7px; color: #3f5569; font-size: .92rem; }
input:not([type=checkbox]), select, button {
  border: 1px solid #c5d6dc;
  border-radius: 8px;
  padding: 9px 12px;
  min-height: 42px;
  max-width: 100%;
  background: white;
  color: var(--ink);
}
button.primary { background: var(--accent); color: white; font-weight: 660; border-color: var(--accent); }
button.primary:hover { background: #084f47; }
button.quiet:hover { background: #e5f1ef; }
.family-form { border-top: 1px solid var(--line); padding-top: .75rem; }
.family-form > button { margin-top: 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 12px; margin: 10px 0 0; padding: 10px; border: 1px solid var(--line); border-radius: 8px; }
.checks legend { padding: 0 5px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }

.trend-chart, .night-bar { display: block; width: 100%; height: 178px; }
.night-bar { height: 53px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; padding-top: 6px; }
.legend span { color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: .7rem; height: .7rem; margin-right: 5px; border-radius: 2px; background: #908999; }
.legend .legend-absent::before { background: #a7bac7; }
.legend .legend-rest::before { background: #238779; }
.legend .legend-quiet::before { background: #5ab2a0; }
.legend .legend-motion::before { background: #e8aa55; }
.legend .legend-sustained_motion::before { background: #d67740; }
.legend .legend-present_uncertain::before { background: #7b8faf; }
.legend .legend-weak_signal::before { background: #ad8eb7; }
.legend .legend-no_data::before { background: #e5ecef; }
.table-scroll { width: 100%; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 525px; }
th, td { padding: 10px 9px; text-align: left; border-bottom: 1px solid #e8eff1; }
th { color: var(--muted); font-size: .87rem; }
td { line-height: 1.4; font-variant-numeric: tabular-nums; }
footer { font-size: .88rem; padding: 10px 0 4px; line-height: 1.55; }

.login-page { display: grid; min-height: 100dvh; align-items: center; padding: 18px; }
.login-card {
  width: min(100%, 420px);
  margin: auto;
  padding: clamp(24px, 7vw, 42px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
  box-shadow: 0 16px 35px #233f4810;
}
.login-card h1 { margin: 28px 0 24px; }
.stack { display: grid; gap: 16px; }

@media (max-width: 850px) {
  .layout { grid-template-columns: minmax(0,1fr); }
  .sidebar { position: static; height: auto; gap: 10px; padding: 13px 16px 8px; border-right: none; border-bottom: 1px solid var(--line); flex-direction: row; flex-wrap: wrap; }
  .account { display: flex; align-items: center; gap: 6px; margin: 0 0 0 auto; font-size: .87rem; }
  .account button { min-height: 36px; }
  nav { order: 2; display: flex; gap: 4px; overflow-x: auto; width: 100%; }
  nav a { min-height: 38px; padding: 7px 9px; font-size: .92rem; }
  .nav-marker { display: none; }
  .workspace { padding-top: 21px; }
  .page-header { align-items: start; }
}
@media (max-width: 520px) {
  .metrics, .stats { gap: 9px; }
  .metrics .metric, .stat-card { padding: 13px; }
  .stat-card .facts { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .live-banner { padding: 15px; }
  .facts { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
  .device-picker { flex-wrap: wrap; width: 100%; }
  .device-picker select { flex: 1; }
  .device-picker label { width: 100%; }
}

.device-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,290px),1fr));gap:1rem;align-items:start}
.device-grid>.panel{margin:0;min-width:0;padding:1rem 1.2rem}
.device-grid h2,.device-grid p{margin:.35rem 0}.device-grid .facts{font-size:.88rem}
.device-grid details.panel{padding:.5rem 0;margin:0;border:0;box-shadow:none}
.readings{display:grid;grid-template-columns:1fr 1fr;gap:.6rem;margin:.75rem 0}
.reading{display:grid;grid-template-columns:auto 1fr;gap:.1rem .4rem;align-items:baseline;background:#eef6f4;border-radius:.6rem;padding:.6rem .8rem;color:#17544c;text-decoration:none}
.reading.heart{color:#84324b;background:#faf0f3}.reading span{grid-column:1/-1;font-size:.85rem}
.reading strong{font-size:1.6rem;line-height:1.15}.reading small{font-size:.7rem}
.reading.no-reading strong{font-size:1.15rem;grid-column:1/-1}
.reading:hover,.reading:focus-visible{outline:2px solid currentColor}
.chart-controls{display:flex;flex-wrap:wrap;gap:.4rem}.chart-controls .quiet{min-height:36px;padding:.25rem .75rem}
.chart-detail{display:block;min-height:2em;font-size:.87rem;color:#3b5360}.trend-chart{cursor:crosshair}
.coverage-ring{display:block;width:180px;height:180px;max-width:100%;margin:0 auto}
.alert-item{border-bottom:1px solid var(--line);padding:.8rem 0}.alert-item summary{cursor:pointer;line-height:1.65}
.audit-panel{overflow-wrap:anywhere}.device-grid .facts dd{overflow-wrap:anywhere}.wordmark{line-height:1.4}
@media(max-width:600px){.device-grid>.panel{padding:.85rem}.workspace{min-width:0}.chart-controls .quiet{min-height:40px}}

.management-grid{grid-template-columns:repeat(auto-fit,minmax(min(100%,350px),1fr))}
.management-grid .facts{grid-template-columns:repeat(2,minmax(0,1fr));gap:.65rem}
.card-detail{border-top:1px solid var(--line);padding:.65rem 0;margin-top:.4rem}
.card-detail summary{cursor:pointer;font-weight:600;line-height:1.5}
.card-detail[open]>summary{margin-bottom:.65rem}
.compact-form{display:grid;gap:.65rem}.card-actions{display:flex;flex-wrap:wrap;gap:.5rem;margin:.8rem 0}
.danger{background:#fff4f3;color:#9c283a;border:1px solid #e2b8be;border-radius:8px;padding:.6rem 1rem;min-height:40px}
.account-grid .inline-form{margin:.5rem 0}.card-detail .table-scroll{max-height:380px;overflow:auto}
.device-rule-button{display:inline-flex;align-items:center;justify-content:center;gap:.9rem;min-height:46px;max-width:100%;box-sizing:border-box;padding:.7rem 1rem;background:#086b60;color:#fff;border:1px solid #086b60;border-radius:9px;font-size:1rem;font-weight:700;line-height:1.5;text-decoration:none;box-shadow:0 2px 4px #086b6026}
.device-rule-button:hover{background:#07554d;border-color:#07554d;color:#fff}
.device-rule-button:focus-visible{outline:3px solid #e4a52f;outline-offset:3px}
.device-rule-button .rule-arrow{font-size:1.25em;line-height:1;flex-shrink:0}
@media(max-width:520px){.device-rule-button{width:100%;gap:.5rem}}
