/* ============ Màu sắc & phông chữ ============ */
:root {
  --bg: #F6F4EF;
  --surface: #FFFFFF;
  --surface-2: #EFECE5;
  --ink: #1C1B19;
  --muted: #7B776F;
  --line: #E3DED3;
  --gold: #9C7A43;
  --gold-soft: rgba(156, 122, 67, .12);
  --good: #4E7A5A;
  --warn: #B4513A;
  --shadow: 0 1px 2px rgba(28, 27, 25, .04), 0 8px 24px rgba(28, 27, 25, .05);
  --bar-bg: rgba(246, 244, 239, .86);
  --serif: "Cormorant Garamond", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121110;
    --surface: #1B1A18;
    --surface-2: #252320;
    --ink: #EEE9E0;
    --muted: #9C968B;
    --line: #2F2C28;
    --gold: #CFAE72;
    --gold-soft: rgba(207, 174, 114, .14);
    --good: #82B38F;
    --warn: #E38C74;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --bar-bg: rgba(18, 17, 16, .86);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #121110;
  --surface: #1B1A18;
  --surface-2: #252320;
  --ink: #EEE9E0;
  --muted: #9C968B;
  --line: #2F2C28;
  --gold: #CFAE72;
  --gold-soft: rgba(207, 174, 114, .14);
  --good: #82B38F;
  --warn: #E38C74;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  --bar-bg: rgba(18, 17, 16, .86);
  color-scheme: dark;
}

/* ============ Nền tảng ============ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  transition: background .25s, color .25s;
  overscroll-behavior-y: none;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: .01em; }
h2 { font-size: 1.3rem; display: flex; align-items: center; gap: 8px; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
/* Safari (iPhone) tự thêm khoảng đệm vào nút, làm nội dung nút tròn bị lệch phải.
   Xóa hết, nút nào cần khoảng đệm sẽ tự khai báo riêng. */
button { padding: 0; margin: 0; -webkit-appearance: none; appearance: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.eyebrow {
  font-size: .7rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}

/* ============ Đầu trang ============ */
.top {
  position: sticky; top: 0; z-index: 20;
  max-width: 560px; margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bar-bg);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
}
.brand {
  font-family: var(--serif);
  font-size: 1.45rem;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: .02em;
}
.brand em { font-style: italic; color: var(--gold); font-weight: 500; }
.actions { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; line-height: 1;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
  font-size: 1.2rem;
  transition: color .2s, border-color .2s;
}
.icon-btn:active:not(:disabled) { color: var(--ink); border-color: var(--muted); }
.icon-btn.active { color: var(--gold); border-color: var(--gold); }
.icon-btn:disabled { opacity: .3; }

/* ============ Thanh menu dưới đáy ============ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--bar-bg);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; max-width: 120px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 0;
  text-decoration: none;
  color: var(--muted);
  font-size: .68rem;
  letter-spacing: .02em;
  transition: color .2s;
}
.tabbar svg { width: 22px; height: 22px; }
.tabbar a.active { color: var(--gold); }

/* ============ Nội dung ============ */
.view {
  max-width: 560px;
  margin: 0 auto;
  padding: 6px 16px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom));
  display: grid;
  gap: 14px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.card-head .muted { font-size: .85rem; }

/* Nút ⓘ và khung hướng dẫn */
.tip-btn {
  width: 20px; height: 20px; flex: none;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: italic 600 .72rem/1 var(--serif);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  position: relative;
}
.tip-btn::after { content: ""; position: absolute; inset: -12px; } /* vùng bấm rộng hơn */
.tip-btn[aria-expanded="true"] { color: var(--gold); border-color: var(--gold); background: var(--gold-soft); }
.tip {
  font-size: .85rem;
  line-height: 1.55;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 10px 12px;
  margin: -2px 0 12px;
  animation: tipIn .2s ease;
}
.tip b { color: var(--ink); font-weight: 600; }
@keyframes tipIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* Hero trang chủ */
.hero { padding: 22px 18px 20px; }
.display {
  font-size: 3rem;
  line-height: 1.05;
  margin: 4px 0 14px;
}
.display .of { color: var(--muted); font-weight: 400; font-size: .45em; }
.bar {
  height: 4px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--gold);
  border-radius: 99px;
  transition: width .5s ease;
}
.bar.over > span { background: var(--warn); }

