// colors

$black: #444444;
$white: white;
$yellow: #fffebe;
$background-color: #3aade3;

// prefix

$set_prefix: -webkit-, -moz-, -ms-, -o-, "";

// mixins

@mixin border-radius($br_value: 3px) {
  @each $prefix in $set_prefix {
    #{$prefix}border-radius: $br_value;
  }
}

@mixin box-shadow($shadow: default) {
  @each $prefix in $set_prefix {
    #{$prefix}box-shadow: $shadow;
  }
}

@mixin graduent($color: $white) {
  @each $prefix in $set_prefix {
    background: #{$prefix}linear-gradient(top, $color 0%, adjust_color($color, $red: -30, $green: -30, $blue: -30) 88%);
  }
}

@mixin inline-block {
  display: -moz-inline-stack;
  display: inline-block;
  vertical-align: middle;
  *vertical-align: auto;
  zoom: 1;
  *display: inline;
}

@mixin box {
  @each $prefix in $set_prefix {
    display: #{$prefix}box;
  }
}

@mixin box-sizing {
  @each $prefix in $set_prefix {
    #{$prefix}box-sizing: content-box;
  }
}

@mixin box-flex($bf_value: 1) {
  @each $prefix in $set_prefix {
    #{$prefix}box-flex: $bf_value;
  }
}

@mixin silver-graduent {
  @include graduent(#eeeeee);
}

@mixin blue-graduent {
  @include graduent(#b9e0f5);
}

@mixin active-migration {
  height: auto;
  background: $white;
  * {
    font-size: small;
    height: auto;
    overflow: auto;
  }
  td {
    padding: 4px 0.8em;
  }
  input {
    @include inline-block;
  }
}

@mixin table-header {
  @include silver-graduent;
  font: {
    size: 13px;
    weight: bold;
  };
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
  line-height: 2.2;
  padding: 0 0.8em;
}

@mixin column_type_text_color($color: #999999) {
  border-color: $color;
  background: desaturate(lighten($color, 30%), 20%);
  color: $black;
  border-style: solid;
  &:hover {
    border-color: darken($color, 10%);
    background: darken(desaturate(lighten($color, 30%), 20%), 10%);
  }
}

@mixin unsaved {
  background: $yellow;
  position: relative;
  &:before {
    content: "!";
    display: block;
    position: absolute;
    width: 18px;
    height: 18px;
    background: #ec7500;
    left: -14px;
    top: 6px;
    text-align: center;
    line-height: 18px;
    color: $white;
    @include border-radius(100px);
    @include box-shadow(rgba(0, 0, 0, 0.4) 0px 1px 1px);
    font: {
      size: 12px;
      family: Arial, sans-serif;
    };
  }
  &:hover {
    background: adjust_color($yellow, $red: -6, $green: -6, $blue: -6);
  }
}

// reset

html, body, p, ul, ol, dl, p, li, dt, dd, tr, td, form {
  margin: 0;
  padding: 0;
}

li {
  list-style-type: none;
}

// design

.cancel {
  display: block;
  margin: 0.4em auto 0;
  background: rgba(0, 0, 0, 0.4);
  font-size: 12px;
  width: 70px;
  @include border-radius(4px);
  text-decoration: none;
  line-height: 1.8;
  text-align: center;
  color: $white;
  position: relative;
  padding: 2px 0 0 8px;
  text-shadow: none;
  &:hover {
    background: rgba(0, 0, 0, 0.6);
  }
  &:before {
    content: "";
    display: block;
    height: 10px;
    width: 10px;
    position: absolute;
    left: 8px;
    top: 6px;
    background: {
      image: image_url('erd/cancel.png');
      size: 10px 10px;
      position: center center;
    };
  }
}

#erd_box {
  @include box;
}

#erd_container {
  @include box-flex;
}

#open_migration,
#close_migration {
  position: fixed;
  top: 0;
  background: rgba(0, 0, 0, 0.6);
  width: 80px;
  text-align: center;
  color: $white;
  cursor: pointer;
  z-index: 5;
  &:hover {
    background: rgba(0, 0, 0, 0.8);
  }
  img {
    width: 16px;
    height: 27px;
    display: block;
    margin: 16px auto;
  }
}

#open_migration {
  right: 15px;
}
#migrate_form {
  position: relative;
  #open_buttons {
    position: absolute;
    right: 0;
    top: 0;
    li {
      @include inline-block;
    }
  }
}


#migration {
  padding: 10px 10px;
  min-width: 500px;
  overflow-x: auto;
  @include box-sizing;
  position: relative;
  display: none;
  table,
  th,
  td {
    border: 1px $black solid;
    border-collapse: collapse;
  }
  table {
    width: 100%;
    margin: 0 0 0.6em;
    caption {
      font: {
        weight: bold;
      };
      margin: 0 0 0.5em;
    }
    thead {
      td {
        text-align: center;
        button {
          padding: 3px 30px;
        }
      }
    }
    td {
      font-size: 12px;
      padding: 2px 0.8em;
      line-height: 1.4;
      &.migrations {
        background: $black;
        color: $white;
      }
      &.migration_file_name {
        white-space: normal !important;
        word-break: break-all;
        -ms-word-wrap: break-word;
        max-width: 200px;
      }
    }
    th {
      @include table-header;
      &.status {
        width: 60px;
      }
      &.version {
        width: 140px;
      }
    }
  }
  #changes_form {
    margin: 0 0 20px;
  }
}

