/* Energy use: what the model mesh draws and which models it serves.
   See DESIGN.md, "Energy Use". Drawn by energy-view.js. */

.energy {
  grid-area: energy;
  margin-top: 72px;
  scroll-margin-top: calc(var(--header) + 16px);
  background: var(--surface-quiet);
  border: var(--frame);
  box-shadow: var(--shadow-sign);
}
.energy-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 24px;
  padding: 12px 16px;
  background: var(--surface-head);
  border-bottom: var(--frame);
}
.energy-scope { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.energy-state { padding: 0 8px; background: var(--surface-quiet); border: var(--frame); }
.energy-state[data-state="live"] { background: var(--accent); }
.energy-body { padding: 16px; }

.energy-total { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 16px; }
.energy-total b { font: inherit; font-size: 32px; line-height: 32px; }
.energy-month { margin-left: auto; }

.energy-screen {
  margin-top: 16px;
  padding: 16px;
  overflow-x: auto;
  background: var(--screen);
  border: var(--frame);
  color: var(--screen-quiet);
}
.energy-chart { display: grid; grid-template-columns: 64px 480px; gap: 8px; width: max-content; margin: 0 auto; }
.energy-scale { display: flex; flex-direction: column; justify-content: space-between; height: 136px; text-align: right; line-height: 16px; white-space: nowrap; }
#energy-canvas { display: block; width: 480px; height: 136px; image-rendering: pixelated; }
.energy-times { grid-column: 2; display: flex; justify-content: space-between; }

.energy-table { width: 100%; margin-top: 24px; border-collapse: collapse; }
.energy-table th, .energy-table td { padding: 8px 16px 8px 0; font-weight: 400; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.energy-table th:last-child, .energy-table td:last-child { padding-right: 0; }
.energy-table thead th { color: var(--text-quiet); }
.energy-table tbody tr { border-top: 1px solid var(--rule); }
.energy-table .num { text-align: right; white-space: nowrap; }
.energy-table .col-ram { white-space: nowrap; }
.energy-table .col-swatch { width: 40px; }
/* The data source line: the page's small print, at the foot of the card. */
.energy-source { margin-top: 16px; color: var(--text-quiet); }
.energy-source a { color: var(--text); text-underline-offset: 4px; }
.energy-swatch { display: block; width: 24px; height: 24px; border: var(--frame); image-rendering: pixelated; }
.energy-gauge { display: inline-flex; gap: 2px; margin-right: 8px; vertical-align: -2px; }
.energy-gauge i { width: 6px; height: 16px; background: var(--surface); }
.energy-gauge .is-used { background: var(--text-quiet); }

/* The live meter: the reading at the right end of the head panel, there only
   while the mesh reports. It costs width, so its column is a number of its
   own: 336px where the stage has its monitor column, which is the column above
   the work order monitor; 240px from 900px up to the width where the stage is
   one column, the same band game-view.css gives the stage; and below 900px the
   panel cannot hold the text beside it, so the meter lies across the foot of
   the panel at its full width.
   From 1440px, where that monitor column is, it is a card of its own beside
   the panel rather than a band inside it: the panel gives up --meter-room, the
   meter's column and the gutter the stage keeps between its panels, and the
   meter stands in that room with the outline and the shadow every other card
   has. The room is measured from the panel's outer edge, and the space it
   leaves is the field, not the panel's face.
   Topaz advances half an em, and a token rate under a million a minute shows
   at most five figures, so the widest line needs 212px: 176 of the line
   itself, 32 of padding on its two sides and the 4px rule beside it. Below
   900px that rule moves to the top, where it costs height and not width. */

.floor-meter {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface-quiet);
  text-decoration: none;
}
.floor-meter:hover { background: var(--surface); }
.meter-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; white-space: nowrap; }
.meter-row b { font: inherit; }
.meter-row i { font-style: normal; font-size: 32px; line-height: 32px; }
.meter-gauge { display: flex; gap: 4px; }
.meter-gauge i { flex: 1; height: 12px; background: var(--surface); border: 2px solid var(--line); }
.meter-gauge .is-used { background: var(--accent); }

