/*
 * The Launch Director grid. Colors come from the Fluent tokens when the page loads
 * fluent-theme.css, with plain fallbacks so the grid also works on a bare page (the spike).
 *
 * Speed notes: the scroller is size- and paint-contained, rows are absolutely placed with a
 * transform, and every row is layout- and style-contained, so binding one row never lays out
 * another. Column widths are custom properties set once on .ldg.
 */
.ldg {
  --ldg-bg: var(--colorNeutralBackground1, #ffffff);
  --ldg-fg: var(--colorNeutralForeground1, #242424);
  --ldg-muted: var(--colorNeutralForeground3, #707070);
  --ldg-line: var(--colorNeutralStroke3, #ebebeb);
  --ldg-head-bg: var(--colorNeutralBackground2, #fafafa);
  --ldg-head-line: var(--colorNeutralStroke2, #e0e0e0);
  --ldg-sel: var(--colorBrandBackground2, #ebf3fc);
  --ldg-focus: var(--colorStrokeFocus2, #000000);
  --ldg-brand: var(--colorBrandForeground1, #0f6cbd);
  --ldg-blocked: var(--colorPaletteRedBorder2, #c50f1f);
  --ldg-pending: var(--colorPaletteMarigoldBorderActive, #d67f00);
  --ldg-rh: 28px;
  --ldg-indent: 18px;
  position: relative;
  overflow: auto;
  overflow-anchor: none;
  contain: strict;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  background: var(--ldg-bg);
  color: var(--ldg-fg);
  font-size: 13px;
  line-height: var(--ldg-rh);
  outline: none;
  user-select: none;
}

@media (prefers-color-scheme: dark) {
  .ldg {
    --ldg-bg: var(--colorNeutralBackground1, #1f1f1f);
    --ldg-fg: var(--colorNeutralForeground1, #ffffff);
    --ldg-muted: var(--colorNeutralForeground3, #adadad);
    --ldg-line: var(--colorNeutralStroke3, #333333);
    --ldg-head-bg: var(--colorNeutralBackground2, #292929);
    --ldg-head-line: var(--colorNeutralStroke2, #525252);
    --ldg-sel: var(--colorBrandBackground2, #082338);
    --ldg-focus: var(--colorStrokeFocus2, #ffffff);
    --ldg-brand: var(--colorBrandForeground1, #479ef5);
    --ldg-blocked: var(--colorPaletteRedBorder2, #dc626d);
    --ldg-pending: var(--colorPaletteMarigoldBorderActive, #f2c661);
  }
}

.ldg-head { position: sticky; top: 0; z-index: 3; width: var(--ldg-row-w); }
.ldg-headrow {
  display: flex;
  width: var(--ldg-row-w);
  height: var(--ldg-rh);
  background: var(--ldg-head-bg);
  border-bottom: 1px solid var(--ldg-head-line);
  font-weight: 600;
}
.ldg-hcell {
  position: relative;
  flex: 0 0 auto;
  box-sizing: border-box;
  padding: 0 8px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  background: var(--ldg-head-bg);
}
.ldg-hcell.ldg-tree { position: sticky; left: 0; z-index: 1; }
.ldg-resize {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
}
.ldg-resize:hover, .ldg-resizing .ldg-resize { background: var(--ldg-head-line); }

.ldg-canvas { position: relative; width: var(--ldg-row-w); contain: layout style; }

.ldg-row {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  width: var(--ldg-row-w);
  height: var(--ldg-rh);
  box-sizing: border-box;
  border-bottom: 1px solid var(--ldg-line);
  background: var(--ldg-bg);
  contain: layout style;
  will-change: transform;
}
.ldg-row[hidden] { display: none; }
.ldg-row.ldg-selected, .ldg-row.ldg-selected .ldg-tree { background: var(--ldg-sel); }

.ldg-cell {
  flex: 0 0 auto;
  box-sizing: border-box;
  padding: 0 8px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  outline: none;
}
.ldg-end { text-align: end; }
.ldg-text { overflow: hidden; text-overflow: ellipsis; }
.ldg-cell.ldg-tree {
  position: sticky;
  left: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  padding-inline-start: calc(2px + var(--ldg-level, 0) * var(--ldg-indent));
  background: var(--ldg-bg);
}
.ldg-tree .ldg-text { flex: 1 1 auto; min-width: 0; }

/* The focused cell always shows, mouse or keyboard, while the grid has focus. */
.ldg:focus-within .ldg-cell[tabindex="0"] { outline: 2px solid var(--ldg-focus); outline-offset: -2px; }

.ldg-grip {
  flex: 0 0 10px;
  height: 16px;
  cursor: grab;
  touch-action: none;
  opacity: 0;
  background-image: radial-gradient(var(--ldg-muted) 1px, transparent 1.5px);
  background-size: 5px 5px;
}
.ldg-row:hover .ldg-grip, .ldg-selected .ldg-grip { opacity: 1; }
.ldg-dragging, .ldg-dragging .ldg-grip { cursor: grabbing; }

.ldg-toggle { flex: 0 0 16px; height: 16px; cursor: pointer; position: relative; }
.ldg-parent .ldg-toggle::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 4px;
  border-style: solid;
  border-width: 4px 0 4px 6px;
  border-color: transparent transparent transparent var(--ldg-muted);
  transition: none;
}
.ldg-parent.ldg-open .ldg-toggle::before { transform: rotate(90deg); }

/* Row marks: waiting is greyed, blocked has a red bar, not-yet-saved has a dot. The words are
   in .ldg-marks for screen readers. */
.ldg-waiting .ldg-text { color: var(--ldg-muted); }
.ldg-blocked .ldg-cell.ldg-tree { box-shadow: inset 3px 0 0 var(--ldg-blocked); }
.ldg-context .ldg-text { color: var(--ldg-muted); font-style: italic; }
.ldg-badge {
  flex: none;
  padding: 0 6px;
  border: 1px solid var(--ldg-blocked);
  border-radius: 8px;
  color: var(--ldg-blocked);
  font-size: 11px;
  line-height: 16px;
  cursor: help;
}
.ldg-badge[hidden] { display: none; }
.ldg-dot { flex: 0 0 6px; height: 6px; border-radius: 50%; }
.ldg-pending .ldg-dot { background: var(--ldg-pending); }
.ldg-cell-pending .ldg-text { text-decoration: underline dotted var(--ldg-pending); }
.ldg-marks, .ldg-live {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.ldg-editing { padding: 0; overflow: visible; }
.ldg-editing > .ldg-text { display: none; }
.ldg-tree.ldg-editing { padding-inline-end: 0; }
.ldg-editor {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  height: calc(var(--ldg-rh) - 1px);
  box-sizing: border-box;
  margin: 0;
  padding: 0 7px;
  border: 1px solid var(--ldg-brand);
  border-radius: 0;
  background: var(--ldg-bg);
  color: var(--ldg-fg);
  font: inherit;
  outline: none;
}
.ldg-editor[aria-invalid="true"] { border-color: var(--ldg-blocked); box-shadow: inset 0 0 0 1px var(--ldg-blocked); }

.ldg-drop {
  position: absolute;
  top: -1px;
  left: calc(30px + var(--ldg-level, 0) * var(--ldg-indent));
  right: 0;
  height: 2px;
  z-index: 2;
  background: var(--ldg-brand);
  pointer-events: none;
}
.ldg-drop[hidden] { display: none; }
.ldg-drop-inside { top: 0; height: var(--ldg-rh); background: transparent; box-shadow: inset 0 0 0 2px var(--ldg-brand); left: 0; }
.ldg-drop-refused { background: var(--ldg-blocked); }
.ldg-drop-inside.ldg-drop-refused { background: transparent; box-shadow: inset 0 0 0 2px var(--ldg-blocked); }

@media (forced-colors: active) {
  .ldg-row.ldg-selected, .ldg-row.ldg-selected .ldg-tree { background: Highlight; color: HighlightText; }
  .ldg:focus-within .ldg-cell[tabindex="0"] { outline-color: CanvasText; }
  .ldg-pending .ldg-dot { background: CanvasText; }
  .ldg-badge { border-color: CanvasText; color: CanvasText; }
  .ldg-drop { background: Highlight; }
}
