/* 食費見える化レシピアプリ 全スタイル。ライト/ダーク両対応。モバイルファースト。 */

:root {
  --accent: #E8833A;
  --accent-dark: #cf6f2b;
  --accent-soft: #fbe8d8;
  --bg: #faf6f1;
  --surface: #ffffff;
  --surface-2: #f4efe9;
  --text: #2a2620;
  --text-sub: #7a736a;
  --border: #e7ded4;
  --danger: #d64949;
  --danger-soft: #fbe3e3;
  --success: #3f9d5a;
  --nut-p: #e8833a;
  --nut-f: #e0b13a;
  --nut-c: #6aa9c9;
  --shadow: 0 2px 8px rgba(60, 40, 20, 0.08);
  --radius: 14px;
  --nav-h: 62px;
  --max-w: 520px;
}

:root[data-theme="dark"] {
  --accent: #ef9a54;
  --accent-dark: #e8833a;
  --accent-soft: #3a2c20;
  --bg: #17150f;
  --surface: #221f19;
  --surface-2: #2b2720;
  --text: #ece7df;
  --text-sub: #a89f92;
  --border: #38332a;
  --danger: #e86a6a;
  --danger-soft: #3a2020;
  --success: #67bb7f;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #ef9a54;
    --accent-dark: #e8833a;
    --accent-soft: #3a2c20;
    --bg: #17150f;
    --surface: #221f19;
    --surface-2: #2b2720;
    --text: #ece7df;
    --text-sub: #a89f92;
    --border: #38332a;
    --danger: #e86a6a;
    --danger-soft: #3a2020;
    --success: #67bb7f;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

body.modal-open { overflow: hidden; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 16px; }

/* ── レイアウト ── */
#app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--accent);
  color: #fff;
  padding-top: env(safe-area-inset-top);
}
.header-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
}
.header-title { font-size: 18px; font-weight: 700; }
.header-actions { display: flex; gap: 6px; }
.icon-btn {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn.small {
  width: 30px; height: 30px; font-size: 14px;
  background: var(--surface-2);
  color: var(--text-sub);
}

#view {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 14px 14px calc(var(--nav-h) + env(safe-area-inset-bottom) + 20px);
  min-height: 60vh;
}
.page { display: block; }
.page-title { font-size: 20px; margin: 4px 0 14px; }

/* ── 下部ナビ ── */
#app-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  max-width: var(--max-w);
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-sub);
  padding: 8px 2px;
  height: var(--nav-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
}
.nav-btn .nav-icon { font-size: 20px; line-height: 1; }
.nav-btn.active { color: var(--accent); font-weight: 700; }

/* ── ボタン共通 ── */
.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 600;
}
.btn.block { display: block; width: 100%; }
.btn.big-btn { padding: 14px; font-size: 16px; margin-top: 8px; }
.btn.small-btn { padding: 7px 12px; font-size: 13px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-dark); }
.btn-secondary { background: var(--accent-soft); color: var(--accent-dark); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn:disabled { opacity: 0.5; }

/* ── 大提案ボタン ── */
.big-suggest {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 20px;
  font-size: 20px;
  font-weight: 700;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

/* ── 検索 ── */
.search-wrap { margin-bottom: 10px; }
.search-input, .form-input, .form-select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}
.form-select { appearance: none; -webkit-appearance: none; }

/* ── チップ ── */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-wrap: nowrap;
}
.chips::-webkit-scrollbar { display: none; }
.quick-chips { flex-wrap: wrap; overflow-x: visible; }
.chip {
  flex: 0 0 auto;
  white-space: nowrap;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-sub);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
}
.chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.chip.quick { background: var(--surface-2); }

