:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d9e0e7;
  --accent: #0f9f8f;
  --accent-strong: #087f74;
  --accent-soft: #e3f5f2;
  --danger: #c2413b;
  --warn: #e7a83b;
  --sidebar: #101923;
  --sidebar-soft: #1b2734;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 24px 20px;
  background: var(--sidebar);
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  font-size: 15px;
  font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.wave-panel h3 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
}

.brand p {
  margin-top: 4px;
  color: #b7c0cc;
  font-size: 13px;
}

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

.nav-item {
  display: grid;
  gap: 3px;
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  background: transparent;
  color: #c9d3df;
  text-align: left;
  cursor: pointer;
}

.nav-item.active,
.nav-item:hover {
  background: var(--sidebar-soft);
  color: #fff;
}

.nav-item.active {
  box-shadow: inset 4px 0 0 var(--accent);
}

.nav-main {
  font-size: 15px;
  font-weight: 800;
}

.nav-sub {
  color: #8fa0b3;
  font-size: 12px;
}

.nav-item.active .nav-sub,
.nav-item:hover .nav-sub {
  color: #bfd0df;
}

.device-card {
  margin-top: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.06);
}

.device-card strong {
  display: block;
  margin: 10px 0 12px;
  font-size: 22px;
}

.device-card p {
  margin: 7px 0;
  color: #c9d3df;
}

.device-list-card {
  max-height: 310px;
  overflow: auto;
}

.device-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.device-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  border-radius: 8px;
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.07);
  color: #d9e2ec;
  cursor: pointer;
}

.device-row strong {
  overflow: hidden;
  margin: 0;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-row span:last-child {
  color: #aeb9c5;
  font-size: 12px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #8a94a3;
}

.status-dot.online {
  background: #16a085;
}

.status-dot.delayed {
  background: #e7a83b;
}

.status-dot.offline {
  background: #c2413b;
}

.empty-text {
  margin: 0;
  color: #aeb9c5;
  font-size: 13px;
}

.main {
  min-width: 0;
  padding: 26px;
}

.topbar,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar h2 {
  margin-top: 4px;
  font-size: 28px;
  letter-spacing: 0;
}

.section-label {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  min-width: 92px;
  border-radius: 999px;
  padding: 8px 12px;
  background: #e5f6f3;
  color: var(--accent-strong);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

.status-pill.muted {
  min-width: 116px;
  background: #eef1f4;
  color: var(--muted);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin: 20px 0;
}

.metric-card,
.wave-panel,
.history-panel,
.ai-card,
.device-manage-panel,
.alert-panel,
.voice-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 24px rgba(21, 32, 43, 0.05);
}

.metric-card {
  padding: 18px;
}

.metric-card span {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  font-size: 23px;
}

.metric-card.warning strong {
  color: var(--warn);
}

.wave-panel {
  padding: 20px;
  margin-bottom: 18px;
}

.wave-panel h3,
.history-panel h3 {
  margin-top: 5px;
  font-size: 20px;
}

.history-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(420px, 1.5fr);
  align-items: center;
  gap: 20px;
  margin-bottom: 18px;
  padding: 20px 22px;
}

.history-head {
  min-width: 0;
}

.history-head h3 {
  margin-bottom: 8px;
}

.history-toolbar {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 180px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.history-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.field input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
}

.history-controls button {
  min-height: 40px;
  min-width: 74px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

.history-controls button:nth-of-type(2),
.history-controls button:nth-of-type(4) {
  background: #e9eef2;
  color: var(--ink);
}

.history-controls button:nth-of-type(3) {
  background: #2f6fbb;
}

.file-input,
.hidden {
  display: none !important;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.ai-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.ai-card {
  position: relative;
  overflow: hidden;
  border-left: 0;
  padding: 22px 24px 20px;
}

.ai-card::before {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: #8a94a3;
  content: "";
}

.ai-card h3 {
  margin: 8px 0 10px;
  font-size: 28px;
  line-height: 1.25;
}

.ai-card p {
  min-height: 22px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.5;
}

.ai-card strong {
  color: var(--muted);
  font-size: 16px;
}

.ai-card .section-label {
  font-size: 16px;
}

.ai-card.normal {
  border-color: #cfe9e5;
}

.ai-card.warning {
  border-color: #f2dfb9;
}

.ai-card.danger {
  border-color: #edc6c3;
}

.ai-card.pending {
  border-color: #d6dde5;
}

.ai-card.normal::before {
  background: #16a085;
}

.ai-card.warning::before {
  background: #e7a83b;
}

.ai-card.danger::before {
  background: #c2413b;
}

.ai-card.pending::before {
  background: #8a94a3;
}

.canvas-wrap {
  overflow: hidden;
  margin-top: 18px;
  border: 1px solid #dfe5ea;
  border-radius: 8px;
  background: #fff;
}

.device-manage-panel,
.alert-panel,
.voice-panel {
  margin: 20px 0 18px;
  padding: 20px;
}

.voice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.voice-actions button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.voice-actions button:nth-child(2) {
  background: #2f6fbb;
}

.voice-actions button:disabled {
  background: #d8dee6;
  color: #8a94a3;
  cursor: not-allowed;
}

.voice-result {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0 12px;
}

.voice-result article {
  min-height: 130px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfd;
}

.voice-result span {
  display: block;
  margin-bottom: 10px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
}

.voice-result p {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.6;
}

.device-table {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.device-record {
  display: grid;
  grid-template-columns: 140px 1fr 120px 120px 110px;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fbfcfd;
}

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

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

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  border-radius: 999px;
  padding: 5px 10px;
  background: #eef1f4;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-badge.online {
  background: #e3f5f2;
  color: #087f74;
}

.status-badge.delayed {
  background: #fff4dc;
  color: #9a6800;
}

.status-badge.offline,
.status-badge.danger {
  background: #fae7e6;
  color: #a3342e;
}

.status-badge.warning {
  background: #fff4dc;
  color: #9a6800;
}

.alert-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.alert-item {
  display: grid;
  grid-template-columns: 130px 120px 1fr 150px;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--warn);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fff;
}

.alert-item.danger {
  border-left-color: var(--danger);
}

.alert-item strong {
  font-size: 14px;
}

.alert-item span,
.alert-item p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.ghost-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

.empty-state {
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

#ecgCanvas,
#respCanvas,
#tempCanvas {
  display: block;
  width: 100%;
}

#ecgCanvas {
  height: 420px;
}

#respCanvas {
  height: 260px;
}

#tempCanvas {
  height: 220px;
}

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

  .sidebar {
    min-height: auto;
  }

  .nav-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .device-card {
    margin-top: 0;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .device-record,
  .alert-item {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 680px) {
  .main,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .panel-head,
  .history-panel,
  .history-toolbar,
  .history-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .history-panel {
    display: grid;
    grid-template-columns: 1fr;
  }

  .history-toolbar {
    display: grid;
  }

  .history-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-strip {
    width: 100%;
  }

  .status-pill {
    flex: 1;
  }

  .nav-list,
  .metrics,
  .ai-panel {
    grid-template-columns: 1fr;
  }

  .device-record,
  .alert-item,
  .voice-result {
    grid-template-columns: 1fr;
  }

  #ecgCanvas {
    height: 320px;
  }

  #respCanvas {
    height: 220px;
  }

  #tempCanvas {
    height: 200px;
  }
}
