/* ============================================
   健診数値チェッカー — スタイルシート
   モバイルファースト・シニア対応・印刷対応
   ============================================ */

/* CSS変数 */
:root {
  --color-primary: #1565C0;
  --color-primary-dark: #0D47A1;
  --color-primary-tint: #E3F0FC;
  --color-accent: #8E44AD;
  --color-accent-tint: #F3E8F8;
  --color-green: #2E7D32;
  --color-orange: #E65100;
  --color-red: #C62828;
  --color-gray: #5F6B78;
  --color-light-gray: #EEF1F4;
  --color-bg: #F7F8FA;
  --color-card-bg: #FFFFFF;
  --color-text: #1C2530;
  --color-border: #D3D9E0;
  --font-base: 18px;
  --font-large: 24px;
  --font-small: 14px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(21,101,192,0.10), 0 1px 2px rgba(21,101,192,0.08);
  --focus-ring: 0 0 0 3px rgba(21,101,192,0.35);
}

/* 高コントラストモード */
body.high-contrast {
  --color-bg: #000000;
  --color-card-bg: #1A1A1A;
  --color-text: #FFFFFF;
  --color-border: #666666;
  --color-light-gray: #333333;
  --color-gray: #CCCCCC;
}
body.high-contrast .contrast-toggle {
  background: #FFFFFF;
  color: #000000;
  border-color: #FFFFFF;
}

/* リセット */
* { margin: 0; padding: 0; box-sizing: border-box; }

/* ベース */
html {
  width: 100%;
  overflow-x: hidden;
}
body {
  font-size: var(--font-base);
  line-height: 1.7;
  color: var(--color-text);
  background: var(--color-bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* ブランドヘッダー（サイト全体） */
.site-header {
  text-align: center;
  padding: 20px 16px 16px;
  background: var(--color-card-bg);
  border-bottom: 1px solid var(--color-border);
}
.brand-name {
  display: inline-block;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--color-gray);
  margin-bottom: 6px;
}
.site-header h1 {
  font-size: 26px;
  color: var(--color-primary-dark);
  margin-bottom: 4px;
  line-height: 1.3;
}
.subtitle {
  font-size: var(--font-base);
  color: var(--color-gray);
}

/* ツールセレクター（健診/献血を同格の入口として提示） */
.tool-selector {
  background: var(--color-bg);
  padding: 16px 16px 20px;
  border-bottom: 1px solid var(--color-border);
}
.tool-selector-inner {
  max-width: 800px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 560px) {
  .tool-selector-inner {
    grid-template-columns: 1fr;
  }
}
.tool-select-card {
  display: block;
  text-decoration: none;
  border-radius: var(--radius);
  padding: 16px;
  border: 2px solid var(--color-border);
  background: var(--color-card-bg);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
  min-height: 48px;
  min-width: 0;
}
.tool-select-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.tool-select-card:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.tool-select-card .tool-icon {
  font-size: 22px;
  margin-bottom: 6px;
  display: block;
}
.tool-select-card .tool-name {
  display: block;
  font-size: 17px;
  font-weight: bold;
  color: var(--color-text);
  margin-bottom: 2px;
}
.tool-select-card .tool-desc {
  display: block;
  font-size: var(--font-small);
  color: var(--color-gray);
}
.tool-select-card.checkup {
  border-color: var(--color-primary);
}
.tool-select-card.checkup .tool-name { color: var(--color-primary-dark); }
.tool-select-card.blood {
  border-color: var(--color-accent);
}
.tool-select-card.blood .tool-name { color: var(--color-accent); }
.tool-select-card.body-composition {
  border-color: var(--color-green);
}
.tool-select-card.body-composition .tool-name { color: var(--color-green); }

/* 現在表示中のツールを示すマーキング */
.tool-select-card.is-current {
  background: var(--color-primary-tint);
  cursor: default;
}
.tool-select-card.is-current .tool-name {
  color: var(--color-primary-dark);
}
.tool-select-card.blood.is-current {
  background: var(--color-accent-tint);
}
.tool-select-card.blood.is-current .tool-name {
  color: var(--color-accent);
}
.tool-select-card.body-composition.is-current {
  background: #E5F3E6;
}
.tool-select-card.body-composition.is-current .tool-name {
  color: var(--color-green);
}
.tool-select-card.is-current .tool-current-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: bold;
  color: #FFFFFF;
  background: var(--color-primary);
  padding: 2px 8px;
  border-radius: 10px;
  margin-bottom: 6px;
}
.tool-select-card.blood.is-current .tool-current-badge {
  background: var(--color-accent);
}
.tool-select-card.body-composition.is-current .tool-current-badge {
  background: var(--color-green);
}
body.high-contrast .tool-select-card.is-current,
body.high-contrast .tool-select-card.blood.is-current,
body.high-contrast .tool-select-card.body-composition.is-current {
  background: var(--color-card-bg);
  border-color: var(--color-text);
}
body.high-contrast .tool-select-card.is-current .tool-name,
body.high-contrast .tool-select-card.blood.is-current .tool-name,
body.high-contrast .tool-select-card.body-composition.is-current .tool-name {
  color: var(--color-text);
}

