/* Nutrition — Phase 0 minimal styles. Phase 1+ will expand. */

:root {
  --bg:        #0c130e;
  --bg2:       #131b15;
  --card:      #1a2419;
  --border:    #2a3a2c;
  --text1:     #e8f5e9;
  --text2:     #b8c9bb;
  --text3:     #7a8e7e;
  --green:     #16a34a;
  --green-mute:#15803d;
  --red:       #ef4444;
  --shadow:    0 4px 12px rgba(0,0,0,0.3);

  --accent-protein: #f87171;  /* red-400 */
  --accent-carbs:   #fbbf24;  /* amber-400 */
  --accent-fat:     #a78bfa;  /* violet-400 */
  --accent-fiber:   #34d399;  /* emerald-400 */
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Sora', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text1);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

/* Loading splash */
#loading {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  background: var(--bg);
  z-index: 10000;
  font-size: 13px;
  color: var(--text3);
}
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
#toast {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  color: var(--text1);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
  z-index: 9500;
  box-shadow: var(--shadow);
}
#toast.show { opacity: 1; }
#toast[data-kind="error"] { border-color: var(--red); color: #fecaca; }

/* Undo banner (PLAN voice-flow-friction) */
#undo-banner {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--border);
  padding: 8px 12px 8px 16px;
  border-radius: 24px;
  font-size: 13px;
  display: none;
  align-items: center;
  gap: 10px;
  z-index: 9400;
  box-shadow: var(--shadow);
}
#undo-banner.show { display: flex; }
#undo-banner button {
  background: var(--green);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 16px;
  font-weight: 600;
  cursor: pointer;
}

/* Auth */
#auth-screen {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-box {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 32px;
  border-radius: 16px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}
.auth-logo {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}
.auth-logo span { color: var(--green); }
.auth-tagline {
  color: var(--text2);
  font-size: 14px;
  margin: 0 0 24px;
}
.google-btn {
  width: 100%;
  background: #fff;
  color: #1a1a1a;
  border: none;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.google-btn svg { width: 18px; height: 18px; }
.auth-note {
  font-size: 11px;
  color: var(--text3);
  margin: 16px 0 0;
}

/* App */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.brand {
  font-size: 18px;
  font-weight: 700;
}
.brand span { color: var(--green); }
.user-meta {
  display: flex; align-items: center; gap: 12px;
  font-size: 12px;
  color: var(--text2);
}
.user-name { color: var(--text1); font-weight: 500; }
.user-email { color: var(--text3); }

.btn {
  background: var(--green);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.btn-ghost {
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg2); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-danger { background: var(--red); }

/* App header tabs + main layout */
main { max-width: 720px; margin: 0 auto; padding: 16px; padding-bottom: 120px; }
.page-tabs { display: flex; gap: 4px; }
.page-tab {
  background: transparent; border: none; color: var(--text3);
  padding: 8px 14px; font-size: 14px; font-weight: 500; cursor: pointer; border-radius: 6px;
}
.page-tab.active { color: var(--text1); background: var(--bg2); }
.page-tab:hover:not(.active) { color: var(--text2); }
.page { display: none; }
.page.active { display: block; }
.muted { color: var(--text3); font-size: 12px; }

/* Summary card */
.summary-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.summary-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 16px; }
.summary-title { font-size: 14px; color: var(--text3); margin-bottom: 4px; }
.summary-date  { font-size: 22px; font-weight: 600; }
.summary-meta  { font-size: 12px; color: var(--text3); margin-top: 4px; }

/* Calories ring */
.ring-wrap { position: relative; width: 96px; height: 96px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--bg2); stroke-width: 8; }
.ring-fill  { fill: none; stroke: var(--green); stroke-width: 8; stroke-linecap: round;
              transition: stroke-dashoffset 400ms ease; }
.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.ring-val    { font-size: 22px; font-weight: 700; line-height: 1; }
.ring-target { font-size: 10px; color: var(--text3); margin-top: 2px; }

/* Macro bars */
.macro-bars { display: grid; gap: 10px; }
.macro-bar-head {
  display: flex; justify-content: space-between; font-size: 12px;
  color: var(--text2); margin-bottom: 4px;
}
.macro-val { color: var(--text3); }
.macro-bar-track { height: 6px; background: var(--bg2); border-radius: 999px; overflow: hidden; }
.macro-bar-fill  { height: 100%; border-radius: 999px; transition: width 400ms ease; }

/* Entries section */
.entries-section { margin-top: 8px; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 8px 4px 12px;
}
.section-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.head-actions { display: flex; gap: 8px; align-items: center; }

/* Photo button mimics other btns but accepts label-for-input pattern */
label.btn { display: inline-flex; align-items: center; gap: 6px; }

