/* ===========================================================
   Iron — food tracker PWA
   =========================================================== */
:root {
  color-scheme: light;
  --bg: #f2f3f8;
  --surface: #ffffff;
  --surface-2: #f6f7fb;
  --surface-3: #eceef5;
  --line: rgba(20, 24, 60, 0.08);
  --text: #12142b;
  --text-2: #5a5e78;
  --text-3: #8d91a8;
  --brand: #3446e0;
  --brand-2: #6a3df0;
  --brand-soft: rgba(52, 70, 224, 0.1);
  --hero-a: #2f3fd8;
  --hero-b: #6b3cf0;
  --hero-c: #1e2aa8;
  --carbs: #2a78d6;
  --fat: #eb6834;
  --protein: #1baf7a;
  --water: #1e9bf0;
  --good: #15a35a;
  --warn: #e08a00;
  --bad: #e5484d;
  --shadow: 0 1px 2px rgba(18, 20, 43, 0.04), 0 6px 20px rgba(18, 20, 43, 0.06);
  --shadow-lg: 0 10px 40px rgba(18, 20, 43, 0.18);
  --radius: 20px;
  --radius-sm: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-round: ui-rounded, -apple-system, "SF Pro Rounded", BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --cat-fruit: #e5484d;  --cat-fruit-bg: rgba(229, 72, 77, 0.12);
  --cat-veg: #15a35a;    --cat-veg-bg: rgba(21, 163, 90, 0.12);
  --cat-grain: #c98500;  --cat-grain-bg: rgba(237, 161, 0, 0.15);
  --cat-protein: #d4572a;--cat-protein-bg: rgba(235, 104, 52, 0.13);
  --cat-dairy: #2a78d6;  --cat-dairy-bg: rgba(42, 120, 214, 0.12);
  --cat-snack: #8a5a2b;  --cat-snack-bg: rgba(138, 90, 43, 0.13);
  --cat-drink: #6250d6;  --cat-drink-bg: rgba(98, 80, 214, 0.12);
  --cat-meal: #d55181;   --cat-meal-bg: rgba(213, 81, 129, 0.12);
  --cat-quick: #3446e0;  --cat-quick-bg: rgba(52, 70, 224, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0c16;
    --surface: #161828;
    --surface-2: #1d2033;
    --surface-3: #262a40;
    --line: rgba(255, 255, 255, 0.07);
    --text: #f1f2f8;
    --text-2: #a8acc6;
    --text-3: #727693;
    --brand: #6f7dff;
    --brand-2: #9a7bff;
    --brand-soft: rgba(111, 125, 255, 0.16);
    --hero-a: #2532b8;
    --hero-b: #5326c9;
    --hero-c: #151b6e;
    --carbs: #3987e5;
    --fat: #d95926;
    --protein: #199e70;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0c16;
  --surface: #161828;
  --surface-2: #1d2033;
  --surface-3: #262a40;
  --line: rgba(255, 255, 255, 0.07);
  --text: #f1f2f8;
  --text-2: #a8acc6;
  --text-3: #727693;
  --brand: #6f7dff;
  --brand-2: #9a7bff;
  --brand-soft: rgba(111, 125, 255, 0.16);
  --hero-a: #2532b8;
  --hero-b: #5326c9;
  --hero-c: #151b6e;
  --carbs: #3987e5;
  --fat: #d95926;
  --protein: #199e70;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { background: var(--bg); }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-user-select: none;
  user-select: none;
}
input, textarea { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.num { font-family: var(--font-round); font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
#view {
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}
.page { animation: pageIn .28s ease both; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.hero {
  position: relative;
  color: #fff;
  padding: calc(var(--safe-top) + 14px) 20px 64px;
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(255,255,255,0.18) 0%, transparent 55%),
    radial-gradient(80% 80% at 0% 100%, rgba(0,0,0,0.18) 0%, transparent 60%),
    linear-gradient(140deg, var(--hero-a) 0%, var(--hero-b) 60%, var(--hero-c) 130%);
  overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; right: -70px; top: -50px; width: 220px; height: 220px;
  border-radius: 50%; border: 28px solid rgba(255,255,255,0.06);
}
.hero.compact { padding-bottom: 20px; }
.hero-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; position: relative; z-index: 1; }
.hero h1 { margin: 0; font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
.hero .sub { margin: 2px 0 0; font-size: 14px; opacity: .82; font-weight: 500; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 16px;
  background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.3);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.chip-glass {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: rgba(255,255,255,0.16); border: 1px solid rgba(255,255,255,0.22);
}
.chip-glass svg { width: 16px; height: 16px; }

.content { padding: 0 16px; margin-top: -44px; position: relative; z-index: 2; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.hero.compact + .content { margin-top: 14px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  border: 1px solid var(--line);
}
.card-tap { transition: transform .15s ease; }
.card-tap:active { transform: scale(0.985); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.card-sub { font-size: 13px; color: var(--text-3); margin: 2px 0 0; }
.link { color: var(--brand); font-weight: 600; font-size: 14px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.muted { color: var(--text-3); }
.small { font-size: 13px; }

/* ---------- Calorie ring card ---------- */
.cal-card { display: grid; grid-template-columns: minmax(110px, 158px) minmax(0, 1fr); align-items: center; gap: 16px; }
.ring-wrap { position: relative; width: 100%; aspect-ratio: 1; }
.ring-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { stroke: var(--surface-3); }
.ring-bar { transition: stroke-dashoffset 1s cubic-bezier(.2,.8,.2,1), stroke .3s; }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-center .big { font-size: clamp(24px, 8vw, 34px); font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.ring-center .lbl { font-size: 12px; color: var(--text-3); font-weight: 600; margin-top: 4px; text-transform: uppercase; letter-spacing: .06em; }
.cal-stats { display: grid; gap: 12px; }
.cal-stat { display: flex; align-items: center; gap: 10px; }
.cal-stat .ico { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; }
.cal-stat .ico svg { width: 18px; height: 18px; }
.cal-stat .k { font-size: 12px; color: var(--text-3); font-weight: 600; }
.cal-stat .v { font-size: 17px; font-weight: 700; }

/* ---------- Macros ---------- */
.macros { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.macro { text-align: center; }
.macro .mring { position: relative; width: 100%; max-width: 82px; aspect-ratio: 1; margin: 0 auto 8px; }
.macro .mring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.macro .mring .mval { position: absolute; inset: 0; display: grid; place-content: center; font-weight: 800; font-size: 18px; }
.macro .mring .mval small { display: block; font-size: 11px; font-weight: 600; color: var(--text-3); margin-top: -2px; }
.macro .name { font-size: 14px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.macro .name i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.macro .left { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.bar { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 99px; transition: width .8s cubic-bezier(.2,.8,.2,1); }

/* ---------- Small stat tiles ---------- */
.tile { display: flex; flex-direction: column; gap: 10px; min-height: 150px; }
.tile-top { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; }
.tile-top .ico { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; }
.tile-top .ico svg { width: 17px; height: 17px; }
.value { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; line-height: 1; }
.value small { font-size: 14px; color: var(--text-3); font-weight: 600; margin-left: 3px; letter-spacing: 0; }
.tile .foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.cups { display: flex; flex-wrap: wrap; gap: 3px; }
.cup { width: 12px; height: 18px; color: var(--water); opacity: .25; transition: opacity .2s, transform .2s; }
.cup.full { opacity: 1; }
.cup svg { width: 12px; height: 18px; fill: currentColor; stroke: none; }
.round-btn {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line); transition: transform .12s;
}
.round-btn:active { transform: scale(.9); }
.round-btn svg { width: 18px; height: 18px; }
.round-btn.primary { background: var(--brand); color: #fff; border: 0; box-shadow: 0 4px 12px rgba(52,70,224,.35); }

/* ---------- Week bars ---------- */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; align-items: end; height: 140px; box-sizing: border-box; position: relative; padding-top: 6px; }
.week .col { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; position: relative; }
.week .colbar { width: 100%; max-width: 26px; border-radius: 4px 4px 0 0; background: var(--brand); min-height: 2px; transition: height .8s cubic-bezier(.2,.8,.2,1); }
.week .colbar.over { background: var(--fat); }
.week .colbar.empty { background: var(--surface-3); }
.week .day { height: 16px; line-height: 16px; font-size: 11px; font-weight: 600; color: var(--text-3); }
.week .day.today { color: var(--brand); }
.week .goal-line { position: absolute; left: 0; right: 0; border-top: 1.5px dashed var(--text-3); opacity: .55; pointer-events: none; }
.week .goal-tag { position: absolute; right: 0; transform: translateY(-120%); font-size: 10px; font-weight: 700; color: var(--text-3); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-top: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend i.dash { height: 0; border-top: 2px dashed var(--text-3); border-radius: 0; width: 14px; }

/* tooltip */
.tip {
  position: absolute; z-index: 5; pointer-events: none;
  background: var(--text); color: var(--surface); padding: 6px 9px; border-radius: 8px;
  font-size: 12px; font-weight: 600; white-space: nowrap; transform: translate(-50%, -100%);
  box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .15s;
}
.tip.show { opacity: 1; }
.tip small { display: block; font-weight: 500; opacity: .7; font-size: 11px; }

/* ---------- Install banner ---------- */
.banner {
  display: flex; gap: 12px; align-items: center; padding: 14px 16px;
  background: linear-gradient(135deg, var(--brand-soft), transparent);
  border: 1px solid var(--line); border-radius: var(--radius); background-color: var(--surface);
}
.banner .ico { width: 40px; height: 40px; border-radius: 12px; background: var(--brand); color: #fff; display: grid; place-items: center; flex: none; }
.banner p { margin: 0; font-size: 13px; color: var(--text-2); line-height: 1.4; }
.banner b { color: var(--text); }
.banner .x { margin-left: auto; color: var(--text-3); }

/* ---------- Diary ---------- */
.datebar { display: flex; align-items: center; justify-content: space-between; gap: 8px; position: relative; z-index: 1; margin-top: 14px; }
.datebar .navbtn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.14); }
.datebar .navbtn:active { background: rgba(255,255,255,.26); }
.datebar .navbtn:disabled { opacity: .35; }
.datebar .datelabel { position: relative; font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; }
.datebar .datelabel svg { width: 16px; height: 16px; }
.datebar input[type=date] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; -webkit-appearance: none; appearance: none; }

.summary {
  display: grid; grid-template-columns: minmax(0,1fr) auto minmax(0,1fr) auto minmax(0,1fr) auto minmax(0,1.2fr); align-items: center; text-align: center;
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.18); border-radius: 16px; padding: 12px 8px; margin-top: 14px; position: relative; z-index: 1;
}
.summary .n { font-size: clamp(14px, 4.4vw, 17px); font-weight: 800; }
.summary .l { font-size: 9.5px; overflow: hidden; text-overflow: ellipsis; opacity: .75; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }
.summary .op { opacity: .7; font-weight: 700; }
.summary .rem .n { font-size: 20px; }

.meal { padding: 0; overflow: hidden; }
.meal-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px 12px; }
.meal-head .mico { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.meal-head .mico svg { width: 20px; height: 20px; }
.meal-head h3 { margin: 0; font-size: 17px; font-weight: 700; }
.meal-head .mm { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.meal-head .kcal { margin-left: auto; font-weight: 800; font-size: 18px; }
.meal-head .kcal small { font-size: 12px; color: var(--text-3); font-weight: 600; margin-left: 2px; }
.items { border-top: 1px solid var(--line); }
.meal-foot { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: space-between; padding: 10px 12px 12px 18px; border-top: 1px solid var(--line); }
.add-link { display: inline-flex; align-items: center; gap: 6px; color: var(--brand); font-weight: 700; font-size: 14px; letter-spacing: .02em; padding: 6px 0; }
.add-link svg { width: 18px; height: 18px; stroke-width: 2.4; }
.ghost-btn { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); padding: 7px 11px; border-radius: 999px; background: var(--surface-2); }
.ghost-btn svg { width: 15px; height: 15px; }

/* Swipeable rows */
.row-wrap { position: relative; overflow: hidden; }
.row-wrap + .row-wrap { border-top: 1px solid var(--line); }
.row-del {
  position: absolute; right: 0; top: 0; bottom: 0; width: 96px; background: var(--bad); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.row-del svg { width: 20px; height: 20px; margin-bottom: 2px; }
.row {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 18px; background: var(--surface);
  transition: transform .25s cubic-bezier(.2,.8,.2,1);
  touch-action: pan-y;
}
.row:active { background: var(--surface-2); }
.row .ftile { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.row .ftile svg { width: 21px; height: 21px; }
.row .meta { min-width: 0; flex: 1; }
.row .nm { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .ds { font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.row .cal { font-weight: 700; font-size: 15px; text-align: right; }
.row .cal small { display: block; font-size: 11px; color: var(--text-3); font-weight: 600; }
.row .addbtn { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; transition: transform .15s, background .2s; }
.row .addbtn svg { width: 18px; height: 18px; stroke-width: 2.5; }
.row .addbtn.done { background: var(--good); color: #fff; transform: scale(1.1); }

/* category tile colors */
.cat-fruit { color: var(--cat-fruit); background: var(--cat-fruit-bg); }
.cat-veg { color: var(--cat-veg); background: var(--cat-veg-bg); }
.cat-grain { color: var(--cat-grain); background: var(--cat-grain-bg); }
.cat-protein { color: var(--cat-protein); background: var(--cat-protein-bg); }
.cat-dairy { color: var(--cat-dairy); background: var(--cat-dairy-bg); }
.cat-snack { color: var(--cat-snack); background: var(--cat-snack-bg); }
.cat-drink { color: var(--cat-drink); background: var(--cat-drink-bg); }
.cat-meal { color: var(--cat-meal); background: var(--cat-meal-bg); }
.cat-quick { color: var(--cat-quick); background: var(--cat-quick-bg); }
.cat-exercise { color: var(--fat); background: rgba(235, 104, 52, .13); }

.empty { padding: 4px 18px 14px; color: var(--text-3); font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 52px; padding: 0 22px; border-radius: 16px; font-weight: 700; font-size: 16px;
  background: var(--brand); color: #fff; width: 100%;
  background-image: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 8px 20px rgba(52, 70, 224, 0.3);
  transition: transform .12s, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; }
.btn svg { width: 20px; height: 20px; }
.btn { white-space: nowrap; }
.btn.secondary { background: var(--surface-2); background-image: none; color: var(--text); box-shadow: none; border: 1px solid var(--line); }
.btn.danger { background: rgba(229, 72, 77, .12); background-image: none; color: var(--bad); box-shadow: none; }
.btn.sm { height: 42px; font-size: 14px; border-radius: 13px; width: auto; padding: 0 16px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; min-width: 0; padding: 0 12px; }
.btn-row .btn.danger[aria-label] { flex: none; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 6px 6px calc(var(--safe-bottom));
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: start;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; padding-top: 4px; color: var(--text-3); font-size: 10.5px; font-weight: 600; transition: color .2s; }
.tab svg { width: 25px; height: 25px; transition: transform .2s; }
.tab.active { color: var(--brand); }
.tab.active svg { transform: translateY(-1px); stroke-width: 2.3; }
.plus-btn {
  width: 54px; height: 54px; border-radius: 18px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 8px 22px rgba(52, 70, 224, .45); margin-top: -18px;
  transition: transform .2s cubic-bezier(.3,1.6,.5,1);
}
.plus-btn svg { width: 28px; height: 28px; stroke-width: 2.6; }
.tab-plus:active .plus-btn { transform: scale(.92) rotate(90deg); }

/* ---------- Sheets ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(8, 10, 30, 0.45); z-index: 100;
  opacity: 0; transition: opacity .3s ease;
}
.sheet-backdrop.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 101;
  max-height: calc(100vh - var(--safe-top) - 20px);
  max-height: calc(100dvh - var(--safe-top) - 20px);
  background: var(--bg); border-radius: 26px 26px 0 0;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  transform: translateY(105%); transition: transform .38s cubic-bezier(.2,.9,.2,1);
  padding-bottom: var(--safe-bottom);
  max-width: 640px; margin: 0 auto;
}
.sheet.full { height: calc(100vh - var(--safe-top) - 12px); height: calc(100dvh - var(--safe-top) - 12px); }
.sheet.show { transform: translateY(0); }
.sheet.dragging { transition: none; }
.sheet-grab { padding: 8px 0 2px; display: grid; place-items: center; flex: none; touch-action: none; }
.sheet-grab span { width: 38px; height: 5px; border-radius: 99px; background: var(--text-3); opacity: .4; }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 6px 16px 12px; flex: none; touch-action: none; }
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.01em; flex: 1; }
.sheet-head .round-btn { width: 34px; height: 34px; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px 20px; flex: 1; overscroll-behavior: contain; }
.sheet-foot { padding: 12px 16px 14px; border-top: 1px solid var(--line); background: var(--bg); flex: none; }

/* action menu */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-bottom: 6px; }
.action {
  display: flex; flex-direction: column; align-items: flex-start; gap: 14px; padding: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; text-align: left;
  transition: transform .12s;
}
.action:active { transform: scale(.97); }
.action .ico { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; }
.action .t { font-weight: 700; font-size: 16px; }
.action .d { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* search */
.search {
  display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 0 12px; height: 48px; margin-bottom: 12px;
}
.search svg { color: var(--text-3); width: 20px; height: 20px; }
.search input { flex: 1; border: 0; outline: 0; background: transparent; font-size: 16px; height: 100%; min-width: 0; }
.search .clear { color: var(--text-3); display: grid; place-items: center; }

.seg { display: flex; background: var(--surface-3); border-radius: 12px; padding: 3px; gap: 2px; margin-bottom: 12px; }
.seg button { flex: 1; padding: 8px 6px; border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--text-2); transition: background .2s, color .2s; white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.1); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; margin-bottom: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 600; background: var(--surface); border: 1px solid var(--line); color: var(--text-2); }
.chip.on { background: var(--text); color: var(--surface); border-color: transparent; }

.list { background: var(--surface); border-radius: var(--radius-sm); border: 1px solid var(--line); overflow: hidden; }
.list + .list, .section-label + .list { margin-top: 0; }
.section-label { font-size: 12px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .07em; margin: 18px 4px 8px; display: flex; align-items: center; justify-content: space-between; }
.section-label:first-child { margin-top: 4px; }

.quick-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 4px; }
.quick-row .action { flex-direction: row; align-items: center; gap: 10px; padding: 12px; }
.quick-row .action .ico { width: 36px; height: 36px; border-radius: 11px; }
.quick-row .action .ico svg { width: 19px; height: 19px; }
.quick-row .action .t { font-size: 14px; }

.online-btn { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; margin-top: 12px; border-radius: 14px; background: var(--surface); border: 1px dashed var(--brand); color: var(--brand); font-weight: 700; font-size: 14px; }
.online-btn svg { width: 20px; height: 20px; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--brand-soft); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* barcode scanner */
.scanner { position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 46vh; border-radius: 20px; overflow: hidden; background: #000; margin-bottom: 12px; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; left: 10%; right: 10%; top: 30%; height: 40%; border-radius: 16px; border: 2px solid rgba(255,255,255,.9); box-shadow: 0 0 0 9999px rgba(0,0,0,.42); overflow: hidden; }
.scan-line { position: absolute; left: 6%; right: 6%; height: 2px; top: 50%; background: #ff5a5f; box-shadow: 0 0 12px 2px rgba(255,90,95,.7); animation: scanline 1.6s ease-in-out infinite alternate; }
@keyframes scanline { from { top: 12%; } to { top: 88%; } }
.scan-msg { position: absolute; left: 0; right: 0; bottom: 12px; text-align: center; color: #fff; font-weight: 600; font-size: 14px; text-shadow: 0 1px 4px rgba(0,0,0,.6); padding: 0 12px; }
.scan-status { display: block; padding: 14px 16px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; line-height: 1.45; color: var(--text-2); }
.scan-status b { color: var(--text); }
.scan-status .spinner { display: inline-block; vertical-align: -5px; margin-right: 10px; }
.scan-status.bad { border-color: rgba(229,72,77,.35); }
.inline-ico { width: 14px; height: 14px; vertical-align: -2px; }
.search .btn.sm { flex: none; }

.photo-btn { margin: 0 0 4px; cursor: pointer; }
.fix-note { margin: 10px auto 0; max-width: 340px; font-size: 12.5px; color: var(--text-3); line-height: 1.45; text-align: center; }
.fix-note button { display: inline-block; margin-top: 6px; }
.fix-note button { color: var(--brand); font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--brand-soft); }

/* recipe builder */
.recipe-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); text-align: center; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.recipe-stats b { display: block; font-size: 17px; font-weight: 800; }
.recipe-stats span { font-size: 11px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

/* food detail */
.fd-head { text-align: center; padding: 4px 0 14px; }
.fd-head h3 { margin: 10px 0 2px; font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.fd-head p { margin: 0; color: var(--text-3); font-size: 14px; }
.fd-head .ftile { width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; margin: 0 auto; }
.fd-head .ftile svg { width: 28px; height: 28px; }
.donut-row { display: grid; grid-template-columns: minmax(96px, 120px) minmax(0, 1fr); gap: 18px; align-items: center; }
.donut { position: relative; width: 100%; aspect-ratio: 1; }
.donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut .c { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.donut .c b { font-size: 26px; font-weight: 800; line-height: 1; }
.donut .c span { font-size: 11px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-top: 3px; }
.mleg { display: grid; gap: 10px; }
.mleg .it { display: flex; align-items: center; gap: 10px; }
.mleg .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.mleg .nm { font-size: 14px; color: var(--text-2); flex: 1; }
.mleg .g { font-weight: 700; font-size: 15px; }
.mleg .pc { font-size: 12px; color: var(--text-3); width: 38px; text-align: right; }
.mleg .nm small { display: block; font-size: 12px; color: var(--text-3); }
.mleg .pcs { text-align: right; }
.mleg .pcs b { display: block; font-size: 15px; }
.mleg .pcs small { font-size: 11px; color: var(--text-3); white-space: nowrap; }

.stepper { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stepper .ctr { display: flex; align-items: center; gap: 8px; }
.stepper input { width: 76px; height: 44px; text-align: center; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); font-size: 18px; font-weight: 700; outline: none; }
.stepper input:focus { border-color: var(--brand); }
.presets { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.presets button { padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); }
.presets button.on { background: var(--brand); color: #fff; border-color: transparent; }

.facts { padding: 6px 0 0; }
.fact { display: flex; justify-content: space-between; padding: 10px 0; font-size: 15px; border-bottom: 1px solid var(--line); }
.fact:last-child { border-bottom: 0; }
.fact.sub { padding-left: 16px; color: var(--text-2); font-size: 14px; }
.fact b { font-weight: 700; }

/* forms */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin: 0 0 6px 2px; }
.input, .select {
  width: 100%; height: 50px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  padding: 0 14px; font-size: 16px; outline: none; -webkit-appearance: none; appearance: none;
}
.input:focus, .select:focus { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.input-unit { position: relative; }
.input-unit .u { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--text-3); font-size: 14px; font-weight: 600; pointer-events: none; }
.select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238d91a8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; padding-right: 40px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 10px; }

.options { display: grid; gap: 10px; }
.option {
  display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 16px; text-align: left;
  background: var(--surface); border: 2px solid var(--line); transition: border-color .2s, background .2s, transform .12s;
}
.option:active { transform: scale(.985); }
.option.on { border-color: var(--brand); background: var(--brand-soft); }
.option .ico { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: var(--surface-2); color: var(--brand); flex: none; }
.option .t { font-weight: 700; font-size: 16px; }
.option .d { font-size: 13px; color: var(--text-3); margin-top: 2px; }
.option .radio { margin-left: auto; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--text-3); display: grid; place-items: center; flex: none; }
.option.on .radio { border-color: var(--brand); background: var(--brand); color: #fff; }
.option.on .radio::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #fff; }

/* settings list */
.setting { display: flex; align-items: center; gap: 12px; padding: 14px 16px; width: 100%; text-align: left; }
.setting + .setting { border-top: 1px solid var(--line); }
.setting .ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; color: #fff; }
.setting .ico svg { width: 18px; height: 18px; }
.setting .t { flex: 1; font-weight: 600; font-size: 15px; }
.setting .v { color: var(--text-3); font-size: 15px; display: flex; align-items: center; gap: 4px; }
.setting .v svg { width: 18px; height: 18px; }
.setting.danger .t { color: var(--bad); }

.profile-card { display: flex; align-items: center; gap: 14px; }
.profile-card .avatar-lg { width: 62px; height: 62px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 24px; color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2)); flex: none; }
.profile-card h3 { margin: 0; font-size: 19px; font-weight: 800; }
.profile-card p { margin: 3px 0 0; color: var(--text-3); font-size: 13px; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.stat-row b { display: block; font-size: 18px; font-weight: 800; }
.stat-row span { font-size: 12px; color: var(--text-3); font-weight: 600; }

/* macro split editor */
.split { display: grid; gap: 16px; }
.split .lbl { display: flex; justify-content: space-between; font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.split .lbl span:last-child { color: var(--text-3); font-weight: 500; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 99px; background: var(--surface-3); outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.25); border: 0; }
input[type=range]::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.25); border: 0; }
.split-total { text-align: center; font-weight: 700; font-size: 14px; padding: 10px; border-radius: 12px; }
.split-total.ok { color: var(--good); background: rgba(21,163,90,.1); }
.split-total.bad { color: var(--bad); background: rgba(229,72,77,.1); }

/* progress */
.big-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; position: relative; z-index: 1; margin-top: 16px; }
.big-stats > div { background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.18); border-radius: 16px; padding: 12px; }
.big-stats b { display: block; font-size: 20px; font-weight: 800; }
.big-stats span { font-size: 11px; opacity: .8; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .axis text { fill: var(--text-3); font-size: 10px; font-family: var(--font); stroke: none; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart-empty { text-align: center; padding: 30px 10px; color: var(--text-3); font-size: 14px; }
.chart-empty svg { width: 40px; height: 40px; color: var(--text-3); opacity: .6; margin-bottom: 8px; }

.pred { text-align: center; }
.pred .big { font-size: 40px; font-weight: 800; letter-spacing: -0.02em; margin: 6px 0; background: linear-gradient(135deg, var(--brand), var(--brand-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- Onboarding ---------- */
.onboard {
  position: fixed; inset: 0; z-index: 200; background: var(--bg); display: flex; flex-direction: column;
  padding: calc(var(--safe-top) + 12px) 20px calc(var(--safe-bottom) + 16px);
}
.onboard .ob-top { display: flex; align-items: center; gap: 12px; min-height: 40px; }
.ob-progress { flex: 1; height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.ob-progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); border-radius: 99px; transition: width .4s ease; }
.ob-body { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 18px 2px; animation: pageIn .3s ease both; }
.ob-body h2 { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; margin: 6px 0 6px; }
.ob-body > p { color: var(--text-2); margin: 0 0 22px; font-size: 15px; line-height: 1.45; }
.welcome { display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; min-height: 100%; }
.welcome .logo { width: 88px; height: 88px; border-radius: 26px; margin-bottom: 18px; background: url(../icons/icon-192.png) center/cover; box-shadow: 0 16px 40px rgba(0,0,0,.28); flex: none; }
.welcome h1 { font-size: 36px; font-weight: 900; letter-spacing: -0.03em; margin: 0; }
.welcome p { color: var(--text-2); font-size: 16px; line-height: 1.5; max-width: 300px; margin: 10px auto 0; }
.feature-list { display: grid; gap: 12px; margin-top: 24px; text-align: left; width: 100%; max-width: 330px; }
.feature-list div { display: flex; gap: 12px; align-items: center; font-size: 15px; font-weight: 600; }
.feature-list .ico { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.feature-list .ico svg { width: 19px; height: 19px; }
.result-card { text-align: center; padding: 26px 18px; }
.result-card .big { font-size: 56px; font-weight: 900; letter-spacing: -0.03em; line-height: 1; background: linear-gradient(135deg, var(--brand), var(--brand-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; z-index: 300;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--surface); padding: 12px 18px; border-radius: 14px;
  font-weight: 600; font-size: 14px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 8px; transition: opacity .25s, transform .3s cubic-bezier(.3,1.4,.5,1);
  max-width: calc(100vw - 40px);
}
#toast svg { width: 18px; height: 18px; color: var(--good); stroke-width: 2.6; }
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { color: var(--brand-2); font-weight: 700; margin-left: 6px; }

@media (min-width: 700px) {
  #view, .tabbar { max-width: 640px; margin: 0 auto; }
  .tabbar { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
