:root {
  --bg: #f4f6f8; --card: #fff; --text: #1d2730; --muted: #6b7782; --line: #dfe4e9;
  --accent: #1f6feb; --ok: #1a7f37; --bad: #cf222e; --off: #8c959f;
  --solar: #e3a008; --load: #d1495b; --batt: #2f9e44; --soc: #1f6feb;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419; --card: #1a2129; --text: #e6edf3; --muted: #8b98a5; --line: #2b3640;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419; --card: #1a2129; --text: #e6edf3; --muted: #8b98a5; --line: #2b3640;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, sans-serif; }
body.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
main { padding: 16px; max-width: 1100px; margin: 0 auto; }
h1, h2, h3 { margin: 0 0 8px; }
h2 { font-size: 1.4rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); } .small { font-size: 0.85rem; } .error { color: var(--bad); }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 8px 0; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.narrow { width: min(380px, 100%); }
.top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
label { display: grid; gap: 4px; margin-bottom: 12px; font-size: 0.9rem; }
input { font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); width: 100%; }
button, .btn { font: inherit; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; text-decoration: none; }
button.ghost, .btn.ghost { background: transparent; color: var(--accent); }
button.danger { color: var(--bad); border-color: var(--bad); }
button:disabled { opacity: 0.5; cursor: default; }
.notice { background: #fff8c5; color: #3d2e00; padding: 8px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 0.9rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.tile { display: grid; gap: 4px; text-align: left; padding: 18px; background: var(--card); color: var(--text); border: 1px solid var(--line); }
.tile:hover { border-color: var(--accent); }
.badge { padding: 4px 10px; border-radius: 999px; font-size: 0.85rem; background: var(--line); }
.badge.ok { background: #dafbe1; color: var(--ok); }
.badge.bad { background: #ffebe9; color: var(--bad); }
.badge.off { color: var(--off); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 12px 0 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; align-items: center; gap: 12px; min-width: 0; }
.kpi div { display: grid; min-width: 0; }
.kpi-ico { width: 44px; height: 44px; flex: none; }
.kpi span { color: var(--muted); font-size: 0.85rem; }
.kpi strong { font-size: 1.6rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin: 12px 0 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.stat > header { padding: 8px 12px; font-weight: 700; font-size: 0.95rem; }
.stat.yellow > header { background: #f5c518; color: #1d2730; }
.stat.dark > header { background: #3b4148; color: #fff; }
.stat-body { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.stat-ico { width: 84px; height: 84px; flex: none; }
.stat-vals { display: grid; gap: 10px; margin-left: auto; text-align: right; min-width: 0; }
.stat-vals p { margin: 0; display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: baseline; gap: 4px; }
.stat-vals strong { font-size: 1.5rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-vals span { color: var(--muted); }
.stat-vals small { width: 100%; color: var(--muted); font-size: 0.85rem; }
[hidden] { display: none !important; }
.seg { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); }
.seg-btn { flex: 1; background: transparent; color: var(--muted); border: 0; border-radius: 999px; padding: 10px 14px; min-height: 48px; font-size: 1rem; }
.seg-btn.on { background: var(--accent); color: #fff; }
.dt-nav { display: grid; grid-template-columns: 52px 1fr 52px; gap: 8px; margin: 12px 0; }
.nav-btn { min-height: 52px; font-size: 1.6rem; line-height: 1; padding: 0; background: var(--card); color: var(--accent); border: 1px solid var(--line); }
.dt-picker { font-size: 1.1rem; min-height: 52px; text-align: center; }
.chart-wrap { position: relative; }
.dt-tip { position: absolute; z-index: 5; min-width: 170px; pointer-events: none; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15); font-size: 0.9rem; }
.dt-tip[hidden] { display: none; }
.tip-title { display: block; margin-bottom: 4px; }
.tip-row { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 6px; padding: 2px 0; }
.tip-row .sw { width: 12px; height: 4px; }
.tip-row b { font-variant-numeric: tabular-nums; }
.cursor { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.chart svg { min-height: 240px; }
.axis { font-size: 15px; }
@media (max-width: 640px) {
  .chart svg { min-height: 320px; }
}
.bar.solar { fill: var(--solar); }
.bar.load { fill: var(--load); }
.bar.batt { fill: var(--batt); }
.dt-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-top: 12px; }
.dt-total { background: var(--bg); border-radius: 8px; padding: 8px 10px; display: grid; }
.dt-total span { color: var(--muted); font-size: 0.85rem; }
.dt-total strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 8px; margin: 8px 0 14px; }
.tab { display: inline-flex; align-items: center; gap: 6px; background: transparent; color: var(--muted); border: 1px solid var(--line); }
.tab svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab.on { background: var(--accent); color: #fff; border-color: var(--accent); }
/* Phones: the tabs become an app-style bar fixed to the bottom of the screen. */
@media (max-width: 640px) {
  body { padding-bottom: 84px; }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; margin: 0; gap: 0; justify-content: space-around; background: var(--card); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
  .tab { flex: 1; display: grid; justify-items: center; align-content: center; gap: 2px; min-height: 56px; padding: 6px 4px; border: 0; border-radius: 12px; font-size: 0.8rem; }
  .tab svg { width: 24px; height: 24px; }
  .tab.on { background: transparent; color: var(--accent); }
}
.events { list-style: none; margin: 0; padding: 0; }
.events li { display: grid; gap: 4px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.events li:last-child { border-bottom: 0; }
.ev-title { font-weight: 600; color: var(--bad); }
.ev-meta { color: var(--muted); font-size: 0.9rem; }
.weather { background: var(--card); padding: 0; overflow: hidden; }
.weather[hidden] { display: none; }

/* Login: logo on top, one card with large fields, easy to use with a thumb. */
.login-box { width: min(420px, 100%); display: grid; gap: 14px; justify-items: center; }
.login-logo { width: min(260px, 72%); height: auto; }
.login-sub { margin: 0; color: var(--muted); text-align: center; }
.login-card { width: 100%; display: grid; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.login-card label { font-size: 0.95rem; margin-bottom: 10px; }
.login-card input { min-height: 50px; font-size: 1.05rem; }
button.big { width: 100%; min-height: 52px; font-size: 1.05rem; }
.login-card .big { margin-top: 6px; }
.install { margin-top: 2px; }
.help { text-align: center; margin: 0; }
.wx-head { padding: 10px 14px; font-weight: 600; border-bottom: 1px solid var(--line); }
.wx-body { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(200px, 1.3fr); gap: 16px; align-items: center; padding: 16px; }
.wx-now { display: grid; justify-items: center; gap: 8px; text-align: center; }
.wx-icon svg { width: 80px; height: 80px; display: block; color: var(--muted); }
.wx-now strong { font-size: 1rem; }
.wx-side { display: grid; gap: 10px; }
.wx-temp { margin: 0; font-size: 1.2rem; font-weight: 600; }
.wx-yield { background: var(--bg); border-radius: 8px; padding: 8px 12px; display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 6px; }
.wx-yield span { width: 100%; color: var(--muted); font-size: 0.85rem; }
.wx-yield strong { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.wx-yield small { color: var(--muted); }
@media (max-width: 640px) {
  .wx-body { grid-template-columns: 1fr; }
  .wx-icon svg { width: 60px; height: 60px; }
}
.flow-card .flow-narrow { display: none; }
@media (max-width: 640px) {
  .flow-card .flow-wide { display: none; }
  .flow-card .flow-narrow { display: block; max-width: 340px; margin: 0 auto; }
  .stat-ico { width: 72px; height: 72px; }
  .stat-vals strong { font-size: 1.3rem; }
  /* Header fits on one line; the user name is dropped to make room for the buttons. */
  .top { flex-wrap: nowrap; gap: 8px; padding: 10px 12px; }
  #who { display: none; }
  .top button { padding: 10px 12px; min-height: 44px; white-space: nowrap; }
  .logo { height: 30px; }
  /* Tap targets: at least 44px tall, as touch screens need. */
  button, .btn { min-height: 44px; }
  .row { gap: 8px; }
  .stat-vals p { gap: 2px 4px; }
  .stat-vals small { font-size: 0.8rem; }
  .wx-temp { font-size: 1.1rem; }
}
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv { width: 100%; border-collapse: collapse; }
.kv th { text-align: left; font-weight: normal; color: var(--muted); padding: 6px 0; }
.kv td { text-align: right; padding: 6px 0; font-variant-numeric: tabular-nums; }
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; }
.line { fill: none; stroke-width: 2.2; stroke-linejoin: round; }
.line.solar { stroke: var(--solar); } .line.load { stroke: var(--load); }
.line.batt { stroke: var(--batt); } .line.soc { stroke: var(--soc); stroke-dasharray: 4 4; }
.axis { fill: var(--muted); font-size: 12px; }
.chart text { fill: var(--muted); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); }
.sw { display: inline-block; width: 12px; height: 3px; margin-right: 6px; vertical-align: middle; }
.sw.solar { background: var(--solar); } .sw.load { background: var(--load); }
.sw.batt { background: var(--batt); } .sw.soc { background: var(--soc); }
.table-wrap { overflow-x: auto; padding: 0; }
.role { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; background: var(--line); }
.role.admin { background: #dbe9ff; color: #1f4fa0; }
.role.client { background: #dafbe1; color: var(--ok); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.actions { white-space: nowrap; text-align: right; }
.actions button { margin-left: 6px; padding: 6px 10px; }
.checks { display: grid; gap: 6px; max-height: 260px; overflow: auto; padding: 4px; }
.check { display: flex; align-items: center; gap: 8px; margin: 0; }
.check input { width: auto; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 12px 0; }
dialog { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 12px; width: min(480px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog form { padding: 16px; }
.brand { display: flex; align-items: center; min-height: 36px; }
.logo { height: 36px; width: auto; }
.flow-card svg { width: 100%; height: auto; display: block; color: var(--text); }
.flow-card .node { fill: var(--bg); stroke: var(--line); stroke-width: 1.5; }
.flow-card .label { fill: var(--muted); font-size: 13px; }
.flow-card .value { fill: var(--text); font-size: 15px; font-weight: 600; }
.flow-card .link { fill: none; stroke: var(--line); stroke-width: 3; stroke-linecap: round; }
/* Living icons: the sun turns slowly, the battery level moves with the charge direction,
   and the inverter's signal wave keeps moving. */
.sun { transform-box: fill-box; transform-origin: center; animation: sun-spin 24s linear infinite; }
@keyframes sun-spin { to { transform: rotate(360deg); } }
.batt-fill.charging { animation: batt-charge 1.6s ease-in-out infinite; }
.batt-fill.discharging { animation: batt-charge 1.6s ease-in-out infinite reverse; }
@keyframes batt-charge { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
.wave { stroke-dasharray: 6 4; animation: wave-run 1.2s linear infinite; }
@keyframes wave-run { to { stroke-dashoffset: -20; } }
@media (prefers-reduced-motion: reduce) {
  .sun, .batt-fill, .wave { animation: none; }
}

/* Active connections carry bright pulses of light that travel along the cable, so the
   direction of the energy is visible. A reversed link sends the pulses the other way. */
.flow-card .link { stroke-width: 4; }
.flow-card .link.active {
  stroke: #ffe14d;
  stroke-width: 6;
  stroke-dasharray: 34 110;
  animation: pulse-travel 1s linear infinite;
  filter: drop-shadow(0 0 4px #ffc400) drop-shadow(0 0 10px rgba(255, 196, 0, 0.95));
}
.flow-card .link.active.reverse { animation-direction: reverse; }
@keyframes pulse-travel { to { stroke-dashoffset: -144; } }
@media (prefers-reduced-motion: reduce) { .flow-card .link.active { animation: none; } }
.flow-card .chev { display: none; }
@media (prefers-reduced-motion: reduce) { .flow-card .link.active { animation: none; } }
.flow-summary { margin: 4px 0 14px; padding: 12px 14px; border-radius: 10px; background: var(--bg); font-size: 1.02rem; line-height: 1.45; color: var(--text); }
.flow-card .chev path { fill: none; stroke: var(--line); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
/* The chevrons slide along their link. Each group is already rotated to the flow direction,
   so moving along the local x axis follows the energy, forwards or backwards. */
.flow-card .chev.active path { stroke: var(--solar); animation: chev-move 1.1s linear infinite; }
@keyframes chev-move {
  0% { transform: translateX(-12px); opacity: 0.2; }
  50% { opacity: 1; }
  100% { transform: translateX(12px); opacity: 0.2; }
}
@media (prefers-reduced-motion: reduce) { .flow-card .chev.active path { animation: none; } }
@media (max-width: 600px) {
  .top { padding: 10px 12px; }
  .kpi strong { font-size: 1.4rem; }
}
