/* ---- Graph controls ------------------------------------ */

.repository-graph {
  min-width: 0;
}

.repository-graph-page .repository-nav {
  overflow-y: hidden;
}

.repository-graph-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  padding: 8px 10px;
  border: 1px solid var(--warning-text);
  border-radius: 4px;
  color: var(--warning-text);
  background: var(--bg-1);
  font: 600 11px/1.4 var(--font-ui);
}

.repository-graph-notice > span {
  flex: none;
  width: 6px;
  height: 6px;
  background: currentColor;
}

.graph-toolbar {
  position: relative;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.graph-branch-selector {
  position: relative;
  width: min(260px, calc(100vw - 86px));
  color: var(--fg-0);
}

.graph-branch-selector > summary,
.graph-size-button {
  min-height: 44px;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  color: var(--fg-0);
  background: var(--bg-1);
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease, background 140ms ease;
}

.graph-branch-selector > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  list-style: none;
}

.graph-branch-selector > summary::-webkit-details-marker {
  display: none;
}

.graph-branch-selector > summary:hover,
.graph-branch-selector[open] > summary,
.graph-size-button:hover {
  color: var(--fg-1);
  border-color: var(--action);
  background: var(--bg-3);
}

.graph-branch-selector > summary > svg {
  flex: none;
  width: 17px;
  height: 17px;
  color: var(--link-text);
}

.graph-branch-selector > summary > span {
  min-width: 0;
  flex: 1;
  font: 600 13px/1.3 var(--font-ui);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.graph-branch-selector > summary > .graph-selector-chevron {
  width: 15px;
  height: 15px;
  color: var(--muted);
  transition: transform 140ms ease;
}

.graph-branch-selector[open] .graph-selector-chevron {
  transform: rotate(180deg);
}

.graph-branch-menu {
  position: absolute;
  z-index: 60;
  inset: calc(100% + 4px) auto auto 0;
  display: flex;
  width: min(340px, calc(100vw - 32px));
  max-height: min(400px, calc(100dvh - 140px));
  padding: 5px;
  border: 1px solid var(--action);
  border-radius: 4px;
  flex-direction: column;
  background: var(--bg-0);
}

.graph-branch-selector:not([open]) > .graph-branch-menu {
  display: none;
}

.graph-branch-menu-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--control-border);
}

.graph-branch-menu-tools label {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  min-height: 38px;
  border: 1px solid var(--control-border);
  border-radius: 3px;
  background: var(--bg-1);
}

.graph-branch-menu-tools label:focus-within {
  border-color: var(--accent-text);
  box-shadow: inset 0 0 0 1px var(--accent-text);
}

.graph-branch-menu-tools svg {
  width: 15px;
  height: 15px;
  margin-left: 8px;
  color: var(--muted);
}

.graph-branch-menu-tools input {
  width: 100%;
  min-width: 0;
  padding: 6px 7px;
  border: 0;
  outline: 0;
  color: var(--fg-0);
  background: transparent;
  font: 600 12px/1.3 var(--font-ui);
}

.graph-branch-menu-tools input::placeholder {
  color: var(--muted);
  opacity: .8;
}

.graph-branch-menu-tools button {
  padding: 6px 8px;
  border: 1px solid var(--control-border);
  border-radius: 3px;
  color: var(--link-text);
  background: var(--bg-1);
  font: 600 11px/1.2 var(--font-ui);
  white-space: nowrap;
  cursor: pointer;
}

.graph-branch-menu-tools button:hover {
  color: var(--fg-1);
  border-color: var(--action);
  background: var(--bg-3);
}

.graph-branch-options {
  min-height: 0;
  padding-top: 3px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--control-border) transparent;
  scrollbar-width: thin;
}

.graph-branch-option {
  display: grid;
  grid-template-columns: 17px 9px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 6px 7px;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--fg-0);
  font: 500 13px/1.3 var(--font-mono);
  cursor: pointer;
}

.graph-branch-option:hover {
  background: var(--bg-3);
}

.graph-branch-option[hidden] {
  display: none;
}

.graph-branch-option input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--action);
}

.graph-branch-color {
  width: 8px;
  height: 8px;
  background: var(--graph-branch-color);
}

