/* Plan: summary, timeline, grouped schedule, the slot sheet, the half-hour table, the 48 hour chart, what changed, the shadow
   ledger. Styles for this area only; colours and sizes come from the tokens in theme.css (no raw colour values here). The
   timeline is an SVG whose geometry is attributes (public/js/timelineModel.js): everything that is a colour or a stroke is here. */

/* ============================== layout ============================== */

.plan-stack {
  display: grid;
  gap: var(--space-24);
  min-width: 0;
}

.plan-stack > * {
  min-width: 0;
}

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

/* The chart and what changed side by side where there is room; the chart gets the width. */
.plan-pair {
  display: grid;
  gap: var(--space-24);
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
}

@media (min-width: 1024px) {
  .plan-pair {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    align-items: start;
  }
}

/* ============================== summary ============================== */

.plan-summary .card-head button {
  min-height: 40px;
}

.plan-headline {
  display: grid;
  gap: 0;
  margin: 0;
}

.plan-headline-lead {
  color: var(--text-2);
  font-size: var(--text-md-size);
  line-height: var(--text-md-line);
  font-weight: var(--weight-medium);
}

.plan-headline-fig {
  color: var(--accent);
  font-size: var(--display-sm-size);
  line-height: var(--display-sm-line);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.plan-headline-tail {
  color: var(--text-2);
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
}

.plan-chips {
  margin-top: var(--space-12);
  gap: var(--space-6) var(--space-8);
}

/* Three figures in a row, divided by hairlines. */
.plan-facts-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-12);
  margin-top: var(--space-16);
  padding-top: var(--space-16);
  border-top: 1px solid var(--border);
}

.plan-facts-row .ui-stat {
  padding-left: var(--space-12);
  border-left: 1px solid var(--border);
}

.plan-facts-row .ui-stat:first-child {
  padding-left: 0;
  border-left: 0;
}

.plan-facts-row .ui-stat-label {
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
}

.plan-summary > .caption-sm {
  margin: var(--space-12) 0 0;
}

.plan-notes {
  margin-top: var(--space-16);
}

/* On a wide screen the headline sits beside the figures instead of above them. */
@media (min-width: 1024px) {
  .plan-summary-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr);
    gap: var(--space-32);
    align-items: start;
  }

  .plan-detail {
    padding-left: var(--space-32);
    border-left: 1px solid var(--border);
  }

  .plan-detail .plan-facts-row {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }
}

/* ============================== timeline ============================== */

.plan-timeline .card-head {
  margin-bottom: var(--space-8);
}

/* One line above the picture: the hint, or the half hour under the mouse. */
.tl-readout {
  margin: 0 0 var(--space-8);
  min-height: var(--text-sm-line);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tl-frame {
  width: 100%;
  min-width: 0;
}

.tl-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}

.tl-lane {
  fill: var(--surface-2);
  stroke: var(--border);
  stroke-width: 1;
}

.tl-gridline {
  stroke: var(--border);
  stroke-width: 1;
}

.tl-sep {
  stroke: var(--border-strong);
  stroke-width: 1;
  stroke-dasharray: 2 3;
}

.tl-tick {
  stroke: var(--border-strong);
  stroke-width: 1;
}

.tl-text {
  fill: var(--text-2);
  font-family: var(--font-sans);
  font-size: var(--text-xs-size);
  font-variant-numeric: tabular-nums;
}

.tl-day {
  fill: var(--text);
  font-weight: var(--weight-semibold);
}

/* The price axis (50p, 0p): a column of its own left of the picture, so no line can pass under a label. */
.tl-axis-value {
  fill: var(--text-2);
}

/* Numbers sitting inside a lane get a halo in the lane's own colour so a line passing under them cannot spoil them. */
.tl-label {
  paint-order: stroke;
  stroke: var(--surface-2);
  stroke-width: 3px;
  stroke-linejoin: round;
}

/* Mode bands: the colour of where the energy comes from; Self-use has none (its lane is just the track). */
.tl-band-rect {
  stroke-width: 1;
}

.tl-band-GRID_CHARGE .tl-band-rect {
  fill: var(--band-grid-charge);
  stroke: var(--mode-grid-charge);
}

