/* Shared design tokens/components for index.html and insights.html. */

:root {
  color-scheme: light dark;
  --surface-1: #131a22;
  --page-plane: #0b0f14;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255,255,255,0.10);
  --series-1: #3987e5; /* uptime */
  --series-2: #199e70; /* rssi */
  --phase-r: #e5484d; /* L1 / R phase - matches red wiring on the meter */
  --phase-y: #e5b93f; /* L2 / Y phase - matches yellow wiring on the meter */
  --phase-b: #4ba3e5; /* L3 / B phase - matches blue wiring on the meter */
  --series-power: #9a6fe0;
  --series-pf: #199e70;
  --series-max-demand: #c98500;
  --series-charger-1: #2fb8c4;
  --series-charger-2: #e0913f;
  --series-charger-3: #d64ba0;
  --series-charger-4: #5b7fd6;
  --series-charger-5: #4fae5a;
  --series-charger-6: #c9a227;
  --series-charger-7: #8a5fd6;
  --status-good: #0ca30c;
  --status-warn: #c98500;
  --status-critical: #d03b3b;
}
@media (prefers-color-scheme: light) {
  :root {
    --surface-1: #ffffff;
    --page-plane: #f9f9f7;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    /* Darker than the dark-theme value (#898781) - that value is ~4.9:1 on
       the dark surface but only ~3.6:1 on white, under the 4.5:1 AA
       minimum for normal-size text like the tile labels. */
    --text-muted: #6e6d66;
    --gridline: #e1e0d9;
    --baseline: #c3c2b7;
    --border: rgba(11,11,11,0.10);
    --series-1: #2a78d6;
    --series-2: #1baf7a;
    --phase-r: #c73338;
    --phase-y: #b5860a;
    --phase-b: #2a78d6;
    --series-power: #7d4fc9;
    --series-pf: #1baf7a;
    --series-max-demand: #b5760a;
    --series-charger-1: #1c8e98;
    --series-charger-2: #b5701f;
    --series-charger-3: #a83a83;
    --series-charger-4: #3f5fb0;
    --series-charger-5: #2f8a3a;
    --series-charger-6: #a3830f;
    --series-charger-7: #6a3fb5;
    --status-good: #0ca30c;
    --status-warn: #b5760a;
    --status-critical: #d03b3b;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  padding: 24px 16px 60px;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.wrap { max-width: 1920px; margin: 0 auto; }
h1 { font-size: 1.4rem; margin: 0 0 4px; }
.subtitle { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 20px; }
h2 { font-size: 0.95rem; font-weight: 600; margin: 32px 0 12px; color: var(--text-primary); }
h2:first-of-type { margin-top: 24px; }
/* Long single-page dashboards (insights.html) get a divider + jump-anchor
   offset per section - index.html has no #content wrapper, so unaffected. */
#content h2 { padding-top: 18px; border-top: 1px solid var(--border); scroll-margin-top: 64px; }
#content h2:first-of-type { border-top: none; padding-top: 0; }

.nav-links { margin-bottom: 4px; }
.nav-links a { color: var(--series-1); text-decoration: none; font-size: 0.85rem; }
.nav-links a:hover { text-decoration: underline; }

.notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--status-warn) 10%, var(--surface-1));
  color: var(--text-secondary);
  font-size: 0.82rem;
  margin-bottom: 8px;
}
.notice-icon { flex-shrink: 0; opacity: 0.75; line-height: 1.4; }

/* Sticky section nav + range controls - keeps long analytics pages (like
   insights.html) navigable without scrolling back to the top. */
