:root {
  --bg: #f5f7f4;
  --surface: #ffffff;
  --primary: #2e7d55;
  --primary-dark: #1f5a3c;
  --text: #1a2b22;
  --text-sub: #6b7a72;
  --border: #e3e9e5;
  --p-color: #e86a58;
  --f-color: #f4b942;
  --c-color: #5aa8d6;
  --danger: #c94545;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}

#app { min-height: 100vh; min-height: 100dvh; }

.screen { min-height: 100vh; min-height: 100dvh; }
.hidden { display: none !important; }

/* プロフィール設定 */
.profile-wrap {
  padding: 32px 20px calc(32px + env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
}
.profile-wrap h1 {
  font-size: 24px;
  color: var(--primary);
  margin-bottom: 8px;
}
.profile-wrap .lead {
  color: var(--text-sub);
  margin-bottom: 24px;
  font-size: 14px;
}
#profile-form label {
  display: block;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-sub);
  font-weight: 600;
}
#profile-form input,
#profile-form select {
  display: block;
  width: 100%;
  padding: 12px 14px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  background: var(--surface);
  color: var(--text);
}
#profile-form input:focus,
#profile-form select:focus {
  outline: none;
  border-color: var(--primary);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
button.primary {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  border-radius: 10px;
  margin-top: 8px;
}
button.primary:active { background: var(--primary-dark); }
button.danger {
  width: 100%;
  padding: 12px;
  background: #fff;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 10px;
  font-size: 14px;
  margin-top: 12px;
}

/* ヘッダー */
.app-header {
  position: sticky;
  top: 0;
  background: var(--surface);
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.app-header h1 { font-size: 17px; font-weight: 700; }
.icon-btn {
  width: 36px;
  height: 36px;
  font-size: 20px;
  border-radius: 8px;
}
.icon-btn:active { background: var(--bg); }

/* タブコンテンツ */
.tab-content {
  padding: 16px 16px calc(90px + env(safe-area-inset-bottom));
  max-width: 520px;
  margin: 0 auto;
}

/* カード */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.date-label {
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 6px;
}
.calorie-main {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
}
.big-num {
  font-size: 42px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}
.sub { font-size: 13px; color: var(--text-sub); }

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 18px;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s;
  border-radius: 4px;
}
.progress-fill.over { background: var(--danger); }

.pfc-row { display: flex; flex-direction: column; gap: 10px; }
.pfc-item {
  display: grid;
  grid-template-columns: 20px 1fr 80px;
  align-items: center;
  gap: 10px;
}
.pfc-label { font-weight: 700; text-align: center; }
.pfc-bar {
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
}
.pfc-fill { height: 100%; transition: width 0.3s; border-radius: 3px; }
.pfc-fill.p { background: var(--p-color); }
.pfc-fill.f { background: var(--f-color); }
.pfc-fill.c { background: var(--c-color); }
.pfc-val { font-size: 12px; color: var(--text-sub); text-align: right; }

/* 食事ブロック */
.meals-list { display: flex; flex-direction: column; gap: 12px; }
.meal-block {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.meal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.meal-name { font-weight: 700; font-size: 15px; }
.add-btn {
  font-size: 13px;
  color: var(--primary);
  padding: 6px 10px;
  border-radius: 8px;
  font-weight: 600;
}
.add-btn:active { background: var(--bg); }

.meal-items { list-style: none; }
.meal-items li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.meal-items li:first-child { border-top: none; }
.meal-items .mi-info { flex: 1; min-width: 0; }
.meal-items .mi-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal-items .mi-sub { font-size: 11px; color: var(--text-sub); }
.meal-items .mi-cal { font-size: 14px; font-weight: 600; color: var(--primary); margin-left: 8px; }
.meal-items .mi-del {
  padding: 4px 8px;
  color: var(--text-sub);
  font-size: 18px;
  margin-left: 4px;
}

/* 下部ナビ */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 10;
}
.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 14px;
  font-size: 11px;
  color: var(--text-sub);
  flex: 1;
  max-width: 100px;
}
.nav-btn.active { color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 22px; }

