/*
 * ErrorFallback: a padded column (heading, message, then copyable Stack and Data sections) that scrolls on its own,
 * since it replaces whatever crashed and may sit in a host of any height. ErrorStack is a four-track grid per frame
 * (tree connector, function, file, line:column) whose connector is drawn with pseudo-elements, so it needs no markup.
 */

@layer dx-components {
  .dx-error-fallback {
    display: flex;
    flex-direction: column;
    gap: var(--dx-gap-size);
    min-width: 0;
    min-height: 0;
    padding: calc(2 * var(--dx-gap-size));
    overflow: auto;
    font-size: var(--dx-font-size);
    line-height: var(--dx-line-height);
  }

  .dx-error-fallback-title {
    margin: 0;
    font-size: 1.125rem;
    line-height: 1.75rem;
    font-weight: inherit;
    color: var(--color-error-text);
  }

  .dx-error-fallback-message {
    margin: 0;
    overflow-wrap: anywhere;
  }

  /* The copy button leads its section and keeps its own width rather than stretching across it. */
  .dx-error-fallback-section {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    min-width: 0;
  }
  .dx-error-fallback-section > :not(.dx-button) {
    align-self: stretch;
  }
  /* Overrides the generic `.dx-control` centring, so the button heads its section at the start edge. */
  .dx-error-fallback-section > .dx-button {
    align-self: flex-start;
  }

  .dx-error-fallback-data {
    margin: 0;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1rem;
  }

  .dx-error-stack {
    margin: 0;
    padding: 0;
    list-style: none;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.25rem;
  }

  .dx-error-stack-frame {
    position: relative;
    display: grid;
    grid-template-columns: 1rem minmax(0, 1fr) auto auto;
    column-gap: 0.5rem;
    align-items: center;
  }
  .dx-error-stack-frame[data-local] {
    cursor: pointer;
  }
  .dx-error-stack-frame[data-local]:hover {
    background: var(--color-hover-surface);
  }

  /* Tree connector in the first track: a vertical line through the row (half for the last) and a branch to it. */
  .dx-error-stack-frame::before,
  .dx-error-stack-frame::after {
    content: '';
    position: absolute;
    background: var(--color-neutral-500);
    pointer-events: none;
  }
  .dx-error-stack-frame::before {
    inset-inline-start: 0.5rem;
    inset-block: 0;
    width: 1px;
  }
  .dx-error-stack-frame:last-child::before {
    inset-block-end: 50%;
  }
  .dx-error-stack-frame::after {
    inset-inline-start: 0.5rem;
    top: 50%;
    width: 0.5rem;
    height: 1px;
  }

  .dx-error-stack-function {
    grid-column: 2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-fg-subtle);
  }
  a.dx-error-stack-function {
    color: inherit;
    text-decoration: none;
  }

  .dx-error-stack-file,
  .dx-error-stack-line {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.75rem;
    color: var(--color-fg-subtle);
  }
  .dx-error-stack-line {
    text-align: end;
  }
}
