/* 健康データダッシュボードの見た目。スマホで見る前提の1カラム。 */

:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e2e6ec;
  --text: #1c2430;
  --muted: #6b7684;
  --accent: #2f6fd0;
  --ok: #2ea06a;
  --warn: #c9761a;
  --error: #c0392b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

/* 静的な説明文は文節改行(keep-all + 文中のゼロ幅スペース)で折り返す。
   日本語が単語の途中で切れて読みにくくなるのを防ぐ。 */
.note, .lead, .field-label, .brand, .empty, .stat-label { word-break: keep-all; overflow-wrap: anywhere; }

.topbar { background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-inner {
  max-width: 860px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { font-weight: 700; }
.logout { color: var(--muted); font-size: 13px; text-decoration: none; }
.logout:hover { text-decoration: underline; }

.page { max-width: 860px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin: 0 0 8px; }

.note { color: var(--muted); font-size: 12px; line-height: 1.7; margin: 4px 0 10px; }
.empty { color: var(--muted); text-align: center; padding: 20px 0; }

/* ---- 最新値 ---- */
.latest { text-align: center; }
.latest-value { display: flex; align-items: baseline; justify-content: center; gap: 8px; }
.latest-value .number { font-size: 56px; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; }
.latest-value .unit { font-size: 15px; color: var(--muted); }
.latest-value .trend { font-size: 32px; color: var(--accent); }
.latest-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.latest-meta .stale { color: var(--warn); }
.sensor-line { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* ---- 操作 ---- */
.controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; justify-content: space-between; margin-bottom: 12px; }
.ranges { display: flex; flex-wrap: wrap; gap: 6px; }
.ranges button {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.ranges button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.metric-picker { display: flex; flex-direction: column; gap: 2px; }
.metric-picker .field-label { font-size: 11px; color: var(--muted); }
.metric-picker select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 13px; }

/* ---- グラフ ---- */
.chart-wrap { position: relative; height: 320px; }
.chart-status {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px; pointer-events: none;
}
.chart-status[hidden] { display: none; }

/* ---- 統計 ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stat-label { font-size: 11px; color: var(--muted); }
.stat-value { font-size: 20px; font-weight: 600; }

/* ---- 表 ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.msg { white-space: normal; color: var(--muted); font-size: 12px; }
tr.row-error td { background: #fdf3f2; }

/* ---- ログイン ---- */
body.centered { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 340px; margin: 0; }
.login-card h1 { font-size: 18px; margin: 0 0 16px; text-align: center; }
.field { display: block; margin-bottom: 12px; }
.field-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%; padding: 10px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
button.primary {
  width: 100%; padding: 11px; font-size: 15px; font-weight: 600;
  background: var(--accent); color: #fff; border: 0; border-radius: 8px; cursor: pointer;
}
.flash { padding: 8px 10px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.flash.error { background: #fdf3f2; color: var(--error); }

code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ---- セットアップ画面 ---- */
.flash.ok { background: #eef8f2; color: var(--ok); }
.setup-heading { font-size: 13px; color: var(--muted); margin: 20px 0 6px; }
.setup-list { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.9; }
.button-link {
  display: block; text-align: center; text-decoration: none;
  padding: 11px; font-size: 15px; font-weight: 600;
  background: var(--accent); color: #fff; border-radius: 8px;
}
.login-card .note { text-align: left; }
