:root {
  --bg: #0b1426;          /* ダークネイビー（ベース） */
  --bg-soft: #0f1c33;     /* 入力欄など一段沈んだ面 */
  --card: #16233f;        /* カード面 */
  --text: #e8eefb;
  --text-muted: #93a4c4;
  --border: #26334f;
  --primary: #2f6bf2;     /* コバルトブルー（メイン） */
  --primary-dark: #1f56d6;
  --primary-soft: rgba(47, 107, 242, 0.16);
  --accent: #34e0a1;      /* ミントグリーン（アクセント） */
  --accent-dark: #21c489;
  --danger: #f0556b;
  --track: #1f2c47;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.25);
  --radius: 14px;
}

html { color-scheme: dark; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Hiragino Sans", Meiryo, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
}

.app-header h1 {
  font-size: 1.15rem;
  margin: 0;
  font-weight: 700;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  font-size: 1.1rem;
  cursor: pointer;
  color: #fff;
}
.icon-btn:active { transform: scale(0.94); }

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  animation: card-in 0.35s ease both;
}
.container > .card:nth-child(2) { animation-delay: 0.04s; }
.container > .card:nth-child(3) { animation-delay: 0.08s; }
.container > .card:nth-child(4) { animation-delay: 0.12s; }
.container > .card:nth-child(5) { animation-delay: 0.16s; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
  .progress-fill { transition: none; }
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 14px;
}

/* 進捗 */
.progress-top {
  display: flex;
  justify-content: space-around;
  text-align: center;
  margin-bottom: 14px;
}
.stat { display: flex; flex-direction: column; align-items: center; }
.stat-label { font-size: 0.72rem; color: var(--text-muted); }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat-unit { font-size: 0.72rem; color: var(--text-muted); }

.progress-bar {
  height: 12px;
  background: var(--track);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-dark));
  border-radius: 999px;
  transition: width 0.4s ease;
}
.progress-text {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
}

/* グラフのコントロール行 */
.chart-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

/* セグメント切替（体重 / 血圧） */
.seg {
  display: inline-flex;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 6px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg-btn.is-active {
  background: var(--primary);
  color: #fff;
}

/* 期間フィルタ */
.period-filter {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.period-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.period-btn.is-active {
  background: var(--primary);
  color: #fff;
}

/* グラフ */
.chart-wrap {
  position: relative;
  height: 260px;
}

/* サマリー */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.stat-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.stat-tile-value { font-size: 1.2rem; font-weight: 700; line-height: 1.2; }
.stat-tile-label { font-size: 0.68rem; color: var(--text-muted); text-align: center; }
.stat-down { color: var(--accent); }
.stat-up { color: var(--danger); }
.empty-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  margin: 12px 0 0;
}

/* フォーム */
.record-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field-wide { grid-column: 1 / -1; }
.field label { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.field input {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: var(--bg-soft);
  color: var(--text);
}
.field input::placeholder { color: #5d6f8f; }
.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.form-hint {
  margin: -6px 0 14px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
}

.btn {
  padding: 11px 18px;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; flex: 1; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-small { padding: 7px 12px; font-size: 0.82rem; }

.label-hint {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.7rem;
  margin-left: 6px;
}
.settings-section { display: flex; flex-direction: column; gap: 8px; }
.settings-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

/* 一覧 */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.list-header .card-title { margin: 0; }
.export-buttons { display: flex; gap: 8px; }
.export-buttons .btn { background: var(--bg); color: var(--text); border: 1px solid var(--border); }

.record-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.record-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.record-main { display: flex; flex-direction: column; min-width: 0; }
.record-date { font-size: 0.78rem; color: var(--text-muted); }
.record-weight { font-size: 1.05rem; font-weight: 700; }
.record-memo {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.record-actions { display: flex; gap: 6px; flex-shrink: 0; }
.record-actions button {
  border: none;
  background: transparent;
  font-size: 1.05rem;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  line-height: 1;
}
.record-actions button:hover { background: var(--border); }

.record-metrics { display: flex; flex-direction: column; gap: 2px; }
.record-bp { font-size: 0.92rem; font-weight: 600; color: var(--text); }
.record-bp.bp-high { color: var(--danger); }

.record-delta { font-size: 0.72rem; font-weight: 600; }
.delta-down { color: var(--accent); }
.delta-up { color: var(--danger); }

/* ダイアログ */
.dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: 92%;
  width: 380px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog-form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; width: 100%; }

/* トースト */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 0.88rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.25s;
}
.toast.show { opacity: 1; }

[hidden] { display: none !important; }

@media (max-width: 420px) {
  .stat-value { font-size: 1.3rem; }
  .card { padding: 15px; }
  .stat-tile-value { font-size: 1.05rem; }
  .period-btn { padding: 5px 9px; }
}
