:root {
  --bg: #E2DEDE;
  --card: #FAF9F6;
  --card-2: #EBE8E2;
  --text: #3D4F5A;
  --muted: #7B8890;
  --accent: #73795D;
  --accent-dim: #9FA47F;
  --on-accent: #F6F4EF;
  --protein: #4F6B7A;
  --carbs: #B08948;
  --fat: #A9677A;
  --danger: #B4544E;
  --border: #DED8CF;
  --radius: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
}

.hidden { display: none !important; }

/* ---------- Header ---------- */
.view-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 16px;
}
.view-header > div:first-child, .view-header > h1 { flex: 1; }
h1 { font-family: "Newsreader", Georgia, serif; font-size: 32px; font-weight: 500; letter-spacing: -0.01em; }
.subtitle { color: var(--muted); font-size: 14px; }
h2 { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 15px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.13em; margin-bottom: 12px; }

.ring-big, .rs-val, .tile-val, .calc-val, .meal-kcal, .plate-totals, .plate-kcal, .macro-head span:last-child {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
}
.icon-btn:disabled { opacity: 0.35; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: 0 1px 2px rgba(61,79,90,0.04), 0 10px 26px -20px rgba(61,79,90,0.28);
}
.card-head-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card-head-row h2 { margin-bottom: 0; }

.banner {
  background: var(--card-2);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  font-size: 15px;
}
.banner a { color: var(--accent); font-weight: 600; }

