/* Shared components (sheet, segmented control, list rows, stat, ring, sparkline, skeleton, empty state, disclosure) and
   the utility classes the screens build on (figures, captions, chips, two-column grid, entrance). Styles for this area
   only; colours and sizes come from the tokens in theme.css (no raw colour values here). Loaded after styles.css, so
   the sheet rules below deliberately override its older `dialog` rules. Every animation has a reduced-motion twin at the
   foot of the file (styles.css already switches all transitions off). */

:root {
  /* Eon's display-sm (marketing sizes start above it; it is the one Home hero figure and nothing larger). */
  --display-sm-size: 30px;
  --display-sm-line: 38px;
  /* Diagonal hatching for "Hold": lines on the Hold fill. */
  --hatch: var(--border-strong);
}

/* ============================== utilities ============================== */

/* Figures: the number is the hero. Tabular numerals so live values do not jiggle. The unit (.fig-unit, from fig() in dom.js)
   follows in a lighter weight. */
.hero-figure {
  font-size: var(--display-sm-size);
  line-height: var(--display-sm-line);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.card-figure {
  font-size: var(--display-xs-size);
  line-height: var(--display-xs-line);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

.eyebrow {
  color: var(--text-2);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
  font-weight: var(--weight-medium);
  letter-spacing: 0.01em;
}

.caption {
  color: var(--text-2);
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
}

.caption-sm {
  color: var(--text-2);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
}

/* Chips: a small pill with an optional leading icon. One variant per energy actor, per plan mode and per state, so the
   same meaning is the same colour (and the same icon) on every screen. `.badge` (with .ok / .warn / .crit / .info / .neutral) is
   the same component under its older name: same height, padding, radius and tones, so the two can never drift apart. Not
   tabular: the digits of a time or a count do not jiggle, and tabular hyphens make "Self-use" read "Self - use". */
.chip,
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  min-height: 24px;
  padding: var(--space-2) var(--space-10);
  border-radius: var(--radius-full);
  background: var(--fill);
  color: var(--text-strong);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}

.chip > .eh-icon,
.badge > .eh-icon {
  flex: none;
  width: 14px;
  height: 14px;
  margin-left: calc(-1 * var(--space-2));
}

.chip-solar {
  background: var(--energy-solar-weak);
  color: var(--energy-solar-text);
}

.chip-solar > .eh-icon {
  color: var(--energy-solar);
}

.chip-battery {
  background: var(--energy-battery-weak);
  color: var(--energy-battery-text);
}

.chip-battery > .eh-icon {
  color: var(--energy-battery);
}

.chip-grid {
  background: var(--energy-grid-weak);
  color: var(--energy-grid-text);
}

.chip-grid > .eh-icon {
  color: var(--energy-grid);
}

.chip-home {
  background: var(--energy-home-weak);
  color: var(--energy-home-text);
}

.chip-home > .eh-icon {
  color: var(--energy-home);
}

/* Status colours only for state. Small text uses the -700 shades: -600 on a -50 tint is only about 3.5:1. */
.chip-ok,
.badge.ok {
  background: var(--ok-weak);
  color: var(--ok-text);
}

.chip-warn,
.badge.warn {
  background: var(--warn-weak);
  color: var(--warn-text);
}

.chip-crit,
.badge.crit {
  background: var(--crit-weak);
  color: var(--crit-text);
}

.chip-info,
.badge.info {
  background: var(--info-weak);
  color: var(--info-text);
}

.chip-neutral,
.badge.neutral {
  background: var(--fill);
  color: var(--text-strong);
}

/* Plan modes (use with .chip): the colour of the source of the energy, and an icon that says it again. */
.chip.mode-self-use {
  background: var(--fill);
  color: var(--text-strong);
}

.chip.mode-self-use > .eh-icon {
  color: var(--mode-self-use);
}

.chip.mode-grid-charge {
  background: var(--band-grid-charge);
  color: var(--energy-grid-text);
}

.chip.mode-grid-charge > .eh-icon {
  color: var(--mode-grid-charge);
}

.chip.mode-force-export {
  background: var(--band-force-export);
  color: var(--accent-weak-text);
}

.chip.mode-force-export > .eh-icon {
  color: var(--mode-force-export);
}

.chip.mode-hold {
  background-color: var(--band-hold);
  background-image: repeating-linear-gradient(135deg, transparent 0 4px, var(--hatch) 4px 5px);
  color: var(--text-strong);
}

.chip.mode-hold > .eh-icon {
  color: var(--mode-hold);
}

/* The same diagonal hatching on anything else that stands for Hold (a plan band, a timeline lane). */
.hatched {
  background-color: var(--band-hold);
  background-image: repeating-linear-gradient(135deg, transparent 0 4px, var(--hatch) 4px 5px);
}

/* Two columns from 640px, one below: cards, tiles, anything. `.span-2` on a child takes the full row. */
.grid-2 {
  display: grid;
  gap: var(--space-16);
  grid-template-columns: minmax(0, 1fr);
}

.grid-2.tight {
  gap: var(--space-12);
}

.grid-2.loose {
  gap: var(--space-24);
}

@media (min-width: 640px) {
  .grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-2 > .span-2 {
    grid-column: 1 / -1;
  }
}

/* Entrance: content easing in when it arrives (after a skeleton, on a new screen). Stagger siblings with setVar(el, 'i', n). */
@keyframes ui-fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.fade-in {
  animation: ui-fade-in var(--dur-3) var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 40ms);
}

