/* Diary › Move › "Scan treadmill display" (js/treadmillView.js): the row at the top of the workout form and the
   review inside #entry-detail-sheet. Shared tokens only (css/app.css, css/living.css) — sheets stay light in the
   night period, so nothing here needs a dark variant. Fits a 320 px phone with no sideways scroll; the Save bar
   is sticky (it reaches the sheet's edge, as the spending sheet's does). */

/* ---- the row in #exercise-form ---- */
.exercise-form .ex-scan { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px 10px; border-radius: var(--radius-md);
  background: var(--yellow-light); box-shadow: inset 0 0 0 1px var(--line); min-width: 0; }
.exercise-form .ex-scan[hidden] { display: none; }
/* The first row, visually too: css/diary.css pins Activity + Minutes to grid row 1 and the speed fields to row 2. */
#exercise-form > .ex-scan { grid-row: 1; }
#exercise-form:has(> .ex-scan:not([hidden])) .ex-activity, #exercise-form:has(> .ex-scan:not([hidden])) .ex-minutes { grid-row: 2; }
#exercise-form:has(> .ex-scan:not([hidden])) .ex-speed { grid-row: 3; }
.ex-scan-title { flex: 1 1 140px; min-width: 0; font-size: 13.5px; font-weight: 800; color: var(--text-primary); overflow-wrap: anywhere; }
.ex-scan-actions { display: flex; flex: 1 1 220px; gap: 8px; min-width: 0; }
.ex-scan-actions button { flex: 1 1 0; min-width: 0; min-height: 44px; margin: 0; padding: 6px 10px; font-size: 14px; white-space: normal; line-height: 1.2; }
.ex-scan-draft { flex: 0 0 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 0 8px; margin: 0; font-size: 13px; color: var(--yellow-ink); font-weight: 700; }
.ex-scan-draft[hidden] { display: none; }
.ex-scan-draft-text { min-width: 0; overflow-wrap: anywhere; }
.ex-scan-draft-actions { display: inline-flex; gap: 4px; }
.ex-scan-draft .link-btn { min-height: 44px; padding: 0 6px; font-size: 13px; }

/* ---- the sheet while it shows a treadmill view ---- */
#entry-detail-sheet:has(.tm-sheet) .entry-detail-head { position: sticky; top: -14px; z-index: 3; margin: -14px -16px 0; padding: 14px 16px 6px; background: var(--surface); }
#entry-detail-title .tm-title { overflow-wrap: anywhere; }
.tm-sheet { color: var(--text-primary); min-width: 0; }
.tm-sheet * { min-width: 0; }
/* 16 px: iOS doesn't zoom. min-width 0: the app's inputs keep 120 px (css/app.css), which would push a 320 px sheet sideways. */
.tm-sheet input[type="text"], .tm-sheet input[type="date"], .tm-sheet input[type="time"], .tm-sheet select { width: 100%; min-width: 0; margin: 0; font-size: 16px; }
/* Any control focused (Tab, a refused Save, a tap near the bottom) scrolls clear of the sticky head and Save bar. */
.tm-sheet :is(input, select, button, [tabindex]):not(.tm-foot *) { scroll-margin: 72px 0 190px; }
.tm-sheet [aria-invalid="true"] { border-color: #C0584A; }
#entry-detail-sheet .tm-foot { bottom: calc(-16px - env(safe-area-inset-bottom, 0px)); }
.tm-foot .editor-actions button { min-height: 48px; }
.tm-foot .editor-actions #tm-save { flex: 2; }
.tm-stack { flex-wrap: wrap; }
.tm-stack button { flex: 1 1 100%; min-height: 48px; height: auto; }

.tm-card { margin: 4px 0 8px; padding: 12px; border-radius: var(--radius-md); background: var(--surface-soft); box-shadow: inset 0 0 0 1px var(--line); }
.tm-card-title { margin: 0 0 6px; font-size: 15px; font-weight: 800; }
.tm-card-text { margin: 0 0 10px; font-size: 14px; line-height: 1.5; text-wrap: pretty; }
.tm-error-card { background: var(--yellow-light); }
.tm-error-card .tm-card-text { margin: 0; color: var(--text-primary); font-weight: 600; }

/* recognizing */
.tm-busy { display: grid; gap: 8px; justify-items: center; padding: 6px 0 4px; text-align: center; }
.tm-busy-text { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-size: 15px; font-weight: 700; }
.tm-busy-slow { margin: 0; font-size: 13px; color: var(--text-secondary); max-width: 36ch; }
.tm-spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--accent-light); border-top-color: var(--accent); animation: tm-spin 0.9s linear infinite; }
@keyframes tm-spin { to { transform: rotate(360deg); } }
html[data-motion="reduced"] .tm-spinner, html[data-motion="off"] .tm-spinner { animation: none; border-top-color: var(--accent-2); }
@media (prefers-reduced-motion: reduce) { .tm-spinner { animation: none; border-top-color: var(--accent-2); } }

