/* ==========================================================================
   UI shell layer. Loads after theme.css. Presentation only.
   1 Disclaimers off   2 Overflow rules (pills, badges, cells)   3 Folds (progressive disclosure)
   4 Bloodwork lead card   5 Labels   6 Mobile (html.m): home row, sub tabs, sheets, swipe cards
   Desktop (no .m class, wider than 900 px) keeps the existing sidebar navigation exactly.
   ========================================================================== */

/* ---------- 1. Disclaimers: hidden at once, shell.js removes the nodes ---------- */
.safety, .dna-banner, .clin-note { display: none !important; }

/* ---------- 2. Overflow rules ---------- */
/* Flex and grid children may shrink below their content, so long text wraps instead of pushing the layout. */
.card, .tile, .grid > *, .row > *, .meter, .bw-st, .bw-row, .bw-draw, .wk-card, .citem, details.fold, .sh-body { min-width: 0; }
.card, .tile, .banner, .note, .sub, .sm, .xs, p, li, td, th, summary, label, h1, h2, h3, h4 { overflow-wrap: break-word; }
.row { flex-wrap: wrap; }
/* Big numbers never break mid-number; they shrink with the viewport instead. */
.big, .ring .v, .sh-stat .big { white-space: nowrap; overflow-wrap: normal; }
.grid.g4 .big, .grid.g4.two .big { font-size: clamp(1.7rem, 2.4vw + .6rem, 2.6rem); }
/* Pills and badges: wrap inside their box, never spill out of it. */
.pill, .opill, .lpill, .ev, .bw-chip, .bw-n, .bw-bad, .wk-tag, .wk-chip, [class*="-pill"], [class*="badge"] {
  box-sizing: border-box; max-width: 100%; min-width: 0; white-space: normal; overflow-wrap: anywhere; line-height: 1.25; text-align: left; vertical-align: middle;
}
.pill { display: inline-block; }
.opill, .lpill { display: inline-flex; flex-wrap: wrap; align-items: center; }
.ev { display: inline-block; }
/* Single-line text that must stay one line: ellipsis, full text in the title tooltip (shell.js adds it). */
.ell { min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.ell, th.ell { max-width: 16rem; }
/* Table cells: long lists (exercise names) wrap; numeric cells stay compact. */
td { overflow-wrap: anywhere; }
td:last-child:has(button) { white-space: nowrap; }
.tscroll { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Sentence-case table headers (the labels are written for people, not data columns). */
th { text-transform: none; letter-spacing: .01em; white-space: normal; vertical-align: bottom; }
th, td { min-width: 3.5rem; }
/* Page level safety net: nothing may widen the page. */
#view { min-width: 0; max-width: 100%; }
main { min-width: 0; }
img, svg, canvas, video { max-width: 100%; }

/* ---------- 3. Folds (progressive disclosure) ---------- */
details.sh-fold { margin: var(--s3) 0; padding: 0 var(--s4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); }
details.sh-fold > summary { min-height: 52px; font-size: var(--fs-md); font-weight: 650; font-family: var(--font-display); letter-spacing: -.01em; color: var(--text); cursor: pointer; }
details.sh-fold > summary .sh-t { flex: 1 1 auto; }
details.sh-fold > summary::before { content: ""; width: 9px; height: 9px; border-right: 2px solid var(--accent); border-bottom: 2px solid var(--accent); transform: rotate(-45deg); transition: transform var(--dur-2) var(--ease); margin: 0 var(--s2) 0 var(--s1); flex: none; }
details.sh-fold[open] > summary::before { content: ""; transform: rotate(45deg); }
details.sh-fold > summary:hover { color: var(--accent-strong); }
details.sh-fold > .sh-body { padding: 0 0 var(--s4); }
/* The fold's own summary carries the title, so the block's inner heading is not repeated. */
details.sh-fold > .sh-body > div > h2:first-child,
details.sh-fold > .sh-body > .card > h3:first-child { display: none; }
details.sh-fold > .sh-body > .card { border: 0; box-shadow: none; padding: var(--s2) 0 0; background: transparent; }
details.sh-fold > .sh-body > div > .card { box-shadow: none; }
details.sh-fold > .sh-body > :first-child { margin-top: 0; }
details.sh-fold .fold { background: var(--surface-2); }

/* ---------- 4. Bloodwork lead card ---------- */
.sh-bw { margin: var(--s3) 0 var(--s4); }
.sh-stats { display: flex; flex-wrap: wrap; gap: var(--s3) var(--s6); margin: var(--s3) 0; }
.sh-stat { display: flex; flex-direction: column; min-width: 8rem; }
.sh-stat .big { font-size: 2.2rem; }
.sh-flags { display: grid; gap: var(--s2); margin: var(--s2) 0 var(--s4); }
.sh-flag { gap: var(--s3); padding: var(--s2) 0; border-top: 1px solid var(--border); flex-wrap: nowrap; }
.sh-flag .sh-mk { flex: 1 1 6rem; }
.sh-flag .sh-val { flex: none; white-space: nowrap; }
.sh-flag .pill { flex: none; }

/* ---------- 6. Mobile ---------- */
#homerow, #subtabs, #fscrim { display: none; }
html.m #side { display: none; }
html.m #app { display: block; }
html.m #tabbar { display: none !important; }
html.m main { padding: var(--s4) max(var(--s4), env(safe-area-inset-right)) calc(var(--home-h, 68px) + 110px + env(safe-area-inset-bottom)) max(var(--s4), env(safe-area-inset-left)); max-width: none; }
html.m { --home-h: 68px; }

/* Home row: Today, Training, Nutrition, Body, More */
html.m #homerow { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--home-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: color-mix(in srgb, var(--surface) 94%, transparent); -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px); border-top: 1px solid var(--border); box-shadow: 0 -6px 20px rgba(0,0,0,.18); }
html.m #homerow a, html.m #homerow button.tabb { flex: 1 1 0; min-width: 0; min-height: var(--home-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 0 2px; background: transparent; border: 0; border-radius: 0; box-shadow: none; color: var(--muted); font-size: 12px; font-weight: 650; text-decoration: none; position: relative; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
html.m #homerow .ic { width: 26px; height: 26px; }
html.m #homerow a.on, html.m #homerow button.tabb.on { color: var(--accent-strong); }
html.m #homerow a.on::before, html.m #homerow button.tabb.on::before { content: ""; position: absolute; top: -1px; left: 26%; right: 26%; height: 3px; border-radius: 0 0 4px 4px; background: var(--accent); }
html.m #homerow a:active, html.m #homerow button.tabb:active { background: var(--surface-2); }
#homerow a[data-ic="overview"] .ic { -webkit-mask-image: var(--i-overview); mask-image: var(--i-overview); }
#homerow a[data-ic="training"] .ic { -webkit-mask-image: var(--i-training); mask-image: var(--i-training); }
#homerow a[data-ic="nutrition"] .ic { -webkit-mask-image: var(--i-nutrition); mask-image: var(--i-nutrition); }
#homerow a[data-ic="body"] .ic { -webkit-mask-image: var(--i-body); mask-image: var(--i-body); }
#homerow button[data-ic="more"] .ic { -webkit-mask-image: var(--i-more); mask-image: var(--i-more); }
#more-list a.dv-row .ic { -webkit-mask-image: var(--i-data); mask-image: var(--i-data); }
#more-list a[href="#/supplements"] .ic { -webkit-mask-image: var(--i-biohacking); mask-image: var(--i-biohacking); }

/* Quick add stays reachable above the home row */
html.m #fab { bottom: calc(var(--home-h) + 14px + env(safe-area-inset-bottom)); right: calc(16px + env(safe-area-inset-right)); width: 60px; height: 60px; z-index: 29; }
html.m #toast { bottom: calc(var(--home-h) + 86px + env(safe-area-inset-bottom)); }

/* Section sub tabs: horizontal, swipeable, sticky under the top edge */
html.m #subtabs:not([hidden]) { display: flex; gap: var(--s2); position: sticky; top: 0; z-index: 20; margin: calc(var(--s4) * -1) calc(var(--s4) * -1) var(--s3); padding: var(--s3) var(--s4); overflow-x: auto; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; scrollbar-width: none; background: color-mix(in srgb, var(--bg) 92%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
html.m #subtabs::-webkit-scrollbar { display: none; }
html.m #subtabs a { flex: none; scroll-snap-align: start; display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 var(--s5); border-radius: var(--r-pill); border: 1.5px solid var(--border-strong); background: var(--surface); color: var(--text-2); font-weight: 650; font-size: var(--fs-sm); text-decoration: none; touch-action: manipulation; }
html.m #subtabs a.on { background: var(--accent-grad, var(--accent)); color: var(--accent-ink, #04201b); border-color: transparent; }

/* More sheet: single column of large rows */
html.m #more-list { grid-template-columns: 1fr 1fr; }
html.m #more-list a { min-height: 56px; }
#more-list a.dv-row, #more-list a.theme-row { grid-column: 1 / -1; }
html.m .sheet-card { max-height: 86dvh; }

/* Forms open as bottom sheets (the "Add ..." folds) */
html.m body.fs-open { overflow: hidden; }
html.m #fscrim:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 44; background: var(--scrim); }
html.m details.fold.sheeted[open] { position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; margin: 0; max-height: 86dvh; overflow-y: auto; overscroll-behavior: contain; border-radius: var(--r-lg) var(--r-lg) 0 0; border-width: 1px 0 0; padding: var(--s3) var(--s5) calc(var(--s6) + env(safe-area-inset-bottom)); background: var(--surface); box-shadow: var(--elev-3); animation: fd-up var(--dur-3) var(--ease); }
html.m details.fold.sheeted[open] > summary { display: none; }
html.m details.fold.sheeted .fs-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); position: sticky; top: calc(var(--s3) * -1); background: var(--surface); padding: var(--s2) 0 var(--s3); z-index: 1; }
html.m details.fold.sheeted .fs-head b { font-family: var(--font-display); font-size: var(--fs-lg); }
details.fold:not(.sheeted) .fs-head { display: none; }

