/*
 * Size metrics: the only source of truth for sizes (decision 2); every `.dx-*` part that takes a `size` sets
 * `data-size` and inherits the rest. Controls are inset in the block (decision 12); one icon scale serves rail Blocks
 * and controls. Labels read one text step below the body (`--dx-label-font-size`), and help text takes the next-smaller
 * size's label step (`--dx-helper-font-size`; xs and sm have no smaller step, so theirs equals the label's).
 * `--dx-half-block-size` is redeclared per size (like `--dx-control-size`) so it resolves against that size's block.
 */

@layer dx-components {
  /* Defaults for parts rendered outside any sized scope (e.g. portalled popups). */
  :root {
    --dx-block-size: 2rem;
    --dx-line-height: var(--text-base--line-height);
    --dx-font-size: var(--text-base);
    --dx-label-font-size: var(--text-sm);
    --dx-label-line-height: var(--text-sm--line-height);
    --dx-helper-font-size: var(--text-xs);
    --dx-helper-line-height: var(--text-xs--line-height);
    --dx-icon-size: 1rem;
    --dx-gap-size: 0.5rem;
    --dx-control-inset: 2px;
    --dx-control-icon: 1rem;
    --dx-control-size: calc(var(--dx-block-size) - 2 * var(--dx-control-inset));
    --dx-half-block-size: calc(var(--dx-block-size) / 2);
    /* The column a label beside its value takes, so labels down a form line their values up. */
    --dx-label-width: 5rem;
  }

  :is(
    .dx-scope,
    .dx-panel,
    .dx-listbox,
    .dx-drag-preview,
    .dx-container,
    .dx-scroll-root,
    .dx-toolbar,
    .dx-popup,
    .dx-field-header,
    .dx-dialog,
    .dx-dialog-footer,
    .dx-fieldset-legend,
    .dx-avatar,
    .dx-button,
    .dx-card,
    .dx-tree,
    .dx-pin-input,
    .dx-number-input
  )[data-size='xs'] {
    --dx-block-size: 1.25rem;
    --dx-line-height: var(--text-xs--line-height);
    --dx-font-size: var(--text-xs);
    --dx-label-font-size: var(--text-xs);
    --dx-label-line-height: var(--text-xs--line-height);
    --dx-helper-font-size: var(--text-xs);
    --dx-helper-line-height: var(--text-xs--line-height);
    --dx-icon-size: 0.75rem;
    --dx-gap-size: 0.25rem;
    --dx-control-inset: 1px;
    --dx-control-icon: 0.75rem;
    --dx-control-size: calc(var(--dx-block-size) - 2 * var(--dx-control-inset));
    --dx-half-block-size: calc(var(--dx-block-size) / 2);
  }

  :is(
    .dx-scope,
    .dx-panel,
    .dx-listbox,
    .dx-drag-preview,
    .dx-container,
    .dx-scroll-root,
    .dx-toolbar,
    .dx-popup,
    .dx-field-header,
    .dx-dialog,
    .dx-dialog-footer,
    .dx-fieldset-legend,
    .dx-avatar,
    .dx-button,
    .dx-card,
    .dx-tree,
    .dx-pin-input,
    .dx-number-input
  )[data-size='sm'] {
    --dx-block-size: 1.5rem;
    --dx-line-height: var(--text-sm--line-height);
    --dx-font-size: var(--text-sm);
    --dx-label-font-size: var(--text-xs);
    --dx-label-line-height: var(--text-xs--line-height);
    --dx-helper-font-size: var(--text-xs);
    --dx-helper-line-height: var(--text-xs--line-height);
    --dx-icon-size: 0.875rem;
    --dx-gap-size: 0.25rem;
    --dx-control-inset: 2px;
    --dx-control-icon: 0.875rem;
    --dx-control-size: calc(var(--dx-block-size) - 2 * var(--dx-control-inset));
    --dx-half-block-size: calc(var(--dx-block-size) / 2);
  }

  :is(
    .dx-scope,
    .dx-panel,
    .dx-listbox,
    .dx-drag-preview,
    .dx-container,
    .dx-scroll-root,
    .dx-toolbar,
    .dx-popup,
    .dx-field-header,
    .dx-dialog,
    .dx-dialog-footer,
    .dx-fieldset-legend,
    .dx-avatar,
    .dx-button,
    .dx-card,
    .dx-tree,
    .dx-pin-input,
    .dx-number-input
  )[data-size='md'] {
    --dx-block-size: 2rem;
    --dx-line-height: var(--text-base--line-height);
    --dx-font-size: var(--text-base);
    --dx-label-font-size: var(--text-sm);
    --dx-label-line-height: var(--text-sm--line-height);
    --dx-helper-font-size: var(--text-xs);
    --dx-helper-line-height: var(--text-xs--line-height);
    --dx-icon-size: 1rem;
    --dx-gap-size: 0.5rem;
    --dx-control-inset: 2px;
    --dx-control-icon: 1rem;
    --dx-control-size: calc(var(--dx-block-size) - 2 * var(--dx-control-inset));
    --dx-half-block-size: calc(var(--dx-block-size) / 2);
  }

  :is(
    .dx-scope,
    .dx-panel,
    .dx-listbox,
    .dx-drag-preview,
    .dx-container,
    .dx-scroll-root,
    .dx-toolbar,
    .dx-popup,
    .dx-field-header,
    .dx-dialog,
    .dx-dialog-footer,
    .dx-fieldset-legend,
    .dx-avatar,
    .dx-button,
    .dx-card,
    .dx-tree,
    .dx-pin-input,
    .dx-number-input
  )[data-size='lg'] {
    --dx-block-size: 2.5rem;
    --dx-line-height: var(--text-lg--line-height);
    --dx-font-size: var(--text-lg);
    --dx-label-font-size: var(--text-base);
    --dx-label-line-height: var(--text-base--line-height);
    --dx-helper-font-size: var(--text-sm);
    --dx-helper-line-height: var(--text-sm--line-height);
    --dx-icon-size: 1.25rem;
    --dx-gap-size: 0.5rem;
    --dx-control-inset: 3px;
    --dx-control-icon: 1.25rem;
    --dx-control-size: calc(var(--dx-block-size) - 2 * var(--dx-control-inset));
    --dx-half-block-size: calc(var(--dx-block-size) / 2);
  }

  :is(
    .dx-scope,
    .dx-panel,
    .dx-listbox,
    .dx-drag-preview,
    .dx-container,
    .dx-scroll-root,
    .dx-toolbar,
    .dx-popup,
    .dx-field-header,
    .dx-dialog,
    .dx-dialog-footer,
    .dx-fieldset-legend,
    .dx-avatar,
    .dx-button,
    .dx-card,
    .dx-tree,
    .dx-pin-input,
    .dx-number-input
  )[data-size='xl'] {
    --dx-block-size: 3rem;
    --dx-line-height: var(--text-xl--line-height);
    --dx-font-size: var(--text-xl);
    --dx-label-font-size: var(--text-lg);
    --dx-label-line-height: var(--text-lg--line-height);
    --dx-helper-font-size: var(--text-base);
    --dx-helper-line-height: var(--text-base--line-height);
    --dx-icon-size: 1.5rem;
    --dx-gap-size: 0.5rem;
    --dx-control-inset: 3px;
    --dx-control-icon: 1.5rem;
    --dx-control-size: calc(var(--dx-block-size) - 2 * var(--dx-control-inset));
    --dx-half-block-size: calc(var(--dx-block-size) / 2);
  }
}