/* Thẻ số liệu */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.stats .wide { grid-column: 1 / -1; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat-value { font-family: var(--serif); font-size: 1.9rem; font-weight: 600; line-height: 1.1; white-space: nowrap; }
.stat-value small { font-family: var(--sans); font-size: .8rem; color: var(--muted); font-weight: 400; margin-left: 3px; }
.stat-sub { font-size: .82rem; color: var(--muted); }
.stat-sub.good { color: var(--good); }
.stat-sub.warn { color: var(--warn); }
.stat-row { display: flex; align-items: center; gap: 16px; }

.ring { width: 68px; height: 68px; flex: none; }
.ring-bg { fill: none; stroke: var(--surface-2); stroke-width: 6; }
.ring-fg { fill: none; stroke: var(--gold); stroke-width: 6; stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.ring.over .ring-fg { stroke: var(--warn); }

/* Checklist hôm nay */
.checks { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.check {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  border-radius: 99px;
  border: 1px solid var(--line);
  font-size: .82rem;
  color: var(--muted);
}
.check.done { color: var(--ink); border-color: var(--gold); background: var(--gold-soft); }
.check .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.check.done .dot { background: var(--gold); }

/* Lịch 100 chấm */
.dots {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
  max-width: 340px;
  margin: 0 auto;
}
.dots a, .dots span {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  text-decoration: none;
  font-size: 9.5px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  color: var(--muted);
}
.dots .done { background: var(--gold); border-color: var(--gold); color: var(--surface); font-weight: 600; }
.dots .today { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--ink); color: var(--ink); font-weight: 700; }
.dots .today.done { color: var(--surface); }
.dots .future { opacity: .4; }
.legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; border: 1px solid var(--line); vertical-align: -1px; margin: 0 2px; }
.legend-dot.done { background: var(--gold); border-color: var(--gold); }

/* Thông báo nhỏ */
.notice {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px 12px 16px;
  border-radius: 16px;
  border: 1px dashed var(--gold);
  background: var(--gold-soft);
  font-size: .88rem;
}

/* ============ Nút & ô nhập ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  text-decoration: none;
  font-size: .92rem;
  white-space: nowrap;
  transition: opacity .2s, border-color .2s;
}
.btn:active { opacity: .7; }
.btn-primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn-gold { background: var(--gold); color: #fff; border-color: var(--gold); min-height: 38px; padding: 0 14px; }
.btn-danger { color: var(--warn); border-color: var(--warn); }
.btn-block { width: 100%; }
.link { background: none; border: 0; color: var(--gold); cursor: pointer; padding: 4px; text-decoration: underline; text-underline-offset: 3px; font-size: .88rem; }

/* Ô nhập kiểu gạch chân mảnh, chữ số dùng font có chân */
.input, select.input {
  width: 100%;
  min-height: 46px;
  padding: 10px 2px 8px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  outline: none;
  font: 500 1.15rem/1.2 var(--serif); /* ≥16px để iPhone không tự phóng to */
  color: var(--ink);
  text-transform: none;
  letter-spacing: .01em;
  font-variant-numeric: tabular-nums;
  transition: border-color .25s;
  min-width: 0;
}
.input::placeholder { color: var(--muted); opacity: .55; font-style: italic; font-weight: 400; }
.input:focus { border-bottom-color: var(--gold); }
select.input {
  appearance: none; -webkit-appearance: none;
  padding-right: 26px; cursor: pointer;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239C968B' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 2px center / 16px;
}
select.input option { font-family: var(--sans); font-size: 1rem; background: var(--surface); color: var(--ink); }
textarea.input {
  width: 100%; min-height: 96px; resize: none;
  padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 14px;
  background: transparent; outline: none;
  font: 400 1.05rem/1.5 var(--serif); color: var(--ink);
}
textarea.input:focus { border-color: var(--gold); }

/* Ô có đơn vị mờ bên phải: 450 ······ kcal */
.ux { position: relative; display: block; min-width: 0; }
.ux .input { padding-right: 46px; }
.ux > span {
  position: absolute; right: 2px; bottom: 12px;
  font: .7rem var(--sans); letter-spacing: .08em; text-transform: none; color: var(--muted);
  pointer-events: none;
}
/* Ẩn mũi tên tăng/giảm trong ô nhập số cho gọn */
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
/* Nhãn chữ nhỏ cách đều phía trên ô nhập */
label.field, .field {
  display: grid; gap: 2px;
  font-size: .66rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid.three { grid-template-columns: repeat(3, 1fr); }

/* Hàng thêm món / bài tập: tên ở trên, số + nút ＋ ở dưới */
.add-row { display: grid; grid-template-columns: 1fr auto; gap: 10px 18px; align-items: end; }
.add-row .grow { grid-column: 1 / -1; }
.add-row.ex { grid-template-columns: 1fr 1fr auto; }

/* Nút ＋ tròn viền vàng */
.add-btn {
  width: 46px; height: 46px; flex: none;
  border-radius: 50%;
  border: 1px solid var(--gold);
  background: transparent;
  color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  padding: 0; line-height: 1;
  cursor: pointer;
  transition: background .2s, color .2s, transform .15s;
}
.add-btn svg { width: 20px; height: 20px; }
.add-btn:active { background: var(--gold); color: var(--surface); transform: scale(.94); }

/* Chọn bằng chữ có gạch chân vàng (bữa ăn, phút / bước) */
.tabs { display: flex; gap: 22px; border-bottom: 1px solid var(--line); }
.tabs button {
  background: none; border: 0; cursor: pointer;
  padding: 12px 0 10px; margin-bottom: -1px;
  border-bottom: 1.5px solid transparent;
  font-size: .82rem; letter-spacing: .05em; color: var(--muted);
  transition: color .2s, border-color .2s;
}
.tabs button.on { color: var(--ink); border-bottom-color: var(--gold); }

.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--surface-2); gap: 2px; }
.seg button {
  border: 0; background: transparent; min-height: 36px; padding: 0 16px; border-radius: 999px;
  cursor: pointer; color: var(--muted); font-size: .88rem;
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

.chips { display: flex; gap: 6px; margin-top: 12px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  min-height: 34px; padding: 0 12px; font-size: .82rem; cursor: pointer; color: var(--muted);
}
.chip:active { color: var(--ink); border-color: var(--gold); }

/* ============ Nhật ký ============ */
.datebar {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px;
  text-align: center;
}
.datebar-date { font-family: var(--serif); font-size: 1.3rem; font-weight: 600; }

/* Danh sách trong Lịch sử */
.meal-group + .meal-group { margin-top: 6px; }
.mg-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 12px 0 4px;
  font-size: .64rem; letter-spacing: .16em; text-transform: uppercase; color: var(--gold);
}
.mg-head span:last-child { font: 500 .8rem var(--serif); letter-spacing: .02em; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 6px;
  min-height: 46px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.list li:last-child { border-bottom: 0; }
.li-name { font-size: .92rem; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.li-name small { font-size: .72rem; color: var(--muted); }
.list .kcal { font: 500 1rem var(--serif); font-variant-numeric: tabular-nums; color: var(--ink); }
.x {
  width: 32px; height: 32px; border-radius: 50%; border: 0; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
  color: var(--muted); opacity: .5; cursor: pointer; font-size: 1.05rem; line-height: 1;
  transition: opacity .2s, color .2s;
}
.x:active, .x:hover { opacity: 1; color: var(--warn); }
.empty { color: var(--muted); font-size: .88rem; padding: 14px 0; text-align: center; }

.cal-summary { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: .85rem; color: var(--muted); margin: 8px 0 2px; }
.cal-summary b { color: var(--ink); font-weight: 600; }
.cal-summary .warn, .cal-summary .warn b { color: var(--warn); }

.water { display: flex; align-items: center; gap: 12px; }
.cups { display: flex; gap: 5px; flex-wrap: wrap; flex: 1; justify-content: center; }
.cup { width: 9px; height: 24px; border: 1px solid var(--line); border-radius: 99px; transition: background .25s, border-color .25s; }
.cup.full { background: var(--gold); border-color: var(--gold); }

.moods { display: flex; justify-content: space-between; margin-bottom: 12px; }
.mood {
  width: 52px; height: 52px; flex: none; border-radius: 50%;
  border: 1px solid var(--line); background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0; line-height: 1;
  font-size: 1.5rem; filter: grayscale(1); opacity: .5; transition: all .2s;
}
.mood.on { filter: none; opacity: 1; border-color: var(--gold); background: var(--gold-soft); }

/* Mục thu gọn được */
.secs { display: grid; gap: 10px; }
.sec { padding: 0; } /* không cắt khung gợi ý tên món */
.sec-head {
  list-style: none;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  min-height: 64px;
  cursor: pointer;
  user-select: none;
}
.sec-head::-webkit-details-marker { display: none; }
.sec-icon {
  width: 36px; height: 36px; flex: none;
  border-radius: 12px;
  display: grid; place-items: center;
  background: var(--gold-soft);
  color: var(--gold);
}
.sec-icon svg { width: 19px; height: 19px; }
.sec-title {
  font: 600 1.15rem var(--serif);
  display: flex; align-items: center; gap: 8px;
  margin-right: auto;
}
.sec-sum { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sec-sum .warn { color: var(--warn); }
.sec-sum .good { color: var(--good); }

/* Thực phẩm bổ sung: chạm để tích đã uống */
.supp-list { display: grid; }
.supp {
  display: flex; align-items: center; gap: 14px;
  width: 100%; min-height: 54px; padding: 0 2px;
  border: 0; border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  background: transparent; cursor: pointer; text-align: left;
}
.supp:last-child { border-bottom: 0; }
.supp-check {
  width: 26px; height: 26px; flex: none; border-radius: 50%;
  border: 1px solid var(--line);
  display: grid; place-items: center;
  color: transparent;
  transition: background .2s, border-color .2s, color .2s, transform .15s;
}
.supp-check svg { width: 14px; height: 14px; }
.supp:active .supp-check { transform: scale(.9); }
.supp.on .supp-check { background: var(--gold); border-color: var(--gold); color: var(--surface); }
.supp-name { font: 500 1.08rem var(--serif); color: var(--ink); transition: color .2s; }
.supp.on .supp-name { color: var(--muted); }
.sum-emoji { font-size: 1.15rem; }
.chev { width: 18px; height: 18px; color: var(--muted); flex: none; transition: transform .25s ease; }
.sec[open] > .sec-head .chev { transform: rotate(180deg); }
.sec:not([open]) .tip-btn { display: none; }
.sec > .tip { margin: 0 16px 12px; }
.sec-body { padding: 0 16px 18px; animation: tipIn .22s ease; }

/* Bảng Calo hôm nay: vòng cung + một con số lớn */
.daysum { padding-bottom: 6px; }
.daysum-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.daysum .tip { margin: 6px 0 4px; }
.gauge-wrap { position: relative; width: 220px; max-width: 100%; margin: 4px auto 0; }
.gauge { display: block; width: 100%; height: auto; }
.g-bg, .g-fg { fill: none; stroke-width: 6; stroke-linecap: round; }
.g-bg { stroke: var(--surface-2); }
.g-fg { stroke: var(--gold); transition: stroke-dashoffset .6s ease; }
.gauge.over .g-fg { stroke: var(--warn); }
.gauge-center {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: grid; justify-items: center; line-height: 1;
}
.gauge-center small { font-size: .68rem; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.gauge-center b { font: 600 2.9rem/1 var(--serif); font-variant-numeric: tabular-nums; }
.gauge-center b.warn { color: var(--warn); }
.gauge-center span { font-size: .75rem; color: var(--muted); margin-top: 4px; }
.daysum-big { text-align: center; padding: 10px 0 4px; }
.daysum-big b { display: block; font: 600 2.6rem/1 var(--serif); }
.daysum-big span { font-size: .8rem; color: var(--muted); }
.daysum-line {
  display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 16px;
  margin: 14px 0 6px; font-size: .8rem; color: var(--muted);
}
.daysum-line b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.daysum-rows { border-top: 1px solid var(--line); margin-top: 10px; }
.daysum-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 11px 0; font-size: .85rem; color: var(--muted);
}
.daysum-row + .daysum-row { border-top: 1px solid var(--line); }
.daysum-row b { font: 600 1.05rem var(--serif); color: var(--ink); font-variant-numeric: tabular-nums; }
.daysum-row b.good { color: var(--good); }
.daysum-row b.warn { color: var(--warn); }
.center-link { text-align: center; margin: 6px 0 10px; }

/* Tổng ở cuối Lịch sử */
.hist-total {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 4px; padding: 14px 0 2px;
  border-top: 1px solid var(--line);
  font-size: .64rem; letter-spacing: .16em; text-transform: uppercase; color: var(--muted);
}
.hist-total b { font: 600 1.35rem var(--serif); letter-spacing: 0; text-transform: none; color: var(--gold); font-variant-numeric: tabular-nums; }
.hist-total b small { font: .7rem var(--sans); letter-spacing: .06em; color: var(--muted); margin-left: 4px; }

/* Dòng "Lịch sử" thu gọn */
.hist { margin-top: 18px; border-top: 1px solid var(--line); }
.hist > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 10px;
  min-height: 48px;
}
.hist > summary::-webkit-details-marker { display: none; }
.hist > summary > span:first-child {
  margin-right: auto; color: var(--ink);
  font-size: .66rem; letter-spacing: .18em; text-transform: uppercase;
}
.hist > summary .muted { font: italic .9rem var(--serif); }
.hist[open] > summary .chev { transform: rotate(180deg); }
.hist-body { animation: tipIn .2s ease; }
.hist-body .meal-group:first-child h3 { margin-top: 2px; }

/* Ô chọn bài tập (thay cho danh sách thả xuống) */
.picker {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  text-align: left; cursor: pointer; color: var(--muted);
}
.picker > span { font-style: italic; opacity: .7; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker.has > span { font-style: normal; opacity: 1; }
.picker.has { color: var(--ink); }
.picker em { font: .8rem var(--sans); font-style: normal; color: var(--muted); }

/* Bảng chọn một lựa chọn (thay danh sách thả xuống) */
.opt-list { display: grid; gap: 8px; margin-top: 12px; }
.opt {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 62px; padding: 10px 16px;
  border: 1px solid var(--line); border-radius: 16px;
  background: transparent; text-align: left; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.opt b { display: block; font: 600 1.12rem var(--serif); }
.opt small { display: block; font-size: .78rem; color: var(--muted); margin-top: 2px; }
.opt svg { width: 18px; height: 18px; flex: none; color: var(--gold); opacity: 0; transition: opacity .15s; }
.opt:active { background: var(--surface-2); }
.opt.on { border-color: var(--gold); background: var(--gold-soft); }
.opt.on svg { opacity: 1; }

/* Khung gợi ý tên món */
.ac { position: relative; min-width: 0; }
.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 15;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, .18);
  padding: 6px;
  animation: tipIn .15s ease;
}
.sug {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 46px; padding: 0 12px;
  border: 0; border-radius: 11px; background: transparent;
  cursor: pointer; text-align: left;
  font: 500 1.02rem var(--serif); color: var(--ink);
}
.sug span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sug span:last-child { flex: none; font: .74rem var(--sans); letter-spacing: .04em; color: var(--muted); }
.sug:hover, .sug:active { background: var(--surface-2); }
.picker .chev { transition: none; }

/* Bảng trượt từ dưới lên */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(10, 9, 8, .5);
  opacity: 0; transition: opacity .25s ease;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 560px; margin: 0 auto;
  max-height: 82vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface);
  border-radius: 26px 26px 0 0;
  padding: 8px 18px calc(22px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .25);
  transform: translateY(100%); transition: transform .28s cubic-bezier(.2, .8, .2, 1);
  scrollbar-width: none;
}
.sheet::-webkit-scrollbar { display: none; }
#sheet.show .sheet-backdrop { opacity: 1; }
#sheet.show .sheet { transform: none; }
.sheet-handle { width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 4px auto 14px; cursor: pointer; }
.sheet-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.sheet-legend { font-size: .75rem; display: inline-flex; align-items: center; gap: 5px; }
.ex-group { margin-top: 16px; }
.ex-group .eyebrow { margin-bottom: 8px; }
.ex-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ex-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 14px;
  background: transparent; text-align: left; cursor: pointer;
  font-size: .9rem;
  transition: border-color .15s, background .15s;
}
.ex-opt:active { background: var(--surface-2); }
.ex-opt.on { border-color: var(--gold); background: var(--gold-soft); }
.intensity { display: inline-flex; gap: 3px; flex: none; }
.intensity i { width: 5px; height: 5px; border-radius: 50%; background: var(--line); }
.intensity i.f { background: var(--gold); }
.ex-custom { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: end; }

