/*! charts.css 1.0.1 | DJ2000-UK/app-workbench */
/* The family's trend card (charts/charts.js), in Kaizen's Progress → Trends look:
   the name and the average on top, the chart, the range buttons under it inside
   the card, and three tiles. Every colour is one of the app's own tokens (--ink,
   --muted-bright, --muted, --line, --panel, --panel-bright, --void, --positive,
   --accent-rgb, and --health or --danger for worse), so it follows the palette in
   djcns.css, Kaizen, Shinpo and Hokyu alike. Unlayered and scoped to .trend-*.

   An app may set, on the card or anything round it:
     --trend-tone          the line's and the card's colour (charts.card's `tone` sets it)
     --trend-plot-height   the chart's height (240 px; 210 px on a phone) */

.trend-card {
  --trend-ink: var(--trend-tone, rgb(var(--accent-rgb)));
  --trend-bad: var(--health, var(--danger));
  display: grid;
  min-width: 0;
  gap: 12px;
  padding: 16px 16px 14px;
  border: 1px solid color-mix(in srgb, var(--trend-ink) 26%, var(--line));
  border-radius: 22px;
  background:
    radial-gradient(circle at 0 0, color-mix(in srgb, var(--trend-ink) 10%, transparent), transparent 70%),
    linear-gradient(150deg, color-mix(in srgb, var(--panel-bright, var(--panel)) 66%, transparent), color-mix(in srgb, var(--panel) 76%, transparent));
  color: var(--ink);
}
/* The plain palettes, Light and Dark (DESIGN.md, "The plain palettes"): one flat
   panel, no tint and no gradient. Kaizen keys its palettes on data-theme, the
   others on data-palette. */
:root:is([data-palette="athletic-light"], [data-palette="athletic-dark"], [data-theme="athletic-light"], [data-theme="athletic-dark"]) .trend-card { background: var(--panel); }