/* ============================== sheet ============================== */

/* The shared <dialog> (and any other): a bottom sheet on a phone, a centred dialog from 640px. It rises from the bottom
   (or fades and scales in) with a transition on the closed -> open change; the exit runs the same way where the browser
   supports discrete transitions (elsewhere it simply closes). Pulling the handle down sets --sheet-drag (sheet.js). */
dialog {
  width: 100%;
  max-width: none;
  max-height: 90vh;
  max-height: 90dvh;
  margin: auto 0 0;
  padding: var(--space-8) var(--space-20) calc(var(--space-24) + env(safe-area-inset-bottom, 0px));
  overscroll-behavior: contain;
  transform: translateY(100%);
  transition:
    transform var(--dur-3) var(--ease-out),
    overlay var(--dur-3) allow-discrete,
    display var(--dur-3) allow-discrete;
}

dialog[open] {
  transform: translateY(calc(var(--sheet-drag, 0) * 1px));
}

@starting-style {
  dialog[open] {
    transform: translateY(100%);
  }
}

/* A sheet that is leaving must not catch taps meant for the page behind it. */
dialog:not([open]),
dialog:not([open])::backdrop {
  pointer-events: none;
}

dialog.sheet-dragging {
  transition: none;
}

dialog::backdrop {
  background: var(--scrim);
  opacity: 0;
  transition:
    opacity var(--dur-3) var(--ease-out),
    overlay var(--dur-3) allow-discrete,
    display var(--dur-3) allow-discrete;
}

dialog[open]::backdrop {
  opacity: 1;
}

@starting-style {
  dialog[open]::backdrop {
    opacity: 0;
  }
}

/* The drag-handle bar. Without script it is drawn by the dialog itself; initSheet() swaps in a real, draggable element. */
dialog::before {
  width: 36px;
  height: 4px;
  margin: calc(var(--space-12) + var(--space-2)) auto calc(var(--space-12) + var(--space-2));
  background: var(--text-3);
}

dialog.sheet-enhanced::before {
  display: none;
}

.sheet-grab {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  margin: 0 calc(-1 * var(--space-20));
  cursor: grab;
  touch-action: none;
}

.sheet-dragging .sheet-grab {
  cursor: grabbing;
}

.sheet-grab-bar {
  width: 36px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--text-3);
}

dialog > h2 {
  letter-spacing: -0.01em;
}

/* Cancel and Confirm share the row on a phone, each a full-size target. */
.dialog-actions {
  gap: var(--space-12);
}

.dialog-actions button {
  flex: 1 1 auto;
  min-height: 48px;
}

@media (min-width: 640px) {
  dialog {
    width: calc(100% - 2 * var(--space-20));
    max-width: 520px;
    max-height: min(90vh, 760px);
    max-height: min(90dvh, 760px);
    margin: auto;
    padding: var(--space-24);
    border: 1px solid var(--border);
    border-radius: var(--radius-16);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(var(--space-8)) scale(0.97);
    transition:
      transform var(--dur-3) var(--ease-out),
      opacity var(--dur-2) var(--ease-out),
      overlay var(--dur-3) allow-discrete,
      display var(--dur-3) allow-discrete;
  }

  dialog[open] {
    opacity: 1;
    transform: none;
  }

  @starting-style {
    dialog[open] {
      opacity: 0;
      transform: translateY(var(--space-8)) scale(0.97);
    }
  }

  dialog::before,
  .sheet-grab {
    display: none;
  }

  .dialog-actions button {
    flex: 0 0 auto;
    min-height: 44px;
  }
}

