/* ============================================================
   kcal — styles
   Palette: espresso + saffron. Meals carry the hue scale.
   ============================================================ */

:root {
  --bg:        #131009;
  --surface:   #1D1811;
  --surface-2: #262017;
  --line:      #352C1D;
  --ink:       #F3EDE0;
  --muted:     #A2967E;
  --accent:    #E9A13B;   /* saffron */
  --danger:    #E05C4B;

  /* meal hues — warm scale, morning → night */
  --meal-breakfast: #E9A13B;
  --meal-lunch:     #D97E4A;
  --meal-dinner:    #C05B50;
  --meal-snack:     #8FAE6B;

  /* macros */
  --protein: #D96C4F;
  --carbs:   #D6C063;
  --fat:     #8FAE6B;

  --radius: 14px;
  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, output { font: inherit; }
h1, h2 { font-family: var(--font-display); margin: 0; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.view { min-height: 100dvh; }

/* ---------------- auth ---------------- */
#viewAuth { display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 360px; }
.brand { text-align: center; margin-bottom: 28px; }
.brand h1 { font-size: 44px; font-weight: 800; letter-spacing: -0.02em; }
.brand-sub { color: var(--muted); margin: 4px 0 0; }
.brand-mark {
  display: inline-block; width: 52px; height: 14px; border-radius: 7px;
  background: linear-gradient(90deg, var(--meal-breakfast), var(--meal-lunch), var(--meal-dinner), var(--meal-snack));
  margin-bottom: 12px;
}
.auth-error { color: var(--danger); font-size: 14px; text-align: center; }

/* ---------------- fields & buttons ---------------- */
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.btn {
  padding: 12px 18px; border-radius: var(--radius); font-weight: 600;
  transition: transform .06s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: #221805; }
.btn-primary:hover { background: #F0AE52; }
.btn-ghost { background: var(--surface); border: 1px solid var(--line); color: var(--ink); }
.btn-block { display: block; width: 100%; margin-top: 10px; }
.btn:focus-visible, .icon-btn:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------- topbar ---------------- */
.topbar {
  display: flex; align-items: center; gap: 4px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); z-index: 5;
}
.topbar-spacer { flex: 1; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; font-size: 20px;
  display: grid; place-items: center; color: var(--muted);
}
.icon-btn:hover { background: var(--surface); color: var(--ink); }
.date-label { font-family: var(--font-display); font-weight: 700; font-size: 18px; padding: 6px 10px; border-radius: 10px; }
.date-label:hover { background: var(--surface); }

/* ---------------- day gauge (signature) ---------------- */
.gauge-wrap { padding: 6px 16px 18px; }
.gauge-numbers { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.gauge-big {
  font-family: var(--font-display); font-weight: 800; font-size: 52px;
  letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1;
}
.gauge-big.over { color: var(--danger); }
.gauge-small { color: var(--muted); font-size: 14px; margin-left: 8px; }
.gauge-right { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; }

.gauge {
  position: relative; height: 26px; border-radius: 13px;
  background: var(--surface); border: 1px solid var(--line);
  display: flex; overflow: visible;
}
.gauge-seg {
  height: 100%; width: 0; transition: width .5s cubic-bezier(.22,1,.36,1);
}
.gauge-seg[data-meal="breakfast"] { background: var(--meal-breakfast); border-radius: 13px 0 0 13px; }
.gauge-seg[data-meal="lunch"]     { background: var(--meal-lunch); }
.gauge-seg[data-meal="dinner"]    { background: var(--meal-dinner); }
.gauge-seg[data-meal="snack"]     { background: var(--meal-snack); }
.gauge-notch {
  position: absolute; top: -5px; bottom: -5px; left: 100%; width: 3px;
  background: var(--ink); border-radius: 2px; opacity: .9;
}
.gauge.is-over { border-color: var(--danger); }

.macro-row { display: flex; gap: 10px; margin-top: 14px; }
.macro {
  flex: 1; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px;
}
.macro b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.macro span { font-size: 12px; color: var(--muted); }
.macro[data-m="protein"] b { color: var(--protein); }
.macro[data-m="carbs"]   b { color: var(--carbs); }
.macro[data-m="fat"]     b { color: var(--fat); }

/* ---------------- meals ---------------- */
.meals { padding: 0 16px 120px; }
.meal-section { margin-bottom: 18px; }
.meal-head {
  display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px;
}
.meal-head h2 { font-size: 17px; font-weight: 700; }
.meal-head .meal-dot { width: 10px; height: 10px; border-radius: 5px; }
.meal-head .meal-kcal { margin-left: auto; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.meal-add { color: var(--muted); font-size: 20px; line-height: 1; padding: 0 6px; }
.meal-add:hover { color: var(--accent); }

.entry {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 6px;
}
.entry-name { flex: 1; min-width: 0; }
.entry-name b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-name span { font-size: 12px; color: var(--muted); }
.entry-kcal { font-variant-numeric: tabular-nums; font-weight: 600; }
.entry-del { color: var(--muted); padding: 4px 6px; font-size: 16px; }
.entry-del:hover { color: var(--danger); }
.meal-empty { color: var(--muted); font-size: 13px; padding: 4px 2px; }

/* ---------------- fab ---------------- */
.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 30px; font-size: 30px; line-height: 1;
  background: var(--accent); color: #221805; font-weight: 700;
  box-shadow: 0 8px 24px rgba(233,161,59,.35); z-index: 6;
}
.fab:active { transform: scale(.94); }

/* ---------------- sheets ---------------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 8;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  background: var(--surface-2); border-radius: 20px 20px 0 0;
  border: 1px solid var(--line); border-bottom: none;
  padding: 8px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 84dvh; overflow-y: auto;
  animation: sheet-in .22s cubic-bezier(.22,1,.36,1);
}
@keyframes sheet-in { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
  .gauge-seg { transition: none; }
}
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 14px; }
.sheet-title { font-size: 20px; margin-bottom: 4px; }
.sheet-sub { color: var(--muted); font-size: 13px; margin: 2px 0 14px; }
.sheet-sub-inline { color: var(--muted); font-size: 13px; font-weight: 400; }

/* add sheet */
.meal-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.meal-tabs button {
  flex: 1; padding: 8px 4px; border-radius: 10px; font-size: 13px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
}
.meal-tabs button.active { color: #221805; }
.meal-tabs button[data-meal="breakfast"].active { background: var(--meal-breakfast); border-color: transparent; }
.meal-tabs button[data-meal="lunch"].active     { background: var(--meal-lunch); border-color: transparent; }
.meal-tabs button[data-meal="dinner"].active    { background: var(--meal-dinner); border-color: transparent; }
.meal-tabs button[data-meal="snack"].active     { background: var(--meal-snack); border-color: transparent; }

.add-search { display: flex; gap: 8px; margin-bottom: 10px; }
.add-search input {
  flex: 1; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
}
.add-search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.add-results { min-height: 120px; }
.result-group { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin: 12px 0 6px; }
.result {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 6px;
}
.result:hover { border-color: var(--accent); }
.result-name { flex: 1; min-width: 0; }
.result-name b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-name span { font-size: 12px; color: var(--muted); }
.result-kcal { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.result .fav { color: var(--accent); }

.add-footer { display: flex; gap: 8px; margin-top: 14px; }
.add-footer .btn { flex: 1; font-size: 14px; }

/* portion sheet */
.portion-grid { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.chip {
  padding: 10px 16px; border-radius: 20px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--line);
}
.chip:hover, .chip.active { border-color: var(--accent); color: var(--accent); }
.portion-input {
  display: flex; align-items: center; gap: 10px; margin-bottom: 16px;
}
.portion-input input {
  width: 110px; padding: 12px 14px; font-size: 20px; text-align: center;
  border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); color: var(--ink); font-variant-numeric: tabular-nums;
}
.portion-input span { color: var(--muted); }
.portion-input output { margin-left: auto; font-family: var(--font-display); font-weight: 700; font-size: 22px; }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn-primary { flex: 1; }

/* manual + settings */
.manual-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.span2 { grid-column: span 2; }

/* week */
#weekChart { width: 100%; height: auto; margin-top: 8px; }

/* toast + offline */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + env(safe-area-inset-bottom));
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 18px; font-size: 14px; z-index: 20;
}
.offline-pill {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: calc(60px + env(safe-area-inset-top));
  background: var(--danger); color: #fff; font-size: 12px; font-weight: 600;
  padding: 6px 14px; border-radius: 14px; z-index: 20;
}

/* scanner */
#scanBox { margin-bottom: 10px; }
#scanVideo { border-radius: var(--radius); overflow: hidden; margin-bottom: 8px; }

@media (min-width: 640px) {
  .meals, .gauge-wrap { max-width: 560px; margin-left: auto; margin-right: auto; }
  .sheet { max-width: 560px; left: 50%; transform: translateX(-50%); border-radius: 20px; bottom: 20px; border-bottom: 1px solid var(--line); }
}


/* ---------------- recipes (RecipeGuide integration) ---------------- */
.sheet-tall { min-height: 70dvh; }
.btn-back { padding: 6px 12px; font-size: 13px; margin-bottom: 8px; }

.recipe-search {
  width: 100%; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  margin-bottom: 10px;
}
.recipe-search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.recipe-cats { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 6px; }
.recipe-cats .chip { flex: 0 0 auto; padding: 7px 14px; font-size: 13px; }
.recipe-cats .chip.active { background: var(--accent); color: #221805; border-color: transparent; }

.recipe-card {
  display: flex; gap: 12px; width: 100%; text-align: left; align-items: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px; margin-bottom: 8px;
}
.recipe-card:hover { border-color: var(--accent); }
.recipe-cover {
  width: 64px; height: 64px; border-radius: 10px; overflow: hidden; flex: 0 0 auto;
  background: var(--surface-2); display: grid; place-items: center;
}
.recipe-cover img { width: 100%; height: 100%; object-fit: cover; }
.recipe-cover-ph { font-size: 26px; }
.recipe-meta { min-width: 0; }
.recipe-meta b { display: block; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recipe-sub { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 2px 0 6px; }
.recipe-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  font-style: normal; font-size: 11px; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 2px 8px;
}
.badge-plus { color: #221805; background: var(--accent); border-color: transparent; font-weight: 700; }

.rd-summary { color: var(--ink); font-size: 14px; line-height: 1.5; margin: 6px 0 14px; }
.rd-h3 { font-family: var(--font-display); font-size: 15px; margin: 0 0 8px; }
.rd-ingredients { margin: 0 0 14px; padding-left: 20px; color: var(--ink); }
.rd-ingredients li { margin-bottom: 5px; font-size: 14px; }

.cook-track { height: 6px; border-radius: 3px; background: var(--surface); margin: 8px 0 14px; overflow: hidden; }
.cook-bar { height: 100%; background: var(--accent); border-radius: 3px; width: 0; transition: width .3s ease; }
.cook-title { font-size: 26px; margin: 4px 0 12px; }
.cook-text { font-size: 18px; line-height: 1.6; color: var(--ink); min-height: 120px; }
.cook-actions .btn { padding: 16px 18px; font-size: 16px; }
.cook-actions .btn-ghost { flex: 0 0 auto; }
