/* Dense log grid first, charts second. Neutral surfaces, no decoration. */
:root {
  --bg: #faf9f8;
  --surface: #ffffff;
  --fg: #1a1a1a;
  --fg-dim: #6b6b6b;
  --fg-faint: #999999;
  --line: #e0dfdd;
  --line-strong: #c8c7c4;
  --accent: #2563eb;
  --muted-bg: #f3f2f1;
  --ghost: #b0afac;
  --series-1: #3274d9;
  /* Validated for colourblind separation in both themes; see the data-viz notes
     in docs. Order matters: adjacent slots are the pairs that must stay apart. */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a;
  --s4: #eda100; --s5: #e87ba4; --s6: #008300;
  --up: #37872d;
  --down: #c4162a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a19;
    --surface: #242423;
    --fg: #f0efed;
    --fg-dim: #a3a3a0;
    --fg-faint: #787875;
    --line: #353533;
    --line-strong: #4a4a47;
    --accent: #7ba3f5;
    --muted-bg: #2d2d2b;
    --ghost: #63635f;
    --series-1: #5794f2;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70;
    --s4: #c98500; --s5: #d55181; --s6: #008300;
    --up: #73bf69;
    --down: #f2495c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* A display rule on a class beats [hidden]'s default display:none, so pin it.
   Without this, .modes stays visible on the read-only share page. */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  padding: 24px 16px calc(40px + env(safe-area-inset-bottom, 0px));
  -webkit-text-size-adjust: 100%;
}
.wrap { max-width: 900px; margin: 0 auto; }

h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 14px; }
h2 {
  font-size: 16px; font-weight: 600; margin: 30px 0 10px;
  padding-bottom: 8px; border-bottom: 1px solid var(--line-strong);
}
h3 { font-size: 13.5px; font-weight: 600; margin: 20px 0 6px; }
h3 .faint { font-weight: 400; color: var(--fg-faint); }
.note { color: var(--fg-dim); font-size: 13px; margin: 10px 0 0; max-width: 66ch; }
.note strong { color: var(--fg); font-weight: 600; }

/* mode switch */
.modes { display: flex; margin-bottom: 14px; }
.modes button {
  border-radius: 0; border: 1px solid var(--line-strong); margin-left: -1px;
  font-weight: 500; padding: 8px 16px;
}
.modes button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.modes button:last-child { border-radius: 0 6px 6px 0; }
.modes button[aria-pressed="true"] {
  background: var(--fg); color: var(--bg); border-color: var(--fg); position: relative; z-index: 1;
}
.modes button[aria-pressed="true"]:hover { background: var(--fg); }

/* toolbars */
.bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 7px; padding: 10px 12px; margin-bottom: 12px;
}
.bar.footer { margin-top: 12px; margin-bottom: 0; }
.bar label { font-size: 12px; color: var(--fg-dim); }
.bar .spacer { flex: 1 1 auto; }
button, select, input[type="date"], input[type="number"] {
  font: inherit; color: var(--fg); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 5px;
  padding: 6px 9px; min-height: 36px;
}
input.narrow { width: 90px; }
button { cursor: pointer; }
button:hover { background: var(--muted-bg); }
button[disabled] { opacity: 0.5; cursor: default; }
button.primary {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500;
}
button.primary:hover:not([disabled]) { filter: brightness(1.08); }
button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.status { font-size: 13px; color: var(--fg-dim); }

