:root {
  --bg: #fbf7f2; --card: #ffffff; --ink: #2b2620; --muted: #7a7065; --line: #ece4da;
  --brand: #e07a5f; --brand-ink: #fff; --brand-soft: #fbe6df;
  --green: #4f9d69; --green-soft: #e3f2e7; --amber: #d99a1e; --amber-soft: #fbf0d6;
  --red: #c8473d; --red-soft: #f9e0dd; --blue: #3d7ab8; --blue-soft: #e0ecf7;
  --radius: 16px; --shadow: 0 1px 2px rgba(60,40,20,.06), 0 4px 14px rgba(60,40,20,.05);
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1815; --card: #262220; --ink: #f2ece5; --muted: #a99e92; --line: #3a3430;
    --brand: #ee8f74; --brand-ink: #1b1815; --brand-soft: #4a2e26;
    --green: #74c08c; --green-soft: #22382a; --amber: #e8b54d; --amber-soft: #3d3220;
    --red: #ec7b70; --red-soft: #45262323; --blue: #7fb1e3; --blue-soft: #1f3040;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif; min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.hidden { display: none !important; }

header.top {
  position: sticky; top: 0; z-index: 10; background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--line);
}
header.top h1 { font-size: 19px; margin: 0; flex: 1; letter-spacing: -.01em; }
header.top .sub { font-size: 13px; color: var(--muted); font-weight: 400; display: block; }
.iconbtn { background: none; border: 0; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; cursor: pointer; color: var(--ink); }
.iconbtn:active { background: var(--line); }
.iconbtn svg { width: 22px; height: 22px; }

main { padding: 14px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); max-width: 720px; margin: 0 auto; }

nav.bottom {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--card);
  border-top: 1px solid var(--line); display: flex; justify-content: space-around; align-items: center;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
}
nav.bottom button { flex: 1; background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); cursor: pointer; padding: 6px 0; }
nav.bottom button svg { width: 24px; height: 24px; }
nav.bottom button.active { color: var(--brand); }
nav.bottom .plus { flex: 0 0 auto; width: 56px; height: 56px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); box-shadow: 0 4px 14px rgba(224,122,95,.4); margin: -18px 6px 0; justify-content: center; }
nav.bottom .plus svg { width: 28px; height: 28px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px; border: 1px solid var(--line); }
.card h2 { font-size: 16px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.card h3 { font-size: 14px; margin: 12px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.section-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 18px 4px 8px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn { border: 0; border-radius: 12px; padding: 10px 14px; background: var(--brand); color: var(--brand-ink); font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.btn.secondary { background: var(--brand-soft); color: var(--ink); }
.btn.ghost { background: transparent; color: var(--brand); padding: 6px 8px; }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.small { padding: 6px 10px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; font-size: 13px; background: var(--line); color: var(--ink); border: 1px solid transparent; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--brand); color: var(--brand-ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.tag.new { background: var(--blue-soft); color: var(--blue); }
.tag.allergen { background: var(--amber-soft); color: var(--amber); }
.tag.iron { background: var(--red-soft); color: var(--red); }
.tag.safe { background: var(--green-soft); color: var(--green); }
.tag.watch { background: var(--amber-soft); color: var(--amber); }
.tag.avoid { background: var(--red-soft); color: var(--red); }
.tag.maintain { background: var(--green-soft); color: var(--green); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: 0 0 auto; background: var(--line); }
.dot.safe { background: var(--green); } .dot.watch { background: var(--amber); } .dot.avoid { background: var(--red); }

.banner { border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 10px; display: flex; gap: 8px; }
.banner.info { background: var(--blue-soft); }
.banner.warn { background: var(--amber-soft); }
.banner.danger { background: var(--red-soft); }
.banner.ok { background: var(--green-soft); }

.meal { border-top: 1px solid var(--line); padding: 12px 0; }
.meal:first-of-type { border-top: 0; padding-top: 4px; }
.meal .when { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.meal .title { font-weight: 600; margin: 2px 0 6px; }
.meal ul { margin: 4px 0 0; padding-left: 18px; font-size: 14px; }
.meal li { margin-bottom: 4px; }
.meal .actions { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.meal.logged .title::after { content: " ✓"; color: var(--green); }

.check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--line); cursor: pointer; }
.check:first-child { border-top: 0; }
.check input { width: 22px; height: 22px; accent-color: var(--green); margin: 0; flex: 0 0 auto; }
.check.done span { text-decoration: line-through; color: var(--muted); }

.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.list-item:first-child { border-top: 0; }
.list-item .name { flex: 1; }
.list-item .meta { font-size: 13px; color: var(--muted); }

.entry { padding: 10px 0; border-top: 1px solid var(--line); }
.entry:first-child { border-top: 0; }
.entry .head { display: flex; gap: 8px; align-items: baseline; }
.entry .head b { text-transform: capitalize; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); outline: none; min-height: 44px;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
textarea { min-height: 70px; resize: vertical; }
.toggle { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.toggle input { width: 22px; height: 22px; accent-color: var(--brand); }

.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--card); width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 8px 16px calc(env(safe-area-inset-bottom) + 20px); animation: up .2s ease-out; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h2 { margin: 0 0 12px; font-size: 19px; display: flex; align-items: center; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }

.fooditem { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; }
.fooditem .top { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.seg { display: flex; gap: 4px; margin-top: 8px; flex-wrap: wrap; }
.seg button { flex: 1; border: 1px solid var(--line); background: var(--bg); padding: 7px 4px; border-radius: 10px; font-size: 13px; cursor: pointer; min-width: 52px; }
.seg button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.faces button { font-size: 20px; padding: 4px; }
.suggest { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; margin-top: 6px; }
.suggest div { padding: 10px 12px; border-top: 1px solid var(--line); cursor: pointer; display: flex; gap: 8px; align-items: center; }
.suggest div:first-child { border-top: 0; }

.ring { width: 120px; height: 120px; }
.stat { text-align: center; }
.stat b { font-size: 26px; display: block; }
.bars .bar { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 4px 0; }
.bars .bar .track { flex: 1; height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.bars .bar .fill { height: 100%; background: var(--brand); border-radius: 5px; }
.strip { display: grid; grid-template-columns: repeat(14, 1fr); gap: 3px; }
.strip div { aspect-ratio: 1; border-radius: 5px; display: grid; place-items: center; font-size: 10px; color: var(--muted); background: var(--line); }
.strip div.l1 { background: #f6cdbf; color: #6b3b2d; } .strip div.l2 { background: #ee9e85; color: #fff; } .strip div.l3 { background: var(--brand); color: #fff; }
.strip div.flare { outline: 2px solid var(--red); }

table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple td, table.simple th { padding: 7px 4px; border-top: 1px solid var(--line); text-align: left; }
table.simple th { font-size: 12px; color: var(--muted); text-transform: uppercase; border-top: 0; }

.login { max-width: 380px; margin: 12vh auto; padding: 0 20px; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 14px; }
.login h1 { text-align: center; margin: 0 0 4px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 100; font-size: 14px; max-width: 90vw; animation: up .2s; }
.disclaimer { font-size: 12px; color: var(--muted); text-align: center; margin: 20px 8px 0; }
.photo-thumb { max-width: 120px; border-radius: 10px; display: block; margin-top: 6px; }
input[type=range] { width: 100%; accent-color: var(--brand); }
.score { font-size: 28px; font-weight: 700; text-align: center; }