/* 指標別・ガイドページへの補助導線 */
.sub-nav {
  padding: 10px 16px;
  text-align: center;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-card-bg);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  row-gap: 4px;
}
.sub-nav .sub-nav-label {
  font-size: 13px;
  color: var(--color-gray);
  font-weight: 600;
  margin-right: 4px;
}
.sub-nav a {
  font-size: 13px;
  color: var(--color-primary);
  text-decoration: underline;
  margin: 0 6px;
}
.sub-nav a:hover,
.sub-nav a:focus-visible {
  color: var(--color-primary-dark);
}
.sub-nav a:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: 2px;
}

/* 免責バナー */
.disclaimer-banner {
  background: #FFF3E0;
  border-bottom: 1px solid #FFE0B2;
  padding: 12px 16px;
  text-align: center;
  font-size: var(--font-small);
  line-height: 1.6;
  color: #5F4300;
}
.disclaimer-banner p { margin: 0; }
body.high-contrast .disclaimer-banner {
  background: #332B00;
  border-bottom-color: #665600;
  color: #FFE9A8;
}

/* メイン */
.tool-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px;
}

/* セクション */
.input-section {
  background: var(--color-card-bg);
  border-radius: var(--radius);
  padding: 24px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.input-section h2 {
  font-size: var(--font-large);
  margin-bottom: 16px;
  color: var(--color-primary-dark);
  border-bottom: 2px solid var(--color-light-gray);
  padding-bottom: 8px;
}
.section-hint {
  font-size: var(--font-small);
  color: var(--color-gray);
  margin-bottom: 16px;
}

/* フォーム */
.form-group {
  margin-bottom: 20px;
}
.form-label {
  display: block;
  font-weight: bold;
  margin-bottom: 8px;
}
.required { color: var(--color-red); font-weight: normal; font-size: var(--font-small); }
.optional { color: var(--color-gray); font-weight: normal; font-size: var(--font-small); }

/* セグメントボタン */
.segment-control {
  display: flex;
  gap: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--color-primary);
}
.seg-btn {
  flex: 1;
  padding: 14px 24px;
  font-size: var(--font-base);
  border: none;
  background: var(--color-card-bg);
  color: var(--color-primary);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  min-height: 48px;
}
.seg-btn.active {
  background: var(--color-primary);
  color: #FFFFFF;
  font-weight: bold;
}
.seg-btn:focus-visible,
.number-input:focus-visible,
.select-input:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* 入力欄 */
.number-input, .select-input {
  padding: 12px 14px;
  font-size: var(--font-base);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 200px;
  min-height: 48px;
  background: var(--color-card-bg);
  color: var(--color-text);
}
.select-input { max-width: 100%; }

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.input-row label {
  min-width: 120px;
  font-size: var(--font-base);
}
.unit {
  font-size: var(--font-small);
  color: var(--color-gray);
  white-space: nowrap;
}
.hint {
  font-size: var(--font-small);
  color: var(--color-gray);
  margin-top: 4px;
}

