/* ═══════════════ 血糖紀錄簿 — 長輩友善樣式 ═══════════════ */

:root{
  --bg:        #f1f5f4;
  --card:      #ffffff;
  --ink:       #16211f;
  --ink-soft:  #5a6b68;
  --line:      #d5e0dd;
  --brand:     #0f766e;
  --brand-dk:  #0b5c56;

  --good:      #15803d;
  --good-bg:   #dcfce7;
  --high:      #b45309;
  --high-bg:   #fef3c7;
  --veryhigh:  #b91c1c;
  --veryhigh-bg:#fee2e2;
  --low:       #b91c1c;
  --low-bg:    #fee2e2;

  --tap: 64px;                    /* 最小可點擊高度 */
  --radius: 16px;
}

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

html{ font-size:20px; }           /* 全站基準字級：偏大 */

body{
  margin:0;
  padding:0 0 calc(96px + env(safe-area-inset-bottom));
  background:var(--bg);
  color:var(--ink);
  font-family:"Noto Sans TC","PingFang TC","Microsoft JhengHei",
              -apple-system,"Segoe UI",sans-serif;
  font-size:1rem;
  line-height:1.6;
  -webkit-text-size-adjust:100%;
}

button,input{ font-family:inherit; font-size:inherit; color:inherit; }
button{ cursor:pointer; border:none; background:none; }
.hidden{ display:none !important; }

/* ─────────── 頁首 ─────────── */
.topbar{
  background:var(--brand);
  color:#fff;
  padding:calc(14px + env(safe-area-inset-top)) 20px 14px;
  text-align:center;
  position:sticky; top:0; z-index:20;
}
.topbar h1{ margin:0; font-size:1.5rem; font-weight:800; letter-spacing:2px; }
.today{ font-size:1rem; opacity:.92; margin-top:2px; }

/* 聲音開關：放在頁首右上角，不佔版面但好按 */
.sound-toggle{
  position:absolute; top:50%; right:8px; transform:translateY(-25%);
  width:56px; height:56px;
  font-size:1.6rem; line-height:1;
  border-radius:14px; color:#fff;
}
.sound-toggle:active{ background:rgba(255,255,255,.2); }
.sound-toggle.is-off{ opacity:.55; }

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

