/*
  ArtikControl component styles — the "Status Board" system.

  Function-named classes only — never named after what they look like.
  Every color / font-family / border / radius / shadow value below is a
  var(--token) reference into tokens.css; no hex codes and no literal font
  sizes here. See DESIGN.md for the rules this file follows.

  The look: a quiet neutral ground, white rounded cards that lift off it,
  heavy grotesque headings and figures, and status carried in red / amber /
  green by three recurring devices — the distribution bar under a page
  title, the edge on a stat tile or unit card, and the banded bars inside a
  panel.
*/

* {
  box-sizing: border-box;
}

/* The browser hides [hidden] with `display: none`, but that comes from the UA stylesheet, so any
   author rule setting display wins over it — .btn's own `display: inline-flex` was enough to keep
   a hidden button on screen. Restating it here, at author level, makes `hidden` mean hidden for
   every component in this file rather than only the ones that happen not to set display. */
[hidden] {
  display: none !important;
}

/* In the page but off the screen: for a control that has to exist for the browser without being
   seen, like a form's default button for the Enter key. Not [hidden], which removes it outright. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 var(--fs-body)/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--link);
  text-underline-offset: 2px;
}

/* One focus treatment for every focusable thing — links, buttons, menu summaries, the rows
   site.js turns into tab stops. Browsers' own rings change shape and color between engines and
   ignore the palette; one ring is easier to recognise than four. */
a:focus-visible,
button:focus-visible,
summary:focus-visible,
input[type="checkbox"]:focus-visible,
[tabindex]:focus-visible {
  outline: var(--border-heavy) solid var(--link);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------------
   Brand
   The wordmark, set in type so it follows the palette: ARTIK in the
   brand navy, CONTROL in the brand coral, light and wide.
--------------------------------------------------------------------- */

.brand {
  font-family: var(--font-display);
  font-size: var(--fs-title);
  font-weight: 300;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  color: var(--brand-navy);
}

.brand span {
  color: var(--brand-coral);
}

.brand sup {
  font-size: var(--fs-label);
  font-weight: 500;
  vertical-align: top;
  position: relative;
  top: 0.35em;
  margin-left: 1px;
  color: var(--muted);
}

/* ---------------------------------------------------------------------
   Site header / nav / user info
--------------------------------------------------------------------- */

/* The header is its own stacking context, above everything the page draws:
   Leaflet's panes run to z-index 1000, and the Admin and user menus drop down
   from here over the fleet map. One number on the header, not one per menu. */
.site-header {
  position: relative;
  z-index: 1100;
  padding: 0 24px;
  background: var(--ground);
}

/* The rule under the header stops at the content column instead of running
   edge to edge — it underlines the page, it does not fence off a bar. */
.site-header-inner {
  display: flex;
  align-items: center;
  gap: 10px 22px;
  flex-wrap: wrap;
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px 0 14px;
  border-bottom: var(--border-thick) solid var(--ink);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Nav items and page tabs share one voice: small, heavy, tracked capitals in a
   pill. The current one is outlined in Ink on a Surface fill — the reserved
   transparent border keeps the row from shifting when the outline appears. */
.site-nav a,
.page-tabs a {
  padding: 6px 15px;
  border: var(--border-thick) solid transparent;
  border-radius: var(--radius-pill);
  font-size: var(--fs-small);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  text-decoration: none;
  color: var(--faint);
  transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}

.site-nav a:hover,
.page-tabs a:hover {
  color: var(--ink);
}

.site-nav a.active,
.page-tabs a.active {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--ink);
}

.user-info {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: var(--fs-small);
  color: var(--muted);
}

/* An admin page's tab strip, under its title: one tab per table the page can
   show, only one shown at a time. */
.page-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 4px 0 18px;
}

/* Line icons (gear, sun, moon, person): stroked in the current text colour so
   they take every hover/active/focus state their control does, with no colour
   of their own. */
.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Light/dark switch. A lone icon rather than a prominent control: it is a display preference,
   not a place anyone needs to be sent. site.js stamps data-next with the mode a press switches
   TO, which picks the icon. Guarded on :not([hidden]) because an author display rule would
   otherwise beat the hidden attribute the button starts with. */
.theme-toggle {
  width: 36px;
  height: 36px;
  padding: 0;
  background: none;
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  color: var(--muted);
  transition: color 0.15s, background-color 0.15s;
}

.theme-toggle:not([hidden]) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle .icon {
  display: none;
  width: 20px;
  height: 20px;
}

.theme-toggle[data-next="dark"] .moon,
.theme-toggle[data-next="light"] .sun {
  display: block;
}

.theme-toggle:hover {
  color: var(--ink);
  background: var(--hover);
}

/* On the login page the toggle stands alone under the card with nothing to
   align to — outline it so it reads as a control, not a stray glyph. */
.auth-shell .theme-toggle {
  border: var(--border-thick) solid var(--border);
}

/* The header's menus are <details>/<summary> disclosures, so "is it open" is element state
   rather than a class this stylesheet has to coordinate with JavaScript. */

.user-menu,
.admin-menu {
  position: relative;
}

.user-menu > summary,
.admin-menu > summary {
  list-style: none;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}