/* 入力カードグリッド */
.input-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 600px) {
  .input-grid {
    grid-template-columns: 1fr 1fr;
  }
}
@media (min-width: 900px) {
  .input-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.input-card {
  background: var(--color-light-gray);
  border-radius: var(--radius);
  padding: 16px;
}
.card-title {
  font-size: var(--font-base);
  font-weight: bold;
  margin-bottom: 12px;
  color: var(--color-primary-dark);
}
.input-card .input-row label {
  min-width: 100px;
  font-size: var(--font-small);
}

/* アクションボタン */
.action-bar {
  text-align: center;
  padding: 16px 0;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.btn-primary, .btn-secondary {
  padding: 14px 32px;
  font-size: var(--font-base);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 48px;
  transition: opacity 0.2s;
}
.btn-primary {
  background: var(--color-primary);
  color: #FFFFFF;
  font-weight: bold;
}
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-primary:active { transform: translateY(1px); }
.btn-secondary {
  background: var(--color-light-gray);
  color: var(--color-text);
}
.btn-secondary:hover { opacity: 0.8; }
.btn-secondary:active { transform: translateY(1px); }

/* 結果セクション */
.result-section {
  background: var(--color-card-bg);
  border-radius: var(--radius);
  padding: 24px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.result-section h2 {
  font-size: var(--font-large);
  margin-bottom: 16px;
  color: var(--color-primary-dark);
  border-bottom: 2px solid var(--color-light-gray);
  padding-bottom: 8px;
}

/* 結果カード */
.result-card {
  border-left: 6px solid var(--color-gray);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  background: var(--color-light-gray);
}
.result-card.normal { border-left-color: var(--color-green); }
.result-card.borderline { border-left-color: var(--color-orange); }
.result-card.high { border-left-color: var(--color-red); }

.result-card .item-name {
  font-size: var(--font-base);
  font-weight: bold;
  margin-bottom: 4px;
}
.result-card .result-label {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: var(--font-small);
  font-weight: bold;
  color: #FFFFFF;
  margin-bottom: 8px;
}
.result-card .result-value {
  font-size: var(--font-small);
  color: var(--color-gray);
  margin-bottom: 8px;
}
.result-card .threshold-info {
  font-size: var(--font-small);
  color: var(--color-text);
  background: var(--color-card-bg);
  padding: 8px 12px;
  border-radius: 4px;
  margin-bottom: 8px;
  line-height: 1.6;
}
.result-card .advice {
  font-size: var(--font-small);
  color: var(--color-text);
}
.result-card .tag {
  font-weight: bold;
  margin-right: 4px;
}

/* 改善目標値バー */
.goal-bar-container {
  margin: 12px 0;
}
.goal-bar {
  height: 24px;
  background: var(--color-light-gray);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}
.goal-bar.zone-bar {
  overflow: visible;
  border-radius: 12px;
}
.zone-bar-segment {
  position: absolute;
  top: 0;
  height: 100%;
}
.zone-bar-segment:first-child { border-radius: 12px 0 0 12px; }
.zone-bar-segment:last-child { border-radius: 0 12px 12px 0; }
.goal-bar-fill {
  height: 100%;
  border-radius: 12px;
  transition: width 0.5s ease;
}
.goal-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: var(--font-small);
  color: var(--color-gray);
  margin-top: 4px;
}

/* ゾーンバー: 目標値ラベルはバー上段、現在値ラベルはバー下段に配置（重なり回避） */
.zone-bar-marks-top,
.zone-bar-marks-bottom {
  position: relative;
  height: 22px;
}
.zone-bar-marks-top {
  margin-bottom: 2px;
}
.zone-bar-marks-bottom {
  margin-top: 2px;
}
.zone-bar-mark {
  position: absolute;
  transform: translateX(-50%);
  font-size: var(--font-small);
  color: var(--color-gray);
  white-space: nowrap;
  text-align: center;
}
.zone-bar-mark.is-goal {
  color: var(--color-primary);
}
.zone-bar-marks-top .zone-bar-mark {
  bottom: 0;
}
.zone-bar-marks-top .zone-bar-mark::after {
  content: '';
  display: block;
  width: 2px;
  height: 6px;
  background: currentColor;
  margin: 2px auto 0;
}
.zone-bar-marks-bottom .zone-bar-mark {
  top: 0;
}
.zone-bar-marks-bottom .zone-bar-mark::before {
  content: '';
  display: block;
  width: 2px;
  height: 6px;
  background: currentColor;
  margin: 0 auto 2px;
}

/* 3色ゾーンバー（基準範囲に対する現在値の位置） */
.zone-bar-marker {
  position: absolute;
  top: -3px;
  width: 4px;
  height: 30px;
  background: var(--color-text);
  border-radius: 2px;
  transform: translateX(-2px);
  box-shadow: 0 0 0 2px #FFFFFF;
  z-index: 2;
}
.zone-bar-marker.is-goal {
  width: 2px;
  height: 24px;
  top: 0;
  background: var(--color-primary);
  transform: translateX(-1px);
  box-shadow: 0 0 0 1px #FFFFFF;
  z-index: 1;
}

/* 目標値サマリー */
.goal-summary {
  margin-top: 24px;
  padding: 16px;
  background: #E3F2FD;
  border-radius: var(--radius);
  color: var(--color-text);
}
.goal-summary h3 {
  font-size: var(--font-base);
  margin-bottom: 12px;
  color: var(--color-primary-dark);
}
body.high-contrast .goal-summary {
  background: #0D2438;
}
body.high-contrast .goal-summary h3,
body.high-contrast .goal-item .goal-target {
  color: #7FC4FF;
}
.goal-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  font-size: var(--font-base);
}
.goal-item:last-child { border-bottom: none; }
.goal-item .goal-current { color: var(--color-gray); }
.goal-item .goal-target { font-weight: bold; color: var(--color-primary-dark); }

/* フッター */
.site-footer {
  background: var(--color-card-bg);
  padding: 24px 16px;
  margin-top: 24px;
  border-top: 1px solid var(--color-border);
}
.footer-disclaimer h3 {
  font-size: var(--font-base);
  margin-bottom: 8px;
}
.footer-disclaimer p {
  font-size: var(--font-small);
  color: var(--color-gray);
  margin-bottom: 8px;
  line-height: 1.6;
}
.footer-meta {
  margin-top: 16px;
  font-size: var(--font-small);
  color: var(--color-gray);
  text-align: center;
}
.footer-links {
  margin-top: 12px;
  line-height: 2;
}
.footer-links a {
  white-space: nowrap;
}

/* 注意書きボックス（ポリシー・解説ページ用）
   高コントラスト時に背景と文字色を明示的に切り替える。
   インラインstyleで背景色を固定すると、body.high-contrast の
   文字色（白）と衝突して読めなくなるため、必ずこのクラスを使う。 */
.notice-box {
  padding: 14px 16px;
  border-radius: 4px;
  border-left: 4px solid;
  margin-top: 14px;
}
.notice-box.warn   { background: #FFF8E1; border-left-color: #FFA000; color: #4A3800; }
.notice-box.danger { background: #FFEBEE; border-left-color: #E53935; color: #5D1A1A; }
.notice-box.info   { background: #E3F2FD; border-left-color: #1976D2; color: #0D3C61; }
.notice-box.ok     { background: #E8F5E9; border-left-color: #43A047; color: #1B4A20; }
.notice-box.plain  { background: #ECEFF1; border-left-color: #90A4AE; color: #2F3C42; }

body.high-contrast .notice-box.warn {
  background: #332B00; border-left-color: #FFC107; color: #FFE9A8;
}
body.high-contrast .notice-box.danger {
  background: #3A0F0F; border-left-color: #FF6B6B; color: #FFD6D6;
}
body.high-contrast .notice-box.info {
  background: #0D2438; border-left-color: #64B5F6; color: #CFE8FF;
}
body.high-contrast .notice-box.ok {
  background: #0E2A12; border-left-color: #66BB6A; color: #CFF0D4;
}
body.high-contrast .notice-box.plain {
  background: #1F272B; border-left-color: #B0BEC5; color: #E3E9EC;
}
/* ボックス内のリンクは地色に対して十分な明度を確保する */
body.high-contrast .notice-box a { color: #90CAF9; }

/* 高コントラスト時のインライン文字色の上書き。
   ページ内で style="color:#..." により固定された色は、黒背景では
   WCAG AA（4.5:1）を下回るため、地色に対して十分な明度の色へ置換する。
   計算値（カード #1A1A1A 上）: #64B5F6 = 7.86:1 / #B0BEC5 = 9.13:1 */
body.high-contrast a[style*="color:#2196F3"],
body.high-contrast a[style*="color:#1565C0"] {
  color: #64B5F6 !important;
}
body.high-contrast [style*="color:#1976D2"] {
  color: #90CAF9 !important;
}
body.high-contrast [style*="color:#546E7A"],
body.high-contrast [style*="color:#616161"] {
  color: #B0BEC5 !important;
}

/* 広告枠 */
.ad-slot {
  max-width: 800px;
  margin: 16px auto;
  padding: 8px 16px;
  text-align: center;
}
.ad-slot-label {
  font-size: 11px;
  color: var(--color-gray);
  margin-bottom: 4px;
}
@media print {
  .ad-slot { display: none; }
}

/* コントラスト切替ボタン */
.contrast-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 100;
  padding: 8px 14px;
  font-size: var(--font-small);
  background: var(--color-card-bg);
  border: 2px solid var(--color-border);
  border-radius: 20px;
  cursor: pointer;
  min-height: 40px;
}

/* ============================================
   印刷対応（A4）
   ============================================ */
@media print {
  body {
    font-size: 12pt;
    color: #000;
    background: #FFF;
  }
  .site-header {
    border-bottom: 2px solid #000;
    padding: 8px 0;
  }
  .site-header h1 {
    font-size: 20pt;
    color: #000;
  }
  .subtitle { color: #333; }
  .disclaimer-banner {
    background: #FFF;
    border: 1px solid #999;
    font-size: 9pt;
  }
  .tool-container {
    max-width: 100%;
    padding: 0;
  }
  .input-section, .result-section {
    box-shadow: none;
    border: 1px solid #CCC;
    page-break-inside: avoid;
  }
  .input-section { display: none; }
  .action-bar { display: none; }
  .contrast-toggle { display: none; }
  .tool-selector { display: none; }
  .sub-nav { display: none; }
  .result-card {
    background: #FFF;
    border: 1px solid #CCC;
    border-left: 6px solid #999;
  }
  .result-card.normal { border-left-color: #4CAF50; }
  .result-card.borderline { border-left-color: #FF9800; }
  .result-card.high { border-left-color: #f44336; }
  .result-card .result-label {
    color: #FFF;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .goal-bar-fill,
  .zone-bar-segment,
  .zone-bar-marker,
  .zone-bar-marker.is-goal {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .site-footer {
    border-top: 2px solid #000;
    page-break-inside: avoid;
  }
  .footer-disclaimer {
    border: 1px solid #999;
    padding: 8px;
    margin-top: 8px;
  }
  .footer-disclaimer p {
    color: #333;
    font-size: 9pt;
  }
  .result-section h2::before {
    content: "健康情報シート（参考） — ";
  }
}