/* Morsel — a kitchen ledger.
   Palette: paper / ink / basil, with a fixed tricolor macro code:
   protein=lake blue, carbs=wheat gold, fat=toasted clay.
   Signature: the "macro line" — every entry and every day carries a thin
   proportional P/C/F bar, so the shape of what you ate is readable at a glance. */

:root {
  --paper: #FAFAF6;
  --card: #FFFFFF;
  --ink: #1A2620;
  --muted: #6B746E;
  --line: #E4E2D8;
  --basil: #1F7A4C;
  --basil-dark: #145A37;
  --paprika: #C2452A;
  --protein: #3E6FB0;
  --carb: #C99B2E;
  --fat: #A85B3F;
  --radius: 12px;
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; overflow-x: hidden; }
body {
  font-family: var(--body);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100dvh;
  overflow-x: hidden;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
/* iOS Safari zooms the page when a focused input is under 16px and stays
   zoomed, clipping the layout — keep every input at 16px. */
input, select, textarea { font-size: 16px; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

#app { max-width: 680px; margin: 0 auto; padding: 12px 14px 24px; }

h1, h2, h3 { font-family: var(--display); letter-spacing: -0.01em; }
h1 { font-size: 26px; font-weight: 800; }
h2 { font-size: 19px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; }

a { color: var(--basil-dark); }

/* ---------------------------------------------------------------- header */
.day-head { padding: 8px 2px 4px; }
.day-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.day-nav h1 { flex: 1; text-align: center; font-size: 21px; }
.day-nav button {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  width: 40px; height: 40px; font-size: 17px;
}
.kcal-left { text-align: center; margin: 14px 0 4px; }
.kcal-left .big {
  font-family: var(--display); font-weight: 800; font-size: 44px;
  line-height: 1; font-variant-numeric: tabular-nums;
}
.kcal-left .big.over { color: var(--paprika); }
.kcal-left .lbl { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* signature: the macro line */
.macroline {
  display: flex; height: 6px; border-radius: 3px; overflow: hidden;
  background: var(--line); margin-top: 6px;
}
.macroline span { height: 100%; }
.macroline .p { background: var(--protein); }
.macroline .c { background: var(--carb); }
.macroline .f { background: var(--fat); }
.macroline.thin { height: 3px; margin-top: 4px; opacity: .85; }

.macro-row {
  display: flex; justify-content: center; gap: 18px; margin: 10px 0 2px;
  font-size: 12.5px; color: var(--muted);
}
.macro-row b { color: var(--ink); font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 5px; vertical-align: 1px; }
.dot.p { background: var(--protein); } .dot.c { background: var(--carb); }
.dot.f { background: var(--fat); }

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); margin: 12px 0; overflow: hidden;
}
.card-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 14px 6px;
}
.card-head .sum { color: var(--muted); font-size: 13px; }

.entry {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; border-top: 1px solid var(--line);
  width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0;
  text-align: left;
}
.entry .info { flex: 1; min-width: 0; }
.entry .nm { font-weight: 600; font-size: 14.5px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.entry .sub { color: var(--muted); font-size: 12.5px; }
.entry .kc { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; }
.entry .grp { color: var(--basil-dark); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; }

.empty-slot { padding: 10px 14px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 13.5px; width: 100%; background: none;
  border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }

/* ---------------------------------------------------------------- buttons */
.btn {
  background: var(--basil); color: #fff; border: 0; border-radius: 10px;
  padding: 11px 16px; font-weight: 600; font-size: 15px; width: 100%;
}
.btn:active { background: var(--basil-dark); }
.btn.secondary { background: var(--card); color: var(--ink);
  border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--paprika);
  border: 1px solid var(--line); }
.btn.small { width: auto; padding: 7px 12px; font-size: 13.5px; }
.btn:disabled { opacity: .5; }

.fab {
  position: fixed; right: 18px; bottom: calc(76px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--basil); color: #fff; font-size: 28px; line-height: 1;
  box-shadow: 0 4px 14px rgba(20, 90, 55, .35); z-index: 30;
}

/* ----------------------------------------------------------------- forms */
label.fld { display: block; margin: 10px 0 4px; font-size: 13px;
  font-weight: 600; color: var(--muted); }
input.txt, select.txt, textarea.txt {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--card); font-size: 16px;
}
input.txt:focus, select.txt:focus, textarea.txt:focus, .btn:focus-visible,
.tab:focus-visible, .entry:focus-visible {
  outline: 2px solid var(--basil); outline-offset: 1px;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; background: var(--card); }
.seg button { flex: 1; padding: 9px 4px; background: none; border: 0;
  font-size: 13.5px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--ink); color: var(--paper); }