.user-menu > summary::-webkit-details-marker,
.admin-menu > summary::-webkit-details-marker {
  display: none;
}

/* The user menu's summary is the person glyph in a ring. The name itself sits
   at the top of the panel it opens (and in the summary's accessible name). */
.user-menu > summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: var(--border-thick) solid var(--ink);
  border-radius: var(--radius-pill);
  color: var(--ink);
}

.user-menu > summary:hover,
.user-menu[open] > summary {
  background: var(--ink);
  color: var(--on-ink);
}

/* The Admin menu: the one thing in the header's right-hand cluster that is a
   PLACE, so it is a pill like the nav's — outlined at rest, filled in Ink
   while the visitor is inside the admin area. The panel is a small directory:
   every admin table as a link, grouped by page. */
.admin-menu > summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 15px 6px 10px;
  border: var(--border-thick) solid var(--ink);
  border-radius: var(--radius-pill);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--muted);
}

.admin-menu > summary .icon {
  width: 20px;
  height: 20px;
  color: var(--ink);
}

.admin-menu > summary:hover,
.admin-menu[open] > summary {
  color: var(--ink);
  background: var(--surface);
}

.admin-menu.here > summary,
.admin-menu.here > summary .icon {
  background: var(--ink);
  color: var(--on-ink);
}

.admin-menu-panel,
.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  z-index: 30;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-float);
  text-transform: none;
  letter-spacing: normal;
  font-size: var(--fs-body);
  font-weight: 400;
}

.admin-menu-panel {
  width: min(720px, calc(100vw - 28px));
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 22px 28px;
  padding: 22px 24px;
}

.admin-menu-group h4 {
  margin: 0 0 6px;
  padding-bottom: 7px;
  border-bottom: var(--border-thin) solid var(--hairline);
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--faint);
}

.user-info .admin-menu-group a {
  display: block;
  padding: 5px 0;
  color: var(--ink);
  text-decoration: none;
}

.user-info .admin-menu-group a:hover {
  color: var(--link);
  text-decoration: underline;
}

.user-menu-panel {
  min-width: 200px;
  display: flex;
  flex-direction: column;
  padding: 6px;
}

.user-menu-panel form {
  margin: 0;
}

/* Who is signed in — the label the ring in the header stands for. */
.user-menu-name {
  margin: 0 0 4px;
  padding: 8px 12px 10px;
  border-bottom: var(--border-thin) solid var(--hairline);
  font-weight: 700;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.user-info .user-menu-panel a,
.user-menu-panel button {
  display: block;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
}

.user-info .user-menu-panel a:hover,
.user-menu-panel button:hover {
  background: var(--hover);
}

/* ---------------------------------------------------------------------
   Page shell
--------------------------------------------------------------------- */

.page {
  padding: 26px 24px 56px;
  max-width: 1248px; /* a 1200px column inside the 24px gutters, flush with the header rule */
  margin: 0 auto;
}

.back-link {
  display: inline-block;
  margin-bottom: 6px;
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
}

.back-link:hover {
  color: var(--ink);
  text-decoration: underline;
}

/* ---------------------------------------------------------------------
   Page heading block (doc-title) + subtitle line
--------------------------------------------------------------------- */

.doc-title {
  display: flex;
  align-items: center;
  gap: 10px 16px;
  margin: 0 0 12px;
  flex-wrap: wrap;
}

.doc-title h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--fs-display);
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: var(--track-tight);
  text-wrap: balance;
}

/* A second heading further down a page (the gateway page's cellular section)
   needs the room above it that the first one gets from the header. */
.ledger-scroll + .doc-title,
.entry-form + .doc-title {
  margin-top: 34px;
}

/* A control that belongs to the whole page — the savings window — sits
   opposite the title, not inside one of the panels it governs. */
.doc-title .range-form {
  margin: 0 0 0 auto;
}

.sub {
  max-width: 88ch;
  margin: 0 0 16px;
  font-size: var(--fs-small);
  color: var(--muted);
}

/* ---------------------------------------------------------------------
   Status chip
   A status is a WORD first: heavy tracked capitals in the status's text
   tone. On its own (a page title, a unit card) the word sits in a tinted
   pill; inside a table it is the bare word, and "normal" drops to Ink so
   the only colored cells in a column are the ones that need reading.
--------------------------------------------------------------------- */

.status-chip {
  --chip: var(--faint);
  --chip-fill: var(--border-strong);
  display: inline-block;
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--chip-fill) 13%, transparent);
  color: var(--chip);
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  white-space: nowrap;
}

.status-chip.attend {
  --chip: var(--critical);
  --chip-fill: var(--critical-fill);
}

.status-chip.watch {
  --chip: var(--warn);
  --chip-fill: var(--warn-fill);
}

.status-chip.normal {
  --chip: var(--ok);
  --chip-fill: var(--ok-fill);
}

/* For states that are information, not alerts — "this week", "monitor",
   "shadow". Same shape, no color: the row reads as settled. */
.status-chip.quiet {
  --chip: var(--faint);
  --chip-fill: var(--border-strong);
}

.ledger-table .status-chip {
  padding: 0;
  background: none;
}

.ledger-table .status-chip.normal {
  --chip: var(--ink);
}