.tl-band-FORCE_EXPORT .tl-band-rect {
  fill: var(--band-force-export);
  stroke: var(--mode-force-export);
}

.tl-band-HOLD .tl-band-rect {
  stroke: var(--mode-hold);
}

.tl-hatch-bg {
  fill: var(--band-hold);
}

.tl-hatch-line {
  stroke: var(--hatch);
  stroke-width: 1;
}

.tl-band-icon {
  color: var(--mode-self-use);
}

.tl-band-GRID_CHARGE .tl-band-icon {
  color: var(--mode-grid-charge);
}

.tl-band-FORCE_EXPORT .tl-band-icon {
  color: var(--mode-force-export);
}

.tl-band-HOLD .tl-band-icon {
  color: var(--mode-hold);
}

.tl-band-label {
  fill: var(--text-strong);
  font-weight: var(--weight-medium);
  font-variant-numeric: normal; /* tabular figures would space the hyphen of "Self-use" out */
}

.tl-band-GRID_CHARGE .tl-band-label {
  fill: var(--energy-grid-text);
}

.tl-band-FORCE_EXPORT .tl-band-label {
  fill: var(--accent-weak-text);
}

.tl-band-SELF_USE .tl-band-label {
  fill: var(--text-2);
  font-weight: var(--weight-regular);
}

/* Prices: import solid, export dashed, anything estimated dotted. One hue (the grid's); the line style says which. */
.tl-import {
  fill: none;
  stroke: var(--energy-grid);
  stroke-width: 2;
  stroke-linejoin: round;
}

.tl-export {
  fill: none;
  stroke: var(--energy-grid);
  stroke-width: 1.5;
  stroke-dasharray: 5 3;
  opacity: 0.85; /* 0.7 left the dashes under 3:1 on the lane */
}

.tl-import.is-est,
.tl-export.is-est {
  stroke-dasharray: 0 4.5;
  stroke-linecap: round;
  stroke-width: 2.5;
}

.tl-export.is-est {
  stroke-width: 2;
}

/* Below the zero line the price is negative: you are paid to use power. */
.tl-neg-area {
  fill: var(--energy-grid);
  fill-opacity: 0.22;
}

.tl-zero {
  stroke: var(--text-2);
  stroke-width: 1;
}

.tl-base {
  stroke: var(--border-strong);
  stroke-width: 1;
}

.tl-paid-label {
  fill: var(--energy-grid-text);
  font-weight: var(--weight-medium);
}

.tl-soc-area {
  fill: var(--energy-battery);
  fill-opacity: 0.18;
  stroke: none;
}

.tl-soc-line {
  fill: none;
  stroke: var(--energy-battery);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.tl-now {
  stroke: var(--text);
  stroke-width: 1.5;
}

.tl-now-dot {
  fill: var(--text);
}

/* The look-ahead part of the plan is not acted on yet: a pale wash over it. */
.tl-wash {
  fill: var(--surface);
  fill-opacity: 0.55;
  pointer-events: none;
}

.tl-key-wash {
  fill: var(--surface-2);
  stroke: var(--border-strong);
  stroke-width: 1;
}

.tl-cursor-rect {
  fill: var(--text);
  fill-opacity: 0.07;
  pointer-events: none;
}

/* The pointer works on the whole picture; the buttons over the mode blocks are for the keyboard and draw only a ring. */
.tl-hit {
  fill: transparent;
  cursor: pointer;
}

.tl-blocks {
  pointer-events: none;
}

.tl-block,
.tl-block:focus-visible {
  outline: none;
  box-shadow: none;
}

.tl-block-ring {
  fill: none;
  stroke: transparent;
}

.tl-block:focus-visible .tl-block-ring {
  stroke: var(--focus-ring);
  stroke-width: 2;
}

.tl-key {
  display: grid;
  gap: var(--space-8);
  margin-top: var(--space-12);
}

.tl-key-modes,
.tl-key-lines {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-6) var(--space-12);
}

.tl-key-modes {
  gap: var(--space-6) var(--space-8);
}

.tl-key-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-6);
  color: var(--text-2);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
}

.tl-sw {
  flex: none;
}

.plan-table-link {
  margin-top: var(--space-12);
  padding: 0;
  font-size: var(--text-sm-size);
}

