/* ============================================================
   RAK Fuel — app styles. Mobile-first, app-like, RAK-branded.
   Reuses the site palette (navy / Pelorous blue) and Barlow type.
   ============================================================ */

:root {
  --blue:      #298FC2;
  --blue-mid:  #0076A8;
  --blue-dark: #00558C;
  --blue-pale: #e4eef4;
  --navy:      #041E42;
  --navy-mid:  #0a2d5e;
  --white:     #ffffff;
  --cream:     #f8f9fb;
  --stone:     #f2f4f7;
  --border:    #dde2ea;
  --muted:     #5a6473;
  --good:      #1faa6c;
  --warn:      #e0922f;
  --bad:       #d2544b;
  --gold:      #f2b441;
  --font-display: 'Barlow Condensed', sans-serif;
  --font-body:    'Barlow', sans-serif;
  --shadow:    0 10px 30px rgba(4,30,66,0.08);
  --shadow-lg: 0 20px 50px rgba(4,30,66,0.18);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  color: var(--navy);
  background: var(--cream);
  min-height: 100dvh;
  overflow-x: hidden;
}
button { font-family: inherit; cursor: pointer; }
a { color: var(--blue-mid); }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.boot { text-align: center; padding: 30vh 1rem; color: var(--muted); font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------------- App frame ---------------- */
#app { max-width: 540px; margin: 0 auto; min-height: 100dvh; position: relative; padding-bottom: calc(86px + var(--safe-bottom)); }

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; padding: .9rem 1.1rem;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 100%);
  color: #fff;
}
.topbar .brand { display: flex; align-items: center; gap: .55rem; font-family: var(--font-display); font-weight: 900; letter-spacing: 1.5px; text-transform: uppercase; font-size: 19px; }
.topbar .brand .spark { font-size: 20px; }
.topbar .brand small { font-weight: 700; letter-spacing: 2px; font-size: 10px; color: var(--blue); display: block; margin-top: -3px; }
.streak {
  display: inline-flex; align-items: center; gap: .3rem;
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.18);
  padding: .35rem .6rem; border-radius: 999px; font-weight: 700; font-size: 13px;
}
.streak.cold { opacity: .65; }

.datebar { display: flex; align-items: center; justify-content: center; gap: 1rem; padding: .55rem; background: var(--white); border-bottom: 1px solid var(--border); }
.datebar button { background: none; border: 0; font-size: 20px; color: var(--blue-mid); min-width: 44px; min-height: 44px; border-radius: 10px; }
.datebar button:hover { background: var(--stone); }
.datebar .dlabel { font-family: var(--font-display); font-weight: 800; text-transform: uppercase; letter-spacing: 1px; font-size: 16px; min-width: 150px; text-align: center; }
.datebar .today-pill { font-size: 11px; color: var(--blue-mid); font-weight: 700; }

main { padding: 1rem 1rem 2rem; }
.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .view, .sheet, .toast { animation: none !important; } }

/* ---------------- Cards ---------------- */
.card { background: var(--white); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: 1.1rem; margin-bottom: 1rem; }
.card h2, .section-title { font-family: var(--font-display); font-weight: 800; text-transform: uppercase; letter-spacing: 1px; font-size: 15px; color: var(--navy); }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 1.2rem .2rem .6rem; }
.section-title .meal-kcal { color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: .5px; }
.section-title .meal-kcal.low-pro { color: var(--warn); }
.day-target-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: .3rem; }
.day-target { display: flex; flex-direction: column; align-items: center; gap: .2rem; margin: 0; }
.day-target-lbl { font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.day-target input { padding: .4rem .15rem; text-align: center; font-size: 13px; width: 100%; }
.day-carb { width: 100%; padding: .3rem .1rem; text-align: center; font-size: 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--white); color: var(--navy); }
.muted { color: var(--muted); }

