/* 用户侧 H5：只读设备状态页（Spec 14.5）
   视觉沿用现场端 webview 的布局语言：深色顶栏 + 浅色内容区 + 卡片式设备总览。
   本文件不含任何设备管理 / 同步配置 / VNC / 报警灯样式。 */

:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e3e6ea;
  --text: #1a1d21;
  --muted: #6b7280;
  --head: #232b36;
  --head-text: #e8edf3;
  --brand: #0f6e56;
  --brand-weak: #e6f4ef;
  --online: #16a34a;
  --offline: #6b7280;
  --alarm: #dc2626;
  --unknown: #d97706;
  --disabled: #9ca3af;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 顶栏 ---------- */
header.top {
  background: var(--head);
  color: var(--head-text);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 56px;
  flex-wrap: wrap;
}

header.top h1 {
  font-size: 16px;
  font-weight: 500;
  margin: 0;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

nav.menu {
  display: flex;
  gap: 4px;
  flex: 1;
  flex-wrap: wrap;
}

nav.menu button {
  background: transparent;
  border: 0;
  color: #aeb9c7;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}

nav.menu button:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
nav.menu button.active { background: var(--brand); color: #fff; }

.head-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: #aeb9c7;
}

.head-right button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #d6dee8;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}

.head-right button:hover { background: rgba(255, 255, 255, 0.1); }

/* ---------- 站点栏 ---------- */
.site-bar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13px;
}

.site-bar select {
  font-family: inherit;
  font-size: 13px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid transparent;
}

.chip.ok { background: #e8f7ee; color: #15803d; border-color: #c6ecd5; }
.chip.bad { background: #fdeaea; color: #b91c1c; border-color: #f6cfcf; }
.chip.warn { background: #fdf3e3; color: #b45309; border-color: #f5e0bd; }
.chip.mute { background: #eef0f3; color: var(--muted); border-color: #e0e3e8; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

/* ---------- 报警条 ---------- */
#alarm-bar {
  display: none;
  background: #fdeaea;
  border-bottom: 1px solid #f6cfcf;
  color: #991b1b;
  padding: 8px 20px;
  font-size: 13px;
  overflow-x: auto;
  white-space: nowrap;
}

#alarm-bar .item { margin-right: 18px; }

/* ---------- 内容 ---------- */
main#content { padding: 18px 20px 32px; }

.group-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 10px;
  font-size: 14px;
  font-weight: 500;
  color: #374151;
}

.group-title::before {
  content: "";
  width: 3px;
  height: 14px;
  background: var(--brand);
  border-radius: 2px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(228px, 1fr));
  gap: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px 10px;
  border-top: 3px solid var(--offline);
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
}

.card:hover { box-shadow: 0 3px 12px rgba(15, 23, 42, 0.08); transform: translateY(-1px); }
.card.online { border-top-color: var(--online); }
.card.alarm { border-top-color: var(--alarm); }
.card.unknown { border-top-color: var(--unknown); }
.card.disabled { border-top-color: var(--disabled); }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.card-head .name {
  font-weight: 500;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-head .rec { font-size: 11px; color: var(--muted); }

.metric {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 2px 0;
  color: #4b5563;
}

.metric .v { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 500; }

.card-foot {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px dashed var(--line);
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- 表格 ---------- */
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
  max-height: 62vh;
}

table.data {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  white-space: nowrap;
}

table.data th, table.data td {
  border-bottom: 1px solid var(--line);
  padding: 7px 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

table.data th {
  background: #fafbfc;
  position: sticky;
  top: 0;
  font-weight: 500;
  color: #4b5563;
  z-index: 1;
}

table.data th:first-child, table.data td:first-child { text-align: left; }
table.data tbody tr:hover { background: #f8fafb; }

.sev {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid transparent;
}
.sev.critical, .sev.error { background: #fdeaea; color: #b91c1c; border-color: #f6cfcf; }
.sev.warning { background: #fdf3e3; color: #b45309; border-color: #f5e0bd; }
.sev.info { background: #eef2f8; color: #3b5b8c; border-color: #dbe4f0; }

/* ---------- 工具条 ---------- */
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: 13px;
}

.toolbar select, .toolbar input {
  font-family: inherit;
  font-size: 13px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.toolbar button {
  font-family: inherit;
  font-size: 13px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}

.toolbar button:hover { border-color: #c9cfd6; background: #fafbfc; }
.toolbar button.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.toolbar .seg { display: flex; gap: 4px; }

/* ---------- 图表 ---------- */
.chart-box canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.chart-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  height: 420px;
  position: relative;
}

/* ---------- 详情弹层 ---------- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
  z-index: 50;
  padding: 40px 20px;
  overflow-y: auto;
}

.modal.show { display: block; }

.modal-box {
  background: var(--panel);
  border-radius: 12px;
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 20px 22px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.25);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
  margin-bottom: 14px;
}

.modal-head h2 { font-size: 16px; margin: 0; font-weight: 500; }

.modal-close {
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.kpi {
  background: #f8fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.kpi .k { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 22px; font-weight: 500; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .ref { font-size: 11px; color: var(--muted); margin-top: 2px; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px 18px;
  font-size: 13px;
}

.detail-grid .row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed #eef0f3;
  padding: 5px 0;
}

/* ---------- 空状态 / 加载 ---------- */
.empty {
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 36px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.loading { padding: 40px; text-align: center; color: var(--muted); font-size: 13px; }

.err {
  background: #fdeaea;
  border: 1px solid #f6cfcf;
  color: #b91c1c;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #232b36 0, #2d3746 220px, var(--bg) 220px);
}

.login-box {
  background: var(--panel);
  border-radius: 14px;
  padding: 32px 34px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.18);
  text-align: center;
}

.login-box h1 { font-size: 17px; font-weight: 500; margin: 0 0 6px; }
.login-box .sub { font-size: 12px; color: var(--muted); margin-bottom: 22px; }

.qr-frame {
  width: 240px;
  height: 240px;
  margin: 0 auto 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafbfc;
  overflow: hidden;
}

.qr-frame img { width: 100%; height: 100%; object-fit: contain; display: block; }
.qr-frame .qr-hint { font-size: 12px; color: var(--muted); padding: 16px; line-height: 1.6; }

.login-step { font-size: 13px; color: #374151; margin-bottom: 6px; }
.login-tip { font-size: 12px; color: var(--muted); line-height: 1.7; }

.login-box button.refresh {
  margin-top: 14px;
  font-family: inherit;
  font-size: 13px;
  padding: 7px 18px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}

.login-box button.refresh:hover { background: #fafbfc; }

@media (max-width: 640px) {
  header.top { padding: 8px 12px; gap: 10px; }
  header.top h1 { font-size: 15px; }
  nav.menu button { padding: 7px 10px; font-size: 13px; }
  main#content { padding: 12px 12px 28px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .chart-box { height: 320px; }
}