/* ============================== schedule ============================== */

.plan-days {
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* a long block title must not widen the column past the card */
  gap: var(--space-24);
}

/* Wide: the days flow down two columns (a grid of rows leaves a hole under the shorter day). */
@media (min-width: 1024px) {
  .plan-days {
    display: block;
    columns: 2;
    column-gap: var(--space-32);
  }

  .plan-day {
    break-inside: avoid;
    margin-bottom: var(--space-24);
  }

  .plan-day:last-child {
    margin-bottom: 0;
  }
}

.plan-day-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 var(--space-8);
  margin: 0 0 var(--space-8);
}

.plan-day-title .caption {
  font-weight: var(--weight-regular);
}

.plan-blocks {
  display: grid;
  gap: var(--space-8);
}

/* A block: a rail in the colour of its mode, the mode's icon, the range and what it does, and a chevron that opens its half hours. */
.plan-block.ui-disclosure {
  --rail: var(--mode-self-use);
  position: relative;
  padding: 0 var(--space-8) 0 var(--space-20);
  border: 1px solid var(--border);
  border-radius: var(--radius-12);
  background: var(--surface);
}

.plan-block::before {
  content: '';
  position: absolute;
  left: var(--space-6);
  top: var(--space-12);
  bottom: var(--space-12);
  width: 4px;
  border-radius: var(--radius-full);
  background: var(--rail);
}

/* Two classes, to beat the Self-use rail on `.plan-block.ui-disclosure` above. */
.plan-block.plan-block-GRID_CHARGE {
  --rail: var(--mode-grid-charge);
}

.plan-block.plan-block-FORCE_EXPORT {
  --rail: var(--mode-force-export);
}

.plan-block.plan-block-HOLD {
  --rail: var(--mode-hold);
}

.plan-block .ui-disc-summary {
  align-items: flex-start;
  min-height: 56px;
  padding: var(--space-12) 0;
  font-weight: var(--weight-regular);
}

.plan-block .ui-disc-chevron {
  margin-top: var(--space-6);
}

.plan-block-main {
  display: flex;
  align-items: flex-start;
  gap: var(--space-12);
  min-width: 0;
}

.plan-block-icon {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-8);
  background: var(--fill);
  color: var(--rail);
}

.plan-block-GRID_CHARGE .plan-block-icon {
  background: var(--band-grid-charge);
}

.plan-block-FORCE_EXPORT .plan-block-icon {
  background: var(--band-force-export);
}

.plan-block-HOLD .plan-block-icon {
  background-color: var(--band-hold);
  background-image: repeating-linear-gradient(135deg, transparent 0 4px, var(--hatch) 4px 5px);
}

.plan-block-text {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
}

.plan-block-title {
  color: var(--text);
  font-size: var(--text-md-size);
  line-height: var(--text-md-line);
  font-weight: var(--weight-medium);
}

.plan-block-title strong {
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

.plan-block-reason {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  color: var(--text-2);
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
  font-weight: var(--weight-regular);
}

.plan-block-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4) var(--space-8);
  color: var(--text-2);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
  font-weight: var(--weight-regular);
}

.plan-block .ui-disc-body {
  padding: 0 0 var(--space-4);
}

.plan-slots {
  border-top: 1px solid var(--border);
}

.plan-slot {
  display: grid;
  grid-template-columns: 3.4rem minmax(0, 1fr);
  gap: var(--space-12);
  padding: var(--space-12) 0;
  border-bottom: 1px solid var(--border);
}

.plan-slot:last-child {
  border-bottom: 0;
}

.plan-slot-time {
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

.plan-slot-reason {
  margin: 0;
}

.plan-slot-body > .caption-sm {
  margin: var(--space-2) 0 0;
}

.plan-slot-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-12);
  margin-top: var(--space-4);
}

.plan-slot-actions button.link {
  min-height: 32px;
  padding: 0;
  font-size: var(--text-sm-size);
}

/* Text links are 20 to 32px tall: an invisible extension makes each a 44px target without moving anything. */
.plan-table-link,
.plan-slot-actions button.link,
.plan-table button.link {
  position: relative;
}

