/* BESS + Energy Flow reference layout. All rules belong to this one card. */
#card-bess {
  padding: clamp(18px, 1.65vw, 36px);
  padding-top: clamp(18px, 1.05vw, 23px);
  gap: clamp(20px, 1.35vw, 30px);
  border-radius: 20px;
  --overview-muted: var(--ink-dim);
  --overview-track: var(--panel-2);
}
[data-theme="light"] #card-bess {
  background: #f8f7f4;
  --accent: #e77720;
  --ink: #211d1b;
  --overview-muted: #716c65;
  --ink-faint: #918a80;
  --line: rgba(80, 67, 54, 0.13);
  --panel-2: #fffdfa;
  --overview-track: #ebe8e2;
}
#card-bess > .card-head {
  gap: 16px;
  padding-bottom: clamp(12px, 0.7cqw, 16px);
  flex-wrap: wrap;
}
#card-bess .ems-plant-heading,
#card-bess .ems-plant-heading h2,
#card-bess .ems-plant-status {
  display: flex;
  align-items: center;
}
#card-bess .ems-plant-heading { gap: clamp(16px, 1.8cqw, 38px); }
#card-bess .ems-plant-heading h2 {
  gap: clamp(12px, 1.05cqw, 23px);
  color: var(--ink);
  font-size: clamp(22px, 1.7cqw, 36px);
  font-weight: 750;
  line-height: 1.1;
  letter-spacing: 0;
}
#card-bess .ems-plant-heading h2::before { display: none; }
#card-bess .ems-bess-icon {
  width: clamp(32px, 2.5cqw, 52px);
  height: clamp(32px, 2.5cqw, 52px);
}
#card-bess .tag {
  padding: 6px 16px;
  border-radius: 12px;
  background: var(--panel-2);
  font-size: clamp(12px, 1.03cqw, 22px);
  font-weight: 750;
  line-height: 1.25;
  color: var(--overview-muted);
}
#card-bess #bess-mode { letter-spacing: 0.1em; }
#card-bess .ems-plant-status { gap: clamp(14px, 1.5cqw, 32px); }
#card-bess .ems-age { font-size: clamp(11px, 0.92cqw, 19px); }
#card-bess #flow-status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0.035em;
}
#card-bess #flow-status::before {
  content: "";
  width: 0.65em;
  height: 0.65em;
  border-radius: 50%;
  background: var(--ink-faint);
  flex: none;
}
#card-bess #flow-status[data-freshness="current"]::before { background: #85c83e; }
#card-bess #flow-status[data-freshness="partial"]::before,
#card-bess #flow-status[data-freshness="delayed"]::before { background: var(--amber); }
#card-bess .ems-plant-body {
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  grid-template-areas: "flow battery" "flow exec";
  grid-template-rows: auto auto;
  gap: clamp(20px, 1.4cqw, 30px);
  row-gap: clamp(20px, 1.2cqw, 26px);
  align-items: stretch;
}
#card-bess .ems-plant-bess { padding-top: clamp(2px, 0.65cqw, 14px); }
#card-bess .bess-body {
  grid-template-columns: minmax(0, 2fr) minmax(0, 0.98fr);
  gap: clamp(20px, 1.8cqw, 38px);
}
#card-bess .ems-soc-overview { grid-column: 2; grid-row: 1; min-width: 0; text-align: center; }
#card-bess .ems-soc-label {
  margin: 0 0 clamp(12px, 0.8cqw, 18px);
  font-size: clamp(13px, 1.05cqw, 23px);
  line-height: 1.35;
  white-space: nowrap;
  color: var(--overview-muted);
}
#card-bess .soc-ring {
  width: calc(100% - 16px);
  height: auto;
  max-width: none;
  max-height: none;
  margin-inline: auto;
}
#card-bess .ring-bg { stroke: var(--overview-track); }
#card-bess .soc-ring svg { display: block; }
#card-bess .soc-num { gap: 4px; }
#card-bess .soc-num span {
  font-family: inherit;
  font-size: clamp(38px, 3.15cqw, 68px);
  font-weight: 750;
  letter-spacing: -0.035em;
}
#card-bess .soc-num small { font-size: clamp(17px, 1.4cqw, 30px); color: var(--ink); }
#card-bess .bess-side { grid-column: 1; grid-row: 1; min-width: 0; }
#card-bess .bess-stats:not(.stacks) > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: clamp(5px, 0.35cqw, 8px) 0;
  border-bottom: 1px solid var(--line);
  font-size: clamp(13px, 1.1cqw, 24px);
  line-height: 1.3;
}
#card-bess .bess-stats:not(.stacks) > div > span { color: var(--overview-muted); }
#card-bess .bess-stats:not(.stacks) > div > b { flex: none; font-weight: 700; }
#card-bess .bess-stats.stacks {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 0;
}
#card-bess .bess-stats.stacks > .stack-card {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: baseline;
  gap: 0;
  padding: clamp(10px, 0.7cqw, 15px) 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: none;
}
#card-bess .bess-stats.stacks > .stack-card:last-child { border-bottom: 0; }
#card-bess .bess-stats.stacks > .stack-card > span {
  font-size: clamp(13px, 1.1cqw, 24px);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--overview-muted);
}
#card-bess .bess-stats.stacks > .stack-card > span::after { content: "   "; white-space: pre; }
#card-bess .bess-stats.stacks > .stack-card b {
  font-size: clamp(13px, 1.1cqw, 24px);
  line-height: 1.4;
  text-align: left;
  font-weight: 700;
}
#card-bess .stack-detail { display: inline; white-space: nowrap; color: var(--overview-muted); font-weight: 400; }
#card-bess .stack-detail::before { content: " · "; }
#card-bess .bess-execution {
  padding: 0;
  gap: 8px;
  border: 0;
  border-radius: 0;
  background: none;
  align-self: end;
}
#card-bess .bess-execution-step {
  padding: clamp(12px, 0.85cqw, 18px) clamp(12px, 1.2cqw, 25px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-2);
}
#card-bess .bess-execution-step span {
  margin-bottom: 5px;
  color: var(--ink-faint);
  font-size: clamp(10px, 0.75cqw, 15px);
  letter-spacing: 0;
}
#card-bess .bess-execution-step b {
  font-size: clamp(11px, 0.85cqw, 18px);
  line-height: 1.3;
  overflow: visible;
  overflow-wrap: anywhere;
}
#card-bess .bess-execution-step.is-ok b { color: var(--ink); }
#card-bess .bess-execution-source {
  margin-top: 5px;
  font-size: clamp(11px, 0.98cqw, 21px);
  line-height: 1.4;
}
#card-bess .ems-plant-flow {
  width: 100%;
  align-self: stretch;
  padding: 0 clamp(20px, 1.7cqw, 36px) 0 0;
  border-left: 0;
  border-right: 1px solid var(--line-strong);
  border-top: 0;
  overflow: visible;
  background: none;
}
#card-bess .ems-flow-heading { display: flex; align-items: baseline; flex-wrap: wrap; gap: 14px; }
#card-bess .ems-flow-heading h3 {
  font-size: clamp(14px, 1.18cqw, 25px);
  font-weight: 750;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}