/* ============================== segmented control ============================== */

.seg {
  --seg-track: var(--fill);
  --seg-pill: var(--surface-raised);
  position: relative;
  display: flex;
  isolation: isolate;
  max-width: min(100%, 560px);
  padding: var(--space-4);
  border-radius: var(--radius-12);
  background: var(--seg-track);
}

/* In dark a lighter pill reads as "selected"; inside a sheet the track steps down instead. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .seg {
    --seg-pill: var(--fill-raised);
  }

  :root:not([data-theme='light']) dialog .seg {
    --seg-track: var(--surface-2);
    --seg-pill: var(--fill);
  }
}

:root[data-theme='dark'] .seg {
  --seg-pill: var(--fill-raised);
}

:root[data-theme='dark'] dialog .seg {
  --seg-track: var(--surface-2);
  --seg-pill: var(--fill);
}

.seg-inline {
  display: inline-flex;
}

.seg-inline.seg-n-2 {
  width: min(100%, 240px);
}

.seg-inline.seg-n-3 {
  width: min(100%, 336px);
}

.seg-inline.seg-n-4 {
  width: min(100%, 440px);
}

/* The pill sits in one of up to four equal slots: width from .seg-n-N, place from .seg-pos-P, so choosing an option is a
   class swap and the browser animates the slide. */
.seg-pill {
  position: absolute;
  z-index: 0;
  top: var(--space-4);
  bottom: var(--space-4);
  left: var(--space-4);
  border-radius: var(--radius-8);
  background: var(--seg-pill);
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  transition: transform var(--dur-2) var(--ease-out);
}

.seg-n-2 > .seg-pill {
  width: calc((100% - 2 * var(--space-4)) / 2);
}

.seg-n-3 > .seg-pill {
  width: calc((100% - 2 * var(--space-4)) / 3);
}

.seg-n-4 > .seg-pill {
  width: calc((100% - 2 * var(--space-4)) / 4);
}

.seg-pos-0 > .seg-pill {
  transform: translateX(0);
}

.seg-pos-1 > .seg-pill {
  transform: translateX(100%);
}

.seg-pos-2 > .seg-pill {
  transform: translateX(200%);
}

.seg-pos-3 > .seg-pill {
  transform: translateX(300%);
}

.seg button.seg-tab {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  gap: var(--space-6);
  min-width: 0;
  min-height: 40px;
  padding: var(--space-10) var(--space-12);
  border: 0;
  border-radius: var(--radius-8);
  background: none;
  box-shadow: none;
  color: var(--text-2-strong);
  font-weight: var(--weight-medium);
  text-align: center;
  transition: color var(--dur-1) var(--ease-out);
}

.seg-sm button.seg-tab {
  min-height: 32px;
  padding: var(--space-6) var(--space-10);
}

/* The tab looks 40px (32px small) and answers a tap over 44px: an invisible extension above and below, sized from the tab. */
.seg button.seg-tab::after {
  content: '';
  position: absolute;
  inset-block: calc(-1 * max(0px, (44px - 100%) / 2));
  inset-inline: 0;
}

/* Four options on a phone leave about 80px each: smaller labels (and badge) so "Memory 3" still fits. */
@media (max-width: 639.98px) {
  .seg-n-4 button.seg-tab {
    gap: var(--space-4);
    padding: var(--space-6) var(--space-2);
    font-size: var(--text-xs-size);
  }

  .seg-n-4 .seg-badge {
    min-width: 16px;
    height: 16px;
    padding: 0 var(--space-4);
    font-size: var(--text-xs-size);
    line-height: 16px;
  }
}

.seg button.seg-tab:hover:not(:disabled) {
  background: none;
  color: var(--text);
}

.seg button.seg-tab[aria-selected='true'] {
  color: var(--text);
  font-weight: var(--weight-semibold);
}