/* ---------------------------------------------------------------------
   Status summary — the distribution bar under a page title
   One bar, cut into critical / warning / healthy in proportion to the
   sites in each, with the counts spelled out beneath it. The bar is the
   glance; the words and figures are the answer, so nothing here is read
   from color alone.
--------------------------------------------------------------------- */

.status-summary {
  margin: 0 0 22px;
}

.status-bar {
  display: flex;
  height: 12px;
  border-radius: var(--radius-pill);
  background: var(--band);
  animation: status-bar-in 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Each segment is a full pill tucked 12px under the one before it, so every
   boundary shows the earlier segment's rounded cap — the more serious state
   visibly overlaps the calmer one. A floor on the two attention states keeps
   three sites in three hundred from vanishing into a hairline. */
.status-seg {
  position: relative;
  min-width: 12px;
  border-radius: var(--radius-pill);
}

.status-seg + .status-seg {
  margin-left: -12px;
}

.status-seg:nth-child(1) { z-index: 3; }
.status-seg:nth-child(2) { z-index: 2; }
.status-seg:nth-child(3) { z-index: 1; }

.status-seg.critical {
  min-width: max(7%, 40px);
  background: var(--critical-fill);
}

.status-seg.warning {
  min-width: max(9%, 52px);
  background: var(--warn-fill);
}

.status-seg.healthy {
  background: var(--ok-fill);
}

@keyframes status-bar-in {
  from { clip-path: inset(0 100% 0 0 round var(--radius-pill)); }
  to { clip-path: inset(0 0 0 0 round var(--radius-pill)); }
}

.status-counts {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 30px;
  list-style: none;
  margin: 8px 0 0;
  padding: 0 2px;
  font-size: var(--fs-small);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--muted);
}

.status-counts b {
  margin-right: 8px;
  font-size: var(--fs-figure);
  font-weight: 800;
  letter-spacing: var(--track-tight);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.status-counts .critical b { color: var(--critical); }
.status-counts .warning b { color: var(--warn); }
.status-counts .healthy b { color: var(--ok); }

/* Nothing in that state: the figure stays, the alarm color does not. A red
   zero is a false alarm. */
.status-counts .none b {
  color: var(--faint);
}

.status-counts .status-total {
  margin-left: auto;
  font-size: var(--fs-label);
  color: var(--faint);
}

/* ---------------------------------------------------------------------
   Stat tiles — the counted facts under the status bar
   A white tile with a heavy figure over a tracked label, and an edge down
   its left side: Ink for a plain count, red or amber when the count is
   itself a status (needing attention, inactive).
--------------------------------------------------------------------- */

.stat-tiles {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 14px;
  margin: 0 0 24px;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 172px;
  padding: 14px 22px 14px 18px;
  background: var(--surface);
  border-left: var(--edge) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-raised);
}

.stat-tile b {
  font-size: var(--fs-figure);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: var(--track-tight);
  font-variant-numeric: tabular-nums;
}

/* "3 of 120": the denominator rides along at label weight. */
.stat-tile b small {
  font-size: var(--fs-small);
  font-weight: 600;
  letter-spacing: normal;
  color: var(--muted);
}

.stat-label {
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--muted);
}

.stat-tile.attend {
  border-left-color: var(--critical-fill);
}

.stat-tile.attend b {
  color: var(--critical);
}

.stat-tile.watch {
  border-left-color: var(--warn-fill);
}

.stat-tile.watch b {
  color: var(--warn);
}

/* A count of zero keeps its tile and its edge — the tile is still what that
   number means — but the figure goes back to Ink: nothing is wrong. */
.stat-tile.clear b {
  color: var(--ink);
}

/* A tile that carries its own control — "Inactive 18 [ ] show inactive". */
.stat-tile.has-control {
  flex-direction: row;
  align-items: center;
  gap: 20px;
}

.stat-main {
  display: flex;
  flex-direction: column;
}

/* The page's export sits at the far end of the tile row, on its baseline. */
.stat-tiles > .csv-link {
  margin-left: auto;
  align-self: flex-end;
}

/* The "Show inactive" filter. The checkbox keeps its native rendering; a hand-drawn one would
   cost the platform's own focus, keyboard and forced-colours behaviour to gain nothing. */
.show-inactive {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}

/* Two classes deep on purpose: this is the one checkbox label that stays in
   the label voice, and it has to outrank the sentence-style rule for labels
   that wrap a checkbox. */
.show-inactive label:has(> input[type="checkbox"]) {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  cursor: pointer;
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--faint);
}

.show-inactive label:hover {
  color: var(--ink);
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--ink);
  cursor: pointer;
}

/* The no-script fallback submit: present in the markup, removed by site.js. */
.show-inactive .btn {
  margin-top: 0;
  padding: 5px 14px;
}

/* ---------------------------------------------------------------------
   Ledger head — the line of facts and actions above a table
   Label then figure, inline. Page-level counts are stat tiles; this is the
   smaller device for "37 customers · Download CSV" over one ledger.
--------------------------------------------------------------------- */

.ledger-head {
  display: flex;
  align-items: center;
  gap: 8px 24px;
  flex-wrap: wrap;
  margin: 0 0 12px;
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--muted);
}

