:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-soft: #edf3f1;
  --text: #172026;
  --muted: #60717a;
  --border: #d8e2df;
  --accent: #17745f;
  --accent-strong: #0e5c4b;
  --heat: #be3a34;
  --power: #245eb8;
  --warn: #b7791f;
  --shadow: 0 12px 30px rgba(18, 38, 45, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 68px;
  padding: 0.8rem clamp(1rem, 2.5vw, 2rem);
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 0.1rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
}

.main-nav a {
  flex: 0 0 auto;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
}

.main-nav a.active {
  background: var(--surface);
  color: var(--accent-strong);
  box-shadow: 0 1px 4px rgba(18, 38, 45, 0.08);
}

/* Unterseiten eines Agents, gleiche Form wie .view-switch, in der zweiten Kopfzeile rechts. */
.sub-nav {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.2rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-soft);
  overflow-x: auto;
}

.sub-nav a {
  flex: 0 0 auto;
  padding: 0.35rem 0.65rem;
  border-radius: 5px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 750;
}

.sub-nav a.active {
  background: var(--surface);
  color: var(--accent-strong);
  box-shadow: 0 1px 3px rgba(34, 45, 50, 0.12);
}

.page-subnav {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.75rem;
}

.page-subnav:not(:has(> :not([hidden]))) {
  display: none;
}

.header-subnav:not(:has(> :not([hidden]))) {
  display: none;
}

.header-subnav {
  display: flex;
  flex: 1 0 100%;
  justify-content: flex-end;
  align-items: center;
  gap: 0.6rem;
}

.reset-button {
  min-height: 38px;
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 750;
  cursor: pointer;
}

.reset-button:hover {
  border-color: #d8433e;
  color: #b42318;
}

.reset-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.page {
  width: 100%;
  margin: 0;
  padding: clamp(1rem, 2.2vw, 2rem);
}

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.page-heading h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  line-height: 1.05;
}

.page-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.6rem;
}

.eyebrow {
  margin: 0 0 0.3rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.health-pill {
  flex: 0 0 auto;
  padding: 0.45rem 0.7rem;
  border: 1px solid #b9ddd1;
  border-radius: 999px;
  background: #e9f7f1;
  color: var(--accent-strong);
  font-size: 0.84rem;
  font-weight: 700;
}

.status-grid,
.split-grid,
.section-grid,
.power-grid {
  display: grid;
  gap: 1rem;
}

.status-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 1rem;
}

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

.section-grid {
  grid-template-columns: minmax(240px, 0.8fr) minmax(320px, 1.15fr) minmax(320px, 1.15fr);
}

.section-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metric-card,
.work-card,
.power-metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 94px;
  padding: 1rem;
}

.metric-card span,
.power-metric span,
.muted {
  color: var(--muted);
  font-size: 0.84rem;
}

.metric-card strong {
  display: block;
  margin-top: 0.5rem;
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  overflow-wrap: anywhere;
}

.work-card {
  margin-bottom: 1rem;
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  min-height: 54px;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.card-header h2 {
  margin: 0;
  font-size: 1rem;
}

.card-header a {
  color: var(--accent-strong);
  font-weight: 700;
  text-decoration: none;
}

.view-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.2rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-soft);
}

.view-switch button {
  min-height: 32px;
  padding: 0.35rem 0.65rem;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 750;
  cursor: pointer;
}

.view-switch button.active {
  background: var(--surface);
  color: var(--accent-strong);
  box-shadow: 0 1px 3px rgba(34, 45, 50, 0.12);
}

.kv-list {
  display: grid;
  gap: 0.75rem;
  margin: 0;
  padding: 1rem;
}

.kv-list div {
  display: grid;
  grid-template-columns: minmax(110px, 0.45fr) minmax(0, 1fr);
  gap: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.kv-list div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

dt {
  color: var(--muted);
  font-size: 0.84rem;
}

dd {
  margin: 0;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  padding: 0.8rem 1rem 0;
}

.legend-row.pump {
  padding-top: 0.5rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
  font-family: inherit;
  cursor: pointer;
}

.legend-item.hidden {
  opacity: 0.38;
}

.legend-item i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dot);
}

