/* Photo scanner review (js/scanReview.js): compact editable cards that fit a 320 px phone.
   Theme tokens from css/app.css / css/living.css only; no horizontal scroll, nothing clipped. */
.scan-review { margin-top: 8px; min-width: 0; }
.scan-review * { min-width: 0; }
.sr-head { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.sr-thumb { width: 64px; height: 64px; flex: none; object-fit: cover; border-radius: var(--radius-md, 14px); box-shadow: 0 0 0 1px var(--line); }
.sr-head-text { flex: 1; }
.sr-title { font-weight: 700; font-size: 15px; }
.sr-head .note { margin: 2px 0 0; font-size: 12px; }
.sr-label { font-size: 12px; font-weight: 700; color: var(--text-secondary); display: block; margin: 6px 0 4px; }

.sr-scale, .sr-more { border-radius: var(--radius-md, 14px); background: var(--surface-soft, var(--surface-muted)); margin: 6px 0; }
.sr-scale > summary, .sr-more > summary { cursor: pointer; padding: 10px 12px; font-size: 13px; font-weight: 600; color: var(--text-primary); min-height: 44px; display: flex; align-items: center; list-style-position: inside; }
.sr-scale > summary::marker, .sr-more > summary::marker { color: var(--accent); }
.sr-scale-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 0 12px 4px; }
.sr-scale-row select { width: auto; flex: 0 1 auto; margin: 0; }
.sr-scale-row input { width: 72px; flex: none; margin: 0; text-align: center; }
.sr-scale .note { padding: 0 12px 10px; margin: 0; font-size: 12px; }

.sr-questions { margin: 6px 0 8px; padding: 8px 10px; border-radius: var(--radius-md, 14px); background: var(--accent-light); }
.sr-questions .sr-label { color: var(--accent-strong); margin-top: 0; }
.sr-q + .sr-q { margin-top: 8px; }
.sr-q-text { font-size: 13px; font-weight: 600; margin-bottom: 4px; overflow-wrap: anywhere; }

.sr-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sr-chips .chip { min-height: 36px; padding: 4px 10px; }
.sr-size { margin: 2px 0 6px; }
.sr-usual { border-style: dashed; }

