// Name:            Utility
// Description:     Utilities collection
//
// Component:       `ui-panel-*`
//                  `ui-clearfix`
//                  `ui-float-*`
//                  `ui-overflow-*`
//                  `ui-resize-*`
//                  `ui-display-*`
//                  `ui-inline-*`
//                  `ui-responsive-*`
//                  `ui-preserve-width`
//                  `ui-border-*`
//                  `ui-box-shadow-*`
//                  `ui-box-shadow-bottom`
//                  `ui-dropcap`
//                  `ui-logo`
//                  `ui-blend-*`
//                  `ui-transform-*`
//                  `ui-transform-origin-*`
//
// States:          `ui-disabled`
//                  `ui-drag`
//                  `ui-dragover`
//                  `ui-preserve`
//
// ========================================================================


// Variables
// ========================================================================

@panel-scrollable-height:                       170px;
@panel-scrollable-padding:                      10px;
@panel-scrollable-border-width:                 @global-border-width;
@panel-scrollable-border:                       @global-border;

@border-rounded-border-radius:                  5px;

@box-shadow-duration:                           0.1s;

@box-shadow-bottom-height:                      30px;
@box-shadow-bottom-border-radius:               100%;
@box-shadow-bottom-background:                  #444;
@box-shadow-bottom-blur:                        20px;

@dropcap-margin-right:                          10px;
@dropcap-font-size:                             ((@global-line-height * 3) * 1em);

@logo-font-size:                                @global-large-font-size;
@logo-font-family:                              @global-font-family;
@logo-color:                                    @global-color;
@logo-hover-color:                              @global-color;

@dragover-box-shadow:                           0 0 20px rgba(100,100,100,0.3);


/* ========================================================================
   Component: Utility
 ========================================================================== */


/* Panel
 ========================================================================== */

.ui-panel {
  position: relative;
  box-sizing: border-box;
}

/*
 * Micro clearfix
 */

.ui-panel::before,
.ui-panel::after {
  content: "";
  display: table;
}

.ui-panel::after { clear: both; }

/*
 * Remove margin from the last-child
 */

.ui-panel > :last-child { margin-bottom: 0; }


/*
 * Scrollable
 */

.ui-panel-scrollable {
  height: @panel-scrollable-height;
  padding: @panel-scrollable-padding;
  border: @panel-scrollable-border-width solid @panel-scrollable-border;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  resize: both;
  .hook-panel-scrollable;
}


/* Clearfix
 ========================================================================== */

/*
 * 1. `table-cell` is used with `::before` because `table` creates a 1px gap when it becomes a flex item, only in Webkit
 * 2. `table` is used again with `::after` because `clear` only works with block elements.
 * Note: `display: block` with `overflow: hidden` is currently not working in the latest Safari
 */

/* 1 */
.ui-clearfix::before {
  content: "";
  display: table-cell;
}

/* 2 */
.ui-clearfix::after {
  content: "";
  display: table;
  clear: both;
}


/* Float
 ========================================================================== */

/*
 * 1. Prevent content overflow
 */

.ui-float-left { float: left; }
.ui-float-right { float: right; }

/* 1 */
[class*='ui-float-'] { max-width: 100%; }


/* Overfow
 ========================================================================== */

.ui-overflow-hidden { overflow: hidden; }

/*
 * Enable scrollbars if content is clipped
 * Note: Firefox ignores `padding-bottom` for the scrollable overflow https://bugzilla.mozilla.org/show_bug.cgi?id=748518
 */