.seg button.seg-tab:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
  box-shadow: none;
}

/* A label may wrap (larger text, a long translation): it is never cut short with an ellipsis. */
.seg-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.seg-badge {
  flex: none;
  min-width: 18px;
  height: 18px;
  padding: 0 var(--space-6);
  border-radius: var(--radius-full);
  background: var(--accent-weak);
  color: var(--accent-weak-text);
  font-size: var(--text-xs-size);
  line-height: 18px;
  font-weight: var(--weight-semibold);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ============================== list rows ============================== */

.ui-list-group {
  min-width: 0;
}

.ui-list-title {
  margin: 0 0 var(--space-8);
  padding: 0 var(--space-4);
  color: var(--text-2);
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
  font-weight: var(--weight-medium);
}

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

/* Rows in a framed card, with hairline dividers that start under the text (after the icon). */
.ui-list-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-12);
  background: var(--surface);
}

.ui-list-item {
  position: relative;
}

.ui-list-item + .ui-list-item::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  left: calc(var(--space-16) + 40px + var(--space-12));
  height: 1px;
  background: var(--border);
}

.ui-list-item:has(> .ui-row-noicon)::before {
  left: var(--space-16);
}

.ui-list-flat .ui-list-item + .ui-list-item::before {
  left: calc(40px + var(--space-12));
}

.ui-list-flat .ui-list-item:has(> .ui-row-noicon)::before {
  left: 0;
}

.ui-list .ui-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-12);
  width: 100%;
  min-height: 56px;
  margin: 0;
  padding: var(--space-8) var(--space-16);
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  color: var(--text);
  font-size: var(--text-md-size);
  line-height: var(--text-md-line);
  font-weight: var(--weight-medium);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur-1) var(--ease-out);
}

.ui-list-flat .ui-row {
  padding-right: 0;
  padding-left: 0;
}

.ui-list .ui-row.ui-row-static {
  cursor: default;
}

.ui-list a.ui-row:hover,
.ui-list button.ui-row:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.ui-list a.ui-row:active,
.ui-list button.ui-row:active:not(:disabled) {
  background: var(--fill);
}

.ui-list .ui-row:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
  box-shadow: none;
}

.ui-row-text {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
  overflow-wrap: anywhere;
}

.ui-row-sub {
  color: var(--text-2);
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
  font-weight: var(--weight-regular);
}

.ui-row-value {
  flex: none;
  max-width: 45%;
  color: var(--text-2);
  font-size: var(--text-md-size);
  font-weight: var(--weight-regular);
  text-align: right;
  overflow-wrap: anywhere;
}

.ui-row-chevron {
  flex: none;
  margin-right: calc(-1 * var(--space-4));
  color: var(--text-2);
  transition: transform var(--dur-2) var(--ease-out);
}

.ui-list a.ui-row:hover .ui-row-chevron,
.ui-list button.ui-row:hover:not(:disabled) .ui-row-chevron {
  transform: translateX(var(--space-2));
}

.ui-row-badge {
  flex: none;
}

/* The icon tile is the shared .featured.circle from styles.css; a tone swaps it to the actor's tint. */
.ui-row-icon.tone-solar {
  border-color: transparent;
  background: var(--energy-solar-weak);
  color: var(--energy-solar);
}

.ui-row-icon.tone-battery {
  border-color: transparent;
  background: var(--energy-battery-weak);
  color: var(--energy-battery);
}

.ui-row-icon.tone-grid {
  border-color: transparent;
  background: var(--energy-grid-weak);
  color: var(--energy-grid);
}

.ui-row-icon.tone-home {
  border-color: transparent;
  background: var(--energy-home-weak);
  color: var(--energy-home);
}

.ui-row-icon.tone-ok {
  border-color: transparent;
  background: var(--ok-weak);
  color: var(--ok);
}

.ui-row-icon.tone-warn {
  border-color: transparent;
  background: var(--warn-weak);
  color: var(--warn);
}

.ui-row-icon.tone-crit {
  border-color: transparent;
  background: var(--crit-weak);
  color: var(--crit);
}

.ui-row-icon.tone-info {
  border-color: transparent;
  background: var(--info-weak);
  color: var(--info);
}

/* Destructive (Log out): the same row in the error colours; keep it last in its own group. */
.ui-list .ui-row.ui-row-destructive {
  color: var(--crit-text);
}