#migration_status {
  width: 386px;
  td {
    &.migration_file_name {
      word-break: break-all;
    }
    label {
      white-space: nowrap;
    }
  }
  tr {
    &.up,
    &.down {
      font-size: 0;
      height: 2px;
      overflow: hidden;
      * {
        font-size: 0;
        overflow: hidden;
      }
      input {
        display: none;
      }
      &:hover,&.active,&.open {
        @include active-migration;
      }
      &.active {
        background: $yellow;
      }
    }
  }
  &.show_all_migrations {
    .up,
    .down {
      @include active-migration;
    }
  }
}

#erd {
  overflow: auto;
  position: relative;
  background-color: $background-color;
  background-image: image_url('/erd/background.png');
  form {
    display: none;
  }
  .model {
    background-color: $white;
    position: absolute;
    border: 1px $black solid;
    cursor: move;
    z-index: 1;
    &:hover {
      @include box-shadow(rgba(0, 0, 0, 0.7) 0 2px 2px);
    }
    .model_name {
      border-bottom: 1px $black solid;
      cursor: pointer;
      margin: 1px 5px 0 5px auto;
      .model_name_text {
        text-align: center;
        display: block;
        @include table-header;
        &.unsaved {
          background: $yellow;
          position: relative;
          @include unsaved;
        }
      }
      form {
        @include table-header;
        padding: 8px;
      }
      & > div.model_name_text:hover {
        @include blue-graduent;
      }
    }
    a.close {
      position: absolute;
      top: -6px;
      right: -6px;
      z-index: 2;
      background-color: $black;
      border: 1px solid $black;
      display: block;
      width: 16px;
      height: 13px;
      text-align: center;
      @include border-radius(9px);
      padding: 3px 0 0;
      &:hover {
        background: adjust_color($black, $red: +50, $green: +50, $blue: +50);
      }
      img {
        width: 10px;
        height: 10px;
        display: block;
        margin: 0 auto;
      }
    }
  }
}

.add_column_box {
  text-align: center;
  a.add_column {
    font-size: small;
    display: block;
    padding: 0 5px;
    line-height: 2;
    background: $black;
    color: $white;
    text: {
      decoration: none;
    };
    &:hover {
      background: adjust_color($black, $red: -10, $green: -10, $blue: -10);
    }
  }
}

.add_column_form {
  background: $black;
  color: $white;
  padding: 8px;
}

.columns {
  .column {
    border-bottom: dotted 1px #cccccc;
    padding: 0 0.8em;
    clear: both;
    line-height: 28px;
    font-size: 14px;
    table {
      width: 100%;
    }
    &:nth-child(even) {
      background: adjust_color($white, $red: -6, $green: -6, $blue: -6);
    }
    &:last-child {
      border-bottom: none;
    }
    .column_name_text,
    .column_type_text {
      cursor: pointer;
    }
    .column_name_text {
      margin: 0 1.4em 0 0;
      &:hover {
        text-decoration: underline;
      }
    }
    &.unsaved {
      @include unsaved;
    }
    .rename_column_form {
      padding: 8px;
    }
    .column_type_text {
      font-size: 10px;
      float: right;
      display: block;
      line-height: 16px;
      margin: 5px 0 0;
      @include border-radius(4px);
      border-width: 1px;
      border-style: solid;
      width: 70px;
      text-align: center;
      @include column_type_text_color(#e98c60);
      &.date,
      &.time,
      &.timestamp,
      &.datetime {
        @include column_type_text_color(#da6272);
      }
      &.boolean {
        @include column_type_text_color(#45a1cf);
      }
      &.text {
        @include column_type_text_color(#dab24f);
      }
      &.decimal {
        @include column_type_text_color(#8e8e08);
      }
      &.float {
        @include column_type_text_color(#85616b);
      }
      &.integer {
        @include column_type_text_color(#7c80aa);
      }
      &.primary_key {
        @include column_type_text_color(#ea9a5d);
      }
      &.string {
        @include column_type_text_color(#a4c520);
      }
      &.unsaved {
        @include column_type_text_color(#a55d00);
      }
    }
    .alter_column_form {
      padding: 8px;
    }
    &:hover {
      background-color: adjust_color($white, $red: -20, $green: -20, $blue: -20);
    }
  }
}

#executed,#failed {
  padding: 7px;
  padding-bottom: 0;
  margin-bottom: 20px;
  background-color: #f0f0f0;
  h2 {
    text-align: left;
    font-weight: bold;
    padding: 5px 5px 5px 15px;
    font-size: 12px;
    margin: -7px;
    margin-bottom: 0px;
    color: white;
  }
  h3 {
    font-size: 12px;
    margin: 0;
    padding: 0;
  }
  ul li {
    margin-left: 25px;
    font-size: 12px;
    list-style: square;
  }
}

#executed {
  border: 2px lime solid;
  h2 {
    background-color: #00cc00;
  }
}

#failed {
  border: 2px red solid;
  h2 {
    background-color: #cc0000;
  }
}

#model_name_changes, #column_name_changes {
  display: none;
}

#open_create_model_dialog {
  position: fixed;
  right: 15px;
  top: 70px;
  background: rgba(0, 0, 0, .6);
  padding: 12px 20px;
  color: $white;
  text-decoration: none;
  font-size: 13px;
  &:hover {
    background: rgba(0, 0, 0, .8)
  }
}

#create_model_form {
  font-size: 14px;
}
#create_model_table {
  margin: 12px auto;
  border-spacing: 0;
  width: 100%;
  tr {
    &:nth-child(odd) {
      td {
        background: #f8f8f8;
      }
    }
    &:nth-child(even) {
      td {
        background: #eee;
      }
    }
    td {
      padding: 6px 12px;
      input {
        width: 100%;
        box-sizing: border-box;
      }
      &.separator {
        padding: 6px 0;
      }
    }
  }
}
#new_model_add_column {
  margin: 10px auto 0;
  display: block;
  width: 160px;
  padding: 2px 10px;
  text-decoration: none;
}
