/* Aimee's Place nutrition: brand tokens lifted from aimees.place */
:root {
  --ink: #33302b;
  --muted: #7a736b;
  --stone: #b8b1a6;
  --sand: #e7dfd4;
  --cream: #fffdfa;
  --paper: #faf7f2;
  --blush: #f5e9e8;
  --rose: #b85c74;
  --rose-deep: #9c465e;
  --sage: #54724f;
  --sage-soft: #e3eadf;
  --gold: #b99247;
  --gold-soft: #f3ead6;
  --danger: #a8403f;
  --protein: #54724f;
  --carbs: #b99247;
  --fat: #b85c74;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(51, 48, 43, 0.06), 0 8px 24px rgba(51, 48, 43, 0.06);
  --font-body: 'Nunito Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
  --nav-h: 64px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
}
a { color: var(--rose-deep); text-decoration: none; }
h1, h2, h3, .display { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 1.75rem; line-height: 1.15; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
em.rose { font-style: italic; color: var(--rose); }
em.sage { font-style: italic; color: var(--sage); }
p { margin: 0 0 0.75rem; }
small, .muted { color: var(--muted); }
.muted { font-size: 0.9rem; }
.tiny { font-size: 0.8rem; }
.eyebrow { font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--rose); font-weight: 700; }

.shell { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 24px); }
.shell.wide { max-width: 1080px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand .mark { width: 34px; height: 34px; border-radius: 50%; background: var(--rose); color: #fff; display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; }
.brand .word { font-family: var(--font-display); font-size: 1.2rem; font-weight: 600; }
.brand .word em { color: var(--rose); }
.brand .sub { display: block; font-family: var(--font-body); font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin-top: -2px; }

.card { background: var(--cream); border: 1px solid var(--sand); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card.flat { box-shadow: none; }
.card h2 { margin-bottom: 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--rose); background: var(--rose); color: #fff;
  border-radius: 999px; padding: 10px 18px; font: 700 0.95rem var(--font-body);
  cursor: pointer; text-decoration: none; letter-spacing: 0.02em; line-height: 1.2;
}
.btn:hover { background: var(--rose-deep); border-color: var(--rose-deep); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--stone); }
.btn.ghost:hover { background: var(--sand); }
.btn.sage { background: var(--sage); border-color: var(--sage); }
.btn.sm { padding: 6px 12px; font-size: 0.85rem; }
.btn.block { width: 100%; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--sand); }
.btn:disabled { opacity: 0.5; cursor: default; }
.iconbtn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--sand); background: var(--cream); color: var(--ink); display: grid; place-items: center; cursor: pointer; font-size: 1.1rem; }
.iconbtn:hover { background: var(--sand); }

label { display: block; font-size: 0.85rem; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: 1rem var(--font-body); color: var(--ink);
  background: #fff; border: 1px solid var(--sand); border-radius: 12px; padding: 11px 12px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--rose); outline-offset: 1px; border-color: var(--rose); }
textarea { min-height: 84px; resize: vertical; }
.field { margin-bottom: 12px; }
.field .hint { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { flex: 1; }
.flash { border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-size: 0.92rem; }
.flash.ok { background: var(--sage-soft); color: var(--sage); }
.flash.err { background: var(--blush); color: var(--danger); }

/* Bottom navigation */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h);
  background: var(--cream); border-top: 1px solid var(--sand);
  display: flex; justify-content: space-around; align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom); z-index: 20;
}
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.02em; }
.nav a.active { color: var(--rose); }
.nav a svg { width: 22px; height: 22px; }
.nav a .dot { position: absolute; margin-left: 22px; margin-top: -2px; width: 8px; height: 8px; border-radius: 50%; background: var(--rose); }

