/*
 * Layout and components. Colours, type, shape and motion come from
 * tokens.css; nothing here names a colour value.
 *
 * Layout. How many sections stand side by side and which navigation there
 * is, is decided in one place, layoutFor() of js/router.js, from the width
 * of the window; app.js writes the answer to the shell:
 *
 *   data-columns="1" | "2" | "3"     the panes
 *   data-nav="bar" | "rail" | "none" bottom bar, navigation rail, nothing
 *
 * The rules of the shell use these attributes, never a width. The one width
 * named in this file is 600 px (BREAKPOINTS.rail), in media queries that
 * give single components more room (a test keeps the two in agreement).
 *
 * Contents:
 *   1. Base              6. Status screen (hero, bolt, figure, table)
 *   2. Shell, nav        7. Login and start-up screens
 *   3. Banner, snackbar  8. Sheet (confirmation), account menu
 *   4. Pages, sections   9. History screen (range, tabs, readout, legend)
 *   5. Buttons, fields  10. Chart (the SVG of chart/chart.js)
 *                       11. Billing screen (figures, facts, notice, invoices)
 */

/* === 1. Base ============================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-body-large);
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
p {
  margin: 0;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.noscript {
  padding: var(--app-gutter);
}

/* Icons are outlines drawn in the text colour (icons.js). */
.icon {
  flex: none;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Figures that change in place keep their width. */
.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* === 2. Shell and navigation ============================================== */

.shell {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
}

.shell__content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.panes {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
}

.pane {
  display: grid;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Bottom navigation bar */
.nav {
  order: 1;
  display: flex;
  height: calc(var(--app-nav-bar-height) + env(safe-area-inset-bottom, 0px));
  padding: 0 8px env(safe-area-inset-bottom, 0px);
  background: var(--md-sys-color-surface-container);
}

.nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 48px;
  min-height: 56px;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-label-medium);
  text-decoration: none;
  outline-offset: -4px;
  border-radius: var(--md-sys-shape-corner-large);
}

.nav__indicator {
  display: grid;
  place-items: center;
  width: 64px;
  height: 32px;
  border-radius: var(--md-sys-shape-corner-full);
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.nav__item:hover .nav__indicator {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) var(--md-sys-state-hover), transparent);
}

.nav__item:active .nav__indicator {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) var(--md-sys-state-pressed), transparent);
}

.nav__item[aria-current='page'] {
  color: var(--md-sys-color-on-surface);
  font-weight: 700;
}

.nav__item[aria-current='page'] .nav__indicator {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

/* Only what the layout offers is there (app.js hides the other links). */
.shell[data-nav='none'] .nav {
  display: none;
}

/* The account button of the rail; with the bottom bar every screen has its
   own in its header instead (see `.account-btn`). */
.nav__account {
  display: none;
  border: 0;
  background: transparent;
  cursor: pointer;
}

/* Navigation rail */
.shell[data-nav='rail'] {
  grid-template-rows: minmax(0, 1fr);
  grid-template-columns: var(--app-nav-rail-width) minmax(0, 1fr);
}

.shell[data-nav='rail'] .nav {
  order: 0;
  flex-direction: column;
  gap: 12px;
  height: auto;
  padding: 28px 0 16px;
  padding-left: env(safe-area-inset-left, 0px);
  background: var(--md-sys-color-surface);
  overflow-y: auto;
}

.shell[data-nav='rail'] .nav__item {
  flex: none;
  width: 100%;
}

.shell[data-nav='rail'] .nav__indicator {
  width: 56px;
}

.shell[data-nav='rail'] .nav__account {
  display: flex;
  margin-top: auto;
}

.nav__account[aria-expanded='true'] .nav__indicator {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) var(--md-sys-state-pressed), transparent);
}

/* Without navigation the shell is the content alone. */
.shell[data-nav='none'] {
  grid-template-rows: minmax(0, 1fr);
}

/* Two columns: status keeps a fixed share, the other section gets the rest. */
.shell[data-columns='2'] .panes {
  grid-template-columns: minmax(400px, 32%) minmax(0, 1fr);
}

/* Three columns: status and billing are as wide as they need to be, the
   charts get everything else. Hairlines separate the two text columns from
   the chart; the status column is set apart by its coloured surface. */
.shell[data-columns='3'] .panes {
  grid-template-columns: clamp(380px, 27vw, 480px) minmax(0, 1fr) clamp(380px, 27vw, 480px);
  width: 100%;
  max-width: 2080px;
  margin: 0 auto;
}

