.container {
  max-width: var(--container);
  margin: 0 auto;
  padding: 32px var(--margin) 80px;
}

body.centered {
  display: grid;
  place-items: center;
  min-height: 100vh;
  /* A wash of brand rather than a slab of it. */
  background:
    radial-gradient(1200px 500px at 50% -10%, var(--brand-tint), transparent 70%),
    var(--surface);
}

/* Top bar - the brand carrier, so the red lives here rather than being
   sprinkled through the content. */
.topbar {
  background: var(--brand);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow-sm);
}

.topbar__inner {
  max-width: var(--container);
  margin: 0 auto;
  padding: 12px var(--margin);
  display: flex;
  align-items: center;
  gap: var(--gap);
}

.brand {
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 1.0625rem;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

/* A rotated rounded square - reads as a node or a rack tile, which suits a
   data centre tool. Drawn in CSS so there is no asset to go missing. */
.brand::before {
  content: "";
  width: 17px;
  height: 17px;
  border-radius: 5px;
  border: 3px solid #fff;
  transform: rotate(45deg);
  flex: none;
}

.topbar .muted { color: rgba(255, 255, 255, 0.82); }

.topbar__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-bottom: 16px;
  font-size: 0.875rem;
}

.crumb {
  background: none;
  border: 0;
  padding: 4px 2px;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crumb:last-of-type {
  color: var(--ink);
  font-weight: 600;
}

.crumb__sep {
  color: var(--muted);
}

/* Toolbar */
.toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.toolbar__spacer {
  flex: 1;
}

/* Hero */
.hero {
  padding: 26px 28px 22px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  /* A brand edge rather than a brand fill - the numbers stay the loudest
     thing on the page. */
  border-top: 3px solid var(--brand);
  margin-bottom: 20px;
}

.hero__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: 24px;
}