.graph-branch-option > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.graph-branch-empty {
  margin: 0;
  padding: 9px 7px;
  color: var(--muted);
  font: 600 12px/1.3 var(--font-ui);
}

.graph-size-button {
  display: grid;
  width: 44px;
  flex: none;
  margin-left: auto;
  padding: 0;
  place-items: center;
}

.graph-size-button svg {
  width: 18px;
  height: 18px;
  color: var(--link-text);
}

.graph-size-button svg[hidden] {
  display: none;
}

/* ---- Graph panel --------------------------------------- */

.repository-graph-canvas {
  display: grid;
  width: 100%;
  height: clamp(
    440px,
    calc(240px + var(--graph-node-space)),
    min(740px, 70vh)
  );
  min-width: 0;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--bg-1);
}

body.graph-fullscreen {
  overflow: hidden;
}

.graph-panel.is-fullscreen {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 0;
  background: var(--bg-0);
}

.graph-panel.is-fullscreen .graph-toolbar {
  margin: 0;
  padding:
    max(8px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    8px
    max(8px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--control-border);
  background: var(--bg-0);
}

.graph-panel.is-fullscreen .repository-graph-canvas {
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
}

.graph-state {
  max-width: 360px;
  margin: 0;
  padding: 24px;
  color: var(--muted);
  font: 13px/1.5 var(--font-ui);
  text-align: center;
}

.graph-error {
  color: var(--warning-text);
}

/* ---- Graph surface --------------------------------------- */

.gg-viewport {
  --gg-surface: var(--bg-1);
  --gg-ink: var(--fg-0);
  --gg-accent: var(--accent-text);
  --gg-guide-color: var(--control-border);
  --gg-badge-surface: var(--bg-0);
  --gg-popover-surface: var(--bg-0);
  --gg-popover-border: var(--control-border);
  --gg-font: var(--font-ui);
  --gg-mono-font: var(--font-mono);
  --gg-guide-width: 1px;
  --gg-guide-dash-length: 1px;
  --gg-guide-dash-gap: 8px;
  --gg-line-width: 3px;
  --gg-node-size: 12px;
  --gg-merge-node-size: 16px;
  --gg-node-outline-width: 3px;
  --gg-hit-target-size: 38px;
  --gg-halo-size: 32px;
  position: relative;
  display: block;
  place-items: normal;
  overflow: auto;
  color: var(--gg-ink);
  background: var(--gg-surface);
  isolation: isolate;
  overscroll-behavior: contain;
  scrollbar-color: var(--control-border) transparent;
  scrollbar-width: thin;
}

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

.gg-viewport:focus-visible {
  outline: 2px solid var(--action);
  outline-offset: -2px;
}

.gg-viewport::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.gg-viewport::-webkit-scrollbar-thumb {
  min-height: 40px;
  border: 2px solid var(--gg-surface);
  border-radius: 3px;
  background: var(--control-border);
}

.gg-surface {
  position: relative;
  min-width: 100%;
  overflow: visible;
  color: var(--gg-ink);
  background: var(--gg-surface);
  font-family: var(--gg-font);
}

.gg-canvas {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  shape-rendering: geometricPrecision;
}

.gg-guides line {
  stroke: var(--gg-guide-color);
  stroke-width: var(--gg-guide-width);
  stroke-dasharray: var(--gg-guide-dash-length) var(--gg-guide-dash-gap);
  opacity: .75;
  vector-effect: non-scaling-stroke;
}

.gg-edge {
  fill: none;
  stroke: var(--gg-edge-color);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: var(--gg-line-width);
  vector-effect: non-scaling-stroke;
}

.gg-row-highlight {
  position: absolute;
  z-index: 2;
  right: 0;
  left: 0;
  height: 44px;
  border-top: 1px solid color-mix(in srgb, var(--action) 25%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--action) 25%, transparent);
  background: color-mix(in srgb, var(--action) 7%, transparent);
  pointer-events: none;
  transform: translateY(-50%);
}

.gg-row-highlight[hidden],
.gg-popover[hidden] {
  display: none;
}

.gg-lane-bar {
  position: sticky;
  z-index: 20;
  top: 0;
  width: 100%;
  height: var(--gg-header-height, 68px);
  border-bottom: 1px solid var(--control-border);
  background: var(--bg-1);
  pointer-events: none;
}

