// out: ../style-template.css, compress:true

.markdown-preview {
  width: 100%;
  height: 100%;
  box-sizing: border-box;

  .pagebreak,
  .newpage {
    page-break-before: always;
  }

  // code block line numbers 
  pre.line-numbers {
    position: relative;
    padding-left: 3.8em;
    counter-reset: linenumber;

    &>code {
      position: relative;
    }

    .line-numbers-rows {
      position: absolute;
      pointer-events: none;
      top: 1em;
      font-size: 100%;
      left: 0; //-3.8em;
      width: 3em;
      /* works for line-numbers below 1000 lines */
      letter-spacing: -1px;
      border-right: 1px solid #999;

      -webkit-user-select: none;
      -moz-user-select: none;
      -ms-user-select: none;
      user-select: none;

      &>span {
        pointer-events: none;
        display: block;
        counter-increment: linenumber;
      }

      &>span:before {
        content: counter(linenumber);
        color: #999;
        display: block;
        padding-right: 0.8em;
        text-align: right;
      }
    }
  }

  // MathJax
  .mathjax-exps .MathJax_Display {
    text-align: center !important;
  }

  &:not([for="preview"]) {
    .code-chunk {
      .btn-group {
        display: none;
      }

      .status {
        display: none;
      }

      .output-div {
        margin-bottom: 16px;
      }
    }
  }

  // TOC
  .md-toc {
    padding: 0;
    
    .md-toc-link-wrapper {
      .md-toc-link {
        display: inline;
        padding: 0.25rem 0;

        p,
        div {
          display: inline;
        }
      }

      &.highlighted {
        .md-toc-link {
          font-weight: 800;
        }
      }
    }
  }
}

.scrollbar-style {
  &::-webkit-scrollbar {
    width: 8px;
  }

  &::-webkit-scrollbar-track {
    // -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
    border-radius: 10px;
    background-color: transparent;
  }

  &::-webkit-scrollbar-thumb {
    border-radius: 5px; // -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
    background-color: rgba(150, 150, 150, .66);
    border: 4px solid rgba(150, 150, 150, .66);
    background-clip: content-box;
  }
}

html body[for="html-export"]:not([data-presentation-mode]) {
  @sidebar-toc-width: 300px;

  position: relative;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  margin: 0;
  padding: 0; // <= this has to be zero; otherwise prince export will have issue.  
  overflow: auto;

  .markdown-preview {
    position: relative;
    top: 0;

    @media screen and (min-width: 914px) {
      padding: 2em calc(~"50% - 457px + 2em");
    }

    @media screen and (max-width: 914px) {
      padding: 2em;
    }

    // mobile
    @media screen and (max-width: 450px) {
      font-size: 14px !important; // <= this line is necessary. otherwise #sidebar-toc-btn position will be wrong.  
      padding: 1em;
    }
  }

  @media print {
    #sidebar-toc-btn {
      display: none;
    }
  }

  #sidebar-toc-btn {
    // please note that this is different from the one in preview.less
    position: fixed;
    bottom: 8px;
    left: 8px;
    font-size: 28px;
    cursor: pointer;
    color: inherit;
    z-index: 99;
    width: 32px;
    text-align: center;
    opacity: 0.4;
  }

  &[html-show-sidebar-toc] {
    #sidebar-toc-btn {
      opacity: 1.0
    }

    .md-sidebar-toc {
      .scrollbar-style();

      position: fixed;
      top: 0;
      left: 0;
      width: @sidebar-toc-width;
      height: 100%;
      padding: 32px 0 48px 0;
      font-size: 14px;
      box-shadow: 0 0 4px rgba(150, 150, 150, 0.33);
      box-sizing: border-box;
      overflow: auto;
      background-color: inherit;

      a {
        text-decoration: none;
      }

      .md-toc {
        padding: 0 16px;
        
        .md-toc-link-wrapper {
          .md-toc-link {
            display: inline;
            padding: 0.25rem 0;

            p,
            div {
              display: inline;
            }
          }

          &.highlighted {
            .md-toc-link {
              font-weight: 800;
            }
          }
        }
      }
    }

    .markdown-preview {
      left: @sidebar-toc-width;
      width: calc(~"100% - "@sidebar-toc-width);
      padding: 2em calc(~"50% - 457px - "(@sidebar-toc-width/2));
      margin: 0;
      box-sizing: border-box;

      @media screen and (max-width: (914px+@sidebar-toc-width+60px)) {
        padding: 2em;
      }

      // mobile
      @media screen and (max-width: 450px) {
        width: 100%;
      }
    }
  }

  &:not([html-show-sidebar-toc]) {
    .markdown-preview {
      left: 50%;
      transform: translateX(-50%);
    }

    .md-sidebar-toc {
      display: none;
    }
  }
}