.ledger-head b {
  margin-left: 4px;
  font-size: var(--fs-body);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* An identifier in the line (a gateway's MAC) is still an identifier. */
.ledger-head b.mono {
  font-size: var(--fs-small);
  font-weight: 600;
}

/* Actions cluster at the far end: the first one takes the free space, the
   rest follow it. (An auto margin on each would strand the first in the
   middle of the strip.) */
.ledger-head .csv-link {
  margin-left: auto;
}

.ledger-head .csv-link ~ .csv-link,
.ledger-head.actions .csv-link {
  margin-left: 0;
}

/* The history pages' picker is a ledger head that is a FORM: unit, range and
   dates, each a labelled field, in one raised bar above the chart. */
form.ledger-head {
  align-items: flex-end;
  gap: 12px 16px;
  margin-bottom: 18px;
  padding: 16px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-raised);
}

form.ledger-head .field-input {
  width: auto;
}

/* ---------------------------------------------------------------------
   Ledger table
--------------------------------------------------------------------- */

/* Every ledger table sits in one of these, and this is the card the table
   is drawn on. On a desktop it only frames; in a narrow window or on a phone
   the TABLE keeps its native layout — every column, correct row heights —
   and scrolls inside this box, so the page itself never scrolls sideways. */
.ledger-scroll {
  margin: 0 0 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-raised);
}

.ledger-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-body);
}

.ledger-table th {
  padding: 12px 18px;
  background: var(--band);
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
  color: var(--ink);
}

.ledger-table td {
  padding: 11px 18px;
  border-top: var(--border-thin) solid var(--hairline);
  font-variant-numeric: tabular-nums;
  vertical-align: top;
}

.ledger-table tbody tr:first-child td {
  border-top: none;
}

/* Zebra, counted over the rows actually showing: ledger-tools.js hides
   filtered and paged-out rows with .pg-hide, and a plain :nth-child(even)
   would band two neighbours alike the moment one row between them hid. */
.ledger-table tbody tr:nth-child(even of :not(.pg-hide)) > * {
  background: var(--band-soft);
}

.ledger-table th.num,
.ledger-table td.num {
  text-align: right;
}

/* A wide ledger — nine columns or more, the gateway and device tables — has
   to fit a dozen facts across one row, so it trades the generous cell for a
   tighter one and steps its cells down a size. Chosen by the table's own
   column count, so no page has to remember to ask for it. */
.ledger-table:has(thead th:nth-child(9)) th,
.ledger-table:has(thead th:nth-child(9)) td {
  padding-left: 10px;
  padding-right: 10px;
}

.ledger-table:has(thead th:nth-child(9)) th:first-child,
.ledger-table:has(thead th:nth-child(9)) td:first-child {
  padding-left: 18px;
}

.ledger-table:has(thead th:nth-child(9)) td {
  font-size: var(--fs-small);
}

/* A row header in a two-column facts table (the gateway page). */
.ledger-table tbody th {
  width: 14rem;
  background: none;
  border-top: var(--border-thin) solid var(--hairline);
  color: var(--muted);
  vertical-align: top;
}

.ledger-table tbody tr:first-child th {
  border-top: none;
}

/* Identifier-shaped cells — MAC addresses, ZigBee ids, Modbus addresses.
   Mono so eyes can diff two of them; never applied to prose. */
.mono,
.ledger-table td.mono {
  font-family: var(--font-mono);
  font-size: var(--fs-small);
}

.ledger-table tr.row-link {
  cursor: pointer;
}

/* The name that opens a row reads as the row's title, not as a blue link:
   the whole row is the target, and it says so on hover. */
.ledger-table tr.row-link td:first-child > a {
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}

.ledger-table tr.row-link:hover td:first-child > a {
  text-decoration: underline;
}

.ledger-table tbody tr.row-link:hover td,
.ledger-table tbody tr.row-link:focus-visible td {
  background: var(--hover);
}

/* site.js makes these rows a real tab stop; the ring sits inside the row
   rather than straddling it. */
.ledger-table tr.row-link:focus-visible {
  outline-offset: -2px;
}

/* A deactivated row: still a record, no longer a place you can go. It reads back one tone (Muted
   rather than Ink) and takes no hover or pointer, because there is nothing to click. The
   "Inactive" word carries the meaning; this is only the supporting weight. */
.ledger-table tr.row-inactive td {
  color: var(--muted);
}

.ledger-table td .why {
  margin-top: 1px;
  font-size: var(--fs-small);
  color: var(--muted);
}

.ledger-table td.checkbox-cell {
  text-align: center;
}

/* ---------------------------------------------------------------------
   Unit cards
--------------------------------------------------------------------- */

.unit-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 22px;
}

/* Every card reserves the status edge, so a card that goes critical does not
   shift its contents by the width of the edge. */
.unit-card {
  position: relative;
  padding: 18px 20px 16px 19px;
  background: var(--surface);
  border-left: var(--edge) solid transparent;
  border-radius: var(--radius);
  box-shadow: var(--shadow-raised);
}

.unit-card.attend {
  border-left-color: var(--critical-fill);
}

.unit-card h3 {
  margin: 2px 0 0;
  padding-right: 7rem; /* clear of the status chip pinned to the corner */
  font-family: var(--font-display);
  font-size: var(--fs-title);
  font-weight: 700;
  line-height: 1.25;
}

