:root {
  color-scheme: dark;
  font: 16px/1.5 system-ui, sans-serif;
  background: #10151c;
  color: #edf3fb;
  --muted: #a6b7ca;
}

* { box-sizing: border-box; }
main { max-width: 74rem; margin: auto; padding: clamp(1rem, 4vw, 3rem); }
header, .card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: .7rem; }
header { flex-wrap: wrap; align-items: end; margin-bottom: 1.5rem; }
h1, h2, p, dl, dd { margin: 0; }
h1 { font-size: clamp(2rem, 5vw, 3.5rem); line-height: 1.15; }
h2 { font-size: 1.3rem; }
.eyebrow { color: #9bc8ff; font-size: .7rem; font-weight: 750; letter-spacing: .13em; }
#refresh-status, dt, .detail { color: var(--muted); font-size: .85rem; }
.dashboard { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1rem; }
section {
  grid-column: span 2;
  border: 1px solid #354356;
  border-radius: 1rem;
  padding: 1.15rem;
  background: #1a2330;
}
.deye, .leaf, .tesy, .programming { grid-column: 1 / -1; }
.leaf .eyebrow { color: #89dddc; }
dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; margin-top: 1.15rem; }
dl > div { grid-column: span 2; padding: .65rem; border-radius: .6rem; background: #131b25; }
.leaf dl { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.leaf dl > div { grid-column: span 1; }
dd { font-size: 1.15rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.detail { font-weight: normal; }
.detail:empty { display: none; }
.badge {
  border: 1px solid #46566c;
  border-radius: 1rem;
  padding: .15rem .55rem;
  font-size: .75rem;
  text-align: center;
  color: #d0dced;
}
.badge.good { color: #b5f1be; background: #203d30; border-color: #4a7d5d; }
.badge.warn { color: #ffcf9f; background: #473025; border-color: #8c6344; }
.header-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; }
.login-page { max-width: 29rem; padding-top: clamp(2rem, 12vh, 7rem); }
.login-form {
  display: grid;
  gap: 1rem;
  margin-top: 1.25rem;
  padding: 1.25rem;
  border: 1px solid #354356;
  border-radius: 1rem;
  background: #1a2330;
}
.login-form label { display: grid; gap: .3rem; }
.login-form .remember { display: flex; align-items: center; }
.login-form input:not([type="checkbox"]), button {
  font: inherit;
  color: inherit;
  border: 1px solid #526985;
  border-radius: .45rem;
  background: #131b25;
  padding: .4rem .7rem;
}
button { cursor: pointer; }
button:hover { background: #263b52; }
.login-message { color: #ffcf9f; }
.login-message:empty { display: none; }
.device-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }
.device-actions button { min-height: 2.65rem; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: #1c494a; border-color: #4e9293; }
button.danger { background: #542f35; border-color: #a15f67; }
button.primary:not(:disabled):hover { background: #286264; }
button.danger:not(:disabled):hover { background: #6b3a42; }
progress {
  display: block;
  width: 100%;
  height: .45rem;
  margin-top: .4rem;
  accent-color: #83ce92;
}
progress[hidden] { display: none; }
.leaf progress { accent-color: #79d7cb; }
.charge-progress { margin: .7rem 0; padding: .55rem .65rem; background: #131b25; border-radius: .6rem; }
.command-status { margin-top: .55rem; font-size: .9rem; color: #b5f1be; }
.command-status.warn { color: #ffcf9f; }
.command-status:empty { display: none; }
dialog {
  width: min(34rem, calc(100% - 1.5rem));
  max-height: calc(100% - 2rem);
  overflow: auto;
  border: 1px solid #526985;
  border-radius: 1rem;
  padding: 1rem;
  background: #1a2330;
  color: inherit;
}
dialog::backdrop { background: #080e16ba; }
.control-form { display: grid; gap: .75rem; margin-top: 1rem; }
.control-form label { display: grid; align-content: start; gap: .25rem; }
.control-form .checkbox { display: flex; align-items: center; gap: .5rem; }
.control-form input:not([type="checkbox"]), .control-form select {
  min-width: 0;
  width: 100%;
  font: inherit;
  color: inherit;
  background: #131b25;
  border: 1px solid #526985;
  border-radius: .45rem;
  padding: .45rem .6rem;
}
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
.control-form h3 { margin: 0; }
.tesy dl > div { grid-column: span 1; }
.tesy .detail { margin-top: .55rem; }
.tesy-fields { display: grid; gap: .75rem; }
.tesy-fields [hidden] { display: none; }
#programming-form [hidden] { display: none; }
.tesy-slot { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem; margin-block: .4rem; }
.tesy-fields details > summary { cursor: pointer; }
.tesy-history { max-height: 16rem; overflow: auto; }
.tesy-history table { width: 100%; text-align: left; }
.tesy-history th, .tesy-history td { padding: .2rem .35rem; }
.record-list { display: grid; gap: .5rem; margin: .7rem 0; padding: 0; list-style: none; }
.record-list li { padding: .65rem; background: #131b25; border-radius: .5rem; }
.record-list .device-actions { margin-top: .35rem; }

.deye {
  --solar: #ffcc76;
  --home: #9cc6ff;
  --battery: #84e3bb;
  --grid: #c9b5ff;
  background: radial-gradient(ellipse at 1% 0%, #283342, transparent 60%), #182230;
}.energy-header { align-items: center; margin-bottom: 1rem; }
.energy-header .eyebrow { color: var(--solar); }
.energy-header h2 { font-size: clamp(1.55rem, 3vw, 2.1rem); }
.energy-board { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.12fr); gap: .9rem; }
.energy-flow, .energy-trend {
  min-width: 0;
  border: 1px solid #344358;
  border-radius: .85rem;
  background-color: #111b28;
}
.energy-flow {
  position: relative;
  min-height: 290px;
  isolation: isolate;
  background-image: radial-gradient(#60748a45 1px, transparent 1px);
  background-size: 16px 16px;
}
.flow-caption {
  position: absolute;
  top: .65rem;
  left: .7rem;
  color: var(--muted);
  font-size: .63rem;
  font-weight: 700;
  letter-spacing: .1em;
}
.flow-connections { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.flow-connections path { fill: none; vector-effect: non-scaling-stroke; }
.flow-base { stroke: #465a71; stroke-width: 2; }
.flow-river {
  stroke-width: 0;
  stroke-linecap: round;
  opacity: 0;
  transition: stroke-width .5s cubic-bezier(.3, 1.4, .5, 1), opacity .3s ease;
}
.flow-river.flow-active {
  opacity: 1;
  stroke-width: var(--river-weight, 3);
  stroke-dasharray: 14 10;
  animation: river-flow 1s linear infinite;
  filter: drop-shadow(0 0 6px var(--river-glow, transparent)) drop-shadow(0 0 14px var(--river-glow, transparent));
}
.flow-river.flow-reverse { animation-direction: reverse; }
@keyframes river-flow { to { stroke-dashoffset: -48; } }
@keyframes river-pulse { 0%, 100% { filter: drop-shadow(0 0 6px var(--river-glow)) drop-shadow(0 0 14px var(--river-glow)); } 50% { filter: drop-shadow(0 0 10px var(--river-glow)) drop-shadow(0 0 24px var(--river-glow)); } }
.flow-river[data-flow="pv"] { --river-glow: #ffb340cc; }
.flow-river[data-flow="load"] { --river-glow: #9cc6ffcc; }
.flow-river[data-flow="grid"] { --river-glow: #c9b5ffcc; }
.flow-river[data-flow="battery"] { --river-glow: #84e3bbcc; }
.flow-node, .flow-inverter {
  position: absolute;
  display: grid;
  justify-items: center;
  transform: translate(-50%, -50%);
  text-align: center;
}
.flow-node {
  width: min(31%, 8rem);
  min-height: 4.35rem;
  padding: .45rem .3rem;
  border-radius: .63rem;
  background: #192638;
  border-color: #415571;
  align-content: center;
  transition: box-shadow .4s ease, border-color .3s ease;
}
.flow-node:hover, .flow-node[aria-pressed="true"] { border-color: var(--energy-accent); background: #23344a; }
.flow-node.flow-hot {
  border-color: var(--energy-accent);
  box-shadow: 0 0 0 1px var(--energy-accent), 0 0 18px -2px var(--energy-accent), inset 0 0 14px -6px var(--energy-accent);
  animation: node-pulse 2.2s ease-in-out infinite;
}
@keyframes node-pulse {
  0%, 100% { box-shadow: 0 0 0 1px var(--energy-accent), 0 0 14px -2px var(--energy-accent), inset 0 0 10px -6px var(--energy-accent); }
  50% { box-shadow: 0 0 0 1px var(--energy-accent), 0 0 30px -2px var(--energy-accent), inset 0 0 20px -6px var(--energy-accent); }
}
.node-fill {
  display: block;
  width: 100%;
  height: .38rem;
  margin-top: .35rem;
  border-radius: 99px;
  background: #2d3d52;
  overflow: hidden;
}
.node-fill > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--energy-accent) 55%, #1c2a3d), var(--energy-accent));
  transition: width .55s cubic-bezier(.3, 1.3, .5, 1);
}
.flow-node strong { font-size: clamp(.9rem, 2.4vw, 1.15rem); font-variant-numeric: tabular-nums; white-space: nowrap; }
.flow-node small { color: var(--muted); font-size: .67rem; line-height: 1.15; }
.energy-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem .6rem;
  margin-top: .85rem;
  padding: .55rem .75rem;
  border: 1px solid #344358;
  border-radius: .6rem;
  background: #111b28;
  font-size: .82rem;
  color: var(--muted);
  min-height: 2.5rem;
}
.energy-summary:empty::before { content: 'Se așteaptă măsurătorile…'; }
.energy-summary .tag {
  display: inline-flex;
  align-items: baseline;
  gap: .3rem;
  padding: .18rem .55rem;
  border-radius: 99px;
  border: 1px solid #3b4e65;
  background: #182536;
}
.energy-summary .tag strong { color: var(--energy-accent); font-variant-numeric: tabular-nums; }
.energy-summary .tag::before { content: ''; width: .5rem; height: .5rem; border-radius: 50%; background: var(--energy-accent); box-shadow: 0 0 8px var(--energy-accent); align-self: center; }
.deye :is([data-metric="battery"], [data-flow="battery"], [data-series="battery"], [data-metric="soc"], [data-series="soc"]) { --energy-accent: var(--battery); }
.energy-summary .tag[data-metric="battery"] { --energy-accent: var(--battery); }
.flow-node svg, .flow-inverter svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.flow-inverter {
  top: 50%;
  left: 50%;
  gap: .2rem;
  padding: .65rem .4rem;
  border-radius: .7rem;
  border: 1px solid #536c89;
  background: #263a52;
  color: #d9eaff;
  font-size: .7rem;
}
.flow-inverter svg { width: 1.35rem; height: 1.35rem; }
.flow-solar { top: 17.7%; left: 50%; }
.flow-house { top: 50%; left: 82.5%; }
.flow-battery { top: 82.3%; left: 50%; }
.flow-grid { top: 50%; left: 17.5%; }
.deye :is([data-metric="pv"], [data-flow="pv"], [data-series="pv"]) { --energy-accent: var(--solar); }
.deye :is([data-metric="load"], [data-flow="load"], [data-series="load"]) { --energy-accent: var(--home); }
.deye :is([data-metric="battery"], [data-flow="battery"], [data-series="battery"], [data-metric="soc"], [data-series="soc"]) { --energy-accent: var(--battery); }
.deye :is([data-metric="grid"], [data-flow="grid"], [data-series="grid"]) { --energy-accent: var(--grid); }
.energy-trend { padding: clamp(.65rem, 2vw, 1rem); }
.trend-header, .trend-reading { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .4rem .65rem; align-items: center; }
.trend-header .eyebrow { color: var(--energy-accent); }
.trend-header h3 { margin: 0; font-size: 1.05rem; }
.trend-options { display: flex; flex-wrap: wrap; gap: .3rem; }
.trend-options button {
  min-height: 2rem;
  padding: .2rem .52rem;
  background: #182536;
  border-color: #3b4e65;
  font-size: .76rem;
}
.trend-options button[aria-pressed="true"] { color: var(--energy-accent); border-color: currentColor; background: #243348; }
.trend-options button:hover { background: #243348; }
.trend-metrics { margin-top: .65rem; }
.trend-reading { min-height: 2.5rem; margin-top: .35rem; font-variant-numeric: tabular-nums; }
.trend-reading strong { font-size: clamp(1.1rem, 3vw, 1.5rem); color: var(--energy-accent); }
.trend-reading span { color: var(--muted); font-size: .77rem; }
.trend-plot { border-radius: .4rem; cursor: crosshair; }
.trend-plot:focus-visible, .energy-board button:focus-visible { outline: 2px solid #a9ccf9; outline-offset: 2px; }
.trend-plot svg { display: block; width: 100%; }
.trend-plot text { fill: var(--muted); font-size: 13px; }
.trend-guide { stroke: #314259; stroke-dasharray: 2 4; }
.trend-zero { stroke: #536b86; }
#trend-line { stroke: var(--energy-accent); stroke-width: 2; fill: none; }
#trend-fill { fill: var(--energy-accent); fill-opacity: .13; }
#trend-cursor { stroke: #92a6bf; stroke-dasharray: 4 4; }
#trend-marker { fill: var(--energy-accent); stroke: #111b28; stroke-width: 2; }
#trend-help { margin-top: .25rem; font-size: .75rem; }
#trend-resolution { margin-top: .2rem; color: #aebfdb; font-size: .73rem; }

.forecast { grid-column: 1 / -1; --forecast-accent: #ffcc76; }
.forecast-header { align-items: center; margin-bottom: 1rem; }
.forecast-header .eyebrow { color: var(--forecast-accent); }
.forecast-header h2 { font-size: clamp(1.55rem, 3vw, 2.1rem); }
.forecast-body {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: .9rem;
  align-items: stretch;
}
.forecast-today, .forecast-days {
  border: 1px solid #344358;
  border-radius: .85rem;
  background-color: #111b28;
  padding: .85rem;
}
.forecast-today-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .4rem 1.2rem;
  margin-bottom: .5rem;
}
.forecast-today-head > div:not(.forecast-method) { display: grid; gap: .1rem; }
.forecast-today-head strong {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  color: var(--forecast-accent);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.forecast-today-head span { color: var(--muted); font-size: .72rem; }
.forecast-today-head .forecast-method { margin-left: auto; align-self: center; }
.forecast-plot { border-radius: .4rem; }
.forecast-plot svg { display: block; width: 100%; }
.forecast-plot text { fill: var(--muted); font-size: 12px; }
.forecast-guide { stroke: #314259; stroke-dasharray: 2 4; }
.forecast-zero { stroke: #536b86; }
.forecast-bar { fill: var(--forecast-accent); opacity: .85; }
.forecast-bar-past { opacity: .3; }
.forecast-days {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .55rem;
}
.forecast-day {
  display: grid;
  align-content: start;
  gap: .3rem;
  padding: .65rem;
  border: 1px solid #3b4e65;
  border-radius: .6rem;
  background: #182536;
}
.forecast-day-head { display: flex; align-items: center; gap: .35rem; font-size: .82rem; }
.forecast-glyph { font-size: 1.15rem; line-height: 1; }
.forecast-day-total { font-size: 1.05rem; font-weight: 650; color: var(--forecast-accent); font-variant-numeric: tabular-nums; }
.forecast-note { margin-top: .7rem; color: #aebfdb; }
.forecast-note:empty { display: none; }
.forecast-totals-title { margin: 0 0 .45rem; color: #8ce0ff; }
.forecast-totals {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .6rem;
  margin-bottom: .9rem;
}
.forecast-total-card {
  display: grid;
  gap: .15rem;
  padding: .65rem .75rem;
  border: 1px solid #344358;
  border-radius: .7rem;
  background: #111b28;
}
.forecast-total-card > span {
  color: var(--muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.forecast-total-card strong {
  color: #8ce0ff;
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}
.forecast-total-card small { color: var(--muted); font-size: .7rem; }
.forecast-plot { cursor: crosshair; border-radius: .4rem; }
.forecast-plot:focus-visible { outline: 2px solid #a9ccf9; outline-offset: 2px; }
#forecast-cursor { stroke: #92a6bf; stroke-dasharray: 4 4; }
#forecast-marker { fill: var(--forecast-accent); stroke: #111b28; stroke-width: 2; }
.forecast-reading { min-height: 1.3rem; margin: .35rem 0 0; font-size: .85rem; color: #dbe6f5; font-variant-numeric: tabular-nums; }
.forecast-reading:empty { display: none; }
#forecast-help { margin-top: .15rem; font-size: .73rem; }

.ai { grid-column: 1 / -1; }
.ai .eyebrow { color: #c4a9ff; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.ai-budget { margin-top: .85rem; }
.ai-budget-bar {
  height: .5rem;
  border: 1px solid #344358;
  border-radius: 999px;
  background: #131b25;
  overflow: hidden;
}
.ai-budget-bar > span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #79d7cb, #8ce0ff);
  transition: width .4s ease;
}
.ai-budget-bar[data-level="low"] > span { background: linear-gradient(90deg, #ffcf8a, #ffb340); }
.ai-budget-bar[data-level="empty"] > span { background: #ff8d8d; }
.ai-budget .detail { margin-top: .35rem; font-size: .78rem; }
.ai-summary, .ai-chat {
  margin-top: 1rem;
  padding: .8rem;
  border: 1px solid #344358;
  border-radius: .7rem;
  background: #131b25;
}
.ai-summary-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .6rem; }
.ai h3 { margin: 0 0 .5rem; font-size: 1rem; color: #cfe3ff; }
.ai-summary-head h3 { margin: 0; }
.ai-summary-text { margin-top: .55rem; font-size: .92rem; line-height: 1.55; white-space: pre-line; }
.ai-summary-meta { margin-top: .35rem; }
.ai-summary-meta.warn { color: #ffcf9f; }
.ai-chat-log {
  display: grid;
  gap: .5rem;
  max-height: clamp(15rem, 45vh, 23rem);
  margin: .55rem 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  font-size: .9rem;
}
.ai-chat-log:empty { display: none; }
.ai-message { padding: .55rem .65rem; border-radius: .55rem; background: #182536; }
.ai-message-user { margin-left: 1.5rem; background: #1d3346; }
.ai-message-assistant { margin-right: 1.5rem; }
.ai-message-role {
  display: block;
  margin-bottom: .15rem;
  color: #9bc8ff;
  font-size: .68rem;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.ai-message-text { white-space: pre-line; }
.ai-message-action { margin-top: .35rem; color: #ffcf9f; font-size: .8rem; }
.ai-chat-form { display: flex; gap: .5rem; margin-top: .55rem; }
.ai-chat-form input {
  flex: 1;
  min-width: 0;
  padding: .5rem .65rem;
  font: inherit;
  color: inherit;
  background: #0f1720;
  border: 1px solid #526985;
  border-radius: .45rem;
}
.ai-chat-form button { flex: none; }
.ai-chat-tools {
  display: flex;
  justify-content: flex-end;
  margin-top: .65rem;
}
#ai-chat-clear {
  min-height: 2rem;
  padding: .2rem .55rem;
  font-size: .78rem;
  border-radius: .45rem;
  background: transparent;
}
#ai-chat-clear:not(:disabled):hover { background: #27374b; }
.ai-proposal {
  margin-top: .75rem;
  padding: .7rem;
  border: 1px solid #a15f67;
  border-radius: .6rem;
  background: #2a1c22;
}
.ai-message .ai-proposal { margin-top: .5rem; }
.ai-proposal .eyebrow { color: #ffb3b3; }
.ai-proposal-label { margin-top: .2rem; font-weight: 650; }
.ai-proposal #ai-proposal-hint.warn { color: #ffcf9f; }
.ai-proposal .checkbox { display: flex; align-items: flex-start; gap: .5rem; margin: .5rem 0; font-size: .85rem; }
.ai-proposal .checkbox[hidden] { display: none; }
.ai-proposal .command-status { margin-top: .35rem; }
.ai-events {
  display: grid;
  gap: .45rem;
  max-height: 16rem;
  margin: .6rem 0 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}
.ai-event { padding: .6rem .7rem; border-left: 3px solid #4e6c8f; border-radius: .55rem; background: #131b25; }
.ai-event-action { border-left-color: #79d7cb; }
.ai-event-proposal { border-left-color: #c4a9ff; }
.ai-event-warning { border-left-color: #c98a4b; }
.ai-event-head { display: flex; justify-content: space-between; align-items: baseline; gap: .6rem; font-size: .88rem; }
.ai-event .detail { margin-top: .2rem; font-size: .8rem; }

body:has(.home-page, .login-page) {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 9% 0%, #142e35 0, transparent 38rem),
    radial-gradient(ellipse at 92% 10%, #1b253c 0, transparent 34rem),
    #0d141e;
}
.home-page, .login-page {
  --surface: #172330;
  --inset: #101a26;
  --line: #33475b;
  --accent: #9ce8d2;
}
.home-header {
  padding: clamp(1.15rem, 3.5vw, 2.4rem);
  margin-bottom: .85rem;
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  background: linear-gradient(118deg, #1d383e, #182a3a 67%, #212a40);
  box-shadow: 0 16px 40px #060e1850;
  gap: 1rem 2rem;
}
.home-brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  color: var(--accent);
  font-size: .73rem;
  font-weight: 750;
  letter-spacing: .14em;
  margin-bottom: .75rem;
}
.brand-icon {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid #78c4ad60;
  border-radius: .65rem;
  background: #193b37;
}
.brand-icon svg { width: 1.18rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.home-header h1, .login-page h1 { letter-spacing: -.045em; }
.home-intro { margin-top: .35rem; color: #b7c8db; }
.home-header .header-actions { gap: .5rem 1rem; }
.home-header #refresh-status { font-variant-numeric: tabular-nums; }
.section-nav {
  position: sticky;
  z-index: 3;
  top: 0;
  display: flex;
  gap: .35rem;
  overflow: auto;
  margin-bottom: 1.15rem;
  padding: .4rem;
  border: 1px solid var(--line);
  border-radius: .95rem;
  background: #131e2af5;
  box-shadow: 0 5px 16px #060e1840;
}
.section-nav a {
  flex: 1 0 auto;
  padding: .55rem .85rem;
  border-radius: .6rem;
  color: #c6d6e8;
  font-size: .85rem;
  font-weight: 650;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
}
.section-nav a:hover, .section-nav a:focus-visible { background: #233947; color: var(--accent); }
.home-page [id]:is(section, .group-heading) { scroll-margin-top: 5rem; }
.home-page .dashboard > section:not(.deye) {
  min-width: 0;
  padding: clamp(1rem, 2.3vw, 1.55rem);
  border-color: var(--line);
  border-radius: 1.25rem;
  background: linear-gradient(160deg, #1b2b3c, var(--surface) 60%);
  box-shadow: 0 10px 24px #060e1840;
}
.home-page section:not(.deye) .card-header { margin-bottom: 1rem; }
.home-page section:not(.deye) .card-header .eyebrow { margin-bottom: .25rem; }
.home-page section:not(.deye) .card-header .badge { flex-shrink: 0; max-width: 42%; }
.home-page section:not(.deye) dl > div { background: var(--inset); border: 1px solid #263749; border-radius: .8rem; }
.home-page #washer dl > div, .home-page :is(#jos, #sus) dl > div { grid-column: span 1; }
.radiator-climate dl { margin-top: .75rem; }
.radiator-climate > .detail { margin-top: .5rem; }
.radiator-climate .climate-rating { font-size: .78rem; }
.home-page section .radiator-climate [data-comfort="good"] {
  color: #b5f1be; background: #203d30; border-color: #4a7d5d;
}
.home-page section .radiator-climate [data-comfort="fair"] {
  color: #ffe198; background: #3e341c; border-color: #907536;
}
.home-page section .radiator-climate [data-comfort="poor"] {
  color: #ffb6ba; background: #43272d; border-color: #a55d65;
}
.radiator-climate :is([data-comfort="good"], [data-comfort="fair"], [data-comfort="poor"]) dt { color: inherit; }
.radiator-climate [data-comfort="unknown"] .climate-rating { color: var(--muted); }
.group-heading { grid-column: 1 / -1; margin-top: .65rem; }
.group-heading h2 { font-size: 1.55rem; }
.home-page section:not(.deye) details {
  margin-block: .6rem;
  padding: .65rem .85rem;
  background: var(--inset);
  border: 1px solid #263749;
  border-radius: .75rem;
}
.home-page section:not(.deye) summary { cursor: pointer; color: #c6d6e8; font-size: .9rem; font-weight: 650; }
.home-page section:not(.deye) summary:hover { color: var(--accent); }
.home-page button:not(.deye button), .home-page ~ dialog button, .login-page button {
  min-height: 2.65rem;
  border-radius: .7rem;
}
.home-page button.primary, .home-page ~ dialog button.primary, .login-page button.primary {
  background: #9ce8d2;
  border-color: #9ce8d2;
  color: #102a29;
  font-weight: 700;
}
.home-page button.primary:not(:disabled):hover,
.home-page ~ dialog button.primary:not(:disabled):hover,
.login-page button.primary:hover { background: #b9f1e2; }
.home-page :focus-visible:not(.deye *), .home-page ~ dialog :focus-visible, .login-page :focus-visible {
  outline: 2px solid #b1dbff;
  outline-offset: 3px;
}
.outlet-status {
  margin-block: .85rem;
  padding: .65rem .8rem;
  border: 1px solid #786045;
  border-radius: .75rem;
  background: #30291f;
  color: #ffdaaa;
}
.outlet-status[data-state="ready"] { background: #192f2d; border-color: #446d60; color: #b5ebd9; }
.outlet-status a { color: inherit; font-size: .85rem; font-weight: 700; }
.outlet-status .detail { color: #e3dbc9; margin-top: .2rem; }
.outlet-status[data-state="ready"] .detail { color: #c7dfd8; }
.washer-rule { margin-top: .75rem; }
.home-footer {
  display: flex;
  justify-content: space-between;
  padding: 1.15rem 0 0;
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .85rem;
}
.home-footer a { color: var(--accent); }
#admin { margin-top: 1rem; scroll-margin-top: 7rem; }
#admin[hidden], #admin-nav[hidden] { display: none; }
#house-name, #house-footer { overflow-wrap: anywhere; }
.admin-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: .55rem;
  margin: .85rem 0;
}
.admin-form label { display: grid; flex: 1 1 12rem; min-width: 0; gap: .25rem; }
.admin-form :is(input, select, textarea) { width: 100%; padding: .5rem; border: 1px solid var(--line, #526985); border-radius: .45rem; font: inherit; }
.admin-form textarea { resize: vertical; }
#admin-project-patch {
  max-height: 22rem;
  overflow: auto;
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: .45rem;
  background: var(--inset);
  font-size: .82rem;
}
#guard-state[data-state="on"] { color: #b5ebd9; border-color: #446d60; }
#guard-state[data-state="off"] { color: #ffdaaa; border-color: #786045; }
#guard-state[data-state="unknown"] { color: var(--muted); }
.leaf-preheat {
  margin: 1rem 0;
  padding: .8rem;
  border: 1px solid var(--line);
  border-radius: .8rem;
  background: var(--inset);
}
.preheat-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem; }
.preheat-heading h3 { margin: 0; font-size: 1rem; }
#preheat-status { margin-top: .35rem; }
#preheat-actions[hidden] { display: none; }
#preheat-form button { justify-self: start; }
.login-page .login-form {
  padding: clamp(1rem, 5vw, 1.75rem);
  border-color: var(--line);
  border-radius: 1.25rem;
  background: var(--surface);
  box-shadow: 0 16px 40px #060e1860;
}
.login-page input:not([type="checkbox"]) { min-height: 2.75rem; background: var(--inset); border-radius: .7rem; }
.login-page .remember { color: #b7c8db; font-size: .9rem; }

.theme-choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
  gap: .65rem;
  margin: .75rem 0;
  padding: 0;
  border: 0;
}
.theme-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-content: start;
  gap: .25rem .4rem;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: .8rem;
  padding: .5rem;
  cursor: pointer;
}
.theme-option:has(input:checked) { border-color: var(--accent); background: var(--surface); }
.theme-option input { margin: 0; accent-color: var(--accent); }
.theme-option small { grid-column: 1 / -1; color: var(--muted); line-height: 1.35; }
.theme-preview {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 2.3fr 1fr;
  gap: .28rem;
  padding: .35rem;
  min-height: 3.25rem;
  border-radius: .45rem;
  background: var(--theme-hero, linear-gradient(118deg, #1d383e, #182a3a 67%, #212a40));
}
.theme-preview::before, .theme-preview::after {
  content: "";
  border: 1px solid var(--theme-line, #7899aa66);
  border-radius: var(--theme-control, .4rem);
  background: var(--theme-card, #172330);
}
.theme-preview::before { border-left: .3rem solid var(--theme-accent, #9ce8d2); }
.theme-preview::after { background: var(--theme-accent, #9ce8d2); }
.theme-preview[data-palette="classic"] {
  --theme-hero: linear-gradient(118deg, #1d383e, #182a3a 67%, #212a40);
  --theme-card: #172330;
  --theme-line: #7899aa66;
  --theme-control: .4rem;
  --theme-accent: #9ce8d2;
}

:is(:root[data-theme="glass"], .theme-preview[data-palette="glass"]) {
  --theme-backdrop: radial-gradient(ellipse at 12% 0%, #233d6a, transparent 39rem),
                    radial-gradient(ellipse at 96% 28%, #31244f, transparent 42rem), #0c1525;
  --theme-hero: linear-gradient(132deg, #3f5b87b5, #232a51c7 58%, #302346d9);
  --theme-card: linear-gradient(155deg, #294163aa, #17233be8 72%);
  --theme-panel: #202e4a;
  --theme-inset: #101a2dcf;
  --theme-overlay: #142037ed;
  --theme-line: #b4d2ff55;
  --theme-hover: #344a70;
  --theme-accent: #bbdbff;
  --theme-on-accent: #122443;
  --theme-muted: #b6c8e3;
  --theme-radius: 1.45rem;
  --theme-control: .85rem;
  --theme-shadow: inset 0 1px #e6f4ff24, 0 16px 38px #050a1c59;
}
:is(:root[data-theme="material"], .theme-preview[data-palette="material"]) {
  --theme-backdrop: #16141d;
  --theme-hero: #312944;
  --theme-card: #25222e;
  --theme-panel: #2c2837;
  --theme-inset: #1c1925;
  --theme-overlay: #2a2634;
  --theme-line: #716880;
  --theme-hover: #463c59;
  --theme-accent: #dfc5ff;
  --theme-on-accent: #302047;
  --theme-muted: #c9c0d3;
  --theme-radius: 1.75rem;
  --theme-control: 1.5rem;
  --theme-shadow: 0 6px 15px #100c1970;
}
:is(:root[data-theme="aurora"], .theme-preview[data-palette="aurora"]) {
  --theme-backdrop: radial-gradient(ellipse at 10% 5%, #143b43, transparent 42rem),
                    radial-gradient(ellipse at 87% 14%, #382447, transparent 37rem), #10151f;
  --theme-hero: linear-gradient(117deg, #1a4846, #223447 60%, #402d51);
  --theme-card: linear-gradient(145deg, #203b42, #1d2636 70%);
  --theme-panel: #263745;
  --theme-inset: #141f2b;
  --theme-overlay: #182b36f5;
  --theme-line: #54848b;
  --theme-hover: #2d4956;
  --theme-accent: #9ff6c7;
  --theme-on-accent: #122d27;
  --theme-muted: #b2c9ca;
  --theme-radius: 1.15rem;
  --theme-control: .65rem;
  --theme-shadow: 0 12px 30px #080f1859;
}
:is(:root[data-theme="graphite"], .theme-preview[data-palette="graphite"]) {
  --theme-backdrop: radial-gradient(ellipse at top, #252329, transparent 38rem), #0d0e10;
  --theme-hero: linear-gradient(118deg, #322b26, #222226 65%, #282630);
  --theme-card: #1a1b1f;
  --theme-panel: #24252a;
  --theme-inset: #121316;
  --theme-overlay: #191a1ef5;
  --theme-line: #5c5b62;
  --theme-hover: #363337;
  --theme-accent: #ffce91;
  --theme-on-accent: #362311;
  --theme-muted: #bfbac0;
  --theme-radius: .9rem;
  --theme-control: .45rem;
  --theme-shadow: 0 12px 32px #0007;
}

:root[data-theme]:not([data-theme="classic"]) {
  --muted: var(--theme-muted);
  accent-color: var(--theme-accent);
}
:root[data-theme]:not([data-theme="classic"]) body:has(.home-page, .login-page) { background: var(--theme-backdrop); }
:root[data-theme]:not([data-theme="classic"]) :is(.home-page, .login-page, dialog) {
  --surface: var(--theme-panel);
  --inset: var(--theme-inset);
  --line: var(--theme-line);
  --accent: var(--theme-accent);
}
:root[data-theme]:not([data-theme="classic"]) :is(.home-header, .login-page .login-form, .home-page .dashboard > section:not(.deye), .home-page .deye, #admin, dialog) {
  background: var(--theme-card);
  border-color: var(--theme-line);
  border-radius: var(--theme-radius);
  box-shadow: var(--theme-shadow);
}
:root[data-theme]:not([data-theme="classic"]) .home-header { background: var(--theme-hero); }
:root[data-theme]:not([data-theme="classic"]) .section-nav {
  background: var(--theme-overlay);
  border-color: var(--theme-line);
  border-radius: var(--theme-control);
}
:root[data-theme]:not([data-theme="classic"]) :is(.brand-icon, .charge-progress, .record-list li,
  .ai-summary, .ai-chat, .ai-event, .energy-trend, .energy-flow) {
  background-color: var(--theme-inset);
  border-color: var(--theme-line);
}
:root[data-theme]:not([data-theme="classic"]) :is(.ai-message-user, .ai-message-assistant, .forecast-total-card) { background: var(--theme-panel); }
:root[data-theme]:not([data-theme="classic"]) :is(.control-form, .admin-form, #admin-theme-form, .ai-chat-form) :is(input:not([type="checkbox"], [type="radio"]), select, textarea) {
  border-color: var(--theme-line);
  background: var(--theme-inset);
}
:root[data-theme]:not([data-theme="classic"]) :is(.home-page, .login-page, dialog) button:not(.danger) {
  border-radius: var(--theme-control);
  border-color: var(--theme-line);
  background: var(--theme-inset);
}
:root[data-theme]:not([data-theme="classic"]) :is(.home-page, .login-page, dialog) button:not(.primary, .danger, :disabled):hover,
:root[data-theme]:not([data-theme="classic"]) .section-nav a:hover { background: var(--theme-hover); }
:root[data-theme]:not([data-theme="classic"]) :is(.home-page, .login-page, dialog) button.primary {
  background: var(--theme-accent);
  border-color: var(--theme-accent);
  color: var(--theme-on-accent);
}
:root[data-theme]:not([data-theme="classic"]) :is(.home-page, .login-page, dialog) button.primary:not(:disabled):hover { filter: brightness(1.09); }
:root[data-theme]:not([data-theme="classic"]) :is(.home-page, .login-page, dialog) :focus-visible { outline-color: var(--theme-accent); }
@supports (backdrop-filter: blur(1px)) {
  :root[data-theme="glass"] .home-header { backdrop-filter: blur(16px); }
  :root[data-theme="glass"] .section-nav {
    background: #17243bd6;
    backdrop-filter: blur(14px) saturate(135%);
  }
}

@media (min-width: 56rem) {
  .home-page .leaf, .home-page .tesy { grid-column: span 3; }
}

@media (prefers-reduced-motion: reduce) {
  .flow-river.flow-active { animation: none; }
  .flow-node.flow-hot { animation: none; box-shadow: 0 0 0 1px var(--energy-accent); }
  .flow-river, .node-fill > span { transition: none; }
  .ai-budget-bar > span { transition: none; }
}
@media (max-width: 52rem) {
  section { grid-column: span 3; }
  .deye, .leaf { grid-column: 1 / -1; }
  .energy-board { grid-template-columns: minmax(0, 1fr); }
  .forecast-body { grid-template-columns: minmax(0, 1fr); }
  .leaf dl { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 38rem) {
  .section-nav { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .2rem; }
  .section-nav a { padding-inline: .25rem; }
  .home-page [id]:is(section, .group-heading) { scroll-margin-top: 7rem; }
  .dashboard { grid-template-columns: minmax(0, 1fr); }
  section, .deye, .leaf { grid-column: 1; }
  .deye { padding: .75rem; }
  .energy-flow { min-height: 264px; }
  .energy-summary { font-size: .76rem; }
  .forecast-days { grid-template-columns: minmax(0, 1fr); }
  .forecast-totals { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ai-chat-form { flex-wrap: wrap; }
  .ai-message-user { margin-left: .5rem; }
  .ai-message-assistant { margin-right: .5rem; }
  .trend-header .trend-options { display: grid; width: 100%; grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
