/* Food Log — warm minimal, numbers-first, hairline-only chrome.
 * Source: Anton's design package (Food Logger.html).
 * Mobile-first, plain CSS, no build step.
 */

:root {
  /* ── Color (oklch where supported, hex fallback) ── */
  --bg:        #f8f6f2;             /* warm cream — page background */
  --surface:   #f3efe8;             /* slightly deeper, used for sheets/tiles */
  --fg:        #2a2620;             /* near-black ink */
  --muted:     #8a8378;             /* secondary copy */
  --hairline:  #e6e0d4;             /* dividers and faint borders */
  --accent:    #b85c3a;             /* terracotta — used very sparingly */
  --accent-soft: #f0e4dc;
  --destructive: #b85c3a;           /* same terracotta — single accent */

  /* ── Typography ── */
  --font-ui:      "Inter Tight", Inter, system-ui, -apple-system, sans-serif;
  --font-display: "Source Serif 4", "Source Serif Pro", Georgia, serif;

  --text-xs:    11px;
  --text-sm:    12px;
  --text-body:  14px;
  --text-md:    16px;
  --text-heading: 22px;
  --text-display: 64px;             /* hero "remaining" number */

  /* ── Spacing (4px base) ── */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  /* ── Layout ── */
  --page-pad: 24px;
  --content-max: 480px;
  --touch-min: 44px;

  /* Numeric column widths so today / 7d-avg / meal-totals all line up */
  --col-kcal: 56px;
  --col-unit: 32px;
  --col-macro: 32px;
}

/* ── Reset & base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  font-size: var(--text-body);
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

::selection { background: var(--accent); color: #fff; }

.num { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }
.display {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: -0.02em;
}

/* ── Page container ─────────────────────────────────────── */
.page-container {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--page-pad) 120px;   /* bottom pad clears the log-food affordance */
  min-height: 100vh;
  position: relative;
}

/* ── Hero — big remaining kcal ──────────────────────────── */
.hero {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-md);
  padding-top: var(--space-2xl);
}

.hero-number {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-display);
  line-height: 0.95;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}

.hero-number.over {
  color: var(--accent);
}

.hero-label {
  font-size: var(--text-xs);
  color: var(--muted);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* ── Tracker rows — TODAY / 7-DAY AVG ───────────────────── */
.tracker {
  margin-top: var(--space-xl);
}

.tracker-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-xs) 0;
}

.tracker-label {
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.tracker-row.faded .tracker-label,
.tracker-row.faded .stat-grid {
  opacity: 0.65;
}

/* ── Stat grid — column-aligned tabular numbers ─────────── */
/* "1,125 kcal  66p · 124c · 37f" with each column fixed-width
   so the rightmost edge stays put across rows */
.stat-grid {
  display: inline-flex;
  align-items: baseline;
  font-variant-numeric: tabular-nums;
  font-size: var(--text-body);
  white-space: nowrap;
}

.stat-grid .sg-kcal {
  display: inline-block;
  width: var(--col-kcal);
  text-align: right;
  font-weight: 500;
  color: var(--fg);
}

.stat-grid .sg-unit {
  display: inline-block;
  width: var(--col-unit);
  margin-left: var(--space-xs);
  color: var(--muted);
  font-weight: 400;
}

.stat-grid .sg-macro {
  display: inline-block;
  width: var(--col-macro);
  text-align: right;
  color: var(--muted);
  margin-left: var(--space-xs);
  font-weight: 400;
}

.stat-grid .sg-macro .sg-suffix {
  color: var(--muted);
  opacity: 0.7;
  margin-left: 1px;
}

.stat-grid.faded .sg-kcal,
.stat-grid.faded .sg-unit,
.stat-grid.faded .sg-macro { color: var(--muted); }

/* ── Meal sections ──────────────────────────────────────── */
.meal-section {
  margin-top: var(--space-xl);
}

.meal-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-md);
  padding: 0 0 var(--space-sm);
  border-bottom: 1px solid var(--hairline);
}

.meal-header.empty {
  border-bottom: none;
}

.meal-name {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--fg);
}

.meal-section.empty .meal-name {
  opacity: 0.4;
}

/* ── Entry rows (within a meal) ─────────────────────────── */
.entry-row {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: var(--space-sm);
  align-items: baseline;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--hairline);
  position: relative;
}

.entry-row:last-child {
  border-bottom: none;
}

.entry-time {
  font-size: var(--text-xs);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.entry-name-wrap {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-xs);
  min-width: 0;
  overflow: hidden;
}

.entry-name {
  font-size: var(--text-body);
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.entry-thumb-wrap {
  grid-column: 1 / -1;
  margin-top: 4px;
  display: flex;
  justify-content: flex-end;
}

.entry-name.editable {
  border-bottom: 1px dashed transparent;
  cursor: pointer;
}
.entry-name.editable:hover {
  border-bottom-color: var(--hairline);
}

.entry-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.entry-range {
  font-size: 10px;
  color: var(--muted);
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

/* Entry actions row — appears below an entry when needed (delete, etc.) */
.entry-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: 4px 0 0;
  margin-bottom: -4px;
}

.btn-delete {
  background: none;
  border: none;
  color: var(--muted);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: var(--space-xs) var(--space-sm);
  min-height: 32px;
  cursor: pointer;
}

.btn-delete:hover { color: var(--accent); }

/* ── Date navigation (sits subtly above hero) ───────────── */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) 0 0;
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.date-nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  color: var(--muted);
  text-decoration: none;
  font-size: 18px;
}