/* ---------- Calorie ring ---------- */
.ring-card { display: flex; align-items: center; gap: 20px; }
.ring-wrap { position: relative; width: 150px; height: 150px; flex-shrink: 0; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg, .ring-fg { fill: none; stroke-width: 11; stroke-linecap: round; }
.ring-bg { stroke: var(--card-2); }
.ring-fg { stroke: var(--accent); stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset 0.6s ease, stroke 0.3s; }
.ring-fg.over { stroke: var(--danger); }
.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.ring-big { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.ring-big.over { color: var(--danger); }
.ring-label { font-size: 12px; color: var(--muted); }
.ring-stats { flex: 1; display: flex; flex-direction: column; gap: 16px; }
.rs { display: flex; flex-direction: column; }
.rs-val { font-size: 22px; font-weight: 700; }
.rs-label { font-size: 13px; color: var(--muted); }

/* ---------- Macros ---------- */
.macro-row { display: flex; flex-direction: column; gap: 14px; }
.macro-head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.macro-head span:last-child { color: var(--muted); }
.bar { height: 8px; background: var(--card-2); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; width: 0%; border-radius: 99px; transition: width 0.5s ease; }
.bar-fill.p { background: var(--protein); }
.bar-fill.c { background: var(--carbs); }
.bar-fill.f { background: var(--fat); }

/* ---------- Meal list ---------- */
.meal-list { list-style: none; }
.meal-list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.meal-list li:last-child { border-bottom: none; }
.meal-list .empty { color: var(--muted); font-size: 14px; justify-content: center; }
.meal-info { flex: 1; min-width: 0; }
.meal-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-macros { font-size: 12.5px; color: var(--muted); }
.meal-kcal { font-weight: 700; font-size: 15px; white-space: nowrap; }
.meal-del {
  border: none; background: none; color: var(--muted);
  font-size: 18px; cursor: pointer; padding: 6px;
}
.meal-del:active { color: var(--danger); }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  padding: 14px 18px;
  cursor: pointer;
  color: var(--on-accent);
  background: var(--accent);
}
.btn:active { transform: scale(0.98); }
.btn-sm { padding: 8px 14px; font-size: 14px; }
.btn-block { display: block; width: 100%; margin-top: 16px; }

/* ---------- Segmented control ---------- */
.seg {
  display: flex; gap: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 14px;
}
.seg-btn {
  flex: 1;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 9px;
  border-radius: 9px;
  cursor: pointer;
}
.seg-btn.active { background: var(--card-2); color: var(--text); }

/* ---------- Stats ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.grid-2 .card { margin-bottom: 0; }
.stat-tile { display: flex; flex-direction: column; gap: 2px; padding: 16px; }
.tile-val { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.tile-label { font-size: 12.5px; color: var(--muted); }

.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; }
.legend { display: flex; gap: 18px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.dot-accent { background: var(--accent); }
.dot-line { background: var(--carbs); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; flex: 1; }
.field span { font-size: 13.5px; color: var(--muted); font-weight: 600; }
.field input, .field select, .search-input {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  padding: 13px 14px;
  width: 100%;
  appearance: none;
}
.field input:focus, .field select:focus, .search-input:focus { outline: 2px solid var(--accent-dim); }
.field-row { display: flex; gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); margin: 6px 0 4px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; }
#profile-form h2 { margin-top: 14px; }
#profile-form h2:first-of-type { margin-top: 0; }

/* ---------- Calc results ---------- */
.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.calc-item {
  background: var(--card-2);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex; flex-direction: column;
}
.calc-item.accent { outline: 1px solid var(--accent-dim); }
.calc-item.accent .calc-val { color: var(--accent); }
.calc-val { font-size: 21px; font-weight: 700; }
.calc-label { font-size: 12px; color: var(--muted); }
.note { font-size: 13.5px; color: var(--muted); margin-bottom: 14px; }
.warn { font-size: 14px; color: var(--carbs); margin-top: 8px; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-around;
  background: rgba(250,249,246,0.9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  z-index: 50;
}
.tab {
  flex: 1;
  max-width: 120px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 0;
  border-radius: 12px;
  cursor: pointer;
}
.tab-ico { font-size: 21px; }
.tab.active { color: var(--accent); }

/* ---------- Bottom sheets ---------- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(61,79,90,0.32);
  z-index: 90;
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 520px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  z-index: 100;
  max-height: 85vh;
  overflow-y: auto;
  animation: sheet-up 0.25s ease;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 42px; height: 5px; border-radius: 99px; background: var(--border); margin: 6px auto 16px; }
.sheet h2 { font-family: "Newsreader", Georgia, serif; font-weight: 500; color: var(--text); text-transform: none; font-size: 22px; letter-spacing: -0.01em; margin-bottom: 14px; }

.search-input { margin-bottom: 10px; }
.saved-list { list-style: none; max-height: 42vh; overflow-y: auto; }
.saved-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.saved-list li:last-child { border-bottom: none; }
.saved-list .empty { color: var(--muted); font-size: 14px; cursor: default; justify-content: center; }
.saved-add {
  border: none;
  background: var(--accent);
  color: var(--on-accent);
  width: 34px; height: 34px;
  border-radius: 10px;
  font-size: 20px; font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}
.saved-del { border: none; background: none; color: var(--muted); font-size: 17px; padding: 6px; cursor: pointer; flex-shrink: 0; }

/* ---------- Login ---------- */
.login-header { margin-top: 28px; }
body.logged-out .tabbar { display: none; }

.user-list { list-style: none; }
.user-list > li { border-bottom: 1px solid var(--border); }
.user-list > li:last-child { border-bottom: none; }
.user-list .empty { color: var(--muted); font-size: 14px; padding: 12px 0; text-align: center; }
.user-line { display: flex; align-items: center; }
.user-row {
  display: flex; align-items: center; gap: 14px;
  flex: 1; min-width: 0;
  padding: 13px 4px;
  border: none; background: none;
  color: var(--text);
  font-size: 16px; font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700;
  flex-shrink: 0;
}
.user-row .meal-info { flex: 1; }
.user-lock { color: var(--muted); font-size: 14px; }
.user-del { border: none; background: none; color: var(--muted); font-size: 17px; padding: 8px; cursor: pointer; }

.pin-row { display: flex; gap: 10px; padding: 0 4px 14px 60px; }
.pin-row input {
  flex: 1; min-width: 0;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  padding: 11px 14px;
}
.pin-row input:focus { outline: 2px solid var(--accent-dim); }
.pin-row .btn { padding: 11px 18px; }
.pin-error { color: var(--danger); font-size: 13px; padding: 0 4px 12px 60px; }

.account-row { display: flex; align-items: center; gap: 12px; }
.btn-ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--border); }

