// Grids introduce a negative vertical margin that we can't allow inside blocks
// otherwise, it breaks the block engine flow.
.block {
  .ui.grid {
    margin-top: 0;
    margin-bottom: 0;
  }
}

[data-rbd-draggable-context-id] {
  margin-bottom: 2rem;
}

.block-editor-title .drag.handle.wrapper {
  top: 5px;
}

// Here should be placed all blocks that receive (faked) focus
.block:focus {
  outline: none;
}

.block .block:not(.inner)::before {
  position: absolute;
  z-index: -1;
  z-index: -1;
  top: -9px;
  left: -9px;
  width: ~'calc(100% + 18px)';
  height: ~'calc(100% + 18px)';
  border: 1px solid rgba(120, 192, 215, 0);
  border-radius: 3px;
  content: '';
}

.block .block-add-button {
  display: inline-block;
}

.block .block.selected::before,
.block .block.selected:hover::before {
  border-width: 1px;
  border-color: rgba(120, 192, 215, 0.75);
}

.block .block:hover::before {
  border-color: rgba(120, 192, 215, 0.375);
}

.block .block.multiSelected::before {
  z-index: 1;
  background-color: rgba(120, 192, 215, 0.375);
}

#toolbar .toolbar-actions .blockCount {
  position: absolute;
  margin-top: 18px;
  margin-left: 15px;
  font-size: x-small;
}

.block.video,
.block.image {
  /* This fixes two left floated items in a row */
  clear: both;
}

// Deprecated
.ui.drag.block:not(:last-child) {
  margin-bottom: 2rem;
}

.ui.drag.block.video,
.ui.drag.block.image {
  z-index: 2;
  // This fixes the floating images in Volto Editor! Muahahaha
  display: block;
  // This fixes two left floated items in a row
  clear: both;
}

.block .ui.image {
  width: 100%;
}

.block .ui.message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  .message-text {
    margin-top: 20px;
    color: #767676;
  }

  span {
    margin-top: 20px;
  }
}

.block.maps {
  position: relative;

  iframe {
    width: 100%;
    height: 45vh;
  }
}

