:root {
  --green: #b3502e; /* terracotta accent (variable name kept for brevity) */
  --bg: #faf5f1;
  --card: #ffffff;
  --text: #33261f;
  --muted: #93817a;
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, system-ui, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 90px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.85rem; }
.error { color: #b3392f; min-height: 1em; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

#login { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-card { width: min(320px, 90vw); display: flex; flex-direction: column; gap: 12px; text-align: center; }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--green); color: #fff;
  position: sticky; top: 0;
}
header h2 { margin: 0; font-size: 1.05rem; font-weight: 600; }
header button {
  background: rgba(255,255,255,0.18); color: #fff; border: none;
  width: 38px; height: 38px; border-radius: 50%; font-size: 1.3rem; cursor: pointer;
}

.summary { display: flex; align-items: center; justify-content: space-between; }
.summary .kcal strong { font-size: 1.6rem; color: var(--green); margin-right: 4px; }
.summary .macros { display: flex; gap: 14px; font-size: 0.9rem; color: var(--muted); }
.summary .macros strong { color: var(--text); }

.entry .items { margin: 6px 0 0; padding-left: 18px; font-size: 0.9rem; }
.entry .items li { margin: 2px 0; }

.food-search { position: relative; }
.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; padding: 10px; border: 1px solid #e0d3cb; border-radius: 8px; font: inherit; }
.search-row button {
  border: 1px solid var(--green); background: #fff; color: var(--green);
  border-radius: 8px; padding: 0 12px; cursor: pointer; white-space: nowrap;
}
.food-results {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 10;
  background: #fff; border: 1px solid #e0d3cb; border-radius: 10px;
  max-height: 240px; overflow-y: auto; box-shadow: 0 6px 18px rgba(0,0,0,0.15);
}
.results-head { padding: 8px 12px 2px; font-size: 0.75rem; text-transform: uppercase; }
.result {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; padding: 8px 12px; border: none; background: none;
  text-align: left; cursor: pointer; font: inherit;
}
.result:hover { background: #f6ece5; }

.picked-items { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.picked {
  display: flex; align-items: center; gap: 8px;
  background: #f6ece5; border-radius: 8px; padding: 6px 10px; font-size: 0.9rem;
}
.picked .pname { flex: 1; }
.picked .qty { display: flex; align-items: center; gap: 6px; }
.picked .qty button {
  width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--green);
  background: #fff; color: var(--green); cursor: pointer; line-height: 1;
}
.picked .delete { background: none; border: none; color: var(--muted); cursor: pointer; }
.picked-total { text-align: right; font-weight: 600; font-size: 0.9rem; }

.linklike { background: none; border: none; color: var(--green); cursor: pointer; font: inherit; text-align: left; padding: 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2 label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.grid2 input { width: 100%; padding: 8px; border: 1px solid #e0d3cb; border-radius: 8px; font: inherit; }

.scan-card { display: flex; flex-direction: column; gap: 10px; }
#scanVideo { width: 100%; border-radius: 10px; background: #000; aspect-ratio: 4/3; object-fit: cover; }
#manualBarcode { width: 100%; padding: 10px; border: 1px solid #e0d3cb; border-radius: 8px; font: inherit; }
#manualLookup { padding: 10px 18px; border-radius: 8px; border: none; cursor: pointer; font: inherit; background: var(--green); color: #fff; }

.water { display: flex; align-items: center; justify-content: space-between; }
.water-controls { display: flex; align-items: center; gap: 12px; }

.header-right { display: flex; gap: 8px; }

:root {
  --c-protein: #f5a623;
  --c-carbs: #3cb371;
  --c-fat: #2196f3;
}

/* --- meal sections (Practice Better style) --- */
.section-head { display: flex; align-items: center; justify-content: space-between; }
.section-head h3 { margin: 0; color: var(--green); text-transform: uppercase; font-size: 0.95rem; letter-spacing: 0.5px; }
.add-btn {
  background: var(--green); color: #fff; border: none; border-radius: 8px;
  padding: 8px 22px; font-weight: 600; cursor: pointer; font-size: 0.85rem;
}
.meal-section .empty { margin: 14px 0 4px; }

.pb-entry { border-top: 1px solid #f0e7e1; margin-top: 12px; padding-top: 12px; }
.entry-top { display: flex; align-items: baseline; gap: 8px; }
.time-chip { background: #efe5de; border-radius: 6px; padding: 2px 8px; font-size: 0.8rem; color: #6b5c52; white-space: nowrap; }
.entry-top .desc { flex: 1; font-weight: 500; white-space: pre-wrap; }
.entry-top .delete { background: none; border: none; color: var(--muted); cursor: pointer; }
.freeform { display: block; margin-top: 2px; }
.pb-entry .items { margin: 6px 0 0; padding-left: 18px; font-size: 0.9rem; }
.macro-row {
  display: flex; gap: 18px; flex-wrap: wrap;
  background: #faf5f1; border-radius: 8px; padding: 10px 12px; margin-top: 10px;
}
.macro-row div { display: flex; flex-direction: column; }
.mlabel { font-size: 0.7rem; text-transform: uppercase; color: var(--muted); letter-spacing: 0.5px; }
.macro-row strong { color: var(--green); }
.entry-photo { width: 100%; border-radius: 10px; margin-top: 10px; }
.loc-mood { margin-top: 10px; }
.loc-mood p { margin: 2px 0 0; font-size: 0.9rem; }

/* --- water (litres) --- */
.water-title { margin: 0; color: #2596be; text-transform: uppercase; font-size: 0.95rem; letter-spacing: 0.5px; }
.water-total { text-align: center; font-size: 1.7rem; margin: 10px 0; font-weight: 300; }
.water-chips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.water-chips button {
  border: 1px solid #bfe0ee; background: #fff; color: #2596be;
  border-radius: 999px; padding: 8px 12px; cursor: pointer; font-size: 0.9rem;
}
.water-chips .minus { color: var(--muted); border-color: #e0d3cb; }

/* --- targets & totals --- */
.targets h3 { margin: 0 0 12px; color: var(--green); text-transform: uppercase; font-size: 0.95rem; letter-spacing: 0.5px; }
.targets h4 { margin: 18px 0 6px; color: var(--green); }
.donut-wrap { display: flex; align-items: center; gap: 22px; }
.donut {
  width: 130px; height: 130px; border-radius: 50%; background: #eee5df;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.donut-hole { width: 64px; height: 64px; border-radius: 50%; background: var(--card); }
.donut-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.donut-legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 8px; }
.sw.protein { background: var(--c-protein); }
.sw.carbs { background: var(--c-carbs); }
.sw.fat { background: var(--c-fat); }
.nutrients { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.nutrients td { padding: 8px 0; border-bottom: 1px solid #f0e7e1; }
.nutrients td:last-child { text-align: right; font-weight: 600; }
.day-summary { margin: 14px 0 0; color: var(--muted); }

/* --- add dialog ("What did you have?") --- */
.add-form { max-height: 85vh; overflow-y: auto; }
.add-form h3 { color: var(--green); }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.field select, .field input, .field textarea {
  width: 100%; padding: 10px; border: 1px solid #e0d3cb; border-radius: 8px; font: inherit; color: var(--text);
}
.datetime-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.estimate { background: #faf5f1; border-radius: 10px; padding: 12px; }
.estimate p { margin: 0 0 8px; font-size: 0.9rem; }
.estimate ul { margin: 0 0 10px; padding-left: 18px; font-size: 0.9rem; }
.estimate ul.accepted { opacity: 0.7; }
.estimate #useData {
  background: var(--green); color: #fff; border: none; border-radius: 8px;
  padding: 8px 18px; cursor: pointer; font: inherit;
}
.row-left { display: flex; gap: 14px; align-items: center; }
.db-search summary { cursor: pointer; color: var(--green); font-size: 0.9rem; }
.db-search { border: 1px dashed #e0d3cb; border-radius: 10px; padding: 10px; }
.photo-row { display: flex; gap: 10px; }
.photo-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 2px dashed #e0d3cb; border-radius: 10px; padding: 12px; cursor: pointer;
  font-size: 0.9rem; color: var(--green);
}
.photo-btn input { display: none; }
#photoPreview { max-width: 100%; max-height: 200px; border-radius: 10px; }
#savePlusOne { background: #8e3e22; color: #fff; border: none; border-radius: 8px; padding: 10px 14px; cursor: pointer; font: inherit; }

.users-list { list-style: none; margin: 0; padding: 0; }
.users-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; border-bottom: 1px solid #f0e7e1;
}
.users-list .delete { background: none; border: none; color: var(--muted); cursor: pointer; }
#newUserForm { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
#nuName, #nuPassword { width: 100%; padding: 10px; border: 1px solid #e0d3cb; border-radius: 8px; font: inherit; }

.weight-head { display: flex; align-items: center; justify-content: space-between; }
.weight-add { display: flex; gap: 8px; }
.weight-add input { width: 90px; padding: 8px; border: 1px solid #e0d3cb; border-radius: 8px; font: inherit; }
.weight-add button {
  padding: 8px 14px; border-radius: 8px; border: none; cursor: pointer;
  background: var(--green); color: #fff; font: inherit;
}
.weight-list { list-style: none; margin: 8px 0 0; padding: 0; }
.weight-list:empty { display: none; }
.weight-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0; border-top: 1px solid #f0e7e1; font-size: 0.92rem;
}
.weight-list .delete { background: none; border: none; color: var(--muted); cursor: pointer; }
.water-controls button {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--green);
  background: #fff; color: var(--green); font-size: 1.2rem; cursor: pointer;
}

.entry { display: flex; gap: 12px; }
.entry img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; }
.entry .body { flex: 1; }
.entry .head { display: flex; justify-content: space-between; align-items: baseline; }
.entry .type { font-weight: 600; text-transform: capitalize; }
.entry .delete { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; }
.entry p { margin: 6px 0 0; white-space: pre-wrap; }
.empty { text-align: center; color: var(--muted); margin-top: 40px; }

.fab {
  position: fixed; right: 20px; bottom: 24px;
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--green); color: #fff; border: none;
  font-size: 1.8rem; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

dialog { border: none; border-radius: var(--radius); padding: 0; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,0.4); }
dialog .card { margin: 0; display: flex; flex-direction: column; gap: 12px; }

.meal-types { display: flex; flex-wrap: wrap; gap: 8px; }
.meal-types button {
  border: 1px solid #e0d3cb; background: #fff; border-radius: 999px;
  padding: 8px 12px; cursor: pointer; font-size: 0.9rem;
}
.meal-types button.active { background: var(--green); color: #fff; border-color: var(--green); }

.photo-label {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  border: 2px dashed #e0d3cb; border-radius: 10px; padding: 14px; cursor: pointer;
}
.photo-label input { display: none; }
#photoPreview { max-width: 100%; max-height: 180px; border-radius: 8px; }

input[type="time"], input[type="password"], input[type="text"], #cfName, #cfBrand, #cfServing, textarea {
  width: 100%; padding: 10px; border: 1px solid #e0d3cb; border-radius: 8px;
  font: inherit;
}
.row { display: flex; gap: 8px; justify-content: flex-end; }
button[type="submit"], .secondary {
  padding: 10px 18px; border-radius: 8px; border: none; cursor: pointer; font: inherit;
}
button[type="submit"] { background: var(--green); color: #fff; }
.secondary { background: #efe5de; color: var(--text); }
