/*
 * Panel (Phase 4 decision 1): the plank host. It fills its parent, stacks header, body and footer, and is the pane's
 * query container (decision 5), so every template root inside collapses at the panel's width.
 */

@layer dx-components {
  /* A pane hosted by a popup (a form in a popover) is part of the popup's surface, not a base-level plank inside it. */
  .dx-popup .dx-panel[data-surface='base'] {
    --surface-bg: var(--dx-surface-popup);
  }
  /* Likewise a pane in a dialog (a settings form) is the dialog's raised surface. */
  .dx-dialog .dx-panel[data-surface='base'] {
    --surface-bg: var(--dx-surface-raised);
  }
  /*
   * A header or footer is a bar, a step lighter than the plank it belongs to. In a popup or a dialog there is no
   * plank under it: the surface is already raised, so the band reads as a strip of its own. `inherit` takes the
   * panel's surface, whichever of the two rules above gave it.
   */
  .dx-popup .dx-panel > .dx-panel-header,
  .dx-popup .dx-panel > .dx-panel-footer,
  .dx-dialog .dx-panel > .dx-panel-header,
  .dx-dialog .dx-panel > .dx-panel-footer {
    --surface-bg: inherit;
  }

  /* Header and footer rows size to their content, so a missing or empty one takes no space. */
  .dx-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    /* `clip`, not `hidden`: a hidden box can still be scrolled by focus or scrollIntoView, which shifts the body under
       the header and leaves a gap below it; only the body scrolls. */
    overflow: clip;
    font-size: var(--dx-font-size);
    line-height: var(--dx-line-height);
    container-type: inline-size;
  }

  /* Rows are placed explicitly, so a panel without a header still puts its body in the growing track. */
  .dx-panel-header {
    grid-row: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  /* A header that is the toolbar (`Panel.Header asChild`) keeps the toolbar's row, or its centring acts across it. */
  .dx-panel-header.dx-toolbar {
    flex-direction: row;
  }
  /*
   * An article's toolbar is the app's toolbar height (ui-theme `--dx-toolbar-size`), its controls centred in it; a panel
   * given its own size keeps that size's block-tall header.
   */
  .dx-panel:not([data-size]) > .dx-panel-header .dx-toolbar,
  .dx-panel:not([data-size]) > .dx-panel-header.dx-toolbar {
    min-height: var(--dx-toolbar-size, 2.5rem);
  }

  /*
   * A plain slot; it is no query container even when it is a ScrollArea frame (`asChild`), so the content collapses
   * against the panel.
   */
  .dx-panel > .dx-panel-body {
    grid-row: 2;
    min-width: 0;
    min-height: 0;
    container-type: normal;
  }

  /* A scrolling Body pads its viewport rather than narrowing the frame, so the scrollbar stays at the panel's edge. */
  .dx-panel[data-width='document'] > .dx-panel-body > .dx-scroll-viewport {
    padding-inline: max(0px, calc((100% - var(--spacing-document-max-width, 50rem)) / 2));
  }

  .dx-panel-footer {
    grid-row: 3;
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
}