/* ── 並べ替え ── */
.sort-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 12px;
}
.sort-label { font-size: 13px; color: var(--text-sub); }
.sort-select {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.count-line { font-size: 12px; color: var(--text-sub); margin: 2px 0 8px; }

/* ── レシピカード ── */
.recipe-list { display: flex; flex-direction: column; gap: 12px; }
.recipe-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
  position: relative;
}
.card-thumb {
  flex: 0 0 64px;
  width: 64px;
  height: 64px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
}
.card-body { flex: 1; min-width: 0; }
.card-badges { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 3px; }
.card-name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.35;
  margin-bottom: 3px;
  word-break: break-word;
}
.card-meta { font-size: 11.5px; color: var(--text-sub); }
.card-extra {
  font-size: 11.5px;
  color: var(--accent-dark);
  margin-top: 4px;
  font-weight: 600;
}
.fav-btn {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 24px;
  padding: 4px 6px;
  align-self: flex-start;
}
.fav-btn.on { color: #e14b6a; }
.fav-btn.big { font-size: 30px; }

/* ── バッジ ── */
.badge {
  display: inline-block;
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 6px;
  font-weight: 600;
  line-height: 1.5;
}
.badge-cat { background: var(--accent-soft); color: var(--accent-dark); }
.badge-diff.diff-簡単 { background: #dceccf; color: #4c8a3e; }
.badge-diff.diff-普通 { background: #f4ead0; color: #b0862c; }
.badge-diff.diff-上級 { background: #f3dcd6; color: #b45641; }
.badge-plain { background: var(--surface-2); color: var(--text-sub); }
.badge-tag { background: var(--surface-2); color: var(--text-sub); }
.badge-custom { background: #d9e6f2; color: #3d6f9e; }
.badge-fridge { background: #d6ecf2; color: #2f7f95; margin-left: 6px; }

/* ── 空状態 ── */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-sub);
}
.empty-emoji { font-size: 42px; margin-bottom: 10px; }
.empty p { margin: 0 0 16px; }

/* ── 詳細画面 ── */
.back-btn {
  background: none;
  border: none;
  color: var(--accent-dark);
  font-size: 14px;
  padding: 4px 0;
  margin-bottom: 6px;
}
.detail-hero {
  height: 140px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 68px;
  margin-bottom: 12px;
}
.detail-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.detail-title { font-size: 22px; margin: 0; flex: 1; }
.detail-badges { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }

.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  margin: 14px 0;
}
.step-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 22px;
  font-weight: 700;
}
.step-num { font-size: 22px; font-weight: 700; min-width: 28px; text-align: center; }
.step-label { color: var(--text-sub); }

.section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.section-title { font-size: 16px; margin: 0 0 10px; }
.sub-title { font-size: 14px; margin: 14px 0 6px; color: var(--text-sub); }

.ing-list, .sea-list { list-style: none; margin: 0; padding: 0; }
.ing-list li, .sea-list li {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}
.ing-list li:last-child, .sea-list li:last-child { border-bottom: none; }
.ing-qty, .sea-amount { color: var(--text-sub); font-weight: 600; white-space: nowrap; padding-left: 10px; }

/* ── 栄養バー ── */
.kcal-big { font-size: 24px; font-weight: 700; color: var(--accent-dark); margin-bottom: 12px; }
.nut-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.nut-label { flex: 0 0 68px; font-size: 12.5px; color: var(--text-sub); }
.nut-bar-wrap { flex: 1; height: 12px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.nut-bar { height: 100%; border-radius: 6px; transition: width 0.3s; }
.nut-p { background: var(--nut-p); }
.nut-f { background: var(--nut-f); }
.nut-c { background: var(--nut-c); }
.nut-val { flex: 0 0 44px; text-align: right; font-size: 12.5px; font-weight: 600; }

.cost-value { font-size: 24px; font-weight: 700; color: var(--accent-dark); }
.cost-note { font-size: 12px; margin-top: 4px; }

.steps { margin: 0; padding-left: 22px; }
.steps li { padding: 5px 0; }
.source-link { color: var(--accent-dark); font-weight: 600; text-decoration: none; }

.detail-actions { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 12px; }
.detail-actions.edit-row { flex-direction: row; }
.detail-actions.edit-row .btn { flex: 1; }
.cook-stat {
  text-align: center;
  font-size: 13px;
  color: var(--text-sub);
  background: var(--surface-2);
  padding: 10px;
  border-radius: 10px;
  margin-bottom: 12px;
}

/* ── フォーム共通 ── */
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
  margin: 12px 0 5px;
}
.form-row2 { display: flex; gap: 10px; }
.form-row2 > div { flex: 1; }
.form-row4 { display: flex; gap: 8px; }
.labeled-num { flex: 1; display: flex; flex-direction: column; }
.mini-label { font-size: 11px; color: var(--text-sub); margin-bottom: 3px; }

.dyn-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 6px; }
.dyn-row { display: flex; gap: 6px; align-items: center; }
.ing-row .ing-name { flex: 2; }
.ing-row .ing-qty-in { flex: 1; min-width: 0; }
.ing-row .ing-unit { flex: 1; min-width: 0; }
.ing-row .ing-price { flex: 1; min-width: 0; }
.sea-row .sea-name { flex: 1; }
.sea-row .sea-amount-in { flex: 1.4; }
.step-row .step-in { flex: 1; }

.info-note, .info-banner {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
  border: none;
  width: 100%;
  text-align: left;
  display: block;
}
.info-banner { cursor: pointer; }

/* ── 冷蔵庫 ── */
.fridge-form, .shop-form { display: flex; gap: 8px; margin-bottom: 12px; }
.fridge-form .form-input { flex: 1; }
.fridge-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.fridge-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: var(--shadow);
}
.fridge-name { flex: 0 0 auto; font-weight: 600; max-width: 40%; word-break: break-word; }
.fridge-note {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  background: var(--surface-2);
  color: var(--text);
  min-width: 0;
}

