@add-widget-padding: 16px;
@add-widget-border: 1px;
@add-widget-space-or-radius: 8px;
@add-widget-categories: 200px + @add-widget-space-or-radius + @add-widget-border;
@add-widget-widgets: 270px + @add-widget-padding + @add-widget-border;
@add-widget-preview: 407px;
@add-widget-height: 600px;
@add-widget-item-height: 32px;


// 60px comes from padding (32px on the left and 28px on the right)
.modal.add-widget-modal {
  width: 1000px;
  max-width: 90%;
  height: @add-widget-height;
  max-height: 90vh;
  border-radius: @add-widget-space-or-radius;

  .widgetpreview-categorylist .widgetpreview-choosen,
  .widgetpreview-widgetlist .widgetpreview-choosen {
    background-color: @theme-color-background-tinyContrast;

    .widget-button-item,
    .category-button-item {
      color: @theme-color-text;
    }
  }
  .widgetpreview-widgetlist .widgetpreview-unavailable .widget-button-item {
    color: @theme-color-text-disabled;
  }
  // Hovering an already-added row restores the hovered/chosen text colour, so the
  // row reads as focusable rather than staying greyed while it's under the cursor.
  // Two classes give this higher specificity than the disabled rule above, which
  // a same-element hovered+added row would otherwise win.
  .widgetpreview-widgetlist .widgetpreview-choosen.widgetpreview-unavailable .widget-button-item {
    color: @theme-color-text;
  }
}

.add-widget-modal {
  .btn-close.modal-close {
    top: 4px;
    right: 4px;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    padding: 14px;
    color: @theme-color-text-lighter;
  }

  .add-widget-modal-content {
    background: @theme-color-background-contrast;
    display: flex;
    flex-direction: column;
    overflow-x: auto;
    overflow-y: hidden;
    min-width: 0;
    padding: 32px 28px 0 32px;
    -webkit-overflow-scrolling: touch;
  }

  .add-widget-modal-title {
    margin-bottom: 32px;
    text-align: left;
    flex: none;
    font-size: 20px;
    font-weight: 600;
    color: @theme-color-text;
  }

  .add-widget-modal-body {
    display: grid;
    grid-template-columns: @add-widget-categories @add-widget-widgets @add-widget-preview;
    gap: @add-widget-padding;
    flex: 1 1 auto;
    min-height: 0;
    width: max-content;
    min-width: 100%;
  }

  .add-widget-modal-categories,
  .add-widget-modal-widgets,
  .add-widget-modal-preview {
    min-width: 0;
    min-height: 0;
  }

  .add-widget-modal-categories,
  .add-widget-modal-widgets {
    overflow-y: auto;
    overscroll-behavior: contain;
    border-right: @add-widget-border solid @theme-color-background-tinyContrast;
  }
  .add-widget-modal-categories {
    padding-right: @add-widget-space-or-radius;
  }
  .add-widget-modal-widgets {
    padding-right: @add-widget-padding;
  }
  .add-widget-modal-preview {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    align-self: start;
    max-height: 100%;
  }

  // The preview widget hosts arbitrary reports; datatables and other content
  // can be intrinsically wider than the 500px column. Box it in so the widget
  // border stays flush with the column edges and any overflow scrolls inside
  // the inner report rather than stretching the column.
  .widgetpreview-preview .widget {
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
  }

  // Re-apply the global `.widget div.dataTable…` cell-level padding rules
  // (CoreHome/stylesheets/dataTable/_dataTable.less:194 and :498) with higher
  // specificity scoped to the preview pane, so they always take precedence
  // over any layout shrinks the preview column imposes.
  .widgetpreview-preview .widget .card-content div.dataTable:not(.isComparing) table.dataTable th,
  .widgetpreview-preview .widget .card-content div.dataTable:not(.isComparing) table.dataTable tbody > tr > td:not(.cellSubDataTable):first-child {
    padding-left: 30px !important;
  }

  .add-widget-modal-preview .select-wrapper.cohorts-metric-picker {
    min-width: 16rem;
  }

  .widgetpreview-categorylist,
  .widgetpreview-widgetlist {
    width: 100%;
    float: none;
    margin: 0;
    padding: 0;
  }

  .widgetpreview-widgetlist {
    font-weight: normal;
  }

  .widgetpreview-preview {
    float: none;
    width: 100%;
    margin-top: 0;
  }

  .widgetTop {
    cursor: pointer;
  }

  // Overrides the global `ul.widgetpreview-widgetlist li { padding: 0 25px 0 5px }`
  .category-list-item,
  .widget-list-item {
    border-radius: @add-widget-space-or-radius;
    padding: 0;
  }

  .widget-button-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: @add-widget-space-or-radius;
  }

  .category-button-item,
  .widget-button-item {
    width: 100%;
    min-height: @add-widget-item-height;
    border: 0;
    background: transparent;
    box-sizing: border-box;
    color: @theme-color-text-lighter;
    text-align: left;
    font: inherit;
    cursor: inherit;
    font-size: 14px;
    line-height: 20px;
    padding: 4px @add-widget-space-or-radius;
    white-space: normal;
  }

  .widgetpreview-widgetlist .widgetpreview-widgetname {
    flex: 1 1 auto;
    min-width: 0;
    white-space: normal;
  }

  // Keep the focus ring for keyboard users but suppress it after a mouse click,
  // otherwise the row button keeps a dashed outline after selection and leaks
  // into screenshot tests.
  .widgetpreview-categorylist .category-button-item:focus:not(:focus-visible),
  .widgetpreview-widgetlist .widget-button-item:focus:not(:focus-visible) {
    outline: none;
  }

  .widgetpreview-categorylist .category-button-item:focus-visible,
  .widgetpreview-widgetlist .widget-button-item:focus-visible {
    outline: 2px solid @theme-color-focus-ring;
    outline-offset: -2px;
    border-radius: @add-widget-space-or-radius;
  }


  .widgetpreview-choosen::after {
    display: none;
  }

  .widgetpreview-widgetlist .widgetpreview-add-hint {
    flex: 0 0 auto;
    padding: 0 6px;
    color: @theme-color-text-lighter;
    opacity: 0;
    transition: opacity 80ms linear;
    font-size: 12px;
    line-height: 16px;
  }

  .widgetpreview-widgetlist .widgetpreview-choosen .widgetpreview-add-hint {
    opacity: 1;
  }

  // Transient "added" confirmation: the leading "+" becomes a green check on the
  // row just added, reverting once the hover moves elsewhere (see WidgetsList).
  .widgetpreview-widgetlist .widgetpreview-add-check {
    color: @color-green-matomo;
  }
}