/* ---------------------------------------------------------------- tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab { flex: 1; padding: 8px 0 7px; background: none; border: 0;
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 1px; }
.tab.active { color: var(--basil-dark); }
.tab-ic { font-size: 17px; }

/* ---------------------------------------------------------------- sheets */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(20, 30, 25, .45); z-index: 40;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  background: var(--paper); border-radius: 16px 16px 0 0;
  max-height: 92dvh; overflow-y: auto; padding: 10px 16px
    calc(18px + env(safe-area-inset-bottom));
  max-width: 680px; margin: 0 auto;
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(30px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet-grab { width: 36px; height: 4px; border-radius: 2px;
  background: var(--line); margin: 2px auto 10px; }
.sheet h2 { margin-bottom: 8px; }

.result {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 4px; background: none; border: 0;
  border-bottom: 1px solid var(--line); text-align: left;
}
.result .info { flex: 1; min-width: 0; }
.result .nm { font-weight: 600; font-size: 14.5px; }
.result .sub { color: var(--muted); font-size: 12.5px; }
.result .src { font-size: 10.5px; font-weight: 700; letter-spacing: .05em;
  color: var(--basil-dark); border: 1px solid var(--line); border-radius: 6px;
  padding: 2px 6px; }

.search-tabs { display: flex; gap: 6px; margin: 8px 0 10px; overflow-x: auto; }
.search-tabs button { border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 7px 14px; font-size: 13.5px; font-weight: 600;
  white-space: nowrap; color: var(--muted); }
.search-tabs button.on { background: var(--ink); color: var(--paper);
  border-color: var(--ink); }

#scan-region { width: 100%; border-radius: var(--radius); overflow: hidden;
  background: #000; min-height: 240px; }

.ing-row { display: flex; align-items: center; gap: 8px; padding: 8px 0;
  border-bottom: 1px solid var(--line); }
.ing-row .nm { flex: 1; font-size: 14px; font-weight: 600; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ing-row input { width: 74px; padding: 7px 8px; border: 1px solid var(--line);
  border-radius: 8px; text-align: right; font-size: 16px; }
.ing-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--basil); }
.ing-row .un { color: var(--muted); font-size: 12.5px; }
.ing-row .rm { background: none; border: 0; color: var(--paprika);
  font-size: 17px; padding: 4px 6px; }

.note { color: var(--muted); font-size: 12.5px; margin: 6px 0; }
.stat-line { display: flex; justify-content: space-between; font-size: 13.5px;
  padding: 3px 0; }
.stat-line b { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ auth */
.auth-wrap { max-width: 380px; margin: 10dvh auto 0; padding: 0 8px; }
.auth-wrap .brand { font-family: var(--display); font-weight: 800;
  font-size: 40px; letter-spacing: -0.02em; }
.auth-wrap .brand em { color: var(--basil); font-style: normal; }
.auth-wrap .tag { color: var(--muted); margin: 2px 0 22px; }
.auth-err { color: var(--paprika); font-size: 13.5px; margin-top: 8px; }
.auth-switch { margin-top: 16px; font-size: 14px; color: var(--muted); }

/* ----------------------------------------------------------------- toast */
#toast-root { position: fixed; left: 0; right: 0;
  bottom: calc(74px + env(safe-area-inset-bottom)); z-index: 60;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none; }
.toast { background: var(--ink); color: var(--paper); border-radius: 10px;
  padding: 9px 16px; font-size: 13.5px; max-width: 90%;
  box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.toast.err { background: var(--paprika); }

.list-item { display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border-top: 1px solid var(--line); width: 100%; background: none;
  border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }
.list-item:first-child { border-top: 0; }
.list-item .info { flex: 1; min-width: 0; }
.list-item .nm { font-weight: 600; }
.list-item .sub { color: var(--muted); font-size: 12.5px; }
.chev { color: var(--muted); }

.topbar { display: flex; justify-content: space-between; align-items: center;
  padding: 8px 2px; }

/* ------------------------------------------------------------------- 2FA */
#qr-box { display: flex; justify-content: center; padding: 14px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  margin: 10px 0; }
.secret-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px; letter-spacing: .08em; word-break: break-all;
  background: var(--card); border: 1px dashed var(--line); border-radius: 8px;
  padding: 8px 10px; margin: 8px 0; user-select: all; -webkit-user-select: all; }
.badge-on { color: var(--basil-dark); font-weight: 700; font-size: 12px;
  border: 1px solid var(--basil); border-radius: 6px; padding: 2px 8px; }
.badge-off { color: var(--muted); font-weight: 700; font-size: 12px;
  border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; }