/* the grid */
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
thead th {
  background: var(--muted-bg); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--fg-dim); white-space: nowrap;
}
.num { text-align: right; font-variant-numeric: tabular-nums; }
#grid { min-width: 560px; }
#grid td.ex { font-weight: 500; white-space: nowrap; }
#grid td.tgt { color: var(--fg-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
#grid td.cell { padding: 0; width: 60px; }
#grid td.cell input {
  width: 100%; border: 0; background: transparent; font: inherit; color: var(--fg);
  text-align: right; padding: 8px; min-height: 0; border-radius: 0;
  font-variant-numeric: tabular-nums;
}
#grid td.cell input::placeholder { color: var(--ghost); }
#grid td.cell:focus-within { outline: 2px solid var(--series-1); outline-offset: -2px; }
#grid td.cell.off { background: var(--muted-bg); }
#grid td.vol { color: var(--fg-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
#grid tfoot td { background: var(--muted-bg); font-weight: 600; }
.swap {
  font: inherit; font-size: 11px; padding: 2px 6px; min-height: 0;
  border-radius: 4px; color: var(--accent); border-color: var(--line-strong);
  margin-left: 6px; background: transparent;
}

/* charts */
.inline-prog {
  border: 1px solid var(--line); border-left: 3px solid var(--series-1);
  border-radius: 0 7px 7px 0; padding: 12px 14px; margin-bottom: 12px; background: var(--surface);
}
.inline-prog .ihead {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--fg-dim);
}
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px 20px; margin-top: 10px; }
.charts.pair { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.facet { margin: 0; min-width: 0; }
.facet figcaption { font-size: 12.5px; font-weight: 500; }
.facet .trend { color: var(--fg-faint); font-weight: 400; font-size: 11.5px; }
.facet svg, .barchart svg { width: 100%; height: auto; display: block; }
.facet.none {
  border: 1px dashed var(--line-strong); border-radius: 6px; padding: 10px;
  font-size: 12px; color: var(--fg-dim); display: flex; flex-direction: column; gap: 2px;
}
.facet.none b { font-size: 12.5px; font-weight: 500; color: var(--fg); }
.barchart { margin-top: 10px; }
.line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.area { fill: var(--series-1); opacity: 0.1; stroke: none; }
.pt { fill: var(--surface); stroke: var(--series-1); stroke-width: 2; }
.pt-last { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.axis { stroke: var(--line-strong); stroke-width: 1; }
.grid { stroke: var(--line); stroke-width: 1; }
.bar { fill: var(--series-1); }
.val { fill: var(--fg); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; text-anchor: start; }
.val.end-first { text-anchor: end; fill: var(--fg-dim); font-weight: 500; }
.tick { fill: var(--fg-faint); font-size: 10px; text-anchor: middle; }
.barval { fill: var(--fg); font-size: 12px; font-weight: 600; text-anchor: middle; font-variant-numeric: tabular-nums; }
.xlab { fill: var(--fg-dim); font-size: 11px; text-anchor: middle; }
.ylab { fill: var(--fg-faint); font-size: 10px; text-anchor: end; font-variant-numeric: tabular-nums; }

/* body composition */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 12px 0; }
.metric {
  background: var(--surface); border: 1px solid var(--line); border-radius: 7px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 3px; min-width: 0;
}
.mlabel { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--fg-dim); }
.metric b { font-size: 26px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.metric b .unit { font-size: 14px; font-weight: 400; color: var(--fg-dim); }
.mcap { font-size: 12px; color: var(--fg-dim); }

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


/* header menu */
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.menu-wrap { position: relative; }
.dots {
  min-height: 34px; padding: 2px 10px; font-size: 18px; line-height: 1;
  border-radius: 6px; color: var(--fg-dim);
}
.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 10;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 7px; padding: 4px; min-width: 170px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}
.menu button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 8px 10px; border-radius: 5px; min-height: 0;
}
.menu button:hover { background: var(--muted-bg); }

