*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #f0f2f5;
  --card:     #ffffff;
  --green:    #16a34a;
  --green-dk: #14532d;
  --green-lt: #dcfce7;
  --text:     #111827;
  --muted:    #6b7280;
  --border:   #e5e7eb;
  --shadow:   0 1px 4px rgba(0,0,0,.07), 0 2px 14px rgba(0,0,0,.05);
  --ring-trk: #e0e4f7;
  --nav-h:    70px;
  --hdr-h:    62px;
  --safe-t:   env(safe-area-inset-top, 0px);
  --safe-b:   env(safe-area-inset-bottom, 0px);
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 16px; -webkit-font-smoothing: antialiased; }
* { -webkit-tap-highlight-color: transparent; }
::-webkit-scrollbar { display: none; }

#app { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

/* ── HEADER ── */
.hdr {
  flex-shrink: 0;
  height: calc(var(--hdr-h) + var(--safe-t));
  padding: var(--safe-t) 16px 0;
  background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.hdr-left  { display: flex; align-items: center; gap: 12px; }
.hdr-name { font-size: 17px; font-weight: 700; color: var(--green-dk); line-height: 1.2; }
.hdr-date { font-size: 12px; color: var(--muted); }

/* ── MAIN / VIEWS ── */
.main { flex: 1; overflow: hidden; position: relative; }
.view {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden;
  display: none; -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
}
.view.active { display: block; }

/* ── SHARED ── */
.card { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); margin: 0 16px 14px; }
.section-hd { font-size: 16px; font-weight: 700; color: var(--text); padding: 4px 16px 10px; }

/* ── CALORIE CARD ── */
.cal-card { display: flex; align-items: center; gap: 16px; padding: 20px 18px; margin-top: 16px; }
.ring-wrap { position: relative; flex-shrink: 0; }
.ring-svg  { display: block; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--ring-trk); stroke-width: 9; }
.ring-fill  {
  fill: none; stroke: var(--green); stroke-width: 9; stroke-linecap: round;
  stroke-dasharray: 314.2; stroke-dashoffset: 314.2;
  transition: stroke-dashoffset .7s ease;
}
.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.ring-num  { font-size: 26px; font-weight: 800; color: var(--green-dk); line-height: 1; }
.ring-sub  { font-size: 8px;  color: var(--muted); letter-spacing: .8px; margin-top: 2px; }
.ring-lbl  { font-size: 10px; color: var(--muted); margin-top: 1px; }

