/* Devices: flexible loads and hot water.
   Styles for this area only; colours and sizes come from the tokens in theme.css (no raw colour values here). Phone first;
   the loads fill the width in as many columns of at least 300px as there are loads (so two loads are two wide cards, never
   two cards and an empty third) and the hot-water card lays itself out in two columns from 1024px. */

/* ============================== flexible loads ============================== */

.dev-loads > h2 {
  margin-bottom: var(--space-4);
}

.dev-loads-note {
  margin: 0 0 var(--space-16);
  color: var(--text-2);
}

.dev-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: var(--space-16);
}

.dev-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-16);
}

.dev-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--space-12);
}

.dev-title {
  flex: 1 1 8em;
  min-width: 0;
}

.dev-name {
  margin: 0;
  font-size: var(--text-md-size);
  line-height: var(--text-md-line);
}

/* The kind of load in a tinted tile: quiet when the plan has it off, the accent tint when it is on. */
.dev-tile {
  width: 44px;
  height: 44px;
  border-color: transparent;
  border-radius: var(--radius-12);
  background: var(--fill);
  box-shadow: none;
  color: var(--text-2);
  transition:
    background-color var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out);
}

.dev-tile.is-on {
  background: var(--accent-weak);
  color: var(--accent);
}

.dev-chip {
  flex: none;
  margin-top: var(--space-2);
}

.dev-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding-top: var(--space-16);
  border-top: 1px solid var(--border);
}

.dev-fact {
  min-width: 0;
}

.dev-fact + .dev-fact {
  padding-left: var(--space-16);
  border-left: 1px solid var(--border);
}

.dev-fact-label {
  margin: 0;
  color: var(--text-2);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
}

.dev-fact-value {
  margin: var(--space-2) 0 0;
  font-size: var(--text-lg-size);
  line-height: var(--text-lg-line);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

.dev-fact-value.is-none {
  color: var(--text-2);
  font-size: var(--text-md-size);
  font-weight: var(--weight-regular);
}

.dev-strategy {
  margin: var(--space-2) 0 0;
}

.dev-note {
  margin: 0;
}

.dev-note {
  color: var(--text-2-strong);
}

/* The buttons of a row of cards line up at the foot, whatever the text above them. */
.dev-control {
  width: 100%;
  min-height: 44px;
  margin-top: auto;
}

/* ============================== hot water: the card ============================== */

.hw-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-20);
}

.hw-top {
  display: grid;
  gap: var(--space-4);
}

.hw-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
}

.hw-head h2 {
  margin: 0;
}

.hw-mode-hint {
  margin: 0;
}

/* What the last read of the Bot said: plain text, in the warning colour when hot water cannot work (not Custom Mode). */
.hw-botline {
  margin: 0;
}

.hw-botline[data-tone='crit'] {
  color: var(--crit);
}

/* The mode of hot water (its own, not the inverter's): a chip like every other (same height, padding and type), in the mode
   colours: Shadow grey, Live solid green with a still dot. */
.hw-mode {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  min-height: 24px;
  padding: var(--space-2) var(--space-10);
  border-radius: var(--radius-full);
  background: var(--mode-shadow-bg);
  color: var(--mode-shadow-text);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
  font-weight: var(--weight-medium);
}

.hw-mode .mode-dot {
  display: none;
}

.hw-mode[data-mode='live'],
.hw-mode[data-mode='armed'] {
  padding-left: var(--space-8);
}

.hw-mode[data-mode='live'] .mode-dot,
.hw-mode[data-mode='armed'] .mode-dot {
  display: block;
}

.hw-mode[data-mode='live'] {
  background: var(--mode-live-bg);
  color: var(--mode-live-text);
}

.hw-mode[data-mode='armed'] {
  background: var(--mode-paused-bg);
  color: var(--mode-paused-text);
}

.hw-mode[data-mode='off'] {
  background: var(--fill);
  color: var(--text-2-strong);
}

/* Tonight, front and centre: an inset with the plan in a sentence. Its tint says how it is going. */
.hw-plan {
  display: grid;
  gap: var(--space-12);
  align-content: start;
}

