:root {
  color-scheme: dark;
  --page: #101714;
  --surface: #18221e;
  --surface-strong: #203029;
  --text: #eff7f0;
  --muted: #a9b8ae;
  --border: #31443a;
  --accent: #81d49c;
  --accent-strong: #3fa966;
  --warning: #f0c46b;
  --danger: #ec8383;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--text); }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
main, .site-header { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.site-header { min-height: 68px; display: flex; align-items: center; gap: 26px; border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; letter-spacing: .01em; }
nav { display: flex; gap: 18px; color: var(--muted); }
nav a:hover { color: var(--text); }
.account-actions { margin-left: auto; display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: .9rem; }
.account-actions form { margin: 0; }
.mobile-users-link { display: none; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 18px; margin: 42px 0 24px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(1.75rem, 4vw, 2.5rem); }
h2 { margin-bottom: 6px; font-size: 1.2rem; }
h3 { margin-bottom: 18px; font-size: 1rem; }
.eyebrow { color: var(--accent); font-size: .76rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; margin-bottom: 7px; }
.muted, small { color: var(--muted); }
.connection-state { color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); padding: 8px 12px; border-radius: 999px; font-size: .9rem; white-space: nowrap; }
.connection-state::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: currentColor; }
.connection-state.is-waiting { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 45%, transparent); }
.connection-state.is-offline { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric-card, .surface, .login-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; }
.metric-card { min-height: 142px; padding: 20px; display: flex; flex-direction: column; gap: 9px; }
.metric-card span { color: var(--muted); font-size: .86rem; }
.metric-card strong { font-size: 1.55rem; letter-spacing: -.03em; }
.metric-card small { margin-top: auto; }
.detail-layout, .chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.detail-layout { margin-top: 16px; }
.surface { padding: 22px; }
.section-heading { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.cell-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.cell-list div { background: var(--surface-strong); border-radius: 10px; padding: 12px; display: flex; justify-content: space-between; gap: 10px; }
.cell-list span { color: var(--muted); font-size: .86rem; }
.temperatures { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 18px; color: var(--muted); }
.temperatures strong { color: var(--text); margin-left: 5px; }
.device-details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 16px 0 0; }
.device-details div { border-top: 1px solid var(--border); padding-top: 12px; }
dt { color: var(--muted); font-size: .84rem; }
dd { margin: 5px 0 0; font-weight: 600; }
.history-section { margin: 32px 0 48px; }
.history-heading { align-items: flex-end; margin-bottom: 14px; }
.range-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.button { border: 1px solid var(--border); background: transparent; color: var(--text); padding: 9px 12px; border-radius: 9px; cursor: pointer; }
.button:hover, .button.is-active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.button-primary { color: #08210f; background: var(--accent); border-color: var(--accent); font-weight: 700; }
.button-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.button-quiet { font-size: .88rem; padding: 7px 10px; }
.chart-surface { min-height: 360px; }
.chart-surface canvas { width: 100% !important; height: 288px !important; }
.login-shell { min-height: calc(100vh - 69px); display: grid; place-items: center; padding: 40px 0; }
.login-panel { width: min(100%, 440px); padding: 30px; }
.stacked-form { display: grid; gap: 8px; margin-top: 20px; }
.stacked-form label { font-size: .9rem; color: var(--muted); }
.stacked-form input { min-height: 43px; color: var(--text); background: var(--page); border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; margin-bottom: 6px; }
.stacked-form input:focus, .stacked-form select:focus, .account-form input:focus, .account-form select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.stacked-form select, .account-form select { min-height: 43px; color: var(--text); background: var(--page); border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; margin-bottom: 6px; }
.stacked-form .button { margin-top: 6px; }
.form-error { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); border-radius: 8px; padding: 10px; }
.form-success { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); border-radius: 8px; padding: 10px; margin: 20px 0 -10px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 11px 8px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; }
.accounts-section { margin: 34px 0 48px; }
.account-settings { margin: 34px 0 48px; }
.accounts-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.account-card { display: flex; flex-direction: column; }
.account-card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 6px; }
.account-card-heading h3 { margin-bottom: 5px; }
.account-card-heading p { margin-bottom: 8px; font-size: .86rem; }
.account-badge, .role-badge { display: inline-block; border-radius: 999px; padding: 4px 8px; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.account-badge { margin-left: 8px; color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, transparent); }
.role-badge { color: var(--muted); background: var(--surface-strong); }
.role-admin { color: #0b2815; background: var(--accent); }
.account-activity { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 18px 0; }
.account-activity div { background: var(--surface-strong); border-radius: 10px; padding: 12px; }
.account-activity dd { font-size: .92rem; }
.account-presence { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; }
.account-presence::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.account-presence.is-online { color: var(--accent); }
.account-presence.is-online::before { background: var(--accent); }
.account-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; margin-top: 8px; }
.account-form label { color: var(--muted); font-size: .84rem; }
.account-form input, .account-form select { width: 100%; }
.account-form .button { grid-column: 1 / -1; justify-self: start; margin-top: 5px; }
.delete-user-form { margin: 12px 0 0; padding-top: 12px; border-top: 1px solid var(--border); }
.button-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 55%, var(--border)); }
.button-danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); border-color: var(--danger); }

