/* xPDM History graph (history-graph.js): per-item version graph + Branches page branch map. */

/* Lane colours, in fixed order (lane 0 = main). Validated as a categorical set for light and dark
   surfaces (lightness band, chroma, colour-blind and normal-vision separation, 3:1 contrast). */
:root {
  --hg-c0: #16a34a; --hg-c1: #7c5cf0; --hg-c2: #eb6834; --hg-c3: #2a78d6;
  --hg-c4: #d55181; --hg-c5: #c98500; --hg-c6: #0e9fae; --hg-c7: #e34948;
  --hg-cx: var(--text-3);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --hg-c0: #1fa94f; --hg-c1: #8f76ee; --hg-c2: #e2652f; --hg-c3: #3a85e0;
    --hg-c4: #d55181; --hg-c5: #c98500; --hg-c6: #139fae; --hg-c7: #e05252;
  }
}
:root[data-theme="dark"] {
  --hg-c0: #1fa94f; --hg-c1: #8f76ee; --hg-c2: #e2652f; --hg-c3: #3a85e0;
  --hg-c4: #d55181; --hg-c5: #c98500; --hg-c6: #139fae; --hg-c7: #e05252;
}

/* ------------------------------------------------------------ layout */

.hg { margin: 0 -8px; }
.hg-scroll { overflow-x: auto; overflow-y: hidden; }
.hg-inner { position: relative; padding: 0 0 6px; }
.hg-svg { position: absolute; left: 0; top: 0; z-index: 1; pointer-events: none; overflow: visible; }

/* Lane headers: a staircase, lane i's label starts at lane i, so long names never hit another lane. */
.hg-heads { padding: 0 0 6px; }
.hg-head { height: 26px; display: flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 12.5px; min-width: 0; padding-right: 8px; }
.hg-head .hg-name {
  font: inherit; font-weight: 650; color: var(--text); border: 0; background: none; padding: 0;
  overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto;
}
.hg-head button.hg-name { cursor: pointer; }
.hg-head button.hg-name:hover { color: var(--accent-text); text-decoration: underline; }
.hg-head.closed .hg-name { color: var(--text-2); }
.hg-head .chip, .hg-l1 .chip { height: 18px; padding: 0 6px; font-size: 11px; gap: 4px; flex: none; }
.hg-head .chip svg.i { width: 11px; height: 11px; }
/* The count gives way first (shrinks, then disappears) so branch names stay readable in narrow panes. */
.hg-count { color: var(--text-3); font-size: 11.5px; margin-left: auto; padding-left: 4px; flex: 0 1000 auto; min-width: 0; overflow: hidden; text-overflow: clip; }

.hg-row {
  position: relative; padding: 7px 8px 8px var(--hg-gutter, 100px); cursor: pointer; min-height: 34px; outline: 0;
}
/* Highlight only the text column, so the gutter stays the surface colour behind the lanes. */
.hg-row::before {
  content: ""; position: absolute; inset: 2px 0 2px calc(var(--hg-gutter, 100px) - 7px); border-radius: 8px; z-index: -1;
}
.hg-rows { position: relative; z-index: 0; }
.hg-row:hover::before { background: var(--surface-hover); }
.hg-row.cur::before { background: color-mix(in srgb, var(--accent-soft) 70%, transparent); box-shadow: inset 3px 0 0 var(--accent); }
.hg-row:focus-visible::before { box-shadow: 0 0 0 2px var(--accent); }
.hg-row.flash::before { animation: hg-flash 1.4s ease-out; }
@keyframes hg-flash { 0%, 30% { background: color-mix(in srgb, var(--lc) 26%, transparent); } }
.hg-row.faded .hg-l1, .hg-row.faded .hg-meta, .hg-row.faded .hg-cm { opacity: .62; }

