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

:root {
  --green: #2d8a4e;
  --green-dark: #1e6438;
  --green-light: #e8f5ec;
  --orange: #e85d04;
  --red: #c62828;
  --text: #1a1a1a;
  --text-muted: #666;
  --border: #e0e0e0;
  --bg: #f5f6f7;
  --card: #ffffff;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ===== Header ===== */
.header {
  background: var(--green);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 16px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo { font-size: 20px; font-weight: 700; color: white; letter-spacing: 0.03em; }
.header-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.header-btn:hover { background: rgba(255,255,255,0.3); }

/* ===== Tab nav ===== */
.tabs {
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  position: sticky;
  top: 52px;
  z-index: 99;
}
.tab {
  flex: 1;
  padding: 12px 8px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  border-bottom: 3px solid transparent;
  transition: all 0.15s;
}
.tab.active { color: var(--green); border-bottom-color: var(--green); font-weight: 500; }
.tab:hover:not(.active) { background: var(--bg); }

/* ===== Main ===== */
.main {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.tab-heading {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--green-dark);
  padding-left: 12px;
  border-left: 4px solid var(--green);
}

/* ===== Panel header ===== */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.panel-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--green-dark);
  padding-left: 12px;
  border-left: 4px solid var(--green);
}

/* ===== Buttons ===== */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn.primary { background: var(--green); color: white; }
.btn.primary:hover { background: var(--green-dark); }
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.outline { background: white; color: var(--green); border: 1px solid var(--green); }
.btn.outline:hover { background: var(--green-light); }
.btn.full { width: 100%; }

/* ===== Week plan ===== */
.day-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 12px;
}
.day-header {
  background: var(--green);
  color: white;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.day-name { font-weight: 600; font-size: 15px; }
.time-badge {
  font-size: 12px;
  background: rgba(255,255,255,0.25);
  padding: 2px 10px;
  border-radius: 12px;
}
.meals-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.meal-item {
  padding: 12px 16px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.meal-item:nth-child(2n) { border-right: none; }
.meal-item:nth-child(3),
.meal-item:nth-child(4) { border-bottom: none; }
.meal-item:last-child { border-right: none; border-bottom: none; }
.meal-item:hover { background: var(--green-light); }
.meal-type { font-size: 11px; color: var(--green); font-weight: 600; margin-bottom: 2px; letter-spacing: 0.03em; }
.meal-name { font-size: 14px; font-weight: 500; line-height: 1.4; }
.meal-time { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* ===== Nutrition ===== */
.nutr-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.nutr-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
}
.nutr-value { font-size: 24px; font-weight: 600; color: var(--green); }
.nutr-unit { font-size: 12px; color: var(--text-muted); }
.nutr-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }
.nutr-target { font-size: 11px; color: var(--green); margin-top: 2px; font-weight: 500; }

.bar-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.bar-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--green-dark);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--green-light);
}
.bar-row { margin-bottom: 14px; }
.bar-row:last-child { margin-bottom: 0; }
.bar-labels { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.bar-labels span:last-child { color: var(--text-muted); }
.bar-track {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 4px; transition: width 0.5s ease; }

/* ===== Shopping list ===== */
.shop-group {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
}
.shop-group-title {
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 700;
  background: var(--green-light);
  border-bottom: 1px solid var(--border);
  color: var(--green-dark);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.shop-item {
  display: flex;
  align-items: flex-start;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.shop-item:last-child { border-bottom: none; }
.shop-item.checked .shop-name {
  text-decoration: line-through;
  color: var(--text-muted);
}
.shop-cb { width: 18px; height: 18px; cursor: pointer; flex-shrink: 0; accent-color: var(--green); margin-top: 1px; }
.shop-body { flex: 1; min-width: 0; }
.shop-row-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.shop-name { font-size: 14px; }
.shop-qty { font-size: 13px; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.shop-days { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.shop-day {
  font-size: 11px;
  font-weight: 600;
  background: var(--green-light);
  color: var(--green-dark);
  padding: 1px 8px;
  border-radius: 10px;
  line-height: 1.7;
}
.pantry-tag {
  font-size: 11px;
  background: var(--green-light);
  color: var(--green);
  padding: 1px 7px;
  border-radius: 4px;
  white-space: nowrap;
}
.shop-item.pantry-item { opacity: 0.55; }

/* ===== Pantry ===== */
.pantry-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.pantry-item-row {
  display: flex;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 8px;
  gap: 10px;
}
.pantry-item-name { flex: 1; font-size: 14px; }
.pantry-item-qty { font-size: 13px; color: var(--text-muted); }
.del-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 0 2px;
}
.del-btn:hover { color: var(--red); }

/* ===== Input ===== */
.input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}
.input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(45,138,78,0.12); }
.input.short { width: 90px; flex-shrink: 0; }

/* ===== Modal ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.overlay.hidden { display: none; }
.modal {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 440px;
  overflow: hidden;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal.wide { max-width: 600px; }
.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.modal-head h3 { font-size: 17px; font-weight: 600; }
.close-btn {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0 4px;
}
.close-btn:hover { color: var(--text); }
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-foot {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.label { display: block; font-weight: 500; font-size: 14px; margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 8px; line-height: 1.5; }
.hint a { color: var(--green); }

/* ===== Recipe detail ===== */
.recipe-meta {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.recipe-meta-item { font-size: 13px; color: var(--text-muted); }
.recipe-meta-value { font-size: 18px; font-weight: 600; color: var(--text); display: block; }

.nutr-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}
.nutr-chip {
  background: var(--bg);
  border-radius: 6px;
  padding: 8px;
  text-align: center;
}
.nutr-chip-val { font-size: 16px; font-weight: 600; color: var(--green); }
.nutr-chip-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.recipe-section-title {
  font-weight: 700;
  font-size: 13px;
  margin: 16px 0 8px;
  color: var(--green-dark);
  padding-left: 8px;
  border-left: 3px solid var(--green);
}
.ingredient-list { list-style: none; }
.ingredient-list li {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--bg);
  font-size: 14px;
}
.ingredient-list li:last-child { border-bottom: none; }
.ingredient-list li span:last-child { color: var(--text-muted); }
.steps-list { padding-left: 0; list-style: none; counter-reset: steps; }
.steps-list li {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  font-size: 14px;
  line-height: 1.6;
  border-bottom: 1px solid var(--bg);
  counter-increment: steps;
}
.steps-list li:last-child { border-bottom: none; }
.steps-list li::before {
  content: counter(steps);
  min-width: 22px;
  height: 22px;
  background: var(--green);
  color: white;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

/* ===== Loading ===== */
.loading-box {
  background: white;
  border-radius: 12px;
  padding: 36px 32px;
  text-align: center;
  max-width: 260px;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-box p { color: var(--text-muted); font-size: 14px; line-height: 1.7; }
.loading-box small { font-size: 12px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 300;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

/* ===== Empty state ===== */
.empty {
  text-align: center;
  padding: 56px 16px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.8;
}

/* ===== Responsive ===== */
@media (max-width: 500px) {
  .nutr-cards { grid-template-columns: repeat(2, 1fr); }
  .meals-grid { grid-template-columns: 1fr; }
  .meal-item { border-right: none !important; }
  .meal-item { border-bottom: 1px solid var(--border) !important; }
  .meal-item:last-child { border-bottom: none !important; }
  .nutr-row { grid-template-columns: repeat(2, 1fr); }
  .recipe-meta { gap: 12px; }
}