/* the photo (this tab only: never stored) */
.tm-photo-row { display: flex; align-items: center; gap: 10px; margin: 2px 0 6px; }
.tm-photo { flex: 0 0 auto; display: block; padding: 0; border: 0; border-radius: var(--radius-md); background: var(--surface-muted); box-shadow: 0 0 0 1px var(--line); cursor: zoom-in; overflow: hidden; min-height: 44px; }
.tm-photo img { display: block; width: 96px; height: 72px; object-fit: cover; }
.tm-photo.is-big { flex: 1 1 100%; cursor: zoom-out; }
.tm-photo.is-big img { width: 100%; height: auto; max-height: 50vh; object-fit: contain; }
.tm-photo-row:has(.tm-photo.is-big) { flex-wrap: wrap; }
.tm-busy .tm-photo img { width: 160px; height: 120px; }
.tm-photo-none { flex: 1 1 auto; margin: 0; font-size: 13px; color: var(--text-secondary); line-height: 1.4; }
.tm-photo-actions { display: flex; flex-wrap: wrap; gap: 0 4px; margin-left: auto; }
.tm-photo-actions .link-btn { min-height: 44px; padding: 0 8px; font-size: 14px; }

.tm-note { margin: 4px 0 0; font-size: 12.5px; line-height: 1.45; color: var(--text-secondary); text-wrap: pretty; overflow-wrap: anywhere; }
.tm-note[hidden], .tm-msg[hidden], .tm-offer[hidden], .tm-check[hidden], .tm-overlap[hidden] { display: none; }
.tm-review-note { margin: 0 0 8px; padding: 8px 10px; border-radius: 12px; background: var(--yellow-light); color: var(--yellow-ink); font-size: 13.5px; font-weight: 700; line-height: 1.4; }
.tm-provisional { margin: 0 0 8px; }
.tm-provisional .tm-review-note { margin-bottom: 4px; }
.tm-check { display: flex; align-items: flex-start; gap: 8px; min-height: 44px; padding: 8px 2px; font-size: 14px; line-height: 1.35; cursor: pointer; }
.tm-check input { flex: 0 0 auto; width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }

/* fields */
.tm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; margin: 4px 0 8px; }
.tm-wide { grid-column: 1 / -1; }
.tm-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 700; color: var(--text-secondary); }
.tm-metric { margin: 0 0 8px; padding: 8px 10px 10px; border: 0; border-radius: var(--radius-md); background: var(--surface-soft); box-shadow: inset 0 0 0 1px var(--line); }
.tm-metric > legend { float: left; width: 100%; padding: 0; margin: 0 0 6px; font-size: 13px; font-weight: 800; color: var(--text-primary); }
.tm-metric > legend + * { clear: both; }
.tm-pair { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 8px; }
.tm-kind { margin-top: 6px; }
.tm-unit { align-self: center; font-size: 14px; font-weight: 700; color: var(--text-secondary); }
.tm-printed { margin: 6px 0 0; font-size: 12.5px; color: var(--text-secondary); overflow-wrap: anywhere; }
.tm-msg { margin: 6px 0 0; font-size: 12.5px; font-weight: 700; line-height: 1.4; color: var(--yellow-ink); }
.tm-msg.is-error { color: #A4231B; }
/* An unclear field: a warm tint, its reason in words beside it (never colour alone) */
.tm-sheet .scan-unclear { background: var(--yellow-light); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--yellow) 70%, transparent); }
.tm-sheet .is-bad { box-shadow: inset 0 0 0 2px #C0584A; }
.tm-field.is-bad { box-shadow: none; }
.tm-field.is-bad input { border-color: #C0584A; }

.tm-hms { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tm-hms-part { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text-secondary); font-weight: 700; }
.tm-sheet .tm-hms-part input { flex: 1 1 0; width: 0; text-align: center; } /* the unit word beside it, never pushed out */
.tm-hms-part span { flex: 0 0 auto; }
.tm-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.tm-chip { flex: 1 1 120px; display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 10px; border-radius: var(--radius-md); background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line); font-size: 14px; font-weight: 700; cursor: pointer; }
.tm-chip input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.tm-chip:has(input:checked) { background: var(--accent-light); box-shadow: inset 0 0 0 2px var(--accent); }
.tm-chip:has(input:focus-visible) { box-shadow: inset 0 0 0 2px var(--accent), var(--focus-ring); }
.tm-ask { margin-top: 8px; padding: 8px 10px; border-radius: 12px; background: var(--yellow-light); }
.tm-ask-text { margin: 0 0 6px; font-size: 13.5px; font-weight: 700; color: var(--yellow-ink); overflow-wrap: anywhere; }
.tm-pick { flex: 1 1 120px; min-height: 44px; margin: 0; padding: 6px 10px; border-radius: var(--radius-md); background: var(--surface); color: var(--text-primary);
  box-shadow: inset 0 0 0 1px var(--line-strong); font-size: 14px; font-weight: 700; }
.tm-pick.is-on { background: var(--accent); color: var(--text-on-accent); box-shadow: none; }
.tm-offer { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 8px; padding: 8px 10px; border-radius: 12px; background: var(--accent-light); font-size: 13.5px; font-weight: 700; color: var(--accent-strong); }
.tm-offer span { flex: 1 1 160px; }
.tm-offer button { flex: 0 0 auto; min-height: 44px; margin: 0; padding: 6px 14px; }
.tm-metric.is-calculated [data-tm-f="speed.input"] { background: var(--accent-light); }

/* calories: both values, exactly one counted */
.tm-kcal-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tm-kcal-card { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px 10px; border-radius: var(--radius-md); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.tm-kcal-card.is-on { box-shadow: inset 0 0 0 2px var(--accent); background: color-mix(in srgb, var(--accent-light) 55%, var(--surface)); }
.tm-kcal-card.is-off .tm-kcal-value { text-decoration: line-through; text-decoration-thickness: 1px; color: var(--text-secondary); }
.tm-kcal-pick { display: flex; align-items: flex-start; gap: 8px; min-height: 44px; padding: 2px 0; cursor: pointer; }
.tm-kcal-pick input { flex: 0 0 auto; width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); }
.tm-kcal-pick input:disabled + .tm-kcal-name { color: var(--text-secondary); }
.tm-kcal-name { font-size: 13.5px; font-weight: 800; line-height: 1.3; overflow-wrap: anywhere; }
.tm-kcal-state { align-self: flex-start; padding: 1px 8px; border-radius: var(--radius-pill); background: var(--surface-muted); color: var(--text-secondary); font-size: 12px; font-weight: 800; }
.tm-kcal-state:empty { display: none; }
.tm-kcal-state.is-on { background: var(--accent); color: var(--text-on-accent); }
.tm-kcal-value { margin: 0; font-size: 18px; font-weight: 800; }
.tm-kcal-card .tm-pair { grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr); }
.tm-kcal-card .tm-msg { margin-top: 0; }
@media (max-width: 560px) { .tm-kcal-cards { grid-template-columns: minmax(0, 1fr); } } /* a phone: one card above the other (the unit stays readable) */

.tm-counts { margin: 0 0 8px; padding: 0; border: 0; min-width: 0; }
.tm-overlap { scroll-margin: 72px 0 120px; margin: 0 0 8px; padding: 10px 12px; border-radius: var(--radius-md); background: var(--yellow-light); box-shadow: inset 0 0 0 1px var(--line); }
.tm-overlap-text { margin: 0 0 8px; font-size: 14px; line-height: 1.45; font-weight: 700; }
.tm-overlap-text:focus { outline: none; }
.tm-overlap-text:focus-visible { outline: 3px solid var(--accent-strong); outline-offset: 2px; border-radius: 6px; }
.tm-overlap-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tm-overlap-actions button { flex: 1 1 100%; min-height: 44px; margin: 0; padding: 8px 12px; font-size: 14px; height: auto; white-space: normal; }

/* while a save is on its way the review is locked (js/treadmillView.js): its links and choices look it */
.tm-sheet[aria-busy="true"] .link-btn:disabled, .tm-sheet[aria-busy="true"] button.secondary:disabled { opacity: .55; text-decoration-color: transparent; }
.tm-sheet[aria-busy="true"] .tm-chip, .tm-sheet[aria-busy="true"] .ex-count-opt, .tm-sheet[aria-busy="true"] .tm-kcal-pick { opacity: .7; }

/* a wide, short window (a rotated tablet, a desktop): paired fields side by side */
@media (min-width: 700px) {
  .tm-photo img { width: 128px; height: 96px; }
  .tm-overlap-actions button { flex: 1 1 0; }
}
@media (max-width: 340px) { .tm-grid { grid-template-columns: minmax(0, 1fr); } .tm-photo-actions { margin-left: 0; } }