.unit-card .tag {
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--faint);
}

.reading {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--fs-display);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: var(--track-tight);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.unit-card .reading {
  margin: 10px 0 2px;
}

.unit-card.attend .reading {
  color: var(--critical);
}

.unit-card .reading small {
  font-size: var(--fs-small);
  font-weight: 500;
  letter-spacing: normal;
  color: var(--muted);
}

.unit-card .stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin-top: 10px;
  /* .settings-link is pinned to the card's bottom-right corner and is out of flow, so this row
     has to keep clear of it or the two collide. Reserved in `ch` against this row's own font:
     "Settings" is 8 characters, plus the link's inset and a gap, so the reservation tracks the
     type ramp instead of going stale the next time a step moves. */
  padding-right: calc(8ch + 26px);
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.unit-card .stats b {
  font-weight: 700;
  color: var(--ink);
}

.unit-card .status-chip {
  position: absolute;
  top: 16px;
  right: 16px;
}

.unit-card .settings-link {
  position: absolute;
  bottom: 16px;
  right: 18px;
  font-size: var(--fs-small);
  font-weight: 600;
}

/* The heading over a group of cards of one kind — "ACHC", "TMON". */
.group-title {
  margin: 4px 0 10px;
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--muted);
}

/* A retired unit card. The card keeps its shape — it is still a real controller with a last
   known reading — but the reading drops to Muted, because a heavy Ink figure is this system's
   way of saying "this is the current value" and on a deactivated unit it is the last thing seen
   before someone switched it off. The Inactive chip in the corner carries the state. */
.unit-card.unit-card-inactive .reading,
.unit-card.unit-card-inactive h3 {
  color: var(--muted);
}

/* ---------------------------------------------------------------------
   Chart / info panels
--------------------------------------------------------------------- */

.chart-panel,
.panel-box {
  margin-bottom: 20px;
  padding: 20px 22px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-raised);
}

.chart-panel h4,
.panel-box h4 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: var(--fs-title);
  font-weight: 700;
  line-height: 1.25;
}

.chart-panel .sub,
.panel-box .sub {
  margin-bottom: 10px;
}

/* A panel's title line when something (the CSV link) sits opposite the heading. */
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.panel-head h4 {
  margin-bottom: 0;
}

/* Named for the one thing it styles, not for a container: the fleet map lives inside a
   .chart-panel too, and any rule broad enough to catch its SVGs breaks Leaflet's coordinate
   mapping and hides every status marker. */
.strip-chart {
  display: block;
  width: 100%;
  height: auto;
}

/* ---------------------------------------------------------------------
   Entry forms
--------------------------------------------------------------------- */

.entry-form {
  /* 680px keeps the form a column, not a sheet, and gives each field of a
     pair a usable ~300px. */
  max-width: 680px;
  padding: 22px 24px 24px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-raised);
}

/* A form whose body is a TABLE (the recipients editor) needs the width of a
   ledger, not of a field column. */
.entry-form.entry-form-wide {
  max-width: 980px;
}

/* A table inside a form card is already on a card. */
.entry-form .ledger-scroll {
  border-radius: var(--radius-sm);
  box-shadow: none;
  border: var(--border-thin) solid var(--hairline);
}

.entry-form h4 {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: var(--fs-title);
  font-weight: 700;
}

.entry-form .field + h4,
.entry-form .field-grid + h4 {
  margin-top: 26px;
}

.entry-form .field {
  margin-bottom: 14px;
}

.entry-form .field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}

label,
.field-key,
.field-label {
  display: block;
  margin-bottom: 5px;
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--muted);
}

/* A label that wraps its own checkbox is a sentence to read ("Send this
   company the weekly report"), not a caption over a field — so it is set as
   body text beside the box, not as tracked capitals. */
label:has(> input[type="checkbox"]) {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 0;
  font-size: var(--fs-body);
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
  color: var(--ink);
  cursor: pointer;
}

/* A field is a box you type in: a bordered well on the card. */
.field-input {
  width: 100%;
  padding: 8px 11px;
  background: var(--input-bg);
  border: var(--border-thin) solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font: 400 var(--fs-body)/1.4 var(--font-body);
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field-input:hover {
  border-color: var(--border-strong);
}

.field-input:focus {
  outline: none;
  border-color: var(--link);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--link) 24%, transparent);
}

/* Writes are switched off while the legacy system is the record: every edit
   form renders inside a disabled fieldset. The fields stay legible — they
   are the page's content — and stop offering themselves. */
.field-input:disabled {
  background: var(--band-soft);
  border-color: var(--hairline);
  color: var(--muted);
  cursor: not-allowed;
  opacity: 1;
}

fieldset:disabled {
  min-width: 0;
}

/* A field inside a ledger cell (the recipients editor, any inline-edit row) is
   sized by the column, and columns size to their longest TEXT — an empty input
   collapses to nothing. Floors keep an email or a name legible while typing. */
.ledger-table td .field-input {
  min-width: 11rem;
}

.ledger-table td input[type="email"].field-input {
  min-width: 20rem;
}

/* Something went wrong, or cannot be done here. */
.form-error {
  margin: 0 0 14px;
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--critical);
}

