/* Energy › Now — hero, who-is-using-it list, stacked chart, today strip.
 * Two layouts chosen by the SHAPE of the window, not its width, because the owner runs the same
 * dashboard on a portrait and a landscape monitor:
 *   portrait / squarish  -> one column: hero, loads, chart (takes the spare height), today, details
 *   landscape            -> hero + loads on the left, the chart beside them, today underneath
 * Colours, spacing, radii and type are tokens from design-tokens.css (dark and light follow the theme). */

/* The always-on vitals strip repeats the hero's numbers; on the Now tab the hero is the numbers. */
#section-energy[data-panel="now"] #iot-vitals-energy { display: none; }

.now-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "hero" "loads" "chart" "day" "details";
  grid-template-rows: auto auto minmax(340px, 1fr) auto auto;
  /* Fill the screen below the page header, tabs and sub-tabs: the chart takes whatever is left, so
     a tall monitor is used instead of left empty under a short panel. */
  min-height: calc(100dvh - 320px);
}
.now-hero, .now-loads, .now-chart, .now-day {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-4);
  min-width: 0;
}
.now-hero { grid-area: hero; }
.now-loads { grid-area: loads; }
.now-chart { grid-area: chart; display: flex; flex-direction: column; }
.now-day { grid-area: day; }
.now-details { grid-area: details; }

.now-grid h3 {
  margin: 0 0 var(--space-3);
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
  color: var(--text-muted);
}
.now-sec-hd { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-2); }
.now-sec-hd h3 { margin: 0; }
.now-foot { margin: var(--space-2) 0 0; font-size: var(--font-size-xs); color: var(--text-muted); }

/* Hero */
.now-big { display: flex; align-items: baseline; gap: var(--space-2); line-height: 1; }
.now-num { font-size: clamp(3.5rem, 9vw, 6rem); font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text-primary); }
.now-unit { font-size: var(--font-size-2xl); font-weight: 600; color: var(--text-muted); }
.now-ctx { margin-top: var(--space-2); font-size: var(--font-size-lg); font-weight: 600; color: var(--text-primary); }
.now-ctx small { display: block; font-size: var(--font-size-xs); font-weight: 400; color: var(--text-muted); }
.now-ctx--ok { color: var(--color-success); }
.now-ctx--low { color: var(--color-info-dark); }
.now-ctx--high { color: var(--color-warning-dark); }
.now-stale { margin-bottom: var(--space-2); font-size: var(--font-size-sm); color: var(--color-warning-dark); }
.now-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: var(--space-3); margin: var(--space-4) 0 0; }
.now-facts dt { font-size: var(--font-size-xs); color: var(--text-muted); font-weight: 500; }
.now-facts dd { margin: 0; font-size: var(--font-size-lg); font-weight: 600; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.now-facts dd small { font-size: var(--font-size-xs); font-weight: 400; color: var(--text-muted); }
.now-chip { display: inline-block; margin-left: var(--space-1); padding: 0 var(--space-2); border-radius: var(--radius-full); font-size: var(--font-size-2xs); font-weight: 600; text-transform: uppercase; vertical-align: middle; }
.now-chip--cheap { background: var(--color-success-row); color: var(--color-success); }
.now-chip--normal { background: var(--bg-subtle); color: var(--text-muted); }
.now-chip--expensive { background: var(--color-warning-row); color: var(--color-warning-dark); }

/* Who is using it now: name + watts on one line, a thin bar under it */
.now-load-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.now-load { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; grid-template-areas: "dot name w" ". bar bar"; align-items: center; column-gap: var(--space-2); row-gap: var(--space-1); }
.now-dot { grid-area: dot; width: 10px; height: 10px; border-radius: var(--radius-full); }
.now-load-name { grid-area: name; display: flex; align-items: baseline; gap: var(--space-2); min-width: 0; font-size: var(--font-size-base); color: var(--text-primary); }
.now-load-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now-load-w { grid-area: w; font-size: var(--font-size-lg); font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text-primary); text-align: right; }
.now-tag { flex: none; font-size: var(--font-size-2xs); font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: var(--letter-spacing-wide); }
.now-load-bar { grid-area: bar; height: 6px; background: var(--bg-subtle); border-radius: var(--radius-full); overflow: hidden; }
.now-load-bar i { display: block; height: 100%; border-radius: var(--radius-full); }
.now-load--idle .now-load-name, .now-load--idle .now-load-w { color: var(--text-muted); font-weight: 400; }
.now-load--bad .now-load-w, .now-load--bad .now-tag { color: var(--color-danger); font-weight: 700; }
.now-running { margin: var(--space-3) 0 0; font-size: var(--font-size-sm); color: var(--text-muted); }