.hw-hero {
  --hero-tint: var(--info-weak);
  --hero-ink: var(--info);
  padding: var(--space-16);
  border: 1px solid var(--border);
  border-radius: var(--radius-12);
  background: var(--surface-2);
}

.hw-hero[data-tone='ok'] {
  --hero-tint: var(--ok-weak);
  --hero-ink: var(--ok);
}

.hw-hero[data-tone='warn'] {
  --hero-tint: var(--warn-weak);
  --hero-ink: var(--warn);
}

.hw-hero[data-tone='crit'] {
  --hero-tint: var(--crit-weak);
  --hero-ink: var(--crit);
}

.hw-hero[data-tone='neutral'] {
  --hero-tint: var(--fill);
  --hero-ink: var(--text-2);
}

.hw-hero-top {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.hw-hero-tile {
  border-color: transparent;
  background: var(--hero-tint);
  box-shadow: none;
  color: var(--hero-ink);
  transition:
    background-color var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out);
}

/* "Tonight": a small title above the headline, in the same case as every other label (nothing else on the dashboard is upper case). */
.hw-eyebrow {
  margin: 0;
  color: var(--text-2-strong);
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
  font-weight: var(--weight-semibold);
}

.hw-title {
  margin: var(--space-8) 0 var(--space-4);
  font-size: var(--text-xl-size);
  line-height: var(--text-xl-line);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
}

.hw-detail {
  margin: 0;
  color: var(--text-2-strong);
}

.hw-reason {
  margin: var(--space-8) 0 0;
  color: var(--text-2-strong);
}

.hw-plan-btn {
  width: 100%;
  min-height: 44px;
}

/* The line under a disclosure is the next section's own top border. */
.hw-plan .ui-disclosure-plain,
.hw-history .ui-disclosure-plain {
  border-bottom: 0;
}

@media (min-width: 640px) {
  .hw-plan-btn {
    width: auto;
    justify-self: start;
  }

  .hw-title {
    font-size: var(--display-xs-size);
    line-height: var(--display-xs-line);
  }
}

/* The morning question: three big targets side by side. */
.hw-feedback,
.hw-history,
.hw-arm {
  min-width: 0;
  padding-top: var(--space-20);
  border-top: 1px solid var(--border);
}

.hw-choices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-8);
  margin-top: var(--space-12);
}

.hw-choice {
  min-height: 56px;
  padding: 0 var(--space-8);
  border-color: var(--control-border, var(--btn-border));
  font-size: var(--text-md-size);
  line-height: var(--text-md-line);
}

.hw-choice.is-answered {
  border-color: var(--accent);
  background: var(--accent-weak);
  color: var(--accent-weak-text);
}

.hw-choice.is-answered::before {
  content: '\2713';
  content: '\2713' / '';
  margin-right: var(--space-6);
}

.hw-answer {
  margin: var(--space-8) 0 0;
}

/* The last 14 nights: a dot each, oldest first. A shape and a glyph say what happened as well as the colour. */
.hw-strip {
  display: grid;
  grid-template-columns: repeat(14, minmax(0, 1fr));
  gap: var(--space-4);
  margin: var(--space-12) 0 var(--space-4);
  padding: 0;
  list-style: none;
}

.hw-strip-item {
  display: grid;
  place-items: center;
  min-width: 0;
}

.hw-dot {
  display: grid;
  place-items: center;
  box-sizing: border-box;
  width: 100%;
  max-width: 24px;
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: var(--radius-full);
}

.hw-dot > .eh-icon {
  width: 62%;
  height: 62%;
}

.hw-dot.is-heated {
  background: var(--ok);
  color: var(--surface);
}

.hw-dot.is-planned {
  border-color: var(--ok);
  color: var(--ok);
}

.hw-dot.is-skipped {
  background: var(--text-faint);
  color: var(--surface);
}

.hw-dot.is-failed {
  background: var(--crit);
  color: var(--surface);
}

.hw-dot.is-missed {
  background: var(--warn);
  color: var(--surface);
}

.hw-dot.is-upcoming {
  border-style: dashed;
  border-color: var(--info);
  color: var(--info);
}

.hw-dot.is-none {
  border-width: 1.5px;
  border-style: dashed;
  border-color: var(--text-faint);
}