/* Swipe-friendly rows of cards */
html.m .tiles, html.m .bw-draws, html.m .grid.g3:not(.keep1) { display: flex; gap: var(--s3); overflow-x: auto; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; padding-bottom: var(--s2); scrollbar-width: none; }
html.m .tiles::-webkit-scrollbar, html.m .bw-draws::-webkit-scrollbar, html.m .grid.g3::-webkit-scrollbar { display: none; }
html.m .tiles > *, html.m .bw-draws > *, html.m .grid.g3:not(.keep1) > * { flex: 0 0 min(78%, 300px); scroll-snap-align: start; }

/* Touch targets */
html.m a.btn, html.m button, html.m summary, html.m select, html.m input:not([type=checkbox]):not([type=radio]) { min-height: var(--tap); }
html.m .check, html.m input[type=checkbox], html.m input[type=radio] { min-width: 24px; min-height: 24px; }
html.m table { font-size: var(--fs-sm); }
html.m .card { padding: var(--s4); }
html.m h1 { font-size: 1.7rem; }

/* Desktop view button only shows on touch devices; on a real desktop it stays hidden. */
#dv-btn[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  details.sh-fold > summary::before, html.m details.fold.sheeted[open] { transition: none; animation: none; }
}
@media print { #homerow, #subtabs, #fscrim { display: none !important; } details.sh-fold:not([open]) > .sh-body { display: block; } }