/* Chart takes the spare height */
.now-chart-wrap { position: relative; flex: 1 1 auto; min-height: 280px; }

/* Today: price bars, then the day's cycles */
.now-price-bars { display: flex; align-items: flex-end; gap: 2px; height: 72px; }
.now-price-bars .pb { flex: 1 1 0; min-width: 2px; border-radius: 2px 2px 0 0; background: var(--bg-active); }
.now-price-bars .pb--cheap { background: var(--color-success); opacity: .85; }
.now-price-bars .pb--normal { background: var(--color-info-dark); opacity: .55; }
.now-price-bars .pb--expensive { background: var(--color-warning-dark); opacity: .9; }
.now-price-bars .pb--now { outline: 2px solid var(--text-primary); outline-offset: 1px; opacity: 1; }
.now-price-axis { display: flex; justify-content: space-between; margin-top: var(--space-1); font-size: var(--font-size-2xs); color: var(--text-muted); }
.now-events { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: grid; gap: var(--space-1); font-size: var(--font-size-sm); color: var(--text-primary); }
.now-events small { color: var(--text-muted); }

/* Meter details: the old technical block, collapsed */
.now-details { border: 1px solid var(--border-default); border-radius: var(--radius-xl); background: var(--bg-card); padding: 0 var(--space-4); }
.now-details > summary { cursor: pointer; padding: var(--space-3) 0; font-size: var(--font-size-sm); color: var(--text-muted); list-style: none; }
.now-details > summary::-webkit-details-marker { display: none; }
.now-details[open] > summary { border-bottom: 1px solid var(--border-default); margin-bottom: var(--space-3); }
.now-details > .metrics-grid, .now-details > .charts-grid { margin-bottom: var(--space-4); }

/* Landscape: hero + loads on the left, the chart beside them */
@media (min-aspect-ratio: 5/4) and (min-width: 900px) {
  .now-grid {
    grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
    grid-template-areas: "hero chart" "loads chart" "day day" "details details";
    grid-template-rows: auto 1fr auto auto;
    min-height: calc(100dvh - 300px);
  }
  .now-chart-wrap { min-height: 320px; }
  /* 1080 p must not scroll: tighter hero, rows and price strip than portrait needs. */
  .now-grid { gap: var(--space-3); }
  .now-hero, .now-loads, .now-chart, .now-day { padding: var(--space-3) var(--space-4); }
  .now-num { font-size: clamp(3rem, 5vw, 4.75rem); }
  .now-facts { margin-top: var(--space-3); }
  .now-load-list { gap: var(--space-2); }
  .now-price-bars { height: 52px; }
  .now-day { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); column-gap: var(--space-5); align-items: start; }
  .now-day > .now-sec-hd { grid-column: 1 / -1; }
  .now-day > .now-price-bars, .now-day > .now-price-axis { grid-column: 1; }
  .now-day > .now-events { grid-column: 2; grid-row: 2 / span 2; margin-top: 0; }
  .now-day > .now-foot { grid-column: 1 / -1; }
}


/* ── Energy › Appliances ─────────────────────────────────────────────────────── */
.hint-fold { display: block; margin-top: var(--space-1); }
.hint-fold > summary { cursor: pointer; font-size: var(--font-size-xs); font-weight: 400; color: var(--text-muted); }
.hint-fold[open] > summary { margin-bottom: var(--space-1); }
.wash-log--collapsed .wash-more { display: none; }

/* Landscape on a wide screen: two appliances per row instead of one tall column; the detected-loads
   module (the last one) keeps the full width. The panel's inline display:none still hides it when
   another sub-tab is showing. */
@media (min-aspect-ratio: 5/4) and (min-width: 1500px) {
  #energy-panel-appliances { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); align-items: start; }
  #energy-panel-appliances > .sensor-module { margin: 0; min-width: 0; }
  #energy-panel-appliances > .sensor-module:last-child { grid-column: 1 / -1; }
}


/* Cost › daily table: on a narrow window the three usually-small loads fold behind "More loads". */
.daily-minor-toggle { display: none; }
@media (max-width: 1199px) {
  .daily-minor-toggle { display: inline-block; }
  #daily-cost-table:not(.show-minor) .col-minor { display: none; }
}
