/* Layered 2D DAG view (Issue #525).
 *
 * Phone-first: the header wraps, the diagram scrolls horizontally inside its
 * own box, and the details/legend panels stack under it on narrow viewports.
 */

:root {
  /* Keep in sync with docs/styles.css theme tokens (subset). */
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #111827;
  --muted: #4b5563;
  --border: rgba(17, 24, 39, 0.12);
  --buttonSecondaryBg: rgba(17, 24, 39, 0.05);
  --progressTrackBg: rgba(17, 24, 39, 0.12);
  --accent: #2563eb;
  --accentHover: #1d4ed8;
  --positive: #00875d;
  --negative: #dc2626;
  --highlight: #b45309;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0e1a;
    --panel: #111827;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: rgba(255, 255, 255, 0.08);
    --buttonSecondaryBg: rgba(255, 255, 255, 0.05);
    --progressTrackBg: rgba(255, 255, 255, 0.1);
    --accent: #60a5fa;
    --accentHover: #93c5fd;
    --positive: #34d399;
    --negative: #f87171;
    --highlight: #fbbf24;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Header ------------------------------------------------------------- */

.appHeader {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.appHeader h1 {
  font-size: 16px;
  margin: 0;
  white-space: nowrap;
}

.headerControls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
}

.browseGroup {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}

.button:hover {
  background: var(--accentHover);
}

.buttonSecondary {
  background: var(--buttonSecondaryBg);
  color: var(--text);
}

.buttonSecondary:hover {
  background: var(--border);
}

.buttonSmall {
  min-height: 30px;
  padding: 4px 10px;
  font-size: 12px;
}

.input,
.select {
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
}

.input {
  flex: 1 1 220px;
  min-width: 0;
}

.selectWide {
  width: 100%;
}

.detailLabel {
  color: var(--muted);
  font-size: 12px;
}

.snapshotDetails {
  position: relative;
}

.snapshotSummary {
  list-style: none;
}

.snapshotPanel {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}

.progressContainer {
  flex: 0 0 120px;
  height: 6px;
  border-radius: 3px;
  background: var(--progressTrackBg);
  overflow: hidden;
}

.progressBar {
  width: 0;
  height: 100%;
  background: var(--accent);
}

.statusInline {
  color: var(--muted);
  font-size: 12px;
}

.statusInline.good {
  color: var(--positive);
}

.statusInline.warn {
  color: var(--highlight);
}

.statusInline.bad {
  color: var(--negative);
}

/* --- Stage -------------------------------------------------------------- */

.stage {
  padding: 12px 14px 24px;
}

.summaryLine {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.diagram {
  overflow: auto;
  max-height: 70vh;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  -webkit-overflow-scrolling: touch;
}

.dagSvg {
  display: block;
}

.dagColumnLabel {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.dagNodeLabel {
  fill: var(--muted);
  font-size: 11px;
}

.dagNode {
  cursor: pointer;
}

.dagNode circle {
  stroke: var(--panel);
  stroke-width: 1.5;
}

.dagNode:hover circle,
.dagNode.isSelected circle {
  stroke: var(--text);
  stroke-width: 3;
}

/* --- Panels ------------------------------------------------------------- */

.panels {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}

.panel {
  flex: 1 1 280px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
}

.panelHeader {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.panelTitle {
  font-size: 13px;
  font-weight: 700;
}

.panelBody {
  padding: 10px 12px;
  font-size: 13px;
}

.detailsBody {
  margin-top: 10px;
  color: var(--text);
}

.detailsTitle {
  margin: 0 0 8px;
  font-size: 14px;
}

.detailsGrid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  margin: 0 0 10px;
}

.detailsGrid dt {
  color: var(--muted);
}

.detailsGrid dd {
  margin: 0;
}

.detailsMembers {
  margin: 0;
  padding-left: 18px;
  max-height: 220px;
  overflow-y: auto;
}

.detailsMembers li {
  margin-bottom: 2px;
}

.detailsMore {
  margin: 6px 0 0;
  color: var(--muted);
}

.dagLegend {
  margin: 0;
}

.dagLegendRow {
  display: grid;
  grid-template-columns: minmax(90px, auto) 1fr;
  gap: 2px 10px;
  margin-bottom: 4px;
}

.dagLegend dt {
  color: var(--muted);
}

.dagLegend dd {
  margin: 0;
}

@media (max-width: 640px) {
  .appHeader h1 {
    font-size: 14px;
  }

  .stage {
    padding: 10px 8px 20px;
  }

  .panel {
    flex: 1 1 100%;
  }
}
