:root {
  --bg: #f6f7f5;
  --card: #ffffff;
  --text: #1c1f1a;
  --muted: #6b7068;
  --line: #e3e6e0;
  --accent: #16a34a;
  --accent-soft: #dcfce7;
  --danger: #dc2626;
  --protein: #2563eb;
  --fat: #d97706;
  --carbs: #9333ea;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121411;
    --card: #1c1f1b;
    --text: #eceee9;
    --muted: #9aa096;
    --line: #2d312b;
    --accent: #22c55e;
    --accent-soft: #163322;
    --protein: #60a5fa;
    --fat: #fbbf24;
    --carbs: #c084fc;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(env(safe-area-inset-bottom) + 90px);
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 560px; margin: 0 auto; padding: 12px 14px; }
h1 { font-size: 20px; margin: 4px 0 12px; }
h2 { font-size: 17px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }

button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 10px; padding: 9px 14px; cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 6px 8px; }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; }
button.block { width: 100%; padding: 12px; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 11px; width: 100%;
}
textarea { resize: vertical; min-height: 60px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }

/* day header */
.daynav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.daynav h1 { margin: 0; }

/* summary */
.kcal-big { font-size: 34px; font-weight: 700; letter-spacing: -0.5px; }
.kcal-big small { font-size: 16px; font-weight: 500; color: var(--muted); }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.over > i { background: var(--danger); }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.macro b { display: block; font-size: 15px; }
.macro .bar > i { background: var(--c); }

/* meals */
.meal { cursor: pointer; }
.meal-head { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.meal-items { margin-top: 4px; font-size: 14px; color: var(--muted); }
.empty { padding: 30px 10px; text-align: center; color: var(--muted); }

.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  background: var(--accent); color: #fff; border: none; border-radius: 99px;
  padding: 15px 26px; font-size: 17px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.18);
}

/* bottom sheet */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; z-index: 10; }
.sheet[hidden] { display: none; }
.sheet-body {
  background: var(--bg); width: 100%; max-width: 560px; margin: 0 auto; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 16px 14px calc(env(safe-area-inset-bottom) + 18px);
}

/* photo picker */
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pick label.btn { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 0; padding: 18px 8px; color: var(--text); font-size: 15px; text-align: center; }
.pick input { display: none; }
.preview { width: 100%; max-height: 220px; object-fit: cover; border-radius: var(--radius); margin-top: 10px; }

/* draft editor */
.item { border-top: 1px solid var(--line); padding: 10px 0; }
.item:first-child { border-top: none; }
.item-name { font-weight: 600; }
.grams { display: flex; align-items: center; gap: 4px; }
.grams input { width: 76px; text-align: center; padding: 7px 4px; }
.grams button { padding: 7px 10px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--line); color: var(--muted); vertical-align: middle; }
.badge.db { background: var(--accent-soft); color: var(--accent); }
.badge.low { background: #fee2e2; color: var(--danger); }
.item select { margin-top: 6px; font-size: 13px; padding: 6px 8px; }
.totals { position: sticky; bottom: -18px; background: var(--bg); padding: 10px 0 4px; border-top: 1px solid var(--line); }
.search-results button { display: block; width: 100%; text-align: left; margin-top: 6px; font-size: 14px; }

.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 90px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 20;
  max-width: 90vw; font-size: 14px;
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
td, th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.error { color: var(--danger); font-size: 14px; margin-top: 8px; }
