/* Garmin Health — giao diện tối kiểu WHOOP. Màu kiểm bằng validator dataviz (nền #1A2227). */
:root {
  color-scheme: dark;
  --bg: #0b1013;
  --bg-top: #18232a;
  --card: #161f24;
  --card-2: #1e2a31;
  --line: #2a363e;
  --text: #ffffff;
  --text-2: #b4bec5;
  --text-3: #7d8a93;
  --green: #16ec06;
  --yellow: #ffde00;
  --red: #ff0026;
  --strain: #0a84d6;
  --strain-hi: #3aa7f0;
  --sleep: #a5b4fc;
  --st-awake: #e2e8f0;
  --st-rem: #a5b4fc;
  --st-light: #7b84f4;
  --st-deep: #4f46e5;
  --good: #16ec06;
  --bad: #ff4d61;
  --radius: 14px;
  --gap: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg) radial-gradient(120% 60% at 50% 0%, var(--bg-top) 0%, var(--bg) 70%) no-repeat;
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--strain-hi); outline-offset: 2px; border-radius: 8px; }
a { color: var(--strain-hi); }
.muted { color: var(--text-3); }
.sec { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- khung ---------- */
.app { max-width: 1080px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-bottom: 104px; }
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  padding: 10px 0 8px;
  /* nền mờ tràn hết chiều ngang dù nội dung bị giới hạn bề rộng */
  background: rgba(11, 16, 19, .82); box-shadow: 0 0 0 100vmax rgba(11, 16, 19, .82); clip-path: inset(0 -100vmax);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--text-2); }
.icon-btn:hover { background: var(--card-2); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.datebar { display: flex; align-items: center; justify-content: center; gap: 4px; }
.datebar .label { min-width: 132px; text-align: center; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; font-size: 14px; position: relative; }
.datebar .label small { display: block; font-weight: 500; letter-spacing: .02em; text-transform: none; color: var(--text-3); font-size: 12px; }
.datebar .icon-btn[disabled] { opacity: .25; pointer-events: none; }

.tabs { display: flex; gap: 4px; background: var(--card); border-radius: 999px; padding: 4px; margin: 4px 0 18px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 1 0 auto; padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); white-space: nowrap; }
.tabs button[aria-selected=true] { background: var(--card-2); color: var(--text); }

.bottomnav {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 30;
  width: 100%; max-width: 560px; display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: rgba(11, 16, 19, .86); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
@media (min-width: 600px) { .bottomnav { bottom: 14px; border: 1px solid var(--line); border-radius: 20px; width: calc(100% - 32px); } }
.bottomnav button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; color: var(--text-3); font-size: 11px; font-weight: 600; letter-spacing: .03em; border-radius: 12px; }
.bottomnav button svg { width: 24px; height: 24px; }
.bottomnav button[aria-current=page] { color: var(--text); }

/* ---------- thẻ ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: var(--gap); }
.card h2, .h2 { margin: 0 0 4px; font-size: 13px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--text-2); }
.card .sub { margin: 0 0 12px; color: var(--text-3); font-size: 13px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card-head .toggle { font-size: 12px; color: var(--text-3); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; }
.card-head .toggle:hover { color: var(--text); }
.grid { display: grid; gap: var(--gap); }
@media (min-width: 900px) {
  .grid-2 { grid-template-columns: 1fr 1fr; align-items: start; }
  .grid-2 > .card { margin-bottom: 0; }
  .grid-2 { margin-bottom: var(--gap); }
}
.section-title { font-size: 13px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--text-3); margin: 22px 2px 10px; }

/* ---------- 3 vòng tổng quan ---------- */
.dials { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px auto 18px; max-width: 720px; }
.dial { display: flex; flex-direction: column; align-items: center; gap: 8px; border-radius: 16px; padding: 6px 0 8px; }
.dial:hover { background: rgba(255, 255, 255, .03); }
.dial .name { font-size: 12px; font-weight: 700; letter-spacing: .1em; color: var(--text-2); text-transform: uppercase; }
.dial svg { width: 100%; max-width: 132px; height: auto; overflow: visible; }
.ring-value { font-weight: 800; fill: var(--text); }
.ring-unit { font-weight: 700; fill: var(--text-2); }
.ring-sub { fill: var(--text-3); font-weight: 600; letter-spacing: .06em; }
.ring-anim { animation: ring-fill .6s ease-out; }   /* reduced-motion: tắt bởi luật chung cuối file */
@keyframes ring-fill { from { stroke-dashoffset: var(--ring-c); } }

.hero { display: grid; justify-items: center; text-align: center; padding: 6px 0 4px; }
.hero svg { width: 220px; max-width: 70vw; height: auto; overflow: visible; }
.hero .zone-label { margin-top: 10px; font-size: 13px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; display: inline-flex; gap: 6px; align-items: center; }
.hero .msg { margin: 6px auto 0; max-width: 420px; color: var(--text-2); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* coach */
.coach { display: grid; gap: 10px; }
.coach .line { display: flex; align-items: center; gap: 10px; }
.coach .big { font-size: 17px; font-weight: 700; }
.progress { position: relative; height: 10px; background: var(--card-2); border-radius: 999px; }
.progress .band { position: absolute; top: -3px; bottom: -3px; border-radius: 4px; background: rgba(58, 167, 240, .25); border: 1px solid rgba(58, 167, 240, .6); }
.progress .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--strain); }
.progress-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-3); margin-top: 6px; }