.heat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.8rem 1rem;
}

.heat-tabs,
.heat-time-nav {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  overflow-x: auto;
}

.heat-tabs button,
.heat-time-nav button,
.heat-time-nav input {
  flex: 0 0 auto;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
}

.heat-tabs button,
.heat-time-nav button {
  padding: 0.45rem 0.65rem;
  cursor: pointer;
  font-weight: 700;
}

.heat-tabs button.active {
  border-color: #b9ddd1;
  background: #e9f7f1;
  color: var(--accent-strong);
}

.heat-time-nav input {
  padding: 0.4rem 0.55rem;
  color: var(--muted);
}

.icon-button {
  width: 36px;
  padding: 0;
}

.loading-bar {
  height: 3px;
  overflow: hidden;
  background: var(--surface-soft);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.loading-bar.active {
  opacity: 1;
}

.loading-bar-fill {
  width: 38%;
  height: 100%;
  background: var(--accent);
  transform: translateX(-100%);
}

.loading-bar.active .loading-bar-fill {
  animation: loading-slide 0.9s ease-in-out infinite;
}

@keyframes loading-slide {
  0% {
    transform: translateX(-110%);
  }

  100% {
    transform: translateX(280%);
  }
}

.chart-shell {
  position: relative;
  height: 320px;
  margin: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(23, 116, 95, 0.08), rgba(36, 94, 184, 0.06)),
    var(--surface-soft);
  overflow: hidden;
}

.heat-chart-shell {
  height: 460px;
  background: var(--surface);
}

.heat-chart-shell canvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.heat-chart-tooltip {
  position: absolute;
  z-index: 2;
  min-width: 220px;
  max-width: min(320px, calc(100% - 16px));
  max-height: calc(100% - 16px);
  padding: 0.75rem;
  overflow-y: auto;
  border: 1px solid rgba(14, 92, 75, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 14px 30px rgba(18, 38, 45, 0.16);
  color: var(--text);
  font-size: 0.8rem;
  pointer-events: none;
}

.heat-chart-tooltip[hidden] {
  display: none;
}

.tooltip-title {
  margin-bottom: 0.5rem;
  color: var(--accent-strong);
  font-weight: 800;
}

.tooltip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.18rem 0;
}

.tooltip-row span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
}

.tooltip-row i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--dot);
}

.tooltip-row strong {
  font-variant-numeric: tabular-nums;
}

.chart-shell.compact {
  height: 220px;
}

.chart-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 100% 25%, 12.5% 100%;
  opacity: 0.65;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  color: var(--muted);
  font-weight: 650;
  text-align: center;
}

.chart-empty.hidden {
  display: none;
}

.status-line {
  padding: 0.7rem 1rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border-top: 1px solid var(--border);
}

.table-footer .status-line {
  border-top: 0;
}

.table-pagination {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 1rem;
  color: var(--muted);
  font-size: 0.84rem;
  white-space: nowrap;
}

.table-pagination button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

/* Scrolls inside its own box so the column headers can stay sticky. */
.table-scroll {
  max-height: 70vh;
  overflow-y: auto;
}

.table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  box-shadow: inset 0 -1px 0 var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

th,
td {
  padding: 0.65rem 0.8rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--accent-strong);
  background: #f8fbfa;
  font-weight: 750;
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

