:root {
  --indigo: #4f46e5;
  --purple: #7c3aed;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e8edf3;
  --bg: #eef2f7;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
}

/* 手機優先：內容置中、限制為直式手機寬度（9:16 舒適） */
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.topbar {
  background: linear-gradient(135deg, var(--indigo), var(--purple));
  color: #fff;
  padding: calc(16px + env(safe-area-inset-top)) 20px 16px;
  text-align: center;
  position: sticky; top: 0; z-index: 10;
}
.topbar .logo { font-size: 26px; }
.topbar h1 { margin: 2px 0 0; font-size: 19px; font-weight: 800; }
.range-label { font-size: 13px; opacity: .9; margin-top: 4px; }

.content { flex: 1; padding: 14px; }

/* 控制區 */
.ctrl {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 6px 16px 16px; margin-bottom: 14px;
}
.ctrl summary {
  cursor: pointer; font-weight: 700; font-size: 14px; color: var(--indigo);
  padding: 10px 0; list-style: none;
}
.ctrl summary::-webkit-details-marker { display: none; }
.lbl { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin: 8px 0 4px; }
textarea, input[type=date], select {
  width: 100%; padding: 11px 12px; border: 1px solid #cbd5e1; border-radius: 10px;
  font-size: 16px; font-family: inherit; background: #fff; color: var(--ink);
}
textarea { resize: vertical; line-height: 1.5; }
.row2 { display: flex; gap: 10px; }
.row2 .field { flex: 1; }
.btns { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.btn-primary {
  flex: 1; min-width: 80px; background: var(--indigo); color: #fff; border: none;
  padding: 12px; border-radius: 10px; font-weight: 700; font-size: 15px; cursor: pointer;
}
.btn-primary:disabled { opacity: .5; }
.btn-ghost {
  background: #fff; color: var(--indigo); border: 1px solid var(--indigo);
  padding: 12px 14px; border-radius: 10px; font-weight: 600; font-size: 14px; cursor: pointer;
}

.placeholder, .loading, .error { text-align: center; padding: 44px 16px; color: var(--muted); font-size: 15px; }
.loading { color: var(--indigo); }
.error { color: #dc2626; }

/* Hero：全部加總 */
.hero {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff; border-radius: 16px; padding: 22px; text-align: center;
  margin-bottom: 14px; box-shadow: 0 8px 24px rgba(79,70,229,.25);
}
.hero .num { font-size: 52px; font-weight: 900; line-height: 1; letter-spacing: -1px; }
.hero .cap { font-size: 14px; opacity: .9; margin-top: 6px; }
.hero .meta { font-size: 12px; opacity: .8; margin-top: 10px; }

/* 區塊卡 */
.sec { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 14px; }
.sec h2 { margin: 0 0 12px; font-size: 15px; font-weight: 800; display: flex; justify-content: space-between; align-items: baseline; }
.sec h2 small { font-size: 12px; color: var(--muted); font-weight: 600; }

.bar-row { display: flex; align-items: center; gap: 10px; margin: 9px 0; }
.bar-row .name {
  font-size: 14px; color: #334155; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.daily .name { width: 92px; flex: none; font-variant-numeric: tabular-nums; }
.bytag .name, .byday .name { width: 92px; flex: none; }
.empty-day { color: #94a3b8; font-size: 13px; padding: 4px 2px; }

/* 可展開的每日卡片 */
.sec.byday { padding: 0; overflow: hidden; }
.sec.byday > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; font-size: 15px; font-weight: 800;
}
.sec.byday > summary::-webkit-details-marker { display: none; }
.sec.byday > summary:active { background: #f8fafc; }
.sec.byday .d-right { display: flex; align-items: center; gap: 10px; }
.sec.byday .d-right small { font-size: 12px; color: var(--muted); font-weight: 600; }
.sec.byday .chev { color: #94a3b8; font-size: 13px; transition: transform .2s; }
.sec.byday[open] .chev { transform: rotate(180deg); }
.sec.byday .d-name em {
  font-style: normal; background: #eef2ff; color: #4338ca;
  font-size: 11px; padding: 1px 8px; border-radius: 999px; margin-left: 6px; font-weight: 700;
}
.sec.byday .day-body { padding: 0 16px 14px; }
.track { flex: 1; background: #eef2f7; border-radius: 6px; height: 22px; overflow: hidden; }
.fill { height: 100%; border-radius: 6px; }
.val { width: 56px; text-align: right; font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar-row.zero .val { color: #94a3b8; font-weight: 600; }

.foot { text-align: center; color: var(--muted); font-size: 11px; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); line-height: 1.7; }
.foot span { display: block; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: .95; }

/* 桌機：維持手機直式寬度置中，外圍留白 */
@media (min-width: 540px) {
  body { padding: 0; }
  .app { box-shadow: 0 0 40px rgba(0,0,0,.08); }
}
