/*
 * do not edit this file.
 * see the following change record for more information,
 * https://www.drupal.org/node/3084859
 * @preserve
 */

/**
 * @file
 * styles for the managed file widget.
 *
 * this includes the styles for the file widgets and the image widgets.
 */

/**
 * the root element of the file/image widget.
 */

.form-managed-file.no-upload {
  display: inline-flex;
  flex-direction: column;
  max-width: 100%;
}

.form-managed-file.has-value.is-multiple {
  display: block;
}

/**
 * the main element of the file/image widget.
 *
 * this contains the upload input and the upload of the empty file/image
 * widgets, or the file name (with icon and size) and the remove button of
 * filled widgets.
 *
 * the inline-flex display shrinks the width to the minimal needed amount. this
 * helps to keep the remove as close to the other elements as possible.
 */

.form-managed-file__main {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
}

/**
 * inside (draggable) tables, this should be flex-displayed. this keeps even
 * long file names in the same visual line where the drag handle is.
 */

.draggable .form-managed-file.has-value .form-managed-file__main {
  display: flex;
}

/* add some bottom margin for single widgets if no meta is present. */

.form-managed-file.is-single.has-value .form-managed-file__main:last-child {
  margin-bottom: 1rem;
}

/**
 * the 'meta' element of the file/image widget.
 *
 * this element is available only if the file widget has a value and when there
 * are other input options than the ones rendered in the 'main' element.
 * these inputs are:
 *  - file description and/or the file display checkbox of file widgets
 *  - image alt and/or title text as well as the preview image of the image
 *    widgets.
 *
 * the trick here is that we will display the alt/title inputs next to the image
 * preview if there is enough space left. enough space means the value of the
 * '--file-widget-form-item-min-width' variable.
 */

.form-managed-file__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  margin-top: 1rem; /* bottom margin will be added by the child elements: because of we use flex display here, our margins won't collapse. */
}

/**
 * in tables, this should be inline-flex. this is needed to make this element be
 * pushed to a new line, to the bottom of the drag handle.
 */

.draggable .form-managed-file.has-value .form-managed-file__meta {
  display: inline-flex;
}

/**
 * internet explorer 11 does not shrinks our meta elements if one of its parent
 * element is a table. without this fix, the file widgets table cell would have
 * the same width that is needed for displaying the file name in a single line.
 *
 * @see https://github.com/philipwalton/flexbugs/issues/179
 */

@media all and (-ms-high-contrast: active), (-ms-high-contrast: none) {
  *::-ms-backdrop,
  td .form-managed-file__meta {
    flex-basis: 100%;
  }
}

/**
 * the 'image preview' element.
 *
 * this is used and display only by the image widget.
 */

.form-managed-file__image-preview {
  flex: 0 0 auto;
  max-width: 100%;
  margin-bottom: 1rem;
}

/* add some 'end' margin if there are other meta inputs. */

.form-managed-file.has-meta .form-managed-file__image-preview {
  margin-right: 1rem; /* ltr */
}

[dir="rtl"] .form-managed-file.has-meta .form-managed-file__image-preview {
  margin-right: 0;
  margin-left: 1rem;
}

/**
 * if this is rendered inside a file multiple table and there are no alt or
 * title, we have to reduce the amount of the bottom margin.
 */

td .form-managed-file.no-meta .form-managed-file__image-preview {
  margin-bottom: 0.5rem;
}

/**
 * the children of the 'meta items' element are the inputs that were described
 * at the 'meta' element '.form-managed-file__meta', except of the image
 * preview.
 *
 * the flex-basis is set to the minimal width where we can display these inputs
 * next tho the preview image.
 *
 * we limit the max width directly on the '.form-item' elements.
 */

.form-managed-file__meta-items {
  flex: 1 1 16rem;
  max-width: 100%;
}

/**
 * internet explorer 11 does not increase the width of those flex items that are
 * allowed to be wrapped. we just simply change the basis to the max-width.
 */

@media all and (-ms-high-contrast: active), (-ms-high-contrast: none) {
  *::-ms-backdrop,
  .form-managed-file__meta-items {
    flex-basis: 32rem;
  }
}

/**
 * meta items wrapper.
 * this markup element is needed only for working around the same ie 11 bug that
 * is described above, at the 'meta' element.
 *
 * @see https://github.com/philipwalton/flexbugs/issues/179
 */

@media all and (-ms-high-contrast: active), (-ms-high-contrast: none) {
  *::-ms-backdrop,
  td .form-managed-file__meta-wrapper {
    display: flex;
  }
}

/**
 * modify component defaults for file/image widgets.
 */

/**
 * file component style overrides for managed file widgets.
 */

.form-managed-file .file {
  word-break: break-all;
  -webkit-hyphens: auto;
  -ms-hyphens: auto;
  hyphens: auto;
}

.form-managed-file .file__size {
  word-break: normal;
}

.form-managed-file__main .file {
  flex: 1 1 auto;
  margin: 0.5rem 1rem 0.5rem 0; /* ltr */
}

[dir="rtl"] .form-managed-file__main .file {
  margin-right: 0;
  margin-left: 1rem;
}

/**
 * fix and override the table-related bug of internet explorer 11 (described at
 * the 'meta' element).
 *
 * @see https://github.com/philipwalton/flexbugs/issues/179
 */

@media all and (-ms-high-contrast: active), (-ms-high-contrast: none) {
  *::-ms-backdrop,
  td .form-managed-file__main .file {
    flex: 0 1 100%;
  }
}

/**
 * the file upload input.
 */

.form-managed-file__main .form-element--api-file {
  flex: 1 1 auto;
  min-width: 1px; /* this makes the element shrink on ie11 */
}

/**
 * remove the default button margins and prevent shrinking or growing buttons.
 * this applies both on the 'no-js' upload button and the remove button. the
 * weight of this ruleset has been increase for this to take effect on rtl.
 */

.form-managed-file__main .button.button {
  flex: 0 0 auto;
  margin: 0;
}

/**
 * limiting the width of form items inside the meta element.
 */

.form-managed-file__meta .form-item {
  max-width: 32rem;
  margin-top: 0; /* top margin is added by the parent element */
  margin-bottom: 1rem;
}

/**
 * reduce the bottom margin of the last 'meta' form-item for field multiple
 * tables.
 */

.form-managed-file__meta .form-item:last-child {
  margin-bottom: 0.5rem;
}

.form-managed-file__meta .form-element {
  width: 100%;
}

/**
 * add side margins if a table precedes the managed file form element.
 */

.file-widget-multiple.has-table .form-type--managed-file {
  margin-right: 1rem;
  margin-left: 1rem;
}