.shell[data-columns='3'] .pane + .pane {
  border-left: 1px solid var(--md-sys-color-outline-variant);
}

.shell[data-columns='3'] .pane[data-view='verlauf'] {
  justify-items: center;
}

.shell[data-columns='3'] .pane[data-view='verlauf'] .page {
  max-width: 1040px;
}

/* === 3. Banner and snackbar =============================================== */

/* Persistent notice above the content: live connection lost (shell) or
   wallbox offline (status screen). */
.banner {
  padding: 12px var(--app-gutter);
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  font: var(--md-sys-typescale-body-medium);
}

.banner:not([hidden]) + .panes .banner--inline {
  /* Never two banners: the shell's one is the more fundamental. */
  display: none;
}

@media (min-width: 600px) {
  .banner {
    margin: 16px 16px 0;
    padding-top: 12px;
    border-radius: var(--md-sys-shape-corner-medium);
  }
}

.snackbar {
  position: fixed;
  z-index: 10;
  left: 16px;
  right: 16px;
  bottom: calc(var(--app-nav-bar-height) + 16px + env(safe-area-inset-bottom, 0px));
  max-width: 480px;
  margin: 0 auto;
  padding: 14px 16px;
  border-radius: var(--md-sys-shape-corner-extra-small);
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  box-shadow: var(--md-sys-elevation-level3);
  font: var(--md-sys-typescale-body-medium);
}

/* Without a bottom bar: centred at the foot of the window, clear of the
   rail and of whatever the columns show at their edges. */
@media (min-width: 600px) {
  .snackbar {
    bottom: 24px;
    width: fit-content;
  }
}

/* === 4. Pages and sections (history, billing) ============================= */

.page {
  align-self: start;
  width: 100%;
  min-width: 0;
  max-width: 720px;
  padding: calc(24px + env(safe-area-inset-top, 0px)) var(--app-gutter) 32px;
}

/* The title of a screen and, to its right, its account button (if this
   layout shows it there). The button does not make the row taller. */
.page__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 36px;
}

.page__header .account-btn {
  margin: -6px -12px -6px 0;
}

.page__title {
  min-width: 0;
  font: var(--md-sys-typescale-headline-medium);
}

.page__lead {
  margin-top: 8px;
  color: var(--md-sys-color-on-surface-variant);
}

.section {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.section__title {
  margin-bottom: 12px;
  font: var(--md-sys-typescale-title-medium);
}

/* === 5. Buttons, fields, messages ========================================= */

.btn {
  --btn-bg: transparent;
  --btn-fg: var(--md-sys-color-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 24px;
  border: 0;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: var(--md-sys-typescale-label-large);
  cursor: pointer;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.btn:hover {
  background: color-mix(in srgb, var(--btn-fg) var(--md-sys-state-hover), var(--btn-bg));
}

.btn:active {
  background: color-mix(in srgb, var(--btn-fg) var(--md-sys-state-pressed), var(--btn-bg));
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn[aria-busy='true'] {
  cursor: progress;
}

/* Not available right now, but still focusable (it says so when read out). */
.btn[aria-disabled='true'],
.icon-btn[aria-disabled='true'] {
  opacity: 0.38;
  cursor: default;
}

/* A round button that is only an icon; it needs an aria-label. */
.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.icon-btn:not([aria-disabled='true']):hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) var(--md-sys-state-hover), transparent);
}

.icon-btn:not([aria-disabled='true']):active {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) var(--md-sys-state-pressed), transparent);
}

/*
 * The account button in the header of a screen. Every screen has one; it is
 * shown where the layout has no other place for the account: with the
 * bottom bar on every screen, and without navigation (three columns) in the
 * last column, i.e. in the top right corner of the window. With the rail
 * the account button is the one at the rail's foot.
 */
.account-btn {
  display: none;
  color: inherit;
}

.shell[data-nav='bar'] .account-btn,
.shell[data-nav='none'] .pane:last-child .account-btn {
  display: grid;
}

.account-btn:not([aria-disabled='true']):hover,
.account-btn[aria-expanded='true'] {
  background: color-mix(in srgb, currentColor var(--md-sys-state-hover), transparent);
}

.account-btn:not([aria-disabled='true']):active {
  background: color-mix(in srgb, currentColor var(--md-sys-state-pressed), transparent);
}

