/* Insights: the pieces of this redesigned screen only (docs/mockups/redesign/screens.css); shared ones are
   css/widgets.css. Colours come from the tokens in style.css only. */

/* The chart (.ins-box: Insights #ins-chart, Glucose #glu-chart, Today #tdy-chart): most of the first screen (its
   height is set from insights-chart.yaml), nearly the card's full width, on an opaque plot so the living paper never
   shows through the data. A horizontal drag reads it and a vertical swipe scrolls the page (pan-y); the pieces over
   it stack in DOM order: the night behind the curve, the workouts, the meal labels, the crosshair, the bubble on top.
   Every piece over it is positioned against the box and clipped to it (position, overflow and paint containment),
   so none can land over the cards below it as the page scrolls, whichever screen mounts it. */
:is(#app,#pane).screen .card.ins-main{padding-inline:10px}
:is(#app,#pane).screen .card.ins-main>:not(#ins-chart){margin-inline:8px}
.ins-box{position:relative;isolation:isolate;contain:paint;cursor:crosshair;touch-action:pan-y;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;border-radius:var(--rm);background:var(--surface);border:1px solid var(--line);overflow:hidden}
.ins-box:focus-visible{outline:3px solid var(--focus);outline-offset:2px}
.ins-box>.ltr,.ins-box .gchart{position:relative;height:100%}
.ins-box .gchart text{font-size:11px}
.ins-box .gchart .grid{stroke:var(--line)}
.ins-box .gchart .grid.y{stroke-dasharray:1 5;opacity:.8}
.ins-box .gchart text.yl{fill:var(--mut);font-size:10.5px}
/* the y label's backing: the card colour at 85%, so a label stays readable where the curve passes it */
.ins-curve .ylb{fill:var(--surface);opacity:.85}
/* the range: a very faint band and its edges as two quiet lines */
.ins-curve .band{fill:var(--band);opacity:.55}
.ins-curve .redge{stroke:var(--c);stroke-width:1;stroke-dasharray:6 4;opacity:.55}
.ins-curve .line.zl{stroke-width:3.4}
.ins-curve .ghost-b{fill:var(--mut);opacity:.14}
.ins-curve .ghost-l{fill:none;stroke:var(--mut);stroke-width:1.6;stroke-dasharray:3 4;opacity:.7}
.ins-curve .wk{fill:var(--b);opacity:.07}
.ins-curve .win{fill:var(--b);opacity:0;transition:opacity .2s}
.ins-curve .win.on{opacity:.13}
.ins-curve .lead{stroke:var(--b);stroke-width:1;opacity:.4}
.ins-curve .dot{fill:var(--b);stroke:var(--surface);stroke-width:2.4}
.ins-curve .now{fill:var(--ink)}
.ins-curve .halo{fill:var(--ink);opacity:.14}
@media (prefers-reduced-motion:no-preference){
  .ins-curve .line.draw{stroke-dasharray:1;stroke-dashoffset:1;animation:ins-draw 1s cubic-bezier(.3,.6,.3,1) forwards}
  .ins-curve .area.draw{animation:ins-fade 1s ease-out both}
}
@keyframes ins-draw{to{stroke-dashoffset:0}}
@keyframes ins-fade{from{opacity:0}}
/* sleep: the night's shading with its moon and hours */
.ins-night{position:absolute;top:0;bottom:22px;background:linear-gradient(180deg,color-mix(in srgb,var(--a-soft) 85%,transparent),color-mix(in srgb,var(--a-soft) 35%,transparent))}
/* the night's label sits at its end edge (the box is ltr: the morning side), clear of the y labels at the start */
.ins-nightl{position:absolute;inset-inline-end:4px;display:inline-flex;align-items:center;gap:4px;min-height:26px;padding:0 8px;border:0;border-radius:var(--pill);background:var(--surface);color:var(--a);font:800 .7rem/1 var(--sans);white-space:nowrap;cursor:pointer;box-shadow:var(--shadow-sm)}
.ins-nightl .i{width:14px;height:14px}
/* the hit area: 48 px each way around the small pill, drawn by nothing (docs/design/ux-redesign-lld.md 7.2); the
   button itself never clips (its text does), so a tap anywhere on the area reaches it */
.ins-nightl::before,.ins-ctxb::before{content:'';position:absolute;inset:min(0px,calc((100% - 48px) / 2))}
/* Today's meal labels in their rows over the plot (insights-chart.yaml labels, stackLabels) */
.ins-mls{position:absolute;inset:0;pointer-events:none}
.ins-ml{position:absolute;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;padding:0 6px;border:1px solid color-mix(in srgb,var(--b) 45%,transparent);border-radius:9px;background:var(--b-soft);color:var(--ink);overflow:hidden;cursor:pointer;pointer-events:auto;font-family:var(--sans)}
.ins-ml b{max-width:100%;font-size:.68rem;font-weight:800;line-height:1.1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ins-ml small{font-size:.64rem;font-weight:800;line-height:1.1;color:var(--b);white-space:nowrap}
.ins-ml.more{flex-direction:row;gap:4px;border-color:var(--b);background:var(--surface);color:var(--b);font-size:.7rem;font-weight:800}
.ins-ml.more .i{width:13px;height:13px}
/* workouts and other entries along the bottom (insights-chart.yaml ctx, packLanes) */
.ins-ctx{position:absolute;inset-inline:0;pointer-events:none}
.ins-ctxb{position:absolute;display:inline-flex;align-items:center;justify-content:center;gap:4px;padding:0 6px;border:1px solid var(--b);border-radius:8px;background:color-mix(in srgb,var(--b-soft) 90%,transparent);color:var(--ink);font:700 .7rem/1 var(--sans);white-space:nowrap;cursor:pointer;pointer-events:auto}
.ins-ctxb .i{width:15px;height:15px;flex:none;color:var(--b)}
.ins-ctxb span{min-width:0;overflow:hidden;text-overflow:clip}
.ins-ctxb.pt{padding:0;border-radius:50%}
.ins-ctxb.more{padding:0 6px;border-radius:var(--pill);border-color:var(--ink2);background:var(--surface);color:var(--ink);font-weight:800}
/* the reading: a crosshair and a bubble placed where it hides the least of the curve (insights-scrub.js placeBubble) */
.ins-scrub{position:absolute;inset:0;width:100%;height:100%;pointer-events:none;opacity:0;transition:opacity .35s}
.ins-scrub .cursor,.ins-scrub .hx{stroke:var(--ink2);stroke-width:1;stroke-dasharray:3 3}
.ins-scrub .now{fill:var(--ink);stroke:var(--surface);stroke-width:2.5}
.ins-ro{position:absolute;top:0;display:flex;flex-flow:row wrap;align-items:baseline;column-gap:8px;row-gap:0;max-width:min(100%,240px);padding:6px 11px;border:1px solid var(--line);border-radius:var(--rm);background:var(--surface);box-shadow:var(--shadow);pointer-events:none;opacity:0;transition:opacity .35s}
.ins-box.scrubbing .ins-scrub,.ins-box.scrubbing .ins-ro{opacity:1;transition:none}
@media (prefers-reduced-motion:reduce){.ins-scrub,.ins-ro,.ins-curve .win{transition:none}}
.ins-ro-t{font-size:.75rem;font-weight:700;color:var(--mut)}
.ins-ro-v b{font-size:1.2rem;font-weight:800;color:var(--ink)}
.ins-ro-g{display:inline-block;margin-inline-start:4px;padding:1px 8px;border-radius:var(--pill);border:1px solid currentColor;font-size:.72rem;font-weight:800}
.ins-lv-in{color:var(--c);background:var(--c-soft)}
.ins-lv-high{color:var(--d);background:var(--d-soft)}
.ins-lv-low,.ins-lv-vhigh{color:var(--red);background:var(--red-t)}
.ins-ro-m{flex-basis:100%;font-size:.76rem;color:var(--ink2);white-space:normal;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;line-clamp:2;overflow:hidden}
/* while reading, the labels in the band the bubble docks in step back */
.ins-mls,.ins-nightl{transition:opacity .35s}
.ins-box.scrubbing .ins-mls,.ins-box.scrubbing .ins-nightl{opacity:.15;transition:none}
.legend i.ins-lg{width:16px;height:4px;border-radius:2px;background:var(--c)}
.legend i.ins-lw{width:14px;height:9px;border-radius:3px;border:1px solid var(--b);background:var(--b-soft)}
.legend i.ins-ls{width:14px;height:9px;border-radius:3px;background:var(--a-soft);border:1px solid var(--a)}
/* the keyboard reading is spoken, not shown */
.ins-live{position:absolute;width:1px;height:1px;margin:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}

/* The hero line over the day chart: the latest reading large, then three small stats and the ghost chip. */
.ins-hero{display:flex;flex-direction:column;gap:8px;margin-block:4px 10px}
.ins-hnow{display:flex;align-items:center;flex-wrap:wrap;gap:6px 10px}
.ins-hnow>b{font:800 2.6rem/1 var(--sans);letter-spacing:-.02em;color:var(--ink)}
.ins-hunit{font-size:.8rem;font-weight:700;color:var(--mut);align-self:flex-end;padding-block-end:5px}
.ins-htrend{display:inline-grid;place-items:center;width:30px;height:30px;border-radius:50%;background:var(--surface2);color:var(--ink)}
.ins-htrend .i{width:18px;height:18px}
.ins-hmeta{display:flex;flex-direction:column;align-items:flex-start;gap:3px}
.ins-hmeta small{font-size:.74rem;color:var(--mut);font-weight:700}
/* the arrow keeps its drawn direction in Hebrew: it points the way the chart's time runs */
.ins-hstats{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:6px}
.ins-hstat{display:flex;flex-direction:column;align-items:flex-start;gap:3px;min-height:48px;padding:6px 10px;border:1px solid var(--line);border-radius:var(--rm);background:var(--surface);color:var(--mut);font:700 .7rem/1.1 var(--sans);text-align:start;cursor:pointer;min-width:0}
.ins-hstat>span{max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ins-hstat b{font-size:1.05rem;font-weight:800;color:var(--ink)}
.ins-hstat[aria-expanded=true]{border-color:var(--a);box-shadow:0 0 0 1px var(--a)}
.ins-ghostchip{min-height:48px;padding:0 12px;border:1px dashed var(--mut);border-radius:var(--pill);background:none;color:var(--mut);font:700 .76rem/1 var(--sans);cursor:pointer;margin-inline-start:auto}
.ins-ghostchip[aria-pressed=true]{border-style:solid;border-color:var(--ink2);background:var(--surface2);color:var(--ink)}
.ins-hx{margin:0;color:var(--ink2)}

/* A ranked food: the name and its bar take the width, the rise sits at the end. */
.lrow.ins-rank{grid-template-columns:minmax(0,1fr) auto}
.lrow.ins-rank .what{gap:6px}

/* the biggest rise's meal wraps whole words onto a second line in a narrow tile instead of being cut with "..." */
.ins-bigname{font-size:.7rem;line-height:1.25;overflow-wrap:normal;word-break:normal;hyphens:auto}

/* About to eat? */
:is(#app,#pane) .card.ins-ask,:is(#app,#pane).screen .card.ins-ask{display:grid;grid-template-columns:auto minmax(0,1fr) auto;align-items:center;gap:14px;padding:16px 18px;min-height:48px}
.ins-ask .rowic{background:linear-gradient(135deg,var(--p1),var(--p2));color:var(--on-p)}
.ins-ask .tt,.ins-more .tt{display:flex;flex-direction:column;min-width:0}
.ins-ask .tt b{font-weight:700;color:var(--ink)}
.ins-ask .tt small{color:var(--mut);font-size:.8rem;font-weight:500}

/* More analysis: the Explore tools as a list. */
/* its card: the fold's one line keeps 48 px, the card's edge replaces the fold's top rule */
.card.ins-more{padding-block:4px}
.ins-more>details.fold{border-top:0}
.ins-more .item{width:100%;background:none;text-align:start;cursor:pointer;color:var(--ink);font:inherit}

/* Details: each graded statistic is a row of name, value and grade word, a tap target that opens its explanation.
   The grade colours and their three depths are Today's pills' (css/today.css), so a grade reads the same on both. */
.ins-stats{display:flex;flex-direction:column}
.ins-stat+.ins-stat{border-top:1px solid var(--line)}
.ins-statrow{display:grid;grid-template-columns:minmax(0,1fr) auto auto;align-items:center;gap:10px;width:100%;min-height:48px;padding:6px 0;background:none;border:0;color:var(--ink);font:inherit;text-align:start;cursor:pointer}
.ins-sname{font-size:.88rem;color:var(--ink2);min-width:0}
.ins-statrow b{font-weight:700;font-variant-numeric:tabular-nums}
.ins-grade{display:inline-flex;align-items:center;min-height:26px;padding:0 10px;border-radius:var(--pill);border:1px solid var(--line);background:var(--surface2);color:var(--mut);font-size:.76rem;font-weight:800;white-space:nowrap}
.ins-good{color:var(--c);border-color:var(--c)}
.ins-fair{color:var(--d);border-color:var(--d)}
.ins-poor{color:var(--red);border-color:var(--red)}
.ins-good.ins-s1{background:color-mix(in srgb,var(--c-soft) 45%,var(--surface))}
.ins-good.ins-s2{background:color-mix(in srgb,var(--c-soft) 75%,var(--surface))}
.ins-good.ins-s3{background:var(--c-soft)}
.ins-fair.ins-s1{background:color-mix(in srgb,var(--d-soft) 45%,var(--surface))}
.ins-fair.ins-s2{background:color-mix(in srgb,var(--d-soft) 75%,var(--surface))}
.ins-fair.ins-s3{background:var(--d-soft)}
.ins-poor.ins-s1{background:color-mix(in srgb,var(--red-t) 45%,var(--surface))}
.ins-poor.ins-s2{background:color-mix(in srgb,var(--red-t) 75%,var(--surface))}
.ins-poor.ins-s3{background:var(--red-t)}
.ins-unknown{font-weight:600}
.ins-sx{margin:0 0 10px;color:var(--mut)}
/* Explore → Summary: one full-width card per day, a row of stat tiles, then one-line extras. */
.sum-days{display:grid;gap:12px;margin-block-end:12px}
.sum-days>.card{margin:0}
/* the tiles share the card's width: one tile is the whole line, three are a third each */
.sum-tiles{display:grid;grid-template-columns:repeat(auto-fit,minmax(72px,1fr));gap:8px;margin-block:8px}
.sum-tile{background:var(--bg);border:1px solid var(--line);border-radius:10px;padding:8px 6px;text-align:center;display:flex;flex-direction:column;gap:2px;min-inline-size:0}
.sum-tile b{font-size:1.25rem;line-height:1.1}
.sum-tile span{font-size:.75rem;color:var(--mut)}
.sum-rise{display:flex;flex-direction:column;justify-content:center;gap:2px;align-items:flex-start;inline-size:100%;min-block-size:48px;background:none;border:0;padding:0;font:inherit;font-size:.875rem;color:var(--ink);text-align:start;cursor:pointer}
.sum-rise>span:first-child{flex:none;font-weight:600}
.sum-rise-m{min-inline-size:0;max-inline-size:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--a,var(--accent))}
.sum-line{margin:4px 0 0}
/* the night's label never runs past the night (or the chart's start): views/insights-scale.js nightLabel sizes it */
.ins-nightl{max-width:calc(100% - 8px)}
.ins-nightl .num{min-width:0;overflow:hidden}