#card-bess .ems-flow-heading > span { font-size: clamp(13px, 1.05cqw, 23px); color: var(--ink-faint); }
#card-bess #flow-svg {
  width: 100%;
  height: auto;
  min-height: 0;
  max-height: none;
  aspect-ratio: 500 / 330;
  margin: 4px auto 0;
}
#card-bess .flow-node-label,
#card-bess .flow-node-value {
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  stroke: none;
  fill: var(--ink);
}
#card-bess .flow-node-label { letter-spacing: 0.035em; }
#card-bess .flow-node-value { letter-spacing: 0; }
#card-bess .flow-edge-value { font-family: inherit; font-size: 15px; font-weight: 700; }
#card-bess .flow-node-self-use { font-size: 11px; }

@container ems-plant (max-width: 1000px) {
  #card-bess .ems-plant-body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "battery" "exec" "flow";
    gap: 22px;
  }
  #card-bess .ems-plant-flow { border-right: 0; padding: 20px 0 0; border-top: 1px solid var(--line); }
  #card-bess #flow-svg { max-width: 650px; }
  #card-bess .bess-body { grid-template-columns: minmax(0, 2fr) minmax(0, 0.85fr); }
  #card-bess .soc-num span { font-size: clamp(38px, 7cqw, 64px); }
  #card-bess .soc-num small { font-size: 22px; }
}
@container ems-plant (max-width: 560px) {
  #card-bess .ems-plant-status { width: 100%; justify-content: space-between; gap: 8px; }
  #card-bess .tag { padding: 5px 10px; border-radius: 9px; }
  #card-bess .bess-body { grid-template-columns: minmax(0, 1fr); gap: 22px; }
  #card-bess .ems-soc-overview { grid-column: 1; grid-row: 2; width: min(70%, 240px); justify-self: center; }
  #card-bess .bess-side { grid-column: 1; grid-row: 1; }
  #card-bess .soc-num span { font-size: clamp(42px, 13cqw, 58px); }
  #card-bess .bess-stats:not(.stacks) > div { padding: 8px 0; }
  #card-bess .bess-stats:not(.stacks) > div > span { max-width: 64%; }
  #card-bess .bess-stats.stacks > .stack-card { padding: 13px 0; }
  #card-bess .bess-execution { grid-template-columns: 1fr; }
  #card-bess .bess-execution-step { padding: 12px 14px; border-radius: 12px; }
  #card-bess .bess-execution-source { grid-column: 1; }
  #card-bess .ems-flow-heading { gap: 10px; }
}
#card-bess .ems-plant-body:has(#card-flow.hidden) {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "battery" "exec";
}