.gg-lane-heading {
  position: absolute;
  top: 15px;
  display: inline-flex;
  min-width: 0;
  height: 38px;
  align-items: center;
  padding: 0 11px;
  overflow: hidden;
  border: 1px solid var(--gg-color);
  border-radius: 4px;
  color: var(--button-text);
  background: var(--gg-color);
  pointer-events: auto;
  transform: translateX(-50%);
}

.gg-lane-name {
  min-width: 0;
  overflow: hidden;
  font: 600 12px/1.3 var(--gg-mono-font);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Graph nodes ----------------------------------------- */

.gg-node {
  position: absolute;
  z-index: 6;
  display: grid;
  width: var(--gg-hit-target-size);
  min-width: 0;
  max-width: none;
  height: var(--gg-hit-target-size);
  min-height: 0;
  max-height: none;
  margin: 0;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  appearance: none;
  color: inherit;
  background: transparent;
  cursor: pointer;
  transform: translate(-50%, -50%);
}

.gg-node-core {
  display: block;
  width: var(--gg-node-size);
  height: var(--gg-node-size);
  border-radius: 50%;
  background: var(--gg-color);
  box-shadow: 0 0 0 var(--gg-node-outline-width) var(--gg-surface);
}

.gg-node--merge .gg-node-core {
  width: var(--gg-merge-node-size);
  height: var(--gg-merge-node-size);
}

.gg-node::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--gg-halo-size);
  height: var(--gg-halo-size);
  border: 1px solid color-mix(in srgb, var(--gg-color) 75%, transparent);
  border-radius: 50%;
  background: color-mix(in srgb, var(--gg-color) 9%, transparent);
  content: "";
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: opacity 140ms ease;
}

.gg-node:hover,
.gg-node:focus-visible,
.gg-node.is-active {
  z-index: 9;
  outline: 0;
}

.gg-node:hover::after,
.gg-node:focus-visible::after,
.gg-node.is-active::after {
  opacity: 1;
}

.gg-badge-list {
  position: absolute;
  z-index: 8;
  display: flex;
  gap: 4px;
  margin-left: 12px;
  pointer-events: none;
  transform: translateY(-50%);
}

.gg-badge-list--left {
  flex-direction: row-reverse;
  margin-left: 0;
  transform: translate(calc(-100% - 12px), -50%);
}

.gg-badge {
  display: inline-flex;
  height: 24px;
  align-items: center;
  padding: 0 8px;
  border: 1px solid var(--gg-color);
  border-radius: 3px;
  color: var(--gg-color);
  background: var(--gg-badge-surface);
  font: 600 11px/1 var(--gg-mono-font);
  white-space: nowrap;
}

.gg-badge:first-child {
  color: var(--button-text);
  background: var(--gg-color);
}

/* ---- Graph popover --------------------------------------- */

.gg-popover {
  position: absolute;
  z-index: 40;
  width: 340px;
  max-width: calc(100% - 16px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--gg-popover-border);
  border-top: 2px solid var(--gg-accent);
  border-radius: 4px;
  color: var(--fg-0);
  background: var(--gg-popover-surface);
  pointer-events: none;
  overflow-wrap: anywhere;
}

.gg-popover--interactive {
  pointer-events: auto;
}

.gg-popover-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 11px;
}

.graph-snapshot-info {
  display: grid;
  flex: none;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 3px;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.graph-snapshot-info:hover {
  border-color: var(--control-border);
  color: var(--fg-1);
}

.graph-snapshot-info svg {
  width: 16px;
  height: 16px;
}

.gg-popover-lane {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
  font: 600 11px/1.3 var(--font-mono);
}

.gg-popover-lane i {
  display: block;
  flex: none;
  width: 8px;
  height: 8px;
}

.gg-popover-lane > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gg-popover-id {
  display: block;
  margin: 7px 0 0;
  padding: 0;
  border: 0;
  color: var(--muted);
  background: none;
  font: 11px/1.3 var(--font-mono);
}

.gg-popover-title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  margin: 0;
  color: var(--fg-1);
  font: 600 16px/1.35 var(--font-ui);
}