/* ---------- Auth (email + Google) ---------- */
.auth-card { display: flex; flex-direction: column; }
.btn-google {
  background: #ffffff;
  color: #1f2328;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  border: 1px solid var(--border);
}
.btn-google:active { transform: scale(0.98); }
.g-icon { width: 18px; height: 18px; flex-shrink: 0; }
#auth-form { margin-top: 4px; }
.auth-error {
  color: var(--danger);
  font-size: 13.5px;
  font-weight: 600;
  padding: 2px 2px 10px;
}
.link-btn {
  background: none; border: none;
  color: var(--accent);
  font-size: 14px; font-weight: 600;
  padding: 14px 8px 4px;
  cursor: pointer;
  text-align: center;
}

/* ---------- Brand lockup (login) ---------- */
.brand-lockup { display:flex; flex-direction:column; align-items:center; gap:14px; margin:20px 0 24px; text-align:center; }
.brand-mark { display:inline-flex; align-items:center; justify-content:center; width:66px; height:66px; border-radius:18px; background:var(--card); border:1px solid var(--border); box-shadow:0 12px 30px -18px rgba(61,79,90,0.35); }
.brand-bars { display:flex; align-items:flex-end; gap:5px; height:32px; }
.brand-bars i { display:block; width:6px; border-radius:3px; }
.brand-bars i:nth-child(1){ height:15px; background:#5C6248; }
.brand-bars i:nth-child(2){ height:23px; background:var(--accent); }
.brand-bars i:nth-child(3){ height:32px; background:#979C7E; }
.brand-word { font-family:"Newsreader", Georgia, serif; font-size:27px; font-weight:500; letter-spacing:-0.01em; color:var(--text); }

/* ---------- Estimator ---------- */
.est-heading {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.13em;
  margin: 14px 0 8px;
}
#estimate-pane .note { margin-bottom: 10px; }
#food-results { max-height: 30vh; }
#food-results .food-meta { font-size: 12px; color: var(--muted); }

.plate-list { list-style: none; }
.plate-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.plate-list li:last-child { border-bottom: none; }
.plate-name { flex: 1; min-width: 0; font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate-grams {
  width: 74px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  padding: 8px 10px;
  text-align: right;
}
.plate-grams:focus { outline: 2px solid var(--accent-dim); }
.plate-unit { font-size: 12.5px; color: var(--muted); width: 14px; }
.plate-kcal { font-size: 13.5px; color: var(--muted); width: 70px; text-align: right; white-space: nowrap; }

.plate-totals {
  display: flex; justify-content: space-between;
  background: var(--card-2);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 10px 0 12px;
  font-size: 14px; font-weight: 600;
}
.plate-totals span b { color: var(--accent); }

.est-divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); font-size: 13px;
  margin: 18px 0 4px;
}
.est-divider::before, .est-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.ai-textarea {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  padding: 13px 14px;
  resize: vertical;
  margin-bottom: 10px;
}
.ai-textarea:focus { outline: 2px solid var(--accent-dim); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }

.ai-result {
  background: var(--card-2);
  border: 1px solid var(--accent-dim);
  border-radius: 14px;
  padding: 14px;
  margin-top: 12px;
}
.ai-result .meal-name { margin-bottom: 10px; white-space: normal; }
.ai-grid { grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ai-grid .calc-item { background: var(--card); padding: 10px 8px; align-items: center; }
.ai-grid .calc-val { font-size: 17px; }
.ai-result .btn { margin-top: 4px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(92px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  border: 1px solid var(--border);
  color: var(--card);
  font-size: 14.5px;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 99px;
  z-index: 200;
  white-space: nowrap;
  animation: toast-in 0.2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
