@media screen {
  .viewing .controls {
    display: flex !important;
  }
}

$btn-pad: 4px 8px;
$btn-hover: rgba(0, 0, 0, 0.04);
$btn-active: rgba(0, 0, 0, 0.08);

@mixin withHover {
  &:hover {
    background: $btn-hover;
  }

  &:active {
    background: $btn-active;
  }
}

@mixin focusState {
  outline: 0;
  box-shadow: 0 0 0 1px var(--bindery-ui-bg), 0 0 0 3px rgba(0, 0, 0, 0.3);
}

.controls {
  font: 14px / 1.4 $system;
  display: none;
  flex-direction: row;
  align-items: start;
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 99;
  margin: auto;
  color: var(--bindery-ui-text);
  padding: 8px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;

  * {
    font: inherit;
    color: inherit;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }

  a {
    color: var(--bindery-ui-accent);
    text-decoration: none;
  }
}

.row {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  cursor: default;
  user-select: none;
}

.controls .btn {
  -webkit-appearance: none;
  cursor: pointer;
  display: inline-block;
  margin-right: 8px;
  text-decoration: none;

  @include withHover;

  &:last-child {
    margin-right: 0;
  }
}

.control {
  border-radius: 6px;
  color: var(--bindery-ui-text);
  padding: $btn-pad;
  border: 1px solid #ddd;
  margin-right: 12px;
}

.controls .btn-main {
  position: absolute;
  top: 8px;
  right: 8px;

  background: var(--bindery-ui-accent);
  border-color: var(--bindery-ui-accent);
  color: white;

  &:hover {
    background: var(--bindery-ui-accent);
    opacity: 0.7;
  }

  &:active {
    background: black;
    opacity: 1;
  }

  &:focus {
    @include focusState;
  }
}

.view-row {
  transition: all 0.3s;
  .in-progress & {
    opacity: 0;
    pointer-events: none;
  }
  .debug & {
    display: none;
  }
}

.btn-print {
  margin-left: auto;
  transition: all 0.3s;
  .in-progress & {
    opacity: 0;
    pointer-events: none;
  }
}

.controls .select-wrap {
  padding-right: 24px;
  transition: all 0.2s;
  white-space: nowrap;
  width: 100%;
  position: relative;

  &:after {
    // Draw dropdown
    content: '';
    position: absolute;
    right: 9px;
    top: 12px;
    border-bottom: 1px solid;
    border-right: 1px solid;
    padding: 0px;
    border: 4px solid transparent;
    border-top-color: currentColor;
  }

  @include withHover;

  &:focus-within {
    @include focusState;
  }
}

.select {
  cursor: pointer;
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;

  -webkit-appearance: none;
  -moz-appearance: none;
  padding: $btn-pad;
  color: black;
  border: transparent;
  width: 100%;

  font-size: 18px; // avoid iOS zoom-in
}

.view-print .controls {
  background: var(--bindery-ui-bg);
}

@media screen and (max-width: 960px) {
  .view-print, .view-preview {
    .controls {
      background: var(--bindery-ui-bg);
      flex-direction: column;  
    }
  }
}

@media screen and (max-width: 500px) {
  .view-print .controls {
    background: var(--bindery-ui-bg);
  }
  .view-row {
    margin-bottom: 8px;
  }
  .print-options {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    .row + .row {
      margin-top: 8px;
    }
    .select-wrap {
      margin: 0;
    }
  }
}