.btn--filled {
  --btn-bg: var(--md-sys-color-primary);
  --btn-fg: var(--md-sys-color-on-primary);
}

.btn--tonal {
  --btn-bg: var(--md-sys-color-secondary-container);
  --btn-fg: var(--md-sys-color-on-secondary-container);
}

.btn--text {
  padding: 0 12px;
}

.btn--wide {
  width: 100%;
  min-height: 56px;
  font: var(--md-sys-typescale-title-medium);
}

.field {
  display: grid;
  gap: 6px;
}

.field__label {
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-body-medium);
}

.field__input {
  width: 100%;
  height: 56px;
  padding: 0 16px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-small);
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-body-large);
}

.field__input:hover {
  border-color: var(--md-sys-color-on-surface);
}

.field__input:focus-visible {
  border-color: var(--md-sys-color-primary);
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: -2px;
}

.field__support {
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-body-small);
}

.check {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  font: var(--md-sys-typescale-body-medium);
  cursor: pointer;
}

.check__box {
  width: 20px;
  height: 20px;
  margin: 0 2px;
  accent-color: var(--md-sys-color-primary);
}

/* Inline message of a form. Empty (no error) it takes no space. */
.message {
  color: var(--md-sys-color-error);
  font: var(--md-sys-typescale-body-medium);
}

.message:empty {
  display: none;
}

.message--info {
  padding: 12px 16px;
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

/* === 6. Status screen ====================================================== */

/*
 * The lock state drives the colour role of the upper surface (`data-tone`,
 * set by views/status.js from status-model.js):
 *   neutral   locked, offline, unknown   surface container highest
 *   released  unlocked, not charging     primary container
 *   charging  charge running             tertiary container
 *   error     fault                      error container
 * The bolt (the lock control) inverts the surface's pair of colours, except
 * on the neutral surface, where it is the one primary-coloured element.
 */
.status {
  --hero-bg: var(--md-sys-color-surface-container-highest);
  --hero-fg: var(--md-sys-color-on-surface);
  --bolt-bg: var(--md-sys-color-primary);
  --bolt-fg: var(--md-sys-color-on-primary);
  --accent: var(--md-sys-color-on-surface-variant);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.status[data-tone='released'] {
  --hero-bg: var(--md-sys-color-primary-container);
  --hero-fg: var(--md-sys-color-on-primary-container);
  --bolt-bg: var(--md-sys-color-on-primary-container);
  --bolt-fg: var(--md-sys-color-primary-container);
  --accent: var(--md-sys-color-primary);
}

.status[data-tone='charging'] {
  --hero-bg: var(--md-sys-color-tertiary-container);
  --hero-fg: var(--md-sys-color-on-tertiary-container);
  --bolt-bg: var(--md-sys-color-on-tertiary-container);
  --bolt-fg: var(--md-sys-color-tertiary-container);
  --accent: var(--md-sys-color-tertiary);
}

.status[data-tone='error'] {
  --hero-bg: var(--md-sys-color-error-container);
  --hero-fg: var(--md-sys-color-on-error-container);
  --bolt-bg: var(--md-sys-color-on-error-container);
  --bolt-fg: var(--md-sys-color-error-container);
  --accent: var(--md-sys-color-error);
}

/* --- Hero: the upper surface ---------------------------------------------- */

.hero {
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: clamp(264px, 50svh - 40px, 520px);
  padding: calc(20px + env(safe-area-inset-top, 0px)) var(--app-gutter) var(--app-gutter);
  border-radius: 0 0 var(--md-sys-shape-corner-extra-large) var(--md-sys-shape-corner-extra-large);
  background: var(--hero-bg);
  color: var(--hero-fg);
  transition:
    background-color var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard),
    color var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}

.hero :focus-visible {
  outline-color: var(--hero-fg);
}

.hero__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 24px;
}

.hero__top .account-btn {
  margin: -12px -12px -12px 0;
}

.hero__title {
  font: var(--md-sys-typescale-title-medium);
  opacity: 0.8;
}

.hero__state {
  margin-top: auto;
  padding-top: 24px;
}

.hero__word {
  font: var(--md-sys-typescale-display-large);
  font-size: clamp(2.5rem, 13vw, 3.25rem);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.015em;
}

.hero__hint {
  min-height: 1.5rem;
  margin-top: 6px;
  font: var(--md-sys-typescale-body-large);
}

.status[data-stale] .hero__word {
  opacity: 0.55;
}

