/**
 * Moodle forms HTML isn't changeable via renderers (yet?) so this
 * .less file imports styles from the bootstrap @variables file and
 * adds them to the existing Moodle form CSS ids and classes.
 *
 */

form {
  margin: 0;
}

.mform fieldset .advancedbutton {
  text-align: right;
}

.jsenabled .mform .containsadvancedelements .advanced {
  display: none;
}

.mform .containsadvancedelements .advanced.show {
  display: block;
}

.mform fieldset.group {
  margin-bottom: 0
}

.mform fieldset.error {
  border: 1px solid @errorText;
}

.mform span.error,
#adminsettings span.error {
  display: inline-block;
  border: 1px solid @errorBorder;
  border-radius: 4px;
  background-color: @errorBackground;
  padding: 4px;
  margin-bottom: 4px;
}

.mform fieldset.collapsible legend a.fheader {
  padding: 0 5px 0 20px;
  margin-left: -20px;
  margin-right: 0;
  background-position: 2px center;
  background-repeat: no-repeat;
}

.jsenabled .mform .collapsed .fcontainer {
  display: none;
}

.mform .fitem .fitemtitle div {
  display: inline;
}

#adminsettings span.error,
.loginpanel .error,
.mform .error {
  color: @errorText;
}

.mform .fdescription.required {
  margin-left: @horizontalComponentOffset;
}

.mform .fpassword .unmask {
  display: inline-block;
  margin-left: 0.5em;
  & > input {
    margin: 0;
  }
  & > label {
    display: inline-block;
  }
}

.mform label {
  display: inline-block;
}

.mform .iconhelp {
  margin-left: 4px;
}

.mform .ftextarea #id_alltext {
  width: 100%;
}

.mform ul.file-list {
  padding: 0;
  margin: 0;
  list-style: none;
}

.mform label .req,
.mform label .adv {
  cursor: help;
}

.mform .fcheckbox input {
  margin-left: 0;
  margin-top: 5px;
}

.mform .fitem fieldset.fgroup label,
.mform fieldset.fdate_selector label {
  display: inline;
  float: none;
  width: auto;
}

.mform .ftags label.accesshide {
  display: block;
  position: static;
}

.mform .ftags select {
  margin-bottom: 0.7em;
  min-width: 22em;
}

.mform .helplink img {
  margin: 0 .45em;
  padding: 0;
}

.mform legend .helplink img {
  margin: 0 .2em;
}

.singleselect label {
  margin-left: 0;
  margin-right: .3em;
}

input#id_externalurl {
  direction: ltr;
}

#portfolio-add-button {
  display: inline;
}

// Copying in Bootstrap styles.
.form-item,
.mform .fitem {
  .form-horizontal .control-group;
  margin-bottom: 10px;
  // Theres's a mysterious extra 10px inside this item,
  // so reduce margin by 10px from 20px standard to compensate.
}

.form-item .form-label,
.mform .fitem div.fitemtitle {
  .form-horizontal .control-label
}

.form-defaultinfo,
.form-label .form-shortname {
  .muted;
}

.form-label .form-shortname {
  font-size: @fontSizeMini;
  display: block;
}

.form-item .form-setting,
.form-item .form-description,
.mform .fitem .felement,
#page-mod-forum-search .c1 {
  .form-horizontal .controls
}

.formsettingheading {
  .form-horizontal .help-block
}

// Moodle doesn't differentiate between what Bootstrap calls
// .uneditable-inputs and form help text. Styling them both as
// uneditable looks ugly, styling both as form help is fairly
// subtle in it's impact. Going for the latter as the best option.
.form-item .form-description,
.felement.fstatic {
  .help-block;
  padding-top: 5px;
}

.form-item .form-description {
  padding-top: 0;
}

// Pale grey container for submit buttons.
table#form td.submit,
.form-buttons,
.path-admin .buttons,
#fitem_id_submitbutton,
.fp-content-center form + div,
div.backup-section + form,
#fgroup_id_buttonar {
  .form-actions;
  padding-left: 0;
}

.path-admin .buttons,
.form-buttons {
  // Add back the padding it would usually get from being inside a .form-horizontal.
  padding-left: @horizontalComponentOffset;
}

.form-item .form-setting .form-checkbox.defaultsnext {
  // Need to specify .defaultsnext and the .form-checkbox class
  // is somewhat randomly re-used on various actual checkboxes
  // throughout the admin forms, instead of on the wrapper div.
  margin-top: 5px; // Push down checkboxes to align.
  display: inline-block; // So above style sticks.
}

#adminsettings h3 {
  // Copied from bootstrap/forms.less tag legend.
  display: block;
  width: 100%;
  padding: 0;
  margin-bottom: @baseLineHeight;
  font-size: @baseFontSize * 1.5;
  line-height: @baseLineHeight * 2;
  color: @grayDark;
  border: 0;
  border-bottom: 1px solid #e5e5e5;
}

.mform legend a,
.mform legend a:hover {
  color: @textColor;
  text-decoration: none;
}

#page-grade-edit-outcome-course .courseoutcomes {
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

#page-grade-edit-outcome-course .courseoutcomes td {
  text-align: center;
}

/* Install Process' text fields Forms, should always be justified to the left */
#installform #id_wwwroot,
#installform #id_dirroot,
#installform #id_dataroot,
#installform #id_dbhost,
#installform #id_dbname,
#installform #id_dbuser,
#installform #id_dbpass,
#installform #id_prefix {
  direction: ltr;
}

.mdl-right > label {
  // Workaround for repository pop-up because the : are outside the label,
  // can/should be fixed in filemanager renderers.
  display: inline-block;
}