.hw-strip-ends {
  display: flex;
  justify-content: space-between;
  margin: 0;
}

.hw-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-16);
  margin: var(--space-12) 0;
  padding: 0;
  list-style: none;
}

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

.hw-dot.hw-dot-key {
  flex: none;
  width: 16px;
  border-width: 1.5px;
}

.hw-legend-item .num {
  color: var(--text);
  font-weight: var(--weight-semibold);
}

/* Live pressing is apart from the everyday buttons: it is the one that makes the SwitchBot press for real. */
.hw-arm .row {
  margin-top: var(--space-12);
}

.hw-arm button {
  min-height: 44px;
}

.hw-blockers {
  margin: var(--space-12) 0 0;
}

.hw-settings-row {
  margin-bottom: calc(-1 * var(--space-4));
  border-top: 1px solid var(--border);
}

@media (min-width: 1024px) {
  /* Two columns: tonight and live pressing on the left, the morning question and the last 14 nights on the right. */
  .hw-card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      'top top'
      'plan feedback'
      'plan history'
      'arm history'
      'settings settings';
    gap: var(--space-24) var(--space-32);
  }

  .hw-top {
    grid-area: top;
  }

  .hw-plan {
    grid-area: plan;
  }

  .hw-feedback {
    grid-area: feedback;
    padding-top: 0;
    border-top: 0;
  }

  .hw-history {
    grid-area: history;
  }

  .hw-arm {
    grid-area: arm;
  }

  .hw-settings-row {
    grid-area: settings;
  }
}

/* ============================== hot water: the settings page ============================== */

.hw-page {
  display: grid;
  gap: var(--space-24);
}

@media (min-width: 1024px) {
  /* A list of settings does not want the width (as on the Settings screen). */
  .hw-page {
    max-width: 720px;
    margin-inline: auto;
  }
}

.hw-connection {
  display: grid;
  gap: var(--space-12);
  align-content: start;
}

.hw-connection p,
.hw-connection h2 {
  margin: 0;
}

.hw-conn-out:empty {
  display: none;
}

/* Testing: the only place that presses real hardware, set apart at the end with the warning colour on its frame. */
.hw-testing {
  display: grid;
  gap: var(--space-16);
  align-content: start;
  border-color: var(--warn);
}

.hw-testing h2 {
  margin: 0;
}

.hw-test-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-12);
}

.hw-test-row .field {
  width: 7em;
}

.hw-test-row button {
  min-height: 44px;
}

.hw-test-result {
  padding-top: var(--space-12);
  border-top: 1px solid var(--border);
}

/* ============================== hot water use: the pipe probe ============================== */

.tank-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-16);
}

.tank-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
}

.tank-head h2 {
  margin: 0;
}

.tank-detail,
.tank-today,
.tank-headline,
.tank-age,
.tank-caveat {
  margin: 0;
}

.tank-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-16);
}

.tank-temp {
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--text);
}

.tank-temp[data-trend='draw'],
.tank-temp[data-trend='rising'] {
  color: var(--accent);
}

.tank-headline {
  font-weight: 600;
}

/* The chart is an SVG stretched to the card; the axis labels are HTML on top of it so the type never stretches. */
.tank-chart {
  position: relative;
  padding: var(--space-8) 0 var(--space-20) var(--space-32);
}

.tank-chart-svg {
  display: block;
  width: 100%;
  border-bottom: 1px solid var(--chart-grid);
  border-left: 1px solid var(--chart-grid);
}

.tank-line {
  stroke: var(--series-load);
}

.tank-band {
  fill: var(--accent-weak);
}

.tank-band.is-live {
  fill: var(--accent);
  fill-opacity: 0.25;
}

.tank-y {
  position: absolute;
  left: 0;
  color: var(--text-2);
}

.tank-y-max {
  top: var(--space-8);
}

.tank-y-min {
  bottom: var(--space-20);
}

.tank-ticks {
  position: absolute;
  right: 0;
  bottom: 0;
  left: var(--space-32);
  height: var(--space-16);
  color: var(--text-2);
}

.tank-tick {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

.tank-chart-empty {
  margin: 0;
  padding: var(--space-16) 0;
}

.tank-actions {
  display: flex;
  gap: var(--space-8);
}