/* 献立提案 */
.plan-header {
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.plan-header .hint {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 10px;
  text-align: center;
}
.day-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.day-title {
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 10px;
  font-size: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.day-total {
  font-size: 12px;
  color: var(--text-sub);
  font-weight: 500;
}
.day-meal {
  padding: 8px 0;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.day-meal:first-of-type { border-top: none; }
.dm-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-sub);
  min-width: 28px;
}
.dm-name { flex: 1; font-size: 13px; }
.dm-cal { font-size: 12px; color: var(--primary); font-weight: 600; }
.day-meal.clickable {
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(0,0,0,0.05);
  transition: background 0.15s;
}
.day-meal.clickable:active { background: rgba(0,0,0,0.04); }
.dm-arrow {
  font-size: 20px;
  color: var(--text-sub);
  font-weight: 300;
  line-height: 1;
  margin-left: 4px;
}

/* レシピモーダル */
.recipe-body {
  padding: 0 2px;
}
.recipe-nutrition {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text-sub);
  margin-bottom: 18px;
}
.recipe-nutrition .rn-cal {
  color: var(--primary);
  font-weight: 700;
  font-size: 15px;
}
.recipe-nutrition .rn-sep { color: var(--border); }
.recipe-section-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  margin: 14px 0 8px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--primary);
}
.recipe-ingredients {
  list-style: none;
  padding: 0;
  margin: 0 0 8px;
}
.recipe-ingredients li {
  display: flex;
  justify-content: space-between;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.recipe-ingredients li:last-child { border-bottom: none; }
.ing-name { color: var(--text); }
.ing-amount { color: var(--text-sub); font-weight: 600; }
.recipe-steps {
  padding-left: 24px;
  margin: 0;
}
.recipe-steps li {
  padding: 8px 0 8px 6px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}
.recipe-steps li::marker {
  color: var(--primary);
  font-weight: 700;
}

/* 買い物リスト */
.shop-category {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.shop-cat-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--primary);
  margin-bottom: 8px;
}
.shop-item {
  display: flex;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  gap: 10px;
}
.shop-item:first-of-type { border-top: none; }
.shop-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}
.shop-item label {
  flex: 1;
  font-size: 14px;
}
.shop-item.checked label {
  color: var(--text-sub);
  text-decoration: line-through;
}
.shop-amount { font-size: 12px; color: var(--text-sub); }

/* モーダル */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-content {
  background: var(--surface);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.modal-head h2 { font-size: 17px; }
.close-btn {
  width: 32px;
  height: 32px;
  font-size: 24px;
  border-radius: 8px;
  color: var(--text-sub);
}

#food-search {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  margin-bottom: 12px;
  background: var(--bg);
}
#food-search:focus { outline: none; border-color: var(--primary); }

.food-list {
  max-height: 50vh;
  overflow-y: auto;
  margin: 0 -4px;
}
.food-item {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 8px;
}
.food-item:active { background: var(--bg); }
.food-item .fi-name { font-size: 14px; font-weight: 500; }
.food-item .fi-cat { font-size: 11px; color: var(--text-sub); margin-top: 2px; }
.food-item .fi-kcal { font-size: 13px; color: var(--primary); font-weight: 600; }

.food-detail { padding: 8px 4px; }
.food-detail h3 { margin-bottom: 10px; font-size: 17px; }
.fd-base, .fd-calc {
  font-size: 13px;
  color: var(--text-sub);
  padding: 8px 0;
}
.fd-calc { color: var(--primary); font-weight: 600; }
.food-detail label {
  display: block;
  margin: 12px 0 4px;
  font-size: 13px;
  color: var(--text-sub);
  font-weight: 600;
}
.food-detail input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  margin-top: 4px;
}
.fd-actions {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
  margin-top: 16px;
}
.fd-actions button { padding: 13px; border-radius: 10px; font-weight: 600; }
.fd-actions button:not(.primary) {
  background: var(--bg);
  color: var(--text);
}