/* Day header and summary ring */
.dayhead { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 14px; }
.dayhead h1 { font-size: 1.5rem; }
.dayhead .date { color: var(--muted); font-size: 0.85rem; }
.summary { display: grid; grid-template-columns: 140px 1fr; gap: 14px; align-items: center; }
.ring { position: relative; width: 140px; height: 140px; }
.ring svg { transform: rotate(-90deg); }
.ring .track { fill: none; stroke: var(--sand); stroke-width: 10; }
.ring .bar { fill: none; stroke: var(--rose); stroke-width: 10; stroke-linecap: round; transition: stroke-dasharray 0.4s ease; }
.ring .bar.over { stroke: var(--danger); }
.ring .centre { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.ring .centre .big { font-family: var(--font-display); font-size: 1.8rem; font-weight: 600; line-height: 1; }
.ring .centre .lbl { font-size: 0.7rem; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 4px; }
.kcal-maths { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--muted); margin-top: 10px; }
.kcal-maths b { display: block; color: var(--ink); font-size: 0.95rem; }
.macro { margin-bottom: 8px; }
.macro .lbl { display: flex; justify-content: space-between; font-size: 0.8rem; margin-bottom: 3px; }
.macro .lbl b { font-weight: 700; }
.meter { height: 8px; background: var(--sand); border-radius: 99px; overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 99px; background: var(--rose); }
.meter.protein > i { background: var(--protein); }
.meter.carbs > i { background: var(--carbs); }
.meter.fat > i { background: var(--fat); }
.meter.water > i { background: #5f8fa8; }
.meter > i.over { background: var(--danger); }
.minis { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.minis span { font-size: 0.75rem; background: var(--paper); border: 1px solid var(--sand); border-radius: 99px; padding: 3px 9px; color: var(--muted); }
.minis span b { color: var(--ink); }

/* Meals */
.meal { background: var(--cream); border: 1px solid var(--sand); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.meal header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--sand); background: #fff; }
.meal header h3 { font-size: 1.05rem; }
.meal header .kcal { font-size: 0.85rem; color: var(--muted); }
.meal header .kcal b { color: var(--ink); font-size: 1rem; }
.entry { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--paper); }
.entry:last-child { border-bottom: 0; }
.entry .info { flex: 1; min-width: 0; }
.entry .name { font-weight: 700; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .detail { font-size: 0.78rem; color: var(--muted); }
.entry .kcal { font-weight: 700; font-size: 0.95rem; }
.entry form { margin: 0; }
.entry .del { background: none; border: 0; color: var(--stone); font-size: 1.2rem; cursor: pointer; padding: 4px 6px; }
.entry .del:hover { color: var(--danger); }
.meal .empty { padding: 12px 14px; color: var(--stone); font-size: 0.85rem; font-style: italic; }
.meal footer { padding: 10px 14px; display: flex; gap: 8px; flex-wrap: wrap; }

/* Search */
.searchbar { position: sticky; top: 0; background: var(--paper); padding: 8px 0 10px; z-index: 5; }
.searchbar form { display: flex; gap: 8px; }
.searchbar input { border-radius: 999px; padding-left: 16px; }
.result { display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--sand); color: var(--ink); }
.result .info { flex: 1; min-width: 0; }
.result .name { font-weight: 700; font-size: 0.95rem; }
.result .detail { font-size: 0.78rem; color: var(--muted); }
.result .per { font-size: 0.8rem; color: var(--muted); text-align: right; white-space: nowrap; }
.result .per b { display: block; color: var(--ink); font-size: 0.95rem; }
.tag { display: inline-block; font-size: 0.65rem; letter-spacing: 0.08em; text-transform: uppercase; padding: 2px 7px; border-radius: 99px; background: var(--sand); color: var(--muted); font-weight: 700; vertical-align: middle; }
.tag.custom { background: var(--sage-soft); color: var(--sage); }
.tag.off { background: var(--gold-soft); color: var(--gold); }
.tag.coach { background: var(--blush); color: var(--rose-deep); }
.tag.warn { background: var(--blush); color: var(--danger); }
.tag.ok { background: var(--sage-soft); color: var(--sage); }

/* Nutrition preview table */
.nut { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.nut td { padding: 6px 0; border-bottom: 1px solid var(--paper); }
.nut td:last-child { text-align: right; font-weight: 700; }
.nut tr.main td { font-size: 1rem; }

/* Chart */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--sand); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--rose); stroke-width: 2.5; stroke-linejoin: round; }
.chart .area { fill: var(--rose); opacity: 0.08; }
.chart .pt { fill: var(--cream); stroke: var(--rose); stroke-width: 2; }
.chart .target { stroke: var(--sage); stroke-dasharray: 4 4; stroke-width: 1.5; }
.chart text { font: 10px var(--font-body); fill: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 90px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 3px; }
.bars .b i { display: block; width: 100%; max-width: 28px; background: var(--rose); border-radius: 4px 4px 0 0; min-height: 2px; opacity: 0.85; }
.bars .b i.over { background: var(--danger); }
.bars .b i.none { background: var(--sand); }
.bars .b small { font-size: 0.65rem; color: var(--muted); }