/* --- Bolt: the lock control ----------------------------------------------- */

/*
 * A track with a round thumb that sits left while locked and right while
 * released, like the bolt of a door lock. The whole track is one button; its
 * label is the action. The slide of the thumb is the one animation of the
 * application.
 */
.bolt {
  --thumb: 64px;
  --inset: 8px;
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: calc(var(--thumb) + 2 * var(--inset));
  margin-top: 20px;
  padding: 0 calc(var(--thumb) + 2 * var(--inset));
  border: 0;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--bolt-bg);
  color: var(--bolt-fg);
  font: var(--md-sys-typescale-title-large);
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background-color var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard),
    color var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}

.bolt:hover {
  background: color-mix(in srgb, var(--bolt-fg) var(--md-sys-state-hover), var(--bolt-bg));
}

.bolt:active {
  background: color-mix(in srgb, var(--bolt-fg) var(--md-sys-state-pressed), var(--bolt-bg));
}

.bolt:focus-visible {
  outline-offset: 3px;
}

.bolt__thumb {
  position: absolute;
  top: var(--inset);
  left: var(--inset);
  width: var(--thumb);
  height: var(--thumb);
  border-radius: 50%;
  background: var(--bolt-fg);
  color: var(--bolt-bg);
  transition:
    left var(--md-sys-motion-duration-long) var(--md-sys-motion-easing-emphasized),
    background-color var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard),
    color var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}

.bolt[data-locked='false'] .bolt__thumb {
  left: calc(100% - var(--thumb) - var(--inset));
}

.bolt__icon {
  position: absolute;
  inset: 0;
  width: 28px;
  height: 28px;
  margin: auto;
  transition: opacity var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}

.bolt[data-locked='false'] .bolt__icon--locked,
.bolt:not([data-locked='false']) .bolt__icon--open {
  opacity: 0;
}

.bolt__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Not available (offline, unknown): the Material disabled treatment. The
   element keeps the focus and explains itself when pressed. */
.bolt[aria-disabled='true'] {
  cursor: default;
}

.bolt[aria-disabled='true']:not([data-pending]) {
  background: color-mix(in srgb, var(--hero-fg) var(--md-sys-state-disabled-container), transparent);
  color: color-mix(in srgb, var(--hero-fg) 60%, transparent);
}

.bolt[aria-disabled='true']:not([data-pending]) .bolt__thumb {
  background: color-mix(in srgb, var(--hero-fg) var(--md-sys-state-disabled-container), transparent);
  color: color-mix(in srgb, var(--hero-fg) 60%, transparent);
}

/* Command running: a ring circles the thumb until the headend confirms. */
.bolt[data-pending] {
  cursor: progress;
}

.bolt[data-pending]:hover,
.bolt[data-pending]:active {
  background: var(--bolt-bg);
}

.bolt[data-pending] .bolt__label {
  opacity: 0.7;
}

.bolt[data-pending] .bolt__thumb::after {
  content: '';
  position: absolute;
  inset: -6px;
  border: 3px solid var(--bolt-fg);
  border-top-color: transparent;
  border-radius: 50%;
  animation: bolt-pending 0.9s linear infinite;
}

@keyframes bolt-pending {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .bolt[data-pending] .bolt__thumb::after {
    animation: none;
  }
}

/* --- Below the hero -------------------------------------------------------- */

.status__body {
  display: grid;
  gap: 28px;
  align-content: start;
  padding: 24px var(--app-gutter) 32px;
}

.charge {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.charge__icon {
  display: grid;
  color: var(--accent);
}

.charge__text {
  font: var(--md-sys-typescale-title-medium);
}

.charge__detail {
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-body-medium);
  overflow-wrap: anywhere;
}

/* A figure: quiet label, large number, small notes. */
.figure__label {
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-label-large);
}

.figure__number {
  margin: 2px 0 6px;
  white-space: nowrap;
}

.figure__value {
  font: var(--md-sys-typescale-display-large);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.figure__unit {
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-title-large);
}

.figure__note {
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-body-small);
}

/* What the device itself says about a fault: its words, marked as a quotation. */
.charge__report {
  margin-top: 4px;
}

.charge__report-label {
  font-weight: 500;
}

.charge__quote {
  color: var(--md-sys-color-on-surface);
  quotes: '„' '“';
}

.status[data-stale] .charge__text,
.status[data-stale] .figure__number,
.status[data-stale] .table td {
  opacity: 0.55;
}

