:root {
  color-scheme: light;
  font-family: "Inter", "Segoe UI", sans-serif;
  color: #192e3b;
  background: #eff2f3;
  font-synthesis: none;
  --ink: #192e3b;
  --muted: #4e6573;
  --navy: #152b39;
  --line: #dce5e8;
  --mono: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 280px; }
h1, h2, h3, h4, p, dd { margin: 0; }
button { font: inherit; }
[hidden] { display: none !important; }

.shell {
  width: min(100% - 80px, 1320px);
  margin-inline: auto;
}

.topbar {
  background: white;
  border-bottom: 1px solid #e1e8ea;
}

.topbar-inner {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  color: var(--navy);
  font-size: 1.075rem;
  font-weight: 700;
  letter-spacing: -0.035em;
  white-space: nowrap;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin-right: 6px;
  color: #dcf995;
  background: var(--navy);
  border-radius: 8px;
  font-size: 1.375rem;
  line-height: 1;
}

.brand-accent { color: #476473; }
.topbar-actions { display: flex; gap: 5px 14px; flex-wrap: wrap; justify-content: end; }

.disconnect {
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: .8125rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.disconnect:disabled { opacity: .6; cursor: progress; }

.settings-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 42px;
  padding: 8px;
  border: 1px solid #d2dde2;
  border-radius: 8px;
  background: white;
  color: var(--ink);
  cursor: pointer;
}
.settings-button svg { display: block; pointer-events: none; }
.settings-button:hover { background: #edf4f6; }
.settings-button:disabled { opacity: .6; cursor: progress; }

.refresh {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  min-height: 42px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid #d2dde2;
  background: white;
  color: var(--ink);
  cursor: pointer;
  font-size: .875rem;
  font-weight: 650;
}

.refresh:hover { background: #edf4f6; }
.refresh[aria-disabled="true"] { color: var(--muted); cursor: progress; }
.refresh-icon { display: inline-block; font-size: 1.25rem; line-height: 1; }
.refresh[aria-busy="true"] .refresh-icon { animation: rotate 1s linear infinite; }
@keyframes rotate { to { transform: rotate(360deg); } }
:focus-visible { outline: 3px solid #267bbc; outline-offset: 4px; }

.overview {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: clamp(22px, 5vw, 70px);
  margin-block: 32px 29px;
  min-height: 162px;
  padding: clamp(24px, 3.4vw, 50px);
  border: 1px solid #203d4d;
  border-radius: 18px;
  color: #f3f8f9;
  background: linear-gradient(108deg, #152b39 25%, #1d3e4f 76%, #243f46);
}

.overview::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 0 0 30%;
  opacity: .26;
  background-image: linear-gradient(90deg, #5c7f8e 1px, transparent 1px), linear-gradient(#5c7f8e 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(to left, #000, transparent 98%);
}

.overview h1 {
  margin: 0 0 9px -2px;
  font-size: clamp(2rem, 4.1vw, 3.8rem);
  letter-spacing: -.06em;
  line-height: 1;
  font-weight: 680;
}

.overview-title p { color: #c3d6de; font-size: 1rem; }

.overview-stats {
  display: flex;
  gap: 24px;
  margin: 0;
  flex-shrink: 0;
}

.overview-stat {
  min-width: 117px;
  padding: 2px 0 2px 17px;
  border-left: 1px solid #6c919e;
}

.overview-stat dt { color: #d0e0e5; font-size: .8125rem; }
.overview-stat dd { margin-top: 5px; color: #defb97; font: 650 2.1rem/1.25 var(--mono); letter-spacing: -.08em; }
.overview-unit { color: #b4cad2; font-size: .875rem; letter-spacing: normal; }
#active-alarms.attention { color: #ffba9d; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px 18px;
  flex-wrap: wrap;
  margin-bottom: 15px;
}

.section-head h2 { font-size: 1.25rem; font-weight: 700; letter-spacing: -.035em; }
.section-head p, .page-footer { color: var(--muted); font-size: .8125rem; }

.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 1px 10px;
  padding: 10px 13px;
  margin-bottom: 14px;
  border: 1px solid #ebd1a5;
  border-radius: 8px;
  background: #fcf5e7;
  color: #674817;
  font-size: .875rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.setup-notice { align-items: center; justify-content: space-between; gap: 7px 14px; }
.setup-notice strong { margin-right: 5px; }
.connect {
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--navy);
  color: white;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 650;
}
.connect:hover { background: #254757; }
.connect:disabled { opacity: .7; cursor: progress; }

.connect-dialog {
  width: min(100% - 38px, 500px);
  max-height: min(100dvh - 38px, 700px);
  overflow: auto;
  padding: clamp(17px, 3.3vw, 28px);
  border: 1px solid #d8e2e5;
  border-radius: 14px;
  background: white;
  color: var(--ink);
  box-shadow: 0 12px 42px #10263155;
}
.connect-dialog::backdrop { background: #10263199; }
.settings-dialog .disconnect {
  display: block;
  min-height: 44px;
  margin-top: 16px;
  padding: 8px 14px;
  border: 1px solid #b75b48;
  border-radius: 7px;
  color: #8b3425;
  text-decoration: none;
}
.settings-dialog .disconnect:hover { background: #fceee9; }
.connect-dialog form { display: grid; gap: 8px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dialog-head h2 { font-size: 1.375rem; letter-spacing: -.04em; }
.close-dialog {
  width: 42px;
  height: 42px;
  border: 1px solid #d2dde2;
  border-radius: 7px;
  background: white;
  color: var(--ink);
  font-size: 1.5rem;
  cursor: pointer;
}
.close-dialog:hover { background: #edf4f6; }
.connect-dialog p, .connect-dialog label { font-size: .875rem; line-height: 1.5; }
.connect-dialog a { width: fit-content; color: #195982; font-size: .875rem; text-underline-offset: 3px; }
.connect-dialog label { margin-top: 8px; font-weight: 650; }
.connect-dialog label span, #vrm-ids-help { color: var(--muted); font-weight: 400; }
.connect-dialog input {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  color: var(--ink);
  border: 1px solid #8fa4ae;
  border-radius: 6px;
  font: inherit;
}
.connect-dialog .connect { justify-self: start; margin-top: 8px; }
.connect-error {
  padding: 8px 10px;
  border-radius: 6px;
  color: #813726;
  background: #fceee9;
  overflow-wrap: anywhere;
}

.site-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(12px, 1.7vw, 24px);
}

.site-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  container: site / inline-size;
  background: white;
  border: 1px solid #d8e2e5;
  border-radius: 14px;
  box-shadow: 0 2px 4px #152b3908;
  overflow: hidden;
  --card-padding: clamp(12px, 1.7vw, 24px);
}

.site-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 7px 10px;
  padding: var(--card-padding) var(--card-padding) 0;
  min-height: 58px;
}

.site-name {
  max-width: 100%;
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -.025em;
  overflow-wrap: anywhere;
}

.site-state {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  border-radius: 50px;
  padding: 5px 8px;
  background: #edf1f3;
  color: #4a5f6b;
  font-size: .6875rem;
  font-weight: 660;
  line-height: 1.125;
}

.site-state::before { content: ""; width: 6px; height: 6px; background: currentColor; border-radius: 50%; }
.site-card[data-state="recent"] .site-state { color: #23624d; background: #e4f3e7; }
.site-card[data-state="stale"] .site-state { color: #774b16; background: #f8eedb; }
.site-card[data-state="error"] .site-state { color: #85402f; background: #fceee9; }

.battery-section {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px clamp(12px, 2vw, 25px);
  padding: 19px var(--card-padding) 16px;
}

.battery-trend { grid-column: 1 / -1; }

.battery-gauge {
  --soc: 0%;
  --gauge-color: #2b8a70;
  position: relative;
  flex: none;
  width: clamp(56px, 7vw, 86px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(closest-side, white 75%, transparent 77%), conic-gradient(var(--gauge-color) 0 var(--soc), #e8eff0 0);
}

.battery-gauge[data-low="true"] { --gauge-color: #c2622c; }
.battery-gauge::before {
  content: "";
  width: 30%;
  height: 18%;
  border: 1.5px solid #42636f;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--gauge-color) min(100%, var(--soc)), #e8eff0 0) center / 90% 69% no-repeat;
}
.battery-gauge::after {
  content: "";
  position: absolute;
  inset-inline-start: 65%;
  width: 2px;
  height: 8%;
  background: #42636f;
  border-radius: 0 1px 1px 0;
}

.metric-label { display: block; color: var(--muted); font-size: .8125rem; font-weight: 600; }
.metric-number {
  color: var(--navy);
  margin-top: 2px;
  font: 680 clamp(2.25rem, 3.65vw, 3.4rem)/1.08 var(--mono);
  letter-spacing: -.09em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.soc-unit { margin-left: 5px; font-size: .47em; letter-spacing: 0; color: var(--muted); }

.power-section {
  display: flex;
  align-items: end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin: 0 var(--card-padding);
  padding: 14px 0;
  border-block: 1px solid var(--line);
}

.power-reading { margin-top: 4px; font: 650 clamp(1.05rem, 1.6vw, 1.3rem)/1.25 var(--mono); letter-spacing: -.055em; white-space: nowrap; }
.power-unit { color: var(--muted); font-size: .7em; }
.power-estimate { color: var(--muted); font: 500 .6875rem/1.2 "Inter", "Segoe UI", sans-serif; letter-spacing: normal; }
.direction-label {
  padding: 4px 7px;
  border-radius: 5px;
  background: #edf1f3;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 640;
  white-space: nowrap;
}
.direction[data-direction="charge"] .direction-label { color: #23624d; background: #e6f4e8; }
.direction[data-direction="discharge"] .direction-label { color: #665121; background: #f6f0e1; }

.energy-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0 var(--card-padding);
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.energy-metric {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid #e2eaee;
  border-radius: 8px;
  background: #f7fafb;
}

.energy-reading {
  margin-top: 4px;
  color: var(--navy);
  font: 650 clamp(.96875rem, 1.45vw, 1.2rem)/1.25 var(--mono);
  letter-spacing: -.045em;
  overflow-wrap: anywhere;
}

.inverter-state {
  margin-top: 4px;
  color: #195982;
  font-size: .875rem;
  font-weight: 650;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.energy-direction { margin-top: 3px; color: var(--muted); font-size: .6875rem; line-height: 1.25; }
.net-metric[data-direction="import"] .energy-direction { color: #913c26; }
.net-metric[data-direction="export"] .energy-direction { color: #23624d; }

.trend { min-width: 0; height: 23px; }
.energy-metric .trend { margin-top: auto; height: 27px; padding-top: 4px; }
.trend canvas { display: block; width: 100%; height: 100%; }
.trend-placeholder { font-size: .6875rem; line-height: 23px; color: var(--muted); }

@container site (max-width: 245px) {
  .energy-grid { gap: 5px; }
  .energy-metric { padding-inline: 5px; }
  .energy-reading { font-size: .875rem; }
  .energy-metric .metric-label, .inverter-state { overflow-wrap: anywhere; }
}

.alarms-section { flex-grow: 1; padding: 14px var(--card-padding) 17px; min-height: 92px; }
.alarms-state, .alarms-list, .site-issue {
  margin: 7px 0 0;
  color: #425b68;
  font-size: .875rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.alarms-list { padding-inline-start: 16px; color: #913c26; }
.alarms-list li + li { margin-top: 4px; }
.alarms-section[data-has-alarms="true"] .alarms-state { color: #913c26; font-weight: 650; }
.site-issue { color: #85402f; font-size: .75rem; }

.site-footer {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 3px 14px;
  padding: 12px var(--card-padding);
  border-top: 1px solid #e5ecee;
  background: #f8fafb;
  color: var(--muted);
  font-size: .75rem;
  line-height: 1.4;
}
.site-link { color: #195982; text-decoration-thickness: 1px; text-underline-offset: 3px; font-weight: 630; }
.site-link:hover { color: #103d59; }

.page-footer {
  display: flex;
  justify-content: space-between;
  gap: 6px 15px;
  flex-wrap: wrap;
  padding-block: 19px 24px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-width: 1000px) {
  .shell { width: calc(100% - 48px); }
  .site-header { flex-wrap: wrap; }
}

@media (max-width: 700px) {
  .shell { width: calc(100% - 30px); }
  .topbar-inner { min-height: 58px; }
  .overview { align-items: start; flex-direction: column; margin-block: 21px; }
  .overview-stats { flex-wrap: wrap; }
  .site-grid { gap: 10px; }
  .site-card { --card-padding: 12px; }
  .battery-gauge { width: 40px; }
  .battery-section { column-gap: 8px; }
  .metric-label { font-size: .75rem; }
}

@media (max-width: 555px) {
  .site-grid { grid-template-columns: minmax(0, 1fr); }
  .site-card { --card-padding: 18px; }
  .battery-gauge { width: 68px; }
  .site-header { min-height: initial; }
  .battery-section { column-gap: 19px; }
}

@media (min-width: 701px) and (max-height: 900px) {
  .topbar-inner { min-height: 58px; }
  .overview { min-height: initial; margin-block: 16px 17px; padding: 16px clamp(24px, 3.4vw, 42px); }
  .overview h1 { font-size: clamp(2rem, 4vw, 3.2rem); margin-bottom: 6px; }
  .overview-stat dd { font-size: 1.75rem; }
  .section-head { margin-bottom: 10px; }
  .site-header { min-height: 46px; padding-top: 12px; }
  .battery-section { padding-block: 8px 12px; }
  .battery-gauge { width: clamp(40px, 4.5vw, 60px); }
  .power-section { padding-block: 10px; }
  .energy-grid { padding-block: 9px; }
  .energy-metric { padding-block: 6px; }
  .alarms-section { padding-block: 10px 11px; min-height: 66px; }
  .site-footer { padding-block: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  .refresh[aria-busy="true"] .refresh-icon { animation: none; }
}