/* Coach */
.client { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--sand); color: var(--ink); align-items: center; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--blush); color: var(--rose-deep); display: grid; place-items: center; font-weight: 800; font-size: 0.95rem; flex-shrink: 0; }
.avatar.sage { background: var(--sage-soft); color: var(--sage); }
.client .info { flex: 1; min-width: 0; }
.client .name { font-weight: 800; }
.client .meta { font-size: 0.78rem; color: var(--muted); }
.client .stats { display: flex; gap: 10px; font-size: 0.78rem; color: var(--muted); text-align: right; }
.client .stats b { display: block; color: var(--ink); font-size: 0.95rem; }
.flags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.kpi { background: var(--paper); border: 1px solid var(--sand); border-radius: 12px; padding: 10px 12px; }
.kpi .v { font-family: var(--font-display); font-size: 1.4rem; font-weight: 600; line-height: 1.1; }
.kpi .l { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-top: 2px; }
.weektable { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.weektable th { text-align: left; font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: 6px 4px; border-bottom: 1px solid var(--sand); }
.weektable td { padding: 7px 4px; border-bottom: 1px solid var(--paper); white-space: nowrap; }
.weektable td.num, .weektable th.num { text-align: right; }
.weektable tr.today td { background: var(--blush); }
.weektable a { color: var(--ink); font-weight: 700; }
.note { background: var(--blush); border-left: 3px solid var(--rose); border-radius: 0 12px 12px 0; padding: 10px 12px; margin-bottom: 8px; }
.note .who { font-size: 0.72rem; color: var(--rose-deep); font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }
.note p { margin: 4px 0 0; font-size: 0.92rem; white-space: pre-wrap; }

/* Messages */
.thread { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }
.msg { max-width: 84%; padding: 9px 13px; border-radius: 16px; font-size: 0.95rem; white-space: pre-wrap; }
.msg.me { align-self: flex-end; background: var(--rose); color: #fff; border-bottom-right-radius: 4px; }
.msg.them { align-self: flex-start; background: #fff; border: 1px solid var(--sand); border-bottom-left-radius: 4px; }
.msg .t { display: block; font-size: 0.68rem; opacity: 0.7; margin-top: 3px; }
.composer { position: sticky; bottom: calc(var(--nav-h) + 8px); background: var(--paper); padding-top: 8px; }

/* Auth pages */
.auth { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px 16px; max-width: 420px; margin: 0 auto; }
.auth .brand { justify-content: center; margin-bottom: 20px; }
.auth h1 { text-align: center; margin-bottom: 6px; font-size: 1.9rem; }
.auth .lead { text-align: center; color: var(--muted); margin-bottom: 22px; }

/* Scanner */
#scanner { display: none; position: fixed; inset: 0; background: #000; z-index: 50; }
#scanner video { width: 100%; height: 100%; object-fit: cover; }
#scanner .close { position: absolute; top: calc(16px + env(safe-area-inset-top)); right: 16px; background: rgba(0,0,0,0.5); color: #fff; border-color: rgba(255,255,255,0.5); }
#scanner .frame { position: absolute; left: 10%; right: 10%; top: 30%; height: 26%; border: 2px solid var(--rose); border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0,0,0,0.35); }
#scanner .hint { position: absolute; bottom: calc(28px + env(safe-area-inset-bottom)); left: 16px; right: 16px; text-align: center; color: #fff; font-size: 0.95rem; display: flex; flex-direction: column; gap: 12px; align-items: center; }
#scanner .hint .tiny { opacity: 0.75; }
#scanner .photo { background: #fff; color: var(--ink); border-color: #fff; cursor: pointer; }

.divider { border: 0; border-top: 1px solid var(--sand); margin: 14px 0; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 12px; }
.mb0 { margin-bottom: 0; }
.hide { display: none !important; }
.code { font-family: ui-monospace, Menlo, monospace; letter-spacing: 0.12em; font-weight: 800; font-size: 1.3rem; background: var(--paper); border: 1px dashed var(--stone); border-radius: 10px; padding: 8px 14px; display: inline-block; }

@media (min-width: 900px) {
  .shell.wide .cols { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 16px; align-items: start; }
}
@media (max-width: 380px) {
  .summary { grid-template-columns: 120px 1fr; }
  .ring { width: 120px; height: 120px; }
}
