/* 運動 App 風格：亮橘色重點、淺灰底、白色卡片、粗體大數字、底部分頁列 */

:root {
  color-scheme: light;
  --bg: #f2f2f4;
  --card: #ffffff;
  --line: #e2e2e7;
  --text: #242428;
  --text-2: #6d6d78;
  --text-3: #85858f;
  --orange: #fc5200;          /* 圖表線條、圓點、強調色塊 */
  --orange-ink: #cc4100;      /* 白底上的橘色文字（對比 4.9:1） */
  --orange-btn: #cc4100;      /* 按鈕、徽章：上面放白字 */
  --orange-soft: #fff0e8;
  --series: #fc5200;
  --band: #ececf0;
  --rule: #6d6d78;
  --good: #1a8a4a;
  --warn: #8f5b00;
  --warn-bg: #fff6e0;
  --bad: #c62828;
  --bad-bg: #fdecea;
  --tab-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f0f10;
    --card: #1c1c1f;
    --line: #2f2f34;
    --text: #f4f4f6;
    --text-2: #a9a9b3;
    --text-3: #8b8b95;
    --orange: #ff6a1f;
    --orange-ink: #ff8a4c;
    --orange-btn: #cc4100;
    --orange-soft: #3a1f12;
    --series: #ff6a1f;
    --band: #2c2c31;
    --rule: #a9a9b3;
    --good: #5fd08e;
    --warn: #f3c25a;
    --warn-bg: #3a2f14;
    --bad: #ff8a80;
    --bad-bg: #3d1f1c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f10;
  --card: #1c1c1f;
  --line: #2f2f34;
  --text: #f4f4f6;
  --text-2: #a9a9b3;
  --text-3: #8b8b95;
  --orange: #ff6a1f;
  --orange-ink: #ff8a4c;
  --orange-btn: #cc4100;
  --orange-soft: #3a1f12;
  --series: #ff6a1f;
  --band: #2c2c31;
  --rule: #a9a9b3;
  --good: #5fd08e;
  --warn: #f3c25a;
  --warn-bg: #3a2f14;
  --bad: #ff8a80;
  --bad-bg: #3d1f1c;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- 頂部列 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.topbar-inner { max-width: 720px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; letter-spacing: -0.02em; color: var(--orange-ink); }
.brand svg { width: 22px; height: 22px; color: var(--orange); }
.updated { color: var(--text-3); font-size: 12px; text-align: right; line-height: 1.3; }
.view-title { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; margin: 18px 4px 0; }

main { max-width: 720px; margin: 0 auto; padding: 0 0 calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px); }
.view { padding: 0 12px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  margin: 12px 0;
  box-shadow: 0 1px 0 var(--line);
}
.section-label { font-size: 13px; font-weight: 700; color: var(--text-2); letter-spacing: 0.04em; margin: 22px 4px 0; }
.card h3 { font-size: 17px; font-weight: 700; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.card h3 svg { width: 20px; height: 20px; color: var(--orange); flex: none; }
.card p { margin: 0 0 10px; }
.card ul { margin: 0; padding-left: 0; list-style: none; }
.card li { position: relative; padding: 8px 0 8px 18px; border-top: 1px solid var(--line); }
.card li:first-child { border-top: 0; }
.card li::before { content: ""; position: absolute; left: 2px; top: 17px; width: 6px; height: 6px; border-radius: 50%; background: var(--orange); }

/* 動態卡片的頭（圖示 + 標題 + 副標） */
.feed-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  background: var(--orange-soft); color: var(--orange-ink);
  display: grid; place-items: center;
}
.avatar svg { width: 22px; height: 22px; }
.feed-title { font-weight: 700; font-size: 16px; line-height: 1.3; }
.feed-sub { color: var(--text-3); font-size: 13px; line-height: 1.3; }
.feed-head .badge { margin-left: auto; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--orange-btn); color: #fff; white-space: nowrap;
}
.badge.soft { background: var(--orange-soft); color: var(--orange-ink); }

