/* Deliberately dark-only: the dark steps of the reference dataviz palette,
   validated against the #1a1a19 chart surface. */
:root {
  color-scheme: dark;

  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.1);

  --series-import: #3987e5; /* blue    — grid import */
  --series-export: #d95926; /* orange  — grid export */
  --series-grid: #199e70;   /* aqua    — grid net */
  --series-tank: #c98500;   /* yellow  — tank PV */
  --series-pv: #d55181;     /* magenta — PV generation */
  --series-load: #008300;   /* green   — house load */
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.page-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--text-secondary);
}

/* Daily summary tiles */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tile-label {
  color: var(--text-secondary);
  font-size: 12px;
}

.tile-value {
  color: var(--text-primary);
  font-size: 24px;
  font-weight: 650;
}

.tile-value .unit {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  margin-left: 2px;
}

.tariff-note {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
}

/* Live flow diagram */
.flow-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 16px 4px;
  margin-top: 12px;
}

.flow-card svg {
  display: block;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  font-family: inherit;
}

.flow-card .icon path,
.flow-card .icon circle {
  fill: none;
  stroke: var(--text-secondary);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.node-label {
  fill: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  text-anchor: middle;
  stroke: none;
}

.flow-value {
  fill: var(--text-primary);
  font-size: 16px;
  font-weight: 650;
  text-anchor: middle;
}

.flow-dir {
  fill: var(--text-muted);
  font-size: 12px;
  text-anchor: middle;
}

.edge {
  fill: none;
  stroke: var(--gridline);
  stroke-width: 2.5;
  stroke-dasharray: 7 7;
}

.edge.flow-forward {
  animation: flow-dash 0.8s linear infinite;
}

.edge.flow-reverse {
  animation: flow-dash 0.8s linear infinite reverse;
}

@keyframes flow-dash {
  to {
    stroke-dashoffset: -14;
  }
}

#edge-pv.flow-forward {
  stroke: var(--series-pv);
}

#edge-grid.importing {
  stroke: var(--series-import);
}

#edge-grid.exporting {
  stroke: var(--series-export);
}

.flow-updated {
  margin: 4px 0 8px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}

/* Controls — one row above the chart */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
  margin: 16px 0 12px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-1);
  padding: 2px;
  gap: 2px;
}

.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.segmented button:hover {
  color: var(--text-primary);
}

.segmented button[aria-pressed="true"] {
  background: color-mix(in srgb, var(--text-primary) 8%, transparent);
  color: var(--text-primary);
  font-weight: 600;
}

.segmented button:focus-visible {
  outline: 2px solid var(--series-import);
  outline-offset: 1px;
}

.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.chart-wrap {
  position: relative;
  height: 360px;
  transition: opacity 120ms ease;
}

/* Refetch keeps the frame: previous render dims while new data loads */
.chart-wrap.loading {
  opacity: 0.45;
}

.status {
  margin: 8px 0 0;
  color: var(--text-muted);
}

.status.error {
  color: #d03b3b;
}

.table-view {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-1);
}

.table-view summary {
  cursor: pointer;
  padding: 10px 16px;
  color: var(--text-secondary);
  font-weight: 600;
}

.table-scroll {
  overflow-x: auto;
  padding: 0 16px 16px;
}

.table-view table {
  border-collapse: collapse;
  width: 100%;
  font-variant-numeric: tabular-nums;
}

.table-view th,
.table-view td {
  text-align: right;
  padding: 4px 12px;
  border-top: 1px solid var(--gridline);
  white-space: nowrap;
}

.table-view th:first-child,
.table-view td:first-child {
  text-align: left;
  padding-left: 0;
}

.table-view thead th {
  border-top: 0;
  color: var(--text-secondary);
  font-weight: 600;
}
