/* ── CalorieTracker ── */

:root {
  --bg:      #f7faf7;
  --card:    #ffffff;
  --ink:     #1d2b22;
  --muted:   #71837a;
  --line:    #e3ebe5;
  --accent:  #2f9e63;
  --accent2: #e8f5ee;
  --protein: #2f9e63;
  --carbs:   #d99a2b;
  --fat:     #c45d8a;
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

/* ── Page scaffolding ─────────────────────────────────────────────────────── */

.pg-hdr {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 20px 20px 8px;
}
.pg-title { font-size: 22px; font-weight: 800; letter-spacing: -0.3px; }
.pg-date  { font-size: 14px; color: var(--muted); font-weight: 600; }

.pg { padding: 8px 16px 24px; display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}

.field-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin-bottom: 8px;
}

.recipe-hint { font-size: 12px; color: var(--muted); margin-top: 10px; }

.empty-state {
  list-style: none;
  padding: 36px 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Calorie ring + macros ────────────────────────────────────────────────── */

.ring-card { display: flex; align-items: center; gap: 18px; }

.ring-wrap { position: relative; width: 130px; height: 130px; flex-shrink: 0; }
.ring      { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg   { fill: none; stroke: var(--accent2); stroke-width: 11; }
.ring-fg   {
  fill: none;
  stroke: var(--accent);
  stroke-width: 11;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.4s ease;
}
.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.ring-val { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.ring-sub { font-size: 11px; color: var(--muted); font-weight: 600; }

.macros { flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.macro-top   { display: flex; justify-content: space-between; margin-bottom: 4px; }
.macro-label { font-size: 12px; font-weight: 700; color: var(--muted); }
.macro-val   { font-size: 12px; font-weight: 600; color: var(--ink); }
.macro-track { height: 6px; border-radius: 3px; background: var(--accent2); overflow: hidden; }
.macro-fill  { height: 100%; border-radius: 3px; background: var(--accent); }
.macro:nth-child(2) .macro-fill { background: var(--carbs); }
.macro:nth-child(3) .macro-fill { background: var(--fat); }

/* ── Entry list ───────────────────────────────────────────────────────────── */

.entry-list { list-style: none; }
.entry-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.entry-item:last-child { border-bottom: none; }
.entry-l    { min-width: 0; }
.entry-name { font-size: 15px; font-weight: 600; }
.entry-sub  { font-size: 12px; color: var(--muted); margin-top: 2px; text-transform: capitalize; }
.entry-cal  { font-size: 14px; font-weight: 700; color: var(--accent); white-space: nowrap; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.btn-accent { background: var(--accent); color: #fff; }
.btn-ghost  { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn-sm     { width: auto; padding: 8px 14px; font-size: 13px; }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(78px + env(safe-area-inset-bottom));
  width: 58px; height: 58px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 30px;
  font-weight: 600;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(47, 158, 99, 0.4);
  cursor: pointer;
}

/* ── Settings ─────────────────────────────────────────────────────────────── */

.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0;
  font-size: 15px;
  border-bottom: 1px solid var(--line);
}
.settings-row:last-of-type { border-bottom: none; }

.target-edit { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 14px; }
.target-edit input {
  width: 72px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  text-align: right;
  background: var(--bg);
  color: var(--ink);
}
.target-edit input:focus { outline: none; border-color: var(--accent); }

/* ── Bottom nav ───────────────────────────────────────────────────────────── */

#nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
#nav button {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 0 7px;
  border: none;
  background: none;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
#nav button.on { color: var(--accent); }
#nav svg {
  width: 22px; height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Modal ────────────────────────────────────────────────────────────────── */

#modal {
  position: fixed; inset: 0;
  background: rgba(20, 35, 26, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}
#modal.hidden { display: none; }

.modal-sheet {
  background: var(--card);
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
}
.modal-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.modal-title { font-size: 18px; font-weight: 800; }
.modal-close {
  background: none;
  border: none;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  margin-right: -6px;
  border-radius: 8px;
}
.modal-close:active { background: var(--accent2); }
.modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }

.btn-danger { color: #c0392b; border-color: #f0c9c3; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* ── Meal entry: loading + errors ─────────────────────────────────────────── */

.meal-error {
  background: #fdecea;
  color: #c0392b;
  border: 1px solid #f3c9c3;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}
/* ── Voice dictation ──────────────────────────────────────────────────────── */

.ta-wrap { position: relative; }
.ta-wrap textarea { padding-right: 46px; }
.mic-btn {
  position: absolute;
  right: 8px; bottom: 8px;
  width: 34px; height: 34px;
  border: none; border-radius: 50%;
  background: var(--accent2);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.mic-btn svg {
  width: 17px; height: 17px;
  fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}
.mic-btn.dictating {
  background: var(--accent);
  color: #fff;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(47, 158, 99, 0.5); }
  50%      { box-shadow: 0 0 0 7px rgba(47, 158, 99, 0); }
}

/* ── Photo controls ───────────────────────────────────────────────────────── */

.photo-btns { display: flex; gap: 10px; margin-bottom: 4px; }
.btn-soft {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--accent2);
  color: var(--accent);
  font-size: 14px;
  padding: 12px;
}
.btn-soft svg {
  width: 18px; height: 18px;
  fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}

.meal-photo { position: relative; margin-bottom: 14px; }
.meal-photo img {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: 12px;
  display: block;
}
.meal-photo-x {
  position: absolute; top: 8px; right: 8px;
  width: 30px; height: 30px;
  border: none; border-radius: 50%;
  background: rgba(20, 35, 26, 0.6);
  color: #fff; font-size: 18px; line-height: 1;
  cursor: pointer;
}

.meal-loading { text-align: center; padding: 40px 0; }
.meal-loading-text { font-size: 14px; color: var(--muted); margin-top: 14px; }
.spinner {
  width: 34px; height: 34px;
  margin: 0 auto;
  border: 3px solid var(--accent2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Estimate card ────────────────────────────────────────────────────────── */

.est-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.est-name { font-size: 17px; font-weight: 800; }
.est-meta { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.est-meal { font-size: 12px; color: var(--muted); text-transform: capitalize; }

.conf {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 2px 6px;
  border-radius: 6px;
}
.conf-high   { background: #e3f5ea; color: #1f7a47; }
.conf-medium { background: #fcf2dc; color: #9a6a14; }
.conf-low    { background: #fbe6ec; color: #a83258; }

.est-totals {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 14px 0;
  padding: 12px 14px;
  background: var(--accent2);
  border-radius: 12px;
}
.est-total-cal { font-size: 26px; font-weight: 800; color: var(--accent); }
.est-total-cal span { font-size: 13px; font-weight: 600; margin-left: 4px; }
.est-total-macros { display: flex; gap: 12px; font-size: 13px; font-weight: 600; color: var(--ink); }

.est-items { list-style: none; }
.est-item {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.est-item:last-child { border-bottom: none; }
.est-item-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.est-item-qty  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.est-item-macros { text-align: right; flex-shrink: 0; }
.est-cal { display: block; font-size: 14px; font-weight: 700; color: var(--accent); }
.est-pcf { font-size: 11px; color: var(--muted); }

.est-meal-chips { margin: 8px 0 0; }

.conf-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
  padding-top: 8px;
}

.est-redesc {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.est-assume { margin-top: 14px; }
.est-assume-h, .est-q-h {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--muted); margin-bottom: 6px;
}
.est-assume ul { margin: 0; padding-left: 18px; }
.est-assume li { font-size: 13px; color: var(--ink); line-height: 1.5; }

.est-questions {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.est-q { margin-bottom: 14px; }
.est-q-text { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.clarify-extra {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--ink);
  resize: none;
}
.clarify-extra:focus { outline: none; border-color: var(--accent); }

/* ── Form bits (used from phase 3 on) ─────────────────────────────────────── */

.fg { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.fg label { font-size: 13px; font-weight: 600; color: var(--muted); }
.fg input, .fg select, .fg textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: var(--bg);
  color: var(--ink);
}
.fg input:focus, .fg select:focus, .fg textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.chip.on { background: var(--accent2); border-color: var(--accent); color: var(--accent); }

/* ── Meal grouping (Today) ────────────────────────────────────────────────── */

.meal-card { padding: 12px 16px; }
.meal-group-h {
  display: flex; align-items: baseline; justify-content: space-between;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 2px;
}
.meal-group-h > span:first-child {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--muted);
}
.meal-group-cal { font-size: 13px; font-weight: 700; color: var(--ink); }

/* ── Entry editing ────────────────────────────────────────────────────────── */

.edit-meal-name {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px; font-weight: 700;
  font-family: inherit;
  background: var(--bg);
  color: var(--ink);
}
.edit-meal-name:focus { outline: none; border-color: var(--accent); }

.edit-items { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.edit-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: var(--bg);
}
.edit-item-top { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.edit-name {
  flex: 1; min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px; font-weight: 600;
  font-family: inherit;
  background: var(--card);
  color: var(--ink);
}
.edit-item-x {
  width: 30px; height: 30px; flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--muted);
  font-size: 18px; line-height: 1;
  cursor: pointer;
}
.edit-item-x[disabled] { opacity: 0.3; pointer-events: none; }
.edit-qty {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: var(--card);
  color: var(--muted);
  margin-bottom: 8px;
}
.edit-name:focus, .edit-qty:focus, .macro-input input:focus { outline: none; border-color: var(--accent); }

.edit-macros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.macro-input { display: flex; flex-direction: column; gap: 3px; }
.macro-input span { font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.macro-input input {
  width: 100%;
  padding: 7px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  text-align: center;
  background: var(--card);
  color: var(--ink);
}

/* ── Login ────────────────────────────────────────────────────────────────── */

#login {
  position: fixed; inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 30;
  padding: 24px;
}
.login-card {
  text-align: center;
  max-width: 320px;
  width: 100%;
}
.login-logo  { font-size: 52px; margin-bottom: 12px; }
.login-title { font-size: 26px; font-weight: 800; color: var(--accent); margin-bottom: 8px; }
.login-sub   { font-size: 14px; color: var(--muted); line-height: 1.5; margin-bottom: 24px; }
.login-btn   { margin-bottom: 14px; }
.login-foot  { font-size: 12px; color: var(--muted); }