.map-overlay {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

.block.video {
  .ui.embed > .placeholder {
    top: 50%;
    width: unset;
    min-width: 100%;
    height: unset;
    min-height: 100%;
    object-fit: cover;
    transform: translateY(-50%);
  }

  video {
    width: 100%;
  }
}

.block.align.left {
  z-index: 2;

  &.video .video-inner,
  &.maps iframe,
  img {
    margin-right: 1em !important;
    margin-bottom: 1em;
    float: left;
  }

  &.video .video-inner {
    width: 50%;

    .ui.embed {
      background: #fff;
    }

    img {
      max-width: 100%;
    }
  }

  &.maps iframe {
    width: 50%;
    height: 45vh;
  }

  .ui.image,
  img {
    max-width: 50%;
  }
}

.block.align.right {
  z-index: 2;

  &.maps iframe,
  &.video .video-inner,
  img {
    margin-bottom: 1em;
    margin-left: 1em !important;
    float: right;
  }

  &.video .video-inner {
    width: 50%;

    .ui.embed {
      background: #fff;
    }

    img {
      max-width: 100%;
    }
  }

  &.maps iframe {
    width: 50%;
    height: 45vh;
  }

  .ui.image,
  img {
    max-width: 50%;
  }
}

.block.align.center {
  text-align: center;

  iframe,
  img {
    max-width: 100%;
    margin-right: auto;
    margin-left: auto;

    &.medium {
      max-width: 50%;
    }

    &.small {
      max-width: 25%;
    }
  }

  iframe {
    width: 100%;
  }
}

.draggable {
  position: absolute;
  top: 20px;
  left: -32px;
}

// Hacks for the full width image
body .ui.wrapper > .block.align.full,
body.has-toolbar.has-sidebar .ui.wrapper > .ui.inner .block.align.full,
body.has-toolbar-collapsed.has-sidebar
  .ui.wrapper
  > .ui.inner
  .block.align.full,
body.has-toolbar-collapsed.has-sidebar-collapsed
  .ui.wrapper
  > .ui.inner
  .block.align.full,
body.has-toolbar.has-sidebar-collapsed
  .ui.wrapper
  > .ui.inner
  .block.align.full {
  width: 100% !important;

  iframe {
    width: 100%;
  }

  img {
    width: 100%;
  }
}

body.has-toolbar.has-sidebar .ui.wrapper > .ui.inner.block.full,
body.has-toolbar-collapsed.has-sidebar .ui.wrapper > .ui.inner.block.full,
body.has-toolbar-collapsed.has-sidebar-collapsed
  .ui.wrapper
  > .ui.inner.block.full,
body.has-toolbar.has-sidebar-collapsed .ui.wrapper > .ui.inner.block.full {
  width: 100% !important;

  iframe {
    width: 100%;
  }

  img {
    width: 100%;
  }
}

.block.align:not(.right):not(.left) {
  clear: both;
}

.title.block .public-DraftEditorPlaceholder-inner {
  font-size: @h1;
  font-weight: @headerFontWeight;
  line-height: @headerLineHeight;
}

.ui.block.table {
  border: 0;
}

.block {
  position: relative;
  margin-bottom: 1em;

  h1:last-child,
  h2:last-child,
  h3:last-child,
  h4:last-child,
  h5:last-child {
    margin: @headerMargin;
  }

  p {
    margin: @paragraphMargin;
  }

  .toolbar {
    position: absolute;
    z-index: 10;
    top: -32px;
    left: 50%;
    display: flex;
    padding: 4px;
    background-color: rgba(255, 255, 255, 0.975);
    border-radius: 2px;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.05);
    transform: translate(-50%, 0);

    form {
      display: flex;
    }

    & > svg {
      display: inline-block !important;
      box-sizing: content-box;
      padding: 4px;
      margin-right: 4px;
      color: @brown !important;
    }

    .ui.input > input {
      padding: 0;
      border: none;
    }

    .ui.icon.button {
      padding: 4px;
      margin-left: 4px;
      border-radius: 1px;
      color: @brown !important;

      &:hover {
        background-color: #edf1f2 !important;
      }
    }

    .ui.buttons:first-child {
      & .ui.icon.button {
        margin-left: 0;
      }
    }
  }

  .toolbar-inner {
    display: flex;
    width: ~'min(100%, 450px)';
    height: 40px;
    padding: 4px;
    background-color: rgba(255, 255, 255, 0.975);
    border-radius: 2px;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.05);

    form {
      display: flex;
    }

    & > svg {
      display: inline-block !important;
      box-sizing: content-box;
      padding: 4px;
      margin-right: 4px;
      color: @brown !important;
    }

    .ui.input {
      width: 100%;
      margin-left: 8px;
    }

    .ui.input > input {
      padding: 0;
      border: none;
    }

    .ui.icon.button {
      padding: 4px;
      margin-left: 4px;
      border-radius: 1px;
      color: @brown !important;

      &:hover {
        background-color: #edf1f2 !important;
      }
    }

    .ui.buttons:first-child {
      & .ui.icon.button {
        margin-left: 0;
      }
    }
  }

  .ui.active.basic.icon.button {
    border: 1px solid #2996da;
    background: transparent !important;
  }
}

// Hero block
.block.hero {
  clear: both;

  .toolbar {
    left: 25%;
  }

  .hero-body {
    display: flex;

    max-height: 400px;
    flex: 1 1;
    flex-direction: column;
    justify-content: space-between;
    padding: 30px;
    background-color: @tealBackground;
    overflow-y: hidden;

    h1 {
      margin-top: 0;
    }

    p {
      max-height: 287px;
      margin: 0;
      overflow-y: hidden;
      word-break: break-word;
    }

    .link-more {
      text-align: right;
    }
  }

  .hero-image {
    display: block;
    width: auto;
    max-width: 50%;
    height: auto;
    max-height: 400px;
  }

  .image-add {
    min-width: 50%;
  }

  .image-message {
    min-height: 400px !important;
  }

  .block-inner-wrapper {
    position: relative;
    z-index: 1;
    display: flex;
  }

  .title-editor,
  .description-editor {
    max-height: 287px;
    overflow-y: hidden;
    word-break: break-word;
  }
}

.ui.basic.button.block-add-button {
  // .ui.basic.button.block-delete-button {
  position: absolute;
  z-index: 2;
  // margin-top: -21px;
  top: -2px;
  padding: 0;
  border: none;
  margin-bottom: 0;
  -webkit-box-shadow: none;
  box-shadow: none;
  color: #b8c6c8 !important;
  transform: translateX(-40px);

  &:hover,
  &:focus {
    -webkit-box-shadow: none;
    box-shadow: none;
    color: @brown !important;
  }
}

.block .ui.basic.button.delete-button {
  position: absolute;
  top: 0;
  right: 0;
  padding: 0;
  border: none;
  -webkit-box-shadow: none;
  box-shadow: none;

  &:hover,
  &:focus {
    -webkit-box-shadow: none;
    box-shadow: none;
    color: #e40166 !important;
  }
}

// .ui.basic.button.block-delete-button {
//   top: 22px;
//   right: 0;
//   color: #b8c6b8 !important;
//   transform: translateX(40px);