/* danh sách hoạt động */
.acts { display: grid; gap: 8px; }
.act { display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 12px; padding: 10px; background: var(--card-2); border-radius: 12px; text-align: left; width: 100%; }
.act .badge { width: 52px; height: 52px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; font-size: 17px; color: #fff; }
.act .badge.strain { background: var(--strain); }
.act .badge.sleep { background: var(--st-deep); }
.act .badge.none { background: var(--line); color: var(--text-3); }
.act .title { font-weight: 700; }
.act .meta { color: var(--text-3); font-size: 13px; }
.act .right { text-align: right; font-size: 13px; color: var(--text-2); }

/* bảng chỉ số chính */
.stats { display: grid; }
.stat-row { display: grid; grid-template-columns: 1fr auto 92px; gap: 10px; align-items: center; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.stat-row:last-child { border-bottom: 0; }
.stat-row .label { color: var(--text-2); font-size: 14px; }
.stat-row .value { font-weight: 700; font-size: 18px; text-align: right; }
.stat-row .value small { font-size: 12px; color: var(--text-3); font-weight: 600; margin-left: 2px; }
.stat-row .base { text-align: right; font-size: 12px; color: var(--text-3); line-height: 1.2; white-space: nowrap; }
.trend { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; font-size: 12px; }
.trend.good { color: var(--good); }
.trend.bad { color: var(--bad); }
.trend.flat { color: var(--text-3); }

/* tile */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .tiles.t4 { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--card-2); border-radius: 12px; padding: 12px; }
.tile .k { font-size: 12px; color: var(--text-3); font-weight: 600; letter-spacing: .03em; }
.tile .v { font-size: 24px; font-weight: 800; margin-top: 2px; }
.tile .v small { font-size: 13px; color: var(--text-3); font-weight: 700; margin-left: 2px; }
.tile .d { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* đóng góp recovery */
.contrib { display: grid; grid-template-columns: 1fr auto 64px; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.contrib:last-child { border-bottom: 0; }
.contrib .pts { text-align: right; font-weight: 800; }
.contrib .pts.good { color: var(--good); }
.contrib .pts.bad { color: var(--bad); }
.contrib .what { font-weight: 600; }
.contrib .why { font-size: 12px; color: var(--text-3); }
.contrib .val { text-align: right; font-weight: 700; }

/* nhu cầu ngủ */
.need-row { display: flex; justify-content: space-between; padding: 7px 0; color: var(--text-2); }
.need-row.total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; color: var(--text); font-weight: 800; }
.need-row b { color: var(--text); font-variant-numeric: tabular-nums; }

/* thanh xếp chồng */
.stack { display: flex; gap: 2px; height: 14px; border-radius: 4px; overflow: hidden; margin: 6px 0 12px; }
.stack > span { display: block; height: 100%; min-width: 2px; }
.legend { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 16px; }
@media (min-width: 560px) { .legend.l4 { grid-template-columns: repeat(4, 1fr); } }
.legend .item { display: grid; grid-template-columns: 12px 1fr; column-gap: 8px; align-items: center; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; }
.legend .item .k { font-size: 13px; color: var(--text-2); }
.legend .item .v { grid-column: 2; font-weight: 700; font-variant-numeric: tabular-nums; }
.legend .item .v small { color: var(--text-3); font-weight: 600; margin-left: 4px; }

/* vùng tim */
.zones { display: grid; gap: 8px; }
.zone { display: grid; grid-template-columns: 70px 1fr 54px; gap: 10px; align-items: center; font-size: 13px; }
.zone .bar { height: 10px; background: var(--card-2); border-radius: 999px; overflow: hidden; }
.zone .bar span { display: block; height: 100%; border-radius: 999px; }
.zone .t { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.zone .n { color: var(--text-2); }

/* planner */
.planner { display: grid; gap: 8px; }
.plan { display: grid; grid-template-columns: 1fr auto; padding: 12px; background: var(--card-2); border-radius: 12px; align-items: center; }
.plan .t { font-size: 22px; font-weight: 800; }
.plan .l { font-weight: 700; }
.plan .s { font-size: 12px; color: var(--text-3); }

/* health monitor */
.hm-head { display: flex; align-items: center; gap: 12px; }
.hm-head .big { font-size: 28px; font-weight: 800; }
.hm { display: grid; gap: 10px; }
.hm-card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; }
.hm-card .top { display: flex; justify-content: space-between; align-items: center; }
.hm-card .name { font-weight: 700; color: var(--text-2); font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
.hm-card .state { font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }
.hm-card .state.in { color: var(--good); }
.hm-card .state.out { color: var(--yellow); }
.hm-card .state.fav { color: var(--good); }
.hm-card .val { font-size: 30px; font-weight: 800; margin: 2px 0 6px; }
.hm-card .val small { font-size: 14px; color: var(--text-3); margin-left: 3px; }
.rangebar { position: relative; height: 26px; margin: 4px 0 2px; }
.rangebar .track { position: absolute; left: 0; right: 0; top: 11px; height: 4px; background: var(--card-2); border-radius: 999px; }
.rangebar .ok { position: absolute; top: 9px; height: 8px; background: rgba(22, 236, 6, .28); border-radius: 999px; }
.rangebar .pin { position: absolute; top: 5px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; border: 3px solid var(--card); }
.rangebar-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-3); }

/* journal */
.q { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.q:last-child { border-bottom: 0; }
.seg { display: inline-flex; background: var(--card-2); border-radius: 999px; padding: 3px; }
.seg button { padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--text-3); }
.seg button[aria-pressed=true] { background: var(--text); color: #0b1013; }
.impact { display: grid; grid-template-columns: 1.4fr 1fr 56px; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.impact:last-child { border-bottom: 0; }
.impact .lbl { font-weight: 600; }
.impact .lbl small { display: block; font-weight: 500; color: var(--text-3); font-size: 12px; }
.impact .bar { position: relative; height: 12px; }
.impact .bar .mid { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--line); }
.impact .bar span { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.impact .v { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 7px; margin-left: 6px; vertical-align: 1px; }
.pill.sig { background: rgba(255, 255, 255, .1); color: var(--text); }

/* bộ lọc khoảng ngày */
.range { display: inline-flex; background: var(--card); border-radius: 999px; padding: 4px; margin: 4px 0 14px; }
.range button { padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--text-3); }
.range button[aria-pressed=true] { background: var(--card-2); color: var(--text); }

/* bảng */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th { text-align: right; color: var(--text-3); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.data td { text-align: right; padding: 7px 4px; border-bottom: 1px solid var(--line); }
table.data th:first-child, table.data td:first-child { text-align: left; }
.table-scroll { overflow-x: auto; max-height: 340px; overflow-y: auto; }

/* biểu đồ */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .bar-mark:hover, .chart .bar-mark.active { filter: brightness(1.25); }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: #0b1013; border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; font-size: 12px; min-width: 120px; box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  opacity: 0; transition: opacity .1s;
}
.tooltip.show { opacity: 1; }
.tooltip .tt-title { color: var(--text-3); margin-bottom: 4px; }
.tooltip .tt-row { display: grid; grid-template-columns: 14px 1fr auto; gap: 6px; align-items: center; }
.tooltip .tt-row b { font-size: 14px; color: var(--text); text-align: right; }
.tooltip .tt-row .key { width: 12px; height: 2px; border-radius: 1px; }
.tooltip .tt-row .lbl { color: var(--text-2); }

.sample-note { display: flex; justify-content: center; margin: 0 0 10px; }
.sample-note span { font-size: 12px; color: var(--text-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px; }
/* trạng thái, toast, sheet */
.toast { position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); z-index: 60; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; font-size: 13px; max-width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(0, 0, 0, .5); }
.toast[hidden] { display: none; }
.toast .bar { height: 3px; background: var(--line); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.toast .bar span { display: block; height: 100%; background: var(--strain-hi); transition: width .3s; }
.empty { text-align: center; padding: 48px 16px; }
.empty h1 { font-size: 22px; margin: 0 0 8px; }
.empty code, .help code { background: var(--card-2); border-radius: 6px; padding: 2px 6px; font-size: 13px; }
.empty ol { text-align: left; display: inline-block; color: var(--text-2); }
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 70; display: grid; place-items: end center; }
.sheet-backdrop[hidden] { display: none; }
.sheet { width: 100%; max-width: 560px; background: var(--card); border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto; }
@media (min-width: 600px) { .sheet-backdrop { place-items: center; } .sheet { border-radius: 20px; } }
.sheet h2 { margin: 0 0 14px; font-size: 18px; }
.field { display: grid; gap: 4px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--text-2); font-weight: 600; }
.field input, .field select { background: var(--card-2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 10px 12px; font: inherit; }
.field .hint { font-size: 12px; color: var(--text-3); }
.btn { background: var(--text); color: #0b1013; font-weight: 800; border-radius: 999px; padding: 11px 18px; }
.btn.ghost { background: var(--card-2); color: var(--text); }
.row-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.note { font-size: 12px; color: var(--text-3); margin-top: 8px; }
.info { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--text-2); }
.loading { opacity: .5; transition: opacity .2s; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
/* trang đăng nhập (login.html) */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding-bottom: 0; }
.login form { width: 100%; max-width: 360px; padding: 24px 20px; display: grid; justify-items: center; }
.login h1 { margin: 10px 0 20px; font-size: 20px; }
.login .field { width: 100%; }
.login .btn { width: 100%; }
.login .note { min-height: 1.4em; margin-bottom: 0; text-align: center; }
