:root {
  --brand: #b91c1c;
  --brand-dark: #991b1b;
  --navy: #0b3040;
  --navy-deep: #062733;
  --teal: #008c8c;
  --teal-dark: #006f72;
  --ink: #19313c;
  --muted: #6f8188;
  --surface: #ffffff;
  --page: #f3f6f5;
  --line: #dce5e4;
  --solar: #e6a91d;
  --battery: #3f7fca;
  --grid: #d34e52;
  --consumer: #26936b;
  --success: #21815c;
  --warning: #c78412;
  --danger: #b91c1c;
  --shadow: 0 16px 44px rgba(7, 43, 55, .09);
  --shell: min(1320px, calc(100% - 40px));
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--page); font-family: Inter, "Avenir Next", "Segoe UI", Arial, sans-serif; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
button { color: inherit; }
svg { display: block; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; z-index: 1000; left: 12px; top: 12px; padding: 10px 15px; border-radius: 8px; color: #fff; background: var(--navy); transform: translateY(-150%); }
.skip-link:focus { transform: none; }

.em-header { position: sticky; z-index: 100; top: 0; background: #fff; box-shadow: 0 4px 18px rgba(8,45,57,.08); }
.em-info-row { width: var(--shell); height: 76px; margin: 0 auto; display: flex; align-items: center; gap: 28px; }
.em-brand { display: inline-flex; align-items: center; gap: 10px; color: var(--navy); text-decoration: none; }
.em-brand img { width: 39px; height: 39px; }
.em-brand > span { display: flex; align-items: baseline; font-size: 18px; font-weight: 850; letter-spacing: -.04em; }
.em-brand b { color: var(--navy); }
.em-brand strong { color: var(--brand); }
.site-identity { padding-left: 26px; display: flex; align-items: center; gap: 14px; border-left: 1px solid var(--line); }
.site-name { font-size: 13px; font-weight: 750; }
.live-state { padding: 6px 10px; display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; color: #65777e; background: #eff3f2; font-size: 10px; font-weight: 750; }
.live-state i { width: 7px; height: 7px; border-radius: 50%; background: #91a09f; }
.live-state.connected { color: #176c4d; background: #e7f5ef; }
.live-state.connected i { background: #25aa76; box-shadow: 0 0 0 4px rgba(37,170,118,.13); animation: livePulse 2s infinite; }
.live-state.stale { color: #95650e; background: #fff3d9; }
.live-state.stale i { background: #d89b27; }
.live-state.offline { color: #9b2c30; background: #fde8e8; }
.live-state.offline i { background: var(--grid); }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 13px; }
.demo-clock { color: #52676f; font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 750; }
.readonly-badge { padding: 7px 11px; display: inline-flex; align-items: center; gap: 7px; border-radius: 999px; color: var(--teal-dark); background: #e4f3f1; font-size: 10px; font-weight: 800; }
.readonly-badge svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.back-link { color: var(--navy); text-decoration: none; font-size: 11px; font-weight: 750; }
.back-link:hover { color: var(--brand); }
.menu-toggle { display: none; width: 42px; height: 42px; margin-left: auto; border: 0; border-radius: 50%; background: #f3f0e9; cursor: pointer; align-items: center; justify-content: center; flex-direction: column; gap: 4px; }
.menu-toggle i { width: 18px; height: 2px; display: block; background: var(--navy); transition: transform .2s, opacity .2s; }
.menu-toggle[aria-expanded="true"] i:first-of-type { transform: translateY(6px) rotate(45deg); }
.menu-toggle[aria-expanded="true"] i:nth-of-type(2) { opacity: 0; }
.menu-toggle[aria-expanded="true"] i:last-of-type { transform: translateY(-6px) rotate(-45deg); }

.em-navigation { height: 48px; padding-left: max(20px, calc((100% - min(1320px, calc(100% - 40px))) / 2)); display: flex; align-items: stretch; gap: 2px; background: linear-gradient(90deg, var(--brand-dark), var(--brand)); }
.nav-tab { min-width: 145px; padding: 0 20px; border: 0; border-bottom: 3px solid transparent; color: rgba(255,255,255,.82); background: transparent; cursor: pointer; font-size: 12px; font-weight: 700; transition: color .2s, background .2s, border-color .2s; }
.nav-tab:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav-tab.active { border-bottom-color: #fff; color: var(--brand-dark); background: #fff; }

.demo-main { width: var(--shell); min-height: calc(100vh - 177px); margin: 0 auto; padding: 42px 0 68px; }
.connection-message { margin-bottom: 20px; padding: 14px 17px; border: 1px solid #f1c3c3; border-radius: 12px; color: #8c2529; background: #fff0f0; font-size: 12px; }
.demo-view { animation: viewIn .3s ease both; }
.page-heading { margin-bottom: 30px; display: flex; align-items: flex-end; justify-content: space-between; gap: 40px; }
.eyebrow { margin: 0 0 8px; color: var(--brand); font-size: 10px; font-weight: 850; letter-spacing: .15em; text-transform: uppercase; }
.page-heading h1, .page-heading h2 { margin: 0; color: var(--navy); font-size: clamp(32px,4vw,46px); line-height: 1.08; letter-spacing: -.045em; }
.page-heading > div:first-child > p:last-child { max-width: 710px; margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.updated-card { min-width: 205px; padding: 14px 17px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.7); }
.updated-card span, .updated-card strong, .updated-card small { display: block; }
.updated-card span { color: #809096; font-size: 9px; text-transform: uppercase; letter-spacing: .1em; }
.updated-card strong { margin-top: 2px; color: var(--navy); font-size: 14px; }
.updated-card small { margin-top: 2px; color: #839399; font-size: 9px; }

.metric-grid { display: grid; gap: 14px; }
.live-metrics { grid-template-columns: repeat(4,1fr); margin-bottom: 18px; }
.metric-card { min-height: 112px; padding: 20px; display: flex; align-items: center; gap: 15px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); box-shadow: 0 8px 24px rgba(8,45,57,.045); }
.metric-icon { width: 49px; height: 49px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 14px; color: currentColor; font-size: 9px; font-weight: 900; letter-spacing: -.02em; }
.metric-card.solar .metric-icon { color: #a66e00; background: #fff2cf; }
.metric-card.battery .metric-icon { color: #2e6caf; background: #e6f0fc; }
.metric-card.grid .metric-icon { color: #b63e43; background: #fdebec; }
.metric-card.consumer .metric-icon { color: #1d7d59; background: #e4f4ed; }
.metric-card small, .metric-card strong, .metric-card div > span { display: block; }
.metric-card small { color: #7a8b91; font-size: 10px; }
.metric-card strong { margin: 1px 0; color: var(--navy); font-size: 24px; letter-spacing: -.04em; }
.metric-card div > span { color: #89979c; font-size: 9px; }

.dashboard-grid { display: grid; grid-template-columns: 1.45fr .75fr; gap: 18px; }
.panel { border: 1px solid var(--line); border-radius: 19px; background: var(--surface); box-shadow: var(--shadow); }
.panel-head { min-height: 76px; padding: 17px 21px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid #e8eeee; }
.panel-kicker { display: block; color: #849399; font-size: 8px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.panel-head h2 { margin: 2px 0 0; color: var(--navy); font-size: 18px; letter-spacing: -.025em; }
.source-pill, .status-pill { padding: 6px 10px; border-radius: 999px; color: var(--teal-dark); background: #e5f4f1; font-size: 8px; font-weight: 800; }

.flow-canvas { position: relative; height: 390px; overflow: hidden; background: radial-gradient(circle at 50% 50%, rgba(0,140,140,.07), transparent 34%), linear-gradient(#fbfcfc,#fff); }
.flow-lines { position: absolute; inset: 0; width: 100%; height: 100%; }
.flow-path { fill: none; stroke-width: 2; stroke-dasharray: 7 8; opacity: .72; }
.flow-path.toward-core { animation: flowDashTowardCore 1.8s linear infinite; }
.flow-path.from-core { animation: flowDashFromCore 1.8s linear infinite; }
.flow-path.flow-idle { animation: none; opacity: .2; stroke-dasharray: 3 9; marker-start: none; marker-end: none; }
.pv-path.toward-core { marker-end: url(#flow-arrow-solar); }.pv-path.from-core { marker-start: url(#flow-arrow-solar); }
.battery-path.toward-core { marker-end: url(#flow-arrow-battery); }.battery-path.from-core { marker-start: url(#flow-arrow-battery); }
.grid-path.toward-core { marker-end: url(#flow-arrow-grid); }.grid-path.from-core { marker-start: url(#flow-arrow-grid); }
.load-path.toward-core { marker-end: url(#flow-arrow-load); }.load-path.from-core { marker-start: url(#flow-arrow-load); }
.pv-path { stroke: var(--solar); }.battery-path { stroke: var(--battery); }.grid-path { stroke: var(--grid); }.load-path { stroke: var(--consumer); }
.flow-node { position: absolute; width: 126px; display: flex; align-items: center; flex-direction: column; text-align: center; transform: translate(-50%,-50%); }
.flow-pv { left: 18%; top: 23%; }.flow-battery { left: 82%; top: 23%; }.flow-grid { left: 18%; top: 77%; }.flow-load { left: 82%; top: 77%; }
.node-icon { width: 48px; height: 48px; margin-bottom: 7px; display: grid; place-items: center; border-radius: 50%; font-style: normal; font-size: 8px; font-weight: 900; box-shadow: 0 7px 20px rgba(8,45,57,.1); }
.node-icon.solar { color: #9b6800; background: #fff0c1; }.node-icon.battery { color: #2665ac; background: #e4effb; }.node-icon.grid { color: #ae343a; background: #fbe5e6; }.node-icon.consumer { color: #187451; background: #def2e9; }
.flow-node span { color: #76878d; font-size: 9px; }
.flow-node strong { color: var(--navy); font-size: 15px; }
.flow-node small { color: #7c8d92; font-size: 8px; }
.flow-core { position: absolute; left: 50%; top: 50%; width: 116px; height: 116px; display: flex; align-items: center; justify-content: center; flex-direction: column; border: 1px solid #d8e4e2; border-radius: 50%; background: #fff; box-shadow: 0 16px 42px rgba(7,43,55,.14); transform: translate(-50%,-50%); }
.flow-core img { width: 36px; height: 36px; margin-bottom: 3px; }
.flow-core span { color: var(--navy); font-size: 11px; font-weight: 850; }
.flow-core small { color: #87969b; font-size: 7px; }

.decision-list, .status-list { margin: 0; }
.decision-list > div { min-height: 75px; padding: 13px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid #edf1f0; }
.decision-list dt, .status-list dt { color: #71838a; font-size: 10px; }
.decision-list dd { margin: 0; text-align: right; }
.decision-list dd strong, .decision-list dd > span:not(.signal-badge) { display: block; }
.decision-list dd strong { color: var(--navy); font-size: 12px; }
.decision-list dd > span:not(.signal-badge) { color: #849399; font-size: 8px; }
.signal-badge { margin-top: 3px; padding: 3px 7px; display: inline-block; border-radius: 999px; color: #76540f; background: #fff1ce; font-size: 7px; font-weight: 800; }
.readonly-note { margin: 15px; padding: 13px; display: flex; align-items: flex-start; gap: 10px; border-radius: 12px; color: #42616a; background: #e9f4f2; }
.readonly-note svg { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: var(--teal-dark); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.readonly-note p { margin: 0; font-size: 9px; line-height: 1.55; }.readonly-note strong { display: block; color: var(--teal-dark); font-size: 10px; }

.chart-panel { margin-top: 18px; }
.chart-wrap { position: relative; height: 300px; padding: 20px 22px 10px; }
.chart-legend { display: flex; align-items: center; gap: 14px; color: #71838a; font-size: 8px; }
.chart-legend span::before { content: ""; width: 16px; margin-right: 5px; display: inline-block; vertical-align: middle; border-top: 2px solid; }
.chart-legend .grid-line::before, .chart-legend .demand-line::before { border-color: var(--grid); }
.chart-legend .pv-line::before { border-color: var(--solar); }
.chart-legend .battery-line::before, .chart-legend .soc-line::before { border-color: var(--battery); }
.chart-legend .price-line::before { border-color: var(--teal-dark); }
.chart-legend .soc-history-line::before { border-color: #8299ad; border-top-style: dashed; }
.chart-legend .soc-plan-line::before { border-color: #3f7fca; border-top-width: 3px; }
.price-chart-legend .charge-zone::before, .price-chart-legend .discharge-zone::before { width: 14px; height: 8px; border: 0; border-radius: 2px; }
.price-chart-legend .charge-zone::before { background: rgba(32,168,115,.22); }
.price-chart-legend .discharge-zone::before { background: rgba(211,78,82,.2); }
.chart-status { margin: 0; padding: 0 22px 16px; color: #87979c; font-size: 9px; }

.planning-metrics { grid-template-columns: repeat(4,1fr); margin-bottom: 18px; }
.summary-card { min-height: 120px; padding: 19px 20px; border: 1px solid var(--line); border-radius: 17px; background: #fff; box-shadow: 0 8px 24px rgba(8,45,57,.045); }
.summary-card small, .summary-card strong, .summary-card span { display: block; }
.summary-card small { color: #77898f; font-size: 9px; }
.summary-card strong { margin: 7px 0 2px; color: var(--navy); font-size: 25px; letter-spacing: -.04em; }
.summary-card span { color: #8b999d; font-size: 8px; }
.summary-card.highlight { color: #fff; border-color: var(--navy); background: var(--navy); }
.summary-card.highlight small, .summary-card.highlight span { color: #abc0c5; }.summary-card.highlight strong { color: #fff; }
.planning-chart-panel { margin-top: 0; }
.planning-chart-wrap { height: 380px; }
.price-chart-panel { margin-top: 18px; }
.price-chart-panel .panel-head { gap: 18px; }
.price-chart-wrap { height: 330px; }
.planning-details { margin-top: 18px; grid-template-columns: 1.3fr .7fr; }
.window-list { padding: 5px 20px 17px; }
.window-row { padding: 13px 0; display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 14px; border-bottom: 1px solid #edf1f0; }
.window-row:last-child { border: 0; }
.window-row > div strong, .window-row > div span { display: block; }
.window-row > div strong { color: var(--navy); font-size: 11px; }.window-row > div span { color: #829197; font-size: 8px; }
.window-price { color: var(--teal-dark); font-size: 11px; font-weight: 800; }
.window-tag { padding: 4px 7px; border-radius: 999px; color: #66787e; background: #edf2f1; font-size: 7px; font-weight: 800; }
.window-tag.selected { color: #11694a; background: #e1f4eb; }
.empty-state { padding: 18px 0; color: #8b999d; font-size: 10px; }

.range-heading { align-items: center; }
.range-switch { padding: 4px; display: inline-flex; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.range-switch button { min-width: 68px; height: 35px; border: 0; border-radius: 8px; color: #687c83; background: transparent; cursor: pointer; font-size: 9px; font-weight: 750; }
.range-switch button.active { color: #fff; background: var(--navy); }
.performance-metrics { grid-template-columns: repeat(4,1fr); margin-bottom: 18px; }
.performance-details { grid-template-columns: 1fr 1fr; }
.status-list > div { min-height: 54px; padding: 10px 20px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid #edf1f0; }
.status-list > div:last-child { border: 0; }
.status-list dd { margin: 0; color: var(--navy); text-align: right; font-size: 11px; font-weight: 750; }
.status-list.compact > div { min-height: 51px; }
.calculation-note { margin: 14px 0 0; color: #829197; font-size: 9px; }

.status-overview { margin-bottom: 18px; display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; }
.system-health-card { min-height: 270px; padding: 34px; display: flex; align-items: center; gap: 31px; border-radius: 19px; color: #fff; background: linear-gradient(135deg, #0c4958, var(--navy-deep)); box-shadow: 0 20px 48px rgba(6,39,51,.2); }
.health-orb { width: 126px; height: 126px; display: grid; place-content: center; flex: 0 0 auto; border: 1px solid rgba(90,220,187,.38); border-radius: 50%; text-align: center; background: rgba(59,194,153,.11); box-shadow: inset 0 0 0 10px rgba(255,255,255,.025); }
.health-orb span { font-size: 33px; font-weight: 850; }.health-orb small { color: #84cfb7; font-size: 9px; }
.system-health-card > div:last-child > small { color: #85aab3; font-size: 9px; text-transform: uppercase; letter-spacing: .1em; }
.system-health-card h2 { margin: 4px 0 8px; font-size: 28px; letter-spacing: -.04em; }
.system-health-card p { max-width: 390px; margin: 0; color: #a8c0c6; font-size: 11px; }
.system-health-card.warning { background: linear-gradient(135deg,#78510c,#4f370b); }.system-health-card.danger { background: linear-gradient(135deg,#8d252a,#54161a); }
.service-panel { box-shadow: var(--shadow); }
.device-panel { overflow: hidden; }
.device-table { width: 100%; }
.device-row { min-height: 74px; padding: 13px 21px; display: grid; grid-template-columns: 42px minmax(170px,1.3fr) minmax(100px,.8fr) minmax(90px,.6fr) minmax(130px,.8fr); align-items: center; gap: 14px; border-bottom: 1px solid #edf1f0; }
.device-row:last-child { border: 0; }
.device-type-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; color: var(--navy); background: #edf2f2; font-size: 7px; font-weight: 900; }
.device-type-icon.pv { color: #946400; background: #fff0c8; }.device-type-icon.battery { color: #2767ae; background: #e4eefb; }
.device-primary strong, .device-primary span { display: block; }.device-primary strong { color: var(--navy); font-size: 11px; }.device-primary span, .device-cell span { color: #849399; font-size: 8px; }
.device-cell strong, .device-cell span { display: block; }.device-cell strong { color: #405a64; font-size: 10px; }
.health-badge { justify-self: end; padding: 6px 9px; border-radius: 999px; color: #1a7452; background: #e5f5ed; font-size: 8px; font-weight: 800; text-transform: capitalize; }
.health-badge.warning, .health-badge.expected_idle { color: #93620d; background: #fff1d2; }.health-badge.degraded, .health-badge.offline { color: #9a292e; background: #fde7e7; }

.demo-footer { min-height: 53px; padding: 0 max(20px, calc((100% - min(1320px, calc(100% - 40px))) / 2)); display: flex; align-items: center; justify-content: space-between; color: #80959b; background: var(--navy-deep); font-size: 8px; }
.demo-footer > div { display: flex; gap: 20px; }.demo-footer a { color: #a6bec3; text-decoration: none; }

/* A negative dash offset moves the pattern forward along the SVG path.
   All flow paths are drawn from the device toward the SmartEner core. */
@keyframes flowDashTowardCore { to { stroke-dashoffset: -30; } }
@keyframes flowDashFromCore { to { stroke-dashoffset: 30; } }
@keyframes livePulse { 50% { box-shadow: 0 0 0 7px rgba(37,170,118,0); } }
@keyframes viewIn { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }

@media (max-width: 980px) {
  :root { --shell: min(100% - 28px, 820px); }
  .site-identity { display: none; }
  .live-metrics, .planning-metrics, .performance-metrics { grid-template-columns: repeat(2,1fr); }
  .dashboard-grid, .planning-details, .performance-details, .status-overview { grid-template-columns: 1fr; }
  .control-panel { display: grid; grid-template-columns: 1fr 1fr; }.control-panel .panel-head { grid-column: 1 / -1; }.readonly-note { align-self: center; }
}

@media (max-width: 700px) {
  :root { --shell: calc(100% - 22px); }
  .em-info-row { height: 68px; gap: 12px; }.em-brand img { width: 33px; height: 33px; }.em-brand > span { font-size: 16px; }
  .header-actions { display: none; }.menu-toggle { display: flex; }
  .em-navigation { position: absolute; left: 10px; right: 10px; top: 64px; height: auto; padding: 10px; display: none; flex-direction: column; border-radius: 13px; box-shadow: 0 16px 36px rgba(7,43,55,.22); }
  .em-navigation.open { display: flex; }.nav-tab { min-height: 42px; border: 0; border-radius: 8px; text-align: left; }.nav-tab.active { color: var(--brand-dark); }
  .demo-main { min-height: calc(100vh - 121px); padding: 30px 0 50px; }
  .page-heading { align-items: stretch; flex-direction: column; gap: 17px; }.page-heading h1, .page-heading h2 { font-size: 34px; }.updated-card { min-width: 0; }
  .live-metrics, .planning-metrics, .performance-metrics { grid-template-columns: 1fr 1fr; gap: 9px; }
  .metric-card { min-height: 100px; padding: 13px; gap: 10px; }.metric-icon { width: 39px; height: 39px; border-radius: 11px; font-size: 7px; }.metric-card strong { font-size: 19px; }
  .flow-canvas { height: 360px; }.flow-node { width: 105px; }.flow-pv, .flow-grid { left: 17%; }.flow-battery, .flow-load { left: 83%; }.flow-core { width: 94px; height: 94px; }.flow-core img { width: 29px; height: 29px; }
  .control-panel { display: block; }.decision-list > div { min-height: 66px; }
  .chart-wrap { height: 260px; padding-inline: 12px; }.planning-chart-wrap { height: 350px; }.chart-legend { display: none; }.price-chart-legend, .planning-balance-legend { width: 100%; display: flex; flex-wrap: wrap; }
  .summary-card { min-height: 105px; padding: 15px; }.summary-card strong { font-size: 20px; }
  .range-heading { align-items: stretch; }.range-switch { width: 100%; }.range-switch button { min-width: 0; flex: 1; }
  .system-health-card { min-height: 0; padding: 25px 20px; align-items: flex-start; flex-direction: column; gap: 20px; }.health-orb { width: 100px; height: 100px; }
  .device-row { grid-template-columns: 38px 1fr auto; gap: 10px; }.device-cell { grid-column: 2; }.device-cell.secondary { display: none; }.health-badge { grid-column: 3; grid-row: 1; }
  .demo-footer { padding: 14px 12px; align-items: flex-start; flex-direction: column; gap: 8px; }.demo-footer > div { flex-direction: column; gap: 3px; }
}

@media (max-width: 430px) {
  .live-metrics { grid-template-columns: 1fr; }.planning-metrics, .performance-metrics { grid-template-columns: 1fr 1fr; }
  .metric-card { min-height: 92px; }.panel-head { padding-inline: 15px; }.flow-canvas { height: 340px; }
  .summary-card strong { font-size: 18px; }.window-row { grid-template-columns: 1fr auto; }.window-tag { grid-column: 2; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
