/* Embeddable widget (/embed/widget). Self-contained: this file and widget.js
 * are all the widget loads, because it runs inside other people's pages.
 * Hand-written, not Tailwind: app.css is ~250 KB and built for /site/.
 *
 * Fills its iframe edge to edge (the host page draws the border). Opened as a
 * page of its own (html.wv-standalone) it sits as a card in the middle.
 * Themes: <html data-theme="light|dark|auto">; auto follows the visitor. */

:root {
  --bg: #ffffff;
  --fg: #0f1f17;
  --muted: #5d7066;
  --faint: #98a89f;
  --line: #e6ece8;
  --well: #f2f6f3;
  --brand: #1f9d55;
  --brand-ink: #157a41;
  --brand-glow: rgba(31, 157, 85, 0.22);
  --ghost: #dfe6e1;
  --up: #d9580b;
  --down: #157a41;
  --solar: #e8a317;
  --heat-0: #f2f6f3;
  --heat-1: #d3eedb;
  --heat-2: #9fd9b0;
  --heat-3: #5cbf7e;
  --heat-4: #279a53;
  --heat-5: #11663a;
  --tip-bg: #0f1f17;
  --tip-fg: #ffffff;
  --page: #eef3f0;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d1511;
  --fg: #e8f1eb;
  --muted: #95a89d;
  --faint: #5f7067;
  --line: #1f2c25;
  --well: #15211b;
  --brand: #3ccf78;
  --brand-ink: #6be39a;
  --brand-glow: rgba(60, 207, 120, 0.25);
  --ghost: #24332b;
  --up: #ff8a3d;
  --down: #6be39a;
  --solar: #f5b83d;
  --heat-0: #15211b;
  --heat-1: #173a26;
  --heat-2: #1d5c36;
  --heat-3: #22874a;
  --heat-4: #33b766;
  --heat-5: #7cf0a6;
  --tip-bg: #e8f1eb;
  --tip-fg: #0d1511;
  --page: #070b09;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0d1511;
    --fg: #e8f1eb;
    --muted: #95a89d;
    --faint: #5f7067;
    --line: #1f2c25;
    --well: #15211b;
    --brand: #3ccf78;
    --brand-ink: #6be39a;
    --brand-glow: rgba(60, 207, 120, 0.25);
    --ghost: #24332b;
    --up: #ff8a3d;
    --down: #6be39a;
    --solar: #f5b83d;
    --heat-0: #15211b;
    --heat-1: #173a26;
    --heat-2: #1d5c36;
    --heat-3: #22874a;
    --heat-4: #33b766;
    --heat-5: #7cf0a6;
    --tip-bg: #e8f1eb;
    --tip-fg: #0d1511;
    --page: #070b09;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

[hidden] { display: none !important; }

.wv {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  position: relative;
}

/* Opened directly (a shared link, not an iframe): a card on a soft page. */
html.wv-standalone body {
  background: var(--page);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
html.wv-standalone .wv {
  width: 100%;
  max-width: 560px;
  height: min(440px, 100%);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(15, 31, 23, 0.04), 0 12px 32px -12px rgba(15, 31, 23, 0.18);
  overflow: hidden;
}

/* --- header ---------------------------------------------------------------- */

.wv-head {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 12px 16px 0;
}

.wv-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 140px;
}

.wv-name {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wv-status {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 8px 0 7px;
  border-radius: 999px;
  background: var(--well);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.wv-status[data-live="1"] { color: var(--brand-ink); }

.wv-pulse {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
}
.wv-status[data-live="1"] .wv-pulse { background: var(--brand); }
.wv-status[data-live="1"] .wv-pulse::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--brand);
  opacity: 0;
  animation: wv-ring 2s ease-out infinite;
}
@keyframes wv-ring {
  0% { transform: scale(0.4); opacity: 0.7; }
  80%, 100% { transform: scale(1.4); opacity: 0; }
}

.wv-tabs {
  flex: none;
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--well);
}
.wv-tabs button {
  appearance: none;
  border: 0;
  margin: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  height: 26px;
  padding: 0 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s, box-shadow 0.15s;
}
.wv-tabs button:hover { color: var(--fg); }
.wv-tabs button[aria-selected="true"] {
  background: var(--bg);
  color: var(--fg);
  box-shadow: 0 1px 2px rgba(15, 31, 23, 0.12), 0 0 0 1px var(--line);
}
.wv-tabs button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* Narrow embeds: the tabs take their own full-width row. */
@media (max-width: 419px) {
  .wv-tabs { width: 100%; }
  .wv-tabs button { flex: 1; padding: 0 4px; }
}

/* --- panels ------------------------------------------------------------------ */

.wv-panels {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
}