/* Confirmation of something that just happened — the counterpart to .form-error. */
.form-note,
.form-ok {
  margin: 0 0 14px;
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--ok);
}

/* A value the form shows but does not let this user edit: the same slot as .field-input, without
   the affordances of one. The dashed outline is what says "not a field you can type in" — a
   solid box of the same weight reads as an input someone should be able to click into. */
.field-static {
  margin: 0;
  padding: 8px 11px;
  background: var(--band-soft);
  border: var(--border-thin) dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* A lowercase word stored in the database (usertype_name is "general user") shown as a label. */
.field-static.db-term {
  text-transform: capitalize;
}

/* A second form panel stacked under the first. */
.form-stack {
  margin-top: 20px;
}

/* ---------------------------------------------------------------------
   Buttons and action links
--------------------------------------------------------------------- */

/* .btn-ghost is written on its own as often as beside .btn ("Cancel" next to
   "Save", "Remove" in a table row), so the two share one base and the ghost
   only changes the fill. */
.btn,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  padding: 9px 22px;
  background: var(--ink);
  border: var(--border-thick) solid var(--ink);
  border-radius: var(--radius-pill);
  color: var(--on-ink);
  font: 700 var(--fs-body)/1.3 var(--font-body);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}

.btn:hover {
  background: color-mix(in srgb, var(--ink) 80%, var(--ground));
  border-color: color-mix(in srgb, var(--ink) 80%, var(--ground));
}

.btn-ghost {
  margin-left: 8px;
  background: transparent;
  border-color: var(--border-strong);
  color: var(--ink);
}

.btn-ghost:hover {
  background: var(--surface);
  border-color: var(--ink);
}

.btn:active,
.btn-ghost:active {
  transform: translateY(1px);
}

.btn:disabled,
.btn-ghost:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* In a table row or a line of actions a button is one item among others, not
   the end of a form: no form spacing, and a row's worth of height. */
.ledger-table td .btn-ghost,
.ledger-head .btn-ghost {
  margin: 0;
  padding: 5px 14px;
  font-size: var(--fs-small);
}

/* An action that belongs to the table or panel beside it — Download CSV,
   Show archived, Edit site. A quiet outlined pill in the label voice, so it
   reads as something to press without competing with the page's one solid
   button. The name is historical: it began as the CSV link. */
.csv-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  background: var(--surface);
  border: var(--border-thick) solid var(--border);
  border-radius: var(--radius-pill);
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  color: var(--muted);
  transition: color 0.15s, border-color 0.15s;
}

.csv-link:hover {
  border-color: var(--ink);
  color: var(--ink);
}

/* The ones that really are downloads get the tray-and-arrow glyph, drawn as a
   mask so it takes the link's own color in both palettes and on hover. */
.csv-link[href*="handler=Csv"]::before {
  content: "";
  width: 15px;
  height: 15px;
  flex: none;
  background: currentColor;
  -webkit-mask: var(--glyph-download) center / contain no-repeat;
  mask: var(--glyph-download) center / contain no-repeat;
}

/* ---------------------------------------------------------------------
   Ledger tools (search / status filter / page size) + pager strip.
   Both strips are injected by ledger-tools.js on tables marked data-tools;
   with scripting off neither exists and the full table simply renders.
--------------------------------------------------------------------- */

.ledger-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: var(--fs-small);
  color: var(--muted);
}

.ledger-tools .ledger-search,
.ledger-tools select,
.range-select {
  padding: 7px 12px;
  background: var(--input-bg);
  border: var(--border-thin) solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font: 400 var(--fs-small)/1.4 var(--font-body);
}

.ledger-tools .ledger-search {
  flex: 0 1 300px;
}

.ledger-tools select,
.range-select {
  width: auto;
  font-weight: 600;
  cursor: pointer;
}

.ledger-tools .ledger-search:focus,
.ledger-tools select:focus,
.range-select:focus {
  outline: none;
  border-color: var(--link);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--link) 24%, transparent);
}

/* Page size sits opposite the filters: it belongs to the pager below, not the search. */
.ledger-tools .pg-size {
  margin: 0 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.ledger-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: -6px 0 22px;
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.ledger-foot button {
  padding: 5px 14px;
  background: var(--surface);
  border: var(--border-thin) solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--ink);
  font: 600 var(--fs-small)/1.4 var(--font-body);
  cursor: pointer;
}

.ledger-foot button:hover:not(:disabled) {
  border-color: var(--ink);
}

.ledger-foot button:disabled {
  color: var(--faint);
  background: none;
  cursor: default;
}

.ledger-foot .pg-range {
  margin-left: auto;
}

/* Rows paged or filtered out of view. Only ever set by ledger-tools.js. */
.ledger-table tr.pg-hide {
  display: none;
}

.ledger-table tr.pg-empty td {
  padding: 18px;
  font-size: var(--fs-small);
  color: var(--faint);
}

/* ---------------------------------------------------------------------
   Standalone auth / error pages (login, forbidden, not-found)
--------------------------------------------------------------------- */

.auth-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 24px;
}

.auth-shell .brand {
  font-size: var(--fs-figure);
}

.auth-shell .entry-form,
.auth-card {
  width: 100%;
  max-width: 420px;
}

