// =============================================================================
// Global Form Styles
// (c) Mathigon
// =============================================================================


@import "variables";


form, input, button, select, textarea { border: none; margin: 0; padding: 0; }
input:invalid { box-shadow: none; }

input, button, select, textarea {
  display: inline-block;
  background: transparent;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
}

input[type="email"], input[type="text"], input[type="password"], input[type="date"], textarea { cursor: text; }
select, button { cursor: pointer; }


// -----------------------------------------------------------------------------
// Form and Large Inputs

form.form-large { max-width: 600px; margin: 0 auto }
.form-row { display: flex; flex-direction: row; flex-wrap: wrap; }
.form-row .form-field { width: 180px; flex-grow: 1; }
.form-large p { margin: 0 8px 16px; }
.form-large .btn { margin: 12px 8px; }

.form-field { display: block; position: relative; padding: 8px; }

.form-field input, .form-field select, .form-field textarea, .form-field-style {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background: no-repeat #{"top 12px right 10px / 24px 24px"};
  border: 1px solid;
  @include theme(background-color, #f6f6f6, mix($dark-mode, white, 85%));
  @include theme(border-color, rgba(black, 10%), rgba(white, 50%));
  @include theme(color, black, white);
  border-radius: 4px;
  box-sizing: border-box;
  display: block;
  line-height: 1.4em;
  padding: 18px 16px 4px;
  transition: border .2s, background .2s, box-shadow .2s;
  width: 100%;

  &:not([disabled]) {
    &:hover, &:focus { @include theme(background-color, #eee, mix($dark-mode, white, 70%)); }
    &:focus { border-color: $blue; box-shadow: 0 0 0 3px rgba($blue, 50%); outline: none; }
    &:focus + .placeholder { color: $blue; }
  }
  &[disabled] { cursor: default !important; opacity: 0.6; }

  &.no-label { padding-top: 4px; background-position: top 5px right 10px; }
}

.form-field input {
  &::placeholder { opacity: 0; }
  &:placeholder-shown { padding: 11px 16px; }
  &:placeholder-shown + .placeholder { transform: none; }

  &.dirty:not(:focus) {
    padding-right: 36px;
    &:valid, &.valid { background-image: icon('check', $success); }
    &:invalid, &.invalid { background-image: icon('warning', $error); border-color: $error; }
  }
}

.form-field textarea {
  height: auto;
  resize: vertical;
  padding: 10px 16px;
  // TODO Can we have animated placeholders for text boxes?
  &::placeholder  { color: #aaa; opacity: 1; transition: color .2s; }
  &:focus::placeholder, &:active::placeholder { color: $blue; }
}

.form-field select {
  padding-right: 40px;
  background-image: icon('dropdown', '#4d4d4d');
}

.form-field {
  .form-hint, .form-error { margin: 4px 17px 0; font-size: 14px; line-height: 1.3; }
  .form-error { color: $error; }
}

.form-field .placeholder {
  position: absolute;
  line-height: 1.4em;
  top: 19px;
  left: 24px;
  transition: transform .2s, color .2s;
  color: #aaa;
  transform-origin: top left;
  transform: translateY(-7px) scale(0.7);
  pointer-events: none;
  user-select: none;
}

.form-checkbox {
  padding-left: 40px;
  min-height: 28px;
  cursor: pointer;
  display: block;
  position: relative;
  margin: 16px 8px;

  input { position: absolute; left: 5px; top: 7px; opacity: 0; }

  .control {
    background: #f6f6f6;
    border: 1px solid rgba(black, 10%);
    border-radius: 4px;
    height: 22px;
    left: 0;
    position: absolute;
    top: 2px;
    width: 22px;
    transition: border .2s, background .2s, box-shadow .2s;
  }

  .control:after {
    display: block;
    content: " ";
    width: 21px;
    height: 21px;
    background: icon('check', 'white', 21);
    top: 0;
    left: 1px;
    position: absolute;
    transform: scale(0);
    transition: transform .4s $bounce;
  }

  &:hover .control, input:focus + .control { border-color: $blue; background: #eee; }
  input:focus + .control { box-shadow: 0 0 0 3px rgba($blue, 50%); outline: none; }

  input:checked + .control { background: $blue; }
  input:checked + .control:after { transform: none; }

  &:hover input:checked + .control,
  input:focus:checked + .control { border-color: darken($blue, 30%); }
}


// -----------------------------------------------------------------------------
// Small Input Fields

.input-field {
  display: block;
  border-radius: 4px;
  cursor: text;
  text-align: center;
  padding: 0;
  color: inherit;
  line-height: 1.7em;
  border: 1px solid currentColor;

  transition: border .2s, background .2s, box-shadow .2s, color .2s;
  &:focus { border-color: $blue; box-shadow: 0 0 0 3px rgba($blue, 50%); outline: none; }

  -webkit-appearance: none;
  -moz-appearance: textfield;
  &::-webkit-inner-spin-button, &::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
}


// -----------------------------------------------------------------------------
// Buttons

.btn {
  @include button();
  min-width: 48px;
  padding: 0 1.2em;
  height: 2em;
  line-height: 2em;
  font-weight: 600;
  letter-spacing: .2px;
  background-color: $dark-grey;
  appearance: none;
  outline: none;

  @include bouncy();
  transition: transform .3s, background .2s, color .2s, box-shadow .2s, opacity .2s;

  &:hover, &:active { background-color: mix($grey, $medium-grey); }
  html.is-tabbing &:focus { box-shadow: 0 0 0 2px currentColor, 0 0 0 4px $dark-grey; }

  &.disabled, &[disabled] {
    background-color: #ddd !important;
    color: #999 !important;
  }

  x-icon { opacity: 0.95; transition: opacity .2s; margin: 0 6px -6px 0; fill: currentColor; }
  &:hover x-icon, &:active x-icon { opacity: 1; }
}

.btn-small {
  height: 1.6em;
  line-height: 1.6em;
  padding: 0 .8em;
}

.btn-large {
  font-size: 22px;
  padding: 0 20px;
  height: 44px;
  line-height: 44px;
  x-icon { margin: 0 10px -6px -2px; }
  .arrow { margin: 0 -2px -1px 6px; }
}

.btn-row { margin: -10px; }
.btn-row .btn { margin: 10px; }

.btn-red { @include coloured-btn($red); }
.btn-blue { @include coloured-btn($blue); }
.btn-green { @include coloured-btn($green); }
.btn-yellow { @include coloured-btn($yellow); }
.btn-grey { @include coloured-btn($medium-grey); }

.btn-white {
  @include coloured-btn(white);
  &, &:hover, &:active { color: $grey; }
}

.btn.facebook  { @include coloured-btn(#1878f2); }
.btn.twitter   { @include coloured-btn(#00b6f1); }
.btn.youtube   { @include coloured-btn(#ff0000); }
.btn.instagram { @include coloured-btn(#bc2a8d); }
.btn.pinterest { @include coloured-btn(#cb2027); }
.btn.tumblr    { @include coloured-btn(#35465d); }
.btn.reddit    { @include coloured-btn(#ff5700); }
.btn.microsoft { @include coloured-btn(#2f2f2f); }

.btn.google {
  // Special treatment for a white button on white background. Ugh.
  background: white; color: $grey; box-shadow: inset 0 0 0 1px #aaa;
  &:hover { box-shadow: inset 0 0 0 1px #aaa, 0 4px 12px rgba(black, 25%); }
  html.is-tabbing &:focus { box-shadow: inset 0 0 0 1px #aaa, 0 0 0 2px white, 0 0 0 4px $medium-grey; }
}

.icon-btn {
  @extend .btn;
  display: block;
  padding: 0;
  min-width: 40px;
  height: 40px;
  border-radius: 20px;
  x-icon { display: block; margin: 8px; }
}
