:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);

  --production: #008300;
  --consumption: #eb6834;
  --battery: #2a78d6;
  --grid-import: #e34948;
  --grid-export: #4a3aa7;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
  --paper: #fffdf6;
  --sun: #f6b93b;
}


* { box-sizing: border-box; }

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

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

.flow-diagram {
  background:
    repeating-linear-gradient(var(--paper, #fffdf6) 0 27px, rgba(120, 150, 210, 0.12) 27px 28px),
    var(--paper, #fffdf6);
  border: 2px solid var(--text-primary);
  border-radius: 3px 14px 4px 16px / 12px 4px 16px 4px;
  padding: 10px;
  margin-bottom: 10px;
  position: relative;
  box-shadow: 3px 4px 0 rgba(11, 11, 11, 0.06);
}
.flow-diagram::before {
  content: "";
  position: absolute;
  left: 34px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(211, 90, 90, 0.35);
  pointer-events: none;
}
.flow-diagram svg { width: 100%; height: auto; display: block; }

.flow-diagram .ink { fill: none; stroke: var(--text-primary); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.flow-diagram .ink-fill { fill: var(--surface); stroke: var(--text-primary); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.flow-diagram .muted-fill { fill: var(--gridline); stroke: var(--text-primary); stroke-width: 2; }
.flow-diagram .icon-label {
  fill: var(--text-secondary);
  font-size: 15px;
  text-anchor: middle;
  font-family: "Patrick Hand", "Comic Sans MS", cursive, sans-serif;
}
.flow-diagram .icon-value {
  font-size: 17px;
  font-weight: 400;
  text-anchor: middle;
  font-variant-numeric: normal;
  font-family: "Patrick Hand", "Comic Sans MS", cursive, sans-serif;
}

.flow-diagram .battery-fill {
  fill: var(--battery);
  transition: height 0.8s ease, y 0.8s ease;
}
.flow-diagram .icon-value { transition: fill 0.4s ease; }

.flow-diagram .flow-line {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 7 7;
  animation: flow-dash 0.9s linear infinite;
  transition: stroke 0.5s ease, opacity 0.5s ease;
}
.flow-diagram .flow-reverse { animation-direction: reverse; }
.flow-diagram .flow-idle {
  stroke: var(--gridline);
  stroke-dasharray: none;
  animation: none;
  opacity: 0.6;
}
.flow-diagram .flow-production { stroke: var(--production); }
.flow-diagram .flow-consumption { stroke: var(--consumption); }
.flow-diagram .flow-battery { stroke: var(--battery); }
.flow-diagram .flow-grid-import { stroke: var(--grid-import); }
.flow-diagram .flow-grid-export { stroke: var(--grid-export); }
.flow-diagram .sun2Ray { stroke: var(--sun); }

@keyframes flow-dash {
  to { stroke-dashoffset: -28; }
}

/* Heat pump fan spins only while the device is actually running */
#hpFan { transition: opacity 0.4s ease; }
#hpFan.spin { animation: hp-spin 2.4s linear infinite; }
@keyframes hp-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .flow-diagram .flow-line,
  #hpFan.spin {
    animation: none;
  }
}

/* Heat pump card: same paper look as the flow diagram */
.hp-card {
  background:
    repeating-linear-gradient(var(--paper) 0 27px, rgba(120, 150, 210, 0.12) 27px 28px),
    var(--paper);
  border: 2px solid var(--text-primary);
  border-radius: 14px 3px 16px 4px / 4px 12px 4px 16px;
  padding: 12px 18px 10px 50px;
  margin-bottom: 10px;
  position: relative;
  box-shadow: 3px 4px 0 rgba(11, 11, 11, 0.06);
  font-family: "Patrick Hand", "Comic Sans MS", cursive, sans-serif;
  font-size: 18px;
  line-height: 28px;
}
.hp-card::before {
  content: "";
  position: absolute;
  left: 34px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(211, 90, 90, 0.35);
}
.hp-card h2 { margin: 0 0 4px; font-size: 24px; font-weight: 400; }
.hp-card .hp-status { font-size: 18px; color: var(--text-secondary); margin-left: 8px; }
.hp-card dl {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(115px, 1fr));
  gap: 0 20px;
  margin: 0;
}
.hp-card dt { color: var(--text-secondary); font-size: 15px; }
.hp-card dd { margin: 0 0 4px; font-size: 20px; }
.hp-card p { margin: 4px 0 0; }
.hp-card .hp-muted { color: var(--text-muted); font-size: 15px; }
.hp-card .hp-stale { color: var(--status-warning); }
.hp-card .hp-error { color: var(--status-critical); }
.hp-card a { color: var(--battery); }

/* Register page */
.hp-regs h2 { margin-bottom: 8px; }
.hp-regs .hp-back { font-size: 16px; }
.hp-tools { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; }
.hp-tools input[type="search"] {
  font: inherit;
  font-size: 17px;
  padding: 2px 8px;
  border: 2px solid var(--text-primary);
  border-radius: 3px 10px 4px 8px;
  background: var(--surface);
  min-width: 0;
  width: 260px;
  max-width: 100%;
}
.hp-table-wrap { overflow-x: auto; margin-top: 8px; }
.hp-table { border-collapse: collapse; width: 100%; font-size: 16px; line-height: 22px; }
.hp-table th, .hp-table td {
  text-align: left;
  vertical-align: top;
  padding: 4px 8px;
  border-bottom: 1px solid rgba(11, 11, 11, 0.12);
}
.hp-table thead th { color: var(--text-secondary); font-weight: 400; border-bottom: 2px solid var(--text-primary); }
.hp-table .hp-group th { font-size: 20px; padding-top: 16px; border-bottom: 2px solid var(--text-primary); }
.hp-table .hp-num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hp-table .hp-range { color: var(--text-secondary); font-size: 14px; line-height: 18px; margin-top: 2px; }
.hp-table .hp-live { font-size: 18px; min-width: 110px; }
.hp-table .hp-access { font-size: 14px; white-space: nowrap; }
.hp-table .hp-rw { color: var(--consumption); }
.hp-table .hp-r { color: var(--text-muted); }
.hp-table .hp-unsupported td { opacity: 0.45; }
.hp-table .hp-changed .hp-live { background: rgba(246, 185, 59, 0.35); }
.hp-table .hp-access-m { display: none; font-size: 13px; }
@media (max-width: 600px) {
  .hp-table th:nth-child(3), .hp-table td:nth-child(3),
  .hp-table th:nth-child(4), .hp-table td:nth-child(4) { display: none; }
  .hp-table .hp-group th { display: table-cell; }
  .hp-table .hp-access-m { display: inline; }
  .hp-card.hp-regs { padding-left: 42px; padding-right: 10px; }
}
.hp-badge {
  display: inline-block;
  font-size: 13px;
  line-height: 18px;
  padding: 0 6px;
  border: 1px solid var(--text-muted);
  border-radius: 8px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--page);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  max-width: 90vw;
}
.toast.error { background: var(--status-critical); color: #fff; }
