/*
 * MyBuilding light design system — cloud & local UI.
 * An intentionally restrained, readable operations interface:
 * white surfaces, ink typography, clear information hierarchy and
 * accessible action states. This stylesheet comes AFTER legacy CSS.
 */
:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel2: #edf3fa;
  --line: #dbe3ee;
  --text: #17283f;
  --muted: #546780;
  --brand: #2459a6;
  --good: #16714e;
  --warn: #956000;
  --bad: #ae3443;
  --solar: #b07600;
  --focus: #2459a6;
  --surface: #ffffff;
  --surface-subtle: #f8fafd;
}
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
::selection { background: #d8e8ff; color: #132a4e; }
a { color: #20539e; text-underline-offset: 3px; }
a:hover { color: #163e78; }
button, select, input, textarea { color: var(--text); }
button, select { min-height: 42px; }
button:disabled, select:disabled { cursor: not-allowed; opacity: .54; }
:where(a, button, select, input, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--focus) !important;
  outline-offset: 3px !important;
}
.skip-link {
  position: fixed; top: 10px; left: 12px; z-index: 1000;
  transform: translateY(-170%);
  padding: 10px 15px; border: 2px solid var(--focus);
  border-radius: 9px; background: #fff; color: var(--text);
  font-weight: 700; text-decoration: none;
}
.skip-link:focus { transform: none; }
.app, .shell { grid-template-columns: 230px minmax(0, 1fr); }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 28px 14px 20px;
}
.brand {
  color: var(--text);
  font-size: 22px; font-weight: 750; letter-spacing: -.6px;
  margin: 0 10px 32px;
}
.brand span { color: var(--brand); }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.nav { gap: 4px; }
.nav button {
  font-size: 13px;
  line-height: 1.3;
  color: #415571;
  font-weight: 580;
  padding: 11px 14px;
  min-height: 43px;
  border-radius: 9px;
  transition: background-color 120ms ease, color 120ms ease;
}
.nav button:hover { background: #f0f4fa; color: var(--text); }
.nav button.active, .nav button[aria-current="page"] {
  background: #e8f0fc;
  color: #174887;
  font-weight: 750;
  box-shadow: inset 3px 0 0 #2459a6;
}
.identity, .side-meta {
  color: var(--muted);
  font-size: 11px;
  left: 23px; right: 19px;
}
main {
  padding: 34px clamp(20px, 3vw, 46px) 64px;
  max-width: 1560px;
  margin: 0 auto;
}
.top { gap: 16px; margin-bottom: 24px; align-items: flex-start; }
.top h1 {
  margin: 4px 0 7px;
  font-size: clamp(23px, 2.1vw, 31px);
  line-height: 1.18;
  font-weight: 750;
  letter-spacing: -.8px;
  color: #17283f;
}
.eyebrow {
  color: #386494;
  text-transform: none;
  letter-spacing: .025em;
  font-size: 12px;
  font-weight: 700;
}
.site-health, .muted, .label, .sub, .history-note { color: var(--muted); }
.controls { gap: 8px; align-items: center; }
.select, .controls select, input, textarea {
  background: var(--surface);
  color: var(--text);
  border: 1px solid #c6d2e1;
  border-radius: 9px;
}
.select { padding: 9px 30px 9px 12px; min-height: 42px; }
input, textarea { padding: 9px 12px; }
input::placeholder, textarea::placeholder { color: #67798e; }
.btn {
  background: var(--brand);
  color: #fff;
  font-weight: 690;
  min-height: 42px;
  border: 1px solid var(--brand);
  border-radius: 9px;
  padding: 9px 15px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: #174785; color: white; }
.btn.secondary {
  background: var(--surface);
  border: 1px solid #c6d2e1;
  color: #2c4565;
}
.btn.secondary:hover:not(:disabled) { background: #edf3fa; color: #1b3d69; }
.language-toggle { order: 0; background: #edf2f8; border-color: var(--line); }
.language-toggle button {
  min-height: 36px; min-width: 40px;
  color: #4d627b; font-size: 12px;
}
.language-toggle button.active { background: var(--surface); color: #174887; box-shadow: 0 1px 3px #19314a18; }
.pill, .status-pill, .group-source-status {
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  color: #425670;
}
.grid { gap: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(22,44,70,.035);
}
.card .card { box-shadow: none; background: var(--surface-subtle); }
.section h2, .section-title h2, h2 {
  color: var(--text);
  font-weight: 700;
  letter-spacing: -.2px;
}
.section h2, .section-title h2 { font-size: 16px; }
.value { color: #183351; font-weight: 750; }
.metric, .live-row, .node, .state-item, .state-explanation {
  background: var(--surface-subtle);
  border: 1px solid #e2e9f2;
  border-radius: 10px;
}
.metric, .live-row { padding: 14px 16px; }
.metric strong, .live-row strong, .state-item .state-value { color: var(--text); }
.metric label, .live-row label, .state-item .state-name, .field>span {
  color: #4d6078;
  font-weight: 650;
  font-size: 11px;
  letter-spacing: .025em;
}
.status-pill.good { background: #ecf8f1; color: #146844; border-color: #b8e2cb; }
.status-pill.warn { background: #fff6df; color: #865500; border-color: #efdaad; }
.status-pill.bad { background: #fff0f0; color: #a3283b; border-color: #eec1c8; }
.status-pill.neutral { background: #f2f5f9; color: #405975; }
.banner {
  background: #fff8e8; color: #77500d; border: 1px solid #e8d5aa;
  border-radius: 10px;
}
.json {
  background: #f4f7fb; color: #203750;
  border: 1px solid var(--line);
}
.chart, .energy-flow-svg {
  background: #fff;
  border: 1px solid #e1e8f1;
  border-radius: 10px;
}
.chart text { fill: #435a77 !important; }
.energy-flow-node { fill: #f5f8fc; stroke: #8ca6c1; }
.energy-flow-node-icon-bg { fill: #fff; stroke: #9db1c7; }
.energy-flow-title, .energy-flow-power { fill: #18344e; }
.energy-flow-sub, .energy-flow-energy { fill: #4c6078; }
.energy-flow-energy {
  font-size: 11px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.energy-flow-power-bg { fill: #fff; stroke: #bdcde0; }
.energy-flow-icon { stroke: #28557e; }
.energy-flow-icon-fill { fill: #28557e; }
/* Grid status and electrical telemetry are displayed inside the Utility grid
 * node, preserving the System state panel for system-wide conditions. */
.energy-flow-grid-status,
.energy-flow-battery-status {
  fill: #173650;
  font-size: 12px;
  font-weight: 800;
}
.energy-flow-grid-electrical {
  fill: #385774;
  font-size: 11px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}
/* High contrast in the dark card: the default light-theme fill is illegible. */
html[data-theme="dark"] .energy-flow-grid-status,
html[data-theme="dark"] .energy-flow-battery-status { fill: #f4fbff; }
html[data-theme="dark"] .energy-flow-grid-electrical { fill: #e2efff; }
.energy-flow-grid-dot.available { fill: #1aa36d; }
.energy-flow-grid-dot.unavailable { fill: #d04e57; }
.energy-flow-grid-dot.unknown { fill: #94a4b6; }
/* A photovoltaic module: silver aluminium frame, dark solar-cell glass,
 * fine contacts, glancing reflection and discrete support. Fits mobile. */
.energy-flow-pv-frame { fill: #a7bfcd; stroke: #314c62; stroke-width: 1.4; }
.energy-flow-pv-glass { fill: #061b32; stroke: #28517b; stroke-width: .8; }
.energy-flow-pv-cells { fill: none; stroke: #9eb7d2; stroke-width: .7; opacity: .7; }
.energy-flow-pv-reflection { fill: #b6dbff; opacity: .15; }
.energy-flow-pv-stand { fill: none; stroke: #7896ab; stroke-width: 2; stroke-linecap: round; }
@media (max-width: 640px) {
  .energy-flow-grid-status,
  .energy-flow-battery-status { font-size: 11px; }
  .energy-flow-grid-electrical { font-size: 10px; }
}
.energy-flow-path.grid { stroke: #7652a5; }
.energy-flow-path.solar { stroke: #bb800c; }
.energy-flow-path.battery { stroke: #178260; }
.energy-flow-path.load { stroke: #2464a9; }
.energy-flow-arrow.grid { fill: #7652a5; }
.energy-flow-arrow.solar { fill: #bb800c; }
.energy-flow-arrow.battery { fill: #178260; }
.energy-flow-arrow.load { fill: #2464a9; }
.chart-tooltip {
  background: #fff; color: var(--text);
  border: 1px solid #cdd8e6;
  box-shadow: 0 9px 28px rgba(27,47,72,.12);
}
table { color: var(--text); }
th { color: #4d6078; background: #f8fafd; font-size: 11px; }
th, td { border-bottom: 1px solid #e4eaf2; }
tbody tr:hover { background: #f5f8fc; }
.table-pagination button, .table-pagination select {
  background: var(--surface); color: var(--text); border-color: #bdcadb;
}
.disk-bar { background: #e8eef5; border-color: #dce5ee; }
.contact-dialog {
  background: var(--surface); color: var(--text);
  border: 1px solid #d6dfeb;
  box-shadow: 0 20px 60px rgba(15,34,57,.18);
}
.contact-dialog::backdrop { background: rgba(15,35,56,.40); }
.app-footer { color: var(--muted); }
.app-footer a { color: var(--brand); text-decoration: underline; text-underline-offset: 2px; }
@media (max-width: 920px) {
  .app, .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static; height: auto;
    padding: 16px 20px 10px;
    border-right: none; border-bottom: 1px solid var(--line);
  }
  .brand { margin: 0 6px 12px; }
  .nav { display: flex; gap: 5px; overflow-x: auto; padding: 0 0 9px; }
  .nav button { flex: 0 0 auto; min-height: 42px; }
  .nav button.active, .nav button[aria-current="page"] {
    box-shadow: inset 0 -3px 0 #2459a6;
  }
  main { padding: 23px 20px 40px; }
  .top { flex-direction: column; }
  .top .controls { display: flex; flex-wrap: wrap; width: 100%; }
  .top .controls .select, .top .controls .btn { width: auto; min-width: 0; }
  .top .controls select { flex: 1 1 180px; }
  .top .controls .btn { flex: 0 0 auto; }
  .top .controls #refresh, .top .controls #site,
  .top .controls #language { grid-column: auto; }
  .energy-flow-svg { height: 340px; }
}
@media (max-width: 640px) {
  .sidebar { padding: 14px 12px 7px; }
  .brand { font-size: 21px; margin-bottom: 12px; }
  .nav { gap: 3px; }
  .nav button { padding: 10px 13px; }
  main { padding: 20px 14px 40px; }
  .top { gap: 13px; margin-bottom: 18px; }
  .top h1 { font-size: 25px; }
  .top .controls { gap: 8px; }
  .app .top .controls #tenant,
  .app .top .controls #site { flex: 1 0 100%; width: 100%; }
  .app .top .controls #login,
  .app .top .controls #logout {
    flex: 0 0 auto; width: auto; min-width: 96px;
    max-width: 132px; min-height: 44px;
    padding: 9px 15px;
  }
  .app .top .controls #refresh { flex: 0 0 auto; width: auto; min-height: 44px; }
  .app .top .controls #language { width: auto; margin-left: auto; }
  .shell .top .controls #language { flex: 1 1 145px; width: auto; }
  .card { padding: 16px; border-radius: 11px; }
  .grid { gap: 12px; }
  table.responsive-table tr { background: #fff; border-color: var(--line); }
  table.responsive-table td { border-bottom-color: var(--line); }
  table.responsive-table td::before { color: #4a5e77; font-size: 11px; }
  .metric-grid, .live-list, .state-grid { grid-template-columns: 1fr; }
  .energy-flow-svg { height: 310px; }
  .contact-dialog { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (forced-colors: active) {
  .nav button.active, .nav button[aria-current="page"] { outline: 2px solid Highlight; outline-offset: -2px; }
  .status-pill { border: 1px solid CanvasText; }
}

/* Compact native appearance dropdown preserves keyboard and touch behavior. */
.theme-select {
  width: 112px;
  min-width: 112px;
  max-width: 112px;
  min-height: 44px;
  flex: 0 0 112px;
  font-weight: 650;
  cursor: pointer;
}
@media (max-width: 920px) {
  .top .controls #theme-toggle {
    grid-column: auto;
    flex: 0 0 112px;
    width: 112px;
    min-width: 112px;
    max-width: 112px;
  }
}
@media (max-width: 640px) {
  .app .top .controls #theme-toggle,
  .shell .top .controls #theme-toggle {
    flex: 0 0 112px;
    width: 112px;
    min-width: 112px;
    max-width: 112px;
    margin-left: 0;
  }
}

/* Dark is deliberate, rather than a CSS invert that distorts charts. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1723;
  --panel: #192536;
  --panel2: #23344a;
  --line: #384b62;
  --text: #eaf1fa;
  --muted: #b5c5d9;
  --brand: #91c1ff;
  --good: #75dbb2;
  --warn: #ffcc70;
  --bad: #ff9eaa;
  --solar: #f3bd62;
  --focus: #a6d0ff;
  --surface: #192536;
  --surface-subtle: #1e2d40;
}
html[data-theme="dark"] body { background: var(--bg); color: var(--text); }
html[data-theme="dark"] ::selection { background: #46658b; color: #fff; }
html[data-theme="dark"] a { color: #a6d0ff; }
html[data-theme="dark"] a:hover { color: #d0e4ff; }
html[data-theme="dark"] .skip-link { background: var(--surface); color: var(--text); }
html[data-theme="dark"] .sidebar {
  background: #151f2e; border-color: var(--line);
}
html[data-theme="dark"] .brand { color: var(--text); }
html[data-theme="dark"] .brand span { color: var(--brand); }
html[data-theme="dark"] .nav button { color: #b8c8de; }
html[data-theme="dark"] .nav button:hover {
  background: #263a51; color: #fff;
}
html[data-theme="dark"] .nav button.active,
html[data-theme="dark"] .nav button[aria-current="page"] {
  background: #253d5c; color: #e6f3ff;
  box-shadow: inset 3px 0 0 #88baff;
}
html[data-theme="dark"] .top h1,
html[data-theme="dark"] .section h2,
html[data-theme="dark"] .section-title h2,
html[data-theme="dark"] h2,
html[data-theme="dark"] .value,
html[data-theme="dark"] .metric strong,
html[data-theme="dark"] .live-row strong,
html[data-theme="dark"] .state-item .state-value {
  color: var(--text);
}
html[data-theme="dark"] .eyebrow { color: #a2c9f6; }
html[data-theme="dark"] .site-health,
html[data-theme="dark"] .muted,
html[data-theme="dark"] .label,
html[data-theme="dark"] .sub,
html[data-theme="dark"] .history-note { color: var(--muted); }
html[data-theme="dark"] .select,
html[data-theme="dark"] .controls select,
html[data-theme="dark"] input,
html[data-theme="dark"] textarea {
  background: #172535; border-color: #526780; color: var(--text);
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #b0bed0; }
html[data-theme="dark"] .btn {
  color: #fff; background: #235d9e; border-color: #457ab8;
}
html[data-theme="dark"] .btn:hover:not(:disabled) {
  color: #fff; background: #3270b6;
}
html[data-theme="dark"] .btn.secondary {
  color: #e7effb; background: #22354b; border-color: #526780;
}
html[data-theme="dark"] .btn.secondary:hover:not(:disabled) {
  color: #fff; background: #304862;
}
html[data-theme="dark"] .language-toggle {
  background: #23364b; border-color: #526780;
}
html[data-theme="dark"] .language-toggle button { color: #c5d3e4; }
html[data-theme="dark"] .language-toggle button.active {
  background: #3d5874; color: #fff;
}
html[data-theme="dark"] .language-toggle button:hover { color: #fff; }
html[data-theme="dark"] .card {
  background: var(--surface); border-color: var(--line);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
html[data-theme="dark"] .card .card,
html[data-theme="dark"] .metric,
html[data-theme="dark"] .live-row,
html[data-theme="dark"] .node,
html[data-theme="dark"] .state-item,
html[data-theme="dark"] .state-explanation {
  background: var(--surface-subtle); border-color: #43576e;
}
html[data-theme="dark"] .metric label,
html[data-theme="dark"] .live-row label,
html[data-theme="dark"] .state-item .state-name,
html[data-theme="dark"] .field>span { color: #bdcbe0; }
html[data-theme="dark"] .pill,
html[data-theme="dark"] .status-pill,
html[data-theme="dark"] .group-source-status {
  background: #23354a; color: #d8e5f5; border-color: #50657e;
}
html[data-theme="dark"] .status-pill.good { background: #15392f; color: #98e7c5; border-color: #336f5b; }
html[data-theme="dark"] .status-pill.warn { background: #463519; color: #ffdc95; border-color: #86632b; }
html[data-theme="dark"] .status-pill.bad { background: #45252e; color: #ffb4be; border-color: #88505b; }
html[data-theme="dark"] .status-pill.neutral { background: #283950; color: #d3e2f6; }
html[data-theme="dark"] .good { color: var(--good); }
html[data-theme="dark"] .warn { color: var(--warn); }
html[data-theme="dark"] .bad { color: var(--bad); }
html[data-theme="dark"] .banner {
  color: #ffe0a8; background: #382b18; border-color: #816439;
}
html[data-theme="dark"] .json,
html[data-theme="dark"] pre[style*="white-space:pre-wrap"] {
  background: #152234 !important; color: #d8e4f5 !important;
  border-color: #4c627c !important;
}
html[data-theme="dark"] .chart,
html[data-theme="dark"] .energy-flow-svg {
  background: #142235; border-color: #41556e;
}
html[data-theme="dark"] .chart text { fill: #c4d3e6 !important; }
html[data-theme="dark"] .energy-flow-node { fill: #203349; stroke: #6886a6; }
html[data-theme="dark"] .energy-flow-node-icon-bg { fill: #1b2c41; stroke: #6585a5; }
html[data-theme="dark"] .energy-flow-title,
html[data-theme="dark"] .energy-flow-power { fill: #f0f6ff; }
html[data-theme="dark"] .energy-flow-sub,
html[data-theme="dark"] .energy-flow-energy { fill: #c0d0e5; }
html[data-theme="dark"] .energy-flow-power-bg { fill: #132338; stroke: #6885a3; }
html[data-theme="dark"] .energy-flow-icon { stroke: #d9e9ff; }
html[data-theme="dark"] .energy-flow-icon-fill { fill: #d9e9ff; }
html[data-theme="dark"] .chart-tooltip {
  color: var(--text); background: #192b40;
  border-color: #59718e; box-shadow: 0 12px 30px rgba(0,0,0,.33);
}
html[data-theme="dark"] table { color: var(--text); }
html[data-theme="dark"] th { color: #c0cee0; background: #203045; }
html[data-theme="dark"] th,
html[data-theme="dark"] td { border-color: #40546c; }
html[data-theme="dark"] tbody tr:hover { background: #23364b; }
html[data-theme="dark"] .table-pagination button,
html[data-theme="dark"] .table-pagination select {
  background: #203349; color: var(--text); border-color: #536b85;
}
html[data-theme="dark"] .disk-bar { background: #2b3c51; border-color: #50657d; }
html[data-theme="dark"] .contact-dialog {
  background: var(--surface); color: var(--text);
  border-color: #5b718c; box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
html[data-theme="dark"] .contact-dialog::backdrop { background: rgba(0,7,16,.65); }
html[data-theme="dark"] .app-footer { color: var(--muted); }
html[data-theme="dark"] .app-footer a { color: #a6d0ff; }
@media (max-width: 920px) {
  html[data-theme="dark"] .nav button.active,
  html[data-theme="dark"] .nav button[aria-current="page"] {
    box-shadow: inset 0 -3px 0 #88baff;
  }
}
@media (max-width: 640px) {
  html[data-theme="dark"] table.responsive-table tr {
    background: #1d2c40; border-color: var(--line);
  }
  html[data-theme="dark"] table.responsive-table td { border-color: var(--line); }
  html[data-theme="dark"] table.responsive-table td::before { color: #c0d0e6; }
}

/* MyBuilding EN/FR language switch: a tactile flag slider, not emoji glyphs.
   EN: knob left / British flag right; FR: French flag left / knob right. */
.language-switcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex: 0 0 auto;
  white-space: nowrap;
}
.language-label {
  appearance: none;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
  letter-spacing: .02em;
  min-width: 33px;
  min-height: 44px;
  padding: 6px 4px;
}
.language-label.active { color: var(--text); }
.language-label:hover { color: var(--brand); }
.language-track {
  appearance: none;
  position: relative;
  display: block;
  isolation: isolate;
  box-sizing: border-box;
  overflow: hidden;
  width: 88px;
  height: 44px;
  min-width: 88px;
  min-height: 44px;
  padding: 0;
  border: 1px solid #65758a;
  border-radius: 999px;
  background: #e7ebf2;
  box-shadow: inset 0 2px 3px rgba(26,44,68,.12);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.language-flag {
  position: absolute;
  top: 0;
  height: 100%;
  width: 49px;
  object-fit: cover;
  pointer-events: none;
  opacity: 0;
  transition: opacity 140ms ease;
}
.language-flag--en { right: 0; }
.language-flag--fr { left: 0; }
.language-track[data-active-language="en"] .language-flag--en,
.language-track[data-active-language="fr"] .language-flag--fr { opacity: 1; }
.language-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 38px;
  height: 38px;
  background: linear-gradient(#fff, #f6f8fc);
  border: 1px solid #bdc8d7;
  border-radius: 50%;
  box-sizing: border-box;
  box-shadow: 0 1px 4px rgba(19,31,51,.33);
  pointer-events: none;
  transition: transform 180ms cubic-bezier(.2,.8,.2,1);
}
.language-track[data-active-language="fr"] .language-thumb { transform: translateX(44px); }
.language-track:hover { border-color: var(--brand); }
.language-track:focus-visible, .language-label:focus-visible {
  outline: 3px solid var(--focus) !important;
  outline-offset: 3px !important;
}
html[data-theme="dark"] .language-track {
  background: #26354b;
  border-color: #a0b7d2;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.35);
}
html[data-theme="dark"] .language-thumb {
  background: #f7f9fc;
  border-color: #d0d6df;
  box-shadow: 0 2px 5px rgba(0,0,0,.45);
}
@media (max-width: 920px) {
  .top .controls #language { grid-column: auto; width: auto; justify-self: auto; }
}
@media (max-width: 640px) {
  .app .top .controls #language,
  .shell .top .controls #language {
    grid-column: auto;
    flex: 0 0 auto;
    width: auto;
    margin-left: 0;
  }
  .language-switcher { gap: 4px; }
  .language-label { min-width: 30px; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .language-flag, .language-thumb { transition: none; }
}

/*
 * Compact header-only controls (desktop and mobile). The pictured controls
 * were 44px high; visually halve them to 22px. Keep other form controls and
 * navigation at their existing sizes. EN/FR halves its complete width from
 * ~168px to 84px; the flag track is 44px instead of 88px.
 */
:is(.app, .shell) .top .controls {
  gap: 4px;
}
:is(.app, .shell) .top .controls .select,
:is(.app, .shell) .top .controls .btn {
  box-sizing: border-box;
  height: 22px;
  min-height: 22px;
  max-height: 22px;
  padding: 0 8px;
  border-radius: 5px;
  font-size: 11px;
  line-height: 20px;
}
:is(.app, .shell) .top .controls #tenant,
:is(.app, .shell) .top .controls #site {
  padding: 0 20px 0 7px;
}
:is(.app, .shell) .top .controls #theme-toggle {
  flex: 0 0 112px;
  width: 112px;
  min-width: 112px;
  max-width: 112px;
  height: 22px;
  min-height: 22px;
  max-height: 22px;
  padding: 0 12px 0 4px;
  font-size: 10px;
}
:is(.app, .shell) .top .controls #language {
  flex: 0 0 84px;
  width: 84px;
  min-width: 84px;
  max-width: 84px;
  gap: 4px;
  margin-left: 0;
  justify-content: center;
}
:is(.app, .shell) .top .controls #language .language-label {
  box-sizing: border-box;
  width: 16px;
  min-width: 16px;
  height: 22px;
  min-height: 22px;
  padding: 0;
  border-radius: 4px;
  font-size: 10px;
  line-height: 22px;
}
:is(.app, .shell) .top .controls #language .language-track {
  flex: 0 0 44px;
  box-sizing: border-box;
  width: 44px;
  min-width: 44px;
  max-width: 44px;
  height: 22px;
  min-height: 22px;
  max-height: 22px;
}
:is(.app, .shell) .top .controls #language .language-flag {
  width: 24px;
}
:is(.app, .shell) .top .controls #language .language-thumb {
  top: 1px;
  left: 1px;
  width: 18px;
  height: 18px;
}
:is(.app, .shell) .top .controls #language
.language-track[data-active-language="fr"] .language-thumb {
  transform: translateX(22px);
}
:is(.app, .shell) .top .controls #mode-pill {
  box-sizing: border-box;
  min-height: 22px;
  height: 22px;
  padding: 1px 7px;
  font-size: 11px;
  line-height: 18px;
}
@media (max-width: 920px) {
  :is(.app, .shell) .top .controls #tenant,
  :is(.app, .shell) .top .controls #site {
    flex: 1 1 150px;
  }
  :is(.app, .shell) .top .controls #theme-toggle {
    flex: 0 0 112px;
  }
}
@media (max-width: 640px) {
  :is(.app, .shell) .top .controls #tenant,
  :is(.app, .shell) .top .controls #site {
    flex: 1 1 100%;
  }
  :is(.app, .shell) .top .controls #login,
  :is(.app, .shell) .top .controls #logout,
  :is(.app, .shell) .top .controls #refresh {
    min-height: 22px;
    max-height: 22px;
    height: 22px;
    padding: 0 8px;
  }
  :is(.app, .shell) .top .controls #language {
    flex: 0 0 84px;
    width: 84px;
    min-width: 84px;
    max-width: 84px;
  }
}

/* Compact System card: standard span4 footprint, three readable mini-meters. */
.system-util-card {
  align-self: start;
  padding: 13px 15px;
}
.system-util-card h2 {
  margin: 0 0 7px;
  font-size: 14px;
  line-height: 1.3;
}
.system-util-card .system-util-row + .system-util-row {
  margin-top: 7px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}
.system-util-card .system-util-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 7px;
  min-width: 0;
}
.system-util-card .system-util-head .label {
  font-size: 11px;
  line-height: 1.3;
}
.system-util-card .system-util-head .value {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.15;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.system-util-card .disk-bar {
  height: 5px;
  margin-top: 4px;
}
.system-util-card .disk-detail {
  margin-top: 3px;
  font-size: 10px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Header controls: keep the language switch at the top-right of this header,
 * regardless of the controls wrapping on desktop, tablet, or phone. */
:is(.app, .shell) .top {
  position: relative;
  min-width: 0;
}
:is(.app, .shell) .top > div:first-child { min-width: 0; }
:is(.app, .shell) .top .controls {
  gap: 6px;
  padding-top: 32px;
  justify-content: flex-end;
  min-width: 0;
}
:is(.app, .shell) .top .controls .select,
:is(.app, .shell) .top .controls .btn {
  height: 32px;
  min-height: 32px;
  max-height: none;
  padding: 0 9px;
  border-radius: 7px;
  line-height: normal;
  font-size: 12px;
}
:is(.app, .shell) .top .controls #tenant,
:is(.app, .shell) .top .controls #site {
  padding-right: 23px;
}
:is(.app, .shell) .top .controls #theme-toggle {
  flex: 0 0 116px;
  width: 116px;
  min-width: 116px;
  max-width: 116px;
  height: 32px;
  min-height: 32px;
  max-height: 32px;
  padding: 0 23px 0 8px;
  font-size: 12px;
}
:is(.app, .shell) .top .controls #language {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 3;
  flex: 0 0 100px;
  box-sizing: border-box;
  width: 100px;
  min-width: 100px;
  max-width: 100px;
  gap: 4px;
  margin: 0;
  justify-content: flex-end;
}
:is(.app, .shell) .top .controls #language .language-label {
  width: 19px;
  min-width: 19px;
  height: 32px;
  min-height: 32px;
  line-height: 32px;
  padding: 0;
  font-size: 10px;
}
:is(.app, .shell) .top .controls #language .language-track {
  flex: 0 0 52px;
  width: 52px;
  min-width: 52px;
  max-width: 52px;
  height: 30px;
  min-height: 30px;
  max-height: 30px;
}
:is(.app, .shell) .top .controls #language .language-flag { width: 30px; }
:is(.app, .shell) .top .controls #language .language-thumb {
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
}
:is(.app, .shell) .top .controls #language
.language-track[data-active-language="fr"] .language-thumb {
  transform: translateX(24px);
}
:is(.app, .shell) .top .controls #mode-pill {
  height: 32px;
  min-height: 32px;
  line-height: 28px;
}

/* Responsive mobile overview: reserve a clear lane for the language control,
 * eliminate letterboxing and keep every SVG flow arrow visible. */
@media (max-width: 920px) {
  :is(.app, .shell) .top { gap: 9px; margin-bottom: 12px; }
  :is(.app, .shell) .top > div:first-child { padding-top: 30px; }
  :is(.app, .shell) .top .controls {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
    padding-top: 0;
  }
  :is(.app, .shell) .top .controls #tenant,
  :is(.app, .shell) .top .controls #site { flex: 1 1 170px; min-width: 0; }
}
@media (max-width: 640px) {
  :is(.app, .shell) main { padding: 12px 10px 28px; }
  :is(.app, .shell) .top h1 {
    font-size: 21px;
    line-height: 1.15;
    margin: 2px 0 4px;
    overflow-wrap: anywhere;
  }
  :is(.app, .shell) .top .eyebrow { font-size: 11px; }
  .app .top > div:first-child {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 8px;
    row-gap: 2px;
    width: 100%;
  }
  .app .top .eyebrow { grid-column: 1 / -1; }
  .app .top h1 { grid-column: 1; margin: 0; }
  .app .top .site-health {
    grid-column: 2;
    grid-row: 2;
    white-space: nowrap;
    font-size: 12px;
  }
  .app .top #cloud-live-collected-at {
    grid-column: 1 / -1;
    margin-top: 0 !important;
    font-size: 11px;
    line-height: 1.4;
    overflow-wrap: anywhere;
  }
  .shell .top #updated { font-size: 11px; line-height: 1.4; }
  :is(.app, .shell) .top .controls .select,
  :is(.app, .shell) .top .controls .btn {
    height: 40px;
    min-height: 40px;
    max-height: none;
    padding: 0 10px;
    font-size: 12px;
    border-radius: 8px;
  }
  :is(.app, .shell) .top .controls #tenant,
  :is(.app, .shell) .top .controls #site {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    padding-right: 24px;
  }
  :is(.app, .shell) .top .controls #login,
  :is(.app, .shell) .top .controls #logout,
  :is(.app, .shell) .top .controls #refresh {
    flex: 0 1 auto;
    width: auto;
    min-width: 76px;
    max-width: none;
    height: 40px;
    min-height: 40px;
    max-height: none;
    padding: 0 10px;
  }
  :is(.app, .shell) .top .controls #theme-toggle {
    flex: 0 0 116px;
    width: 116px;
    min-width: 116px;
    max-width: 116px;
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    padding: 0 24px 0 9px;
  }
  :is(.app, .shell) .energy-flow-card { padding: 11px; margin-bottom: 10px; }
  :is(.app, .shell) .energy-flow-card :is(.section, .section-title) {
    margin-bottom: 8px;
    align-items: center;
  }
  :is(.app, .shell) .energy-flow-card h2 { font-size: 16px; }
  :is(.app, .shell) .energy-flow-svg {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 480 / 510;
  }
  :is(.app, .shell) .energy-flow-svg[data-flow-layout="mobile"] .energy-flow-title {
    font-size: 14px;
  }
  :is(.app, .shell) .energy-flow-svg[data-flow-layout="mobile"] .energy-flow-power {
    font-size: 13px;
  }
}


/* Energy-flow cards are the single source of current hardware readings. */
.energy-flow-readings{display:flex;gap:10px;align-items:stretch;flex-wrap:wrap;margin-top:12px}
.energy-flow-reading{display:flex;align-items:center;justify-content:space-between;gap:10px 18px;flex:1 1 230px;min-width:0;padding:11px 15px;border:1px solid var(--line);border-radius:10px;background:var(--panel2);color:var(--text)}
.energy-flow-reading span{color:var(--muted);font-size:12px;font-weight:650}
.energy-flow-reading strong{font-size:17px;font-weight:800;font-variant-numeric:tabular-nums;white-space:nowrap}
.energy-flow-reading[hidden]{display:none}
.energy-flow-energy{font-size:11px;font-weight:750;font-variant-numeric:tabular-nums}
.energy-flow-temperature{fill:#385774;font-size:11px;font-weight:700;font-variant-numeric:tabular-nums}
html[data-theme="dark"] .energy-flow-temperature{fill:#c0d0e5}
@media(max-width:640px){.energy-flow-readings{gap:8px}.energy-flow-reading{padding:10px 12px}.energy-flow-reading strong{font-size:16px}.energy-flow-energy{font-size:10.5px}}
