/* ==== Quick-Add expand menu ==== */
.qa-backdrop {
  position: fixed; inset: 0; z-index: 25;
  background: rgba(255, 255, 255, 0);
  backdrop-filter: blur(0px);
  pointer-events: none;
  transition: background .3s ease, backdrop-filter .3s ease;
}
.qa-backdrop.on {
  background: rgba(30, 20, 40, 0.35);
  backdrop-filter: blur(6px);
  pointer-events: auto;
}
.qa-grid {
  position: fixed; z-index: 26;
  right: 18px;
  bottom: calc(96px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: min(370px, calc(100% - 36px));
  pointer-events: none;
}
@media (min-width: 500px) {
  .qa-grid {
    right: 50%;
    transform: translateX(calc(215px - 18px));
  }
}
.qa-hint {
  grid-column: 1 / -1;
  background: #111; color: #fff; border-radius: 18px; padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  box-shadow: 0 10px 28px rgba(17,17,17,0.18);
  opacity: 0; transform: translateY(40px) scale(.9); transform-origin: bottom right;
  transition: opacity .3s cubic-bezier(.34,1.56,.64,1), transform .4s cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
}
.qa-grid.on .qa-hint { opacity: 1; transform: none; pointer-events: auto; }
.qa-hint[hidden] { display: none; }   /* [hidden] must beat display:flex */
.qa-hint-t { font-size: 14px; font-weight: 600; line-height: 1.3; }
.qa-hint-t b { font-weight: 800; }
.qa-hint-btn {
  flex-shrink: 0; border: none; cursor: pointer; white-space: nowrap;
  background: #fff; color: #111; border-radius: 999px; padding: 8px 14px;
  font: inherit; font-size: 13px; font-weight: 700;
}
.qa-btn {
  background: #fff; border-radius: 22px;
  padding: 20px 18px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 12px;
  border: 1px solid rgba(17,17,17,0.06);
  box-shadow: 0 10px 28px rgba(17,17,17,0.14);
  cursor: pointer;
  color: #111;
  text-decoration: none;
  opacity: 0;
  transform: translate(60px, 60px) scale(.55);
  transform-origin: bottom right;
  transition: opacity .32s cubic-bezier(.34,1.56,.64,1),
              transform .42s cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
}
.qa-btn img.qa-ic {
  width: 36px; height: 36px; object-fit: contain;
  padding: 8px; background: #f5f2ea; border-radius: 12px;
  box-sizing: content-box;
}
.qa-btn .qa-lbl {
  font-size: 15px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2;
}
.qa-btn .qa-sub {
  font-size: 12px; font-weight: 500; color: #7d786a; margin-top: 2px;
}
.qa-grid.on .qa-btn {
  opacity: 1;
  transform: translate(0,0) scale(1);
  pointer-events: auto;
}
.qa-grid.on .qa-btn:nth-child(1) { transition-delay: .05s; }
.qa-grid.on .qa-btn:nth-child(2) { transition-delay: .10s; }
.qa-grid.on .qa-btn:nth-child(3) { transition-delay: .00s; }
.qa-grid.on .qa-btn:nth-child(4) { transition-delay: .15s; }

.fab.qa-open {
  transform: rotate(45deg);
  background: #4b5563;
}
.fab { transition: transform .35s cubic-bezier(.34,1.56,.64,1), background .25s; }

/* ==== Food-search modal ==== */
.fs-modal {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(30, 20, 40, 0);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  opacity: 0; pointer-events: none;
  transition: opacity .28s ease, background .28s ease;
}
.fs-modal.on {
  opacity: 1; pointer-events: auto;
  background: rgba(30, 20, 40, 0.4);
  backdrop-filter: blur(6px);
}
body.fs-lock { overflow: hidden; }

.fs-sheet {
  background: #fff;
  width: 100%; max-width: 480px;
  border-radius: 24px 24px 0 0;
  padding: 14px 14px calc(20px + env(safe-area-inset-bottom));
  height: 92dvh; max-height: 92dvh;
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform .34s cubic-bezier(.32,.72,.24,1);
  box-shadow: 0 -20px 40px rgba(0,0,0,0.18);
}
.fs-modal.on .fs-sheet { transform: translateY(0); }
@media (min-width: 500px) {
  .fs-modal { align-items: center; padding: 0 16px; }
  .fs-sheet { border-radius: 24px; max-height: 720px; height: 82dvh; transform: translateY(24px) scale(.98); }
  .fs-modal.on .fs-sheet { transform: translateY(0) scale(1); }
}

.fs-head {
  display: flex; align-items: center; gap: 12px; padding: 4px 6px 12px;
}
.fs-close {
  width: 36px; height: 36px; border-radius: 50%;
  background: #f5f2ea; border: none; cursor: pointer;
  display: grid; place-items: center;
}
.fs-close svg { width: 18px; height: 18px; stroke: #111; fill: none; stroke-width: 2.2; stroke-linecap: round; }
.fs-title { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }

.fs-search {
  position: relative; display: flex; align-items: center;
  background: #f5f2ea; border-radius: 14px; padding: 12px 14px;
  margin-bottom: 12px;
}
.fs-glass { width: 20px; height: 20px; stroke: #7d786a; fill: none; stroke-width: 2; flex-shrink: 0; }
.fs-input {
  flex: 1; border: none; background: transparent; outline: none;
  font: 500 16px/1.2 inherit; color: #111;
  margin-left: 10px; padding: 4px 0;
  -webkit-appearance: none;
}
.fs-input::placeholder { color: #a8a394; }
/* type=search draws its own WebKit clear button — next to .fs-clear that made two
   crosses. -webkit-appearance:none on the field itself does not remove it. */
.fs-input::-webkit-search-cancel-button,
.fs-input::-webkit-search-decoration,
.fs-input::-webkit-search-results-button,
.fs-input::-webkit-search-results-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}
.fs-clear {
  border: none; background: rgba(17,17,17,0.06); border-radius: 50%;
  width: 24px; height: 24px; display: grid; place-items: center;
  cursor: pointer; margin-left: 6px;
}
.fs-clear svg { width: 12px; height: 12px; stroke: #4b5563; fill: none; stroke-width: 2.4; stroke-linecap: round; }

.fs-list {
  flex: 1; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 6px;
  padding-bottom: 8px;
}
.fs-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #fff; border: 1px solid rgba(17,17,17,0.06);
  border-radius: 14px; padding: 12px 14px;
  cursor: pointer; text-align: left;
  transition: background .15s, border-color .15s;
}
.fs-item:hover { background: #fafaf7; border-color: rgba(17,17,17,0.10); }
.fs-item:active { background: #f5f2ea; }
.fs-item-l { flex: 1; min-width: 0; }
.fs-name {
  font-weight: 700; font-size: 15px; color: #111;
  letter-spacing: -0.01em; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fs-brand {
  font-weight: 500; color: #7d786a; margin-left: 6px; font-size: 13px;
}
.fs-macros {
  display: flex; gap: 8px; margin-top: 4px; font-size: 12px; font-weight: 600;
  color: #7d786a;
}
.fs-macros .mm.p { color: #b45309; }
.fs-macros .mm.c { color: #4338ca; }
.fs-macros .mm.f { color: #b91c1c; }
.fs-kcal {
  font-weight: 800; font-size: 20px; letter-spacing: -0.02em; color: #111;
  display: flex; flex-direction: column; align-items: flex-end; line-height: 1;
  flex-shrink: 0;
}
.fs-kcal small { font-size: 10px; font-weight: 600; color: #a8a394; margin-top: 3px; letter-spacing: 0.02em; }

.fs-empty, .fs-null, .fs-err {
  padding: 40px 24px; text-align: center;
  color: #7d786a; font-size: 14px; line-height: 1.5;
}
.fs-err { color: #b91c1c; }
.fs-loading {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 40px 24px; color: #7d786a; font-size: 14px; font-weight: 600;
}
.fs-loading[hidden] { display: none; }   /* [hidden] must beat display:flex */
.fs-spin {
  width: 20px; height: 20px; border-radius: 999px;
  border: 2.5px solid #e3dfd2; border-top-color: #7c3aed;
  animation: fsspin .7s linear infinite; flex-shrink: 0;
}
@keyframes fsspin { to { transform: rotate(360deg); } }

/* ==== Portion / photo-confirm sheet ==== */
.cm-modal {
  position: fixed; inset: 0; z-index: 45;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(30,20,40,0); opacity: 0; pointer-events: none;
  transition: opacity .28s ease, background .28s ease;
}
.cm-modal.on { opacity: 1; pointer-events: auto; background: rgba(30,20,40,.4); backdrop-filter: blur(6px); }
.cm-sheet {
  background: #fff; width: 100%; max-width: 480px;
  border-radius: 24px 24px 0 0;
  padding: 18px 20px calc(22px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform .34s cubic-bezier(.32,.72,.24,1);
  box-shadow: 0 -20px 40px rgba(0,0,0,.18);
}
.cm-modal.on .cm-sheet { transform: translateY(0); }
@media (min-width: 500px) {
  .cm-modal { align-items: center; padding: 0 16px; }
  .cm-sheet { border-radius: 24px; transform: translateY(24px) scale(.98); }
  .cm-modal.on .cm-sheet { transform: none; }
}
.cm-h { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.cm-title { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; flex: 1; line-height: 1.2; }
.cm-daterow {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: -2px 0 14px; font-size: 13.5px; color: #7d786a; font-weight: 600;
}
.cm-daterow b { color: #111; font-weight: 800; }
.cm-daytoday {
  flex-shrink: 0; border: none; background: #f5f2ea; color: #111; cursor: pointer;
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 12.5px; font-weight: 700;
}
.cm-field { margin-bottom: 12px; }
.cm-field label { display: block; font-size: 12.5px; color: #a8a394; font-weight: 700; margin-bottom: 6px; }
.cm-inp {
  width: 100%; background: #f5f2ea; border: none; border-radius: 14px;
  padding: 14px 16px; font: 700 18px/1.1 inherit; color: #111; outline: none; -webkit-appearance: none;
}
.cm-inp.name { font-size: 16px; }
.cm-step {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #f5f2ea; border-radius: 14px; padding: 10px 12px;
}
.cm-sbtn {
  width: 44px; height: 44px; border-radius: 12px; border: none; flex-shrink: 0;
  background: #fff; color: #111; font-size: 26px; font-weight: 700; line-height: 1; cursor: pointer;
  box-shadow: 0 1px 3px rgba(17,17,17,.08); display: grid; place-items: center;
}
.cm-sbtn:active { transform: scale(.92); }
.cm-scount { text-align: center; line-height: 1.1; }
.cm-scount b { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.cm-scount small { display: block; font-size: 12px; color: #7d786a; font-weight: 600; margin-top: 3px; }
.cm-total { text-align: center; font-size: 13px; color: #a8a394; font-weight: 700; margin-top: 8px; }
.cm-macros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 6px 0 18px; }
.cm-macro { background: #faf8f2; border: 1px solid rgba(17,17,17,.05); border-radius: 14px; padding: 12px 4px; text-align: center; }
.cm-macro .v { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; }
.cm-macro .k { font-size: 11px; color: #a8a394; font-weight: 700; margin-top: 3px; }
.cm-add {
  width: 100%; background: #111; color: #fff; border: none; border-radius: 16px;
  padding: 16px; font-size: 16px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.cm-add:disabled { opacity: .5; }
.cm-add svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2.6; stroke-linecap: round; }
.cm-recog { text-align: center; }
.cm-preview { width: 100%; max-height: 210px; object-fit: cover; border-radius: 16px; display: block; }
.cm-preview.sm { max-height: 130px; margin-bottom: 14px; }
.cm-note { color: #7d786a; font-size: 15px; text-align: center; padding: 26px 10px; line-height: 1.5; }
.cm-spin { text-align: center; padding: 34px 10px; color: #7d786a; font-weight: 600; }
.cm-spin .dot { animation: cmpulse 1s infinite; }
@keyframes cmpulse { 0%,100%{opacity:.3} 50%{opacity:1} }

/* purple scanner over the photo while recognising — a 5.4s cycle of three
   effects: laser sweeps top->bottom, then left->right, then the photo pulses
   with a violet glow. All phases share one timeline so they never overlap. */
.cm-scan { position: relative; border-radius: 16px; overflow: hidden; animation: kring 5.4s ease-in-out infinite; }
.cm-scan img { display: block; animation: kflash 5.4s ease-in-out infinite; }
.cm-scan::before {          /* phase 1: horizontal beam going down */
  content: ''; position: absolute; left: 0; right: 0; top: -48px; height: 48px; z-index: 2; opacity: 0;
  background: linear-gradient(180deg, rgba(124,58,237,0), rgba(124,58,237,.22) 60%, rgba(167,139,250,.85));
  border-bottom: 2px solid rgba(216,204,255,.95);
  box-shadow: 0 4px 18px 3px rgba(124,58,237,.55);
  animation: kbeamH 5.4s cubic-bezier(.45,0,.55,1) infinite;
}
.cm-scan::after {           /* phase 2: vertical beam going right */
  content: ''; position: absolute; top: 0; bottom: 0; left: -48px; width: 48px; z-index: 2; opacity: 0;
  background: linear-gradient(90deg, rgba(124,58,237,0), rgba(124,58,237,.22) 60%, rgba(167,139,250,.85));
  border-right: 2px solid rgba(216,204,255,.95);
  box-shadow: 4px 0 18px 3px rgba(124,58,237,.55);
  animation: kbeamV 5.4s cubic-bezier(.45,0,.55,1) infinite;
}
@keyframes kbeamH {
  0% { top: -48px; opacity: 0; } 2% { opacity: 1; }
  28% { top: 100%; opacity: 1; } 31% { top: 100%; opacity: 0; }
  100% { top: 100%; opacity: 0; }
}
@keyframes kbeamV {
  0%, 34% { left: -48px; opacity: 0; } 36% { opacity: 1; }
  62% { left: 100%; opacity: 1; } 65%, 100% { left: 100%; opacity: 0; }
}
@keyframes kflash {         /* phase 3: photo brightness pulses */
  0%, 66%, 100% { filter: none; }
  72% { filter: brightness(1.18) saturate(1.25); }
  78% { filter: brightness(1); }
  84% { filter: brightness(1.22) saturate(1.3); }
  92% { filter: none; }
}
@keyframes kring {          /* phase 3: violet glow rings around the frame */
  0%, 66% { box-shadow: 0 0 0 0 rgba(124,58,237,0); }
  72% { box-shadow: 0 0 0 4px rgba(124,58,237,.35), 0 0 24px 6px rgba(124,58,237,.35); }
  78% { box-shadow: 0 0 0 2px rgba(124,58,237,.15), 0 0 10px 2px rgba(124,58,237,.2); }
  84% { box-shadow: 0 0 0 5px rgba(124,58,237,.4), 0 0 28px 8px rgba(124,58,237,.4); }
  92%, 100% { box-shadow: 0 0 0 0 rgba(124,58,237,0); }
}

/* meal edit sheet */
.em-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.em-del {
  display: block; width: 100%; margin-top: 10px; background: transparent;
  border: none; color: #dc2626; font: inherit; font-size: 14px; font-weight: 700;
  padding: 12px; cursor: pointer; border-radius: 12px;
}
.em-del.armed { background: rgba(220,38,38,.08); }
.em-del:disabled { opacity: .5; }

/* AI corrections (refine) */
.cm-refine {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; margin-top: 10px;
  background: #f3eefe; color: #7c3aed;
  border: 1px solid rgba(124,58,237,.22); border-radius: 16px; padding: 14px;
  font: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
}
.cm-refine svg { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; }
.cm-refine:active { transform: scale(.98); }
.cm-add.ai { background: #7c3aed; }
.cm-add.ai svg { fill: #fff; stroke: none; }
.cm-ta {
  width: 100%; background: #f5f2ea; border: none; border-radius: 12px; padding: 12px 14px;
  font: inherit; font-size: 15px; color: #111; outline: none; resize: none; -webkit-appearance: none;
}
.rf-sum { text-align: center; font-size: 13px; font-weight: 700; color: #7d786a; margin: 10px 0 14px; }
.rf-err { color: #dc2626; font-size: 13px; font-weight: 600; text-align: center; margin-bottom: 10px; }

/* pretty error (not food / network) */
.cm-err { text-align: center; padding: 18px 12px 10px; }
.cm-err-ic { width: 74px; height: 74px; margin: 0 auto 16px; border-radius: 50%; background: #f5f2ea; display: grid; place-items: center; font-size: 34px; position: relative; }
.cm-err-ic.nomatch::after { content: ''; position: absolute; width: 3px; height: 54px; background: #dc2626; transform: rotate(45deg); border-radius: 3px; box-shadow: 0 0 0 3px #f5f2ea; }
.cm-err-t { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; margin-bottom: 8px; }
.cm-err-s { color: #7d786a; font-size: 14px; line-height: 1.5; max-width: 300px; margin: 0 auto 18px; }
.cm-err-btn { background: #7c3aed; color: #fff; border: none; border-radius: 14px; padding: 13px 24px; font: inherit; font-size: 15px; font-weight: 700; cursor: pointer; }
.cm-err-btn:active { transform: scale(.97); }
.cm-recents { display: flex; flex-direction: column; gap: 6px; max-height: 60dvh; overflow-y: auto; }

/* recent/frequent dishes in the search empty-state */
.fs-recent-hd {
  font-size: 12.5px; font-weight: 700; color: #a8a394; letter-spacing: 0.02em;
  padding: 2px 4px 8px; text-transform: uppercase;
}
.fs-item .fs-freq {
  display: inline-flex; align-items: center; gap: 3px; margin-left: 8px;
  font-size: 11px; font-weight: 700; color: #7c3aed;
  background: rgba(124,58,237,.10); border-radius: 999px; padding: 1px 7px;
  vertical-align: middle;
}