.ui-overflow-auto {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.ui-overflow-auto > :last-child { margin-bottom: 0; }


/* Resize
 ========================================================================== */

.ui-resize { resize: both; }
.ui-resize-vertical { resize: vertical; }


/* Display
 ========================================================================== */

.ui-display-block { display: block !important; }
.ui-display-inline { display: inline !important; }
.ui-display-inline-block { display: inline-block !important; }


/* Inline
 ========================================================================== */

/*
 * 1. Container fits its content
 * 2. Create position context
 * 3. Prevent content overflow
 * 4. Behave like most inline-block elements
 * 5. Force hardware acceleration without creating a new stacking context
 *    to fix 1px glitch when combined with overlays and transitions in Webkit
 * 6. Clip child elements
 */

[class*='ui-inline'] {
  /* 1 */
  display: inline-block;
  /* 2 */
  position: relative;
  /* 3 */
  max-width: 100%;
  /* 4 */
  vertical-align: middle;
  /* 5 */
  -webkit-backface-visibility: hidden;
}

.ui-inline-clip {
  /* 6 */
  overflow: hidden;
}


/* Responsive objects
 ========================================================================== */

/*
 * Preserve original dimensions
 * Because `img, `video`, `canvas` and  `audio` are already responsive by default, see Base component
 */

.ui-preserve-width,
.ui-preserve-width canvas,
.ui-preserve-width img,
.ui-preserve-width svg,
.ui-preserve-width video { max-width: none; }

/*
 * Responsiveness
 * Corrects `max-width` and `max-height` behavior if padding and border are used
 */

.ui-responsive-width,
.ui-responsive-height { box-sizing: border-box; }

/*
 * 1. Set a maximum width. `important` needed to override `ui-preserve-width img`
 * 2. Auto scale the height. Only needed if `height` attribute is present
 */

.ui-responsive-width {
  /* 1 */
  max-width: 100% !important;
  /* 2 */
  height: auto;
}

/*
 * 1. Set a maximum height. Only works if the parent element has a fixed height
 * 2. Auto scale the width. Only needed if `width` attribute is present
 * 3. Reset max-width, which `img, `video`, `canvas` and  `audio` already have by default
 */

.ui-responsive-height {
  /* 1 */
  max-height: 100%;
  /* 2 */
  width: auto;
  /* 3 */
  max-width: none;
}


/* Border
 ========================================================================== */

.ui-border-circle { border-radius: 50%; }
.ui-border-pill { border-radius: 500px; }
.ui-border-rounded { border-radius: @border-rounded-border-radius; }

/*
 * Fix `overflow: hidden` to be ignored with border-radius and CSS transforms in Webkit
 */

.ui-inline-clip[class*='ui-border-'] { -webkit-transform: translateZ(0); }


/* Box-shadow
 ========================================================================== */

.ui-box-shadow-small { box-shadow: @global-small-box-shadow; }
.ui-box-shadow-medium { box-shadow: @global-medium-box-shadow; }
.ui-box-shadow-large { box-shadow: @global-large-box-shadow; }
.ui-box-shadow-xlarge { box-shadow: @global-xlarge-box-shadow; }

/*
 * Hover
 */

[class*='ui-box-shadow-hover'] { transition: box-shadow @box-shadow-duration ease-in-out; }

.ui-box-shadow-hover-small:hover { box-shadow: @global-small-box-shadow; }
.ui-box-shadow-hover-medium:hover { box-shadow: @global-medium-box-shadow; }
.ui-box-shadow-hover-large:hover { box-shadow: @global-large-box-shadow; }
.ui-box-shadow-hover-xlarge:hover { box-shadow: @global-xlarge-box-shadow; }


/* Box-shadow bottom
 ========================================================================== */

/*
 * 1. Set position.
 * 2. Set style
 * 3. Blur doesn't work on pseudo elements with negative `z-index` in Edge.
 *    Solved by using `before` and add position context to child elements.
 */

@supports (filter: blur(0)) {

  .ui-box-shadow-bottom {
    display: inline-block;
    position: relative;
    max-width: 100%;
    vertical-align: middle;
  }

  .ui-box-shadow-bottom::before {
    content: '';
    /* 1 */
    position: absolute;
    bottom: -@box-shadow-bottom-height;
    left: 0;
    right: 0;
    /* 2 */
    height: @box-shadow-bottom-height;
    border-radius: @box-shadow-bottom-border-radius;
    background: @box-shadow-bottom-background;
    filter: blur(@box-shadow-bottom-blur);
    .hook-box-shadow-bottom;
  }

  /* 3 */
  .ui-box-shadow-bottom > * { position: relative; }

}


/* Drop cap
 ========================================================================== */

/*
 * 1. Firefox doesn't apply `::first-letter` if the first letter is inside child elements
 *    https://bugzilla.mozilla.org/show_bug.cgi?id=214004
 * 2. In Firefox, a floating `::first-letter` doesn't have a line box and there for no `line-height`
 *    https://bugzilla.mozilla.org/show_bug.cgi?id=317933
 * 3. Caused by 1.: Edge creates two nested `::first-letter` containers, one for each selector
 *    This doubles the `font-size` exponential when using the `em` unit.
 */

.ui-dropcap::first-letter,
  /* 1 */
.ui-dropcap > p:first-of-type::first-letter {
  display: block;
  margin-right: @dropcap-margin-right;
  float: left;
  font-size: @dropcap-font-size;
  line-height: 1;
  .hook-dropcap;
}

/* 2 */
@-moz-document url-prefix() {

  .ui-dropcap::first-letter,
  .ui-dropcap > p:first-of-type::first-letter { margin-top: 1.1%; }

}

/* 3 */
@supports (-ms-ime-align: auto) {

  .ui-dropcap > p:first-of-type::first-letter { font-size: 1em; }

}


/* Logo
 ========================================================================== */

/*
 * 1. Required for `a`
 */

.ui-logo {
  font-size: @logo-font-size;
  font-family: @logo-font-family;
  color: @logo-color;
  /* 1 */
  text-decoration: none;
  .hook-logo;
}

/* Hover + Focus */
.ui-logo:hover,
.ui-logo:focus {
  color: @logo-hover-color;
  outline: none;
  /* 1 */
  text-decoration: none;
  .hook-logo-hover;
}

.ui-logo-inverse { display: none; }


/* Disabled State
 ========================================================================== */

.ui-disabled { pointer-events: none; }


/* Drag State
 ========================================================================== */

/*
 * 1. Needed if moving over elements with have their own cursor on hover, e.g. links or buttons
 * 2. Fix dragging over iframes
 */

.ui-drag,
  /* 1 */
.ui-drag * { cursor: move; }

/* 2 */
.ui-drag iframe { pointer-events: none; }


/* Dragover State
 ========================================================================== */

/*
 * Create a box-shadow when dragging a file over the upload area
 */

.ui-dragover { box-shadow: @dragover-box-shadow; }


/* Blend modes
 ========================================================================== */

.ui-blend-multiply { mix-blend-mode: multiply; }
.ui-blend-screen { mix-blend-mode: screen; }
.ui-blend-overlay { mix-blend-mode: overlay; }
.ui-blend-darken { mix-blend-mode: darken; }
.ui-blend-lighten { mix-blend-mode: lighten; }
.ui-blend-color-dodge { mix-blend-mode: color-dodge; }
.ui-blend-color-burn { mix-blend-mode: color-burn; }
.ui-blend-hard-light { mix-blend-mode: hard-light; }
.ui-blend-soft-light { mix-blend-mode: soft-light; }
.ui-blend-difference { mix-blend-mode: difference; }
.ui-blend-exclusion { mix-blend-mode: exclusion; }
.ui-blend-hue { mix-blend-mode: hue; }
.ui-blend-saturation { mix-blend-mode: saturation; }
.ui-blend-color { mix-blend-mode: color; }
.ui-blend-luminosity { mix-blend-mode: luminosity; }


/* Transform
========================================================================== */

.ui-transform-center { transform: translate(-50%, -50%); }


/* Transform Origin
========================================================================== */

.ui-transform-origin-top-left { transform-origin: 0 0; }
.ui-transform-origin-top-center { transform-origin: 50% 0; }
.ui-transform-origin-top-right { transform-origin: 100% 0; }
.ui-transform-origin-center-left { transform-origin: 0 50%; }
.ui-transform-origin-center-right { transform-origin: 100% 50%; }
.ui-transform-origin-bottom-left { transform-origin: 0 100%; }
.ui-transform-origin-bottom-center { transform-origin: 50% 100%; }
.ui-transform-origin-bottom-right { transform-origin: 100% 100%; }


// Hooks
// ========================================================================

.hook-utility-misc;

.hook-panel-scrollable() {}
.hook-box-shadow-bottom() {}
.hook-dropcap() {}
.hook-logo() {}
.hook-logo-hover() {}
.hook-utility-misc() {}


// Inverse
// ========================================================================

@inverse-logo-color:                           @inverse-global-color;
@inverse-logo-hover-color:                     @inverse-global-color;

.hook-inverse() {

  .ui-dropcap::first-letter,
  .ui-dropcap p:first-of-type::first-letter {
    .hook-inverse-dropcap;
  }

  .ui-logo {
    color: @inverse-logo-color;
    .hook-inverse-logo;
  }

  .ui-logo:hover,
  .ui-logo:focus {
    color: @inverse-logo-hover-color;
    .hook-inverse-logo-hover;
  }

  .ui-logo > :not(.ui-logo-inverse):not(:only-of-type) { display: none; }
  .ui-logo-inverse { display: inline; }

}

.hook-inverse-dropcap() {}
.hook-inverse-logo() {}
.hook-inverse-logo-hover() {}