/* 看圖美化：measure（_build/polish.py） */
body .c-demo-banner {
  align-items: center;
  margin: 0 0 var(--sp-3);
  padding: var(--sp-2) var(--sp-3) var(--sp-2) var(--sp-4);
  border: 0;
  border-radius: var(--r-input);
  text-align: left;
}
body .c-demo-banner > svg { flex: none; }
body .c-demo-banner > :not(.c-btn):not(svg) {
  flex: 1 1 auto;
  min-width: 0;
  text-align: left;
}
body .c-demo-banner .c-btn {
  flex: none;
  min-height: 36px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-chip);
  font-size: var(--fs-footnote);
  white-space: nowrap;
}

/* ---------- 清單頁：頂部控制列 ---------- */
body .s-measure__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}
body .s-measure__head .c-seg {
  position: relative;
  flex: none;
  isolation: isolate;
}
body .s-measure__head .c-seg__thumb { z-index: 0; }
body .s-measure__head .c-seg__opt { z-index: 1; min-width: 64px; }
body .s-measure__add {
  flex: none;
  min-height: 40px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-btn);
  font-size: var(--fs-callout);
}
body .s-measure__list { container: smlist / inline-size; }
body .s-measure__detail { min-width: 0; }

/* ---------- 清單 ---------- */
body .s-measure-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
body .s-measure-list__month {
  margin: var(--sp-5) 0 var(--sp-1);
  padding: 0 var(--sp-1);
  font-size: var(--fs-callout);
  line-height: 1.3;
  font-weight: 600;
  letter-spacing: var(--ls-caption);
  color: var(--text-2);
}
body .s-measure-list > .s-measure-list__month:first-child { margin-top: var(--sp-1); }

body .s-measure-row {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-3) var(--sp-2) var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-1);
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
body .s-measure-row.is-selected {
  background: var(--primary-tint);
  border-color: var(--primary);
  box-shadow: inset 3px 0 0 var(--primary);
}
body .s-measure-row__main {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "date date"
    "weight delta"
    "sub sub";
  column-gap: var(--sp-3);
  row-gap: 2px;
  align-items: center;
  color: var(--text);
  text-decoration: none;
  border-radius: var(--r-sm);
}
body .s-measure-row__date {
  grid-area: date;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1) var(--sp-2);
  font-size: var(--fs-footnote);
  line-height: 1.4;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
body .s-measure-row__body { display: contents; }
body .s-measure-row__weight {
  grid-area: weight;
  font-size: var(--fs-title2);
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: var(--ls-title);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
body .s-measure-row__sub {
  grid-area: sub;
  margin-top: 2px;
  font-size: var(--fs-footnote);
  line-height: 1.45;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
body .s-measure-row__delta {
  grid-area: delta;
  justify-self: end;
  align-self: center;
}
body .s-measure-row .c-note {
  display: inline-flex;
  padding: 0 var(--sp-2);
  border-radius: var(--r-chip);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: var(--fs-caption);
  line-height: 18px;
}
body .s-measure-row > .c-btn--icon {
  flex: none;
  width: 40px;
  height: 40px;
  min-height: 40px;
  --btn-fg: var(--text-3);
}
body .s-measure-row > .c-btn--icon:hover,
body .s-measure-row > .c-btn--icon:focus-visible {
  --btn-fg: var(--danger);
  background: var(--danger-soft);
}
@media (hover: hover) and (pointer: fine) {
  body .s-measure-row:not(.is-selected):hover {
    border-color: var(--text-3);
    box-shadow: var(--shadow-2);
  }
}

/* 清單寬度足夠時（平板、桌面單欄）改為單行表格式排列 */
@container smlist (min-width: 520px) {
  body .s-measure-row { padding-left: var(--sp-5); }
  body .s-measure-row__main {
    grid-template-columns: 9.5rem 6.5rem minmax(0, 1fr) auto;
    grid-template-areas: "date weight sub delta";
    column-gap: var(--sp-4);
    row-gap: 0;
  }
  body .s-measure-row__date {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }
  body .s-measure-row__sub { margin-top: 0; }
}

/* ---------- 表單：整體為一張卡片 ---------- */
body .s-measure-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-width: 0;
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-1);
}
@media (min-width: 600px) {
  body .s-measure-form { padding: var(--sp-6); }
}
body .s-measure-form .c-field + .c-field { margin-top: 0; }
body .s-measure-form__title {
  margin: 0;
  font-size: var(--fs-title2);
  line-height: var(--lh-title2);
  font-weight: var(--fw-title2);
  letter-spacing: var(--ls-title);
  color: var(--text);
}
body .s-measure-form > .c-field__hint {
  margin: 0;
  font-size: var(--fs-callout);
  line-height: var(--lh-callout);
  color: var(--text-2);
}
body .s-measure-form__title + .c-field__hint { margin-top: calc(-1 * var(--sp-2)); }

/* 欄位 */
body .s-measure-form .c-field__label { font-size: var(--fs-footnote); color: var(--text-2); }
body .s-measure-form .c-field__control { min-height: 48px; }
body .s-measure-form .c-field__control:has(textarea) { align-items: stretch; }
body .s-measure-form .c-input {
  flex: 1;
  min-width: 0;
  width: 100%;
  min-height: 48px;
  padding: 0 var(--sp-4);
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: var(--r-input);
  outline: 0;
  font: inherit;
  font-size: max(16px, 1rem);
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  -webkit-appearance: none;
  appearance: none;
}
body .s-measure-form textarea.c-input {
  min-height: 96px;
  padding: var(--sp-3) var(--sp-4);
  resize: vertical;
}
body .s-measure-form .c-input::placeholder { color: var(--text-3); }
body #m-weight { font-size: var(--fs-title3); font-weight: 600; }