/* Disclosure: a native <details> with a full-width summary row. */
.disclosure {
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.disclosure__summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-title-small);
  list-style: none;
  cursor: pointer;
  border-radius: var(--md-sys-shape-corner-small);
}

.disclosure__summary::-webkit-details-marker {
  display: none;
}

.disclosure__summary .icon {
  color: var(--md-sys-color-on-surface-variant);
  transition: transform var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.disclosure[open] .disclosure__summary .icon {
  transform: rotate(180deg);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font: var(--md-sys-typescale-body-large);
}

.table th,
.table td {
  height: 44px;
  padding: 0;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  font-weight: 400;
  text-align: left;
}

.table thead th {
  height: 32px;
  border-top: 0;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-label-medium);
  vertical-align: top;
}

.table .num {
  text-align: right;
}

.table tbody th {
  color: var(--md-sys-color-on-surface-variant);
}

/* --- Wider windows ---------------------------------------------------------- */

@media (min-width: 600px) {
  .status {
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
  }

  .hero {
    margin: 16px 16px 0;
    padding-top: 20px;
    border-radius: var(--md-sys-shape-corner-extra-large);
  }

  .status__body {
    padding-inline: calc(16px + var(--app-gutter));
  }
}

/* A low, wide window (phone in landscape) with the status screen alone:
   surface left, values right. */
@media (min-width: 600px) and (max-height: 540px) {
  .shell[data-columns='1'] .status {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    max-width: none;
  }

  .shell[data-columns='1'] .status > .banner {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .shell[data-columns='1'] .hero {
    grid-row: 2;
    min-height: 0;
    margin-bottom: 16px;
  }

  .shell[data-columns='1'] .status__body {
    grid-row: 2;
    padding: 28px var(--app-gutter) 24px 8px;
    gap: 20px;
  }
}

/* === 7. Login and start-up screens ========================================= */

.auth {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.auth__hero {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
  min-height: 30svh;
  padding: calc(20px + env(safe-area-inset-top, 0px)) var(--app-gutter) 28px;
  border-radius: 0 0 var(--md-sys-shape-corner-extra-large) var(--md-sys-shape-corner-extra-large);
  background: var(--md-sys-color-surface-container-highest);
}

.auth__brand {
  font: var(--md-sys-typescale-title-medium);
  opacity: 0.8;
}

.auth__title {
  font: var(--md-sys-typescale-display-small);
  font-size: clamp(2rem, 10vw, 2.8125rem);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.015em;
  overflow-wrap: anywhere;
}

.auth__body {
  width: 100%;
  max-width: 480px;
  padding: 28px var(--app-gutter) 32px;
}

.auth__form {
  display: grid;
  gap: 20px;
  justify-items: stretch;
}

.auth__form .btn--text {
  justify-self: start;
  margin-left: -12px;
}

.auth__text {
  color: var(--md-sys-color-on-surface-variant);
}

@media (min-width: 840px) {
  .auth {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    align-items: stretch;
  }

  .auth__hero {
    margin: 16px;
    padding: 28px 32px 36px;
    border-radius: var(--md-sys-shape-corner-extra-large);
  }

  .auth__body {
    align-self: center;
    padding: 32px 48px;
  }
}

/* === 8. Sheet ============================================================== */

/* Confirmation as a modal bottom sheet (<dialog>), a centred dialog on wide
   windows. */
.sheet {
  width: 100%;
  max-width: 640px;
  margin: auto auto 0;
  padding: 28px var(--app-gutter) calc(24px + env(safe-area-inset-bottom, 0px));
  border: 0;
  border-radius: var(--md-sys-shape-corner-extra-large) var(--md-sys-shape-corner-extra-large) 0 0;
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--md-sys-elevation-level3);
}

.sheet::backdrop {
  background: color-mix(in srgb, var(--md-sys-color-scrim) 45%, transparent);
}

.sheet__title {
  font: var(--md-sys-typescale-headline-small);
}

.sheet__text {
  margin-top: 12px;
  color: var(--md-sys-color-on-surface-variant);
}

.sheet__actions {
  display: flex;
  gap: 12px;
  margin-top: 28px;
}

.sheet__actions .btn {
  flex: 1;
  min-height: 56px;
  padding: 0 16px;
}

@media (min-width: 600px) {
  .sheet {
    max-width: 420px;
    margin: auto;
    padding: 28px;
    border-radius: var(--md-sys-shape-corner-extra-large);
  }

  .sheet__actions {
    justify-content: flex-end;
  }

  .sheet__actions .btn {
    flex: none;
    min-height: 48px;
    padding: 0 24px;
  }
}

/* --- Account menu ----------------------------------------------------------- */

/* Who is logged in, and the logout: a bottom sheet on phones, a small menu
   next to its button otherwise (account.js sets its position). */
.account-menu {
  width: 100%;
  max-width: 640px;
  margin: auto auto 0;
  padding: 24px var(--app-gutter) calc(20px + env(safe-area-inset-bottom, 0px));
  border: 0;
  border-radius: var(--md-sys-shape-corner-extra-large) var(--md-sys-shape-corner-extra-large) 0 0;
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--md-sys-elevation-level3);
}