/* 數字列：小標在上、粗體大數字在下，中間細分隔線 */
.stats { display: grid; grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)); margin: 4px 0 12px; }
.stat { padding: 0 10px; border-left: 1px solid var(--line); min-width: 0; }
.stat:first-child { padding-left: 0; border-left: 0; }
.stat .k { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.stat .v { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.25; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat .v small { font-size: 12px; font-weight: 600; color: var(--text-2); margin-left: 2px; letter-spacing: 0; }
@media (max-width: 380px) { .stat .v { font-size: 19px; } .stat { padding: 0 6px; } }

/* 今天身體數據：兩欄格子 */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 16px; }
@media (min-width: 600px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.tile { padding: 12px 0; border-top: 1px solid var(--line); }
.tiles .tile:nth-child(-n+2) { border-top: 0; padding-top: 0; }
@media (min-width: 600px) { .tiles .tile:nth-child(3) { border-top: 0; padding-top: 0; } }
.tile .k { font-size: 13px; color: var(--text-2); }
.tile .v { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile .v small { font-size: 13px; font-weight: 600; color: var(--text-2); margin-left: 2px; }
.tile .d { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.tile .d.up { color: var(--good); }
.tile .d.down { color: var(--bad); }

.summary { font-size: 15px; margin: 0; }
.avoid { margin-top: 12px; background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.meta { color: var(--text-3); font-size: 12px; margin: 4px 4px 0; }

details.card summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; align-items: center; gap: 8px; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary svg { width: 20px; height: 20px; color: var(--warn); }
details.card summary::after { content: "›"; margin-left: auto; font-size: 22px; line-height: 1; color: var(--text-3); transition: transform .2s; }
details.card[open] summary::after { transform: rotate(90deg); }
details.card[open] summary { margin-bottom: 8px; }

.notice { padding: 10px 14px; border-radius: 10px; margin: 12px 0 0; font-size: 14px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }

/* ---------- 趨勢圖 ---------- */
.chart h3 { margin-bottom: 0; }
.chart .now { font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
.chart .now b { color: var(--text); font-size: 20px; font-weight: 800; margin-right: 2px; font-variant-numeric: tabular-nums; }
.chart canvas { width: 100% !important; height: 180px !important; }
.chart .meta { margin: 6px 0 0; }

/* ---------- 活動動態 ---------- */
.week .stats { --cols: 3; margin-bottom: 0; }
.day-label { font-size: 13px; font-weight: 700; color: var(--text-2); margin: 20px 4px 0; }
.act .feed-head { margin-bottom: 10px; }
.act .stats { --cols: 3; margin-bottom: 0; }
.act .effects { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--text-2); }
.act .effects b { color: var(--text); font-variant-numeric: tabular-nums; }
.empty { color: var(--text-3); text-align: center; padding: 32px 0; }

/* ---------- 問教練 ---------- */
#view-coach { padding-bottom: 90px; }
.chat-log { display: flex; flex-direction: column; gap: 10px; padding: 12px 0; }
.chat-log:empty { display: none; }
.msg { padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; max-width: 88%; font-size: 15px; }
.msg.user { align-self: flex-end; background: var(--orange-btn); color: #fff; border-bottom-right-radius: 6px; }
.msg.coach { align-self: flex-start; background: var(--card); border-bottom-left-radius: 6px; box-shadow: 0 1px 0 var(--line); }
.msg.coach.thinking { color: var(--text-3); }
.msg.error { color: var(--bad); }
.coach-intro { text-align: center; padding: 28px 12px 4px; color: var(--text-2); font-size: 14px; }
.coach-intro .avatar { width: 60px; height: 60px; margin: 0 auto 10px; }
.coach-intro .avatar svg { width: 30px; height: 30px; }
.coach-intro b { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 12px 0 8px; }
.chips button {
  font-size: 14px; padding: 8px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--orange-ink); background: var(--card); color: var(--orange-ink); font-weight: 600;
}
.chat-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--text-3); font-size: 12px; padding: 4px 4px 0; }
.link { background: none; border: 0; color: var(--text-3); font-size: 12px; text-decoration: underline; padding: 4px 0; cursor: pointer; }
.composer {
  position: fixed; left: 0; right: 0; z-index: 9;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
  padding: 8px 12px;
}
.composer form { max-width: 696px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; font: inherit; font-size: 16px; line-height: 1.4; padding: 9px 14px; resize: none; max-height: 120px;
  border: 1px solid var(--line); border-radius: 20px; background: var(--bg); color: var(--text);
}
.composer textarea:focus { outline: 2px solid var(--orange); outline-offset: -1px; }
#chat-send {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--orange-btn); color: #fff; display: grid; place-items: center;
}
#chat-send:disabled { opacity: .45; }
#chat-send svg { width: 20px; height: 20px; }

/* ---------- 底部分頁列 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar-inner { max-width: 720px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); height: var(--tab-h); }
.tab {
  background: none; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-3); font-size: 11px; font-weight: 600; cursor: pointer;
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--orange-ink); }

/* ---------- 登入頁 ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; background: var(--card); border-radius: 16px; padding: 28px 24px; box-shadow: 0 1px 0 var(--line); }
.login .brand { justify-content: center; font-size: 26px; margin-bottom: 4px; }
.login .brand svg { width: 28px; height: 28px; }
.login .sub { text-align: center; color: var(--text-2); font-size: 14px; margin-bottom: 18px; }
.login input {
  width: 100%; font-size: 17px; padding: 12px 14px; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
}
.login input:focus { outline: 2px solid var(--orange); outline-offset: -1px; }
.login button {
  width: 100%; font-size: 17px; padding: 12px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--orange-btn); color: #fff; font-weight: 700; margin-top: 4px;
}
.login .error { color: var(--bad); min-height: 1.6em; font-size: 14px; }
.stats.macros { grid-template-columns: 1.35fr repeat(3, minmax(0, 1fr)); }

/* ---------- 優化（第二版）---------- */

/* 今日建議：一句話重點 + 恢復狀態 */
.headline { font-size: 21px; line-height: 1.35; font-weight: 800; letter-spacing: -0.01em; margin: 2px 0 8px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 3px 10px 3px 8px; border-radius: 999px; margin-bottom: 12px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.good { color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent); }
.status.warn { color: var(--warn); background: var(--warn-bg); }
.status.bad { color: var(--bad); background: var(--bad-bg); }

/* 長文字摺疊 */
.clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: var(--lines, 3); overflow: hidden; }
.clamp.open { display: block; -webkit-line-clamp: unset; }
.clamp p { margin: 0; }
.more { background: none; border: 0; padding: 6px 0 0; color: var(--orange-ink); font-size: 14px; font-weight: 600; cursor: pointer; }
.why { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 14px; color: var(--text-2); }
.why b { color: var(--text); }

/* 步數目標進度條 */
.progress { height: 6px; border-radius: 3px; background: var(--band); overflow: hidden; margin: 6px 0 4px; }
.progress span { display: block; height: 100%; border-radius: 3px; background: var(--orange); }
.tiles-note { margin: 10px 0 0; font-size: 12px; color: var(--text-3); }

/* 載入中的骨架畫面 */
.skeleton .sk { background: var(--band); border-radius: 6px; margin-bottom: 10px; animation: pulse 1.4s ease-in-out infinite; }
.sk-title { height: 24px; width: 60%; }
.sk-line { height: 14px; width: 100%; }
.sk-line.short { width: 70%; }
.sk-stats { height: 44px; width: 100%; margin: 14px 0; }
@keyframes pulse { 50% { opacity: .45; } }

/* 教練思考中：跳動的三個點 */
.msg.coach.thinking::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* 鍵盤打開時：藏起分頁列，輸入框貼著鍵盤 */
body.typing .tabbar { display: none; }
body.typing .composer { bottom: 0; padding-bottom: 8px; }

/* 鍵盤操作時看得到焦點 */
:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; border-radius: 6px; }
.tab:focus-visible { outline-offset: -4px; }