.insights-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 0 -16px 20px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--page-plane) 92%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.quick-nav { display: flex; gap: 4px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.quick-nav::-webkit-scrollbar { display: none; }
.quick-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.8rem;
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.quick-nav a:hover { color: var(--text-primary); background: var(--surface-1); }

.status-tile { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 0.9rem; }
.status-banner-item { display: flex; align-items: center; gap: 10px; }
.status-banner-sep { color: var(--text-muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.dot.ok { background: var(--status-good); }
.dot.bad { background: var(--status-critical); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.tile .label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.tile .value { font-size: 1.35rem; font-weight: 600; margin-top: 4px; color: var(--text-primary); }
.tile .value.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.05rem; }
/* For descriptive/string stats (e.g. "6 PM - 9 PM (~3h)") rather than a
   single number - same tile, less visual weight so numeric KPIs still lead. */
.tile .value.text-value { font-size: 1.05rem; font-weight: 500; }
.tile .unit { font-size: 0.85rem; color: var(--text-secondary); font-weight: 400; }
.tile .label .label-hint { font-weight: 400; color: var(--text-muted); font-size: 0.75rem; text-transform: none; letter-spacing: normal; }

.grid.phase-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-bottom: 12px; }
.phase-tile { border-left-width: 3px; border-left-style: solid; }
.phase-tile-header { font-size: 0.78rem; font-weight: 600; color: var(--text-secondary); letter-spacing: 0.03em; display: flex; align-items: center; gap: 7px; margin-bottom: 10px; }
.phase-tile-header .dot { width: 8px; height: 8px; }
.phase-metrics { display: flex; }
.phase-metric { flex: 1; }
.phase-metric + .phase-metric { margin-left: 14px; padding-left: 14px; border-left: 1px solid var(--border); }

.signal-bars { display: flex; align-items: flex-end; gap: 2px; height: 16px; margin-top: 6px; }
.signal-bars .bar { width: 5px; background: var(--baseline); border-radius: 1px; }
.signal-bars .bar.filled { background: var(--status-good); }
.signal-bars .bar:nth-child(1) { height: 30%; }
.signal-bars .bar:nth-child(2) { height: 55%; }
.signal-bars .bar:nth-child(3) { height: 75%; }
.signal-bars .bar:nth-child(4) { height: 100%; }

.range-row { display: flex; gap: 6px; margin-bottom: 4px; flex-wrap: wrap; }
.range-btn {
  font: inherit;
  font-size: 0.82rem;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
}
.range-btn:hover:not(.active) { color: var(--text-primary); border-color: var(--text-muted); }
.range-btn.active { color: var(--text-primary); border-color: var(--series-1); background: color-mix(in srgb, var(--series-1) 14%, var(--surface-1)); }

.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
  transition: border-color 0.15s ease;
}
.chart-card:hover { border-color: color-mix(in srgb, var(--text-muted) 50%, var(--border)); }
.chart-card .chart-title { font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; }
.chart-card .chart-subtitle { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 10px; }
/* All small-multiple charts (Trends line charts, Insights bar charts) share
   one uniform grid (same card size, 2-up) so they're easy to scan side by
   side instead of scattered cards of varying width. */
.charts-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-bottom: 16px; }
@media (max-width: 640px) { .charts-grid { grid-template-columns: 1fr; } }
.charts-grid .chart-card { margin-bottom: 0; }
/* Charger count varies (1-3) - on wide screens let them share one row
   instead of leaving a single card stranded alone on a second row. */
@media (min-width: 1400px) { #chargerChartsGrid { grid-template-columns: repeat(3, 1fr); } }

.chart-container { position: relative; }
.chart-svg { display: block; overflow: visible; }
.chart-gridline { stroke: var(--gridline); stroke-width: 1; }
.chart-axis-label { fill: var(--text-muted); font-size: 10px; }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-reset-marker { stroke: var(--status-critical); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.7; }
.chart-end-ring { fill: var(--surface-1); }
.chart-crosshair { stroke: var(--baseline); stroke-width: 1; }
.chart-empty { color: var(--text-muted); font-size: 0.85rem; text-align: center; padding: 40px 0; }

.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; }
.chart-legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--text-secondary); }
.chart-legend-key { width: 14px; height: 2px; border-radius: 1px; }
.chart-legend-key.dashed { border-top: 1px dashed var(--status-critical); background: none; height: 0; }

.chart-tooltip {
  position: absolute;
  top: 4px;
  background: var(--page-plane);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.78rem;
  pointer-events: none;
  min-width: 120px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.chart-tooltip-time { color: var(--text-muted); font-size: 0.72rem; margin-bottom: 4px; }
.chart-tooltip-row { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.chart-tooltip-key { width: 10px; height: 2px; border-radius: 1px; flex-shrink: 0; }
.chart-tooltip-value { font-weight: 600; color: var(--text-primary); }
.chart-tooltip-label { color: var(--text-secondary); }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.data-table th, .data-table td {
  text-align: right;
  padding: 6px 10px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--border);
}
.data-table th { color: var(--text-muted); font-weight: 500; text-transform: uppercase; font-size: 0.68rem; }
.data-table td:first-child, .data-table th:first-child { text-align: left; }
.data-table td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.data-table td.reset-row { color: var(--status-critical); }

.meta {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.8rem;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 480px) {
  body { padding: 16px 12px 40px; }
  h1 { font-size: 1.2rem; }
  .subtitle { font-size: 0.82rem; margin-bottom: 16px; }
  h2 { font-size: 0.88rem; margin: 24px 0 10px; }
  .grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
  .tile { padding: 11px 12px; }
  .tile .value { font-size: 1.15rem; }
  .status-tile { font-size: 0.84rem; }
  .chart-card { padding: 12px; margin-bottom: 12px; }
  .chart-card .chart-title { font-size: 0.8rem; }
  .range-btn { padding: 6px 10px; font-size: 0.78rem; }
  .data-table { font-size: 0.7rem; }
  .data-table th, .data-table td { padding: 5px 7px; }
  .insights-toolbar { margin: 0 -12px 16px; padding: 8px 12px; }
  .tile .value.text-value { font-size: 0.92rem; }
}
