:root {
  --bg: #f3f6f5;
  --card: #ffffff;
  --text: #13201b;
  --muted: #6b7a74;
  --line: #e3e9e6;
  --primary: #10b981;
  --primary-soft: #d1fae5;
  --water: #3b82f6;
  --danger: #ef4444;
  --shadow: 0 2px 10px rgba(15, 40, 30, .06);
  --radius: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1412;
    --card: #17211e;
    --text: #e8f0ec;
    --muted: #8fa29a;
    --line: #26332f;
    --primary-soft: #0f3a2c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

h1 { margin: 0; font-size: 1.5rem; color: var(--primary); }
h2 { margin: 0 0 12px; font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--bg);
}
.topbar p { margin: 2px 0 0; font-size: .85rem; }
.date-nav { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.icon-btn:disabled { opacity: .35; }

main { max-width: 560px; margin: 0 auto; padding: 0 16px; }

.view { display: none; animation: fade .2s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  margin-bottom: 14px; box-shadow: var(--shadow);
}
.center { text-align: center; }

/* Hero ring */
.hero { display: flex; flex-direction: column; align-items: center; }
.ring-wrap { position: relative; width: 170px; height: 170px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; stroke-linecap: round; }
.ring-bg { stroke: var(--line); }
.ring-fg { stroke: var(--primary); stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset .6s ease; }
.ring-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-text strong { font-size: 2.6rem; }
.ring-text span { font-size: .8rem; color: var(--muted); }
.tip { margin: 12px 0 0; text-align: center; color: var(--muted); font-size: .92rem; }

/* Stats grid */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.stat {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  background: var(--card); color: var(--text); border: 0; border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); font: inherit; cursor: pointer;
}
.stat-icon { font-size: 1.4rem; }
.stat-label { font-size: .8rem; color: var(--muted); }
.stat strong { font-size: 1.15rem; }
.bar { width: 100%; height: 6px; background: var(--line); border-radius: 6px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; width: 0; background: var(--primary); border-radius: 6px; transition: width .5s ease; }
#home-water-bar { background: var(--water); }

/* Week chart */
.week { display: flex; align-items: flex-end; gap: 8px; height: 130px; }
.week .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.week .col i { width: 100%; max-width: 30px; background: var(--water); opacity: .85; border-radius: 6px 6px 3px 3px; min-height: 3px; transition: height .5s ease; }
.week .col.today i { opacity: 1; }
.week .col span { font-size: .72rem; color: var(--muted); }
.week .col.goal i { background: var(--primary); }

/* Water glass */
.glass {
  position: relative; width: 150px; height: 200px; margin: 6px auto 18px;
  border: 4px solid var(--water); border-top: 0; border-radius: 0 0 26px 26px; overflow: hidden;
}
.glass-fill {
  position: absolute; bottom: 0; left: 0; right: 0; height: 0;
  background: linear-gradient(180deg, #60a5fa, var(--water)); transition: height .6s ease;
}
.glass-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.glass-text strong { font-size: 2rem; }
.glass-text span { font-size: .85rem; }

/* Buttons & forms */
.btn-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; }
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 12px 16px; border-radius: 14px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.ghost { border: 0; background: none; color: var(--muted); font-weight: 500; }
.btn.block { width: 100%; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); flex: 1; }
.form .row { display: flex; gap: 12px; }
input, select {
  width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: 16px;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 0; }