.plan-table-link::after,
.plan-slot-actions button.link::after,
.plan-table button.link::after {
  content: '';
  position: absolute;
  inset: -12px -4px;
}

.plan-slot-actions button.link::after {
  inset: -6px -4px;
}

/* ============================== slot sheet ============================== */

/* The sheet's title takes the focus when it opens (planSlotSheet.js, so it is read first). Like the screen titles and the
   mode sheet's title, it shows no ring: it is not a control. */
#dialog-title:focus,
#dialog-title:focus-visible {
  outline: none;
  box-shadow: none;
}

.plan-sheet-pager {
  display: flex;
  gap: var(--space-8);
}

.plan-sheet-pager button {
  flex: 1 1 0;
  min-height: 44px;
}

.plan-sheet-reason {
  margin: var(--space-2) 0 0;
  font-size: var(--text-md-size);
  line-height: var(--text-md-line);
}

.plan-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-12) var(--space-16);
  margin: 0;
}

.plan-fact dt {
  color: var(--text-2);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
}

.plan-fact dd {
  margin: 0;
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
}

.plan-alts {
  margin-top: var(--space-4);
}

/* ============================== all half hours ============================== */

.plan-lookahead {
  margin: 0 0 var(--space-12);
  color: var(--text-2);
}

.plan-lookahead input[type='checkbox'] {
  margin-right: var(--space-4);
}

/* ============================== 48 hour chart ============================== */

.plan-chart .seg {
  margin-bottom: var(--space-12);
}

.chart-note {
  margin: 0 0 var(--space-8);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-6);
  margin: 0 0 var(--space-8);
  padding: 0;
  list-style: none;
}

.chart-legend button.chart-chip {
  gap: var(--space-6);
  min-height: 28px;
  padding: 0 var(--space-10);
  border-color: var(--control-border);
  border-radius: var(--radius-full);
  box-shadow: none;
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
  font-weight: var(--weight-medium);
}

/* Off: the swatch fades and the name is struck through, but the name keeps its contrast (opacity on the whole chip took it under 3:1). */
.chart-chip[aria-pressed='false'] {
  color: var(--text-2-strong);
  text-decoration: line-through;
}

.chart-chip[aria-pressed='false'] .chart-swatch {
  opacity: 0.35;
}

/* The chips are 28px tall; the invisible extension makes each a 44px target (the chips are a gap apart, so none overlaps). */
.chart-legend button.chart-chip {
  position: relative;
}

.chart-legend button.chart-chip::after {
  content: '';
  position: absolute;
  inset: -9px 0; /* from the padding edge: the 1px border makes it 8px beyond the chip */
}

.chart-swatch {
  display: inline-block;
  width: 18px;
  height: 0;
  border-top: 3px solid currentColor;
}

.chart-swatch.is-dashed {
  border-top-style: dashed;
}

.chart-swatch.tone-solar {
  color: var(--energy-solar);
}

.chart-swatch.tone-home {
  color: var(--energy-home);
}

.chart-swatch.tone-grid {
  color: var(--energy-grid);
}

.chart-swatch.tone-battery {
  color: var(--energy-battery);
}

.plan-chart .chart-frame {
  height: 240px;
}

@media (min-width: 1024px) {
  .plan-chart .chart-frame {
    height: 300px;
  }
}

.plan-band-key {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-6) var(--space-8);
  margin-top: var(--space-12);
}

.chart-loading {
  display: grid;
  gap: var(--space-16);
}

.plan-chart-body .ui-disclosure {
  margin-top: var(--space-12);
}

/* ============================== what changed ============================== */

.plan-causes {
  margin-bottom: var(--space-12);
}

.plan-runs li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4) var(--space-8);
}

/* ============================== shadow ledger ============================== */

.plan-ledger-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4) var(--space-12);
}

#ledger-card .ui-disc-body > .stack > h3 {
  margin-top: var(--space-8);
}

.plan-nowrap {
  white-space: nowrap;
}

/* On the narrowest phones the title may break inside the range and mode rather than run past the card. */
@media (max-width: 359.98px) {
  .plan-nowrap {
    white-space: normal;
  }
}

.plan-sheet.stack > * + * {
  margin-top: var(--space-16);
}