.hg-l1 { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; min-height: 20px; }
.hg-l1 > svg.i { color: var(--text-3); }
.hg-v { font-weight: 680; font-variant-numeric: tabular-nums; margin-right: 1px; }
.hg-meta { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.hg-cm { font-size: 12.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }

/* Branch refs ("which branch sees this version"): text in ink, identity in the coloured border. */
.hg-ref {
  display: inline-flex; align-items: center; gap: 3px; height: 18px; padding: 0 6px; border-radius: 5px;
  font-size: 11px; font-weight: 650; color: var(--text-2); background: var(--surface); border: 1.5px solid var(--lc); white-space: nowrap;
}
.hg-ref svg.i { width: 11px; height: 11px; }
.hg-ref.inh { border-style: dashed; color: var(--text-3); }
.hg-ref.cur { background: var(--accent); border-color: var(--accent); color: #fff; }
.hg-ref.cur.inh { border-style: solid; }

/* ------------------------------------------------------------ SVG marks */

.hg-e { fill: none; stroke: var(--lc); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: opacity .12s; }
.hg-e.restore { stroke-width: 1.6; stroke-dasharray: 3.5 3; }
.hg-e.faded, .faded > .hg-n, .faded > .hg-x { opacity: .5; }
.hg-u { fill: none; stroke: var(--surface); stroke-width: 6; stroke-linecap: butt; }
.hg-guide { fill: none; stroke: var(--lc); stroke-width: 2; stroke-dasharray: 1 4; stroke-linecap: round; opacity: .7; }
.hg-guide.closed { stroke: var(--text-3); opacity: .5; }
.hg-hd { fill: var(--lc); stroke: var(--surface); stroke-width: 2; }
.hg-hd.closed { fill: var(--surface); stroke: var(--lc); stroke-width: 2; }
.hg-n { fill: var(--surface); stroke: var(--lc); stroke-width: 2.5; transition: opacity .12s; }
.hg-n.rel { fill: var(--lc); stroke: var(--surface); stroke-width: 1.5; }
.hg-n.obs { stroke: var(--text-3); stroke-dasharray: 2 2; }
.hg-n.fork { fill: var(--lc); stroke: var(--surface); stroke-width: 1.5; }
.hg-n.cur { fill: var(--lc); }
.hg-n-in { fill: var(--lc); }
.hg-halo { fill: var(--lc); opacity: .2; }
.hg-x { stroke: var(--text-3); stroke-width: 2.2; stroke-linecap: round; }

/* Hovering a row: its node and the edges touching it stay, the rest steps back. */
.hg-focus .hg-e:not(.on), .hg-focus .hg-n:not(.on), .hg-focus .hg-n-in:not(.on) { opacity: .28; }
.hg-focus .hg-e.on { stroke-width: 2.6; }

.hg-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 11.5px; color: var(--text-3); }
.hg-legend span { display: inline-flex; align-items: center; gap: 5px; }
.hg-legend svg { width: 14px; height: 14px; --lc: var(--text-2); overflow: visible; }
.hg-legend svg[viewBox^="0 0 22"] { width: 22px; }

/* ------------------------------------------------------------ version popover (an app .menu) */

.menu.hg-pop { min-width: 260px; padding: 8px 6px 6px; }
.hg-pop-h { display: flex; align-items: center; flex-wrap: wrap; gap: 5px 6px; padding: 2px 10px 6px; }
.hg-pop-h .chip { height: 20px; font-size: 11.5px; }
.hg-pop-br { overflow-wrap: anywhere; }
.hg-sw { width: 10px; height: 10px; border-radius: 50%; background: var(--lc); flex: none; }
.hg-pop-c { margin: 0 10px 8px; padding: 6px 9px; border-radius: 7px; background: var(--surface-2); color: var(--text-2); font-size: 13px; overflow-wrap: anywhere; }
.hg-kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; padding: 0 10px 4px; font-size: 12.5px; }
.hg-kv dt { color: var(--text-3); }
.hg-kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.menu.hg-pop .mi { font-size: 13px; padding: 7px 10px; }
.menu.hg-pop .mi b { font-weight: 650; }
.menu.hg-pop .mi .r { padding-left: 12px; white-space: nowrap; }

/* ------------------------------------------------------------ Branches page map */

.hg-map { margin: 0 0 18px; overflow: hidden; }
.hg-map > summary {
  display: flex; align-items: center; gap: 8px; padding: 12px 16px; cursor: pointer; list-style: none; flex-wrap: wrap;
}
.hg-map > summary::-webkit-details-marker { display: none; }
.hg-map > summary::after { content: "▾"; margin-left: auto; color: var(--text-3); transition: transform .12s; }
.hg-map:not([open]) > summary::after { transform: rotate(-90deg); }
.hg-map > summary .muted { font-size: 12.5px; }
.hg-map-body { padding: 0 16px 12px; border-top: 1px solid var(--border); }
.hg-map-tools { display: flex; justify-content: flex-end; padding: 6px 0 0; }
.hg-vault { margin-top: 8px; }
.hg-vault .hg-row { cursor: default; }
.hg-vault .hg-count { margin-left: 4px; }
.hg-vault .hg-count::before { content: "· "; }
.hg-vault .hg-l1 b { font-weight: 620; }

@media (max-width: 640px) {
  .hg-map > summary .muted { display: none; }
  .hg-map-body { padding: 0 10px 10px; }
}
