/* ---- shared components ---- */

/* Top app bar */
.appbar {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 14px;
  background: var(--surface);
  position: sticky; top: 0; z-index: 5;
  min-height: 56px;
}
.appbar .title { flex: 1; text-align: center; font-weight: 700; font-size: 17px; color: var(--text); }
.appbar .iconbtn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; background: transparent;
  font-size: 18px; color: var(--text);
}
.appbar .iconbtn:hover { background: var(--surface-2); }
.appbar .iconbtn.solid { background: var(--surface-2); }

/* Hero appbar with green background (home) */
.appbar.hero {
  background: linear-gradient(180deg, var(--brand-bg) 0%, var(--brand) 100%);
  color: #2c3a10;
  border-bottom-left-radius: 30px;
  border-bottom-right-radius: 30px;
  padding-bottom: 14px;
}
html[data-theme="dark"] .appbar.hero { color: #f3f6f3; background: linear-gradient(180deg, #5d8b1f 0%, #4a6b18 100%); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 16px 22px; border-radius: var(--radius-pill);
  background: var(--brand); color: var(--brand-ink);
  font-weight: 700; font-size: 15px;
  min-height: 54px; transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.block { display: flex; width: 100%; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.outline { background: var(--surface); border: 1.5px solid var(--border); color: var(--text); }
.btn.danger { background: #fff0f0; color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; }
.btn.weight { background: var(--weight); color: #fff; }
.btn.water { background: var(--water); color: #fff; }
.btn:disabled { opacity: .45; pointer-events: none; }

/* Inputs */
.input { width: 100%; padding: 14px 16px; background: var(--surface-2); border: 1.5px solid transparent; border-radius: 14px; outline: none; }
.input:focus { border-color: var(--brand); background: var(--surface); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--text-2); }
.input.with-icon { padding-right: 44px; }
.input-wrap { position: relative; }
.input-wrap .eye { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); padding: 6px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

/* Cards */
.card { background: var(--surface); border-radius: var(--radius-lg); padding: 16px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; border: 1px solid var(--border); }
.card.tight { padding: 12px; }

/* List item — standalone (each row is its own card with shadow) */
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border-radius: 16px; margin-bottom: 8px; box-shadow: var(--shadow); }
.list-item .leading { width: 42px; height: 42px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; font-size: 22px; flex-shrink: 0; }
.list-item .body { flex: 1; min-width: 0; }
.list-item .body .title { font-weight: 600; font-size: 15px; }
.list-item .body .sub { color: var(--text-2); font-size: 12.5px; margin-top: 1px; }
.list-item .trailing { color: var(--text-2); font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 8px; }

/* Grouped list — settings-style: single white card with rows separated by hairlines */
.grouped {
  background: var(--surface);
  border-radius: 18px;
  margin: 0 0 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.grouped .row {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px;
  border-top: 1px solid var(--border);
}
.grouped .row:first-child { border-top: 0; }
.grouped .row .nm { flex: 1; font-weight: 500; }
.grouped .row .sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.grouped .row .val { color: var(--text-2); font-size: 14px; }
.grouped .row .chev { color: var(--text-3); }
.grouped .row .lead { width: 26px; display: grid; place-items: center; flex-shrink: 0; }
.grouped .row.danger .nm { color: var(--danger); }

/* Bottom nav */
.bottomnav {
  position: sticky; bottom: 0; left: 0; right: 0;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  padding: 10px 8px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  z-index: 4;
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 4px 0;
  color: var(--text-3); font-size: 11px; font-weight: 500;
}
.bottomnav a .ico { font-size: 22px; line-height: 1; }
.bottomnav a.active { color: var(--brand-2); font-weight: 700; }
html[data-theme="dark"] .bottomnav a.active { color: var(--brand); }

/* Tabs — pill-style segmented control as in m8/m12/m33 */
.tabs { display: flex; gap: 0; padding: 5px; background: var(--surface-2); border-radius: var(--radius-pill); margin-bottom: 14px; }
.tabs button { flex: 1; padding: 10px 8px; border-radius: var(--radius-pill); font-weight: 600; font-size: 14px; color: var(--text-2); transition: color .12s, background .12s; }
.tabs button.active { background: var(--brand); color: var(--brand-ink); }

/* Toast */
#toast { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 99; pointer-events: none; max-width: 90vw; }
.toast {
  background: var(--surface); color: var(--text);
  padding: 10px 16px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .2s ease, toastOut .25s ease 2s forwards;
  font-size: 14px; font-weight: 500;
}
.toast .ok { color: var(--brand-2); }
@keyframes toastIn { from { transform: translateY(-10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes toastOut { to { transform: translateY(-10px); opacity: 0; } }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50;
  display: grid; place-items: center;
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--surface); border-radius: 22px; padding: 22px; width: min(92vw, 380px);
  box-shadow: var(--shadow-lg); text-align: center;
}
.modal .title { font-weight: 600; font-size: 18px; margin-bottom: 6px; color: var(--danger); }
.modal .msg { color: var(--text-2); margin-bottom: 18px; }
.modal .actions { display: flex; gap: 10px; }
.modal .actions .btn { flex: 1; }

/* Bottom sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50;
  display: flex; align-items: flex-end;
  animation: fadeIn .15s ease;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 480px; margin: 0 auto;
  border-top-left-radius: 24px; border-top-right-radius: 24px;
  padding: 18px 18px calc(18px + var(--safe-bottom));
  animation: sheetUp .2s ease;
}
.sheet .handle { width: 38px; height: 4px; background: var(--surface-3); border-radius: 4px; margin: 0 auto 14px; }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Macro pills */
.macro { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.macro .dot { width: 8px; height: 8px; border-radius: 50%; }
.macro.carb .dot { background: var(--carb); }
.macro.protein .dot { background: var(--protein); }
.macro.fat .dot { background: var(--fat); }

/* Ring progress (uses CSS conic-gradient) */
.ring {
  --val: 0;
  --color: var(--brand);
  --size: 96px;
  width: var(--size); height: var(--size);
  border-radius: 50%;
  background: conic-gradient(var(--color) calc(var(--val) * 1%), var(--surface-2) 0);
  display: grid; place-items: center;
  position: relative;
}
.ring::before {
  content: '';
  position: absolute; inset: 8px;
  border-radius: 50%;
  background: var(--surface);
}
.ring .val { position: relative; text-align: center; }
.ring .val .num { font-weight: 700; font-size: 18px; }
.ring .val .lbl { font-size: 11px; color: var(--text-2); }

/* Multi-ring (carbs/protein/fat) */
.tri-ring { position: relative; width: 110px; height: 110px; }
.tri-ring svg { transform: rotate(-90deg); }
.tri-ring .center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.tri-ring .center .num { font-size: 22px; font-weight: 700; }
.tri-ring .center .lbl { font-size: 11px; color: var(--text-2); }

/* Progress bar */
.bar { background: var(--surface-2); height: 8px; border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .35s ease; }

/* Steppers */
.stepper { display: inline-flex; align-items: center; gap: 12px; }
.stepper button { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); font-size: 18px; }
.stepper .v { min-width: 26px; text-align: center; }

/* Misc */
.muted { color: var(--text-2); }
.center { text-align: center; }
.spacer { flex: 1; }
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.section-title { font-weight: 700; font-size: 16px; margin: 18px 0 12px; padding: 0 4px; color: var(--text); display: flex; align-items: center; justify-content: space-between; }
.section-title .link { color: var(--brand-2); font-size: 13px; font-weight: 600; }
.padded { padding: 16px; }
.padded-x { padding: 0 16px; }
.bd-action {
  position: fixed; bottom: calc(20px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  width: calc(100% - 32px); max-width: 448px; z-index: 4;
}
/* Fixed bottom CTA bar — white footer with a single primary action (m11, m13, m16, m18, m20) */
.bottom-bar {
  position: sticky; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  padding: 12px 16px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  z-index: 4;
}
.bottom-bar .btn { flex: 1; }
.bottom-bar .secondary { color: var(--text-2); font-size: 13px; }

/* Selectable rows (radio / check list) */
.opt-row { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: var(--surface); border: 1.5px solid var(--border); border-radius: 14px; margin-bottom: 10px; cursor: pointer; }
.opt-row.selected { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, var(--surface)); }
.opt-row .ic { font-size: 22px; }
.opt-row .nm { flex: 1; }
.opt-row .check { color: var(--brand-2); }

/* Switch */
.switch { width: 46px; height: 28px; background: var(--surface-3); border-radius: 99px; position: relative; transition: background .15s; cursor: pointer; flex-shrink: 0; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.switch.on { background: var(--brand); }
.switch.on::after { left: 21px; }

/* Avatar */
.avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 22px; overflow: hidden; }
.avatar.lg { width: 96px; height: 96px; font-size: 40px; }

/* Pager dots */
.pager { display: flex; gap: 6px; justify-content: center; padding: 12px 0; }
.pager span { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-3); }
.pager span.active { width: 20px; background: var(--brand); border-radius: 99px; }

/* Wheel picker (date / time) */
.wheel { display: flex; gap: 10px; justify-content: center; padding: 14px 0; }
.wheel .col { flex: 1; max-width: 100px; height: 220px; overflow-y: scroll; scroll-snap-type: y mandatory; scrollbar-width: none; mask-image: linear-gradient(180deg, transparent 0%, #000 30%, #000 70%, transparent 100%); }
.wheel .col::-webkit-scrollbar { display: none; }
.wheel .col > div { scroll-snap-align: center; padding: 14px 0; text-align: center; color: var(--text-3); }
.wheel .col > div.active { color: var(--brand-2); font-weight: 700; font-size: 18px; }

/* Search input */
.search-row { display: flex; align-items: center; gap: 8px; background: var(--surface-2); padding: 0 12px; border-radius: 14px; margin: 0 0 12px; }
.search-row input { background: transparent; border: 0; padding: 14px 6px; flex: 1; outline: none; min-width: 0; }
.search-row .ic { color: var(--text-3); }

/* Top chips row (Quick Log / Create Food etc) */
.chip-row { display: flex; gap: 10px; margin-bottom: 12px; }
.chip {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px; background: var(--surface);
  border: 1.5px solid var(--border); border-radius: 14px;
  font-weight: 600; font-size: 14px; color: var(--text);
}
.chip .ic { color: var(--brand-2); font-size: 16px; }
.chip:active { background: var(--surface-2); }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 0 8px; }
.cal .h { text-align: center; color: var(--text-3); padding: 8px 0; font-size: 12px; }
.cal .d { aspect-ratio: 1; display: grid; place-items: center; border-radius: 50%; font-size: 14px; }
.cal .d.muted { color: var(--text-3); }
.cal .d.today { color: var(--brand-2); font-weight: 700; }
.cal .d.sel { background: var(--brand); color: #1a2a05; font-weight: 700; }
.cal .d.dot { position: relative; }
.cal .d.dot::after { content: ''; position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%); width: 4px; height: 4px; background: var(--brand-2); border-radius: 50%; }

/* Mini week strip — m20-style: day label above a circled number */
.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 4px 0 14px; }
.week-strip .d { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px 0; font-size: 12px; cursor: pointer; }
.week-strip .d .dy { color: var(--text-2); font-size: 11px; font-weight: 500; }
.week-strip .d .num {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 600;
  border: 1.5px solid transparent;
  color: var(--text);
}
.week-strip .d.active { /* ring around the day */ }
.week-strip .d.active .num { border-color: var(--brand); color: var(--brand-2); }
/* Color variants: water=blue ring, step=orange */
.week-strip.water .d.active .num { border-color: var(--water); color: var(--water); }
.week-strip.step  .d.active .num { border-color: var(--step);  color: var(--step); }

/* Loader spinner */
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--surface-2); border-top-color: var(--brand); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