.account-menu::backdrop {
  background: color-mix(in srgb, var(--md-sys-color-scrim) 45%, transparent);
}

.account-menu__title {
  font: var(--md-sys-typescale-title-medium);
}

.account-menu__label {
  margin-top: 16px;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-body-small);
}

.account-menu__email {
  overflow-wrap: anywhere;
}

.account-menu__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 24px;
}

@media (min-width: 600px) {
  .account-menu {
    position: fixed;
    width: max-content;
    min-width: 264px;
    max-width: min(360px, calc(100vw - 32px));
    margin: 0;
    padding: 20px;
    border-radius: var(--md-sys-shape-corner-large);
  }

  /* A menu dims nothing; a click beside it still closes it. */
  .account-menu::backdrop {
    background: transparent;
  }

  /* Escape or a click elsewhere closes a menu. */
  .account-menu__close {
    display: none;
  }
}

/* === 9. History screen ====================================================== */

/*
 * The colours of the chart, derived from the roles of the status screen:
 * petrol for what is measured, and for the state band neutral (locked),
 * primary (released, plugged), the amber tertiary (charging) and error.
 * The band does not rely on them: every state also has its own height.
 */
.history {
  --chart-ink: var(--md-sys-color-primary);
  --chart-quiet: var(--md-sys-color-secondary);
  --chart-state-locked: var(--md-sys-color-outline);
  --chart-state-none: color-mix(in srgb, var(--md-sys-color-primary) 30%, var(--md-sys-color-primary-container));
  --chart-state-plugged: color-mix(in srgb, var(--md-sys-color-primary) 75%, var(--md-sys-color-primary-container));
  --chart-state-charging: color-mix(in srgb, var(--md-sys-color-tertiary) 60%, var(--md-sys-color-tertiary-container));
  --chart-state-error: var(--md-sys-color-error);
  /* Horizontal swipes change the range and read values from the chart. */
  touch-action: pan-y pinch-zoom;
}

/* The range: its length, and below it which one. One group, set apart from
   the tabs and their content by the space below it. */
.history__range {
  margin-top: 16px;
}

.history__range .segmented {
  max-width: 400px;
}

/* Segmented control: radio buttons on one track; the chosen one is a pill. */
.segmented {
  display: flex;
  min-width: 0;
  margin: 0;
  padding: 0 4px;
  border: 0;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-high);
}

.segmented__option {
  position: relative;
  flex: 1;
  min-width: 0;
  padding: 4px 0;
}

.segmented__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented__label {
  display: grid;
  place-items: center;
  min-height: 40px;
  padding: 0 8px;
  border-radius: var(--md-sys-shape-corner-full);
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-label-large);
  white-space: nowrap;
  transition:
    background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
    color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.segmented__input:hover + .segmented__label {
  color: var(--md-sys-color-on-surface);
}

.segmented__input:checked + .segmented__label {
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  font-weight: 700;
}

.segmented__input:focus-visible + .segmented__label {
  outline: 3px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* Range: previous, the name of the range (opens the date picker), next,
   and the way back to today. */
.range {
  display: flex;
  align-items: center;
  margin: 4px -12px 0;
}

.range__today {
  flex: none;
  margin-left: 4px;
}

.range__picker {
  position: relative;
  flex: 1;
  display: grid;
  min-width: 0;
}

.range__title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  min-height: 48px;
  padding: 0 4px;
  border: 0;
  border-radius: var(--md-sys-shape-corner-full);
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-title-medium);
  font-variant-numeric: tabular-nums;
  text-align: center;
  cursor: pointer;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.range__title:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) var(--md-sys-state-hover), transparent);
}