//   &:hover,
//   &:focus {
//     -webkit-box-shadow: none;
//     box-shadow: none;
//     color: #e40166 !important;
//   }
// }

.drag.block.wrapper {
  position: relative;
}

.drag.handle.wrapper {
  position: absolute;
  z-index: 10;
  // top: 1px;
  left: 0;
  color: #b8c6c8;

  .icon {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
  }

  &:hover {
    background-color: #edf1f2;
    color: @brown;
  }
}

// Deprecated
.drag.block.title .drag.handle.wrapper {
  top: 5px;
}

.drag.handle.wrapper.hidden {
  display: none !important;
}

.description.block .public-DraftEditorPlaceholder-inner {
  font-size: 1.125rem;
  line-height: @lineHeight;
}

.callout {
  padding: 1em;
  border: 1px solid rgba(34, 36, 38, 0.15);
  margin: 1rem 0;
  border-radius: 0.28571429rem;
  box-shadow: 0 1px 2px 0 rgba(34, 36, 38, 0.15);
}

.ui.blocker {
  position: absolute;
  z-index: 1;
  width: 100%;
  height: 100%;
}

.separator {
  position: relative;
  top: 5px;
  display: inline-block;
  height: 24px;
  border-right: 1px solid #ddd;
  margin: 0 0 4px 4px;
  vertical-align: bottom;
}

// HTML block
.html-editor {
  z-index: 1;
  background-color: #f3f6f7;
  border-radius: 4px;
  font-family: monospace;
  font-size: @16px;
  word-break: break-all !important;

  &:focus-within textarea {
    caret-color: #e40166;
    outline: 0;
  }
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: #90a4ae;
}

.token.punctuation {
  color: #9e9e9e;
}

.namespace {
  opacity: 0.7;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
  color: #e91e63;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
  color: #4caf50;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
  color: #795548;
}

.token.atrule,
.token.attr-value,
.token.keyword {
  color: #3f51b5;
}

.token.function {
  color: #f44336;
}

.token.regex,
.token.important,
.token.variable {
  color: #ff9800;
}

.token.important,
.token.bold {
  font-weight: bold;
}

.token.italic {
  font-style: italic;
}

.token.entity {
  cursor: help;
}

.link-form-container {
  .inline.field .wrapper {
    min-height: initial;
    border-bottom: none;
  }

  button {
    padding: 0;
    border: 0;
    background: transparent;
    color: @linkColor;
    cursor: pointer;
    text-align: initial;
    text-decoration: underline;

    &:focus {
      outline: none;
    }
  }

  .ui.input {
    min-width: 250px;
  }
}

.blocks-chooser {
  position: absolute;
  z-index: 10;
  top: -12px;
  left: -9px;
  width: 310px;
  padding: 4px;
  background-color: rgba(255, 255, 255, 0.975);
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.05);

  .ui.basic.button {
    display: flex;
    width: 100px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
    margin-top: 5px;
    margin-bottom: 5px;
    border-radius: 3px;
    color: @brown !important;
    hyphens: auto;
    text-align: center;

    &:hover {
      background: #edf2f3 !important;
    }

    .icon {
      margin-bottom: 10px !important;
    }

    &.table {
      border: none;
    }
  }

  .ui.accordion {
    .active {
      display: flex;
    }

    .title {
      display: flex;
      justify-content: space-between;
    }

    .content {
      padding: 0;
    }
  }

  .ui.accordion .title ~ .content,
  .ui.accordion .accordion .title ~ .content {
    // reseting the default Accordion behavior
    display: initial;
  }
}

.accordion-tools {
  display: flex;
  align-items: center;

  .ui.basic.button {
    margin-right: 10px;

    &:hover {
      background-color: transparent !important;
    }
  }
}

// Listing Block
.listing {
  .items-preview {
    color: @teal;
    text-align: center;
  }
}

.listing.message {
  padding: 1.5em;
  background: #f9edbe;
  color: #613a00;
  text-align: center;
}

.listing-item,
.listing-item a {
  display: flex;
  width: 100%;

  @media only screen and (max-width: (@largestMobileScreen)) {
    flex-direction: column;
  }
}

.listing-item {
  margin-bottom: 20px;

  img {
    width: 15%;
    margin-right: 20px;

    @media only screen and (max-width: (@largestMobileScreen)) {
      width: 100%;
      margin: 0;
    }
  }

  .image-placeholder {
    display: flex;
    width: 15%;
    justify-content: center;
    margin-right: 20px;

    img {
      width: 100%;
      max-width: 100%;
    }
  }

  a {
    p {
      color: @textColor;
    }
  }

  @media only screen and (max-width: (@largestMobileScreen)) {
    h3 {
      margin-top: 1em;
    }
  }
}