.section-list {
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

.section-list h3 {
  margin: 0 0 0.55rem;
  color: var(--accent-strong);
  font-size: 0.95rem;
}

.section-list h4 {
  margin: 0.75rem 0 0.4rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.param-table td:first-child {
  width: 44%;
  color: var(--muted);
}

.param-table {
  table-layout: fixed;
}

.param-table td {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.param-table.compact {
  margin-bottom: 0.3rem;
}

.controller-state-list {
  display: grid;
  gap: 0.8rem;
  padding: 0 1rem 1rem;
}

.controller-state {
  min-width: 0;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border);
}

.controller-state h3 {
  margin: 0 0 0.25rem;
  color: var(--accent-strong);
  font-size: 0.9rem;
}

.controller-state span {
  display: block;
  margin-bottom: 0.45rem;
  color: var(--muted);
  font-size: 0.76rem;
}

.controller-state pre {
  max-width: 100%;
  margin: 0;
  padding: 0.7rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-soft);
  font-size: 0.76rem;
  line-height: 1.35;
}

.empty-note {
  margin: 0;
  padding: 0 1rem 1rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.power-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 1rem;
}

.power-metric {
  min-height: 116px;
  padding: 1rem;
  box-shadow: none;
}

.power-metric strong {
  display: inline-block;
  margin-top: 0.7rem;
  font-size: 2rem;
}

.power-metric small {
  margin-left: 0.25rem;
  color: var(--muted);
  font-weight: 700;
}

@media (max-width: 980px) {
  .status-grid,
  .split-grid,
  .section-grid,
  .section-grid.two,
  .power-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .app-header,
  .page-heading,
  .heat-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .main-nav {
    width: 100%;
  }

  .status-grid,
  .split-grid,
  .section-grid,
  .section-grid.two,
  .power-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .kv-list div {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.25rem;
  }

  .chart-shell {
    height: 260px;
  }

  .heat-chart-shell {
    height: 340px;
  }

  .heat-tabs,
  .heat-time-nav,
  .table-footer {
    width: 100%;
  }

  .table-footer {
    align-items: stretch;
    flex-direction: column;
    gap: 0;
  }

  .table-pagination {
    justify-content: space-between;
  }

  .header-subnav,
  .header-subnav .view-switch {
    width: 100%;
  }

  .header-subnav .view-switch button {
    flex: 1 1 0;
  }

  .header-subnav,
  .page-subnav {
    justify-content: flex-start;
  }

  .sub-nav {
    max-width: 100%;
  }

  .page-tools {
    justify-content: flex-start;
  }

  .param-table td:first-child {
    width: 50%;
  }
}

.buffer-diagram-card {
  margin-bottom: 1rem;
}

.buffer-diagram {
  overflow-x: auto;
  padding: 0.75rem 1rem 1rem;
}

.buffer-diagram svg {
  display: block;
  width: 100%;
  min-width: 760px;
  max-width: 1280px;
  height: auto;
  margin: 0 auto;
}

/* Gemeinsame Diagramme (series-chart.js) und Strom-Ansicht (power-dashboard.js) */
.series-chart-shell {
  height: 300px;
}

.counter-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.counter-controls select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: var(--surface);
}

.counter-table td:not(:first-child),
.counter-table th:not(:first-child) {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ViCare (vicare-dashboard.js, lokal und Server) */
.feature-table td:first-child{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.8rem}
.vicare-features{padding:.75rem 1rem 1rem}
.vicare-features summary{cursor:pointer;color:var(--accent);font-weight:600}

/* Legende der Modus-Kuerzel ueber der Tabelle (heat-dashboard.js) */
.mode-legend{display:flex;flex-wrap:wrap;gap:.35rem 1.25rem;margin:0;padding:.6rem 1rem .4rem;font-size:.85rem;color:var(--muted)}
.mode-legend div{display:flex;gap:.35rem}
.mode-legend dt{font-weight:700;color:var(--text,inherit)}
.mode-legend dd{margin:0}
.heat-toolbar[hidden]{display:none}

/* Waermezaehler (heat-meter-dashboard.js, lokal und Server) */
.hm-table td:not(:first-child),.hm-table th:not(:first-child){text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}
.hm-table tbody tr{cursor:pointer}
.hm-table tbody tr:hover{background:var(--surface-soft)}
.hm-table tbody tr.hm-selected{background:#dff3ea}
.hm-table tbody tr.hm-stale td{color:var(--muted)}
.hm-table .hm-age-stale{color:var(--heat);font-weight:600}
.hm-house-select{padding:.35rem .5rem;border:1px solid var(--border);border-radius:6px;font:inherit}