.macro-list { flex: 1; display: flex; flex-direction: column; gap: 13px; }
.macro-item { display: flex; align-items: center; gap: 10px; }
.macro-ico  { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.macro-ico svg { width: 16px; height: 16px; }
.ico-protein { background: #eef2ff; } .ico-protein svg { stroke: #6366f1; }
.ico-carbs   { background: #fef3c7; } .ico-carbs   svg { stroke: #d97706; }
.ico-fat     { background: #ecfdf5; } .ico-fat     svg { stroke: #059669; }
.macro-name  { font-size: 11px; color: var(--muted); }
.macro-val   { font-size: 13px; font-weight: 600; color: var(--text); }

/* ── PROGRESS CARD ── */
.progress-card { padding: 16px 18px; }
.prog-row  { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.prog-label{ font-size: 13px; color: var(--muted); }
.prog-pct  { font-size: 15px; font-weight: 700; color: var(--green); }
.prog-track{ height: 8px; background: var(--ring-trk); border-radius: 4px; overflow: hidden; }
.prog-bar  { height: 100%; width: 0%; background: var(--green); border-radius: 4px; transition: width .6s ease; }
.prog-quote { font-size: 13px; color: var(--muted); font-style: italic; line-height: 1.55; margin-top: 12px; }

/* ── DASHBOARD MEAL CARDS ── */
.dash-meals { display: flex; flex-direction: column; gap: 10px; padding: 0 16px; }
.meal-card  {
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 14px; padding: 12px 14px;
  cursor: pointer; transition: transform .15s, box-shadow .15s;
}
.meal-card:active { transform: scale(.98); box-shadow: 0 1px 4px rgba(0,0,0,.05); }

.meal-img {
  width: 62px; height: 62px; border-radius: 12px;
  object-fit: cover; flex-shrink: 0; background: var(--ring-trk); display: block;
}
.meal-img-ph {
  width: 62px; height: 62px; border-radius: 12px;
  background: var(--ring-trk); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 28px;
}
.meal-info  { flex: 1; min-width: 0; }
.meal-name  { font-size: 15px; font-weight: 600; line-height: 1.3; }
.meal-kcal  { font-size: 14px; color: var(--green); font-weight: 600; }
.meal-meta  { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.meal-tag   {
  display: inline-block; font-size: 10px; font-weight: 600;
  background: var(--green-lt); color: var(--green-dk);
  border-radius: 20px; padding: 2px 8px;
}
.meal-progress-wrap { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.meal-dots { display: flex; gap: 3px; }
.meal-dot  { width: 6px; height: 6px; border-radius: 50%; background: var(--border); }
.meal-dot.done { background: var(--green); }
.meal-check {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--border); display: flex; align-items: center; justify-content: center;
  background: #fff; transition: all .2s;
}
.meal-check.all-done { background: var(--green); border-color: var(--green); }
.meal-check svg { width: 14px; height: 14px; }

/* ── MEALS DETAIL TAB ── */
.meals-detail { padding: 16px; display: flex; flex-direction: column; gap: 18px; }
.detail-card  { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.detail-head  { display: flex; align-items: center; gap: 14px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.detail-head-img { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; background: var(--ring-trk); flex-shrink: 0; }
.detail-head-ph  { width: 56px; height: 56px; border-radius: 12px; background: var(--ring-trk); flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 26px; }
.detail-head-info { flex: 1; }
.detail-head-name { font-size: 16px; font-weight: 700; }
.detail-head-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.detail-macros { display: flex; justify-content: space-around; padding: 12px 0; border-bottom: 1px solid var(--border); background: #fafafa; }
.dm-item { text-align: center; }
.dm-val  { font-size: 15px; font-weight: 700; color: var(--green-dk); }
.dm-lbl  { font-size: 10px; color: var(--muted); margin-top: 2px; }
.food-items { padding: 6px 0; }
.food-item-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; border-bottom: 1px solid var(--border);
}
.food-item-row:last-child { border-bottom: none; }
.fi-img { width: 36px; height: 36px; border-radius: 8px; object-fit: contain; background: #f8f9fa; flex-shrink: 0; padding: 2px; }
.fi-ph  { width: 36px; height: 36px; border-radius: 8px; background: #f8f9fa; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.fi-info { flex: 1; min-width: 0; }
.food-item-name { font-size: 13px; font-weight: 500; }
.food-item-amt  { font-size: 11px; color: var(--muted); margin-top: 1px; }
.food-item-cal  { font-size: 13px; color: var(--green); font-weight: 600; flex-shrink: 0; }

/* ── WATER ── */
.water-summary { display: flex; align-items: center; gap: 16px; padding: 20px 18px; margin-top: 16px; }
.water-drop-ico { font-size: 44px; flex-shrink: 0; }
.water-info { flex: 1; }
.water-num  { font-size: 28px; font-weight: 800; color: var(--green-dk); line-height: 1; }
.water-unit { font-size: 16px; font-weight: 400; color: var(--muted); }
.water-goal-lbl { font-size: 12px; color: var(--muted); margin: 4px 0 8px; }
.water-bar-track { height: 8px; background: var(--ring-trk); border-radius: 4px; overflow: hidden; }
.water-bar-fill  { height: 100%; background: #0ea5e9; border-radius: 4px; width: 0%; transition: width .6s ease; }
.water-pct  { font-size: 12px; color: #0ea5e9; font-weight: 600; margin-top: 4px; }
.water-list { display: flex; flex-direction: column; gap: 8px; padding: 0 16px; }
.water-slot { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 14px; padding: 14px 16px; cursor: pointer; transition: transform .15s; }
.water-slot:active { transform: scale(.98); }
.water-slot.done { opacity: .55; }
.ws-ico  { width: 40px; height: 40px; border-radius: 50%; background: #e0f2fe; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.ws-info { flex: 1; }
.ws-time { font-size: 14px; font-weight: 600; }
.ws-amt  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.ws-check { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border); background: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all .2s; }
.ws-check.checked { background: #0ea5e9; border-color: #0ea5e9; }
.ws-check svg { width: 14px; height: 14px; stroke: #fff; fill: none; stroke-width: 3; stroke-linecap: round; }

/* ── PROGRESS TAB ── */
.profile-hero { display: flex; flex-direction: column; align-items: center; padding: 24px 20px; margin-top: 16px; text-align: center; }
.profile-av { width: 68px; height: 68px; border-radius: 50%; background: var(--green); color: #fff; font-size: 22px; font-weight: 700; display: flex; align-items: center; justify-content: center; border: 4px solid var(--green-lt); margin-bottom: 10px; }
.profile-n  { font-size: 20px; font-weight: 700; color: var(--green-dk); }
.profile-g  { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.4; }

.targets-card { padding: 6px 0; }
.target-row { display: flex; justify-content: space-between; align-items: center; padding: 11px 18px; border-bottom: 1px solid var(--border); font-size: 14px; }
.target-row:last-child { border-bottom: none; }
.target-row span  { color: var(--muted); }
.target-row strong{ color: var(--text); }

/* Weekly chart */
.chart-card { padding: 16px 12px 8px; }
.chart-title { font-size: 13px; color: var(--muted); margin-bottom: 10px; text-align: center; }
.chart-wrap  { overflow: hidden; }

/* Monthly stats */
.monthly-card { padding: 16px 18px; }
.monthly-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.m-stat { background: #f8f9fa; border-radius: 12px; padding: 14px 12px; text-align: center; }
.m-stat-val { font-size: 22px; font-weight: 800; color: var(--green-dk); line-height: 1; }
.m-stat-lbl { font-size: 11px; color: var(--muted); margin-top: 4px; }
.streak-fire { font-size: 18px; }

/* History list */
#history-list .hist-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; border-bottom: 1px solid var(--border); font-size: 13px;
}
#history-list .hist-row:last-child { border-bottom: none; }
.hist-date { color: var(--text); font-weight: 500; }
.hist-meta { font-size: 11px; color: var(--muted); margin-top: 1px; }
.hist-kcal { font-size: 13px; font-weight: 600; color: var(--green); }
.hist-pct  { font-size: 11px; color: var(--muted); text-align: right; }
.hist-empty { padding: 24px 18px; text-align: center; color: var(--muted); font-size: 13px; }

/* ── ALARM BELL ── */
.alarm-btn {
  background: none; border: none; cursor: pointer; padding: 3px;
  color: var(--border); display: flex; align-items: center; transition: color .2s;
}
.alarm-btn.alarm-on { color: var(--green); }
.alarm-btn svg { width: 15px; height: 15px; }
.alarm-btn:active { opacity: .6; }

/* ── NOTIFICATION CARD ── */
.notif-card { padding: 14px 18px 16px; }
.notif-row  { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.notif-title{ font-size: 14px; font-weight: 600; }
.notif-sub  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.notif-status { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 20px; background: var(--green-lt); color: var(--green-dk); }
.test-notif-btn {
  width: 100%; height: 44px; border-radius: 12px;
  background: #eff6ff; color: #2563eb; border: none;
  font-size: 14px; font-weight: 600; cursor: pointer; transition: background .2s;
}
.test-notif-btn:active { background: #dbeafe; }

/* ── TOAST ── */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + var(--safe-b) + 14px); left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: #1f2937; color: #fff;
  padding: 10px 18px; border-radius: 100px;
  font-size: 13px; font-weight: 500; white-space: nowrap; max-width: calc(100vw - 40px);
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; z-index: 300;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.reset-btn {
  display: block; width: calc(100% - 32px); margin: 8px 16px 4px;
  height: 48px; border-radius: 12px;
  background: #fee2e2; color: #dc2626; border: none;
  font-size: 14px; font-weight: 600; cursor: pointer; transition: background .2s;
}
.reset-btn:active { background: #fecaca; }

/* ── BOTTOM NAV ── */
.bot-nav {
  flex-shrink: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: #fff; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
}
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 0; background: none; border: none; color: var(--muted); font-size: 10px; cursor: pointer; transition: color .2s; }
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--green); }
.nav-item:active { opacity: .6; }

/* ── OVERLAY / SHEET ── */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.55); backdrop-filter: blur(5px);
  display: flex; align-items: flex-end;
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
}
.overlay.open { opacity: 1; pointer-events: all; }

.sheet {
  width: 100%; max-height: 90dvh;
  background: var(--card); border-radius: 22px 22px 0 0;
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.32,.72,0,1);
  padding-bottom: var(--safe-b);
}
.overlay.open .sheet { transform: translateY(0); }
.sheet-handle { width: 38px; height: 4px; background: #e5e7eb; border-radius: 2px; margin: 10px auto 0; flex-shrink: 0; }

/* Items sheet */
.items-sheet { max-height: 85dvh; }
.items-head { padding: 14px 18px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.items-meal-img { width: 100%; height: 140px; object-fit: cover; background: var(--ring-trk); border-radius: 14px; margin-bottom: 12px; display: block; }
.items-meal-img-ph { width: 100%; height: 120px; background: var(--ring-trk); border-radius: 14px; margin-bottom: 12px; display: flex; align-items: center; justify-content: center; font-size: 52px; }
.items-meal-name { font-size: 18px; font-weight: 700; }
.items-meal-meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.items-consumed  { font-size: 13px; font-weight: 600; color: var(--green); margin-top: 6px; }

.items-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.item-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .15s;
}
.item-row:last-child { border-bottom: none; }
.item-row:active { background: #f9fafb; }
.item-row.skipped { opacity: .5; }

.item-img { width: 40px; height: 40px; border-radius: 8px; object-fit: contain; background: #f8f9fa; flex-shrink: 0; padding: 3px; }
.item-img-ph { width: 40px; height: 40px; border-radius: 8px; background: #f8f9fa; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 22px; }
.item-info { flex: 1; min-width: 0; }
.item-name { font-size: 14px; font-weight: 500; }
.item-amt  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.item-kcal { font-size: 13px; color: var(--green); font-weight: 600; margin-right: 8px; flex-shrink: 0; }
.item-check {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--border); background: #fff;
  display: flex; align-items: center; justify-content: center; transition: all .2s;
}
.item-check.checked { background: var(--green); border-color: var(--green); }
.item-check svg { width: 13px; height: 13px; stroke: #fff; fill: none; stroke-width: 3; stroke-linecap: round; }

.items-footer { padding: 12px 18px; flex-shrink: 0; display: flex; gap: 10px; }
.btn-all-done {
  flex: 1; height: 48px; border-radius: 12px;
  background: var(--green); color: #fff; border: none;
  font-size: 15px; font-weight: 600; cursor: pointer; transition: background .2s;
}
.btn-all-done:active { background: var(--green-dk); }
.btn-clear-meal {
  height: 48px; padding: 0 16px; border-radius: 12px;
  background: #fee2e2; color: #dc2626; border: none;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