.ui-row-destructive .ui-row-icon {
  border-color: transparent;
  background: var(--crit-weak);
  color: var(--crit);
}

.ui-list .ui-row.is-disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* The switch: Eon's 44 x 24 track, with an outline when off so it is a visible control in both themes. On = brand fill. */
button.ui-switch {
  position: relative;
  flex: none;
  width: 46px;
  height: 26px;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 2px solid var(--text-faint);
  border-radius: var(--radius-full);
  background: var(--fill);
  box-shadow: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color var(--dur-2) var(--ease-out),
    border-color var(--dur-2) var(--ease-out);
}

button.ui-switch:hover:not(:disabled) {
  background: var(--fill);
}

button.ui-switch[aria-checked='true'] {
  border-color: var(--accent);
  background: var(--accent-solid);
}

button.ui-switch[aria-checked='true']:hover:not(:disabled) {
  background: var(--accent-solid-hover);
}

button.ui-switch:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  box-shadow: var(--focus-ring-brand);
}

button.ui-switch:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button.ui-switch[aria-busy='true'] {
  cursor: progress;
}

.ui-switch-knob {
  position: absolute;
  top: 50%;
  left: 3px;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  border-radius: var(--radius-full);
  background: var(--text-faint);
  transition:
    transform var(--dur-2) var(--ease-out),
    background-color var(--dur-2) var(--ease-out);
}

.ui-switch[aria-checked='true'] > .ui-switch-knob {
  transform: translateX(20px);
  background: var(--text-on-accent);
}

/* ============================== stat ============================== */

.ui-stat {
  display: grid;
  align-content: start;
  gap: var(--space-2);
  min-width: 0;
}

.ui-stat-label {
  color: var(--text-2);
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
  font-weight: var(--weight-medium);
}

.ui-stat-figure {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2) var(--space-8);
  min-width: 0;
  color: var(--text);
  transition: color var(--dur-2) var(--ease-out);
}

/* The number never splits; the unit may drop under it when the text is enlarged and the tile is narrow. */
.ui-stat-figure .fig-num {
  white-space: nowrap;
}

.ui-stat-tile-figure {
  font-size: var(--text-lg-size);
  line-height: var(--text-lg-line);
  font-weight: var(--weight-semibold);
}

.ui-stat-caption {
  color: var(--text-2);
  font-size: var(--text-xs-size);
  line-height: var(--text-xs-line);
}

.ui-stat-boxed {
  padding: var(--space-12) var(--space-16);
  border: 1px solid var(--border);
  border-radius: var(--radius-12);
  background: var(--surface);
}

.ui-stat.tone-solar .ui-stat-figure {
  color: var(--energy-solar-text);
}

.ui-stat.tone-battery .ui-stat-figure {
  color: var(--energy-battery-text);
}

.ui-stat.tone-grid .ui-stat-figure {
  color: var(--energy-grid-text);
}

.ui-stat.tone-home .ui-stat-figure {
  color: var(--energy-home-text);
}

.ui-stat.is-muted .ui-stat-figure {
  color: var(--text-2);
}

/* On the brand strip (the Home headline): the strip's own text colours. */
.ui-stat.tone-strip .ui-stat-label,
.ui-stat.tone-strip .ui-stat-caption {
  color: var(--strip-text-2);
}

.ui-stat.tone-strip .ui-stat-figure {
  color: var(--strip-text);
}

/* The delta chip: arrow up / arrow down (the same glyph turned over) / a dash when nothing changed, and a signed number. */
.delta > .eh-icon {
  transition: transform var(--dur-2) var(--ease-out);
}

.delta-down > .delta-icon-arrow {
  transform: rotate(180deg);
}

.delta-flat > .delta-icon-arrow,
.delta-up > .delta-icon-flat,
.delta-down > .delta-icon-flat {
  display: none;
}

/* ============================== ring ============================== */

.ui-ring {
  --ring-bar: var(--accent);
  --ring-track: var(--accent-weak);
  position: relative;
  display: inline-grid;
  flex: none;
  place-items: center;
}

.ui-ring-svg {
  display: block;
}

.ui-ring-track {
  stroke: var(--ring-track);
}

