:root {
  --bg: #e5e9e6;
  --ink: #202722;
  --soft: #59645d;
  --faint: #5f6962;
  --accent: #2f6b55;
  --accent-strong: #255743;
  --accent-soft: #cfddd5;
  --warning: #925a1b;
  --warning-soft: #eadcc6;
  --critical: #963f39;
  --critical-soft: #ead3d0;
  --shadow-dark: #c3c9c4;
  --shadow-light: #ffffff;
  --shadow: 10px 10px 24px var(--shadow-dark), -10px -10px 24px var(--shadow-light);
  --shadow-sm: 5px 5px 12px var(--shadow-dark), -5px -5px 12px var(--shadow-light);
  --inset: inset 4px 4px 9px var(--shadow-dark), inset -4px -4px 9px var(--shadow-light);
  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
  --mono: "SFMono-Regular", "Cascadia Code", "Roboto Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  font-size: 16px;
  line-height: 1.5;
}

a { color: inherit; }
button { font: inherit; }
a, button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

a:focus-visible,
button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 100;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  transform: translateY(-180%);
}

.skip-link:focus { transform: translateY(0); }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  min-height: 70px;
  align-items: center;
  padding: 0 clamp(18px, 4vw, 56px);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  box-shadow: 0 9px 22px color-mix(in srgb, var(--shadow-dark) 70%, transparent);
  backdrop-filter: blur(15px);
}

.brand {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 11px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .08em;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

.brand svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.main-nav {
  display: flex;
  gap: 4px;
  padding: 5px;
  border-radius: 15px;
  box-shadow: var(--inset);
}

.main-nav a {
  display: grid;
  min-width: 72px;
  min-height: 44px;
  place-items: center;
  border-radius: 11px;
  color: var(--soft);
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
  transition: color 180ms ease, background 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.main-nav a:hover { color: var(--ink); }

.main-nav a.active {
  background: var(--bg);
  box-shadow: var(--shadow-sm);
  color: var(--accent-strong);
}

.main-nav a:active { transform: scale(.98); }

.connection-state {
  display: flex;
  justify-self: end;
  align-items: center;
  gap: 9px;
  color: var(--soft);
  font-size: 12px;
  font-weight: 650;
}

.state-dot,
.status-indicator {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--critical);
  box-shadow: 0 0 0 5px var(--critical-soft);
}

.connection-state.ok .state-dot,
.status-panel.ok .status-indicator {
  background: var(--accent);
  box-shadow: 0 0 0 5px var(--accent-soft);
}

.connection-state.warning .state-dot,
.status-panel.warning .status-indicator {
  background: var(--warning);
  box-shadow: 0 0 0 5px var(--warning-soft);
}

.page-shell {
  width: min(calc(100% - 40px), 1280px);
  margin: 0 auto;
  padding: clamp(38px, 5vw, 64px) 0 28px;
}

.page-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
  padding-inline: 3px;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 5px;
  font-size: clamp(31px, 4vw, 48px);
  font-weight: 680;
  letter-spacing: -.045em;
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  font-weight: 680;
  letter-spacing: -.02em;
}

.page-head p,
.page-head time {
  margin-bottom: 0;
  color: var(--soft);
  font-family: var(--mono);
  font-size: 11px;
}

.status-panel,
.chart-panel,
.compact-panel,
.events-panel {
  border: 1px solid color-mix(in srgb, var(--shadow-light) 58%, transparent);
  border-radius: 24px;
  background: var(--bg);
  box-shadow: var(--shadow);
}