.auth-card {
  padding: 26px 28px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-raised);
}

.auth-shell .entry-form form > .btn {
  width: 100%;
}

.auth-card .doc-title {
  margin-bottom: 6px;
}

.auth-card .sub {
  margin-bottom: 16px;
}

/* The second way in. A ruled "or" rather than a plain gap: this is a fork in a
   form, and the rule says so without a heading. */
.alt-signin {
  margin-top: 20px;
}

.alt-signin-rule {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 14px;
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--faint);
}

.alt-signin-rule::before,
.alt-signin-rule::after {
  content: "";
  flex: 1;
  border-top: var(--border-thin) solid var(--hairline);
}

.alt-signin .btn-ghost {
  width: 100%;
  margin: 0;
}

.passkeys {
  margin-top: 30px;
}

.passkeys h3 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: var(--fs-title);
  font-weight: 700;
}

.passkeys .ledger-table {
  margin-top: 12px;
}

.passkey-add {
  margin-top: 16px;
  max-width: 22rem;
}

.passkey-add .btn {
  margin-top: 10px;
}

/* ---------------------------------------------------------------------
   Energy panels — savings and cooler/freezer performance.

   A ring and two families of bars. The ring is spent on the one split that
   really is parts of a whole — where the energy was saved — in three
   categorical inks that are deliberately NOT the status colors: fan,
   compressor and defrost are kinds, not verdicts. The bars are where the
   status colors work: each one is banded green / amber / red against a
   stated rule, and the rule is printed in the key beneath them.
--------------------------------------------------------------------- */

.energy {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  align-items: start;
  gap: 18px;
  margin: 0 0 24px;
}

.energy-panel {
  min-width: 0;
  padding: 22px 26px 22px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-raised);
}

.panel-title {
  margin: 0 0 20px;
  padding-bottom: 14px;
  border-bottom: var(--border-thick) solid var(--ink);
  font-family: var(--font-display);
  font-size: var(--fs-title);
  font-weight: 700;
  line-height: 1.25;
  color: var(--ink);
}

.energy-headline {
  display: flex;
  align-items: center;
  gap: 18px 34px;
  flex-wrap: wrap;
}

.ring-wrap {
  position: relative;
  flex: none;
  width: 152px;
  height: 152px;
}

.split-ring {
  display: block;
  width: 100%;
  height: 100%;
}

/* Butt caps, not round: a rounded cap overlaps its neighbour and makes a small
   slice look larger than it is. The gaps between arcs are cut from the dash
   lengths in the markup. */
.ring-track,
.ring-arc {
  fill: none;
  stroke-width: 20;
  stroke-linecap: butt;
}

.ring-track { stroke: var(--band); }
.ring-fan { stroke: var(--series-fan); }
.ring-compressor { stroke: var(--series-compressor); }
.ring-defrost { stroke: var(--series-defrost); }

/* The total sits in the ring's own hole, where the eye already is. */
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 34px;
  text-align: center;
}

.ring-center b {
  font-size: var(--fs-title);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: var(--track-tight);
  font-variant-numeric: tabular-nums;
}

.ring-center span {
  font-size: var(--fs-label);
  line-height: 1.25;
  color: var(--muted);
}