.wv-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 16px 8px;
  animation: wv-in 0.25s ease-out;
}
@keyframes wv-in {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

.wv-hero {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}
.wv-big {
  font-size: 40px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  transition: color 0.3s;
}
.wv[data-stale="1"] [data-panel="live"] .wv-big { color: var(--muted); }
.wv-unit {
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}
.wv-side {
  margin-left: auto;
  font-size: 15px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.wv-side small {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.wv-sub {
  margin: 6px 0 0;
  min-height: 19px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wv-sub b { color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }
.wv-sub .up { color: var(--up); font-weight: 600; }
.wv-sub .down { color: var(--down); font-weight: 600; }
.wv-sub .dot { margin: 0 5px; color: var(--faint); }

.wv-chart {
  flex: 1 1 auto;
  min-height: 60px;
  margin-top: 10px;
  position: relative;
  touch-action: pan-y;
}
.wv-chart svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  display: block;
}

.wv-note {
  margin: 6px 0 0;
  min-height: 16px;
  font-size: 11px;
  color: var(--faint);
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  overflow: hidden;
}
.wv-key { display: inline-flex; align-items: center; gap: 4px; }
.wv-key i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
}
.wv-scale { display: inline-flex; gap: 2px; }
.wv-scale i { width: 10px; height: 10px; border-radius: 2px; }

/* Short embeds keep the number and the chart, and drop the rest. */
@media (max-height: 300px) {
  .wv-sub, .wv-note { display: none; }
  .wv-big { font-size: 30px; }
}

/* --- chart marks (SVG drawn by widget.js) --------------------------------- */

.wv-grid { stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
.wv-zero { stroke: var(--faint); stroke-width: 1; shape-rendering: crispEdges; }
.wv-axis { fill: var(--faint); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.wv-line { fill: none; stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.wv-area-top { stop-color: var(--brand); stop-opacity: 0.28; }
.wv-area-bottom { stop-color: var(--brand); stop-opacity: 0; }
.wv-now { fill: var(--brand); stroke: var(--bg); stroke-width: 2; }
.wv-now-ring {
  fill: none;
  stroke: var(--brand);
  stroke-width: 2;
  transform-box: fill-box;
  transform-origin: center;
  animation: wv-ring 2s ease-out infinite;
}
.wv[data-stale="1"] .wv-now-ring { display: none; }
.wv[data-stale="1"] .wv-now { fill: var(--faint); }

.wv-bar { fill: var(--brand); transition: opacity 0.15s; }
.wv-bar.neg { fill: var(--solar); }
.wv-bar.partial { opacity: 0.45; }
.wv-ghost { fill: var(--ghost); }
.wv-avg { stroke: var(--fg); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.45; }
.wv-avg-label { fill: var(--muted); font-size: 10.5px; font-weight: 600; }
.wv-chart.hovering .wv-bar:not(.hot) { opacity: 0.55; }
.wv-chart.hovering .wv-bar.partial:not(.hot) { opacity: 0.3; }

.wv-cell.h-none { fill: var(--heat-0); opacity: 0.5; }
.wv-cell.h0 { fill: var(--heat-0); }
.wv-cell.h1 { fill: var(--heat-1); }
.wv-cell.h2 { fill: var(--heat-2); }
.wv-cell.h3 { fill: var(--heat-3); }
.wv-cell.h4 { fill: var(--heat-4); }
.wv-cell.h5 { fill: var(--heat-5); }
.wv-cell.h-solar { fill: var(--solar); }
.wv-cell.hot { stroke: var(--fg); stroke-width: 1.5; }
.wv-rowlabel { fill: var(--muted); font-size: 10.5px; font-weight: 600; }
.wv-total { fill: var(--fg); font-size: 10.5px; font-weight: 600; font-variant-numeric: tabular-nums; }

.wv-cross { stroke: var(--faint); stroke-width: 1; stroke-dasharray: 2 2; shape-rendering: crispEdges; }
.wv-hotdot { fill: var(--bg); stroke: var(--brand); stroke-width: 2.5; }

.wv-tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  padding: 5px 8px;
  border-radius: 7px;
  background: var(--tip-bg);
  color: var(--tip-fg);
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  transform: translate(-50%, calc(-100% - 10px));
}
.wv-tip b { font-weight: 650; font-variant-numeric: tabular-nums; }
.wv-tip span { opacity: 0.7; }

.wv-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 12px;
  border-radius: 10px;
  background: var(--well);
  color: var(--muted);
  font-size: 13px;
}

/* --- private / waiting ---------------------------------------------------- */

.wv-message {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px 24px;
}
.wv-message-icon { width: 30px; height: 30px; color: var(--faint); margin-bottom: 10px; }
.wv-message h1 { margin: 0; font-size: 15px; font-weight: 650; }
.wv-message p { margin: 4px 0 0; max-width: 300px; font-size: 13px; color: var(--muted); }
.wv-owner { color: var(--brand-ink); font-weight: 600; text-decoration: none; }
.wv-owner:hover { text-decoration: underline; }

/* --- footer -------------------------------------------------------------------- */

.wv-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 36px;
  padding: 0 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
.wv-foot a { color: var(--muted); text-decoration: none; }
.wv-foot a:hover { color: var(--fg); }
.wv-brand {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 650;
  color: var(--fg) !important;
  letter-spacing: -0.005em;
}
.wv-brand svg { width: 14px; height: 14px; fill: var(--brand); }
.wv-cta { font-weight: 550; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wv-cta:hover { color: var(--brand-ink) !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