.quality { display: flex; justify-content: space-between; gap: 6px; }
.quality button {
  flex: 1; font-size: 1.6rem; padding: 8px 0; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); cursor: pointer; filter: grayscale(1); opacity: .6;
}
.quality button.on { filter: none; opacity: 1; border-color: var(--primary); background: var(--primary-soft); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .del { border: 0; background: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 4px 8px; }
.list .empty { color: var(--muted); justify-content: center; }

/* BMI */
.bmi-box { margin-top: 16px; text-align: center; }
.bmi-box strong { font-size: 2.2rem; display: block; }
.bmi-scale {
  position: relative; height: 10px; border-radius: 10px; margin: 12px 0 6px;
  background: linear-gradient(90deg, #60a5fa 0 22%, #10b981 22% 50%, #f59e0b 50% 72%, #ef4444 72%);
}
.bmi-scale i {
  position: absolute; top: -5px; width: 4px; height: 20px; background: var(--text);
  border-radius: 2px; transform: translateX(-50%); transition: left .5s ease;
}
.bmi-legend { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); }

canvas { width: 100%; display: block; }

/* Tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; border: 0; background: none; color: var(--muted);
  font: inherit; font-size: .66rem; cursor: pointer;
}
.tabbar button span { font-size: 1.25rem; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--primary); font-weight: 600; }
.tabbar button.active span { filter: none; opacity: 1; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: .9rem; transition: all .25s ease; z-index: 20; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Kế hoạch 90 ngày ---------- */
.icon-btn.small-icon { font-size: 1rem; }

.plan-card {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  border: 0; font: inherit; color: var(--text); cursor: pointer;
  background: linear-gradient(135deg, var(--primary-soft), var(--card));
}
.plan-card div { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.plan-card .chev { font-size: 1.6rem; color: var(--muted); }

.plan-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.plan-top strong { font-size: 1.1rem; }
.plan-goal { text-align: right; display: flex; flex-direction: column; }
.plan-goal strong { color: var(--primary); font-size: 1.3rem; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 4px; }
.kpis div { background: var(--bg); border-radius: 12px; padding: 10px 6px; text-align: center; display: flex; flex-direction: column; }
.kpis strong { font-size: 1.15rem; }
.kpis span { font-size: .72rem; color: var(--muted); }
.focus { margin: 12px 0 0; font-size: .9rem; }
.focus::before { content: '🎯 '; }
.status { margin: 10px 0 0; font-size: .88rem; padding: 10px 12px; border-radius: 12px; background: var(--primary-soft); }
.warn { margin: 12px 0 0; font-size: .85rem; padding: 10px 12px; border-radius: 12px; background: #fef3c7; color: #92400e; }

.seg {
  display: flex; gap: 4px; margin-bottom: 14px; padding: 4px; border-radius: 14px;
  background: var(--card); box-shadow: var(--shadow); overflow-x: auto; scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: 1 0 auto; border: 0; background: none; color: var(--muted); font: inherit; font-size: .82rem;
  padding: 9px 10px; border-radius: 10px; cursor: pointer; white-space: nowrap;
}
.seg button.active { background: var(--primary); color: #fff; font-weight: 600; }

.block-title { font-size: .85rem; margin: 14px 0 6px; color: var(--primary); }
.ex-list { list-style: none; margin: 0 0 10px; padding: 0; }
.ex-list li {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 0;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.ex-list li:last-child { border-bottom: 0; }
.ex-body { flex: 1; min-width: 0; }
.ex-top { display: flex; justify-content: space-between; gap: 8px; }
.ex-top strong { font-size: .93rem; }
.dose { white-space: nowrap; font-size: .82rem; font-weight: 600; color: var(--primary); }
.ex-list small { display: block; margin-top: 3px; line-height: 1.35; }

.check {
  flex: none; width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center; margin-top: 1px;
}
.done > .check, .done .meal-head .check { background: var(--primary); border-color: var(--primary); }
.done > .check::after, .done .meal-head .check::after { content: '✓'; color: #fff; font-size: .8rem; font-weight: 700; }
.ex-list li.done .ex-top strong { text-decoration: line-through; color: var(--muted); }

.meal { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin-bottom: 10px; }
.meal.done { border-color: var(--primary); background: var(--primary-soft); }
.meal-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.meal-head[data-meal] { cursor: pointer; }
.meal-head strong { flex: 1; }
.meal-head .muted { font-size: .8rem; }
.food-list { list-style: none; margin: 8px 0 0; padding: 0; font-size: .88rem; }
.food-list li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.food-list li span:last-child { white-space: nowrap; font-weight: 600; }

.chips { display: flex; gap: 6px; margin-bottom: 8px; }
.chips button {
  flex: 1; padding: 8px 0; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: .85rem; cursor: pointer;
}
.chips button.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

.tips { margin: 0; padding-left: 18px; font-size: .88rem; line-height: 1.5; }
.tips li { margin-bottom: 6px; }
.tip.left { text-align: left; }

.legend { display: flex; gap: 16px; justify-content: center; margin-top: 8px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 18px; height: 0; border-top: 2px dashed var(--muted); }
.legend i.solid { border-top: 3px solid var(--primary); }

.weeks { list-style: none; margin: 0; padding: 0; }
.weeks li { padding: 10px 12px; border-radius: 12px; margin-bottom: 6px; border: 1px solid var(--line); }
.weeks li.current { border-color: var(--primary); background: var(--primary-soft); }
.wk-head { display: flex; align-items: baseline; gap: 8px; }
.wk-head .wk-target { margin-left: auto; font-weight: 700; color: var(--primary); }
.wk-meta { margin: 2px 0 4px; }

/* Google Sheets */
.form label.inline { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: .9rem; }
.form label.inline input { width: 20px; height: 20px; accent-color: var(--primary); }
.sync-actions { margin-top: 10px; justify-content: flex-start; }
.warn a { color: inherit; font-weight: 700; }

/* ---------- Đi chợ ---------- */
.price { color: #b45309; font-weight: 600; white-space: nowrap; }
@media (prefers-color-scheme: dark) { .price { color: #fbbf24; } }
.trip-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: center; }
.trip-head > div { flex: 1; }
.trip-days { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 6px; }
.trip-day { background: var(--bg); border-radius: 12px; padding: 8px 12px; }
.trip-day-head { display: flex; justify-content: space-between; }
.buy-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 3px; }
.buy-meta small { margin-top: 0 !important; }
.ex-list li.done .price { color: var(--muted); }

.catalog summary { font-weight: 700; cursor: pointer; padding: 2px 0; list-style-position: inside; }
.catalog[open] summary { margin-bottom: 8px; }
.cat-list { list-style: none; margin: 0 0 8px; padding: 0; }
.cat-list li { display: flex; flex-direction: column; gap: 3px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: .85rem; }
.cat-list li:last-child { border-bottom: 0; }
.cat-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cat-top strong { font-size: .93rem; }
.stars { color: #f59e0b; font-size: .8rem; letter-spacing: 1px; }
.tag { margin-left: auto; font-size: .7rem; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.tag.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.cat-price { display: flex; align-items: center; gap: 8px; }
.cat-price input { width: 130px; padding: 8px 10px; }
.group-note { margin: -2px 0 4px; }
#trip-group { margin: 4px 0 8px; }

/* Thông báo đầu trang */
.banner { border: 1px solid var(--primary); background: var(--primary-soft); }
.banner p { margin: 0 0 10px; font-size: .9rem; }
.banner .btn-row { justify-content: flex-start; margin: 0; }

#sync-status { white-space: pre-line; }

/* ---------- Hình minh họa ---------- */
.fig { width: 84px; height: 70px; flex: none; background: var(--bg); border-radius: 10px; }
.fig polyline { fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 4.5; }
.fig .fig-near { stroke: var(--text); }
.fig .fig-far { stroke: var(--muted); opacity: .6; }
.fig-head { fill: var(--text); }
.fig-floor { stroke: var(--line); stroke-width: 2; }
.fig-mat { fill: var(--primary); opacity: .35; }
.fig-prop { fill: var(--line); }
.fig-prop-line { stroke: var(--muted); stroke-width: 3; fill: none; stroke-linecap: round; opacity: .7; }
.fig .fig-towel-line { stroke: #f59e0b; stroke-width: 2.5; }
.fig-towel { fill: #fcd34d; }
.fig-bottle { fill: #60a5fa; }

/* Ảnh thực phẩm & hình bài tập trong danh sách */
.food-img { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; flex: none; background: var(--line); }
.food-img.lg { width: 48px; height: 48px; border-radius: 10px; }
.food-list li { align-items: center; gap: 8px; padding: 4px 0; }
.food-list .fname { flex: 1; min-width: 0; }
.ex-list li > .food-img { margin-top: 0; }
.fig-wrap { flex: none; cursor: zoom-in; display: flex; }
.ex-list .fig { width: 76px; height: 63px; }
.ex-list li.zoom { flex-wrap: wrap; }
.ex-list li.zoom .fig-wrap { order: 5; width: 100%; cursor: zoom-out; }
.ex-list li.zoom .fig { width: 100%; height: auto; aspect-ratio: 6 / 5; max-height: 280px; }