.ui-ring-bar {
  stroke: var(--ring-bar);
  transition:
    stroke-dashoffset calc(var(--dur-3) * 2) var(--ease-out),
    opacity var(--dur-2) var(--ease-out),
    stroke var(--dur-2) var(--ease-out);
}

.ui-ring-bar.is-empty {
  opacity: 0;
}

.ui-ring-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text);
  font-size: var(--text-xs-size);
  line-height: 1;
  font-weight: var(--weight-semibold);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.ring-solar {
  --ring-bar: var(--energy-solar);
  --ring-track: var(--energy-solar-weak);
}

.ring-battery {
  --ring-bar: var(--energy-battery);
  --ring-track: var(--energy-battery-weak);
}

.ring-grid {
  --ring-bar: var(--energy-grid);
  --ring-track: var(--energy-grid-weak);
}

.ring-home {
  --ring-bar: var(--energy-home);
  --ring-track: var(--energy-home-weak);
}

.ring-ok {
  --ring-bar: var(--ok);
  --ring-track: var(--ok-weak);
}

.ring-warn {
  --ring-bar: var(--warn);
  --ring-track: var(--warn-weak);
}

.ring-crit {
  --ring-bar: var(--crit);
  --ring-track: var(--crit-weak);
}

.ring-info {
  --ring-bar: var(--info);
  --ring-track: var(--info-weak);
}

/* ============================== sparkline ============================== */

.ui-spark {
  position: relative;
  display: block;
  width: 100%;
  color: var(--accent);
}

.ui-spark-svg {
  display: block;
  overflow: visible;
}

.ui-spark-line {
  stroke: currentColor;
  vector-effect: non-scaling-stroke;
}

.ui-spark-area {
  fill: currentColor;
  opacity: 0.14;
}

.ui-spark-hl {
  fill: currentColor;
  opacity: 0.12;
}

.ui-spark-zero {
  stroke: var(--border-strong);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  vector-effect: non-scaling-stroke;
}

/* The last-value dot is HTML, positioned by two numbers, because a circle inside the stretched SVG would be an ellipse. */
.ui-spark-dot {
  position: absolute;
  top: calc(var(--spark-y, 50) * 1%);
  left: calc(var(--spark-x, 100) * 1%);
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: var(--radius-full);
  background: currentColor;
  box-shadow: 0 0 0 2px var(--surface);
}

.spark-solar {
  color: var(--energy-solar);
}

.spark-battery {
  color: var(--energy-battery);
}

.spark-grid {
  color: var(--energy-grid);
}

.spark-home {
  color: var(--energy-home);
}

.spark-ok {
  color: var(--ok);
}

.spark-warn {
  color: var(--warn);
}

.spark-crit {
  color: var(--crit);
}

.spark-info {
  color: var(--info);
}

/* ============================== skeleton ============================== */

.ui-skel {
  --skel-hi: var(--surface);
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: var(--radius-6);
  background: var(--border);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .ui-skel {
    --skel-hi: var(--fill-raised);
  }
}

:root[data-theme='dark'] .ui-skel {
  --skel-hi: var(--fill-raised);
}

.ui-skel::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--skel-hi), transparent);
  transform: translateX(-100%);
  animation: ui-shimmer 1.4s ease-in-out infinite;
}

@keyframes ui-shimmer {
  to {
    transform: translateX(100%);
  }
}

.ui-skel-line {
  width: calc(var(--skel-w, 100) * 1%);
  height: 14px;
}

.ui-skel-block {
  height: calc(var(--skel-h, 96) * 1px);
  border-radius: var(--radius-12);
}

.ui-skel-circle {
  flex: none;
  width: calc(var(--skel-size, 40) * 1px);
  height: calc(var(--skel-size, 40) * 1px);
  border-radius: var(--radius-full);
}

.ui-skel-text {
  display: grid;
  gap: var(--space-10);
}

.ui-skel-card {
  display: grid;
  gap: var(--space-16);
}

.ui-skel-rows {
  display: grid;
  gap: var(--space-16);
}

.ui-skel-row {
  display: flex;
  align-items: center;
  gap: var(--space-12);
}

.ui-skel-row-text {
  display: grid;
  flex: 1;
  gap: var(--space-8);
  min-width: 0;
}

/* ============================== empty state ============================== */

.ui-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-32) var(--space-20);
  text-align: center;
}

.ui-empty-compact {
  padding: var(--space-16);
}