.range__title .icon {
  width: 20px;
  height: 20px;
  color: var(--md-sys-color-on-surface-variant);
}

.range__short {
  display: none;
}

/* Not seen; it only anchors the browser's date picker below the title. */
.range__date {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

/* With the bottom bar the row is as wide as a phone: the short name. */
@media (max-width: 599px) {
  .range__long {
    display: none;
  }

  .range__short {
    display: inline;
  }
}

/* On wide panes the date navigation does not spread over the whole width. */
@media (min-width: 600px) {
  .range {
    max-width: 496px;
  }

  .range__title {
    white-space: nowrap;
  }
}

@media (max-width: 359px) {
  .range__title {
    font: var(--md-sys-typescale-title-small);
    font-variant-numeric: tabular-nums;
  }

  .range__title .icon {
    display: none;
  }

  .range__today {
    margin-left: 0;
    padding: 0 8px;
  }
}

/*
 * The content: tabs on a baseline, and directly below it the panel they
 * switch. The chosen tab is in the primary colour and carries the indicator,
 * a short bar that sits on the baseline (Material 3 primary tabs).
 */
.history__content {
  margin-top: 12px;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.tab {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
  max-width: 168px;
  height: 48px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--md-sys-shape-corner-small) var(--md-sys-shape-corner-small) 0 0;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-title-small);
  cursor: pointer;
  outline-offset: -3px;
  transition:
    background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
    color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.tab:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) var(--md-sys-state-hover), transparent);
  color: var(--md-sys-color-on-surface);
}

.tab:active {
  background: color-mix(in srgb, var(--md-sys-color-primary) var(--md-sys-state-pressed), transparent);
}

.tab__label {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  white-space: nowrap;
}

.tab__label::after {
  content: '';
  position: absolute;
  left: -2px;
  right: -2px;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: transparent;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.tab[aria-selected='true'] {
  color: var(--md-sys-color-primary);
}

.tab[aria-selected='true'] .tab__label::after {
  background: var(--md-sys-color-primary);
}

.history__body {
  padding-top: 20px;
}

/* The values of the range, or of the touched moment, above the chart. */
.readout__title {
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-label-large);
}

.readout__figures {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  margin-top: 8px;
}

.readout__label {
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-body-small);
}

.readout__number {
  white-space: nowrap;
}

.readout__value {
  font: var(--md-sys-typescale-headline-medium);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.readout__unit {
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-title-small);
}

.readout__table {
  margin-top: 4px;
}

.readout__note {
  margin-top: 2px;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-body-small);
}

@media (max-width: 359px) {
  .readout__value {
    font: var(--md-sys-typescale-headline-small);
    font-variant-numeric: tabular-nums;
  }
}

.table--dense {
  font: var(--md-sys-typescale-body-medium);
  font-variant-numeric: tabular-nums;
}

.table--dense th,
.table--dense td {
  height: 32px;
  padding-left: 8px;
  white-space: nowrap;
}

.table--dense th:first-child {
  padding-left: 0;
}

.table--dense thead th {
  height: 24px;
  padding-bottom: 4px;
  vertical-align: bottom;
  white-space: normal;
}

.history__plot {
  position: relative;
  min-height: 220px;
  margin-top: 12px;
}

/* Loading, error, or "nothing recorded", in the place of the chart. */
.history__message {
  position: absolute;
  inset: 0 0 40px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  padding: 0 24px;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-body-medium);
  text-align: center;
}

/* While another range is fetched, the previous one steps back. */
.history__body .readout,
.history__body .chart {
  transition: opacity var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.history__body[data-mode='loading'] .readout,
.history__body[data-mode='loading'] .chart {
  opacity: 0.4;
  transition-delay: 120ms;
}

.history__body[data-blank] .chart {
  visibility: hidden;
}

/* Nothing to explain where nothing is drawn. */
.history__body[data-blank] :is(.readout, .legend, .legend__title, .history__note, .disclosure) {
  display: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  margin: 12px 0 0;
  padding: 0;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-body-small);
  list-style: none;
}

.legend--states {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 6px 16px;
  margin-top: 8px;
}

.legend__title {
  margin-top: 20px;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-label-medium);
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.history__note {
  margin-top: 12px;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-body-small);
}

.history__body .disclosure {
  margin-top: 24px;
}

.history__table {
  padding-bottom: 8px;
  overflow-x: auto;
}

/* === 10. Chart ============================================================== */