/* ─────────── 數值顯示 ─────────── */
.readout{
  background:var(--card);
  border:3px solid var(--line);
  border-radius:var(--radius);
  padding:18px 16px 12px;
  text-align:center;
  margin-bottom:18px;
  transition:border-color .2s, background .2s;
}
.readout-num{
  font-size:4.6rem;
  font-weight:800;
  line-height:1;
  letter-spacing:2px;
  font-variant-numeric:tabular-nums;
  color:var(--ink);
}
.readout-num.is-empty{ color:#b9c7c4; }
.readout-unit{ font-size:1.05rem; color:var(--ink-soft); margin-top:6px; font-weight:600; }

.readout.lv-good     { border-color:var(--good);     background:var(--good-bg); }
.readout.lv-good     .readout-num{ color:var(--good); }
.readout.lv-high     { border-color:var(--high);     background:var(--high-bg); }
.readout.lv-high     .readout-num{ color:var(--high); }
.readout.lv-veryhigh { border-color:var(--veryhigh); background:var(--veryhigh-bg); }
.readout.lv-veryhigh .readout-num{ color:var(--veryhigh); }
.readout.lv-low      { border-color:var(--low);      background:var(--low-bg); }
.readout.lv-low      .readout-num{ color:var(--low); }

/* ─────────── 區塊 ─────────── */
.block{ margin-bottom:18px; }
.block-title{
  font-size:1.15rem; font-weight:800; margin:0 0 10px 2px; color:var(--ink);
  display:flex; align-items:center; gap:8px;
}
.block-title b{
  display:inline-flex; align-items:center; justify-content:center;
  width:30px; height:30px; flex:none;
  border-radius:50%; background:var(--brand); color:#fff;
  font-size:1rem; font-weight:800;
}

/* ─────────── 時段按鈕 ─────────── */
.period-main{
  display:grid; grid-template-columns:repeat(2,1fr); gap:12px;
}
.period-btn.period-big{
  min-height:96px;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2px;
  font-size:1.5rem;
}
.period-btn.period-big small{ font-size:.85rem; font-weight:600; opacity:.75; }

/* 其他不常用的時段，預設收起來 */
.period-grid{
  display:grid; grid-template-columns:repeat(2,1fr); gap:10px; margin-top:10px;
}
.period-btn{
  min-height:var(--tap);
  border:3px solid var(--line);
  border-radius:14px;
  background:var(--card);
  font-size:1.2rem; font-weight:700;
  color:var(--ink-soft);
  transition:transform .08s;
}
.period-btn:active{ transform:scale(.96); }
.period-btn.is-on{
  background:var(--brand); border-color:var(--brand-dk); color:#fff;
  box-shadow:0 4px 0 var(--brand-dk);
}

/* ─────────── 數字鍵盤 ─────────── */
.keypad{ display:grid; grid-template-columns:repeat(3,1fr); gap:10px; }
.key{
  min-height:72px;
  border:3px solid var(--line);
  border-radius:14px;
  background:var(--card);
  font-size:2rem; font-weight:800;
  box-shadow:0 3px 0 var(--line);
  transition:transform .06s, box-shadow .06s;
}
.key:active{ transform:translateY(3px); box-shadow:none; background:#eef4f3; }
.key-fn{ font-size:1.2rem; font-weight:700; color:var(--ink-soft); background:#e9eeed; }

/* ─────────── 儲存 ─────────── */
.save-btn{
  display:block; width:100%;
  min-height:78px;
  margin:22px 0 10px;
  border-radius:16px;
  background:var(--brand);
  color:#fff;
  font-size:1.7rem; font-weight:800; letter-spacing:4px;
  box-shadow:0 5px 0 var(--brand-dk);
  transition:transform .08s, box-shadow .08s;
}
.save-btn:active{ transform:translateY(5px); box-shadow:none; }
.save-btn:disabled{ background:#b6c4c2; box-shadow:0 5px 0 #9aa8a6; }

.link-btn{
  display:block; width:100%;
  padding:14px 8px;
  color:var(--brand); font-size:1rem; font-weight:700;
  text-decoration:underline; text-underline-offset:4px;
}
.timebox{
  background:var(--card); border:3px solid var(--line);
  border-radius:var(--radius); padding:14px; margin-bottom:10px;
}
.timebox label{
  display:flex; align-items:center; gap:12px;
  font-size:1.1rem; font-weight:700; margin-bottom:12px;
}
.timebox input{
  flex:1; min-height:56px; padding:8px 12px;
  border:3px solid var(--line); border-radius:12px;
  background:#fff; font-size:1.2rem; font-weight:700;
}

/* ─────────── 歷史紀錄 ─────────── */
.day-head{
  font-size:1.2rem; font-weight:800;
  margin:20px 2px 8px;
  color:var(--ink-soft);
  border-bottom:3px solid var(--line);
  padding-bottom:6px;
}
.day-head:first-child{ margin-top:0; }

.rec{
  display:flex; align-items:center; gap:12px;
  background:var(--card);
  border:3px solid var(--line);
  border-left-width:12px;
  border-radius:14px;
  padding:12px 10px 12px 14px;
  margin-bottom:10px;
}
.rec.lv-good     { border-left-color:var(--good); }
.rec.lv-high     { border-left-color:var(--high); }
.rec.lv-veryhigh { border-left-color:var(--veryhigh); }
.rec.lv-low      { border-left-color:var(--low); }

.rec-when{ flex:1; min-width:0; }
.rec-period{ font-size:1.2rem; font-weight:800; }
.rec-time{ font-size:.95rem; color:var(--ink-soft); font-weight:600; }
.rec-value{
  font-size:2.2rem; font-weight:800; line-height:1;
  font-variant-numeric:tabular-nums;
}
.rec.lv-good     .rec-value{ color:var(--good); }
.rec.lv-high     .rec-value{ color:var(--high); }
.rec.lv-veryhigh .rec-value{ color:var(--veryhigh); }
.rec.lv-low      .rec-value{ color:var(--low); }

.rec-tag{
  font-size:.9rem; font-weight:800; padding:4px 10px; border-radius:999px;
  white-space:nowrap;
}
.lv-good     .rec-tag{ background:var(--good-bg);     color:var(--good); }
.lv-high     .rec-tag{ background:var(--high-bg);     color:var(--high); }
.lv-veryhigh .rec-tag{ background:var(--veryhigh-bg); color:var(--veryhigh); }
.lv-low      .rec-tag{ background:var(--low-bg);      color:var(--low); }

.rec-del{
  width:52px; height:52px; flex:none;
  border-radius:12px; background:#f0f4f3;
  font-size:1.3rem; color:var(--ink-soft);
}
.rec-del:active{ background:var(--veryhigh-bg); }

.empty{
  text-align:center; padding:60px 20px; color:var(--ink-soft); font-size:1.15rem;
}

/* ─────────── 趨勢 ─────────── */
.range-tabs{ display:grid; grid-template-columns:repeat(3,1fr); gap:10px; margin-bottom:16px; }
.range-btn{
  min-height:56px; border:3px solid var(--line); border-radius:14px;
  background:var(--card); font-size:1.05rem; font-weight:700; color:var(--ink-soft);
}
.range-btn.is-on{ background:var(--brand); border-color:var(--brand-dk); color:#fff; }

.stat-grid{ display:grid; grid-template-columns:repeat(2,1fr); gap:10px; margin-bottom:18px; }
.stat{
  background:var(--card); border:3px solid var(--line);
  border-radius:14px; padding:14px 10px; text-align:center;
}
.stat-label{ font-size:.95rem; color:var(--ink-soft); font-weight:700; }
.stat-num{
  font-size:2.3rem; font-weight:800; line-height:1.2;
  font-variant-numeric:tabular-nums;
}
.stat-unit{ font-size:.85rem; color:var(--ink-soft); font-weight:600; }
.stat.is-good .stat-num{ color:var(--good); }
.stat.is-high .stat-num{ color:var(--high); }
.stat.is-veryhigh .stat-num{ color:var(--veryhigh); }

.chart-card{
  background:var(--card); border:3px solid var(--line);
  border-radius:var(--radius); padding:16px 12px; margin-bottom:18px;
}
.chart-card svg{ display:block; width:100%; height:auto; }
.chart-legend{ font-size:.9rem; color:var(--ink-soft); margin-top:8px; font-weight:600; }
.sw{ display:inline-block; width:16px; height:16px; border-radius:4px;
     vertical-align:-3px; margin-right:6px; }
.sw-band{ background:var(--good-bg); border:2px solid var(--good); }

.export-btn{
  display:block; text-align:center; text-decoration:none;
  min-height:70px; line-height:64px;
  border:3px solid var(--brand); border-radius:16px;
  background:var(--card); color:var(--brand);
  font-size:1.2rem; font-weight:800;
}
.export-btn:active{ background:#e0f2f0; }

.disclaimer{
  text-align:center; font-size:.9rem; color:var(--ink-soft);
  line-height:1.7; margin:20px 0 10px;
}

/* ─────────── 底部分頁 ─────────── */
.tabbar{
  position:fixed; left:0; right:0; bottom:0; z-index:30;
  display:grid; grid-template-columns:repeat(3,1fr);
  background:var(--card);
  border-top:3px solid var(--line);
  padding-bottom:env(safe-area-inset-bottom);
}
.tab{
  padding:8px 4px 10px;
  font-size:1rem; font-weight:800; color:var(--ink-soft);
  display:flex; flex-direction:column; align-items:center; gap:2px;
  min-height:76px; justify-content:center;
}
.tab span{ font-size:1.6rem; line-height:1; }
.tab.is-on{ color:var(--brand); background:#e6f2f0; }

/* ─────────── 彈出視窗 ─────────── */
.toast-mask{
  position:fixed; inset:0; z-index:50;
  background:rgba(12,26,24,.55);
  display:flex; align-items:center; justify-content:center; padding:24px;
}
.toast{
  background:#fff; border-radius:22px; padding:28px 22px 22px;
  text-align:center; width:100%; max-width:380px;
  box-shadow:0 20px 50px rgba(0,0,0,.3);
  animation:pop .18s ease-out;
}
@keyframes pop{ from{ transform:scale(.9); opacity:0 } to{ transform:scale(1); opacity:1 } }
.toast-icon{ font-size:3.2rem; line-height:1; }
.toast-value{
  font-size:3.6rem; font-weight:800; line-height:1.1; margin-top:6px;
  font-variant-numeric:tabular-nums;
}
.toast-label{ font-size:1.6rem; font-weight:800; margin-top:4px; }
.toast-msg{ font-size:1.05rem; color:var(--ink-soft); margin-top:10px; line-height:1.6; }
.toast.lv-good     .toast-value,.toast.lv-good     .toast-label{ color:var(--good); }
.toast.lv-high     .toast-value,.toast.lv-high     .toast-label{ color:var(--high); }
.toast.lv-veryhigh .toast-value,.toast.lv-veryhigh .toast-label{ color:var(--veryhigh); }
.toast.lv-low      .toast-value,.toast.lv-low      .toast-label{ color:var(--low); }

.ai-box{
  padding:16px; margin-bottom:18px;
  background:var(--card); border:3px solid var(--brand); border-radius:var(--radius);
  text-align:left;
}
.ai-box .link-btn{ padding:10px 8px 2px; text-align:left; }
.ai-head{ font-size:1rem; font-weight:800; color:var(--brand); margin-bottom:8px; }
.ai-text{ font-size:1.15rem; line-height:1.8; color:var(--ink); }
.ai-text.is-wait{ color:var(--ink-soft); }
.ai-dots::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:'...'} }

.toast-close{
  width:100%; min-height:64px; margin-top:18px;
  border-radius:14px; background:var(--brand); color:#fff;
  font-size:1.3rem; font-weight:800; letter-spacing:2px;
}
.confirm-row{ display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-top:20px; }
.btn-cancel,.btn-danger{
  min-height:64px; border-radius:14px; font-size:1.2rem; font-weight:800;
}
.btn-cancel{ background:#e9eeed; color:var(--ink); }
.btn-danger{ background:var(--veryhigh); color:#fff; }

/* ─────────── 小螢幕微調 ─────────── */
@media (max-width:360px){
  html{ font-size:18px; }
  .readout-num{ font-size:3.8rem; }
  .key{ min-height:64px; }
}
