/* ============================================================================
   血糖图表页样式。
   浅色主题、无外部依赖（不引 CDN 字体/图标库——离线与内网部署都要能用）。
   ========================================================================== */

:root {
  --bg: #f5f7f9;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --line: #e3e8ee;
  --line-strong: #cbd5e1;
  --ink: #16202c;
  --ink-2: #4a5765;
  --ink-3: #7c8a99;
  --accent: #0f6fbf;
  --accent-soft: #e8f2fb;

  /* 血糖语义色。遵循国内习惯：高=红、低=绿（与欧美相反） */
  --high: #d64545;
  --high-soft: #fdeaea;
  --low: #2f9e5f;
  --low-soft: #e8f6ee;
  --in-range: #3f9c8f;
  --band: #eef7f2;

  --flag: #b26a00;
  --flag-soft: #fdf3e3;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 48, 0.04), 0 4px 16px rgba(16, 32, 48, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 -apple-system, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* 数字一律等宽对齐——血糖值是逐位比对的东西，比例字体看着累 */
.num, .stat-v, .latest-v, table td {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 22px 20px 60px; }

/* ---------- 顶部 ---------- */
header.top {
  display: flex; align-items: center; gap: 14px;
  padding: 0 0 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 9px; }
.brand b { font-size: 17px; letter-spacing: -0.2px; }
.brand span { color: var(--ink-3); font-size: 12px; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 100px;
  background: var(--panel); border: 1px solid var(--line);
  font-size: 12px; color: var(--ink-2);
}
.chip b { color: var(--ink); font-weight: 600; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; margin-bottom: 16px;
}
.card > h2 {
  margin: 0 0 12px; font-size: 13px; font-weight: 600;
  color: var(--ink-2); letter-spacing: 0.2px;
}
.card > h2 .sub { font-weight: 400; color: var(--ink-3); margin-left: 8px; }

/* ---------- 登录 ---------- */
.login-grid { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--ink-3); }
input, select, button {
  font: inherit; color: inherit;
  border: 1px solid var(--line-strong); border-radius: 7px;
  padding: 8px 11px; background: #fff;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
button {
  background: var(--accent); color: #fff; border-color: transparent;
  cursor: pointer; font-weight: 500;
}
button:hover:not(:disabled) { filter: brightness(1.06); }
button:disabled { opacity: 0.5; cursor: default; }
button.ghost { background: #fff; color: var(--ink-2); border-color: var(--line-strong); }
button.ghost:hover:not(:disabled) { background: var(--panel-2); }

/* ---------- 窗口切换 ---------- */
.tabs { display: inline-flex; gap: 3px; padding: 3px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; }
.tabs button {
  background: transparent; color: var(--ink-2); border: none;
  padding: 6px 15px; border-radius: 6px; font-weight: 500;
}
.tabs button[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* ---------- 最新值 ---------- */
.latest { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.latest-v { font-size: 46px; font-weight: 600; line-height: 1; letter-spacing: -1.5px; }
.latest-u { font-size: 15px; color: var(--ink-3); font-weight: 400; margin-left: 5px; }
.latest-meta { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--ink-3); padding-bottom: 4px; }
.trend { font-weight: 600; font-size: 14px; }
.state-ok { color: var(--in-range); }
.state-high { color: var(--high); }
.state-low { color: var(--low); }
.state-stale { color: var(--flag); }

/* ---------- 图表 ---------- */
.chart-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.chart-head .legend { margin-left: auto; display: flex; gap: 14px; font-size: 12px; color: var(--ink-3); flex-wrap: wrap; }
.legend i { display: inline-block; width: 16px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.legend .sw-band { width: 14px; height: 10px; background: var(--band); border: 1px solid #cfe6da; }
.legend .sw-flag { background: var(--flag-soft); height: 10px; border: 1px solid #f0d9b0; }

.chart-box { position: relative; width: 100%; }
.chart-box svg { display: block; width: 100%; height: auto; touch-action: none; }

/* 悬浮提示 */
.tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: rgba(20, 32, 44, 0.93); color: #fff;
  border-radius: 7px; padding: 7px 10px; font-size: 12px; line-height: 1.5;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
  transform: translate(-50%, -100%); white-space: nowrap;
}
.tip b { font-size: 14px; }
.tip .tip-flag { color: #ffcf8a; }

.empty {
  padding: 46px 20px; text-align: center; color: var(--ink-3);
  border: 1px dashed var(--line-strong); border-radius: 8px; background: var(--panel-2);
}

/* ---------- 统计 ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 10px 8px; }
.stat { padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; }
.stat-k { font-size: 11.5px; color: var(--ink-3); margin-bottom: 3px; }
.stat-v { font-size: 19px; font-weight: 600; letter-spacing: -0.3px; }
.stat-v small { font-size: 11px; font-weight: 400; color: var(--ink-3); margin-left: 2px; }
.stat.high .stat-v { color: var(--high); }
.stat.low .stat-v { color: var(--low); }
.stat.dim .stat-v { color: var(--ink-3); font-weight: 500; }

/* TIR 横条 */
.tir-bar { display: flex; height: 26px; border-radius: 6px; overflow: hidden; margin: 4px 0 8px; border: 1px solid var(--line); }
.tir-bar > div { display: flex; align-items: center; justify-content: center; font-size: 11.5px; color: #fff; font-weight: 500; min-width: 0; overflow: hidden; }
.tir-low { background: var(--low); }
.tir-in { background: var(--in-range); }
.tir-high { background: var(--high); }
.tir-legend { display: flex; gap: 16px; font-size: 11.5px; color: var(--ink-3); flex-wrap: wrap; }

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--line); }
th { font-size: 11.5px; color: var(--ink-3); font-weight: 500; background: var(--panel-2); }
tbody tr:last-child td { border-bottom: none; }
td.right, th.right { text-align: right; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 100px; font-size: 11px; }
.tag-none { background: var(--panel-2); color: var(--ink-3); border: 1px solid var(--line); }
.tag-flag { background: var(--flag-soft); color: var(--flag); border: 1px solid #f0d9b0; }
.tag-alert { background: var(--high-soft); color: var(--high); border: 1px solid #f3c9c9; }
.tag-low { background: var(--low-soft); color: var(--low); border: 1px solid #c9e8d6; }

/* ---------- 通知条 ---------- */
.notice {
  padding: 10px 13px; border-radius: 8px; font-size: 13px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink-2);
  margin-bottom: 14px;
}
.notice.warn { background: var(--flag-soft); border-color: #f0d9b0; color: #7a4a00; }
.notice.err { background: var(--high-soft); border-color: #f3c9c9; color: #8f2d2d; }
.notice.ok { background: var(--low-soft); border-color: #c9e8d6; color: #1e6b41; }
.hidden { display: none !important; }

@media (max-width: 640px) {
  .wrap { padding: 14px 12px 40px; }
  .latest-v { font-size: 38px; }
  .chart-head .legend { display: none; }
}
