/**
 * Variables declared here can be overridden by consuming applications, with
 * the help of the `!default` flag.
 *
 * @example
 *     // overriding $hoverColor
 *     $hoverColor: rgba(red, 0.05);
 *
 *     // overriding image path
 *     $flagsImagePath: "images/";
 *
 *     // import the scss file after the overrides
 *     @import "bower_component/intl-tel-input/src/css/intlTelInput";
 */

// rgba is needed for the selected flag hover state to blend in with
// the border-highlighting some browsers give the input on focus
$hoverColor: rgba(0, 0, 0, 0.05) !default;
$greyText: #999 !default;
$greyBorder: #CCC !default;

$flagHeight: 15px !default;
$flagWidth: 20px !default;
$flagPadding: 8px !default;
// this border width is used for the popup and divider, but it is also
// assumed to be the border width of the input, which we do not control
$borderWidth: 1px !default;

$arrowHeight: 4px !default;
$arrowWidth: 6px !default;
$triangleBorder: 3px !default;
$arrowPadding: 4px !default;
$arrowColor: #555 !default;

$inputPadding: 6px !default;
$selectedFlagWidth: $flagWidth + $flagPadding + $arrowWidth + (2 * $arrowPadding) !default;

// image related variables
$flagsImagePath: "../img/" !default;
$flagsImageName: "flags" !default;
$flagsImageExtension: "png" !default;

.intl-tel-input {
  // need position on the container so the selected flag can be
  // absolutely positioned over the input
  position: relative;
  // keep the input's default inline properties
  display: inline-block;

  // paul irish says this is ok
  // http://www.paulirish.com/2012/box-sizing-border-box-ftw/
  * {
    box-sizing: border-box;
    -moz-box-sizing: border-box;
  }

  .hide {
    display: none;
  }
  // need this during init, to get the height of the dropdown
  .v-hide {
    visibility: hidden;
  }

  // specify types to increase specificity e.g. to override bootstrap v2.3
  input, input[type=text], input[type=tel] {
    position: relative;
    // input is bottom level, below selected flag and dropdown
    z-index: 0;

    // any vertical margin the user has on their inputs would no longer work as expected
    // because we wrap everything in a container div. i justify the use of !important
    // here because i don't think the user should ever have vertical margin here - when
    // the input is wrapped in a container, vertical margin messes up alignment with other
    // inline elements (e.g. an adjacent button) in firefox, and probably other browsers.
    margin-top: 0 !important;
    margin-bottom: 0 !important;

    // make space for the selected flag
    // Note: no !important here, as the user may want to tweak this so that the
    // perceived input padding matches their existing styles
    padding-left: $selectedFlagWidth + $inputPadding;

    // any margin-left here will push the selected-flag away
    margin-left: 0;

    // when user presses invalid key, we add a class which instantly adds a bg color,
    // then when we remove that class, this does a quick fade back to no bg
    transition: background-color 100ms ease-out;
  }
  // when user presses invalid key, add this class temporarily to change bg color
  input.iti-invalid-key {
    // override the default transition state to show the change instantly
    transition: background-color 0;
    background-color: #FFC7C7;
  }

  .flag-dropdown {
    // positioned over the top of the input
    position: absolute;
    // full height
    top: 0;
    bottom: 0;
    // prevent the highlighted child from overlapping the input border
    padding: $borderWidth;
  }
  // hover state - show flag is clickable
  .flag-dropdown:hover {
    cursor: pointer;
    .selected-flag {
      background-color: $hoverColor;
    }
  }
  // disable hover state when input is disabled
  input[disabled] + .flag-dropdown:hover, input[readonly] + .flag-dropdown:hover {
    cursor: default;
    .selected-flag {
      background-color: transparent;
    }
  }

  .selected-flag {
    // render above the input
    z-index: 1;
    position: relative;
    width: $selectedFlagWidth;
    // this must be full-height both for the hover highlight, and to push down the
    // dropdown so it appears below the input
    height: 100%;
    padding: 0 0 0 $flagPadding;

    // vertically center the flag
    .iti-flag {
      position: absolute;
      top: 0;
      bottom: 0;
      margin: auto;
    }

    .arrow {
      position: absolute;
      // split the difference between the flag and the arrow height to verically center
      top: 50%;
      margin-top: -1 * ($arrowHeight / 2);
      right: $arrowPadding;

      // css triangle
      width: 0;
      height: 0;
      border-left: $triangleBorder solid transparent;
      border-right: $triangleBorder solid transparent;
      border-top: $arrowHeight solid $arrowColor;

      &.up {
        border-top: none;
        border-bottom: $arrowHeight solid $arrowColor;
      }
    }
  }

  // the dropdown
  .country-list {
    // override default list styles
    list-style: none;
    position: absolute;
    // popup so render above everything else
    z-index: 2;

    // inline flags
    .flag {
      display: inline-block;
      width: $flagWidth;
    }

    padding: 0;
    // margin-left to compensate for the padding on the parent
    margin: 0 0 0 (-$borderWidth);

    box-shadow: 1px 1px 4px rgba(0,0,0,0.2);
    background-color: white;
    border: $borderWidth solid $greyBorder;

    // don't let the contents wrap AKA the container will be as wide as the contents
    white-space: nowrap;
    // except on small screens, where we force the dropdown width to match the input
    @media (max-width: 500px) {
      white-space: normal;
    }

    max-height: 200px;
    overflow-y: scroll;

    // the divider below the preferred countries
    .divider {
      padding-bottom: 5px;
      margin-bottom: 5px;
      border-bottom: $borderWidth solid $greyBorder;
    }

    // each country item in dropdown
    .country {
      // Note: decided not to use line-height here for alignment because it causes issues e.g. large font-sizes will overlap, and also looks bad if one country overflows onto 2 lines
      padding: 5px 10px;
      // the dial codes after the country names are greyed out
      .dial-code {
        color: $greyText;
      }
    }
    .country.highlight {
      background-color: $hoverColor;
    }

    // spacing between country flag, name and dial code
    .flag, .country-name, .dial-code {
      vertical-align: middle;
    }
    .flag, .country-name {
      margin-right: 6px;
    }
  }

  // on mobiles we use a select for the country dropdown
  select {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    width: $selectedFlagWidth;
    height: 100%;
    opacity: 0;
  }
}






@import "sprite";

.iti-flag {
  width: $flagWidth;
  height: $flagHeight;
  box-shadow: 0px 0px 1px 0px #888;
  background-image: url("#{$flagsImagePath}#{$flagsImageName}.#{$flagsImageExtension}");
  background-repeat: no-repeat;
  // empty state
  background-color: #DBDBDB;
  background-position: $flagWidth 0;

  @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min--moz-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2 / 1), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) {
    background-image: url("#{$flagsImagePath}#{$flagsImageName}@2x.#{$flagsImageExtension}");
  }
}



// hack for Nepal which is the only flag that is not square/rectangle, so it has transparency, so you can see the default grey behind it
.iti-flag.np {
  background-color: transparent;
}