.ui-empty-icon {
  width: 56px;
  height: 56px;
  margin-bottom: var(--space-12);
  border-color: transparent;
  background: var(--accent-weak);
  box-shadow: none;
  color: var(--accent);
}

.ui-empty-title {
  margin: 0;
  color: var(--text);
  font-size: var(--text-lg-size);
  line-height: var(--text-lg-line);
  font-weight: var(--weight-semibold);
}

.ui-empty-text {
  max-width: 34ch;
  margin: var(--space-4) 0 0;
  color: var(--text-2);
  font-size: var(--text-sm-size);
  line-height: var(--text-sm-line);
}

.ui-empty button.ui-empty-action {
  margin-top: var(--space-16);
}

/* ============================== disclosure ============================== */

.ui-disclosure {
  min-width: 0;
}

.ui-disclosure-plain {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.ui-disclosure-card {
  padding: 0 var(--space-16);
  border: 1px solid var(--border);
  border-radius: var(--radius-12);
  background: var(--surface);
}

.ui-disc-summary {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  min-height: 48px;
  padding: var(--space-8) 0;
  border-radius: var(--radius-8);
  color: var(--text);
  font-size: var(--text-md-size);
  line-height: var(--text-md-line);
  font-weight: var(--weight-medium);
  list-style: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.ui-disc-summary::-webkit-details-marker {
  display: none;
}

.ui-disc-summary::marker {
  content: '';
}

.ui-disc-summary:focus-visible {
  outline-offset: -2px;
}

.ui-disc-title {
  flex: 1 1 auto;
  min-width: 0;
}

.ui-disc-count {
  flex: none;
  font-variant-numeric: tabular-nums;
}

.ui-disc-chevron {
  flex: none;
  color: var(--text-2);
  transition:
    transform var(--dur-2) var(--ease-out),
    color var(--dur-1) var(--ease-out);
}

.ui-disc-summary:hover .ui-disc-chevron {
  color: var(--text);
}

.ui-disclosure[open] > .ui-disc-summary .ui-disc-chevron {
  transform: rotate(180deg);
}

.ui-disc-body {
  padding: var(--space-4) 0 var(--space-16);
}

/* Smooth open and close where the browser can animate to the content's natural height. */
@supports selector(::details-content) {
  .ui-disclosure {
    interpolate-size: allow-keywords;
  }

  .ui-disclosure::details-content {
    height: 0;
    overflow: clip;
    transition:
      height var(--dur-3) var(--ease-out),
      content-visibility var(--dur-3) allow-discrete;
  }

  .ui-disclosure[open]::details-content {
    height: auto;
  }
}

/* ============================== forced colours ============================== */

/* Windows High Contrast and the other forced-colour modes swap every colour for the system's and drop backgrounds and shadows,
   so whatever is told only by a tint or a fill needs an edge or a system colour instead. The kit's part: the focus ring, the
   chips, the switch and the selected segment (the shell has its own at the foot of css/shell.css). System colour keywords only. */
@media (forced-colors: active) {
  :focus-visible {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }

  .chip,
  .badge,
  .seg-badge {
    border: 1px solid CanvasText;
  }

  button.ui-switch {
    forced-color-adjust: none;
    border-color: ButtonText;
    background: Canvas;
  }

  button.ui-switch > .ui-switch-knob {
    background: ButtonText;
  }

  button.ui-switch[aria-checked='true'] {
    border-color: Highlight;
    background: Highlight;
  }

  button.ui-switch[aria-checked='true'] > .ui-switch-knob {
    background: HighlightText;
  }

  button.ui-switch:disabled {
    border-color: GrayText;
  }

  button.ui-switch:disabled > .ui-switch-knob {
    background: GrayText;
  }

  .seg {
    border: 1px solid CanvasText;
  }

  .seg-pill {
    forced-color-adjust: none;
    background: Highlight;
    box-shadow: none;
  }

  .seg button.seg-tab[aria-selected='true'] {
    forced-color-adjust: none;
    color: HighlightText;
  }
}

/* ============================== reduced motion ============================== */

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

  .ui-skel::after {
    display: none;
  }

  dialog,
  dialog::backdrop,
  .seg-pill,
  .ui-ring-bar,
  .ui-disclosure::details-content {
    transition: none;
  }
}