.trend-card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; min-width: 0; }
.trend-card__head > div { min-width: 0; }
.trend-card .trend-card__head .trend-card__title { margin: 0; text-transform: none; color: var(--trend-ink); font-size: 17px; font-weight: 650; letter-spacing: -.01em; line-height: 1.25; overflow-wrap: anywhere; }
.trend-card .trend-card__head .trend-card__source { margin: 4px 0 0; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted-bright); font-size: 12px; line-height: 1.35; }
.trend-card .trend-card__value { display: grid; flex: none; justify-items: end; margin: 0; text-align: right; }
.trend-card .trend-card__value strong { color: var(--ink); font-size: 30px; font-weight: 650; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.trend-card .trend-card__value small { margin-top: 5px; color: var(--muted); font-size: 8px; font-weight: 700; letter-spacing: .1em; line-height: 1.2; white-space: nowrap; }

/* The chart. Drawn at the plot's own width (charts.js measures it), so the type
   is true to size at any width. A sideways move reads off a day; up and down
   still scroll the page. */
.trend-plot {
  position: relative;
  height: var(--trend-plot-height, 240px);
  min-width: 0;
  margin: 0 -4px;
  overflow: hidden;
  border-radius: 10px;
  outline: none;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.trend-plot:focus-visible { box-shadow: 0 0 0 2px var(--trend-ink); }
.trend-plot__svg { display: block; overflow: visible; font-family: inherit; }
.trend-plot__tick { fill: var(--muted-bright); font-size: 11px; font-variant-numeric: tabular-nums; }
.trend-plot__grid { stroke: color-mix(in srgb, var(--muted-bright) 12%, transparent); stroke-width: 1; }
.trend-plot__line { fill: none; stroke: var(--trend-ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.trend-plot__fill-top { stop-color: var(--trend-ink); stop-opacity: .22; }
.trend-plot__fill-end { stop-color: var(--trend-ink); stop-opacity: .03; }
.trend-plot__point { fill: var(--void); stroke: var(--trend-ink); stroke-width: 1.6; }
.trend-plot__point--lone { fill: var(--trend-ink); }
.trend-plot__dot { fill: color-mix(in srgb, var(--muted-bright) 55%, transparent); }
.trend-plot__bar { fill: color-mix(in srgb, var(--trend-ink) 72%, transparent); }
.trend-plot__bar--partial { fill: color-mix(in srgb, var(--trend-ink) 28%, transparent); }
.trend-plot__bar-label { fill: var(--ink); font-size: 10px; font-weight: 700; }
.trend-plot__target { fill: none; stroke: color-mix(in srgb, rgb(var(--secondary-rgb, var(--accent-rgb))) 80%, transparent); stroke-width: 1.5; stroke-dasharray: 4 4; }

/* The average: a dotted line across the chart and its tag (DJ, 2026-11-30). */
.trend-plot__avg { stroke: color-mix(in srgb, var(--ink) 55%, transparent); stroke-width: 1.6; stroke-dasharray: 0 5; stroke-linecap: round; }
.trend-plot__avg-tag {
  position: absolute;
  z-index: 1;
  padding: 2px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--trend-ink) 34%, var(--panel));
  color: var(--ink);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.35;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  transform: translateY(-50%);
}
.trend-plot[data-scrubbing] .trend-plot__avg-tag { opacity: .35; }

/* Days with no record: hatching, a dotted line across them, or both. */
.trend-plot__hatch-line { stroke: color-mix(in srgb, var(--trend-ink) 50%, transparent); stroke-width: 1.3; }
.trend-plot__gap { opacity: .9; }
.trend-plot__bridge { stroke: color-mix(in srgb, var(--trend-ink) 80%, transparent); stroke-width: 2; stroke-dasharray: 0 4.5; stroke-linecap: round; }

/* A finger on the chart: a line down to the day and a dot on its reading. */
.trend-plot__scrub[hidden] { display: none; }
.trend-plot__scrub-line { stroke: color-mix(in srgb, var(--ink) 40%, transparent); stroke-width: 1; }
.trend-plot__scrub-dot { fill: var(--trend-ink); stroke: var(--panel-bright, var(--panel)); stroke-width: 2.5; }

.trend-card .trend-empty { margin: 0; padding: 40px 8px; color: var(--muted); font-size: 13px; text-align: center; }

/* The range: 30D 90D 1Y All Custom under the chart, inside the card. Each
   button is a full 44 px target; the pill drawn in it is 36 px, as Kaizen's. */
.trend-range { display: flex; gap: 4px; margin: -6px 0 -4px; }
.trend-range button {
  position: relative;
  isolation: isolate;
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted-bright);
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: .02em;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.trend-range button::before { content: ""; position: absolute; z-index: -1; inset: 4px 0; border-radius: 999px; }
.trend-range button[aria-pressed="true"] { color: var(--ink); }
.trend-range button[aria-pressed="true"]::before { background: color-mix(in srgb, var(--trend-ink) 22%, transparent); }
.trend-range button:focus-visible { outline: none; }
.trend-range button:focus-visible::before { outline: 2px solid var(--trend-ink); outline-offset: 0; }

/* Latest, the change over the range, and the best. */
.trend-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.trend-stats > div { --trend: var(--ink); display: grid; gap: 4px; min-width: 0; padding: 10px 11px; border: 1px solid var(--line); border-radius: 14px; background: color-mix(in srgb, var(--panel) 60%, transparent); }
.trend-stats > div[data-trend="good"] { --trend: var(--positive); }
.trend-stats > div[data-trend="bad"] { --trend: var(--trend-bad); }
.trend-stats strong { display: flex; align-items: center; gap: 3px; overflow: hidden; color: var(--trend); font-size: 17px; font-weight: 650; letter-spacing: -.02em; white-space: nowrap; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.trend-stats strong svg { flex: none; width: 15px; height: 15px; }
/* LOW–HIGH breaks after its dash rather than being cut off on a narrow phone. */
.trend-stats > div[data-wrap] strong { flex-wrap: wrap; overflow: visible; white-space: normal; line-height: 1.15; }
.trend-stats small { color: var(--muted); font-size: 8px; font-weight: 700; letter-spacing: .1em; }
.trend-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Custom: a sheet from the foot of a phone, centred on a wide screen. */
.trend-sheet {
  position: fixed;
  inset: auto 0 0;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  max-height: calc(100dvh - 24px);
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 27px 27px 0 0;
  background: var(--panel-bright, var(--panel));
  color: var(--ink);
  box-shadow: 0 -18px 60px color-mix(in srgb, var(--void) 70%, transparent);
}
.trend-sheet::backdrop { background: color-mix(in srgb, var(--void) 62%, transparent); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); opacity: var(--sheet-drag-fade, 1); }
.trend-sheet__body { display: grid; gap: 14px; padding: 28px 20px calc(20px + env(safe-area-inset-bottom, 0px)); }
.trend-sheet h2 { margin: 0; font-size: 23px; font-weight: 600; letter-spacing: -.03em; line-height: 1.15; }
.trend-sheet__copy { margin: -6px 0 0; color: var(--muted-bright); font-size: 14px; line-height: 1.4; }
.trend-sheet__fields { display: grid; padding: 2px 14px; border: 1px solid var(--line); border-radius: 16px; background: color-mix(in srgb, var(--panel) 70%, transparent); }
.trend-sheet__fields > div + div { border-top: 1px solid var(--line); }
.trend-sheet__plain { display: flex; min-height: 50px; align-items: center; justify-content: space-between; gap: 12px; font-size: 16px; }
.trend-sheet__plain input { font: inherit; font-size: 16px; }
.trend-sheet__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.trend-sheet__actions button { min-height: 50px; border: 1px solid var(--line); border-radius: 999px; background: none; color: var(--ink); font: inherit; font-size: 16px; font-weight: 650; cursor: pointer; }
.trend-sheet__actions .trend-sheet__show { border-color: transparent; background: color-mix(in srgb, rgb(var(--accent-rgb)) 26%, transparent); }
.trend-sheet__actions button:focus-visible { outline: 2px solid rgb(var(--accent-rgb)); outline-offset: 2px; }

@media (max-width: 900px) {
  .trend-plot { height: var(--trend-plot-height, 210px); }
}
@media (min-width: 901px) {
  .trend-sheet { inset: 50% auto auto 50%; width: min(460px, calc(100vw - 32px)); border-bottom: 1px solid var(--line); border-radius: 27px; transform: translate(-50%, -50%); }
}
@media (max-width: 359px) {
  .trend-card { padding: 14px 12px 12px; }
  .trend-range button { font-size: 12px; letter-spacing: 0; }
  .trend-stats { gap: 6px; }
  .trend-stats > div { padding: 9px 8px; }
  .trend-stats strong { font-size: 15px; }
}