@media (max-width: 820px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-layout, .chart-grid, .accounts-list { grid-template-columns: 1fr; }
  .account-activity { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  main, .site-header { width: min(100% - 24px, 1180px); }
  .site-header { gap: 12px; flex-wrap: wrap; padding: 12px 0; }
  nav { order: 3; width: 100%; }
  .account-actions { margin-left: auto; }
  .page-heading { align-items: flex-start; flex-direction: column; margin-top: 28px; }
  .metric-grid { grid-template-columns: 1fr; }
  .cell-list, .device-details { grid-template-columns: 1fr; }
  .history-heading { align-items: flex-start; flex-direction: column; }
  .chart-surface { min-height: 310px; }
  .chart-surface canvas { height: 245px !important; }
}
@media (max-width: 380px) {
  .site-header { align-items: flex-start; }
  .brand { width: 100%; }
  .account-actions { width: 100%; margin-left: 0; justify-content: space-between; }
  .metric-card, .surface { padding: 16px; }
  .metric-card { min-height: 118px; }
  .range-buttons { width: 100%; }
  .range-buttons .button { flex: 1; padding-inline: 8px; }
  .connection-state { white-space: normal; }
  .account-form { grid-template-columns: 1fr; }
  .account-activity { grid-template-columns: 1fr; }
}

/* Live energy dashboard ---------------------------------------------------- */
.dashboard-page { position: relative; isolation: isolate; overflow-x: clip; padding-bottom: 14px; }
.dashboard-page::before { content: ""; position: absolute; z-index: -1; inset: 0 -80px auto; height: 620px; background: radial-gradient(circle at 76% 18%, rgba(82, 210, 140, .13), transparent 30%), radial-gradient(circle at 18% 3%, rgba(80, 150, 214, .10), transparent 27%); pointer-events: none; }
.energy-hero { position: relative; display: grid; grid-template-columns: minmax(290px, .95fr) minmax(260px, 1.05fr) 228px; grid-template-rows: auto auto auto auto auto auto; column-gap: 28px; row-gap: 7px; align-items: start; overflow: hidden; margin: 30px 0 18px; min-height: 0; padding: 28px 32px; border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--border)); border-radius: 24px; background: linear-gradient(130deg, #162b22 0%, #15211c 48%, #111c18 100%); box-shadow: 0 24px 56px rgba(0, 0, 0, .20); }
.energy-hero::before { content: ""; position: absolute; inset: 0; background-image: linear-gradient(rgba(129, 212, 156, .045) 1px, transparent 1px), linear-gradient(90deg, rgba(129, 212, 156, .045) 1px, transparent 1px); background-size: 34px 34px; mask-image: linear-gradient(90deg, #000, transparent 83%); pointer-events: none; }
.hero-copy { display: contents; }
.hero-summary, .hero-visual, .hero-eyebrow, .energy-hero h1, .hero-updated, .hero-flow, .hero-power, .hero-estimate { position: relative; z-index: 1; }
.hero-eyebrow { display: flex; grid-column: 1 / 3; grid-row: 1; align-items: center; gap: 8px; margin-bottom: 0; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 0 rgba(129, 212, 156, .7); animation: live-pulse 2.2s infinite; }
.energy-hero h1 { grid-column: 1 / 3; grid-row: 2; max-width: 640px; margin-bottom: 0; font-size: clamp(2rem, 4.6vw, 3.35rem); letter-spacing: -.05em; line-height: 1; }
.hero-updated { grid-column: 1 / 3; grid-row: 3; color: #bed0c3; margin-bottom: 0; }
.hero-flow { display: inline-flex; grid-column: 1 / 3; grid-row: 4; justify-self: start; align-items: center; gap: 9px; padding: 8px 11px 8px 9px; border: 1px solid rgba(129, 212, 156, .28); border-radius: 999px; color: var(--accent); background: rgba(10, 38, 22, .48); font-size: .88rem; font-weight: 650; }
.hero-flow-icon { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; color: #0b2815; background: var(--accent); }
.hero-flow-icon svg { width: 14px; height: 14px; }
.hero-power { display: grid; grid-column: 1; grid-row: 5; width: 100%; max-width: 320px; min-width: 0; margin-top: 6px; padding: 10px 12px; border: 1px solid rgba(129, 212, 156, .24); border-radius: 12px; background: rgba(8, 29, 19, .44); }
.hero-power-heading { color: var(--muted); font-size: .72rem; font-weight: 650; text-transform: uppercase; letter-spacing: .07em; }
.hero-power-readings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 6px; }
.hero-power-item { display: grid; gap: 3px; }
.hero-power-item + .hero-power-item { padding-left: 11px; border-left: 1px solid rgba(169, 184, 174, .19); }
.hero-power-item > span { color: var(--muted); font-size: .69rem; }
.hero-power-item strong { font-size: 1.23rem; letter-spacing: -.04em; line-height: 1; }
.hero-solar-power strong { color: var(--warning); }
.hero-battery-power strong { color: var(--accent); }
.hero-power-caption { margin-top: 6px; color: #b9c7bf; font-size: .78rem; }
.hero-power.is-discharging { border-color: rgba(120, 184, 235, .35); }
.hero-power.is-discharging .hero-battery-power strong { color: #78b8eb; }
.hero-power.is-discharging .hero-power-caption { color: #b6d4ec; }
.hero-power.is-idle { border-color: rgba(169, 184, 174, .25); }
.hero-power.is-idle .hero-battery-power strong { color: var(--muted); }
.hero-estimate { display: grid; grid-column: 1; grid-row: 6; grid-template-columns: 30px minmax(0, 1fr); align-items: center; gap: 9px; width: 100%; max-width: 320px; min-width: 0; margin-top: 0; padding: 9px 12px; border: 1px solid rgba(129, 212, 156, .24); border-radius: 12px; background: rgba(8, 29, 19, .44); }
.hero-estimate-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 10px; color: var(--accent); background: rgba(129, 212, 156, .12); }
.hero-estimate-icon svg { width: 18px; height: 18px; }
.hero-estimate-content { display: grid; gap: 1px; }
.hero-estimate-content > span:first-child { color: var(--muted); font-size: .69rem; font-weight: 650; letter-spacing: .07em; text-transform: uppercase; }
.hero-estimate-content strong { color: var(--accent); font-size: 1.03rem; letter-spacing: -.035em; line-height: 1.15; }
.hero-estimate-content > span:last-child { color: #b9c7bf; font-size: .73rem; }
.hero-estimate.is-discharging { border-color: rgba(120, 184, 235, .35); }
.hero-estimate.is-discharging .hero-estimate-icon { color: #78b8eb; background: rgba(120, 184, 235, .12); }
.hero-estimate.is-discharging strong { color: #78b8eb; }
.hero-estimate.is-discharging .hero-estimate-content > span:last-child { color: #b6d4ec; }
.hero-estimate.is-idle { border-color: rgba(169, 184, 174, .25); }
.hero-estimate.is-idle .hero-estimate-icon, .hero-estimate.is-idle strong { color: var(--muted); }
.hero-visual { display: grid; grid-column: 2; grid-row: 5 / 7; grid-template-rows: 1fr auto; align-self: stretch; min-width: 0; min-height: 170px; padding: 8px 10px 0; border-left: 1px solid rgba(240, 196, 107, .16); border-radius: 14px; background: linear-gradient(90deg, rgba(240, 196, 107, .045), transparent 82%); color: #f0c46b; }
.hero-summary { display: grid; grid-column: 3; grid-row: 1 / 7; align-self: center; justify-items: center; gap: 10px; min-width: 0; padding-left: 18px; border-left: 1px solid rgba(129, 212, 156, .16); text-align: center; }
.hero-percent { display: grid; gap: 3px; justify-items: center; min-width: 210px; }
.hero-percent strong { color: var(--text); font-size: 1.95rem; letter-spacing: -.055em; line-height: 1; }
.hero-percent span { color: var(--muted); font-size: .84rem; }
.soc-ring { --charge: 0; display: grid; place-items: center; width: 156px; aspect-ratio: 1; padding: 10px; border-radius: 50%; background: conic-gradient(var(--accent) calc(var(--charge) * 1%), rgba(255, 255, 255, .10) 0); box-shadow: 0 0 0 1px rgba(129, 212, 156, .16), 0 0 38px rgba(129, 212, 156, .2); transition: background .7s ease; }
.soc-ring > div { display: grid; place-items: center; width: 100%; height: 100%; border-radius: 50%; background: #14241d; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .05); }
.soc-ring strong { font-size: 1.22rem; letter-spacing: -.05em; white-space: nowrap; }
.soc-ring span { color: var(--muted); font-size: .75rem; white-space: nowrap; }
.energy-hero .connection-state { width: max-content; max-width: 220px; text-align: center; white-space: normal; background: rgba(11, 34, 23, .55); }
.energy-metrics { margin-top: 18px; }
.dashboard-page .metric-card { position: relative; min-height: 166px; overflow: hidden; padding: 19px; border-color: rgba(113, 161, 130, .34); background: linear-gradient(145deg, rgba(30, 48, 40, .96), rgba(21, 34, 29, .96)); box-shadow: 0 15px 28px rgba(0, 0, 0, .12); animation: card-appear .55s ease both; }
.dashboard-page .metric-card:nth-child(2) { animation-delay: .06s; }
.dashboard-page .metric-card:nth-child(3) { animation-delay: .12s; }
.dashboard-page .metric-card:nth-child(4) { animation-delay: .18s; }
.dashboard-page .metric-card::after { content: ""; position: absolute; width: 120px; height: 120px; right: -42px; bottom: -64px; border-radius: 50%; background: currentColor; opacity: .08; filter: blur(8px); pointer-events: none; }
.dashboard-page .metric-card:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--accent) 64%, var(--border)); box-shadow: 0 20px 32px rgba(0, 0, 0, .18); }
.metric-card-top { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.metric-icon { display: grid; flex: 0 0 auto; place-items: center; width: 35px; height: 35px; border: 1px solid currentColor; border-radius: 11px; background: color-mix(in srgb, currentColor 13%, transparent); }
.metric-icon svg { width: 20px; height: 20px; }
.metric-label { font-size: .82rem; font-weight: 650; }
.metric-flow { color: #8ddfb1; }
.metric-charge { color: #f0c46b; }
.metric-voltage { color: #78b8eb; }
.metric-solar { color: #f0c46b; }
.dashboard-page .metric-card strong { margin-top: 18px; color: var(--text); font-size: clamp(1.45rem, 3vw, 1.86rem); }
.dashboard-page .metric-card small { position: relative; z-index: 1; color: var(--muted); font-size: .88rem; }
.metric-flow.is-charging .icon-bolt { color: var(--accent); box-shadow: 0 0 0 0 rgba(129, 212, 156, .35); animation: icon-pulse 1.55s infinite; }
.metric-flow.is-discharging .icon-bolt { color: #78b8eb; }
.metric-flow.is-idle .icon-bolt { color: var(--muted); }
.dashboard-detail-layout { margin-top: 18px; }
.dashboard-page .detail-panel { position: relative; overflow: hidden; padding: 24px; border-color: rgba(113, 161, 130, .34); background: linear-gradient(145deg, #182821, #16231e); }
.dashboard-page .detail-panel::after { content: ""; position: absolute; top: 0; left: 26px; right: 26px; height: 2px; border-radius: 99px; background: linear-gradient(90deg, var(--accent), transparent 72%); opacity: .75; }
.dashboard-page .mppt-panel::after { background: linear-gradient(90deg, var(--warning), transparent 72%); }
.panel-heading { display: flex; align-items: flex-start; gap: 13px; }
.panel-heading h2 { margin-bottom: 5px; }
.panel-heading .eyebrow { margin-bottom: 4px; }
.panel-icon { display: grid; flex: 0 0 auto; place-items: center; width: 42px; height: 42px; margin-top: 1px; border-radius: 13px; color: var(--accent); background: rgba(129, 212, 156, .12); }
.panel-icon svg { width: 24px; height: 24px; }
.solar-panel-icon { color: var(--warning); background: rgba(240, 196, 107, .12); }
.panel-meta { margin: 0; color: var(--muted); font-size: .84rem; }
.dashboard-page .cell-list { margin-top: 22px; }
.dashboard-page .cell-list div { position: relative; padding: 13px; overflow: hidden; border: 1px solid transparent; background: rgba(42, 68, 56, .62); transition: border-color .2s ease, transform .2s ease; }
.dashboard-page .cell-list div:hover { transform: translateY(-2px); border-color: rgba(129, 212, 156, .38); }
.dashboard-page .cell-list strong { font-size: 1rem; }
.dashboard-page .cell-list .cell-label { display: inline-flex; align-items: center; gap: 6px; }
.dashboard-page .cell-list .cell-reading { display: grid; justify-items: end; align-content: center; gap: 4px; text-align: right; }
.dashboard-page .cell-list .cell-temperature { display: inline-flex; align-items: center; justify-content: end; gap: 4px; color: var(--warning); font-size: .74rem; line-height: 1; white-space: nowrap; }
.cell-label svg { width: 15px; height: 15px; color: #78b8eb; }
.cell-temperature svg { width: 13px; height: 13px; }
.temperature-strip { gap: 9px; margin-top: 16px; }
.temperature-chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; border: 1px solid rgba(113, 161, 130, .24); border-radius: 9px; background: rgba(14, 29, 23, .35); font-size: .85rem; }
.temperature-icon { width: 16px; height: 16px; color: var(--warning); }
.dashboard-page .device-details { margin-top: 22px; gap: 12px 20px; }
.dashboard-page .device-details div { padding: 13px 0 3px; border-color: rgba(113, 161, 130, .28); }
.dashboard-page .device-details dd { font-size: 1.12rem; }
.dashboard-page .history-section { margin-top: 36px; }
.dashboard-page .history-heading { margin-bottom: 16px; }
.dashboard-page .chart-surface { position: relative; overflow: hidden; min-height: 366px; padding: 22px; border-color: rgba(113, 161, 130, .34); background: linear-gradient(145deg, #192a22, #14211c); }
.dashboard-page .chart-surface::before { content: ""; position: absolute; inset: 0 0 auto; height: 2px; background: linear-gradient(90deg, #81d49c, transparent 70%); }
.dashboard-page .chart-capacity::before { background: linear-gradient(90deg, #f0c46b, transparent 70%); }
.chart-title { display: flex; align-items: center; gap: 9px; }
.chart-title h3 { margin-bottom: 0; }
.chart-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px rgba(129, 212, 156, .55); }
.chart-capacity .chart-dot { background: var(--warning); box-shadow: 0 0 12px rgba(240, 196, 107, .5); }
.dashboard-page .chart-surface canvas { margin-top: 18px; }

@keyframes live-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(129, 212, 156, .6); } 50% { box-shadow: 0 0 0 7px rgba(129, 212, 156, 0); } }
@keyframes orbit-spin { to { transform: rotate(360deg); } }
@keyframes hero-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes icon-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(129, 212, 156, .34); } 50% { box-shadow: 0 0 0 7px rgba(129, 212, 156, 0); } }
@keyframes card-appear { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 980px) {
  .energy-hero { grid-template-columns: minmax(0, 1fr) 192px; grid-template-rows: auto auto; gap: 24px; padding: 28px; }
  .hero-copy { display: block; grid-column: 1; grid-row: 1; }
  .hero-eyebrow, .energy-hero h1, .hero-updated, .hero-flow, .hero-power, .hero-estimate { grid-column: auto; grid-row: auto; }
  .energy-hero h1 { max-width: 560px; margin-bottom: 9px; }
  .hero-updated { margin-bottom: 16px; }
  .hero-power { width: max-content; max-width: none; min-width: 284px; margin-top: 13px; }
  .hero-estimate { width: max-content; max-width: none; min-width: 226px; margin-top: 9px; }
  .hero-visual { grid-column: 1 / -1; grid-row: 2; min-height: 148px; height: 148px; padding: 8px 10px 0; border-left: 0; border-top: 1px solid rgba(240, 196, 107, .16); }
  .hero-summary { grid-column: 2; grid-row: 1; align-self: center; padding-left: 0; border-left: 0; }
  .soc-ring { width: 132px; }
}
@media (max-width: 640px) {
  .energy-hero { grid-template-columns: 1fr; grid-template-rows: auto auto auto; min-height: 0; padding: 25px; gap: 22px; }
  .hero-copy { grid-column: 1; grid-row: 1; }
  .hero-summary { grid-template-columns: auto auto; align-items: center; justify-content: center; column-gap: 20px; row-gap: 12px; width: 100%; }
  .hero-summary { grid-column: 1; grid-row: 3; }
  .hero-percent { grid-column: 1; grid-row: 1; min-width: 0; }
  .hero-summary .soc-ring { grid-column: 2; grid-row: 1; }
  .hero-summary .connection-state { grid-column: 1 / -1; grid-row: 2; }
  .energy-hero .connection-state { text-align: center; }
  .hero-visual { grid-column: 1; grid-row: 2; width: min(100%, 320px); min-height: 126px; height: 126px; margin-inline: auto; }
  .soc-ring { width: 124px; }
  .dashboard-page .metric-card { min-height: 150px; }
  .dashboard-page .detail-panel, .dashboard-page .chart-surface { padding: 19px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Fixed-screen live dashboard ------------------------------------------------ */
body.dashboard-body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  min-width: 320px;
  overflow: hidden;
}

main.dashboard-main {
  height: auto;
  min-height: 0;
  overflow: hidden;
}

.dashboard-main .power-screen {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(10px, 1.6vh, 18px);
  height: 100%;
  min-height: 0;
  padding: clamp(10px, 1.8vh, 18px) 0;
  overflow: hidden;
}

.power-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 54px;
  min-width: 0;
}

.power-title { flex: 1 1 0; min-width: 0; }
.power-title .eyebrow { margin-bottom: 3px; }
.power-title h1 { margin: 0; font-size: clamp(1.28rem, 2.4vw, 1.8rem); line-height: 1.08; }
.power-updated { margin: 4px 0 0; color: var(--muted); font-size: clamp(.72rem, 1.25vw, .86rem); }
.power-actions, .dialog-header-actions { display: flex; align-items: center; gap: 9px; }
.power-actions { flex: 0 0 auto; }

.history-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 11px;
  background: rgba(32, 48, 41, .55);
  color: var(--text);
  cursor: pointer;
}

.history-button svg { width: 17px; height: 17px; }
.history-button:hover { border-color: var(--accent); background: rgba(129, 212, 156, .12); }

.dashboard-main .connection-state {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  font-size: clamp(.72rem, 1.2vw, .84rem);
}

.power-stage {
  display: grid;
  grid-template-columns: minmax(235px, 1fr) minmax(178px, .62fr) minmax(235px, 1fr);
  gap: clamp(12px, 2vw, 28px);
  min-height: 0;
  min-width: 0;
}

.power-tile,
.power-flow {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(113, 161, 130, .35);
  border-radius: clamp(19px, 2vw, 28px);
}

.power-tile {
  isolation: isolate;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(22px, 4vw, 56px);
  appearance: none;
  color: var(--text);
  text-align: center;
  cursor: pointer;
  transition: transform .22s ease, border-color .22s ease, box-shadow .22s ease;
}

.power-tile::before,
.power-flow::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.power-tile::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: .24;
  background-image: linear-gradient(rgba(255, 255, 255, .07) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .07) 1px, transparent 1px);
  background-size: 30px 30px;
  mask-image: linear-gradient(145deg, #000, transparent 72%);
  pointer-events: none;
}

.power-tile-solar { background: linear-gradient(145deg, #312b17 0%, #211d13 56%, #171912 100%); }
.power-tile-solar::before { background: radial-gradient(circle at 75% 22%, rgba(255, 207, 103, .26), transparent 34%), linear-gradient(145deg, rgba(248, 194, 80, .10), transparent); }
.power-tile-battery { background: linear-gradient(145deg, #163128 0%, #14251e 56%, #101a16 100%); }
.power-tile-battery::before { background: radial-gradient(circle at 78% 22%, rgba(129, 212, 156, .25), transparent 34%), linear-gradient(145deg, rgba(129, 212, 156, .10), transparent); }
.power-tile-battery.is-discharging::before { background: radial-gradient(circle at 78% 22%, rgba(116, 184, 235, .27), transparent 34%), linear-gradient(145deg, rgba(116, 184, 235, .10), transparent); }
.power-tile-battery.is-idle::before { background: radial-gradient(circle at 78% 22%, rgba(169, 184, 174, .18), transparent 34%), linear-gradient(145deg, rgba(169, 184, 174, .06), transparent); }

.tile-heading { display: flex; align-items: center; justify-content: center; gap: clamp(9px, 1.4vw, 14px); }
.power-tile .tile-icon { flex: 0 0 auto; margin: 0; }
.tile-heading .tile-eyebrow { color: var(--text); font-size: clamp(.9rem, 1.6vw, 1.16rem); letter-spacing: .045em; text-transform: none; }

.power-tile:hover { transform: translateY(-4px); border-color: rgba(240, 196, 107, .75); box-shadow: 0 24px 42px rgba(0, 0, 0, .22); }
.power-tile-battery:hover { border-color: rgba(129, 212, 156, .78); }
.power-tile:focus-visible, .history-button:focus-visible, .dialog-close:focus-visible, .button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.power-tile-glow {
  position: absolute;
  width: 210px;
  height: 210px;
  right: -112px;
  bottom: -120px;
  border-radius: 50%;
  opacity: .5;
  filter: blur(6px);
  background: #f0c46b;
  pointer-events: none;
}

.power-tile-battery .power-tile-glow { background: var(--accent); }
.power-tile-battery.is-discharging .power-tile-glow { background: #78b8eb; }

.tile-icon {
  display: inline-grid;
  place-items: center;
  width: clamp(44px, 5vw, 64px);
  height: clamp(44px, 5vw, 64px);
  margin-bottom: clamp(12px, 2vh, 20px);
  border: 1px solid currentColor;
  border-radius: 16px;
}

.tile-icon svg { width: 58%; height: 58%; }
.tile-icon-solar { color: #f5cc71; background: rgba(240, 196, 107, .11); }
.tile-icon-battery { color: var(--accent); background: rgba(129, 212, 156, .11); }
.tile-eyebrow { color: var(--muted); font-size: clamp(.77rem, 1.25vw, .95rem); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.tile-power { margin: clamp(8px, 1.6vh, 16px) 0 8px; font-size: clamp(3.3rem, 8vw, 7rem); letter-spacing: -.075em; line-height: .86; white-space: nowrap; }
.power-tile-solar .tile-power { color: #ffe1a1; }
.power-tile-battery .tile-power { color: #b4f0c7; }
.power-tile-battery.is-discharging .tile-power { color: #b6dfff; }
.tile-status { display: grid; gap: 3px; max-width: 22ch; color: var(--muted); font-size: clamp(1.02rem, 1.72vw, 1.25rem); font-weight: 600; line-height: 1.25; text-align: center; }
.solar-current-reading { display: inline-flex; align-items: baseline; justify-content: center; gap: .35em; white-space: nowrap; }
.solar-current-reading strong { color: #ffe1a1; font-size: 1.3em; font-weight: 800; letter-spacing: -.03em; }
.battery-tile-meta { display: inline-flex; align-items: baseline; justify-content: center; gap: 10px; margin-top: 5px; color: var(--muted); font-size: clamp(1.06rem, 1.65vw, 1.22rem); font-weight: 600; }
.battery-tile-meta strong { color: var(--text); font-size: 1.08em; }
.battery-tile-meta #hero-soc-percent { font-size: 1.28em; }
.battery-tile-meta #battery-current { color: var(--text); font-size: 1.25em; font-weight: 800; letter-spacing: -.03em; }
.tile-hint { display: inline-flex; align-items: center; justify-content: center; gap: 6px; margin-top: 15px; padding-top: 0; color: rgba(239, 247, 240, .74); font-size: clamp(.76rem, 1.2vw, .9rem); }
.tile-hint span { font-size: 1.2em; transition: transform .2s ease; }
.power-tile:hover .tile-hint span { transform: translateX(4px); }

.power-flow {
  display: grid;
  align-content: center;
  justify-items: stretch;
  gap: clamp(7px, 1.4vh, 12px);
  padding: clamp(14px, 2vw, 24px);
  color: var(--muted);
  text-align: center;
  background: linear-gradient(180deg, rgba(22, 42, 34, .72), rgba(15, 25, 21, .52));
}

.power-flow::before { background: radial-gradient(circle at 50% 50%, rgba(129, 212, 156, .16), transparent 54%); }
.power-flow.is-discharging::before { background: radial-gradient(circle at 50% 50%, rgba(116, 184, 235, .16), transparent 54%); }
.flow-label { margin: 0; color: var(--muted); font-size: .72rem; font-weight: 700; letter-spacing: .11em; text-transform: uppercase; }
.flow-direction { color: var(--text); font-size: clamp(.98rem, 1.8vw, 1.25rem); line-height: 1.16; }
.flow-routes { min-width: 0; }
.flow-route { display: none; align-items: center; justify-content: center; width: 100%; gap: 10px; color: rgba(239, 247, 240, .78); }
.power-flow.is-charging .flow-route-charging, .power-flow.is-discharging .flow-route-discharging, .power-flow.is-idle .flow-route-idle { display: flex; }
.flow-node { display: grid; justify-items: center; gap: 2px; min-width: 46px; color: var(--text); }
.flow-node svg { width: 27px; height: 27px; }
.flow-node-solar { color: #f5cc71; }
.flow-node-battery { color: var(--accent); }
.flow-node-load { color: #9bc7f3; }
.flow-node small { color: var(--text); font-size: .64rem; font-weight: 700; letter-spacing: .03em; }
.flow-line { position: relative; flex: 1; height: 3px; min-width: 28px; overflow: hidden; border-radius: 99px; background: rgba(129, 212, 156, .22); color: var(--accent); }
.flow-line span { position: absolute; inset: 0; width: 42%; border-radius: inherit; background: linear-gradient(90deg, transparent, var(--accent), #e7f9ec); animation: flow-pulse 1.8s linear infinite; }
.flow-line::after { content: ""; position: absolute; top: 50%; right: 1px; width: 7px; height: 7px; border: solid currentColor; border-width: 0 2px 2px 0; transform: translateY(-50%) rotate(-45deg); }
.power-flow.is-discharging .flow-line { background: rgba(116, 184, 235, .22); color: #78b8eb; }
.power-flow.is-discharging .flow-line span { background: linear-gradient(90deg, transparent, #78b8eb, #d9edff); }
.power-flow.is-idle .flow-line span { opacity: .34; animation: none; left: 29%; }
.power-flow.is-idle .flow-line::after { opacity: .34; }
.flow-readout { display: flex; justify-content: center; gap: 12px; color: var(--muted); font-size: clamp(.71rem, 1.2vw, .85rem); }
.flow-readout span { white-space: nowrap; }
.flow-readout strong { color: var(--text); }
.flow-readout span:first-child strong { color: #ffe1a1; }
.flow-readout span:last-child strong { color: #b4f0c7; }
.power-flow.is-discharging .flow-readout span:last-child strong { color: #b6dfff; }
.flow-estimate { display: inline-flex; align-items: baseline; justify-content: center; gap: 6px; color: var(--muted); font-size: clamp(.68rem, 1.1vw, .8rem); }
.flow-estimate strong { color: var(--accent); font-size: 1.05em; }
.flow-estimate.is-discharging strong { color: #b6dfff; }
.flow-estimate.is-idle strong { color: var(--muted); }
.flow-caption { color: var(--muted); font-size: clamp(.69rem, 1.1vw, .8rem); }

.power-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2.2vw, 28px);
  min-height: 35px;
  min-width: 0;
  color: var(--muted);
  font-size: clamp(.72rem, 1.2vw, .84rem);
}

.footer-reading { display: inline-flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.footer-reading strong { color: var(--text); }
#battery-soc { font-size: 1.18em; }
.footer-separator { width: 4px; height: 4px; border-radius: 50%; background: var(--border); }

.detail-dialog {
  width: min(700px, calc(100vw - 28px));
  max-height: min(850px, calc(100dvh - 28px));
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(129, 212, 156, .34);
  border-radius: 22px;
  background: #15211c;
  color: var(--text);
  box-shadow: 0 32px 90px rgba(0, 0, 0, .55);
}

.detail-dialog::backdrop { background: rgba(3, 8, 6, .76); backdrop-filter: blur(7px); }
.detail-dialog.history-dialog { width: min(1180px, calc(100vw - 28px)); }
.dialog-panel { max-height: min(850px, calc(100dvh - 28px)); padding: clamp(20px, 3.5vw, 38px); overflow: auto; background: radial-gradient(circle at 88% 5%, rgba(129, 212, 156, .10), transparent 32%), #15211c; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding-bottom: 17px; border-bottom: 1px solid rgba(113, 161, 130, .28); }
.dialog-header .eyebrow { margin-bottom: 4px; }
.dialog-header h2 { margin: 0; font-size: clamp(1.3rem, 3vw, 1.75rem); }
.dialog-close { display: grid; place-items: center; flex: 0 0 auto; width: 42px; height: 42px; padding: 0; border: 1px solid var(--border); border-radius: 50%; background: rgba(32, 48, 41, .7); color: var(--text); cursor: pointer; font-size: 1.6rem; line-height: 1; }
.dialog-close:hover { border-color: var(--accent); color: var(--accent); }
.dialog-battery-overview { display: grid; grid-template-columns: minmax(150px, .8fr) minmax(200px, 1.2fr); align-items: center; gap: 24px; margin: 24px 0; }
.dialog-battery-overview .soc-ring { width: 150px; margin: 0 auto; }
.soc-ring { aspect-ratio: 1; display: grid; place-items: center; border-radius: 50%; background: conic-gradient(var(--accent) calc(var(--charge) * 1%), rgba(129, 212, 156, .12) 0); }
.soc-ring > div { display: grid; place-items: center; width: 78%; height: 78%; padding: 12px; border-radius: inherit; background: #17231e; text-align: center; }
.soc-ring strong { font-size: clamp(1rem, 2.5vw, 1.35rem); }
.soc-ring span { margin-top: 4px; color: var(--muted); font-size: .78rem; }
.hero-estimate { display: flex; align-items: center; gap: 13px; min-height: 104px; padding: 18px; border: 1px solid rgba(129, 212, 156, .25); border-radius: 16px; background: rgba(27, 47, 38, .5); }
.dialog-battery-overview .hero-estimate { grid-column: auto; grid-row: auto; width: auto; max-width: none; min-width: 0; margin: 0; }
.hero-estimate.is-discharging { border-color: rgba(116, 184, 235, .32); background: rgba(26, 43, 53, .45); }
.hero-estimate.is-idle { border-color: rgba(169, 184, 174, .25); background: rgba(37, 47, 42, .45); }
.estimate-icon { display: grid; place-items: center; flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%; color: var(--accent); background: rgba(129, 212, 156, .12); }
.estimate-icon svg { width: 24px; height: 24px; }
.hero-estimate-content { display: grid; gap: 3px; }
.hero-estimate-content > span { color: var(--muted); font-size: .82rem; }
.hero-estimate-content strong { font-size: clamp(1.05rem, 2.4vw, 1.35rem); }

.dialog-detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 0; }
.dialog-detail-grid div { padding: 14px; border: 1px solid rgba(113, 161, 130, .28); border-radius: 12px; background: rgba(32, 48, 41, .45); }
.dialog-detail-grid dt { color: var(--muted); font-size: .75rem; }
.dialog-detail-grid dd { margin: 5px 0 0; color: var(--text); font-size: 1.06rem; font-weight: 700; }
#bms-model { font-size: .88rem; line-height: 1.3; overflow-wrap: anywhere; }
.solar-detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.solar-dialog-power { display: flex; align-items: center; gap: 16px; padding: 26px 0; }
.solar-dialog-power .tile-icon { flex: 0 0 auto; margin: 0; }
.solar-dialog-power > span:last-child { display: grid; gap: 4px; }
.solar-dialog-power strong { color: #ffe1a1; font-size: clamp(2.2rem, 6vw, 4rem); line-height: .92; }
.solar-dialog-power small { color: var(--muted); }
.dialog-section { margin-top: 25px; padding-top: 24px; border-top: 1px solid rgba(113, 161, 130, .28); }
.dialog-section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dialog-section-heading h3 { margin: 0; font-size: 1.05rem; }
.panel-meta { margin: 0; color: var(--muted); font-size: .82rem; text-align: right; }
.bms-detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 16px 0 0; }
.bms-detail-grid div { min-width: 0; padding: 13px; border: 1px solid rgba(113, 161, 130, .24); border-radius: 12px; background: rgba(32, 48, 41, .45); }
.bms-detail-grid dt { color: var(--muted); font-size: .75rem; }
.bms-detail-grid dd { margin: 5px 0 0; color: var(--text); font-size: .95rem; font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; }
.bms-detail-grid .bms-wide-reading { grid-column: 1 / -1; }
.bms-alert-summary { max-width: 220px; margin: 0; color: var(--muted); font-size: .78rem; font-weight: 700; line-height: 1.35; text-align: right; }
.bms-alert-summary.is-ok { color: #89dfaa; }
.bms-alert-summary.is-alert { color: #f1ca7a; }
.bms-alert-summary.is-waiting { color: var(--muted); }
.bms-detail-grid [hidden] { display: none; }
.dialog-panel .cell-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dialog-panel .cell-list div { padding: 13px; border: 1px solid rgba(113, 161, 130, .24); background: rgba(32, 48, 41, .45); }
.dialog-panel .cell-label { color: var(--muted); }
.dialog-panel .cell-reading { display: grid; justify-items: end; gap: 3px; color: var(--text); }
.cell-temperature { color: #f0c46b; }
.dashboard-page .dialog-panel .cell-list .cell-temperature-shared,
.dashboard-page .dialog-panel .cell-list .cell-temperature-unavailable { color: var(--muted); font-size: .68rem; }

.history-dialog .dialog-header { align-items: center; }
.history-dialog .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 24px; }
.history-dialog .chart-surface { min-height: 330px; padding: 20px; border-color: rgba(113, 161, 130, .34); background: linear-gradient(145deg, #192a22, #14211c); }
.history-dialog .chart-surface canvas { height: 255px !important; }
.chart-title { display: flex; align-items: center; gap: 9px; }
.chart-title h3 { margin: 0; }
.chart-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px rgba(129, 212, 156, .55); }

.diagnostics-dialog { width: min(860px, calc(100vw - 28px)); }
.diagnostics-intro { margin: 20px 0 7px; color: var(--muted); font-size: .87rem; line-height: 1.45; }
.diagnostics-log { display: grid; gap: 8px; margin: 15px 0 0; padding: 0; list-style: none; }
.diagnostics-log-entry { display: grid; grid-template-columns: minmax(110px, auto) minmax(0, 1fr); gap: 11px; align-items: start; padding: 10px 12px; border: 1px solid rgba(113, 161, 130, .24); border-radius: 11px; background: rgba(32, 48, 41, .45); font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: .78rem; line-height: 1.42; }
.diagnostics-log-time { color: #9cbeb0; white-space: nowrap; }
.diagnostics-log-message { min-width: 0; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.diagnostics-log-empty { padding: 17px 12px; border: 1px dashed rgba(113, 161, 130, .32); border-radius: 11px; color: var(--muted); font-size: .87rem; text-align: center; }
.raspberry-console { margin-top: 20px; padding: 18px; border: 1px solid rgba(127, 215, 158, .34); border-radius: 15px; background: linear-gradient(140deg, rgba(37, 77, 58, .28), rgba(17, 34, 28, .54)); }
.raspberry-console-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.raspberry-console-heading h3 { margin: 2px 0 0; font-size: 1.06rem; }
.raspberry-console-state { flex: 0 0 auto; padding: 5px 8px; border: 1px solid rgba(127, 215, 158, .35); border-radius: 999px; color: #a7e6ba; font-size: .72rem; font-weight: 750; white-space: nowrap; }
.raspberry-console-intro { margin: 13px 0 16px; color: var(--muted); font-size: .82rem; line-height: 1.45; }
.raspberry-console-intro code { color: #d3eadb; font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; }
.raspberry-console form { display: grid; gap: 8px; }
.raspberry-console form[hidden] { display: none; }
.raspberry-console label { color: #d9ece0; font-size: .83rem; font-weight: 750; }
.raspberry-console input, .raspberry-console textarea { width: 100%; min-width: 0; border: 1px solid rgba(127, 215, 158, .32); border-radius: 10px; background: rgba(6, 17, 12, .76); color: var(--text); font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: .85rem; line-height: 1.45; }
.raspberry-console input { min-height: 42px; padding: 9px 11px; }
.raspberry-console textarea { min-height: 78px; padding: 10px 11px; resize: vertical; }
.raspberry-console input:focus, .raspberry-console textarea:focus { outline: 2px solid rgba(127, 215, 158, .62); outline-offset: 2px; }
.raspberry-console-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.raspberry-console-actions > input { flex: 1 1 auto; }
.raspberry-console-actions .button { flex: 0 0 auto; min-height: 42px; white-space: nowrap; }
.raspberry-console-actions .panel-meta { min-width: 0; margin: 0; font-size: .77rem; line-height: 1.35; }
.raspberry-console-live-status { display: flex; align-items: center; gap: 8px; margin: 10px 0 0; color: #d6eadc; font-size: .78rem; font-weight: 700; line-height: 1.35; }
.raspberry-console-live-status[hidden] { display: none; }
.raspberry-console-live-status::before { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: #7fd79e; box-shadow: 0 0 0 3px rgba(127, 215, 158, .12); content: ""; }
.raspberry-console-live-status.is-running::before, .raspberry-console-live-status.is-reboot::before { animation: console-status-pulse 1.1s ease-in-out infinite; }
.raspberry-console-live-status.is-reboot { color: #f4d37c; }
.raspberry-console-live-status.is-reboot::before { background: #efbd57; box-shadow: 0 0 0 3px rgba(239, 189, 87, .13); }
.raspberry-console-live-status.is-error { color: #efb3ae; }
.raspberry-console-live-status.is-error::before { background: #dc766d; box-shadow: 0 0 0 3px rgba(220, 118, 109, .12); }
@keyframes console-status-pulse { 50% { opacity: .42; transform: scale(.76); } }
.raspberry-console-output { max-height: 230px; min-height: 58px; margin: 16px 0 0; padding: 11px 12px; overflow: auto; border: 1px solid rgba(113, 161, 130, .3); border-radius: 10px; background: #09130f; color: #d9efe0; font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: .79rem; line-height: 1.48; white-space: pre-wrap; overflow-wrap: anywhere; overscroll-behavior: contain; }
.diagnostics-device-logs { margin-top: 18px; border-top: 1px solid rgba(113, 161, 130, .22); }
.diagnostics-device-logs summary { padding: 15px 0 1px; color: #d9ece0; cursor: pointer; font-size: .9rem; font-weight: 750; }
.diagnostics-device-logs summary::marker { color: var(--accent); }
.chart-capacity .chart-dot { background: var(--warning); box-shadow: 0 0 12px rgba(240, 196, 107, .5); }

@keyframes flow-pulse { from { transform: translateX(-140%); } to { transform: translateX(290%); } }

@media (max-width: 920px) {
  .power-stage { grid-template-columns: minmax(190px, 1fr) minmax(132px, .55fr) minmax(190px, 1fr); gap: 12px; }
  .power-tile { padding: clamp(18px, 3.5vw, 32px); }
  .tile-power { font-size: clamp(2.8rem, 8.2vw, 4.8rem); }
  .power-flow .flow-route { gap: 6px; }
  .power-flow .flow-node { min-width: 28px; }
  .power-flow .flow-node small { display: none; }
  .power-flow .flow-readout { gap: 6px; font-size: .71rem; }
}

@media (min-width: 651px) and (max-width: 900px) {
  /* Narrow tablets need the same clear reading order as phones, without
     squeezing the flow panel into an unreadable middle column. */
  .power-stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) 108px minmax(0, 1fr);
    gap: 10px;
  }

  .power-tile-solar { grid-row: 1; }
  .power-flow {
    grid-column: auto;
    grid-row: 2;
    gap: 3px;
    padding: 8px 18px;
    border-radius: 18px;
  }
  .power-tile-battery { grid-row: 3; }
  .flow-label, .flow-caption { display: none; }
}

@media (max-width: 650px) {
  /* Keep the live overview inside one phone viewport, including iPhone safe areas. */
  body.dashboard-body {
    --dashboard-header-height: calc(68px + env(safe-area-inset-top));
    overscroll-behavior: none;
  }

  main.dashboard-main {
    width: min(100% - 20px, 1180px);
  }

  .site-header {
    width: min(100% - 20px, 1180px);
    min-height: var(--dashboard-header-height);
    flex-wrap: nowrap;
    gap: 12px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: 12px;
  }

  .site-header nav, .account-actions > span { display: none; }
  .site-header .brand {
    width: auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .site-header .account-actions { width: auto; flex: 0 0 auto; gap: 6px; margin-left: auto; }
  .site-header .button { min-height: 44px; }
  .site-header .mobile-users-link { display: inline-flex; align-items: center; justify-content: center; padding-inline: 9px; }

  .dashboard-main .power-screen {
    gap: clamp(8px, 1.3dvh, 12px);
    padding: clamp(10px, 1.5dvh, 14px) 0 max(10px, env(safe-area-inset-bottom));
  }

  .power-topbar { min-height: 44px; gap: 8px; }
  .power-title h1 { overflow: hidden; font-size: 1.2rem; text-overflow: ellipsis; white-space: nowrap; }
  .power-updated { width: 100%; min-width: 0; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .power-actions { gap: 8px; }
  .history-button { flex: 0 0 44px; width: 44px; min-height: 44px; justify-content: center; padding: 0; font-size: 0; touch-action: manipulation; }
  .history-button svg { width: 18px; height: 18px; }
  .dashboard-main .connection-state { width: 44px; min-height: 44px; justify-content: center; padding: 0; overflow: hidden; font-size: 0; }
  .dashboard-main .connection-state::before { width: 9px; height: 9px; margin: 0; }

  .power-stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) clamp(126px, 16dvh, 140px) minmax(0, 1fr);
    gap: 9px;
  }

  .power-tile-solar { grid-row: 1; }
  .power-flow {
    grid-column: auto;
    grid-row: 2;
    min-height: 0;
    gap: 3px;
    padding: 8px 14px;
    border-radius: 16px;
  }
  .power-tile-battery { grid-row: 3; }

  .power-tile {
    grid-column: auto;
    min-height: 0;
    padding: 16px 18px;
    border-radius: 18px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .power-tile .tile-icon { width: 56px; height: 56px; margin: 0; border-radius: 15px; }
  .tile-heading { gap: 12px; }
  .tile-heading .tile-eyebrow { font-size: 1rem; }
  .tile-power { margin: 8px 0 7px; font-size: clamp(3rem, 15vw, 4.1rem); }
  .tile-status { max-width: none; font-size: 1rem; }
  .solar-current-reading strong { font-size: 1.2em; }
  .battery-tile-meta { margin-top: 4px; font-size: .98rem; }
  .battery-tile-meta #battery-current { font-size: 1.2em; }
  .tile-hint { min-height: 28px; margin-top: 11px; padding-top: 0; font-size: .72rem; }

  .flow-label { font-size: .62rem; }
  .flow-direction { font-size: .91rem; }
  .power-flow .flow-route { gap: 8px; }
  .power-flow .flow-node { min-width: 42px; gap: 1px; }
  .power-flow .flow-node svg { width: 23px; height: 23px; }
  .power-flow .flow-node small { display: block; font-size: .57rem; }
  .flow-line { min-width: 42px; }
  .flow-readout { gap: 9px; font-size: .67rem; }
  .flow-readout span { white-space: nowrap; }
  .flow-estimate { gap: 4px; font-size: .61rem; }
  .flow-caption { display: none; }

  .power-footer { min-height: 30px; gap: 12px; font-size: .71rem; }
  .footer-separator { display: none; }
  .footer-reading:last-child { display: none; }

  .detail-dialog,
  .detail-dialog.history-dialog {
    position: fixed;
    inset: auto 0 0;
    width: 100%;
    max-width: none;
    max-height: min(82dvh, calc(100dvh - env(safe-area-inset-top) - 12px));
    margin: 0;
    border-width: 1px 0 0;
    border-radius: 24px 24px 0 0;
  }

  .dialog-panel {
    max-height: min(82dvh, calc(100dvh - env(safe-area-inset-top) - 12px));
    padding: 16px 16px max(20px, calc(16px + env(safe-area-inset-bottom)));
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .dialog-header {
    position: sticky;
    top: -16px;
    z-index: 2;
    margin: -16px -16px 0;
    padding: 16px 16px 14px;
    background: rgba(21, 33, 28, .96);
    backdrop-filter: blur(12px);
  }

  .dialog-close { width: 44px; height: 44px; touch-action: manipulation; }
  .dialog-battery-overview { grid-template-columns: 1fr; gap: 16px; margin: 18px 0; }
  .dialog-battery-overview .soc-ring { width: 130px; }
  .dialog-detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .history-dialog .dialog-header { align-items: stretch; flex-direction: column; }
  .dialog-header-actions { align-items: center; justify-content: space-between; gap: 8px; width: 100%; }
  .history-dialog .range-buttons { flex: 1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .history-dialog .range-buttons .button { min-height: 44px; min-width: 0; padding: 7px 3px; font-size: .72rem; touch-action: manipulation; }
  .history-dialog .chart-grid { grid-template-columns: 1fr; }
  .diagnostics-log-entry { grid-template-columns: 1fr; gap: 3px; }
  .diagnostics-log-time { font-size: .72rem; }
  .raspberry-console { margin-top: 16px; padding: 15px; }
  .raspberry-console-heading { align-items: flex-start; }
  .raspberry-console-state { max-width: 122px; white-space: normal; text-align: center; }
  .raspberry-console-actions { align-items: stretch; flex-wrap: wrap; }
  .raspberry-console-actions > input { flex-basis: 100%; }
  .raspberry-console-actions .button { min-height: 44px; }
  .raspberry-console-actions .panel-meta { flex: 1 1 170px; align-self: center; }
  .raspberry-console-output { max-height: 180px; font-size: .75rem; }
}

@media (max-width: 650px) and (max-height: 760px) {
  /* Keep the live currents visible before the optional click hint on compact phones. */
  .power-tile .tile-icon { width: 48px; height: 48px; }
  .tile-power { font-size: clamp(2.65rem, 13vw, 3.4rem); }
  .tile-hint { display: none; }
}

@media (max-width: 650px) and (max-height: 680px) {
  .dashboard-main .power-screen { gap: 7px; padding: 7px 0 8px; }
  .power-stage { grid-template-rows: minmax(0, 1fr) 84px minmax(0, 1fr); gap: 7px; }
  .power-tile { padding: 10px 14px; }
  .power-tile .tile-icon { width: 40px; height: 40px; border-radius: 12px; }
  .tile-heading { gap: 8px; }
  .tile-heading .tile-eyebrow { font-size: .85rem; }
  .tile-power { margin: 5px 0 3px; font-size: clamp(2.35rem, 12vw, 3.15rem); }
  .power-tile-solar .tile-status { display: grid; gap: 1px; font-size: .98rem; line-height: 1.15; }
  .power-tile-solar .solar-current-reading strong { font-size: 1.22em; }
  .battery-tile-meta { display: inline-flex; margin-top: 2px; font-size: .9rem; }
  .battery-tile-meta #battery-current { font-size: 1.16em; }
  .battery-tile-meta #hero-soc-percent { font-size: 1.3em; }
  .tile-hint { display: none; }
  .power-flow { gap: 1px; padding: 5px 12px; }
  .flow-label, .flow-readout, .flow-caption { display: none; }
  .flow-direction { font-size: .87rem; }
  .flow-estimate { gap: 3px; font-size: .62rem; }
  .power-flow .flow-route { gap: 6px; }
  .power-flow .flow-node { min-width: 34px; }
  .power-flow .flow-node svg { width: 18px; height: 18px; }
  .power-flow .flow-node small { font-size: .57rem; }
  .flow-line { min-width: 30px; }
}

@media (min-width: 651px) and (max-height: 500px) {
  /* Keep both solar-current readings intact on compact desktop windows. */
  .dashboard-main .power-screen { gap: 8px; padding: 7px 0; }
  .power-tile { padding: 10px 16px; }
  .power-tile .tile-icon { width: 50px; height: 50px; }
  .tile-heading { gap: 10px; }
  .tile-heading .tile-eyebrow { font-size: 1rem; }
  .tile-power { margin: 5px 0 4px; font-size: clamp(3.6rem, 6.4vw, 5rem); }
  .tile-status { gap: 1px; font-size: clamp(.94rem, 1.45vw, 1.08rem); }
  .solar-current-reading strong { font-size: 1.22em; }
  .battery-tile-meta { margin-top: 2px; font-size: clamp(.92rem, 1.35vw, 1rem); }
  .battery-tile-meta #battery-current { font-size: 1.22em; }
  .tile-hint { display: none; }
}

@media (max-width: 650px) and (max-height: 540px) {
  /* On very short browser viewports, keep live readings before click hints. */
  .power-stage { grid-template-rows: minmax(0, 1fr) 76px minmax(0, 1fr); }
  .power-tile { padding: 6px 12px; }
  .power-tile-solar .tile-status { line-height: 1.08; }
  .tile-hint { display: none; }
  .power-footer { font-size: .68rem; }
  #battery-soc { font-size: 1.12em; }
}

@media (max-height: 700px) and (min-width: 651px) {
  .dashboard-main .power-screen { gap: 9px; padding: 9px 0; }
  .power-topbar { min-height: 45px; }
  .power-updated { margin-top: 2px; }
  .power-tile { padding: clamp(16px, 3vw, 30px); }
  .tile-icon { width: 42px; height: 42px; margin-bottom: 10px; }
  .tile-power { font-size: clamp(2.8rem, 7vw, 5rem); }
  .flow-route { margin: 14px 0 10px; }
  .tile-hint { padding-top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .flow-line span { animation: none; }
  .power-tile, .tile-hint span { transition: none; }
}