body .s-measure-form .c-field__msg {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-1);
  font-size: var(--fs-footnote);
  line-height: 1.4;
  color: var(--text-2);
}
body .s-measure-form .c-field__msg:empty { display: none; }
body .s-measure-form .c-field__msg.is-error { color: var(--up); }
body .s-measure-form > .c-field__msg.is-error { color: var(--danger); }
body .s-measure-form .c-field__msg svg { flex: none; margin-top: 1px; }

/* 日期與時間 */
body .c-timed { display: flex; flex-direction: column; gap: var(--sp-3); }
body .c-timed__row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: var(--sp-3);
}
body .c-timed .c-toggle { position: relative; min-height: var(--tap); }
body .c-timed > .c-toggle .c-toggle__text { order: -1; flex: 1; }
body .c-timed > .c-toggle .c-toggle__label { font-size: var(--fs-callout); color: var(--text-2); }

/* 同日提示 */
body .s-measure-form .c-confirm-strip p { flex: 1 1 100%; margin: 0; }

/* BMI */
body .s-measure-form__bmirow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-1) var(--sp-4);
  padding: var(--sp-1) var(--sp-4);
  border-radius: var(--r-input);
  background: var(--primary-tint);
}
body .s-measure-form__bmi {
  flex: 1 1 180px;
  min-width: 0;
  font-size: var(--fs-callout);
  line-height: 1.4;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
body .s-measure-form .c-check {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  font-size: var(--fs-callout);
  color: var(--text);
  cursor: pointer;
}
body .s-measure-form .c-check input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--primary);
}
body .s-measure-form__bmirow .c-badge {
  display: inline-flex;
  flex-direction: row;
  width: auto;
  padding: 1px var(--sp-2);
  border-radius: var(--r-chip);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: var(--fs-caption);
  line-height: 18px;
}

/* 裝置估計值 */
body .c-device-section {
  margin: 0;
  padding: var(--sp-2) var(--sp-4) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface-2);
}
body .c-device-section > summary {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  list-style: none;
  cursor: pointer;
  font-size: var(--fs-body);
  font-weight: 600;
  color: var(--text);
}
body .c-device-section > summary::-webkit-details-marker { display: none; }
body .c-device-section > summary::after {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  margin-left: var(--sp-2);
  border-right: 2px solid var(--text-3);
  border-bottom: 2px solid var(--text-3);
  transform: rotate(45deg) translateY(-2px);
  transition: transform var(--dur-2) var(--ease);
}
body .c-device-section[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }
body .c-device-section .c-device-section__model {
  max-width: 45%;
  margin-left: auto;
  overflow: hidden;
  font-size: var(--fs-footnote);
  font-weight: 400;
  color: var(--text-3);
  text-overflow: ellipsis;
  white-space: nowrap;
}
body .c-device-section > * + * { margin-top: var(--sp-3); }
body .c-device-section > .c-field__hint { margin-top: 0; }
body .c-device-section .c-field__control {
  background: var(--surface);
  border-color: var(--border);
}
body .c-device-section .c-field__control:focus-within { border-color: var(--primary); }
body .s-measure-form__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: var(--sp-3);
  align-items: start;
}
body .s-measure-form__grid .c-input { padding: 0 var(--sp-3); }

/* 按鈕列 */
body .s-measure-form__actions {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}
@media (min-width: 600px) {
  body .s-measure-form__actions { flex-direction: row-reverse; align-items: center; }
  body .s-measure-form__actions .c-btn { width: auto; flex: 1 1 0; }
  body .s-measure-form__actions .c-btn--primary { flex: 2 1 0; }
}
body .s-measure-form__actions .c-btn--danger {
  --btn-bg: var(--danger-soft);
  --btn-fg: var(--danger);
}
@media (hover: hover) and (pointer: fine) {
  body .s-measure-form__actions .c-btn--danger:hover {
    background: var(--danger-soft);
    opacity: 1;
    filter: brightness(.96);
  }
}

/* ---------- 桌面右欄：最新一筆概覽 ---------- */
body .s-measure-overview { display: flex; flex-direction: column; gap: var(--sp-4); }
body .s-measure-overview .c-card--hero {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-6) var(--sp-6) var(--sp-6) calc(var(--sp-6) + 4px);
}
body .s-measure-overview .c-caption,
body .s-measure-form .c-caption {
  font-size: var(--fs-footnote);
  line-height: 1.4;
  color: var(--text-3);
}
body .s-measure-overview__weight {
  font-size: var(--fs-display);
  line-height: var(--lh-display);
  font-weight: var(--fw-display);
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
body .s-measure-overview__list {
  display: grid;
  grid-template-columns: 1fr auto;
  margin: var(--sp-3) 0 0;
}
body .s-measure-overview__list dt,
body .s-measure-overview__list dd {
  margin: 0;
  padding: var(--sp-3) 0;
  border-top: 1px solid var(--divider);
  font-size: var(--fs-callout);
  line-height: 1.4;
}
body .s-measure-overview__list dt { color: var(--text-2); }
body .s-measure-overview__list dd {
  text-align: right;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
body .s-measure-overview__actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
body .s-measure-overview__actions .c-btn { flex: 1 1 160px; }

/* hidden 屬性必須勝過上面的 display 設定（放在最後） */
body form.s-measure-form [hidden] { display: none; }
