/* Insights: KPIs, the last 14 days, typical day / weekdays / months, unusual days.
   Styles for this area only; colours and sizes come from the tokens in theme.css (no raw colour values here). */

/* ============================== the screen ============================== */

/* A grid, not .stack: a block that is hidden (loading, empty, error) must not leave a gap behind it. */
.ins-screen {
  display: grid;
  gap: var(--space-24);
  align-content: start;
}

.ins-screen > * {
  min-width: 0;
}

.ins-loading {
  display: grid;
  gap: var(--space-24);
}

.ins-error {
  display: grid;
  gap: var(--space-12);
}

.ins-error-actions {
  display: flex;
}

.ins-unavailable {
  margin: 0;
}

/* ============================== the four figures ============================== */

.ins-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-8) var(--space-12);
  margin-bottom: var(--space-12);
}

.ins-based {
  margin: 0;
}

/* Two by two on a phone, four across from a tablet up. */
.ins-kpis {
  display: grid;
  gap: var(--space-12);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 640px) {
  .ins-kpis {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.ins-history {
  margin: var(--space-12) 0 0;
}

/* ============================== the last days ============================== */

.ins-days-help {
  margin: 0 0 var(--space-12);
}

.ins-key {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-16);
  margin: 0 0 var(--space-8);
  padding: 0;
  list-style: none;
  color: var(--text-2-strong);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
  font-weight: var(--weight-medium);
}

.ins-key li {
  display: inline-flex;
  align-items: center;
  gap: var(--space-6);
}

.ins-key-swatch {
  box-sizing: border-box;
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.sw-solar {
  background: var(--energy-solar);
}

.sw-used {
  background: var(--energy-home);
}

.sw-import {
  background: var(--energy-grid);
}

/* The lighter blue has an edge in the grid's own colour, as its bars do. */
.sw-export {
  border: 1px solid var(--energy-grid);
  background: var(--energy-grid-export);
}

/* The weekend band, as it is in the chart: the fill, with a thin edge so a pale swatch still shows on the card. */
.sw-weekend {
  border: 1px solid var(--border-strong);
  background: var(--fill);
}

.ins-trend-text {
  margin: var(--space-12) 0 0;
}

.ins-days-content > .ui-disclosure {
  margin-top: var(--space-12);
}

.ins-days-error {
  display: grid;
  gap: var(--space-12);
  justify-items: start;
}

/* ---------- the chart (one SVG; every colour is a class, so a theme change needs no redraw) ---------- */

.idc {
  min-width: 0;
}

.idc-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.idc-line {
  stroke: var(--chart-grid);
  stroke-width: 1;
  stroke-dasharray: 2 4;
}

.idc-line.is-zero {
  stroke: var(--border-strong);
  stroke-width: 1.5;
  stroke-dasharray: none;
}

.idc-tick {
  fill: var(--chart-text);
  font-size: var(--text-xs-size);
  font-variant-numeric: tabular-nums;
}

/* A day is a button: the whole column is the target, from the top of the bars to the date. */
.idc-day {
  cursor: pointer;
  outline: none;
}

.idc-hit {
  fill: none;
  pointer-events: all;
  transition: fill var(--dur-1) var(--ease-out);
}

/* Weekend columns sit on a faint band (named "Weekend" in the key), which also helps to find a weekday in a row of fourteen. */
.idc-day.is-weekend .idc-hit {
  fill: var(--fill);
}

@media (hover: hover) {
  .idc-day:hover .idc-hit {
    fill: var(--border);
  }
}

.idc-day:focus-visible .idc-hit {
  fill: var(--fill);
  stroke: var(--focus-ring);
  stroke-width: 2;
}

.idc-bar {
  transition: fill-opacity var(--dur-2) var(--ease-out);
}

.idc-solar {
  fill: var(--energy-solar);
}

.idc-used {
  fill: var(--energy-home);
}

.idc-import {
  fill: var(--energy-grid);
}

/* The lighter export bar keeps its shape against the card with an edge in the grid's colour. */
.idc-export {
  fill: var(--energy-grid-export);
  stroke: var(--energy-grid);
  stroke-width: 1;
}

/* A day with data for only part of it: dashed, paler bars (the shape says it, not only the colour). */
.idc-day.is-partial .idc-bar {
  fill-opacity: 0.35;
  stroke-width: 1.25;
  stroke-dasharray: 3 2;
}

.idc-day.is-partial .idc-solar {
  stroke: var(--energy-solar);
}

.idc-day.is-partial .idc-used {
  stroke: var(--energy-home);
}

.idc-day.is-partial .idc-import {
  stroke: var(--energy-grid);
}

/* A day nothing was summarised for: a faint dashed outline where its bars would meet the line. */
.idc-ph {
  fill: var(--surface-2);
  stroke: var(--border-strong);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.idc-val {
  fill: var(--text-2);
  font-size: var(--text-xs-size);
  font-variant-numeric: tabular-nums;
}

.idc-axis {
  fill: var(--text-2);
  font-size: var(--text-xs-size);
}

.idc-axis-date {
  fill: var(--text);
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
}

.idc-axis-month {
  font-size: var(--text-xs-size);
}

/* The first draw: the bars grow from the line, one day after the other. */
@keyframes idc-grow {
  from {
    transform: scaleY(0);
  }

  to {
    transform: scaleY(1);
  }
}

@keyframes idc-appear {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.idc-enter .idc-bar {
  transform-box: fill-box;
  animation: idc-grow var(--dur-3) var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 24ms);
}

.idc-enter .idc-solar,
.idc-enter .idc-used {
  transform-origin: 50% 100%;
}

.idc-enter .idc-import,
.idc-enter .idc-export {
  transform-origin: 50% 0;
}

.idc-enter .idc-val {
  animation: idc-appear var(--dur-3) var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 24ms + 120ms);
}

/* ============================== the patterns ============================== */

.ins-patterns .seg {
  margin-bottom: var(--space-16);
}

.ins-chart-title {
  margin: 0 0 var(--space-4);
}

.chart-frame.ins-chart-frame {
  height: 260px;
}

.ins-notes {
  display: grid;
  gap: var(--space-4);
}

.ins-notes:not(:empty) {
  margin-top: var(--space-8);
}

.ins-notes .caption {
  margin: 0;
}

.ins-patterns .ui-disclosure {
  margin-top: var(--space-16);
}

/* The swatches of the Chart.js legends take the colour of what they stand for. */
.legend .swatch.k-home {
  color: var(--energy-home);
}

.legend .swatch.k-weekend {
  color: var(--series-export);
}

.legend .swatch.k-grid {
  color: var(--energy-grid);
}

.legend .swatch.k-grid-export {
  color: var(--energy-grid-export);
}

/* Two columns on a wide desktop: the chart wide, the unusual days beside it (both cards the same height). Below 1200px the
   unusual days would be squeezed into a strip too narrow for their rows, so they sit under the chart instead. */
.ins-grid {
  display: grid;
  gap: var(--space-24);
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
}

@media (min-width: 1200px) {
  .ins-grid {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  }
}

/* The list sits in its card with no frame of its own; the first row needs no divider above it. */
.ins-unusual .ui-list-flat {
  margin: 0 calc(-1 * var(--space-4));
}

/* ============================== the foot ============================== */

.ins-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-12) var(--space-16);
  padding-top: var(--space-16);
  border-top: 1px solid var(--border);
}

.ins-foot-text {
  flex: 1 1 280px;
  min-width: 0;
}

.ins-coverage {
  margin: 0;
}

.ins-last-error:not(:empty) {
  margin-top: var(--space-8);
}

/* ============================== a day's sheet ============================== */

/* Two by two even on a phone: the four figures belong side by side. */
.ins-sheet-stats {
  display: grid;
  gap: var(--space-12);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.ins-facts {
  display: grid;
  margin: var(--space-4) 0 0;
  padding: 0;
}

.ins-sheet-stats .ui-stat {
  align-content: start;
}

.ins-facts > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-12);
  padding: var(--space-12) 0;
  border-top: 1px solid var(--border-raised);
}

.ins-facts dt {
  color: var(--text-2);
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
}

.ins-facts dd {
  margin: 0;
  color: var(--text);
  font-size: var(--text-md-size);
  line-height: var(--text-md-line);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
  .idc-enter .idc-bar,
  .idc-enter .idc-val {
    animation: none;
  }
}