.sidebar-listing-data {
  &.ui.form.segment,
  &.listing-style {
    padding-bottom: 20px;
  }

  .simple-field-name {
    padding-top: 20px;
    padding-bottom: 10px;
    font-weight: 500;
  }

  .fields {
    flex-wrap: wrap;
    padding-bottom: 20px;
    border-bottom: 1px dotted @borderColor;
  }

  .fields:last-child {
    padding-bottom: 0;
    border-bottom: none;
  }

  .main-fields-wrapper {
    display: flex;
    width: 100%;
    flex: 1 0 auto;
    padding-right: 0.5em;
    padding-left: 0.5em;
  }

  .button .icon {
    margin: 0 !important;
  }
}

.link-form-container {
  // ToDo: Improve CSS in anchor link component (previously from CSS module to normal theme)
  .input-anchorlink-theme {
    width: 240px;
    height: 34px;
    padding: 0 12px;
    border: none;
    background-color: transparent;
    color: #444;
    font-family: inherit;
    font-size: 15px;
  }

  .input-anchorlink-theme:focus {
    outline: none;
  }

  .input-anchorlink-theme::placeholder {
    color: #888;
  }

  .input-anchorlink-theme-Invalid {
    color: #e65757;
  }

  .link-anchorlink-theme {
    color: #007eb1;
    text-decoration: underline;
  }
}

.block.image.align.left,
.block.image.align.right {
  img {
    &.large {
      max-width: 50%;
    }

    &.medium {
      max-width: 25%;
    }

    &.small {
      max-width: 15%;
    }
  }
}

.block.image .no-image-wrapper {
  width: ~'min(100%, 450px)';
}

// Search block
.block.search {
  .search-wrapper {
    display: flex;
    flex-direction: row;
    align-items: center;

    .search-input {
      position: relative;
      width: 100%;

      & + .button {
        margin-left: 1.5em;
      }
    }

    .ui.input > input {
      padding-left: 10px;
    }
  }

  .search-block-prompt {
    display: block;
    margin-bottom: 0.5rem;
  }

  .facets {
    > .facet:first-child {
      padding-top: 0 !important;
    }

    .segment.facet {
      padding-right: 0;
      padding-left: 0;
    }
  }

  .items {
    padding: 1.5em 0;
  }

  .ui.accordion.filter-listing {
    flex: 1 0 auto;
    margin: 1em 0;

    .filter-list-header {
      display: flex;
      justify-content: space-between;
      padding: 0.5rem;
      background-color: #faf8f8;
      border-radius: 0.3rem;
    }

    .active.title .filter-list-title svg {
      transform: rotate(90deg);
    }

    .ui.basic.button:hover {
      background: transparent !important;
    }

    .filter-list-title {
      display: flex;
      align-items: center;
    }

    .filter-list-content {
      padding-top: 0 !important;
    }

    .filter-list-group {
      display: flex;
      align-items: center;
      margin: 0.5rem 0;

      .ui.labels {
        display: flex;
        flex-direction: row;
        align-items: baseline;
        margin-right: 1.2em;
      }

      .ui.label {
        border: 1px solid #f3f3f3;
        margin-left: 0.8em;
        background-color: transparent;
        font-weight: bold;
      }

      .label-title {
        font-size: small;
      }
    }
  }

  .search-sort-wrapper {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    margin: 1em 0 1em 1em;

    .ui.basic.button {
      padding: 3px !important;
    }
  }

  .search-sort-on {
    display: flex;
    flex-direction: row;
    align-items: center;
    margin-right: 0.5em;
  }

  .sort-label {
    margin-right: 0.7em;
  }

  .search-details {
    color: @lightTextColor;
  }

  .search-filters-sort {
    display: flex;
    align-items: flex-start;

    .search-sort-wrapper {
      padding-top: 4px;
    }
  }

  .search-results-count-sort {
    display: flex;
    align-items: center;
    justify-content: space-between;

    .search-details {
      margin: 1em 0;
    }
  }

  .search-input-live-icon-button {
    position: absolute;
    top: 4px;
    right: 4px;

    svg {
      width: 28px !important;
      height: 28px !important;
    }
  }

  .daterange-facet {
    .ui.date-input input {
      height: auto;
    }

    .ui-button {
      margin: 0;
    }

    .DateInput {
      width: 40%;
      min-width: 75px;
    }

    .DateRangePickerInput_arrow_svg {
      margin: 0 6px;
    }

    .DateRangePicker_picker {
      z-index: 10;
    }

    .radio {
      display: flex;
      min-height: 37px;
      align-items: center;
    }
  }
}