.date-nav a:hover { color: var(--fg); }

.date-display {
  font-size: var(--text-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Log Food affordance — bottom-anchored ──────────────── */
.log-food-cta {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg);
  border-top: 1px solid var(--hairline);
  padding: 14px var(--page-pad) calc(env(safe-area-inset-bottom, 16px) + 18px);
  text-align: center;
  z-index: 10;
  text-decoration: none;
  color: var(--fg);
  display: block;
}

.log-food-cta-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.log-food-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--muted);
  opacity: 0.32;
}

.log-food-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--text-md);
  font-weight: 500;
  color: var(--fg);
  letter-spacing: 0.01em;
}

.log-food-label .plus {
  font-size: 20px;
  font-weight: 300;
  opacity: 0.7;
}

/* ── Empty state ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  color: var(--muted);
  padding: var(--space-2xl) 0;
}

.empty-state h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-heading);
  margin-bottom: var(--space-sm);
  color: var(--fg);
}

/* ── Inline edit form (htmx) ────────────────────────────── */
.edit-form {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
}

.edit-form input,
.edit-form select {
  font-size: var(--text-body);
  padding: 4px 8px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  min-height: 32px;
  font-family: inherit;
}

.btn-save {
  background: var(--fg);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  min-height: 32px;
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}

.btn-cancel {
  background: none;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 4px 10px;
  min-height: 32px;
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}

.error-text {
  color: var(--accent);
  font-size: var(--text-xs);
}

/* ── Photo thumbnail / lightbox ─────────────────────────── */
.entry-thumb {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  display: block;
}

dialog.lightbox {
  border: none;
  background: transparent;
  max-width: 100vw;
  max-height: 100vh;
  padding: 0;
}

dialog.lightbox::backdrop {
  background: rgba(20, 16, 10, 0.85);
}

.lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
}

/* ── Confidence badge — minimal pill, single accent color ─ */
.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--muted);
  vertical-align: 1px;
  margin-left: var(--space-xs);
}

.badge-high { color: var(--muted); border-color: var(--hairline); }
.badge-med  { color: var(--accent); border-color: var(--accent-soft); }
.badge-low  { color: var(--accent); border-color: var(--accent); }

/* ── htmx animations ────────────────────────────────────── */
.entry-row.htmx-swapping {
  opacity: 0;
  transition: opacity 400ms ease-out;
}

.entry-row.flash-success {
  animation: successFlash 600ms ease-out;
}

@keyframes successFlash {
  from { background-color: var(--accent-soft); }
  to   { background-color: transparent; }
}

/* ── Toast (errors + Phase 5 quick-add) ─────────────────── */
.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: var(--text-body);
  z-index: 200;
  background: var(--fg);
  color: var(--bg);
  animation: toastFadeIn 200ms ease-out;
}

.toast-error { background: var(--accent); color: #fff; }

.toast-quickadd {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  transition: opacity 200ms ease-out;
}

.toast-quickadd .btn-undo {
  background: none;
  border: none;
  color: var(--bg);
  text-decoration: underline;
  font: inherit;
  cursor: pointer;
  padding: 0 var(--space-sm);
  min-height: 32px;
}

@keyframes toastFadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Login page ─────────────────────────────────────────── */
.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  padding: var(--space-2xl) var(--page-pad);
}

.login-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 48px;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-sm);
}

.login-subtext {
  font-size: var(--text-body);
  color: var(--muted);
  margin-bottom: var(--space-2xl);
}

.btn-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  height: 48px;
  padding: 0 var(--space-xl);
  background: var(--fg);
  color: var(--bg);
  border: 1px solid var(--fg);
  border-radius: 999px;
  font-size: var(--text-body);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  letter-spacing: 0.02em;
}

.btn-google:hover { opacity: 0.9; }

/* ── Add-food page (Phase 5) ────────────────────────────── */
.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: var(--space-md) 0 var(--space-lg);
}

.page-header h1 {
  font-family: var(--font-display);
  font-size: var(--text-heading);
  font-weight: 400;
  letter-spacing: -0.01em;
}

.link-back {
  color: var(--muted);
  text-decoration: none;
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  min-height: var(--touch-min);
  display: inline-flex;
  align-items: center;
}

.link-back:hover { color: var(--fg); }

.quick-add-section {
  padding: var(--space-md) 0 var(--space-lg);
}

.quick-add-heading {
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--space-sm);
}

.quick-add-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.quick-add-chip {
  min-height: var(--touch-min);
  padding: var(--space-xs) var(--space-md);
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--bg);
  color: var(--fg);
  font-size: var(--text-body);
}

.quick-add-chip:focus,
.quick-add-chip:active {
  border-color: var(--accent);
  outline: none;
}

.add-food-form-placeholder {
  padding: var(--space-lg) 0;
  color: var(--muted);
}

.add-food-form-placeholder p { margin-bottom: var(--space-md); }

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 14px;
  background: var(--fg);
  color: var(--bg);
  border: none;
  border-radius: 999px;
  font-size: var(--text-body);
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  min-height: var(--touch-min);
}

/* ── Error page ─────────────────────────────────────────── */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  text-align: center;
  padding: var(--space-2xl) var(--page-pad);
}

.error-page h1 {
  font-family: var(--font-display);
  font-size: var(--text-heading);
  margin-bottom: var(--space-sm);
}

.error-page p {
  color: var(--muted);
  margin-bottom: var(--space-md);
}

/* ── Responsive ─────────────────────────────────────────── */
@media (min-width: 600px) {
  .page-container { max-width: var(--content-max); }
}