.split-key {
  flex: 1 1 13rem;
  min-width: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.split-item {
  --dot: var(--muted);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.split-item dt {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}

.split-item dt::before {
  content: "";
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: var(--radius-pill);
  background: var(--dot);
}

.split-fan { --dot: var(--series-fan); }
.split-compressor { --dot: var(--series-compressor); }
.split-defrost { --dot: var(--series-defrost); }

.split-item dd {
  margin: 0;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* --- banded bars ---------------------------------------------------------- */

.bar-list {
  list-style: none;
  margin: 22px 0 0;
  padding: 20px 0 0;
  border-top: var(--border-thin) solid var(--hairline);
  display: flex;
  flex-direction: column;
  gap: 11px;
}

/* The two fleet-wide averages lead the performance panel, straight under its
   title rule — they need no rule of their own. */
.bar-list.bar-list-lead {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(7rem, 12.5rem) 1fr 4.75rem;
  align-items: center;
  gap: 14px;
}

.bar-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}

a.bar-name,
.perf-name {
  color: var(--link);
}

.bar-track {
  display: block;
  height: 20px;
  background: var(--band-soft);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

/* No minimum width: a bar of zero is no bar. A sliver would be a claim. */
.bar-fill {
  display: block;
  height: 100%;
  border-radius: var(--radius-sm);
  background: var(--ok-fill);
}

.bar-watch .bar-fill { background: var(--warn-fill); }
.bar-attend .bar-fill { background: var(--critical-fill); }
.bar-reference .bar-fill { background: var(--series-reference); }

.bar-value {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* Cooler and freezer for one site: the site's name, then a line each. */
.perf-list {
  list-style: none;
  margin: 22px 0 0;
  padding: 20px 0 0;
  border-top: var(--border-thin) solid var(--hairline);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.perf-name {
  display: block;
  margin-bottom: 7px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

span.perf-name {
  color: var(--ink);
  font-weight: 600;
}

.perf-line {
  grid-template-columns: 1.1rem 1fr 4.75rem;
  gap: 10px;
}

.perf-line + .perf-line {
  margin-top: 7px;
}

.perf-kind {
  font-weight: 600;
  color: var(--muted);
}

/* What the bar colors mean, stated under the bars that use them. */
.chart-key {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin: 20px 0 0;
  padding: 0;
  font-size: var(--fs-small);
  color: var(--muted);
}

.chart-key li {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.chart-key li::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: var(--radius-xs);
  background: var(--ok-fill);
}

.chart-key .key-watch::before { background: var(--warn-fill); }
.chart-key .key-attend::before { background: var(--critical-fill); }
.chart-key .key-reference::before { background: var(--series-reference); }

.bar-note {
  max-width: 70ch;
  margin: 12px 0 0;
  font-size: var(--fs-small);
  color: var(--faint);
}

/* ---------------------------------------------------------------------
   Signal bars (gateway health)
   Five blocks filled by fifths of DRM's signal percent. A glance, never the
   value: the figure always sits beside them, so a weak link is read from
   its number and its word, not from a colour.
   Heights step 5→13px so the shape reads as bars at ledger row size.
--------------------------------------------------------------------- */
.signal {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  margin-right: 8px;
  vertical-align: -1px;
}

.signal i {
  display: block;
  width: 4px;
  border-radius: var(--radius-xs);
  background: var(--border);
}

.signal i:nth-child(1) { height: 5px; }
.signal i:nth-child(2) { height: 7px; }
.signal i:nth-child(3) { height: 9px; }
.signal i:nth-child(4) { height: 11px; }
.signal i:nth-child(5) { height: 13px; }

.signal i.on {
  background: var(--ink);
}

.signal.weak i.on {
  background: var(--warn-fill);
}

/* The signal cell keeps its figure on one line beside the bars. */
.ledger-table td.signal-cell {
  white-space: nowrap;
}

/* The add-recipient row on the report page: the .cell-label spans caption the
   two edition checkboxes once the row stacks on a phone; on a desktop the
   column headers do that job. */
.cell-label {
  display: none;
}

/* ---------------------------------------------------------------------
   Motion
--------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .status-bar {
    animation: none;
  }

  * {
    transition-duration: 0.01ms !important;
  }
}

/* ---------------------------------------------------------------------
   Responsive
--------------------------------------------------------------------- */

@media (max-width: 760px) {
  .unit-cards,
  .entry-form .field-grid {
    grid-template-columns: 1fr;
  }

  /* ---- Phone layer -------------------------------------------------------
     The rule everywhere below: the PAGE never scrolls sideways; anything wide
     scrolls inside its own box. A ledger keeps every column — an admin on a
     phone is usually hunting one row, and losing columns loses the row. */
  .page {
    padding: 18px 16px 40px;
  }

  .site-header {
    padding: 0 16px;
  }

  .site-header-inner {
    padding: 14px 0 12px;
    gap: 10px 14px;
  }

  .user-info {
    gap: 8px;
  }

  .admin-menu-panel {
    position: fixed;
    left: 14px;
    right: 14px;
    top: auto;
    width: auto;
    margin-top: 10px;
  }

  /* Two tiles to a row: four counts stay one glance instead of a column. */
  .stat-tiles {
    gap: 10px;
  }

  .stat-tile {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
    padding: 12px 14px 12px 13px;
  }

  .stat-tile.has-control {
    flex-basis: 100%;
    justify-content: space-between;
  }

  .stat-tiles > .csv-link {
    margin-left: 0;
  }

  .status-counts {
    gap: 0 18px;
  }

  .status-counts .status-total {
    flex-basis: 100%;
    margin-left: 0;
  }

  .doc-title .range-form {
    margin-left: 0;
  }

  .ledger-table th,
  .ledger-table td {
    padding-left: 12px;
    padding-right: 12px;
  }

  .ledger-tools .ledger-search {
    flex: 1 1 100%;
  }

  .ledger-tools .pg-size {
    margin-left: 0;
  }

  .entry-form,
  .energy-panel,
  .chart-panel,
  .panel-box,
  form.ledger-head {
    padding: 16px;
  }

  .energy {
    grid-template-columns: 1fr;
  }

  .unit-card h3 {
    padding-right: 6rem;
  }
}

@media (max-width: 640px) {
  .bar-row:not(.perf-line) {
    grid-template-columns: 1fr 4.75rem;
    gap: 5px 10px;
  }

  .bar-row:not(.perf-line) .bar-name {
    grid-column: 1 / -1;
  }

  /* Five cells across is wider than a phone, and the one that fell off the
     edge was the Add button — the row's whole point. The row stacks. */
  #add {
    display: block;
    border-top: var(--border-thin) solid var(--hairline);
    padding-top: 8px;
  }

  #add td {
    display: block;
    border: none;
    padding: 4px 0;
    text-align: left; /* stacked cells read as a form; checkbox-cell centering doesn't */
  }

  #add .field-input,
  .ledger-table td #add input[type="email"].field-input {
    min-width: 0;
    width: 100%;
  }

  .cell-label {
    display: inline;
    margin-left: 6px;
    font-size: var(--fs-label);
    font-weight: 700;
    letter-spacing: var(--track-label);
    text-transform: uppercase;
    color: var(--faint);
  }
}