// Checkbox labels. Bootstrap puts the associated checkbox inside the label.
// Moodle puts it beside the label, so we need to make it inline-block
// to keep it on the same horizontal level.
input[type="radio"] + label,
input[type="checkbox"] + label {
  display: inline;
  padding-left: 0.2em;
}

input[type="radio"],
input[type="checkbox"] {
  margin-top: -4px; // Dodgy hack, must be better way.
  margin-left: auto;
  margin-right: 7px;
}

.singleselect {
  display: inline-block;
  form,
  select {
    margin: 0;
  }
}

.form-item .form-label label {
  margin-bottom: 0;
}

.felement.ffilepicker {
  margin-top: 5px;
}

div#dateselector-calendar-panel {
  z-index: 3100; /* Set higher than the z-index of the filemanager - see MDL-39047. */
}

fieldset.coursesearchbox label {
  display: inline;
}

/**
 * Show the labels above text editors and file managers except on wide screens.
 */
#region-main .mform:not(.unresponsive) .fitem .fitemtitle label {
  font-weight: bold;
}

.makeFormsVertical() {
  #region-main .mform:not(.unresponsive) {
    .fitem {
      .fitemtitle {
        display: block;
        margin-top: 4px;
        margin-bottom: 4px;
        text-align: left;
        width: 100%;
      }
      .felement {
        margin-left: 0;
        width: 100%;
        float: left;
        padding-left: 0;
        padding-right: 0;
      }
      .fstatic:empty {
        display: none;
      }
    }
    .femptylabel {
      .fitemtitle {
        display: inline-block;
        width: auto;
        margin-right: 8px;
      }
      .felement {
        display: inline-block;
        margin-top: 4px;
        padding-top: 5px;
        width: auto;
      }
    }
    .fitem_fcheckbox {
      .fitemtitle,
      .felement {
        display: inline-block;
        width: auto;
      }
      .felement {
        padding: 6px;
      }
    }
  }
}

/**
 * Make forms vertical when the screen is less than 1200px;
 */
@media (max-width: 1199px) {
  body {
    .makeFormsVertical;
  }
}

/**
 * Make forms vertical when the screen is less than 1474px AND both side-pre and side-post contain blocks.
 * This is an extra special media rule.
 * It causes forms to show vertically when the screen size is calculated as:
 * 1199px + (1199px * 23%)
 * Where 23% is the width of span3
 * Full calculation is:
 *   @maxWidthForVerticalForms: 1199px * (unit(((@fluidGridColumnWidth1200 * 3) + (@fluidGridGutterWidth * (3 - 1)))) / 100) + 1199px;
 */
@maxWidthForVerticalForms: 1474px;
@media (max-width: @maxWidthForVerticalForms) {
  .used-region-side-pre.used-region-side-post {
    .makeFormsVertical;
  }
}

/* Section and module editing forms contain special JS components for the
   availability system (if enabled). */
#fitem_id_availabilityconditionsjson {
  *[aria-hidden=true] {
    display: none;
  }
  select,
  input[type=text] {
    position: relative;
    top: 4px;
  }
  label {
    display: inline;
  }
  .availability-group {
    margin-right: 8px;
  }
  .availability-item {
    margin-bottom: 6px;
  }
  .availability-none {
    margin-left: 20px;
    margin-bottom: 4px;
  }
  .availability-plugincontrols {
    padding: 2px 0px 0px 4px;
    background: none repeat scroll 0% 0% @wellBackground;
    border: 1px solid @grayLighter;
    border-radius: 4px;
    display: inline-block;
    margin-right: 8px;
  }
  /* Eye icon in front of an item and delete icon after it. */
  .availability-eye,
  .availability-delete {
    margin-right: 8px;
  }
  /* Hidden eye icon still takes up space. */
  .availability-eye[aria-hidden=true] {
    display: inline;
    visibility: hidden;
  }
  /* Eye icons in front of child lists are aligned specially. */
  .availability-list > .availability-eye img {
    vertical-align: top;
    margin-top: 12px;
  }
  /* Add button lines up with child elements. */
  .availability-button {
    margin-left: 15px;
  }
  /* Nested section is grey. */
  .availability-childlist > .availability-inner {
    display: inline-block;
    background: @wellBackground;
    border: 1px solid @grayLighter;
    border-radius: 4px;
    padding: 6px;
    margin-bottom: 6px;
  }
  /* Second (and more) levels of nested sections are white. */
  .availability-childlist .availability-childlist > .availability-inner {
    background: white;
  }
  /* Connecting text needs to be indented. */
  .availability-connector {
    margin-left: 20px;
    margin-bottom: 6px;
  }
}

/* Default form styling colours all text red. With availability conditions
   this looks excessive as we show 'Invalid' markers in specific places. */
.mform .error .availability-field {
  color: @textColor;
}

/* This dialogue is used to add an availability condition. */
.availability-dialogue {
  .moodle-dialogue .moodle-dialogue-bd {
    padding-left: 0;
    padding-right: 0;
    padding-bottom: 2px;
  }
  ul {
    display: block;
    margin: 0;
  }
  li {
    display: block;
    list-style-type: none;
    padding: 0 0 4px;
    clear: both;
    border-bottom: 1px solid @grayLighter;
    margin-bottom: 4px;
  }
  ul button {
    float: left;
    margin-left: 1em;
    min-width: 140px;
    margin-top: 4px;
  }
  label {
    margin-left: 170px;
    margin-right: 1em;
    margin-bottom: 0;
  }
  .availability-buttons button {
    margin-left: 1em;
    margin-right: 1em;
    margin-top: 4px;
  }
}

/* Revert to the non-fixed width where a textarea has the number of columns
   specified, or an input has it's size specified. */
textarea[cols],
input[size] {
  width: auto;
}
