@import "./media-queries";
@import "./icons";

$font-size-normal: 0.75em;
$opacity-normal: 0.6;
$opacity-disabled: 0.125;
$opacity-active: 1;

trix-toolbar {
  * {
    box-sizing: border-box;
  }

  .trix-button-row {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    overflow-x: auto;
  }

  .trix-button-group {
    display: flex;
    margin-bottom: 10px;
    border: 1px solid #bbb;
    border-top-color: #ccc;
    border-bottom-color: #888;
    border-radius: 3px;

    &:not(:first-child) {
      margin-left: 1.5vw;

      @include phone {
        margin-left: 0;
      }
    }
  }

  .trix-button-group-spacer {
    flex-grow: 1;

    @include phone {
      display: none;
    }
  }

  .trix-button {
    position: relative;
    float: left; // Collapse whitespace between elements
    color: rgba(0,0,0, $opacity-normal);
    font-size: $font-size-normal;
    font-weight: 600;
    white-space: nowrap;
    padding: 0 0.5em;
    margin: 0;
    outline: none;
    border: none;
    border-bottom: 1px solid #ddd;
    border-radius: 0;
    background: transparent;

    &:not(:first-child) {
      border-left: 1px solid #ccc;
    }

    &.trix-active {
      background: #cbeefa;
      color: rgba(0,0,0, $opacity-active);
    }

    &:not(:disabled) {
      cursor: pointer;
    }

    &:disabled {
      color: rgba(0,0,0, $opacity-disabled);
    }

    @include phone {
      letter-spacing: -0.01em;
      padding: 0 0.3em;
    }
  }

  .trix-button--icon {
    font-size: inherit;
    width: 2.6em;
    height: 1.6em;
    max-width: calc(0.8em + 4vw);
    text-indent: -9999px;

    @include phone {
      height: 2em;
      max-width: calc(0.8em + 3.5vw);
    }

    &::before {
      display: inline-block;
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      opacity: $opacity-normal;
      content: "";
      background-position: center;
      background-repeat: no-repeat;
      background-size: contain;

      @include phone {
        right: 6%;
        left: 6%;
      }
    }

    &.trix-active::before {
      opacity: $opacity-active;
    }

    &:disabled::before {
      opacity: $opacity-disabled;
    }
  }

  .trix-button--icon-attach::before { background-image: $icon-attach; top: 8%; bottom: 4%; }
  .trix-button--icon-bold::before { background-image: $icon-bold; }
  .trix-button--icon-italic::before { background-image: $icon-italic; }
  .trix-button--icon-link::before { background-image: $icon-link; }
  .trix-button--icon-strike::before { background-image: $icon-strike; }
  .trix-button--icon-quote::before { background-image: $icon-quote; }
  .trix-button--icon-heading-1::before { background-image: $icon-heading-1; }
  .trix-button--icon-code::before { background-image: $icon-code; }
  .trix-button--icon-bullet-list::before { background-image: $icon-bullets; }
  .trix-button--icon-number-list::before { background-image: $icon-numbers; }
  .trix-button--icon-undo::before { background-image: $icon-undo; }
  .trix-button--icon-redo::before { background-image: $icon-redo; }
  .trix-button--icon-decrease-nesting-level::before { background-image: $icon-nesting-level-decrease; }
  .trix-button--icon-increase-nesting-level::before { background-image: $icon-nesting-level-increase; }

  .trix-dialogs {
    position: relative;
  }

  .trix-dialog {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    font-size: $font-size-normal;
    padding: 15px 10px;
    background: #fff;
    box-shadow: 0 0.3em 1em #ccc;
    border-top: 2px solid #888;
    border-radius: 5px;
    z-index: 5;
  }

  .trix-input--dialog {
    font-size: inherit;
    font-weight: normal;
    padding: 0.5em 0.8em;
    margin: 0 10px 0 0;
    border-radius: 3px;
    border: 1px solid #bbb;
    background-color: #fff;
    box-shadow: none;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;

    &.validate:invalid {
      box-shadow: #F00 0px 0px 1.5px 1px;
    }
  }

  .trix-button--dialog {
    font-size: inherit;
    padding: 0.5em;
    border-bottom: none;
  }

  .trix-dialog--link {
    max-width: 600px;
  }

  .trix-dialog__link-fields {
    display: flex;
    align-items: baseline;

    .trix-input {
      flex: 1;
    }

    .trix-button-group {
      flex: 0 0 content;
      margin: 0;
    }
  }
}