/* ── 買い物 ── */
.shop-form { flex-wrap: wrap; }
.shop-form .form-input { flex: 1 1 100%; }
.shop-form .form-input.qty { flex: 1 1 60px; }
.shop-form .form-input.unit { flex: 1 1 60px; }
.shop-form .btn { flex: 0 0 auto; }
.total-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 10px;
}
.total-text { font-size: 13px; color: var(--text-sub); }
.total-val { font-size: 16px; font-weight: 700; color: var(--accent-dark); }
.shop-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.shop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
}
.shop-check { width: 20px; height: 20px; flex: 0 0 auto; accent-color: var(--accent); }
.shop-main { flex: 1; min-width: 0; }
.shop-name-line { display: flex; align-items: center; flex-wrap: wrap; }
.shop-name { font-weight: 600; word-break: break-word; }
.shop-src { font-size: 11px; margin-top: 2px; }
.shop-item.checked .shop-name { text-decoration: line-through; color: var(--text-sub); }
.shop-item.checked { opacity: 0.65; }
.shop-ops { display: flex; gap: 10px; }
.shop-ops .btn { flex: 1; }

/* ── プラン ── */
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab {
  flex: 1;
  background: var(--surface-2);
  border: none;
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-sub);
}
.tab.on { background: var(--accent); color: #fff; }
.plan-preview {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  margin: 12px 0;
  text-align: center;
}
.plan-result-box { margin-top: 14px; }
.plan-summary {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.plan-warn {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
  margin-bottom: 10px;
}
.plan-stats { display: flex; gap: 8px; }
.stat-box {
  flex: 1;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}
.stat-label { font-size: 11px; color: var(--text-sub); }
.stat-value { font-size: 15px; font-weight: 700; color: var(--accent-dark); }

.plan-day {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
}
.plan-day-head { font-weight: 700; margin-bottom: 8px; font-size: 14px; }
.plan-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-top: 1px dashed var(--border);
}
.plan-slot:first-of-type { border-top: none; }
.meal-badge {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}
.meal-朝 { background: #e0a83a; }
.meal-昼 { background: #e8833a; }
.meal-夜 { background: #7a6fb0; }
.plan-recipe-name {
  flex: 1;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  padding: 0;
  min-width: 0;
  word-break: break-word;
}
.plan-cost { flex: 0 0 auto; font-size: 12px; color: var(--text-sub); }
.plan-none { flex: 1; font-size: 13px; }
.plan-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }

.history-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
}
.history-title { font-weight: 700; font-size: 14px; }
.history-sub { font-size: 12px; margin-top: 2px; }
.history-btns { display: flex; gap: 8px; margin-top: 10px; }
.history-btns .btn { flex: 1; }
.history-detail { margin-top: 12px; }

/* ── 価格管理 ── */
.price-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.price-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
}
.price-name { flex: 1; font-weight: 600; font-size: 14px; word-break: break-word; }
.price-base { flex: 0 0 auto; font-size: 11px; }
.price-input { flex: 0 0 90px; text-align: right; }

.app-info { font-size: 13px; line-height: 1.8; }
.caution { font-size: 12px; color: var(--text-sub); margin-top: 12px; }

/* ── トースト ── */
#toast {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(30, 25, 18, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 22px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 50;
  max-width: 80%;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── モーダル ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-box {
  background: var(--surface);
  width: 100%;
  max-width: var(--max-w);
  border-radius: 18px 18px 0 0;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 16px; margin: 0; }
.modal-close {
  background: var(--surface-2);
  border: none;
  color: var(--text-sub);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 14px;
}
.modal-body { padding: 16px; overflow-y: auto; }

.suggest-modal .form-select { margin-bottom: 4px; }
.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  font-size: 14px;
}
.toggle-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.suggest-result { margin: 12px 0; min-height: 40px; }
.suggest-actions { display: flex; gap: 10px; }
.suggest-actions .btn { flex: 1; }

.confirm-msg { margin: 0 0 16px; font-size: 15px; }
.confirm-row { display: flex; gap: 10px; }
.confirm-row .btn { flex: 1; }

.muted { color: var(--text-sub); font-size: 13px; }

.sync-status {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent, #E8833A);
  margin: 4px 0 12px;
}

/* ── 375px対応（崩れ防止）── */
@media (max-width: 380px) {
  .card-thumb { flex-basis: 56px; width: 56px; height: 56px; font-size: 28px; }
  .card-name { font-size: 14px; }
  .form-row4 { flex-wrap: wrap; }
  .form-row4 .labeled-num { flex: 1 1 45%; }
}