.status-panel,
.chart-panel,
.compact-panel,
.events-panel {
  padding: clamp(20px, 2.6vw, 30px);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.status-chip,
.tag {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 11px;
  padding: 0 13px;
  border-radius: 11px;
  box-shadow: var(--inset);
  color: var(--soft);
  font-size: 11px;
  font-weight: 650;
}

.tag-ok { color: var(--accent-strong); }
.tag-warning { color: var(--warning); }
.tag-critical { color: var(--critical); }

.status-grid {
  display: grid;
  grid-template-columns: 1.15fr .9fr .9fr;
  gap: 18px;
  margin: 22px 0;
}

.status-primary,
.readout {
  display: flex;
  min-height: 142px;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
  border-radius: 18px;
  box-shadow: var(--inset);
}

.status-primary > strong {
  font-family: var(--mono);
  font-size: clamp(43px, 5vw, 68px);
  font-weight: 670;
  letter-spacing: -.07em;
  line-height: .95;
}

.status-primary > span,
.readout > span {
  color: var(--soft);
  font-size: 12px;
  font-weight: 600;
}

.readout p,
.metric p {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 0;
}

.readout p strong {
  font-family: var(--mono);
  font-size: clamp(38px, 4vw, 54px);
  font-weight: 560;
  letter-spacing: -.06em;
  line-height: 1;
}

.readout small,
.metric small {
  color: var(--soft);
  font-family: var(--mono);
  font-size: 11px;
}

.power-path {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  gap: 13px;
  align-items: center;
  padding: 14px 18px;
  border-radius: 16px;
  box-shadow: var(--inset);
}

.power-path div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.power-path span { color: var(--soft); font-size: 11px; }
.power-path > span { color: var(--accent); }
.power-path strong { font-family: var(--mono); font-size: 12px; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-top: 26px;
}

.metric {
  min-width: 0;
  min-height: 116px;
  padding: 19px;
  border-radius: 17px;
  box-shadow: var(--shadow-sm);
}

.metric > span { color: var(--soft); font-size: 12px; font-weight: 600; }
.metric p { margin-top: 22px; }

.metric p strong {
  font-family: var(--mono);
  font-size: clamp(29px, 3vw, 40px);
  font-weight: 560;
  letter-spacing: -.055em;
  line-height: 1;
}

.content-grid {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1.8fr) minmax(300px, .8fr);
  gap: 24px;
  align-items: start;
  margin-top: 34px;
}

.side-stack {
  display: grid;
  min-width: 0;
  gap: 24px;
}

.chart-panel,
.compact-panel {
  min-width: 0;
}

.segmented {
  display: flex;
  gap: 3px;
  padding: 4px;
  border-radius: 13px;
  box-shadow: var(--inset);
}

.segmented button,
.legend {
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--soft);
  cursor: pointer;
  font-size: 11px;
  transition: color 180ms ease, background 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.segmented button {
  min-width: 68px;
  padding: 0 11px;
}

.segmented button.active {
  background: var(--accent);
  box-shadow: 3px 3px 7px var(--shadow-dark), -3px -3px 7px var(--shadow-light);
  color: #fff;
}

.segmented button:active,
.legend:active { transform: scale(.97); }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 20px 0 13px;
}

.legend {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  opacity: .55;
}

.legend.active { box-shadow: var(--inset); opacity: 1; }

.line { width: 18px; border-top: 2px solid; }
.line.charge { color: var(--accent); }
.line.load { color: var(--warning); border-top-style: dashed; }
.line.voltage { color: #4b6477; border-top-style: dotted; }

.chart-wrap {
  position: relative;
  min-height: 280px;
  overflow-x: auto;
  padding: 8px 10px 0;
  border-radius: 17px;
  box-shadow: var(--inset);
}

#history-chart {
  display: block;
  width: 100%;
  min-width: 630px;
  height: auto;
}

.chart-grid line {
  stroke: color-mix(in srgb, var(--faint) 24%, transparent);
  vector-effect: non-scaling-stroke;
}

.chart-labels text {
  fill: var(--faint);
  font-family: var(--mono);
  font-size: 9px;
}

.chart-line {
  fill: none;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.chart-line.charge { stroke: var(--accent); }
.chart-line.load { stroke: var(--warning); stroke-dasharray: 7 5; }
.chart-line.input_voltage { stroke: #4b6477; stroke-dasharray: 2 4; }

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--faint);
  font-size: 12px;
}

.chart-empty[hidden] { display: none; }

.policy-flow {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
  margin: 18px 0 14px;
  padding: 0;
  list-style: none;
}

.policy-flow li {
  display: grid;
  min-height: 60px;
  align-content: space-between;
  padding: 10px 12px;
  border-radius: 12px;
  box-shadow: var(--inset);
}

.policy-flow span { color: var(--faint); font-family: var(--mono); font-size: 10px; }
.policy-flow strong { font-size: 12px; }