.gg-popover-description {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.gg-popover-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.gg-popover-footer > span:last-child {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.gg-popover-footer.graph-snapshot-footer {
  display: grid;
  gap: 8px;
}

.graph-snapshot-footer > .snapshot-credits:last-child { display: grid; }

.gg-popover .snapshot-credits {
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
}

.gg-popover .snapshot-credit {
  flex-direction: row;
  gap: 5px;
}

.gg-popover .snapshot-credit-label {
  font-size: 12px;
}

.gg-popover .snapshot-credit-value {
  white-space: normal;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.gg-popover-avatar {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--control-border);
  border-radius: 50%;
  color: var(--fg-1);
  background: var(--bg-3);
  font-size: 10px;
}

.gg-popover-avatar img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
}

.gg-popover-author {
  color: var(--fg-1);
  font-size: 12px;
}

.gg-popover-time {
  color: var(--muted);
  font: 11px/1.3 var(--font-mono);
}

.gg-popover-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid var(--control-border);
}

.gg-popover-action {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--action);
  border-radius: 3px;
  color: var(--link-text);
  background: var(--bg-1);
  font: 600 12px/1 var(--font-ui);
  cursor: pointer;
}

.gg-popover-action:hover,
.gg-popover-action:focus-visible {
  color: var(--fg-1);
  border-color: var(--action);
  outline: 0;
  background: var(--bg-3);
}

.gg-empty {
  position: absolute;
  z-index: 3;
  top: 50%;
  left: 50%;
  width: min(360px, calc(100% - 32px));
  color: var(--muted);
  font: 13px/1.5 var(--font-ui);
  text-align: center;
  transform: translate(-50%, -50%);
}

/* ---- Snapshot dialog --------------------------------------- */

.graph-snapshot-dialog {
  width: 720px;
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  color: var(--fg-1);
  background: var(--bg-1);
}

.graph-snapshot-dialog[open] {
  display: flex;
  flex-direction: column;
}

.graph-snapshot-dialog::backdrop {
  background: var(--dialog-backdrop);
}

.graph-snapshot-dialog > header {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--control-border);
}

.graph-snapshot-dialog h2 {
  margin: 0;
  font: 600 16px/1.4 var(--font-ui);
}

.graph-snapshot-dialog button {
  display: grid;
  flex: none;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 5px;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  color: var(--fg-1);
  background: var(--bg-1);
  font: 12px/1.4 var(--font-ui);
  cursor: pointer;
}

.graph-snapshot-dialog button svg {
  width: 16px;
  height: 16px;
}

.graph-snapshot-dialog button:hover {
  border-color: var(--action);
  background: var(--bg-3);
}

.graph-snapshot-content {
  min-height: 0;
  padding: 16px;
  overflow: auto;
  overscroll-behavior: contain;
  overflow-wrap: anywhere;
}

.graph-snapshot-meta {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0 0 20px;
  font: 12px/1.5 var(--font-mono);
}

.graph-snapshot-meta dt,
.graph-snapshot-content h3 {
  color: var(--muted);
}

.graph-snapshot-meta dd {
  min-width: 0;
  margin: 0;
}

.graph-snapshot-content h3 {
  margin: 0 0 8px;
  font: 600 12px/1.5 var(--font-ui);
}

.graph-snapshot-description {
  margin: 0;
  white-space: pre-wrap;
  font: 14px/1.65 var(--font-ui);
}

/* ---- Responsive ------------------------------------------ */

@media (max-width: 760px) {
  .repository-graph-canvas {
    height: clamp(
      400px,
      calc(220px + var(--graph-node-space)),
      min(650px, 66dvh)
    );
  }

  .gg-popover {
    width: 306px;
  }
}

@media (max-width: 560px) {
  .graph-branch-selector {
    width: min(236px, calc(100vw - 84px));
  }

  .graph-branch-menu {
    width: min(320px, calc(100vw - 32px));
  }

  .graph-branch-menu-tools {
    grid-template-columns: 1fr;
  }

  .graph-branch-menu-tools button {
    min-height: 32px;
  }

  .repository-graph-canvas {
    height: clamp(
      380px,
      calc(210px + var(--graph-node-space)),
      min(590px, 62dvh)
    );
  }

  .graph-panel.is-fullscreen .repository-graph-canvas {
    height: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gg-node::after {
    transition: none;
  }
}