/* Side by side: the panel splits into its text and the meter, and the meter
   stands over the height of the title bar and the lines under it. The split is
   there only while the meter is: a hidden element would leave an empty column.
   The left column is minmax(0, 1fr) so its text wraps instead of pushing the
   meter out of the panel. */
.floor-head:has(> .floor-meter:not([hidden])) {
  display: grid;
  --meter-column: 336px;
  /* What the panel gives up at its right end where the meter is a card of its
     own: the meter's column and the stage's gutter. */
  --meter-room: calc(var(--meter-column) + 24px);
  grid-template-columns: minmax(0, 1fr) var(--meter-column);
  grid-template-rows: auto auto auto;
  grid-template-areas: "title meter" "intro meter" "foot meter";
}
.floor-head > h1 { grid-area: title; }
.floor-head > .floor-intro { grid-area: intro; }
.floor-head > #floor-summary { grid-area: foot; }
.floor-meter { grid-area: meter; border-left: var(--frame); }

/* Wide only: the meter is a card beside the panel, not a band inside it. The
   panel gives up --meter-room at its right end, so its face ends at the stage's
   first column and the meter stands in the room over the monitor column, with
   the outline and the shadow the other cards carry.
   The meter leaves the flow: an out-of-flow child of a grid measures itself
   against the container's own edges, not against its rows, so the card spans
   the panel however many rows the panel holds. --meter-room is counted from the
   panel's outer edge, and the --edge it steps out at the top, the bottom and
   the right is the panel's border, inside which the card's own edges would else
   fall. The column the meter used to fill narrows to nothing, so the panel
   keeps its whole width for the text. */
@media (min-width: 1440px) {
  .floor-head:has(> .floor-meter:not([hidden])) {
    position: relative;
    margin-right: var(--meter-room);
    grid-template-columns: minmax(0, 1fr) 0;
  }
  /* The host line is the panel's third element and names no area of its own.
     With the meter out of the flow nothing holds the column it gave up, so the
     grid's own rules would place the line there, against a track of nothing. It
     belongs under the summary, in the column of the text. */
  .floor-head > .floor-host { grid-column: 1; }
  .floor-head > .floor-meter {
    position: absolute;
    grid-area: auto;
    top: calc(-1 * var(--edge));
    bottom: calc(-1 * var(--edge));
    right: calc(-1 * (var(--meter-room) + var(--edge)));
    width: var(--meter-column);
    border: var(--frame);
    box-shadow: var(--shadow-sign);
  }
}

/* The band where the stage has no monitor column: written as the negation of
   the width game-view.css gives the stage its column, so no width sits between
   the two. */
@media not all and (min-width: 1440px) {
  /* The stage has no monitor column here, so the meter lines up with nothing.
     It keeps a column wide enough for its widest line. */
  .floor-head:has(> .floor-meter:not([hidden])) { --meter-column: 240px; }
}

@media (max-width: 899px) {
  /* Below the width where a paragraph and the meter stand side by side, the
     panel is one column again and the meter takes its foot. */
  .floor-head:has(> .floor-meter:not([hidden])) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    grid-template-areas: "title" "intro" "foot" "meter";
  }
  .floor-meter { border-top: var(--frame); border-left: 0; }
}

/* From 1280px, the width this page's own grid needs: the screen and the models
   side by side, the machines beneath. */
@media (min-width: 1280px) {
  .energy-body {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    grid-template-areas: "total total" "screen models" "hosts hosts" "source source";
    column-gap: 24px;
    align-items: start;
  }
  .energy-total { grid-area: total; }
  .energy-screen { grid-area: screen; }
  .energy-hosts { grid-area: hosts; }
  .energy-source { grid-area: source; }
  #energy-models { grid-area: models; margin-top: 16px; }
  .energy-body:has(#energy-models[hidden]) { grid-template-areas: "total total" "screen screen" "hosts hosts" "source source"; }
}

@media (max-width: 1279px) {
  .energy { grid-area: energy; margin-top: 40px; }
  .energy-table .col-source, .energy-table .col-month { display: none; }
}

@media (max-width: 699px) {
  .energy-screen { padding: 8px; }
  .energy-chart { margin: 0; }
  .energy-table .col-ram, .energy-table .col-hosts { display: none; }
}