/* ============ Biểu đồ ============ */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 13px; font-family: var(--sans); }
.chart .col { fill: var(--gold); opacity: .85; }
.chart .col.over { fill: var(--warn); }
.chart .line { fill: none; stroke: var(--gold); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--surface); stroke: var(--gold); stroke-width: 2; }
.chart .goal { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 4 4; opacity: .45; }
.chart .goal-label { fill: var(--muted); font-size: 12px; font-family: var(--sans); }
.chart-foot { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .82rem; color: var(--muted); margin-top: 8px; }
.chart-foot b { color: var(--ink); font-weight: 600; }
.seg-wrap { display: flex; justify-content: center; }

/* ============ Mục tiêu & huy hiệu ============ */
.calc-out {
  margin-top: 16px; padding: 16px; border-radius: 16px; background: var(--surface-2);
  display: grid; gap: 8px;
}
.calc-big { font-family: var(--serif); font-size: 2.2rem; font-weight: 600; line-height: 1; }
.calc-big small { font-family: var(--sans); font-size: .85rem; color: var(--muted); font-weight: 400; }
.kv { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .82rem; color: var(--muted); }
.kv b { color: var(--ink); font-weight: 600; }

.badges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 8px; }
.badge {
  display: grid; justify-items: center; gap: 6px;
  background: none; border: 0; padding: 0; cursor: pointer;
}
.medal {
  width: 54px; height: 54px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--serif); font-weight: 600; font-size: 1.05rem;
  border: 1.5px dashed var(--line); color: var(--muted);
}
.badge.on .medal {
  border: 1.5px solid var(--gold); color: var(--gold); background: var(--gold-soft);
  box-shadow: inset 0 0 0 4px var(--surface), inset 0 0 0 5px var(--gold);
}
.badge-name { font-size: .72rem; font-weight: 600; text-align: center; line-height: 1.25; }
.badge:not(.on) .badge-name { color: var(--muted); font-weight: 400; }

/* ============ Cài đặt ============ */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }
.pin-input {
  width: 100%; max-width: 180px; text-align: center; letter-spacing: .6em; font-size: 1.4rem;
  min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); outline: none;
}
.pin-input:focus { border-color: var(--gold); }
.err { color: var(--warn); font-size: .85rem; min-height: 1.2em; margin: 8px 0 0; }

/* ============ Khóa PIN ============ */
.lock {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: var(--bg);
}
.lock-box { text-align: center; display: grid; justify-items: center; gap: 8px; padding: 16px; }
.lock-box .brand { font-size: 2.2rem; margin-bottom: 4px; }

/* ============ Toast ============ */
.toast {
  position: fixed; left: 50%;
  bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  transform: translate(-50%, 10px);
  max-width: calc(100% - 32px);
  background: var(--ink); color: var(--bg);
  padding: 9px 18px; border-radius: 999px; font-size: .85rem; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
