: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; }
.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(0, 1fr) 200px 174px; gap: 24px; align-items: center; overflow: hidden; margin: 30px 0 18px; min-height: 232px; padding: 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, .hero-summary, .hero-visual { position: relative; z-index: 1; }
.hero-eyebrow { display: flex; align-items: center; gap: 8px; }
.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 { max-width: 560px; margin-bottom: 9px; font-size: clamp(2rem, 4.6vw, 3.35rem); letter-spacing: -.05em; line-height: 1; }
.hero-updated { color: #bed0c3; margin-bottom: 16px; }
.hero-flow { display: inline-flex; 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-visual { align-self: stretch; min-width: 150px; color: #f0c46b; }
.energy-orbit { position: absolute; border: 1px solid rgba(240, 196, 107, .34); border-radius: 50%; }
.orbit-one { width: 148px; height: 148px; top: 34px; left: 20px; animation: orbit-spin 16s linear infinite; }
.orbit-two { width: 106px; height: 106px; top: 56px; left: 41px; border-style: dashed; animation: orbit-spin 11s linear infinite reverse; }
.hero-sun { position: absolute; top: 66px; left: 50px; width: 90px; height: 90px; filter: drop-shadow(0 0 18px rgba(240, 196, 107, .36)); animation: hero-float 4s ease-in-out infinite; }
.hero-bolt { position: absolute; bottom: 3px; right: 2px; width: 41px; height: 54px; color: var(--accent); filter: drop-shadow(0 0 10px rgba(129, 212, 156, .38)); animation: hero-float 3.3s ease-in-out .4s infinite; }
.hero-summary { display: grid; justify-items: center; gap: 16px; }
.soc-ring { --charge: 0; display: grid; place-items: center; width: 132px; 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 30px rgba(129, 212, 156, .16); 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.5rem; letter-spacing: -.05em; }
.soc-ring span { color: var(--muted); font-size: .75rem; }
.energy-hero .connection-state { width: max-content; max-width: 168px; 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; }
.temperature-strip { gap: 9px; margin-top: 16px; }
.temperature-strip span { 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-dot { width: 6px; height: 6px; border-radius: 50%; background: 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) 164px; }
  .hero-visual { display: none; }
}
@media (max-width: 640px) {
  .energy-hero { grid-template-columns: 1fr; min-height: 0; padding: 25px; gap: 22px; }
  .hero-summary { grid-template-columns: auto 1fr; justify-items: start; align-items: center; }
  .energy-hero .connection-state { text-align: left; }
  .soc-ring { width: 102px; }
  .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; }
}
