/* =============================================================
   MEAL CALCULATOR — search and meal building.

   Scoped under .meal-page. BMR and BMI are a form plus one number; a meal is
   a list the user builds, so this needs its own layout rather than the
   .calc-form / .calc-result pair. It still uses the same tokens and the same
   accent-override mechanism, so it reads as the same product.
   ============================================================= */

.meal-page {
  /* A third accent, distinct from BMR green and BMI blue. */
  --accent: #f0873a;
  --accent-ink: #b95a12;
  --accent-soft: rgba(240, 135, 58, 0.10);
  --accent-ring: rgba(240, 135, 58, 0.30);
}

/* The search box needs a real label for screen readers, but showing
   "Search USDA foods" above it would waste the line it sits on. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- two columns: build on the left, total pinned on the right ---- */
.meal-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-8);
  align-items: start;
}

@media (min-width: 900px) {
  .meal-body { grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.9fr); }
}

/* ---- search ---- */
.meal-search-wrap {
  position: relative;
}

.meal-search {
  width: 100%;
  font: inherit;
  font-size: 1.05rem;
  padding: var(--sp-4) var(--sp-4) var(--sp-4) 48px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink-2);
}

.meal-search:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

.meal-search-icon {
  position: absolute;
  left: var(--sp-4);
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  /* Without these the icon inherits fill:currentColor from the surrounding
     rule and renders as a solid black blob instead of a magnifier. */
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

.meal__hint {
  margin: var(--sp-3) 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.5;
}

.meal__hint--error { color: #c0392b; }

/* ---- result list ---- */
.meal__results {
  list-style: none;
  margin: var(--sp-3) 0 0;
  padding: 0;
  display: grid;
  gap: 2px;
  max-height: 340px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
}

.meal__pick {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.meal__result:last-child .meal__pick { border-bottom: 0; }
.meal__pick:hover, .meal__pick:focus-visible { background: var(--accent-soft); outline: none; }
.meal__pick:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }

.meal__pick-name {
  display: block;
  font-weight: 550;
  line-height: 1.35;
}

.meal__pick-meta {
  display: block;
  margin-top: 2px;
  font-size: 0.84rem;
  color: var(--muted);
}

.meal__pick-meta b { color: var(--accent-ink); font-weight: 600; }

/* ---- the meal list ---- */
.meal__list {
  list-style: none;
  margin: var(--sp-5) 0 0;
  padding: 0;
  display: grid;
  gap: var(--sp-2);
}

.meal__empty {
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
  border: 1px dashed var(--line);
  border-radius: var(--r-sm);
}

.meal__item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: var(--sp-3);
  align-items: center;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
}

.meal__item-name {
  display: block;
  font-weight: 550;
  line-height: 1.35;
}

.meal__item-source {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

.meal__item-qty {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.meal__qty-label {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.meal__qty {
  width: 74px;
  font: inherit;
  padding: var(--sp-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink-2);
  text-align: right;
}

.meal__qty:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.meal__item-kcal {
  min-width: 74px;
  text-align: right;
  line-height: 1.2;
}

.meal__item-kcal-num {
  display: block;
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.meal__item-kcal-unit {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
}

.meal__remove {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}

.meal__remove:hover {
  border-color: #c0392b;
  color: #c0392b;
  background: rgba(192, 57, 43, 0.08);
}

.meal__restore-note {
  margin: var(--sp-3) 0 0;
  font-size: 0.85rem;
  color: var(--accent-ink);
}

/* ---- the total panel ---- */
.meal-total {
  position: sticky;
  top: calc(var(--nav-h) + 16px);
  padding: var(--sp-6);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
}

.meal-total__label {
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 var(--sp-2);
}

.meal-total__value {
  margin: 0;
  font-size: clamp(2.6rem, 7vw, 3.4rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--accent-ink);
  font-variant-numeric: tabular-nums;
}

.meal-total__unit {
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 6px;
}

.meal-total__macros {
  margin: var(--sp-5) 0 0;
  display: grid;
  gap: var(--sp-2);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--line);
}

.macro {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  font-size: 0.92rem;
}

.macro__label { color: var(--muted); }

/* "not reported" is a smaller, quieter line than a number. A 0 in a big
   weightface would read as a measurement; it is not one. */
.macro__value.is-empty {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  opacity: 0.85;
}

.meal-total__basis {
  margin: var(--sp-4) 0 0;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--muted);
}

.meal-permalink {
  display: block;
  margin-top: var(--sp-4);
  font-size: 0.78rem;
  color: var(--muted);
  word-break: break-all;
  line-height: 1.45;
}

/* ---- below the fold ---- */
.meal-content { max-width: 68ch; }

.meal-content h2 {
  margin-top: var(--sp-10);
  font-size: 1.45rem;
  letter-spacing: -0.01em;
}

.meal-content p { line-height: 1.65; }

.meal-content table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--sp-4) 0;
  font-size: 0.92rem;
}

.meal-content th,
.meal-content td {
  text-align: left;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--line);
}

.meal-content th { font-weight: 600; }
.meal-content td:last-child,
.meal-content th:last-child { text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 560px) {
  .meal__item {
    grid-template-columns: minmax(0, 1fr) auto;
    row-gap: var(--sp-2);
  }
  .meal__item-qty { grid-column: 1 / 2; }
  .meal__item-kcal { grid-column: 2 / 3; grid-row: 1 / 2; }
  .meal__remove { grid-column: 2 / 3; grid-row: 2 / 3; }
}