/* ---------------- Dashboard hero ---------------- */
.hero { display: grid; grid-template-columns: auto 1fr; gap: 1.1rem; align-items: center; }
.hero .rings { position: relative; width: 132px; height: 132px; }
.hero .rings svg { transform: rotate(-90deg); display: block; }
.hero .ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.hero .ring-center .big { font-family: var(--font-display); font-weight: 900; font-size: 30px; line-height: .95; }
.hero .ring-center .lbl { font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.hero .ring-center .remain { font-size: 11px; color: var(--blue-mid); font-weight: 700; margin-top: 2px; }

.score-chip { display: inline-flex; align-items: center; gap: .4rem; background: var(--navy); color: #fff; padding: .3rem .7rem; border-radius: 999px; font-family: var(--font-display); font-weight: 800; letter-spacing: .5px; font-size: 14px; }
.score-chip .num { color: var(--gold); }
.verdict { margin-top: .55rem; font-family: var(--font-display); font-weight: 800; text-transform: uppercase; letter-spacing: .5px; font-size: 20px; }
.verdict .emoji { font-size: 22px; }
.coach-line { margin-top: .35rem; font-size: 13.5px; color: var(--muted); line-height: 1.4; }

/* macro bars */
.macros { margin-top: 1rem; display: grid; gap: .7rem; }
.macro { }
.macro .row { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 700; margin-bottom: 3px; }
.macro .row .name { text-transform: uppercase; letter-spacing: .5px; }
.macro .row .val { color: var(--muted); font-weight: 600; }
.bar { height: 9px; background: var(--stone); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; transition: width .5s cubic-bezier(.2,.7,.2,1); }
.bar.protein > i { background: linear-gradient(90deg,#2f8fd0,#1f6fb0); }
.bar.carb > i { background: linear-gradient(90deg,#46b07a,#1faa6c); }
.bar.fat > i { background: linear-gradient(90deg,#f2b441,#e0922f); }
.bar.fiber > i { background: linear-gradient(90deg,#8a6cd6,#6a4cc0); }
.bar.over > i { background: repeating-linear-gradient(45deg,#d2544b,#d2544b 6px,#b8463e 6px,#b8463e 12px); }

/* ---------------- Entry list ---------------- */
.entry { display: flex; align-items: center; gap: .4rem; padding: .35rem .2rem; border-bottom: 1px solid var(--border); }
.entry:last-child { border-bottom: 0; }
.entry .entry-tap { flex: 1; min-width: 0; display: flex; align-items: center; gap: .8rem; background: none; border: 0; text-align: left; color: inherit; padding: .3rem 0; min-height: 44px; }
.entry .entry-del { flex: none; background: none; border: 0; color: var(--muted); font-size: 17px; min-width: 40px; min-height: 44px; border-radius: 10px; opacity: .55; }
.entry .entry-del:hover, .entry .entry-del:active { opacity: 1; background: #fbe6e4; }
.entry .emoji { font-size: 26px; width: 34px; text-align: center; flex: none; }
.entry .info { flex: 1; min-width: 0; }
.entry .info .nm { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .info .sub { font-size: 12px; color: var(--muted); }
.entry .kcal { font-family: var(--font-display); font-weight: 800; font-size: 17px; }
.entry .kcal small { font-size: 10px; color: var(--muted); display: block; text-align: right; font-family: var(--font-body); font-weight: 600; }
.entry .src { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--blue-pale); color: var(--blue-dark); font-weight: 700; margin-left: 4px; }
.empty-meal { color: var(--muted); font-size: 13px; padding: .5rem .2rem; }
.add-to-meal { background: none; border: 1px dashed var(--border); color: var(--blue-mid); border-radius: 10px; padding: .4rem .7rem; font-weight: 700; font-size: 12px; }

/* ---------------- Micronutrient panel ---------------- */
.micros { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem .9rem; }
@media (min-width: 460px) { .micros { grid-template-columns: 1fr 1fr 1fr; } }
.micro { font-size: 12px; }
.micro .top { display: flex; justify-content: space-between; margin-bottom: 2px; }
.micro .top .mn { font-weight: 600; }
.micro .top .mp { font-weight: 700; }
.micro .mbar { height: 6px; background: var(--stone); border-radius: 999px; overflow: hidden; }
.micro .mbar > i { display: block; height: 100%; border-radius: 999px; }
.micro.low  .mp { color: var(--bad); }
.micro.mid  .mp { color: var(--warn); }
.micro.good .mp { color: var(--good); }
.micro.over .mp { color: var(--bad); }
.group-label { grid-column: 1 / -1; font-family: var(--font-display); font-weight: 800; text-transform: uppercase; letter-spacing: 1px; font-size: 12px; color: var(--blue-mid); margin-top: .4rem; }

/* ---------------- Tab bar ---------------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 540px; z-index: 60;
  display: grid; grid-template-columns: repeat(5,1fr); align-items: end;
  background: var(--white); border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -8px 24px rgba(4,30,66,.06);
}
.tabbar button { background: none; border: 0; padding: .55rem 0 .5rem; min-height: 50px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; }
.tabbar button .ic { font-size: 21px; line-height: 1; }
.tabbar button.active { color: var(--blue-mid); }
.tabbar .fab-wrap { position: relative; }
.tabbar .fab {
  width: 60px; height: 60px; border-radius: 50%; margin-top: -26px;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
  color: #fff; font-size: 30px; line-height: 1; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 24px rgba(41,143,194,.45); border: 3px solid var(--cream);
}
.tabbar .fab:active { transform: scale(.94); }

/* ---------------- Bottom sheet / modal ---------------- */
.scrim { position: fixed; inset: 0; background: rgba(4,30,66,.45); z-index: 80; opacity: 0; transition: opacity .2s; }
.scrim.open { opacity: 1; }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%) translateY(100%);
  width: 100%; max-width: 540px; max-height: 92dvh; overflow-y: auto; z-index: 90;
  background: var(--white); border-radius: 22px 22px 0 0;
  padding: 1rem 1.1rem calc(1.4rem + var(--safe-bottom));
  transition: transform .28s cubic-bezier(.2,.8,.2,1); box-shadow: var(--shadow-lg);
}
.sheet.open { transform: translateX(-50%) translateY(0); }
.sheet .grab { width: 42px; height: 5px; border-radius: 999px; background: var(--border); margin: .2rem auto .9rem; }
.sheet h3 { font-family: var(--font-display); font-weight: 800; text-transform: uppercase; letter-spacing: 1px; font-size: 18px; margin-bottom: .2rem; }
.sheet .sub { color: var(--muted); font-size: 13px; margin-bottom: 1rem; }

/* add-method grid */
.methods { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.method {
  border: 1px solid var(--border); border-radius: 16px; padding: 1.1rem .8rem; text-align: center;
  background: var(--cream); transition: transform .12s, box-shadow .12s, border-color .12s;
}
.method:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--blue); }
.method .ic { font-size: 32px; }
.method .t { font-family: var(--font-display); font-weight: 800; text-transform: uppercase; letter-spacing: .5px; margin-top: .4rem; font-size: 15px; }
.method .d { font-size: 12px; color: var(--muted); margin-top: .15rem; }

/* forms */
label.fld { display: block; margin-bottom: .8rem; }
label.fld .lab { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); display: block; margin-bottom: .3rem; }
input, select, textarea {
  width: 100%; font-family: inherit; font-size: 15px; color: var(--navy);
  border: 1.5px solid var(--border); border-radius: 12px; padding: .7rem .8rem; background: var(--white);
}
textarea { min-height: 72px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { border: 1.5px solid var(--border); border-radius: 999px; padding: .4rem .8rem; background: var(--white); font-weight: 700; font-size: 13px; }
.chip.sel { border-color: var(--blue); background: var(--blue-pale); color: var(--blue-dark); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; width: 100%; border: 0; border-radius: 14px; padding: .9rem 1rem; font-family: var(--font-display); font-weight: 800; text-transform: uppercase; letter-spacing: 1px; font-size: 16px; }
.btn-primary { background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%); color: #fff; box-shadow: 0 8px 20px rgba(41,143,194,.35); }
.btn-primary:active { transform: scale(.98); }
.btn-ghost { background: var(--stone); color: var(--navy); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-top: .8rem; }
.btn[disabled] { opacity: .55; pointer-events: none; }

/* search results / review items */
.result { display: flex; align-items: center; gap: .7rem; padding: .65rem .3rem; border-bottom: 1px solid var(--border); }
.result .emoji { font-size: 24px; width: 30px; text-align: center; }
.result .info { flex: 1; min-width: 0; }
.result .info .nm { font-weight: 700; font-size: 14px; }
.result .info .sub { font-size: 11.5px; color: var(--muted); }
.result .src-tag { font-size: 10px; font-weight: 700; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 1px 5px; }
.result button.pick { background: var(--blue-pale); color: var(--blue-dark); border: 0; border-radius: 10px; min-width: 44px; min-height: 44px; font-size: 20px; font-weight: 800; flex: none; }
/* Quick-add row: the food area is a button (adjust portion), ⚡ logs instantly. */
.result .qadd-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: .7rem; background: none; border: 0; text-align: left; padding: 0; min-height: 44px; color: inherit; }
.result .fav { background: none; border: 0; color: var(--gold); font-size: 20px; min-width: 40px; min-height: 44px; flex: none; opacity: .85; }
.result .fav.on { color: var(--gold); }
.result .fav:not(.on) { color: var(--border); }
.review-item.low-conf { border-left: 3px solid var(--warn); padding-left: .5rem; }
details.add-item { margin-top: .7rem; }
details.add-item > summary { cursor: pointer; font-weight: 700; font-size: 13px; color: var(--blue-mid); list-style: none; padding: .5rem 0; min-height: 44px; display: flex; align-items: center; }
details.add-item > summary::-webkit-details-marker { display: none; }

.review-item { display: grid; grid-template-columns: auto 1fr auto; gap: .6rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.review-item .emoji { font-size: 26px; }
.review-item .nm { font-weight: 700; }
.review-item .sub { font-size: 12px; color: var(--muted); }
.review-item input.g { width: 74px; text-align: right; padding: .4rem .5rem; }
.review-item .rm { background: none; border: 0; color: var(--bad); font-size: 20px; min-width: 44px; min-height: 44px; }
.conf { font-size: 10px; font-weight: 700; border-radius: 6px; padding: 1px 5px; }
.conf.hi { background: #e2f5ec; color: var(--good); } .conf.mid { background: #fbf0dd; color: var(--warn); } .conf.lo { background: #fbe6e4; color: var(--bad); }

.photo-preview { width: 100%; border-radius: 14px; max-height: 320px; object-fit: cover; margin-bottom: .8rem; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.dark { border-color: var(--border); border-top-color: var(--blue); }
@keyframes spin { to { transform: rotate(360deg); } }
.listening { display: flex; align-items: center; gap: .6rem; color: var(--blue-dark); font-weight: 700; }
.pulse { width: 14px; height: 14px; border-radius: 50%; background: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.5); opacity: .5; } }

/* trends */
.chart { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: .5rem; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 3px; height: 100%; }
.chart .col .stack { width: 70%; background: var(--blue-pale); border-radius: 5px 5px 0 0; position: relative; min-height: 2px; }
.chart .col .stack > i { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(180deg,var(--blue),var(--blue-dark)); border-radius: 5px 5px 0 0; }
.chart .col.over .stack > i { background: linear-gradient(180deg,#e0705f,var(--bad)); }
.chart .col .d { font-size: 9px; color: var(--muted); font-weight: 700; }
.tgt-line { position: relative; height: 0; border-top: 2px dashed var(--blue); margin-top: -2px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin-top: .4rem; }
.stat { background: var(--cream); border: 1px solid var(--border); border-radius: 14px; padding: .8rem; text-align: center; }
.stat .v { font-family: var(--font-display); font-weight: 900; font-size: 26px; }
.stat .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 700; }

/* toast + confetti */
.toast { position: fixed; left: 50%; bottom: calc(100px + var(--safe-bottom)); transform: translateX(-50%); display: flex; align-items: center; gap: .8rem; background: var(--navy); color: #fff; padding: .7rem 1.1rem; border-radius: 999px; font-weight: 700; font-size: 14px; z-index: 120; box-shadow: var(--shadow-lg); animation: pop .3s; max-width: 92vw; }
.toast-undo { background: none; border: 0; color: var(--gold); font-weight: 800; font-size: 14px; text-transform: uppercase; letter-spacing: .5px; padding: .2rem .3rem; flex: none; }
@keyframes pop { from { transform: translateX(-50%) translateY(10px); opacity: 0; } }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 110; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 9px; height: 14px; opacity: .9; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); opacity: 0; } }

.disclaimer { font-size: 11.5px; color: var(--muted); line-height: 1.5; margin-top: 1rem; }
.linkrow { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .6rem; }
.linkrow a { font-size: 12px; font-weight: 700; }
.banner { background: var(--blue-pale); border: 1px solid #cfe0ea; color: var(--blue-dark); border-radius: 12px; padding: .6rem .8rem; font-size: 12.5px; font-weight: 600; margin-bottom: .8rem; }

/* Proactive "your usual?" suggestion */
.suggest { display: flex; align-items: center; justify-content: space-between; gap: .8rem; background: linear-gradient(135deg, #eaf4fb 0%, #f4f9fd 100%); border: 1px solid #cfe0ea; border-radius: 16px; padding: .8rem 1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }

/* Personalised quick-log tile grid */
.qgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
@media (min-width: 460px) { .qgrid { grid-template-columns: repeat(4, 1fr); } }
.qtile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .25rem; padding: .7rem .3rem; background: var(--cream); border: 1px solid var(--border); border-radius: 14px; min-height: 76px; color: inherit; }
.qtile:active { transform: scale(.95); }
.qtile:hover { border-color: var(--blue); }
.qtile-emoji { font-size: 26px; line-height: 1; }
.qtile-name { font-size: 11px; font-weight: 700; text-align: center; line-height: 1.1; max-height: 2.3em; overflow: hidden; }

/* Fasting metabolic-stage timeline */
.fast-stage { display: flex; gap: .7rem; align-items: flex-start; padding: .5rem 0; border-bottom: 1px solid var(--border); opacity: .5; }
.fast-stage:last-child { border-bottom: 0; }
.fast-stage.reached { opacity: 1; }
.fast-stage.current { opacity: 1; background: var(--blue-pale); border-radius: 10px; padding: .5rem; margin: 0 -.3rem; }
.fast-stage-h { flex: none; width: 34px; font-family: var(--font-display); font-weight: 800; font-size: 14px; color: var(--blue-mid); padding-top: 1px; }