/* 設定 */
.settings-body { padding: 4px; }
.setting-row {
  display: flex;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.setting-label { font-size: 13px; color: var(--text-sub); }
.setting-val { font-weight: 600; font-size: 14px; }
#edit-profile { margin-top: 20px; }

.empty {
  text-align: center;
  padding: 24px;
  color: var(--text-sub);
  font-size: 13px;
}

/* 体組成タブ */
.card-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--text);
}
.body-summary-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.body-latest-date {
  font-size: 12px;
  color: var(--text-sub);
  font-weight: 600;
}
.body-weight-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 16px;
}
.body-goal-info { text-align: right; }
.body-goal-val {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

.weight-chart {
  width: 100%;
  height: 160px;
  position: relative;
}
.weight-chart svg { width: 100%; height: 100%; }
.weight-chart .axis-line { stroke: var(--border); stroke-width: 1; }
.weight-chart .goal-line { stroke: var(--primary); stroke-width: 1; stroke-dasharray: 4 4; opacity: 0.5; }
.weight-chart .data-line { stroke: var(--primary); stroke-width: 2; fill: none; }
.weight-chart .data-point { fill: var(--primary); }
.weight-chart .axis-label { font-size: 10px; fill: var(--text-sub); }

.body-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.stat-box {
  background: var(--bg);
  padding: 12px;
  border-radius: 10px;
}
.stat-label {
  font-size: 11px;
  color: var(--text-sub);
  margin-bottom: 4px;
  font-weight: 600;
}
.stat-val {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}
.stat-unit {
  font-size: 11px;
  color: var(--text-sub);
  font-weight: 500;
  margin-left: 3px;
}

.body-add-fab {
  margin-bottom: 16px;
}

.body-history {
  display: flex;
  flex-direction: column;
}
.history-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.history-row:first-child { border-top: none; }
.history-date {
  font-weight: 600;
  color: var(--text-sub);
  font-size: 12px;
}
.history-weight {
  font-weight: 700;
  color: var(--primary);
}
.history-weight .hw-unit { font-size: 11px; color: var(--text-sub); font-weight: 500; margin-left: 2px; }
.history-del {
  color: var(--text-sub);
  font-size: 18px;
  padding: 4px 8px;
}

/* 体組成フォーム */
.body-form label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-sub);
  font-weight: 600;
}
.body-form input {
  display: block;
  width: 100%;
  padding: 12px 14px;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  background: var(--surface);
}
.body-form input:focus {
  outline: none;
  border-color: var(--primary);
}
.body-form .req { color: var(--danger); }
.body-form .two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.body-form .two-col label { margin-bottom: 0; }
.body-form .two-col { margin-bottom: 14px; }
.body-form .hint {
  font-size: 12px;
  color: var(--text-sub);
  margin: 4px 0 14px;
}

/* OCR アップロード */
.ocr-upload-area {
  background: var(--bg);
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 18px;
  text-align: center;
}
.ocr-btn {
  display: block;
  padding: 14px 16px;
  background: var(--primary);
  color: white;
  border-radius: 10px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  width: 100%;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}
.ocr-btn:active { opacity: 0.85; }
.ocr-hint {
  font-size: 11px;
  color: var(--text-sub);
  margin: 8px 0 0;
  line-height: 1.5;
}
.ocr-status {
  padding: 10px 12px;
  border-radius: 8px;
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.5;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}
.ocr-status.info { background: #e3f2fd; color: #1565c0; }
.ocr-status.success { background: #e8f5e9; color: #2e7d32; }
.ocr-status.warning { background: #fff8e1; color: #ef6c00; }
.ocr-status.error { background: #ffebee; color: #c62828; }

.nav-btn { padding: 6px 8px; }