/* share admin */
.newlink {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 0 7px 7px 0;
  padding: 12px 14px; margin-bottom: 12px;
}
.linkrow { display: flex; gap: 8px; margin-top: 6px; }
.linkrow input {
  flex: 1 1 auto; min-width: 0; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
}
.sharerow {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.sharerow .who { font-weight: 500; }
.sharerow .when { color: var(--fg-dim); font-size: 12.5px; }
.sharerow .idfrag {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11.5px;
  color: var(--fg-faint);
}
.sharerow .spacer { flex: 1 1 auto; }


/* ---- dashboard panels ---------------------------------------------------- */
.charts { grid-template-columns: repeat(auto-fit, minmax(430px, 1fr)); gap: 14px; }
.charts.pair { grid-template-columns: repeat(auto-fit, minmax(430px, 1fr)); }

.panel {
  margin: 0; min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 10px 6px;
}
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px; padding-bottom: 4px;
}
.panel-title {
  font-size: 13px; font-weight: 500; color: var(--fg-dim);
  letter-spacing: 0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.panel-trend { font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.panel-trend.up { color: var(--up); }
.panel-trend.down { color: var(--down); }
.panel-trend.flat { color: var(--fg-faint); }
.panel-body { position: relative; }
.panel-body svg { width: 100%; height: auto; display: block; overflow: visible; }
.panel-legend {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--fg-dim); padding-top: 2px;
}
.g-key {
  width: 10px; height: 3px; border-radius: 2px; background: var(--series-1); display: inline-block;
}
.panel.empty { display: flex; flex-direction: column; }
.panel-empty {
  font-size: 12px; color: var(--fg-faint); padding: 20px 0 22px; text-align: center;
  border: 1px dashed var(--line-strong); border-radius: 3px; margin-top: 4px;
}

.g-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 3; }
.g-axis { stroke: var(--line-strong); stroke-width: 1; }
.g-ylab, .g-xlab {
  fill: var(--fg-faint); font-size: 11px; font-variant-numeric: tabular-nums;
}
.g-ylab { text-anchor: end; }
.g-line {
  fill: none; stroke: var(--series-1); stroke-width: 2;
  stroke-linejoin: round; stroke-linecap: round;
}
.g-stop-a { stop-color: var(--series-1); stop-opacity: 0.28; }
.g-stop-b { stop-color: var(--series-1); stop-opacity: 0.02; }
.g-dot { fill: var(--series-1); opacity: 0; }
.g-dot.on { opacity: 1; stroke: var(--surface); stroke-width: 2; }
.g-cross { stroke: var(--fg-faint); stroke-width: 1; stroke-dasharray: 2 3; }
.g-tip {
  position: absolute; transform: translate(-50%, calc(-100% - 10px));
  background: var(--fg); color: var(--bg);
  border-radius: 3px; padding: 4px 7px; font-size: 11px; line-height: 1.35;
  pointer-events: none; white-space: nowrap; z-index: 5;
  display: flex; flex-direction: column;
}
.g-tip b { font-variant-numeric: tabular-nums; font-weight: 600; }
.g-tip span { opacity: 0.7; }


/* combined multi-series panel */
.panel.wide { grid-column: 1 / -1; }
.multi-legend {
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  padding-top: 8px; font-size: 12px;
}
.multi-legend .item { display: flex; align-items: center; gap: 6px; min-width: 0; }
.multi-legend .k { width: 11px; height: 3px; border-radius: 2px; flex: 0 0 auto; }
.multi-legend .n { color: var(--fg-dim); white-space: nowrap; }
.multi-legend .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.g-tip .tipgrid {
  display: grid; grid-template-columns: auto auto; gap: 1px 10px; margin-top: 3px;
}
.g-tip .tipgrid span { opacity: 0.85; }
.g-tip .tipgrid b { justify-self: end; }
.chartmode { display: flex; }
.chartmode button {
  border-radius: 0; margin-left: -1px; padding: 6px 12px; font-size: 13px; min-height: 32px;
}
.chartmode button:first-child { border-radius: 5px 0 0 5px; margin-left: 0; }
.chartmode button:last-child { border-radius: 0 5px 5px 0; }
.chartmode button[aria-pressed="true"] {
  background: var(--fg); color: var(--bg); border-color: var(--fg);
}
.chartmode button[aria-pressed="true"]:hover { background: var(--fg); }

.g-mdot { stroke: var(--surface); stroke-width: 1.5; }