/* 一天的活動總結 */
.day-label .sum { font-weight: 500; color: var(--text-3); }

/* 趨勢圖：Garmin 狀態小標籤 */
.chip { display: inline-block; font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; margin-left: 6px; vertical-align: 2px; }
.chip.good { color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent); }
.chip.warn { color: var(--warn); background: var(--warn-bg); }
.chip.bad { color: var(--bad); background: var(--bad-bg); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
/* 標題換行平均一點，不會剩一個字掛在第二行；副標只佔一行 */
.headline { text-wrap: balance; }
.hero .feed-sub { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; overflow: hidden; }

/* 問教練：附照片 */
#chat-photo {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--bg); color: var(--text-2); display: grid; place-items: center;
}
#chat-photo svg { width: 22px; height: 22px; }
.attach { max-width: 696px; margin: 0 auto 8px; position: relative; width: fit-content; }
.attach img { display: block; height: 72px; border-radius: 10px; border: 1px solid var(--line); }
.attach button {
  position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--card); background: var(--text); color: var(--card); font-size: 16px; line-height: 1; cursor: pointer;
}
.msg-img { display: block; max-width: 220px; max-height: 260px; border-radius: 12px; margin-bottom: 6px; }
.msg.user.has-img { background: none; padding: 0; color: var(--text); }
.msg.user.has-img .msg-text { background: var(--orange-btn); color: #fff; padding: 10px 14px; border-radius: 18px; border-bottom-right-radius: 6px; display: inline-block; }
.msg.user.has-img { display: flex; flex-direction: column; align-items: flex-end; }

/* 有附照片預覽時輸入區變高，對話底部多留一點空間 */
body:has(#attach:not([hidden])) #view-coach { padding-bottom: 180px; }