/*
 * chart/chart.js builds the SVG; everything about its look is here. Marks
 * are thin and in one colour; grid and axis are hairlines in the outline
 * variant; text uses the type scale. No fills behind the plot, no shadows.
 */
.chart {
  border-radius: var(--md-sys-shape-corner-small);
  outline-offset: 4px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.chart__svg {
  display: block;
  overflow: visible;
}

.chart__grid line {
  stroke: var(--md-sys-color-outline-variant);
  stroke-width: 1;
}

.chart__grid .chart__baseline {
  stroke: var(--md-sys-color-outline);
}

.chart__tick,
.chart__caption,
.chart__lane {
  fill: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-label-small);
  font-variant-numeric: tabular-nums;
}

.chart__caption {
  font: var(--md-sys-typescale-label-medium);
}

.chart__lane {
  fill: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-label-large);
}

.chart__line {
  fill: none;
  stroke: var(--chart-ink);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart__line--max {
  stroke-width: 1;
  opacity: 0.55;
}

.chart__band {
  fill: var(--chart-ink);
  opacity: 0.16;
}

.chart__band--voltage {
  fill: var(--chart-quiet);
  opacity: 0.75;
}

.chart__bar {
  fill: var(--chart-ink);
  transition: opacity var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.chart__bar--partial {
  opacity: 0.5;
}

.chart__svg.has-selection .chart__bar:not(.is-selected) {
  opacity: 0.35;
}

.chart__slot {
  fill: color-mix(in srgb, var(--md-sys-color-on-surface) 7%, transparent);
}

.chart__cursor-line {
  stroke: var(--md-sys-color-on-surface);
  stroke-width: 1;
}

.chart__dot {
  fill: var(--chart-ink);
  stroke: var(--md-sys-color-surface);
  stroke-width: 2;
}

.chart__state--locked {
  fill: var(--chart-state-locked);
}

.chart__state--none {
  fill: var(--chart-state-none);
}

.chart__state--plugged {
  fill: var(--chart-state-plugged);
}

.chart__state--charging {
  fill: var(--chart-state-charging);
}

.chart__state--error {
  fill: var(--chart-state-error);
}

.chart__state--offline {
  stroke: var(--md-sys-color-outline);
  stroke-width: 1;
  stroke-dasharray: 2 3;
}

/* A swatch of the legend: a small SVG with the mark itself. */
.chart-key {
  flex: none;
  width: 20px;
  height: 16px;
  overflow: visible;
}

/* === 11. Billing screen ===================================================== */

.billing__figures {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px 32px;
  margin-top: 28px;
}

.billing__figures + .figure__note {
  margin-top: 4px;
}

/* Label and value pairs as quiet rows. */
.facts {
  margin: 24px 0 0;
}

/* Said in place of the figures while there is nothing to show. */
.billing__hint {
  margin-top: 24px;
  color: var(--md-sys-color-on-surface-variant);
}

.facts__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.facts dt {
  color: var(--md-sys-color-on-surface-variant);
}

.facts dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* An announcement: the one tonal surface of the screen. */
.notice {
  margin-top: 24px;
  padding: 16px 20px 18px;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.notice__title {
  font: var(--md-sys-typescale-title-small);
}

.notice__figures {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 10px;
  margin-top: 4px;
  font: var(--md-sys-typescale-headline-small);
  font-variant-numeric: tabular-nums;
}

.notice__old,
.notice__arrow {
  opacity: 0.65;
}

.notice__note {
  margin-top: 6px;
  font: var(--md-sys-typescale-body-medium);
}

.invoices {
  margin: 0;
  padding: 0;
  list-style: none;
}

.invoice {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  column-gap: 12px;
  min-height: 64px;
  padding: 8px 0;
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.invoice:first-child {
  border-top: 0;
  padding-top: 0;
}

.invoice__period {
  grid-area: 1 / 1;
  align-self: end;
}

.invoice__energy {
  grid-area: 2 / 1;
  align-self: start;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-body-medium);
  font-variant-numeric: tabular-nums;
}

.invoice__amount {
  grid-area: 1 / 2 / span 2;
  font: var(--md-sys-typescale-title-medium);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.invoice__link {
  grid-area: 1 / 3 / span 2;
  margin-right: -12px;
  text-decoration: none;
}

.invoices__message {
  color: var(--md-sys-color-on-surface-variant);
}

.invoices__message.message {
  color: var(--md-sys-color-error);
}

.invoices__message + .btn {
  margin-top: 16px;
}
