:root {
  --brand: #0e7490;
  --brand-dark: #155e75;
  --bg: #f5f7f8;
  --card: #ffffff;
  --text: #17252b;
  --muted: #5b6b73;
  --line: #e2e8ec;
  --danger: #b91c1c;
  --radius: 14px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

.topbar {
  background: var(--brand); color: #fff;
  padding: 10px 16px calc(10px);
  display: flex; align-items: baseline; gap: 10px;
  position: sticky; top: 0; z-index: 10;
}
.logo { font-size: 1.3rem; font-weight: 300; letter-spacing: .5px; }
.logo b { font-weight: 800; }
.tagline { font-size: .75rem; opacity: .85; flex: 1; }
.langsw { font-size: .75rem; }
.langsw a { color: #fff; opacity: .7; text-decoration: none; }
.langsw b { font-weight: 800; }

.pane { padding: 14px 14px 24px; max-width: 640px; margin: 0 auto; }
h2 { font-size: 1.1rem; margin: 4px 0 12px; }
h3 { font-size: .95rem; margin: 20px 0 8px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .8rem; }

/* inputs */
input, select {
  width: 100%; padding: 12px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--brand); border-color: transparent; }
label { display: block; margin: 12px 0 4px; font-size: .85rem; color: var(--muted); }
label input, label select { margin-top: 4px; }

/* buttons */
button { font-size: 1rem; border: none; border-radius: var(--radius); cursor: pointer; }
.primary {
  background: var(--brand); color: #fff; padding: 12px 18px; width: 100%;
  margin-top: 14px; font-weight: 600;
}
.primary:active { background: var(--brand-dark); }
.primary.big { padding: 15px; font-size: 1.1rem; }
.secondary { background: #e5eef1; color: var(--brand-dark); padding: 12px 18px; width: 100%; margin-top: 10px; }
.danger-outline { background: none; border: 1px solid var(--line); color: var(--danger); padding: 12px 18px; width: 100%; margin-top: 10px; }
.linkbtn { background: none; color: var(--brand); padding: 12px 0; width: 100%; text-align: center; font-size: .9rem; }
.iconbtn { background: #e5eef1; color: var(--brand-dark); min-width: 44px; height: 44px; font-size: 1.1rem; flex: none; }
.btnrow { margin-top: 6px; }

/* search */
.searchrow { display: flex; gap: 8px; }
.searchrow input { flex: 1; }
#search-status { margin: 8px 2px; min-height: 1em; }

/* category directory */
.catgrid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin-top: 4px;
}
.catbtn {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 6px;
  font-size: .74rem; color: var(--text); line-height: 1.25;
}
.catbtn span { display: block; font-size: 1.7rem; margin-bottom: 4px; }
.catbtn:active { background: #e5eef1; }

/* food list */
.foodlist { list-style: none; }
.foodlist li {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px; margin-bottom: 8px;
  cursor: pointer;
}
.foodlist img, .foodlist .noimg {
  width: 52px; height: 52px; border-radius: 10px; object-fit: cover;
  background: #eef2f4; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 1.4rem;
}
.foodlist .fi-main { flex: 1; min-width: 0; }
.foodlist .fi-name { font-weight: 600; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foodlist .fi-sub { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foodlist .fi-carbs { text-align: right; flex: none; }
.foodlist .fi-carbs b { font-size: 1.05rem; color: var(--brand-dark); }
.foodlist .fi-carbs span { display: block; font-size: .68rem; color: var(--muted); }
.fi-del { background: none; color: var(--danger); font-size: 1.2rem; padding: 8px; flex: none; }

/* generic (average-values) foods stand out from branded products */
.foodlist li.generic {
  background: #eef7f6;
  border-color: #a7d6d1;
  border-left: 4px solid var(--brand);
}
.foodlist li.generic .noimg { background: #d9edea; }
.avg-tag { color: var(--brand-dark); font-weight: 600; }
.pack-tag {
  background: #eef2f4; border-radius: 6px; padding: 1px 5px;
  color: var(--muted); white-space: nowrap;
}

/* totals */
.totalbar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-top: 12px;
}
.totalbar strong { font-size: 1.3rem; color: var(--brand-dark); }

/* saved meals */
.savedlist { list-style: none; }
.savedlist li {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; margin-bottom: 8px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.savedlist .sm-name { font-weight: 600; font-size: .95rem; }
.savedlist .sm-sub { font-size: .78rem; color: var(--muted); }
.savedlist button { flex: none; }
.sm-load { background: #e5eef1; color: var(--brand-dark); padding: 8px 14px; font-size: .85rem; }

/* dose */
.doseresult {
  margin-top: 16px; text-align: center;
  background: var(--card); border: 2px solid var(--brand);
  border-radius: var(--radius); padding: 18px;
}
.dosenum { font-size: 2.6rem; font-weight: 800; color: var(--brand-dark); }
.dosenum small { font-size: 1.1rem; font-weight: 400; color: var(--muted); }
.disclaimer {
  margin-top: 18px; font-size: .78rem; color: #7c2d12;
  background: #fff7ed; border: 1px solid #fed7aa;
  border-radius: var(--radius); padding: 10px 12px; line-height: 1.45;
}
details { margin-top: 8px; }
summary { font-size: .85rem; color: var(--brand); padding: 8px 0; cursor: pointer; }

/* bottom sheet / modal */
.sheet {
  position: fixed; inset: 0; background: rgba(15, 30, 36, .45);
  display: flex; align-items: flex-end; z-index: 50;
}
.sheet[hidden] { display: none; }
.sheet-card {
  background: var(--card); width: 100%; max-width: 640px; margin: 0 auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 85vh; overflow-y: auto;
}
.sheet-card h2 { margin-bottom: 10px; }
.sheet-card p { margin: 8px 0; font-size: .92rem; line-height: 1.5; }
.sheet-head { display: flex; gap: 12px; align-items: flex-start; }
.sheet-head > div { flex: 1; min-width: 0; }
.sheet-head img { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; flex: none; }
.sheet-title { font-weight: 700; font-size: 1.05rem; }
.quickrow { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
#sheet-slider {
  width: 100%; margin: 14px 0 2px; padding: 0; accent-color: var(--brand);
  border: none; background: transparent; height: 24px;
}
.quickrow button {
  background: #e5eef1; color: var(--brand-dark);
  padding: 9px 13px; font-size: .85rem; border-radius: 999px;
}

/* dose log */
.loglist { list-style: none; }
.loglist li {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; margin-bottom: 8px;
}
.lg-main { flex: 1; min-width: 0; }
.lg-when { font-weight: 600; font-size: .9rem; }
.lg-sub { font-size: .78rem; color: var(--muted); }
.lg-dose { font-size: 1.15rem; font-weight: 800; color: var(--brand-dark); flex: none; }

/* barcode scanner */
.scanner-card { text-align: center; }
#scanner-video {
  width: 100%; max-height: 55vh; border-radius: var(--radius);
  background: #000; object-fit: cover;
}
.center { text-align: center; margin: 10px 0; }

/* tab bar */
.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; background: none; padding: 8px 0 9px;
  font-size: .72rem; color: var(--muted); position: relative;
}
.tab span { display: block; font-size: 1.25rem; margin-bottom: 1px; }
.tab.active { color: var(--brand); font-weight: 700; }
.tab b {
  position: absolute; top: 3px; right: calc(50% - 22px);
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: .65rem; min-width: 17px; height: 17px; line-height: 17px;
}

@media (min-width: 640px) {
  .sheet { align-items: center; }
  .sheet-card { border-radius: 20px; }
}