.policy-foot {
  display: flex;
  justify-content: space-between;
  padding-top: 13px;
  border-top: 1px solid color-mix(in srgb, var(--faint) 22%, transparent);
  color: var(--soft);
  font-size: 12px;
}

.policy-foot strong { color: var(--accent-strong); }

.source-details {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.source-details p {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  color: var(--soft);
  font-size: 12px;
}

.source-details strong {
  color: var(--ink);
  font-family: var(--mono);
  font-size: 10px;
  text-align: right;
}

.events-panel { margin-top: 34px; }
.standalone-events { margin-top: 0; }

.event-table-wrap {
  margin-top: 20px;
  overflow-x: auto;
  border-radius: 14px;
  box-shadow: var(--inset);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  text-align: left;
}

th {
  padding: 11px 13px;
  border-bottom: 1px solid color-mix(in srgb, var(--faint) 25%, transparent);
  color: var(--soft);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
}

td {
  padding: 12px 13px;
  border-bottom: 1px solid color-mix(in srgb, var(--faint) 15%, transparent);
}

tbody tr:last-child td { border-bottom: 0; }
td:first-child, td:last-child { color: var(--soft); font-family: var(--mono); font-size: 10px; white-space: nowrap; }
td:nth-child(2) { min-width: 180px; }
.empty-cell { height: 82px; color: var(--faint); text-align: center; }

footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 38px;
  padding: 15px 3px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10px;
}

@media (min-width: 921px) {
  .content-grid { align-items: stretch; }
}

@media (max-width: 920px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .content-grid { grid-template-columns: 1fr; }
  .side-stack { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 620px) {
  :root {
    --shadow: 7px 7px 17px var(--shadow-dark), -7px -7px 17px var(--shadow-light);
  }

  .site-header {
    grid-template-columns: 1fr auto;
    min-height: 64px;
    padding: 0 14px;
  }
  .brand > span:last-child { display: none; }
  .brand-mark { width: 44px; height: 44px; }
  .connection-state { display: none; }
  .main-nav { justify-self: end; }
  .main-nav a { min-width: 64px; }

  .page-shell { width: min(calc(100% - 26px), 1280px); padding-top: 35px; }
  .page-head { align-items: start; margin-bottom: 24px; }
  .page-head time { max-width: 105px; text-align: right; }
  h1 { font-size: 31px; }

  .status-panel,
  .chart-panel,
  .compact-panel,
  .events-panel { padding: 18px; border-radius: 21px; }

  .status-chip { max-width: 62%; padding: 0 11px; font-size: 10px; }
  .status-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .status-primary { grid-column: 1 / -1; min-height: 104px; }
  .readout { min-height: 126px; padding: 16px; }
  .readout p strong { font-size: 37px; }

  .power-path { gap: 7px; padding: 13px 11px; }
  .power-path div { display: grid; gap: 2px; }
  .power-path span, .power-path strong { font-size: 9px; }

  .metric-grid { gap: 12px; margin-top: 22px; }
  .metric { min-height: 105px; padding: 16px; }
  .metric p { margin-top: 18px; }
  .metric p strong { font-size: 28px; }

  .content-grid, .events-panel { margin-top: 28px; }
  .standalone-events { margin-top: 0; }
  .side-stack { grid-template-columns: 1fr; }
  .chart-head { align-items: stretch; flex-direction: column; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; min-width: 0; }
  .chart-wrap { min-height: 260px; }

  .event-table-wrap { overflow-x: hidden; }
  th:last-child,
  td:last-child { display: none; }
  td:nth-child(2) { min-width: 0; }
  th:first-child,
  td:first-child { width: 106px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .001ms !important;
    animation-duration: .001ms !important;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d2420;
    --ink: #edf2ee;
    --soft: #b4beb7;
    --faint: #8f9992;
    --accent: #72b294;
    --accent-strong: #8ac6a9;
    --accent-soft: #284236;
    --warning: #d0a05e;
    --warning-soft: #493821;
    --critical: #d48078;
    --critical-soft: #492d2b;
    --shadow-dark: #111713;
    --shadow-light: #2a342e;
  }

  .segmented button.active { color: #142019; }
}