.hero__eyebrow {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero__title {
  font-size: 2rem;
  margin: 0;
  overflow-wrap: anywhere;
}

.hero__metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

/* Tiles share hairlines instead of boxes: less furniture, same grouping. */
.metric + .metric {
  border-left: 1px solid var(--border);
  padding-left: 24px;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric__label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric__value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.metric--primary .metric__value {
  font-size: 2.75rem;
  color: var(--brand-dark);
}

/* Secondary rendering of the same figure, e.g. GWh beside MWh. */
.metric__sub {
  font-size: 0.8125rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* The qualifier that keeps a figure honest: its range, or that it was fitted. */
.metric__note {
  display: block;
  margin-top: 4px;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--muted);
  max-width: 24ch;
}

.hero__sub {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.hierarchy-summary {
  margin: 4px 0 20px;
}

/* What the headline numbers actually cover. */
.hero__scope {
  margin: 8px 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.hero__scope strong {
  color: var(--ink);
}

/* How the figures were arrived at, stated next to them. */
.basis {
  margin: 14px 0 0;
  padding: 10px 14px;
  border-left: 3px solid var(--border);
  background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.basis--calibrated {
  border-left-color: var(--success);
}

.basis strong {
  color: var(--ink);
}

.link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.details-toggle {
  margin-bottom: 20px;
}

/* Teal outline so it reads clearly against the page, without competing with
   primary (filled) actions. The two-class selector outranks the .button--ghost
   rule in forms.css (loaded later), which would otherwise win on source order
   and keep the button faint. */
.button.details-toggle {
  color: var(--brand-dark);
  border-color: var(--brand);
  background: var(--brand-tint);
}

.button.details-toggle:hover:not(:disabled) {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}

/* Panels */
.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px;
  margin-bottom: 28px;
  background: var(--bg);
  box-shadow: var(--shadow-sm);
}

.panel__subtitle {
  margin-top: 20px;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

/* Stats grid */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

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

.stat span {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.stat strong {
  font-size: 1.375rem;
  letter-spacing: -0.01em;
}

.stat small {
  color: var(--muted);
  font-size: 0.75rem;
}

/* Charts */
.charts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

.chart {
  margin: 0;
}

.chart--wide {
  grid-column: 1 / -1;
}

.chart figcaption {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 8px;
}

.chart__canvas {
  position: relative;
  height: 240px;
}

.chart-fallback {
  width: 100%;
  height: 120px;
}

/* Ranked list */
.ranked {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.ranked li {
  display: grid;
  grid-template-columns: 1fr auto 64px;
  gap: 12px;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.ranked small {
  color: var(--muted);
  text-align: right;
}

/* List of child nodes */
.list-header {
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.list-title {
  margin: 0;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.list-header__actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
}

.row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.row__select {
  padding: 0 12px 0 4px;
  display: flex;
  align-items: center;
  min-height: 44px;
}

.row--device .row__select {
  display: none;
}

.row__main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(160px, 1.4fr) minmax(80px, 1fr) auto;
  gap: var(--gap);
  align-items: center;
  min-height: 56px;
  padding: 10px 8px;
  background: none;
  border: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.row__main:hover {
  background: var(--surface);
}

.row:hover {
  background: var(--surface);
}

.row__name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.row__bar {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-sunken);
  overflow: hidden;
}

.row__bar-fill {
  display: block;
  height: 100%;
  background: var(--brand);
  border-radius: 3px;
}

.row__stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
}

.row__peak {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.row__meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.row--device .row__main {
  grid-template-columns: minmax(160px, 1.2fr) minmax(120px, 1fr) auto;
}

/* Row delete. Present but understated, so it cannot be hit by accident while
   drilling down; a confirmation with the impact follows regardless. */
.row__delete {
  flex: none;
  width: 44px;
  min-height: 44px;
  border: 0;
  background: none;
  color: var(--border);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius);
  transition: color 0.12s ease, background 0.12s ease;
}

.row:hover .row__delete {
  color: var(--muted);
}

.row__delete:hover,
.row__delete:focus-visible {
  color: var(--error);
  background: rgba(239, 68, 68, 0.1);
}

.row--more {
  justify-content: center;
  padding: 12px 0;
}

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.table th,
.table td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.table tbody tr:hover {
  background: var(--surface);
}

.table thead th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.insights {
  margin: 16px 0 0;
  padding-left: 20px;
  font-size: 0.875rem;
  color: var(--muted);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 96px 0;
}

/* Login */
.login {
  width: min(430px, calc(100vw - 40px));
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 44px 40px 36px;
  box-shadow: var(--shadow-lg);
  border-top: 4px solid var(--brand);
}

.login__title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login__title::before {
  content: "";
  width: 24px;
  height: 24px;
  border-radius: 7px;
  border: 4px solid var(--brand);
  transform: rotate(45deg);
  flex: none;
}

.login__title {
  margin-bottom: 4px;
}

.login__form {
  margin-top: 28px;
}

.login__foot {
  margin: 20px 0 0;
  font-size: 0.8rem;
}

/* Loader and toasts */
.loader {
  position: fixed;
  bottom: 24px;
  left: 24px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
  font-size: 0.875rem;
  z-index: 40;
}

.toasts {
  position: fixed;
  top: 72px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
  max-width: min(380px, calc(100vw - 48px));
}

.toast {
  padding: 13px 16px;
  border-radius: var(--radius);
  border-left: 4px solid var(--brand);
  background: var(--bg);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  animation: slideIn 0.2s ease-out;
}

.toast--success { border-left-color: var(--success); }
.toast--error { border-left-color: var(--danger); }

@keyframes slideIn {
  from { transform: translateX(16px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Modals */
.modal {
  width: min(560px, calc(100vw - 40px));
  border: 0;
  border-radius: var(--radius-lg);
  padding: 0;
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}

.modal--wide {
  width: min(900px, calc(100vw - 40px));
}

.modal::backdrop {
  background: rgba(26, 23, 25, 0.5);
  backdrop-filter: blur(2px);
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 20px 26px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.modal__head h2 {
  margin: 0;
  overflow-wrap: anywhere;
}

.modal__body {
  padding: 24px;
  max-height: 70vh;
  overflow: auto;
}

.spec {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 8px 20px;
  margin: 0;
  font-size: 0.875rem;
}

.spec dt {
  color: var(--muted);
}

.spec dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* Wide content must scroll inside its own box, never the page. */
#compare-table,
#search-results,
#catalog-body {
  overflow-x: auto;
}

/* Catalogue */
.modal__head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: 8px 0 16px;
}

.tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  min-height: 44px;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
}

.tab--active {
  color: var(--brand-dark);
  border-bottom-color: var(--brand);
  font-weight: 600;
}

.table--catalog th[scope="row"] {
  font-weight: 600;
}

.d-block {
  display: block;
}

.sparkline {
  width: 72px;
  height: 20px;
  color: var(--brand);
  display: block;
}

.curve-cell {
  min-width: 84px;
}

.pager {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  padding: 16px 0 0;
}

.editor-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 28px;
  align-items: start;
}

.editor-grid__fields {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0 16px;
}

.field--wide {
  grid-column: 1 / -1;
}

.editor-grid__actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.curve-inputs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.curve-inputs .field {
  margin-bottom: 10px;
}

.curve-inputs label {
  text-align: center;
}

.curve-inputs input {
  padding: 8px 4px;
  text-align: center;
}

.curve-preview {
  margin-top: 12px;
}

.curve-chart {
  width: 100%;
  height: 120px;
  color: var(--brand);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
}

.curve-axis {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 4px;
}

.history {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.history li {
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}

.history time {
  color: var(--ink);
  margin-right: 8px;
}

/* Column mapping */
.map-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 18px 14px;
  margin: 0 0 16px;
}

.map-group legend {
  padding: 0 8px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.map-row {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(220px, 1.2fr);
  gap: 16px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.map-row:last-child {
  border-bottom: 0;
}

.map-row > label {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: normal;
  color: var(--ink);
}

.map-row > label small {
  font-weight: 400;
  margin-top: 2px;
}

.map-row select {
  min-height: 40px;
}

/* Two fields pointing at the same column is usually a mistake. */
.map-row--warn {
  background: rgba(245, 158, 11, 0.09);
  border-radius: 6px;
}

.map-row--warn select {
  border-color: var(--warning);
}

@media (max-width: 768px) {
  .map-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

@media (max-width: 900px) {
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .editor-grid__fields {
    grid-template-columns: 1fr;
  }
}

/* Responsive */
@media (max-width: 1024px) {
  .container,
  .topbar__inner {
    padding-left: 20px;
    padding-right: 20px;
  }

  .hero__metrics {
    grid-template-columns: repeat(2, 1fr);
  }

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

@media (max-width: 768px) {
  .hero__metrics {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .metric--primary .metric__value {
    font-size: 2.25rem;
  }

  .row__main {
    grid-template-columns: 1fr auto;
  }

  .row__bar {
    display: none;
  }

  .crumb {
    max-width: 120px;
  }

  .spec {
    grid-template-columns: 1fr;
    gap: 2px 0;
  }

  .spec dd {
    margin-bottom: 10px;
  }
}