/* Entry list */
.entry-list { display: grid; gap: 8px; }
.entry-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 12px 12px 14px;
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
}
.entry-main   { min-width: 0; }
.entry-name   { font-weight: 600; font-size: 14px; }
.entry-sub    { font-size: 12px; color: var(--text3); margin-top: 2px;
                overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-macros { text-align: right; font-size: 12px; color: var(--text2); }
.entry-cal    { font-weight: 600; color: var(--text1); }
.entry-cal span { color: var(--text3); font-weight: 400; font-size: 10px; }
.entry-protein { color: var(--text3); margin-top: 2px; }
.entry-del {
  background: transparent; color: var(--text3); border: none;
  width: 32px; height: 32px; border-radius: 6px; cursor: pointer; font-size: 14px;
}
.entry-del:hover { background: var(--bg2); color: var(--red); }
.entry-del:disabled { opacity: 0.4; cursor: wait; }

.empty {
  text-align: center; padding: 32px 16px;
  color: var(--text3); font-size: 13px;
  border: 1px dashed var(--border); border-radius: 12px;
}

/* History date groups */
.date-group { margin-bottom: 18px; }
.date-head  {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 0 4px 8px; border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.date-label { font-weight: 600; font-size: 14px; }
.date-sub   { color: var(--text3); font-size: 12px; }

/* FAB — primary add-meal trigger on the home page */
.fab {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0));
  right:  calc(96px + env(safe-area-inset-right, 0));     /* leave room for voice FAB */
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 28px;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(22,163,74,0.4), 0 2px 6px rgba(0,0,0,0.3);
  z-index: 8500;
  transition: transform 150ms ease;
}
.fab:hover { transform: scale(1.06); }
.fab:active { transform: scale(0.96); }

/* Form / modal extensions */
.modal-form { max-width: 480px; }
.modal-body { padding: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-row.full { grid-column: 1 / -1; }
.form-row label { font-size: 12px; color: var(--text3); font-weight: 500; }
.form-row input {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text1);
  padding: 10px 12px; border-radius: 8px; font-size: 14px;
  font-family: inherit;
}
.form-row input:focus { outline: none; border-color: var(--green); }
.form-hint { font-size: 11px; color: var(--text3); margin: 4px 0 0; min-height: 14px; }

.portion-input { display: grid; grid-template-columns: 1fr 1.5fr; gap: 6px; }

.modal-body .modal-footer {
  grid-column: 1 / -1;
  padding: 12px 0 0;
  margin-top: 4px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}
.modal-close {
  background: transparent; border: none; color: var(--text2);
  font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg2); color: var(--text1); }

/* Combobox */
.combobox { position: relative; }
.combobox-list {
  position: absolute; top: 100%; left: 0; right: 0;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  margin: 4px 0 0; padding: 4px; list-style: none;
  max-height: 220px; overflow-y: auto;
  z-index: 100;
  box-shadow: var(--shadow);
}
.cb-opt {
  padding: 8px 10px; border-radius: 6px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  cursor: pointer; font-size: 14px;
}
.cb-opt:hover, .cb-opt.cb-active { background: var(--bg2); }
.cb-name { color: var(--text1); }
.cb-meta { color: var(--text3); font-size: 11px; }

/* Analyzing photo banner — slides up while vision call is in-flight */
.analyzing-banner {
  position: fixed;
  bottom: calc(96px + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text1);
  padding: 10px 16px;
  border-radius: 24px;
  font-size: 13px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  z-index: 9400;
}
.analyzing-banner.show { opacity: 1; transform: translate(-50%, 0); }
.spinner-sm {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

/* Ambiguity follow-up modal — distinct from the form modal */
.amb-body { display: block; padding: 16px 20px 20px; }
.amb-question { margin: 0 0 16px; font-size: 14px; color: var(--text1); }
.candidates { display: grid; gap: 8px; }
.candidate-chip {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text1);
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  text-align: left;
  transition: background 120ms ease, border-color 120ms ease;
}
.candidate-chip:hover { background: var(--card); border-color: var(--green); }
.cand-label { font-weight: 500; }
.cand-cal   { color: var(--text3); font-size: 12px; }

@media (max-width: 540px) {
  main { padding: 12px; padding-bottom: 100px; }
  .modal-body { grid-template-columns: 1fr; }
  .summary-card { padding: 16px; }
  .ring-wrap { width: 80px; height: 80px; }
  .ring-val  { font-size: 18px; }
  .fab { right: calc(88px + env(safe-area-inset-right, 0)); }
  .head-actions .btn { padding: 6px 10px; font-size: 12px; }
}

/* Modal overlay (used by confirmDialog in utils.js) */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center; justify-content: center;
  z-index: 9600;
  padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow);
}
.modal-header { padding: 16px; border-bottom: 1px solid var(--border); }
.modal-title { font-weight: 600; }
.modal-body { padding: 16px; color: var(--text2); font-size: 14px; }
.modal-footer { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