.sr-card { padding: 10px 12px; }
.sr-card-warn { box-shadow: 0 0 0 1.5px #F3D9A8; }
.sr-row1 { display: flex; align-items: flex-start; gap: 8px; justify-content: space-between; }
.sr-card .sr-name { font-size: 15px; overflow-wrap: anywhere; line-height: 1.3; padding-top: 4px; } /* scoped: Diary search rows use .sr-name too */
.sr-x { flex: none; width: 36px; height: 36px; min-height: 36px; padding: 0; border-radius: 50%; background: transparent; color: var(--text-secondary); box-shadow: none; font-size: 15px; }
.sr-x:hover { background: var(--surface-muted); color: var(--text-primary); }
.sr-x-sm { width: 32px; height: 32px; min-height: 32px; font-size: 13px; }
.sr-badges { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0 4px; }
.sr-amount { font-size: 14px; font-weight: 600; margin: 2px 0 6px; overflow-wrap: anywhere; }
.sr-amount-missing { color: #A4231B; }
.sr-eaten { font-weight: 500; color: var(--text-secondary); }
.sr-grams-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.sr-grams-row input { width: 84px; flex: none; height: 40px; margin: 0; text-align: center; font-size: 16px; }
.sr-hint { font-size: 12px; color: #8A4E00; background: #FFF4E0; border-radius: 10px; padding: 6px 8px; margin: 4px 0 6px; }
.sr-nutri { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; margin: 2px 0 4px; }
.sr-kcal { font-size: 18px; }
.sr-nutri .macro-line { font-size: 13px; color: var(--text-secondary); }
.sr-source { font-size: 12px; color: var(--text-secondary); margin: 2px 0 4px; overflow-wrap: anywhere; }
.sr-source .badge { display: inline-block; margin-bottom: 2px; }
.sr-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 2px; }
.sr-confirm { font-size: 13px; background: #FFE8E3; color: #7A2419; border-radius: 10px; padding: 8px; margin: 6px 0; overflow-wrap: anywhere; }
.sr-confirm button { margin: 6px 6px 0 0; }

.sr-more-body { padding: 0 12px 10px; }
.sr-line { margin-bottom: 8px; }
.sr-servings { display: inline-flex; align-items: center; gap: 8px; }
.sr-serv-val { min-width: 44px; text-align: center; font-weight: 700; }
.sr-custom-frac { font-size: 12px; color: var(--text-secondary); display: inline-flex; align-items: center; gap: 4px; }
.sr-custom-frac input { width: 56px; height: 36px; margin: 0; text-align: center; }
.sr-prep { width: 100%; margin: 0; }

.sr-comps { margin: 4px 0 8px; }
.sr-comp { border-top: 1px solid var(--line); padding: 6px 0; }
.sr-comp-main { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
/* Name on its own line; grams, kcal and remove stay together on the next one at every width. */
.sr-comp-name { flex: 1 1 100%; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.sr-comp-g { margin-right: auto; }
.sr-comp-g { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.sr-grams-sm { width: 64px; height: 36px; margin: 0; text-align: center; font-size: 15px; }
.sr-comp-kcal { font-size: 12px; color: var(--text-secondary); min-width: 56px; text-align: right; }
.sr-comp-src, .sr-comp-note { font-size: 11.5px; color: var(--text-secondary); overflow-wrap: anywhere; margin-top: 2px; }
.sr-comp-bad .sr-comp-name { color: #A4231B; }
.sr-comp-extra .sr-comp-name { font-weight: 500; }
.sr-assume ul { margin: 0; padding-left: 18px; font-size: 12px; color: var(--text-secondary); }
.sr-assume li { margin: 2px 0; overflow-wrap: anywhere; }
.sr-src { color: var(--text-secondary); opacity: 0.85; }

.sr-search { margin: 6px 0; }
.sr-search-input { width: 100%; margin: 0 0 4px; }
.sr-search-results { display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow-y: auto; }
.sr-search-row { display: flex; flex-direction: column; align-items: flex-start; text-align: left; background: var(--surface); color: var(--text-primary); box-shadow: 0 0 0 1px var(--line); border-radius: 10px; padding: 8px 10px; min-height: 44px; width: 100%; }
.sr-search-row:hover, .sr-search-row:focus-visible { box-shadow: 0 0 0 1.5px var(--accent); background: var(--accent-light); }
.sr-sr-name { font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.sr-sr-sub { font-size: 11.5px; color: var(--text-secondary); overflow-wrap: anywhere; }
.sr-notice { margin-top: 6px; }

/* While reviewing, the big preview gives way to the thumbnail in the review (Retake / Choose stay). */
.scan-preview-wrap.reviewing #scan-preview, .scan-preview-wrap.reviewing .scan-preview-filename { display: none; }
#scan-summary { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.scan-total-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; font-size: 13px; color: var(--text-secondary); }
.scan-total-row b { font-size: 18px; color: var(--text-primary); }
.scan-total-row .scan-count { flex-basis: 100%; font-size: 12px; }
#scan-summary .scan-not-counted { font-size: 12px; color: #8A4E00; margin: 4px 0; }
#scan-summary .scan-save-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
#scan-summary .scan-save-row select { flex: 1 1 130px; margin: 0; width: auto; }
#scan-summary .scan-save-row button { flex: 1 1 150px; }
.scan-camera-error .scan-camera-actions button { flex: 1 1 140px; }

@media (max-width: 360px) {
  .sr-thumb { width: 52px; height: 52px; }
  .sr-grams-row input { width: 72px; }
  .sr-chips .chip { padding: 4px 8px; font-size: 12.5px; }
}
@media (prefers-reduced-motion: reduce) {
  .sr-search-row, .sr-x { transition: none; }
}

/* ===================================================================================================
   Receipt and treadmill scans (round 9) — the shared pieces; css/receipt.css and css/treadmill.css hold
   each review's own layout. Both reviews render in #entry-detail-sheet with a root `.scan-sheet`. Theme
   tokens only (the period remaps them; sheets stay light at night), 44 px taps, 16 px fields (no iOS
   zoom), uncertainty shown with words as well as colour. The meal scanner's rules above are untouched.
   =================================================================================================== */
#entry-detail-sheet:has(.scan-sheet) .entry-detail-head { position: sticky; top: -14px; z-index: 3; margin: -14px -16px 0; padding: 14px 16px 6px; background: var(--surface); }
.scan-sheet { color: var(--text-primary); min-width: 0; }
.scan-sheet * { min-width: 0; }
.scan-sheet input[type="text"], .scan-sheet input[type="date"], .scan-sheet input[type="time"], .scan-sheet select, .scan-sheet textarea { width: 100%; margin: 0; font-size: 16px; }
/* A field focused after a refused Save clears both the sticky head and the sticky Save bar. */
.scan-sheet [data-focus], .scan-sheet input, .scan-sheet select, .scan-sheet textarea { scroll-margin: 72px 0 190px; }
#entry-detail-sheet .scan-sheet .fs-foot { bottom: calc(-16px - env(safe-area-inset-bottom, 0px)); }
.scan-sheet .fs-foot .editor-actions { flex-wrap: wrap; }

/* The entry row: "📷 Scan receipt" / "Scan treadmill display" with its two buttons (camera | gallery). */
.scan-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin: 0 0 12px; padding: 10px 12px; border-radius: var(--radius-md); background: var(--surface-soft); box-shadow: inset 0 0 0 1px var(--line); }
.scan-pick-label { flex: 1 1 100%; font-size: 14px; font-weight: 800; color: var(--text-primary); }
.scan-pick-label .scan-pick-sub { display: block; margin-top: 2px; font-size: 12.5px; font-weight: 500; color: var(--text-secondary); }
.scan-pick-actions { display: flex; flex: 1 1 100%; flex-wrap: wrap; gap: 8px; }
.scan-pick-actions button { flex: 1 1 130px; min-height: var(--tap); margin: 0; border-radius: var(--radius-pill); font-size: 15px; }

/* Consent: who reads the photo (PROVIDER), what is sent, nothing kept; [Agree] [Enter by hand]. */
.scan-consent { margin: 4px 0 12px; padding: 12px 14px; border-radius: var(--radius-md); background: var(--sky-light); color: var(--text-primary); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--sky) 40%, transparent); }
.scan-consent-title { margin: 0 0 6px; font-size: 15px; font-weight: 800; }
.scan-consent p { margin: 4px 0; font-size: 14px; line-height: 1.45; }
.scan-consent ul { margin: 6px 0; padding-left: 20px; font-size: 13.5px; line-height: 1.45; }
.scan-consent li { margin: 2px 0; overflow-wrap: anywhere; }
.scan-provider { font-weight: 800; color: var(--sky-ink); }
.scan-consent-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.scan-consent-actions button { flex: 1 1 140px; min-height: 48px; margin: 0; }

/* The photo: a thumbnail that opens larger on tap (short landscape phones keep the fields and Save in view). */
.scan-photo { display: block; width: 100%; margin: 0 0 10px; padding: 0; border-radius: var(--radius-md); background: var(--surface-muted); box-shadow: inset 0 0 0 1px var(--line); color: var(--text-secondary); cursor: zoom-in; overflow: hidden; text-align: center; }
.scan-photo:hover { background: var(--surface-muted); }
.scan-photo img { display: block; width: 100%; max-height: 28vh; object-fit: contain; margin: 0 auto; }
.scan-photo[aria-expanded="true"] { cursor: zoom-out; }
.scan-photo[aria-expanded="true"] img { max-height: 70vh; }
.scan-photo-note { display: block; padding: 4px 8px 6px; font-size: 12px; font-weight: 600; }

/* Recognizing / error / saved states. */
.scan-state { display: flex; align-items: flex-start; gap: 12px; margin: 8px 0 12px; padding: 12px 14px; border-radius: var(--radius-md); background: var(--surface-soft); font-size: 14px; line-height: 1.45; }
.scan-state-text { flex: 1; }
.scan-state-text b { display: block; font-size: 15px; }
.scan-state.is-error { background: #FFE8E3; color: #7A2419; box-shadow: inset 0 0 0 1px #F2C2B8; }
.scan-state.is-done { background: var(--accent-light); color: var(--accent-strong); }
.scan-state-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.scan-state-actions button { flex: 1 1 130px; min-height: var(--tap); margin: 0; }
.scan-spinner { flex: none; width: 22px; height: 22px; margin-top: 1px; border-radius: 50%; border: 3px solid color-mix(in srgb, var(--accent) 22%, transparent); border-top-color: var(--accent); animation: scan-spin 0.9s linear infinite; }
@keyframes scan-spin { to { transform: rotate(360deg); } }

/* A field the photo didn't make clear: tinted, with the reason in words and the text it came from. */
.scan-unclear { margin: 0 -8px 8px; padding: 6px 8px 8px; border-radius: 12px; background: var(--yellow-light); box-shadow: inset 3px 0 0 var(--yellow); }
.scan-unclear input, .scan-unclear select { box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--yellow) 80%, #845C00); }
.scan-unclear-why { display: block; margin-top: 4px; color: var(--yellow-ink); font-size: 12.5px; font-weight: 700; line-height: 1.4; overflow-wrap: anywhere; }
.scan-unclear-why::before { content: "⚠ "; }
/* What the receipt / display shows, word for word ("Trên hoá đơn: 45.000", "32:45 · mm:ss"). */
.scan-printed { display: inline-block; max-width: 100%; margin: 4px 4px 0 0; padding: 2px 8px; border-radius: var(--radius-pill); background: var(--surface-muted); color: var(--text-secondary); font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.scan-evidence { margin: 6px 0 0; padding: 6px 10px; border-left: 3px solid var(--line-strong); color: var(--text-secondary); font-size: 12.5px; line-height: 1.45; overflow-wrap: anywhere; }
.scan-evidence q { quotes: "“" "”"; font-style: italic; }
.scan-note { margin: 8px 0; padding: 8px 10px; border-radius: 12px; background: var(--surface-soft); color: var(--text-secondary); font-size: 13px; line-height: 1.45; }

/* Rotated tablets / desktop: photo beside the fields inside the 680 px sheet. */
@media (min-width: 700px) and (orientation: landscape) {
  .scan-split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 14px; align-items: start; }
  .scan-split .scan-photo { position: sticky; top: 52px; }
  .scan-split .scan-photo img { max-height: 46vh; }
}
@media (max-width: 360px) {
  .scan-pick-actions button, .scan-consent-actions button, .scan-state-actions button { flex-basis: 100%; }
}
/* Night: the page turns navy but the sheets stay light; an entry row outside a sheet keeps its edge visible. */
html[data-period="night"] .scan-pick { box-shadow: inset 0 0 0 1px var(--line-strong); }
/* Motion: the app setting and the OS setting still the spinner (the state text says what is happening). */
html[data-motion="reduced"] .scan-spinner, html[data-motion="off"] .scan-spinner { animation: none; border-color: var(--accent); }
@media (prefers-reduced-motion: reduce) {
  .scan-spinner { animation: none; border-color: var(--accent); }
}

/* Meal photo: a copy on the phone, drafts across a reload, the day it is logged to (round 12, js/photoKeep.js). */
.scan-preview-actions { flex-wrap: wrap; }
.scan-gallery-pref label { display: flex; align-items: flex-start; gap: .5rem; font-size: 1rem; }
.scan-gallery-pref input { flex: 0 0 auto; margin-top: .2rem; }
.scan-gallery-pref p { margin: .35rem 0 .6rem; }
#scan-save-photo-hint, #scan-save-photo-status, #scan-draft-note { overflow-wrap: anywhere; margin: 4px 0 6px; }
/* The browser's own long-press menu ("Lưu vào Ảnh" / "Download image") stays on the photo. */
#scan-preview, .sr-thumb { -webkit-touch-callout: default; }
.scan-draft-card { margin: 8px 0 10px; padding: 10px 12px; border-radius: var(--radius-md, 14px); background: var(--accent-light); color: var(--text-primary); }
.scan-draft-card p { margin: 0 0 8px; font-size: 13.5px; font-weight: 600; overflow-wrap: anywhere; }
.scan-draft-card p.note { margin: -4px 0 8px; font-size: 12px; font-weight: 400; }
.scan-draft-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.scan-draft-actions button { flex: 1 1 120px; min-height: 44px; }
.scan-day-line { margin: 6px 0 0; font-size: 13px; font-weight: 600; color: var(--text-primary); overflow-wrap: anywhere; }
.scan-day-line:empty { display: none; }
.scan-done { margin-top: 10px; padding: 10px 12px; border-radius: var(--radius-md, 14px); background: var(--surface-soft, var(--surface-muted)); }
.scan-done p { margin: 0 0 8px; font-size: 13.5px; overflow-wrap: anywhere; }
.scan-done button { width: 100%; min-height: 44px; }
.scan-draft-card[hidden], .scan-done[hidden], #scan-draft-note[hidden] { display: none; }
/* After "Add to meal" the save is the one thing left to do here: a full-size button. */
.scan-preview-wrap.scan-done-mode #scan-save-photo-btn { flex: 1 1 100%; min-height: 44px; padding: 9px 16px; font-size: 15px; background: var(--accent); color: var(--text-on-accent); box-shadow: none; }
